[compiler-rt] [asan][windows] use __builtin_function_address to avoid problematic codegen in weak function registration (PR #108327)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 21:13:42 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Charlie Barto (barcharcraz)
<details>
<summary>Changes</summary>
Previously we were relying on optnone for this, but that didn't seem to be sufficient.
---
Full diff: https://github.com/llvm/llvm-project/pull/108327.diff
1 Files Affected:
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h (+3-2)
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h b/compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h
index fa7b18fdc18f6d..80c56f8f3c9d0f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_win_thunk_interception.h
@@ -62,8 +62,10 @@ 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) \
@@ -71,8 +73,7 @@ void initialize_thunks(const sanitizer_thunk *begin,
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)); \
``````````
</details>
https://github.com/llvm/llvm-project/pull/108327
More information about the llvm-commits
mailing list