[libc] Fix alignment logic in TLS image size calculation.
authorSiva Chandra Reddy <sivachandra@google.com>
Mon, 7 Mar 2022 05:56:04 +0000 (05:56 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Mon, 7 Mar 2022 09:21:37 +0000 (09:21 +0000)
libc/loader/linux/x86_64/start.cpp

index 46b6da6..8a47a27 100644 (file)
@@ -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