[compiler-rt] bd5b775 - __asan_register_elf_globals: properly check the "no instrumented global variable" case
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 13:14:41 PDT 2024
Author: Fangrui Song
Date: 2024-06-25T13:14:39-07:00
New Revision: bd5b77529f07d21c27cf14009845e319e454867d
URL: https://github.com/llvm/llvm-project/commit/bd5b77529f07d21c27cf14009845e319e454867d
DIFF: https://github.com/llvm/llvm-project/commit/bd5b77529f07d21c27cf14009845e319e454867d.diff
LOG: __asan_register_elf_globals: properly check the "no instrumented global variable" case
On ELF platforms, the instrumentation registers global variables using
`__asan_register_elf_globals` for the default `UseGlobalsGC` case. If
all instrumented global variables in a module are discarded by linker
GC, we will have `start == stop`.
Normally `start == 0`, but `start != 0` is possible with a linker script
retaining `asan_globals`. The called `__asan_register_globals` would
access out-of-bounds `globals[n-1]`, though there is likely no runtime
failure.
Pull Request: https://github.com/llvm/llvm-project/pull/96529
Added:
Modified:
compiler-rt/lib/asan/asan_globals.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_globals.cpp b/compiler-rt/lib/asan/asan_globals.cpp
index 6ac64c4b776bb..d413b1ebc9fc0 100644
--- a/compiler-rt/lib/asan/asan_globals.cpp
+++ b/compiler-rt/lib/asan/asan_globals.cpp
@@ -344,8 +344,8 @@ void __asan_unregister_image_globals(uptr *flag) {
}
void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
- if (*flag) return;
- if (!start) return;
+ if (*flag || start == stop)
+ return;
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
__asan_global *globals_start = (__asan_global*)start;
__asan_global *globals_stop = (__asan_global*)stop;
@@ -354,8 +354,8 @@ void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
}
void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
- if (!*flag) return;
- if (!start) return;
+ if (!*flag || start == stop)
+ return;
CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
__asan_global *globals_start = (__asan_global*)start;
__asan_global *globals_stop = (__asan_global*)stop;
More information about the llvm-commits
mailing list