[libc-commits] [libc] c74c344 - [libc] Fix alignment logic in TLS image size calculation.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Mon Mar 7 01:22:42 PST 2022


Author: Siva Chandra Reddy
Date: 2022-03-07T09:21:37Z
New Revision: c74c344263034edda867845c2421f4f0cef03107

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

LOG: [libc] Fix alignment logic in TLS image size calculation.

Added: 
    

Modified: 
    libc/loader/linux/x86_64/start.cpp

Removed: 
    


################################################################################
diff  --git a/libc/loader/linux/x86_64/start.cpp b/libc/loader/linux/x86_64/start.cpp
index 46b6da6f908f1..8a47a2713cfca 100644
--- a/libc/loader/linux/x86_64/start.cpp
+++ b/libc/loader/linux/x86_64/start.cpp
@@ -38,7 +38,9 @@ void initTLS() {
     return;
 
   // We will assume the alignment is always a power of two.
-  uintptr_t tlsSize = (app.tls.size + app.tls.align) & -app.tls.align;
+  uintptr_t tlsSize = app.tls.size & -app.tls.align;
+  if (tlsSize != app.tls.size)
+    tlsSize += app.tls.align;
 
   // Per the x86_64 TLS ABI, the entry pointed to by the thread pointer is the
   // address of the TLS block. So, we add more size to accomodate this address


        


More information about the libc-commits mailing list