Skip to content

Conversation

saturn691
Copy link
Contributor

@saturn691 saturn691 commented Jul 31, 2025

When single-threaded mode is selected, all instances of the keyword LIBC_THREAD_LOCAL are stubbed out, similar to how it currently works on the GPU. This allows baremetal builds to avoid using thread_local.

However, libcxx uses shared headers, so we need to be careful there. Thankfully, there is already an option to disable multithreading in libcxx, so a flag is added such that single-threaded mode is propagated down to libc.

@llvmbot llvmbot added the libc label Jul 31, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2025

@llvm/pr-subscribers-libc

Author: William Huynh (saturn691)

Changes

This allows baremetal builds to avoid using thread_local. However, libcxx may be affected by this.


Full diff: https://github.com/llvm/llvm-project/pull/151527.diff

1 Files Affected:

  • (modified) libc/src/__support/macros/attributes.h (+1-1)
diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index c6474673de85a..23f973827b6f9 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -28,7 +28,7 @@
 #define LIBC_INLINE_ASM __asm__ __volatile__
 #define LIBC_UNUSED __attribute__((unused))
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
+#if LIBC_THREAD_MODE == LIBC_THREAD_MODE_SINGLE
 #define LIBC_THREAD_LOCAL
 #else
 #define LIBC_THREAD_LOCAL thread_local

@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Aug 1, 2025
@saturn691 saturn691 marked this pull request as draft August 1, 2025 14:47
@saturn691 saturn691 force-pushed the libc-thread-local branch 4 times, most recently from d325e19 to 44fc155 Compare August 5, 2025 15:03
@saturn691 saturn691 marked this pull request as ready for review August 6, 2025 13:01
@saturn691
Copy link
Contributor Author

It seems the CI failure here stems from a manual interrupt- requesting review.

@saturn691 saturn691 merged commit 0b16395 into llvm:main Aug 6, 2025
81 of 87 checks passed
@saturn691 saturn691 deleted the libc-thread-local branch August 6, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake Build system in general and CMake in particular libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants