about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorquininer <quininer@live.com>2023-11-13 20:48:23 +0800
committerquininer <quininer@live.com>2023-12-07 00:21:32 +0800
commite5b76892cc5e6fbfb495bf6a7339962a287849a7 (patch)
tree81bfe340a76ab385e4631c2ef51e5c5db55385a0 /library/std/src/sys
parent8a7b2035f816f6d27003a9326d6bd3a3d739fcc3 (diff)
Add emulated TLS support
Currently LLVM uses emutls by default
for some targets (such as android, openbsd),
but rust does not use it, because `has_thread_local` is false.

This commit has some changes to allow users to enable emutls:

1. add `-Zhas-thread-local` flag to specify
    that std uses `#[thread_local]` instead of pthread key.
2. when using emutls, decorate symbol names
    to find thread local symbol correctly.
3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated`
    to explicitly specify whether to generate emutls.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/thread_local_dtor.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs
index 667fd516962..ac85531c372 100644
--- a/library/std/src/sys/unix/thread_local_dtor.rs
+++ b/library/std/src/sys/unix/thread_local_dtor.rs
@@ -12,7 +12,13 @@
 // compiling from a newer linux to an older linux, so we also have a
 // fallback implementation to use as well.
 #[allow(unexpected_cfgs)]
-#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "redox", target_os = "hurd"))]
+#[cfg(any(
+    target_os = "linux",
+    target_os = "android",
+    target_os = "fuchsia",
+    target_os = "redox",
+    target_os = "hurd"
+))]
 // FIXME: The Rust compiler currently omits weakly function definitions (i.e.,
 // __cxa_thread_atexit_impl) and its metadata from LLVM IR.
 #[no_sanitize(cfi, kcfi)]