Skip to content

Commit 8936100

Browse files
authored
[hwasan] Move __hwasan_thread_enter/__hwasan_thread_exit out of namespace (#72123)
Due to a GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25940), GCC doesn't consider extern "C" functions with the same name but different namespace to be the same. As such, the default visibility attribute (on a declaration outside the namespace) doesn't get applied to the definition in the namespace and the symbol is not exported. This came up as an ABI diff when switching between gcc and clang for compiling compiler-rt.
1 parent 261b471 commit 8936100

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,6 @@ void InstallAtExitHandler() { atexit(HwasanAtExit); }
294294

295295
// ---------------------- TSD ---------------- {{{1
296296

297-
extern "C" void __hwasan_thread_enter() {
298-
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
299-
}
300-
301-
extern "C" void __hwasan_thread_exit() {
302-
Thread *t = GetCurrentThread();
303-
// Make sure that signal handler can not see a stale current thread pointer.
304-
atomic_signal_fence(memory_order_seq_cst);
305-
if (t) {
306-
// Block async signals on the thread as the handler can be instrumented.
307-
// After this point instrumented code can't access essential data from TLS
308-
// and will crash.
309-
// Bionic already calls __hwasan_thread_exit with blocked signals.
310-
if (SANITIZER_GLIBC)
311-
BlockSignals();
312-
hwasanThreadList().ReleaseThread(t);
313-
}
314-
}
315-
316297
# if HWASAN_WITH_INTERCEPTORS
317298
static pthread_key_t tsd_key;
318299
static bool tsd_key_inited = false;
@@ -561,4 +542,25 @@ void InstallAtExitCheckLeaks() {
561542

562543
} // namespace __hwasan
563544

545+
using namespace __hwasan;
546+
547+
extern "C" void __hwasan_thread_enter() {
548+
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
549+
}
550+
551+
extern "C" void __hwasan_thread_exit() {
552+
Thread *t = GetCurrentThread();
553+
// Make sure that signal handler can not see a stale current thread pointer.
554+
atomic_signal_fence(memory_order_seq_cst);
555+
if (t) {
556+
// Block async signals on the thread as the handler can be instrumented.
557+
// After this point instrumented code can't access essential data from TLS
558+
// and will crash.
559+
// Bionic already calls __hwasan_thread_exit with blocked signals.
560+
if (SANITIZER_GLIBC)
561+
BlockSignals();
562+
hwasanThreadList().ReleaseThread(t);
563+
}
564+
}
565+
564566
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD

0 commit comments

Comments
 (0)