Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit aa805e4

Browse files
committed
X86: swap EBP, ESP on !APPLE
Restore the `libunwind.h` enumeration values back to the inverted values. This diverges from the DWARF definition of the register values. However, this allows our header to be compatible with other unwind implementations (e.g. HP, GNU Savannah, GCC). The register IDs are only swapped in the header and need to be unswapped when accessing the unwind register file. The flipped EBP and ESP only applies on non-Apple x86 targets. When optimizations were enabled, EBP and ESP would no longer be equivalent. As a result, the incorrect access on Linux would manifest as a failure to unwind the stack. We can now unwind the stack with and without FPO on Linux x86. Resolves PR30879! git-svn-id: https://llvm.org/svn/llvm-project/libunwind/trunk@292723 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e1d4b2e commit aa805e4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

include/libunwind.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,8 @@ enum {
165165
UNW_X86_ECX = 1,
166166
UNW_X86_EDX = 2,
167167
UNW_X86_EBX = 3,
168-
#if defined(__CloudABI__) || defined(__FreeBSD__)
169-
UNW_X86_ESP = 4,
170-
UNW_X86_EBP = 5,
171-
#else
172168
UNW_X86_EBP = 4,
173169
UNW_X86_ESP = 5,
174-
#endif
175170
UNW_X86_ESI = 6,
176171
UNW_X86_EDI = 7
177172
};

src/Registers.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,17 @@ inline uint32_t Registers_x86::getRegister(int regNum) const {
122122
return _registers.__edx;
123123
case UNW_X86_EBX:
124124
return _registers.__ebx;
125+
#if !defined(__APPLE__)
126+
case UNW_X86_ESP:
127+
#else
125128
case UNW_X86_EBP:
129+
#endif
126130
return _registers.__ebp;
131+
#if !defined(__APPLE__)
132+
case UNW_X86_EBP:
133+
#else
127134
case UNW_X86_ESP:
135+
#endif
128136
return _registers.__esp;
129137
case UNW_X86_ESI:
130138
return _registers.__esi;
@@ -154,10 +162,18 @@ inline void Registers_x86::setRegister(int regNum, uint32_t value) {
154162
case UNW_X86_EBX:
155163
_registers.__ebx = value;
156164
return;
165+
#if !defined(__APPLE__)
166+
case UNW_X86_ESP:
167+
#else
157168
case UNW_X86_EBP:
169+
#endif
158170
_registers.__ebp = value;
159171
return;
172+
#if !defined(__APPLE__)
173+
case UNW_X86_EBP:
174+
#else
160175
case UNW_X86_ESP:
176+
#endif
161177
_registers.__esp = value;
162178
return;
163179
case UNW_X86_ESI:

0 commit comments

Comments
 (0)