[libc-commits] [libc] [libc][startup] fix main thread TLS unmapped with wrong value (PR #102009)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Mon Aug 5 09:23:55 PDT 2024


https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/102009

We have been unmapping a wrong address all the time.
```c
munmap(0x704cffebb000, 41048)           = 0
munmap(0x704cffec6000, 69632)           = 0
munmap(0x704cffe9f000, 41048)           = 0
munmap(0x704cffeaa000, 69632)           = 0
munmap(0x704cffe83000, 41048)           = 0
munmap(0x704cffe8e000, 69632)           = 0
munmap(0x704cffe67000, 41048)           = 0
munmap(0x704cffe72000, 69632)           = 0
munmap(0x704cffe4b000, 41048)           = 0
munmap(0x704cffe56000, 69632)           = 0
munmap(0x704cffe2f000, 41048)           = 0
munmap(0x704cffe3a000, 69632)           = 0
munmap(0x704cfff51028, 41048)           = -1 EINVAL (Invalid argument)
```

>From b6fed2cf1625b157bbd28b9ace293d66ca2d599f Mon Sep 17 00:00:00 2001
From: Yifan Zhu <yifzhu at nvidia.com>
Date: Mon, 5 Aug 2024 09:22:31 -0700
Subject: [PATCH] [libc][startup] fix main thread TLS unmapped with wrong value

---
 libc/startup/linux/do_start.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/startup/linux/do_start.cpp b/libc/startup/linux/do_start.cpp
index 824c0e1cf8f26..72060b4adb214 100644
--- a/libc/startup/linux/do_start.cpp
+++ b/libc/startup/linux/do_start.cpp
@@ -133,7 +133,7 @@ static ThreadAttributes main_thread_attrib;
   // We register the cleanup_tls function to be the last atexit callback to be
   // invoked. It will tear down the TLS. Other callbacks may depend on TLS (such
   // as the stack protector canary).
-  atexit([]() { cleanup_tls(tls.tp, tls.size); });
+  atexit([]() { cleanup_tls(tls.addr, tls.size); });
   // We want the fini array callbacks to be run after other atexit
   // callbacks are run. So, we register them before running the init
   // array callbacks as they can potentially register their own atexit



More information about the libc-commits mailing list