Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0c82e7b authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Use elf offset in signal step check.

The function StepIfSignalHandler assumed that the rel_pc passed
to it was actually an elf offset. A new version of clang created a libc.so
that has a load bias, so tests unwinding through a signal handler
would fail on arm. On other ABIs, there is unwind information that could
be used instead, so the unwind still worked.

The fix is to subtract the load bias from the rel_pc to get an elf
offset to pass to the Register StepIfSignalHandler functions. Change all
of the Register funtions to make it clear what the first parameter means.

Add a unit test for this new code. Also, add an offline test for
this case.

Bug: 145683525

Test: Ran unit tests using the new clang and the old clang.
Change-Id: I3e249653b79bcad6d3a56411a7911fde4888e9d6
parent f7a6c458
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@ cc_defaults {
        "tests/files/offline/shared_lib_in_apk_arm64/*",
        "tests/files/offline/shared_lib_in_apk_memory_only_arm64/*",
        "tests/files/offline/shared_lib_in_apk_single_map_arm64/*",
        "tests/files/offline/signal_load_bias_arm/*",
        "tests/files/offline/straddle_arm/*",
        "tests/files/offline/straddle_arm64/*",
    ],
+6 −1
Original line number Diff line number Diff line
@@ -173,7 +173,12 @@ bool Elf::StepIfSignalHandler(uint64_t rel_pc, Regs* regs, Memory* process_memor
  if (!valid_) {
    return false;
  }
  return regs->StepIfSignalHandler(rel_pc, this, process_memory);

  // Convert the rel_pc to an elf_offset.
  if (rel_pc < static_cast<uint64_t>(load_bias_)) {
    return false;
  }
  return regs->StepIfSignalHandler(rel_pc - load_bias_, this, process_memory);
}

// The relative pc is always relative to the start of the map from which it comes.
+2 −2
Original line number Diff line number Diff line
@@ -127,12 +127,12 @@ Regs* RegsArm::CreateFromUcontext(void* ucontext) {
  return regs;
}

bool RegsArm::StepIfSignalHandler(uint64_t rel_pc, Elf* elf, Memory* process_memory) {
bool RegsArm::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
  uint32_t data;
  Memory* elf_memory = elf->memory();
  // Read from elf memory since it is usually more expensive to read from
  // process memory.
  if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
  if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
    return false;
  }

+2 −2
Original line number Diff line number Diff line
@@ -126,12 +126,12 @@ Regs* RegsArm64::CreateFromUcontext(void* ucontext) {
  return regs;
}

bool RegsArm64::StepIfSignalHandler(uint64_t rel_pc, Elf* elf, Memory* process_memory) {
bool RegsArm64::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
  uint64_t data;
  Memory* elf_memory = elf->memory();
  // Read from elf memory since it is usually more expensive to read from
  // process memory.
  if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
  if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
    return false;
  }

+2 −2
Original line number Diff line number Diff line
@@ -129,13 +129,13 @@ Regs* RegsMips::CreateFromUcontext(void* ucontext) {
  return regs;
}

bool RegsMips::StepIfSignalHandler(uint64_t rel_pc, Elf* elf, Memory* process_memory) {
bool RegsMips::StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) {
  uint64_t data;
  uint64_t offset = 0;
  Memory* elf_memory = elf->memory();
  // Read from elf memory since it is usually more expensive to read from
  // process memory.
  if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
  if (!elf_memory->ReadFully(elf_offset, &data, sizeof(data))) {
    return false;
  }

Loading