[sanitizer_common] Fix GetArgsAndEnv on Linux/sparc64#109109
Merged
Conversation
When ASan testing is enabled on SPARC as per PR llvm#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`.
Member
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Rainer Orth (rorth) ChangesWhen ASan testing is enabled on SPARC as per PR #107405, the test It turns out one needs to apply an offset to This patch does this, fixing the test. Tested on Full diff: https://github.com/llvm/llvm-project/pull/109109.diff 1 Files Affected:
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
|
vitalybuka
approved these changes
Sep 24, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When ASan testing is enabled on SPARC as per PR #107405, the
test
FAILs. EitherASAN_OPTIONS=print_cmdline=trueyielded binary garbage in theCommand:output or just an empty string.It turns out one needs to apply an offset to
__libc_stack_endto get at the actualargc/argv, as described inglibc'ssysdeps/sparc/sparc{32,64}/dl-machine.h(DL_STACK_END).This patch does this, fixing the test.
Tested on
sparc64-unknown-linux-gnu.