Skip to content

[ASan][test] Fix TestCases/Posix/stack-overflow.cpp on Solaris/sparcv9 #109101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ extern struct ps_strings *__ps_strings;
# endif // SANITIZER_NETBSD

# if SANITIZER_SOLARIS
# include <stddef.h>
# include <stdlib.h>
# include <sys/frame.h>
# include <thread.h>
# define environ _environ
# endif
Expand Down Expand Up @@ -2617,7 +2619,19 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
# if SANITIZER_SOLARIS
ucontext_t *ucontext = (ucontext_t *)context;
*pc = ucontext->uc_mcontext.gregs[REG_PC];
*sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
*sp = ucontext->uc_mcontext.gregs[REG_SP] + STACK_BIAS;
// Avoid SEGV when dereferencing sp on stack overflow with non-faulting load.
// This requires a SPARC V9 CPU. Cannot use #ASI_PNF here: only supported
// since clang-19.
# if defined(__sparcv9)
asm("ldxa [%[fp]] 0x82, %[bp]"
# else
asm("lduwa [%[fp]] 0x82, %[bp]"
# endif
: [bp] "=r"(*bp)
: [fp] "r"(&((struct frame *)*sp)->fr_savfp));
if (*bp)
*bp += STACK_BIAS;
# else
// Historical BSDism here.
struct sigcontext *scontext = (struct sigcontext *)context;
Expand All @@ -2628,8 +2642,8 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
*pc = scontext->si_regs.pc;
*sp = scontext->si_regs.u_regs[14];
# endif
# endif
*bp = (uptr)((uhwptr *)*sp)[14] + STACK_BIAS;
# endif
# elif defined(__mips__)
ucontext_t *ucontext = (ucontext_t *)context;
*pc = ucontext->uc_mcontext.pc;
Expand Down
15 changes: 9 additions & 6 deletions compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ static void ReportStackOverflowImpl(const SignalContext &sig, u32 tid,
SanitizerToolName, kDescription, (void *)sig.addr, (void *)sig.pc,
(void *)sig.bp, (void *)sig.sp, tid);
Printf("%s", d.Default());
InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
unwind(sig, unwind_context, stack);
stack->Print();
ReportErrorSummary(kDescription, stack);
// Avoid SEGVs in the unwinder when bp couldn't be determined.
if (sig.bp) {
InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
unwind(sig, unwind_context, stack);
stack->Print();
ReportErrorSummary(kDescription, stack);
}
}

static void ReportDeadlySignalImpl(const SignalContext &sig, u32 tid,
Expand Down
Loading