tudasc/TypeART

🔬 Tracking issue for array cookie support

Closed this issue · 0 comments

This is a tracking issue for the support of array cookies in TypeART.

Steps

  • Research when and how array cookies are added
  • Add test cases for cases where array cookies are expected to be added -> 65684d7, 22d8b4f
  • Implementation
    • Finding array cookies -> d40d567
    • Add array cookie data to existing data structures -> 7781f78
    • Consider the padding of array cookies when calculating array element counts -> 0817a3a
    • In case an array cookie is present, instrument the actual starting address of the array instead of the originally allocated address -> 650b1a3
    • Add instrumentation for array cookies

Unresolved Questions

  • Should array cookies be instrumented in any way and if so, how? -> for now, only to correctly calculate array sizes

Array Cookie research

Array cookies are a size_t value saving the allocated length of an array. These cookies are allocated under certain conditions when operator new is used to allocate an array.

=> When are array cookies created?

According to [1], an array cookie is not allocated if either of

  • "the element type T has a trivial destructor […] and the usual (array) deallocation function […] does not take two arguments" or
  • "the new operator being used is ::operator new [](size_t, void*)"

In Clang this is implemented in CGCXXABI::requiresArrayCookie using:

=> How are array cookies created?

According to [1]:

  • array cookies always have size sizeof(size_t)
  • if align is the maximum alignment of size_t and an element of the array and padding is the maximum of sizeof(size_t} and align bytes:
    • "The space allocated for the will be the space required by the array itself plus padding bytes"
    • "The cookie will be stored in the sizeof(size_t) bytes immediately preceding the array
      In Clang this is implemented in ItaniumCXXABI::InitializeArrayCookie.

[1] https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies