Skip to content

Commit 9ca3553

Browse files
committed
Hail mary stack unwwind for ARM
On ARM, if we have no CFI, and no other option, we can just look at the link register, and replace the instruction pointer with it. Unlike on 32- and 64-bit intel platforms, it appears that the linux aarch64 toolchain will not generate FDE data for PLT entries - this means we need this for the case that a process happens to be in a PLT entry when we take a backtrace.
1 parent c0467ce commit 9ca3553

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

libpstack/proc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ enum class UnwindMechanism {
6666
// The stack frame was built up by scanning a log file.
6767
LOGFILE,
6868

69+
// For ARM - last-ditch effort - link register
70+
LINKREG,
71+
6972
INVALID,
7073
};
7174

process.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ std::ostream &operator << (std::ostream &os, UnwindMechanism mech) {
674674
case UnwindMechanism::BAD_IP_RECOVERY: return os << "popped faulting IP";
675675
case UnwindMechanism::TRAMPOLINE: return os << "signal trampoline";
676676
case UnwindMechanism::LOGFILE: return os << "log file";
677+
case UnwindMechanism::LINKREG: return os << "link register";
677678
case UnwindMechanism::INVALID: return os << "invalid";
678679
}
679680
abort();
@@ -1067,6 +1068,15 @@ ThreadStack::unwind(Process &p, Elf::CoreRegisters &regs)
10671068
stack.emplace_back(UnwindMechanism::TRAMPOLINE, newRegs);
10681069
continue;
10691070
}
1071+
// last ditch effort for ARM is to just replace the PC with the
1072+
// LR - this is useful for PLT entries, for example.
1073+
if (prev.regs.regs[30] != prev.regs.pc) {
1074+
Elf::CoreRegisters newRegs = prev.regs;
1075+
newRegs.pc = newRegs.regs[30];
1076+
stack.emplace_back(UnwindMechanism::LINKREG, newRegs);
1077+
continue;
1078+
}
1079+
10701080
#endif
10711081
#if defined(__i386__)
10721082
// Deal with signal trampolines for i386

0 commit comments

Comments
 (0)