[libc-commits] [libc] 0539a6b - [libc] Align the new thread stack as required by the target ABI.

Siva Chandra via libc-commits libc-commits at lists.llvm.org
Mon Jun 6 14:46:22 PDT 2022


Author: Siva Chandra
Date: 2022-06-06T14:45:43-07:00
New Revision: 0539a6b4203d463926774b46170648ae36ec576e

URL: https://github.com/llvm/llvm-project/commit/0539a6b4203d463926774b46170648ae36ec576e
DIFF: https://github.com/llvm/llvm-project/commit/0539a6b4203d463926774b46170648ae36ec576e.diff

LOG: [libc] Align the new thread stack as required by the target ABI.

Added: 
    

Modified: 
    libc/src/__support/threads/linux/thread.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/threads/linux/thread.h b/libc/src/__support/threads/linux/thread.h
index 23e26be17aaf5..a354f2d5528c5 100644
--- a/libc/src/__support/threads/linux/thread.h
+++ b/libc/src/__support/threads/linux/thread.h
@@ -75,7 +75,7 @@ template <typename ReturnType> using ThreadRunner = ReturnType(void *);
 // 16-byte boundary to satisfy the x86_64 and aarch64 ABI requirements.
 // If 
diff erent architecture in future requires higher alignment, then we
 // can add a platform specific alignment spec.
-template <typename ReturnType> struct alignas(16) StartArgs {
+template <typename ReturnType> struct alignas(STACK_ALIGNMENT) StartArgs {
   Thread<ReturnType> *thread;
   ThreadRunner<ReturnType> *func;
   void *arg;
@@ -133,6 +133,7 @@ template <typename ReturnType> struct Thread {
                                sizeof(StartArgs<ReturnType>) -
                                sizeof(ThreadAttributes<ReturnType>) -
                                sizeof(cpp::Atomic<FutexWordType>);
+    adjusted_stack &= ~(uintptr_t(STACK_ALIGNMENT) - 1);
 
     auto *start_args =
         reinterpret_cast<StartArgs<ReturnType> *>(adjusted_stack);


        


More information about the libc-commits mailing list