Skip to content

Commit 4a264c5

Browse files
authored
[sanitizer_common] Fix GetArgsAndEnv on Linux/sparc64 (#109109)
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`.
1 parent 3907d18 commit 4a264c5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@ static void GetArgsAndEnv(char ***argv, char ***envp) {
727727
# if !SANITIZER_GO
728728
if (&__libc_stack_end) {
729729
uptr *stack_end = (uptr *)__libc_stack_end;
730+
// Linux/sparc64 needs an adjustment, cf. glibc
731+
// sysdeps/sparc/sparc{32,64}/dl-machine.h (DL_STACK_END).
732+
# if SANITIZER_LINUX && defined(__sparc__)
733+
stack_end = &stack_end[16];
734+
# endif
730735
// Normally argc can be obtained from *stack_end, however, on ARM glibc's
731736
// _start clobbers it:
732737
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/start.S;hb=refs/heads/release/2.31/master#l75

0 commit comments

Comments
 (0)