Skip to content

Commit 089fc39

Browse files
committed
[LLVM 19] don't optimize register_weak_<whatever> when building with msvc
1 parent 1cb9c6c commit 089fc39

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,26 @@ void initialize_thunks(const sanitizer_thunk *begin,
6060
// ------------------ Weak symbol registration macros ---------------------- //
6161
// Use .WEAK segment to register function pointers that are iterated over during
6262
// startup that will replace sanitizer_export with local_function
63+
#ifdef __clang__
64+
# define REGISTER_WEAK_OPTNONE __attribute__((optnone))
65+
#else
66+
# define REGISTER_WEAK_OPTNONE
67+
#endif
6368

64-
#define REGISTER_WEAK_FUNCTION(local_function) \
65-
extern "C" void local_function(); \
66-
extern "C" void WEAK_EXPORT_NAME(local_function)(); \
67-
WIN_WEAK_IMPORT_DEF(local_function) \
68-
__attribute__((optnone)) static int register_weak_##local_function() { \
69-
if ((uintptr_t) & local_function != (uintptr_t) & \
70-
WEAK_EXPORT_NAME(local_function)) { \
71-
return __sanitizer::register_weak( \
72-
SANITIZER_STRINGIFY(WEAK_EXPORT_NAME(local_function)), \
73-
reinterpret_cast<__sanitizer::uptr>(local_function)); \
74-
} \
75-
return 0; \
76-
} \
77-
__pragma(section(".WEAK$M", long, read)) __declspec(allocate( \
78-
".WEAK$M")) int (*__sanitizer_register_weak_##local_function)() = \
69+
#define REGISTER_WEAK_FUNCTION(local_function) \
70+
extern "C" void local_function(); \
71+
extern "C" void WEAK_EXPORT_NAME(local_function)(); \
72+
WIN_WEAK_IMPORT_DEF(local_function) \
73+
REGISTER_WEAK_OPTNONE static int register_weak_##local_function() { \
74+
if ((uintptr_t) & local_function != (uintptr_t) & \
75+
WEAK_EXPORT_NAME(local_function)) { \
76+
return __sanitizer::register_weak( \
77+
SANITIZER_STRINGIFY(WEAK_EXPORT_NAME(local_function)), \
78+
reinterpret_cast<__sanitizer::uptr>(local_function)); \
79+
} \
80+
return 0; \
81+
} \
82+
__pragma(section(".WEAK$M", long, read)) __declspec(allocate( \
83+
".WEAK$M")) int (*__sanitizer_register_weak_##local_function)() = \
7984
register_weak_##local_function;
80-
8185
#endif // SANITIZER_WIN_STATIC_RUNTIME_THUNK_H

0 commit comments

Comments
 (0)