Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] inline thread self #101739

Merged
merged 1 commit into from
Aug 2, 2024
Merged

Conversation

SchrodingerZhu
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu commented Aug 2, 2024

The codegen for non-inlined version is "quite ugly" as it emits some checks to make sure the initialization routine is properly executed because the compiler does not see how the TLS object is initialized. This leads to some callq 0x0 junk in the final outputs.

For codegen details, see https://godbolt.org/z/rb5qYj3vY.

@llvmbot llvmbot added the libc label Aug 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 2, 2024

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

The codegen for non-inlined version is quite ugly. See https://godbolt.org/z/rb5qYj3vY


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

2 Files Affected:

  • (modified) libc/src/__support/threads/thread.cpp (-3)
  • (modified) libc/src/__support/threads/thread.h (+1-1)
diff --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp
index 886281e0d50f7..dad4f75f092ed 100644
--- a/libc/src/__support/threads/thread.cpp
+++ b/libc/src/__support/threads/thread.cpp
@@ -17,9 +17,6 @@
 #include "src/__support/macros/attributes.h"
 
 namespace LIBC_NAMESPACE_DECL {
-
-LIBC_THREAD_LOCAL Thread self;
-
 namespace {
 
 using AtExitCallback = void(void *);
diff --git a/libc/src/__support/threads/thread.h b/libc/src/__support/threads/thread.h
index 68640cef32964..f2b1f6bbb253d 100644
--- a/libc/src/__support/threads/thread.h
+++ b/libc/src/__support/threads/thread.h
@@ -231,7 +231,7 @@ struct Thread {
   int get_name(cpp::StringStream &name) const;
 };
 
-extern LIBC_THREAD_LOCAL Thread self;
+LIBC_INLINE_VAR LIBC_THREAD_LOCAL Thread self;
 
 // Platforms should implement this function.
 [[noreturn]] void thread_exit(ThreadReturnValue retval, ThreadStyle style);

@SchrodingerZhu SchrodingerZhu merged commit 4ac24b3 into llvm:main Aug 2, 2024
6 of 7 checks passed
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
The codegen for non-inlined version is "quite ugly" as it emits some
checks to make sure the initialization routine is properly executed
because the compiler does not see how the TLS object is initialized.
This leads to some `callq 0x0` junk in the final outputs.

For codegen details, see https://godbolt.org/z/rb5qYj3vY.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants