Skip to content

[asan][windows] use __builtin_function_address to avoid problematic codegen in weak function registration #108327

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ void initialize_thunks(const sanitizer_thunk *begin,
// startup that will replace sanitizer_export with local_function
#ifdef __clang__
# define REGISTER_WEAK_OPTNONE __attribute__((optnone))
# define REGISTER_WEAK_FUNCTION_ADDRESS(fn) __builtin_function_start(fn)
#else
# define REGISTER_WEAK_OPTNONE
# define REGISTER_WEAK_FUNCTION_ADDRESS(fn) &fn
#endif

#define REGISTER_WEAK_FUNCTION(local_function) \
extern "C" void local_function(); \
extern "C" void WEAK_EXPORT_NAME(local_function)(); \
WIN_WEAK_IMPORT_DEF(local_function) \
REGISTER_WEAK_OPTNONE static int register_weak_##local_function() { \
if ((uintptr_t) & local_function != (uintptr_t) & \
WEAK_EXPORT_NAME(local_function)) { \
if ((uintptr_t)REGISTER_WEAK_FUNCTION_ADDRESS(local_function) != \
(uintptr_t)REGISTER_WEAK_FUNCTION_ADDRESS( \
WEAK_EXPORT_NAME(local_function))) { \
return __sanitizer::register_weak( \
SANITIZER_STRINGIFY(WEAK_EXPORT_NAME(local_function)), \
reinterpret_cast<__sanitizer::uptr>(local_function)); \
Expand Down
Loading