[compiler-rt] [scudo] [MTE] resize stack depot for allocation ring buffer (PR #74515)

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 19:06:14 PST 2023


================
@@ -1504,6 +1529,28 @@ class Allocator {
       return;
     u32 AllocationRingBufferSize =
         static_cast<u32>(getFlags()->allocation_ring_buffer_size);
+    // We store alloc and free stacks for each entry.
+    constexpr auto kStacksPerRingBufferEntry = 2;
+    u32 TabSize = static_cast<u32>(roundUpPowerOfTwo(kStacksPerRingBufferEntry *
+                                                     AllocationRingBufferSize));
+    constexpr auto kFramesPerStack = 8;
+    static_assert(isPowerOfTwo(kFramesPerStack));
+    u32 RingSize = static_cast<u32>(TabSize * kFramesPerStack);
+    DCHECK(isPowerOfTwo(RingSize));
+    static_assert(sizeof(StackDepot) % alignof(atomic_u64) == 0);
+
+    StackDepotSize = sizeof(StackDepot) + sizeof(atomic_u64) * RingSize +
----------------
cferris1000 wrote:

Is there any kind of alignment you have to worry about here? For example, if StackDepot winds up ending on an 8 byte aligned value, then atomic_u64 values will be aligned improperly. The next one doesn't matter because you get the same alignment across everything after that.

The alignas on the class, doesn't guarantee that a StackDepot object is aligned, but you might be using some other trick to guarantee the alignment I didn't catch.

https://github.com/llvm/llvm-project/pull/74515


More information about the llvm-commits mailing list