Skip to content

Commit

Permalink
[compiler-rt] Require glibc for DumpAllRegisters on Linux (llvm#101131)
Browse files Browse the repository at this point in the history
For example musl doesn't provide REG_R* definitions for ARM

llvm#100398
  • Loading branch information
chestnykh committed Jul 30, 2024
1 parent 3fcc4f2 commit 28f9575
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ bool SignalContext::IsTrueFaultingAddress() const {
UNUSED
static const char *RegNumToRegName(int reg) {
switch (reg) {
# if SANITIZER_LINUX
# if SANITIZER_LINUX && SANITIZER_GLIBC
# if defined(__x86_64__)
case REG_RAX:
return "rax";
Expand Down Expand Up @@ -2240,14 +2240,15 @@ static const char *RegNumToRegName(int reg) {
case 31:
return "sp";
# endif
# endif // SANITIZER_LINUX
# endif // SANITIZER_LINUX && SANITIZER_GLIBC
default:
return NULL;
}
return NULL;
}

# if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__))
# if SANITIZER_LINUX && SANITIZER_GLIBC && \
(defined(__arm__) || defined(__aarch64__))
static uptr GetArmRegister(ucontext_t *ctx, int RegNum) {
switch (RegNum) {
# if defined(__arm__)
Expand Down Expand Up @@ -2289,7 +2290,8 @@ static uptr GetArmRegister(ucontext_t *ctx, int RegNum) {
}
return 0;
}
# endif // SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__))
# endif // SANITIZER_LINUX && SANITIZER_GLIBC && (defined(__arm__) ||
// defined(__aarch64__))

UNUSED
static void DumpSingleReg(ucontext_t *ctx, int RegNum) {
Expand All @@ -2312,7 +2314,7 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) {

void SignalContext::DumpAllRegisters(void *context) {
ucontext_t *ucontext = (ucontext_t *)context;
# if SANITIZER_LINUX
# if SANITIZER_LINUX && SANITIZER_GLIBC
# if defined(__x86_64__)
Report("Register values:\n");
DumpSingleReg(ucontext, REG_RAX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP
// RUN: not %run %t 2>&1 | FileCheck %s --strict-whitespace --check-prefix=CHECK-DUMP
//
// REQUIRES: aarch64-target-arch
// REQUIRES: aarch64-target-arch && glibc

#include <signal.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP
// RUN: not %run %t 2>&1 | FileCheck %s --strict-whitespace --check-prefix=CHECK-DUMP
//
// REQUIRES: arm-target-arch
// REQUIRES: arm-target-arch && glibc

#include <signal.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NODUMP --strict-whitespace
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-DUMP --strict-whitespace
//
// REQUIRES: i386-target-arch
// REQUIRES: i386-target-arch && glibc

#include <signal.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NODUMP --strict-whitespace
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-DUMP --strict-whitespace
//
// REQUIRES: x86_64-target-arch
// REQUIRES: x86_64-target-arch && glibc

#include <signal.h>

Expand Down

0 comments on commit 28f9575

Please sign in to comment.