🔬 Tracking issue for array cookie support
Closed this issue · 0 comments
alexanderlinne commented
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:
CXXNewExpr::doesUsualArrayDeleteWantSize
andCXXDeleteExpr::doesUsualArrayDeleteWantSize
to check whether the delet function takes two arguments.CXXNewExpr::getAllocatedType
asexpr->getAllocatedType().isDestructedType()
to check whether the array element type has a non-trivial destructor.
=> How are array cookies created?
According to [1]:
- array cookies always have size
sizeof(size_t)
- if
align
is the maximum alignment ofsize_t
and an element of the array andpadding
is the maximum ofsizeof(size_t}
andalign
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 inItaniumCXXABI::InitializeArrayCookie
.
- "The space allocated for the will be the space required by the array itself plus
[1] https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies