[compiler-rt] [sanitizer_common] Fix GetArgsAndEnv on Linux/sparc64 (PR #109109)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 02:25:23 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Rainer Orth (rorth)
<details>
<summary>Changes</summary>
When ASan testing is enabled on SPARC as per PR #<!-- -->107405, the
```
AddressSanitizer-sparc-linux :: TestCases/Posix/print_cmdline.cpp
```
test `FAIL`s. Either `ASAN_OPTIONS=print_cmdline=true` yielded binary garbage in the `Command:` output or just an empty string.
It turns out one needs to apply an offset to `__libc_stack_end` to get at the actual `argc`/`argv`, as described in `glibc`'s `sysdeps/sparc/sparc{32,64}/dl-machine.h` (`DL_STACK_END`).
This patch does this, fixing the test.
Tested on `sparc64-unknown-linux-gnu`.
---
Full diff: https://github.com/llvm/llvm-project/pull/109109.diff
1 Files Affected:
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+5)
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 6359f4348e3c48..2faba3353d13dc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -725,6 +725,11 @@ static void GetArgsAndEnv(char ***argv, char ***envp) {
# if !SANITIZER_GO
if (&__libc_stack_end) {
uptr *stack_end = (uptr *)__libc_stack_end;
+ // Linux/sparc64 needs an adjustment, cf. glibc
+ // sysdeps/sparc/sparc{32,64}/dl-machine.h (DL_STACK_END).
+# if SANITIZER_LINUX && defined(__sparc__)
+ stack_end = &stack_end[16];
+# endif
// Normally argc can be obtained from *stack_end, however, on ARM glibc's
// _start clobbers it:
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/start.S;hb=refs/heads/release/2.31/master#l75
``````````
</details>
https://github.com/llvm/llvm-project/pull/109109
More information about the llvm-commits
mailing list