Skip to content

Commit 4ac24b3

Browse files
[libc] inline thread self (#101739)
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.
1 parent 858bea8 commit 4ac24b3

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

libc/src/__support/threads/thread.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include "src/__support/macros/attributes.h"
1818

1919
namespace LIBC_NAMESPACE_DECL {
20-
21-
LIBC_THREAD_LOCAL Thread self;
22-
2320
namespace {
2421

2522
using AtExitCallback = void(void *);

libc/src/__support/threads/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct Thread {
231231
int get_name(cpp::StringStream &name) const;
232232
};
233233

234-
extern LIBC_THREAD_LOCAL Thread self;
234+
LIBC_INLINE_VAR LIBC_THREAD_LOCAL Thread self;
235235

236236
// Platforms should implement this function.
237237
[[noreturn]] void thread_exit(ThreadReturnValue retval, ThreadStyle style);

0 commit comments

Comments
 (0)