Skip to content

Commit 161445b

Browse files
committed
use __builtin_function_address to avoid problematic UB induced codegen in asan weak function registration
1 parent 8287831 commit 161445b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ void initialize_thunks(const sanitizer_thunk *begin,
6262
// startup that will replace sanitizer_export with local_function
6363
#ifdef __clang__
6464
# define REGISTER_WEAK_OPTNONE __attribute__((optnone))
65+
# define REGISTER_WEAK_FUNCTION_ADDRESS(fn) __builtin_function_start(fn)
6566
#else
6667
# define REGISTER_WEAK_OPTNONE
68+
# define REGISTER_WEAK_FUNCTION_ADDRESS(fn) &fn
6769
#endif
6870

6971
#define REGISTER_WEAK_FUNCTION(local_function) \
7072
extern "C" void local_function(); \
7173
extern "C" void WEAK_EXPORT_NAME(local_function)(); \
7274
WIN_WEAK_IMPORT_DEF(local_function) \
7375
REGISTER_WEAK_OPTNONE static int register_weak_##local_function() { \
74-
if ((uintptr_t) & local_function != (uintptr_t) & \
75-
WEAK_EXPORT_NAME(local_function)) { \
76+
if ((uintptr_t)REGISTER_WEAK_FUNCTION_ADDRESS(local_function) != \
77+
(uintptr_t)REGISTER_WEAK_FUNCTION_ADDRESS( \
78+
WEAK_EXPORT_NAME(local_function))) { \
7679
return __sanitizer::register_weak( \
7780
SANITIZER_STRINGIFY(WEAK_EXPORT_NAME(local_function)), \
7881
reinterpret_cast<__sanitizer::uptr>(local_function)); \

0 commit comments

Comments
 (0)