Skip to content

Commit ed586ac

Browse files
authored
Revert "[libunwind] Fix execution flow imbalance when using C++ Exceptions (#…"
This reverts commit cf35502.
1 parent 36c1273 commit ed586ac

File tree

12 files changed

+19
-396
lines changed

12 files changed

+19
-396
lines changed

libunwind/src/Registers.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,9 +1832,8 @@ inline const char *Registers_ppc64::getRegisterName(int regNum) {
18321832
/// Registers_arm64 holds the register state of a thread in a 64-bit arm
18331833
/// process.
18341834
class _LIBUNWIND_HIDDEN Registers_arm64;
1835+
extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
18351836
extern "C" int64_t __libunwind_Registers_arm64_za_disable();
1836-
extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *,
1837-
unsigned walkedFrames);
18381837

18391838
#if defined(_LIBUNWIND_USE_GCS)
18401839
extern "C" void *__libunwind_shstk_get_jump_target() {
@@ -1862,17 +1861,10 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18621861
v128 getVectorRegister(int num) const;
18631862
void setVectorRegister(int num, v128 value);
18641863
static const char *getRegisterName(int num);
1865-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
1866-
_LIBUNWIND_TRACE_NO_INLINE
1867-
void returnto(unsigned walkedFrames) {
1868-
__libunwind_Registers_arm64_jumpto(this, walkedFrames);
1869-
}
1870-
#else
1871-
void jumpto() {
1872-
zaDisable();
1873-
__libunwind_Registers_arm64_jumpto(this, 0);
1864+
void jumpto() {
1865+
zaDisable();
1866+
__libunwind_Registers_arm64_jumpto(this);
18741867
}
1875-
#endif
18761868
static constexpr int lastDwarfRegNum() {
18771869
return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64;
18781870
}

libunwind/src/UnwindCursor.hpp

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,7 @@ class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
472472
virtual void getInfo(unw_proc_info_t *) {
473473
_LIBUNWIND_ABORT("getInfo not implemented");
474474
}
475-
_LIBUNWIND_TRACE_NO_INLINE virtual void jumpto() {
476-
_LIBUNWIND_ABORT("jumpto not implemented");
477-
}
475+
virtual void jumpto() { _LIBUNWIND_ABORT("jumpto not implemented"); }
478476
virtual bool isSignalFrame() {
479477
_LIBUNWIND_ABORT("isSignalFrame not implemented");
480478
}
@@ -491,12 +489,6 @@ class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
491489
virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }
492490
#endif
493491

494-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
495-
virtual void setWalkedFrames(unsigned) {
496-
_LIBUNWIND_ABORT("setWalkedFrames not implemented");
497-
}
498-
#endif
499-
500492
#ifdef _AIX
501493
virtual uintptr_t getDataRelBase() {
502494
_LIBUNWIND_ABORT("getDataRelBase not implemented");
@@ -973,8 +965,7 @@ class UnwindCursor : public AbstractUnwindCursor{
973965
virtual void setFloatReg(int, unw_fpreg_t);
974966
virtual int step(bool stage2 = false);
975967
virtual void getInfo(unw_proc_info_t *);
976-
_LIBUNWIND_TRACE_NO_INLINE
977-
virtual void jumpto();
968+
virtual void jumpto();
978969
virtual bool isSignalFrame();
979970
virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
980971
virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
@@ -983,10 +974,6 @@ class UnwindCursor : public AbstractUnwindCursor{
983974
virtual void saveVFPAsX();
984975
#endif
985976

986-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
987-
virtual void setWalkedFrames(unsigned);
988-
#endif
989-
990977
#ifdef _AIX
991978
virtual uintptr_t getDataRelBase();
992979
#endif
@@ -1369,9 +1356,6 @@ class UnwindCursor : public AbstractUnwindCursor{
13691356
defined(_LIBUNWIND_TARGET_HAIKU)
13701357
bool _isSigReturn = false;
13711358
#endif
1372-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
1373-
uint32_t _walkedFrames;
1374-
#endif
13751359
};
13761360

13771361

@@ -1426,46 +1410,7 @@ void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
14261410
}
14271411

14281412
template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
1429-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
1430-
/*
1431-
1432-
The value of `_walkedFrames` is computed in `unwind_phase2` and represents the
1433-
number of frames walked starting `unwind_phase2` to get to the landing pad.
1434-
1435-
```
1436-
// uc is initialized by __unw_getcontext in the parent frame.
1437-
// The first stack frame walked is unwind_phase2.
1438-
unsigned framesWalked = 1;
1439-
```
1440-
1441-
To that, we need to add the number of function calls in libunwind between
1442-
`unwind_phase2` & `__libunwind_Registers_arm64_jumpto` which performs the long
1443-
jump, to rebalance the execution flow.
1444-
1445-
```
1446-
frame #0: libunwind.1.dylib`__libunwind_Registers_arm64_jumpto at UnwindRegistersRestore.S:646
1447-
frame #1: libunwind.1.dylib`libunwind::Registers_arm64::returnto at Registers.hpp:2291:3
1448-
frame #2: libunwind.1.dylib`libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>::jumpto at UnwindCursor.hpp:1474:14
1449-
frame #3: libunwind.1.dylib`__unw_resume at libunwind.cpp:375:7
1450-
frame #4: libunwind.1.dylib`__unw_resume_with_frames_walked at libunwind.cpp:363:10
1451-
frame #5: libunwind.1.dylib`unwind_phase2 at UnwindLevel1.c:328:9
1452-
frame #6: libunwind.1.dylib`_Unwind_RaiseException at UnwindLevel1.c:480:10
1453-
frame #7: libc++abi.dylib`__cxa_throw at cxa_exception.cpp:295:5
1454-
...
1455-
```
1456-
1457-
If we look at the backtrace from `__libunwind_Registers_arm64_jumpto`, we see
1458-
there are 5 frames on the stack to reach `unwind_phase2`. However, only 4 of
1459-
them will never return, since `__libunwind_Registers_arm64_jumpto` returns
1460-
back to the landing pad, so we need to subtract 1 to the number of
1461-
`_EXTRA_LIBUNWIND_FRAMES_WALKED`.
1462-
*/
1463-
1464-
static constexpr size_t _EXTRA_LIBUNWIND_FRAMES_WALKED = 5 - 1;
1465-
_registers.returnto(_walkedFrames + _EXTRA_LIBUNWIND_FRAMES_WALKED);
1466-
#else
14671413
_registers.jumpto();
1468-
#endif
14691414
}
14701415

14711416
#ifdef __arm__
@@ -1474,13 +1419,6 @@ template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {
14741419
}
14751420
#endif
14761421

1477-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
1478-
template <typename A, typename R>
1479-
void UnwindCursor<A, R>::setWalkedFrames(unsigned walkedFrames) {
1480-
_walkedFrames = walkedFrames;
1481-
}
1482-
#endif
1483-
14841422
#ifdef _AIX
14851423
template <typename A, typename R>
14861424
uintptr_t UnwindCursor<A, R>::getDataRelBase() {

libunwind/src/UnwindLevel1.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
// avoided when invoking the `jumpto()` function. To do this, we use inline
4949
// assemblies to "goto" the `jumpto()` for these architectures.
5050
#if !defined(_LIBUNWIND_USE_CET) && !defined(_LIBUNWIND_USE_GCS)
51-
#define __unw_phase2_resume(cursor, payload) \
51+
#define __unw_phase2_resume(cursor, fn) \
5252
do { \
53-
__unw_resume_with_frames_walked((cursor), (payload)); \
53+
(void)fn; \
54+
__unw_resume((cursor)); \
5455
} while (0)
5556
#elif defined(_LIBUNWIND_TARGET_I386)
5657
#define __shstk_step_size (4)
57-
#define __unw_phase2_resume(cursor, payload) \
58+
#define __unw_phase2_resume(cursor, fn) \
5859
do { \
59-
_LIBUNWIND_POP_SHSTK_SSP((payload)); \
60+
_LIBUNWIND_POP_SHSTK_SSP((fn)); \
6061
void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \
6162
void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \
6263
__asm__ volatile("push %%edi\n\t" \
@@ -66,27 +67,26 @@
6667
} while (0)
6768
#elif defined(_LIBUNWIND_TARGET_X86_64)
6869
#define __shstk_step_size (8)
69-
#define __unw_phase2_resume(cursor, payload) \
70+
#define __unw_phase2_resume(cursor, fn) \
7071
do { \
71-
_LIBUNWIND_POP_SHSTK_SSP((payload)); \
72+
_LIBUNWIND_POP_SHSTK_SSP((fn)); \
7273
void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \
7374
void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \
7475
__asm__ volatile("jmpq *%%rdx\n\t" ::"D"(shstkRegContext), \
7576
"d"(shstkJumpAddress)); \
7677
} while (0)
7778
#elif defined(_LIBUNWIND_TARGET_AARCH64)
7879
#define __shstk_step_size (8)
79-
#define __unw_phase2_resume(cursor, payload) \
80+
#define __unw_phase2_resume(cursor, fn) \
8081
do { \
81-
_LIBUNWIND_POP_SHSTK_SSP((payload)); \
82+
_LIBUNWIND_POP_SHSTK_SSP((fn)); \
8283
void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \
8384
void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \
8485
__asm__ volatile("mov x0, %0\n\t" \
85-
"mov x1, wzr\n\t" \
8686
"br %1\n\t" \
8787
: \
8888
: "r"(shstkRegContext), "r"(shstkJumpAddress) \
89-
: "x0", "x1"); \
89+
: "x0"); \
9090
} while (0)
9191
#endif
9292

@@ -205,8 +205,6 @@ extern int __unw_step_stage2(unw_cursor_t *);
205205
#if defined(_LIBUNWIND_USE_GCS)
206206
// Enable the GCS target feature to permit gcspop instructions to be used.
207207
__attribute__((target("+gcs")))
208-
#else
209-
_LIBUNWIND_TRACE_NO_INLINE
210208
#endif
211209
static _Unwind_Reason_Code
212210
unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor,
@@ -351,8 +349,6 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor,
351349
#if defined(_LIBUNWIND_USE_GCS)
352350
// Enable the GCS target feature to permit gcspop instructions to be used.
353351
__attribute__((target("+gcs")))
354-
#else
355-
_LIBUNWIND_TRACE_NO_INLINE
356352
#endif
357353
static _Unwind_Reason_Code
358354
unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,

libunwind/src/UnwindRegistersRestore.S

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -645,26 +645,13 @@ Lnovec:
645645
#endif
646646

647647
//
648-
// extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *, unsigned);
648+
// extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
649649
//
650650
// On entry:
651651
// thread_state pointer is in x0
652-
// walked_frames counter is in x1
653652
//
654653
.p2align 2
655654
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
656-
657-
#if defined(_LIBUNWIND_TRACE_RET_INJECT)
658-
cbz w1, 1f
659-
0:
660-
subs w1, w1, #1
661-
adr x16, #8
662-
ret x16
663-
664-
b.ne 0b
665-
1:
666-
#endif
667-
668655
// skip restore of x0,x1 for now
669656
ldp x2, x3, [x0, #0x010]
670657
ldp x4, x5, [x0, #0x020]

libunwind/src/assembly.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@
132132

133133
#if defined(__APPLE__)
134134

135-
#if defined(__aarch64__) || defined(__arm64__) || defined(__arm64e__)
136-
#define _LIBUNWIND_TRACE_RET_INJECT 1
137-
#endif
138-
139135
#define SYMBOL_IS_FUNC(name)
140136
#define HIDDEN_SYMBOL(name) .private_extern name
141137
#if defined(_LIBUNWIND_HIDE_SYMBOLS)

libunwind/src/config.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
2929
#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
3030
#endif
31-
#if defined(__aarch64__) || defined(__arm64__) || defined(__arm64e__)
32-
#define _LIBUNWIND_TRACE_RET_INJECT 1
33-
#endif
3431
#elif defined(_WIN32)
3532
#ifdef __SEH__
3633
#define _LIBUNWIND_SUPPORT_SEH_UNWIND 1
@@ -64,12 +61,6 @@
6461
#endif
6562
#endif
6663

67-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
68-
#define _LIBUNWIND_TRACE_NO_INLINE __attribute__((noinline, disable_tail_calls))
69-
#else
70-
#define _LIBUNWIND_TRACE_NO_INLINE
71-
#endif
72-
7364
#if defined(_LIBUNWIND_HIDE_SYMBOLS)
7465
// The CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility.
7566
#define _LIBUNWIND_EXPORT

libunwind/src/libunwind.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,7 @@ _LIBUNWIND_HIDDEN int __unw_get_proc_info(unw_cursor_t *cursor,
247247
}
248248
_LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info)
249249

250-
/// Rebalance the execution flow by injecting the right amount of `ret`
251-
/// instruction relatively to the amount of `walkedFrames` then resume execution
252-
/// at cursor position (aka longjump).
253-
_LIBUNWIND_HIDDEN int __unw_resume_with_frames_walked(unw_cursor_t *cursor,
254-
unsigned walkedFrames) {
255-
_LIBUNWIND_TRACE_API("__unw_resume(cursor=%p, walkedFrames=%u)",
256-
static_cast<void *>(cursor), walkedFrames);
257-
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
258-
// Inform the ASan runtime that now might be a good time to clean stuff up.
259-
__asan_handle_no_return();
260-
#endif
261-
#ifdef _LIBUNWIND_TRACE_RET_INJECT
262-
AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
263-
co->setWalkedFrames(walkedFrames);
264-
#endif
265-
return __unw_resume(cursor);
266-
}
267-
_LIBUNWIND_WEAK_ALIAS(__unw_resume_with_frames_walked,
268-
unw_resume_with_frames_walked)
269-
270-
/// Legacy function. Resume execution at cursor position (aka longjump).
250+
/// Resume execution at cursor position (aka longjump).
271251
_LIBUNWIND_HIDDEN int __unw_resume(unw_cursor_t *cursor) {
272252
_LIBUNWIND_TRACE_API("__unw_resume(cursor=%p)", static_cast<void *>(cursor));
273253
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)

libunwind/src/libunwind_ext.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ extern int __unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *);
3030
extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *);
3131
extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t);
3232
extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t);
33-
_LIBUNWIND_TRACE_NO_INLINE
34-
extern int __unw_resume_with_frames_walked(unw_cursor_t *, unsigned);
35-
// `__unw_resume` is a legacy function. Use `__unw_resume_with_frames_walked` instead.
36-
_LIBUNWIND_TRACE_NO_INLINE
37-
extern int __unw_resume(unw_cursor_t *);
33+
extern int __unw_resume(unw_cursor_t *);
3834

3935
#ifdef __arm__
4036
/* Save VFP registers in FSTMX format (instead of FSTMD). */

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -647,31 +647,6 @@ def is_out_of_tree_debugserver():
647647
return skipTestIfFn(is_out_of_tree_debugserver)(func)
648648

649649

650-
def skipIfOutOfTreeLibunwind(func):
651-
"""Decorate the item to skip tests if libunwind was not built in-tree."""
652-
653-
def is_out_of_tree_libunwind():
654-
if not configuration.llvm_tools_dir:
655-
return "out-of-tree libunwind"
656-
657-
# llvm_tools_dir is typically <build>/bin, so lib is a sibling.
658-
llvm_lib_dir = os.path.join(
659-
os.path.dirname(configuration.llvm_tools_dir), "lib"
660-
)
661-
662-
if not os.path.isdir(llvm_lib_dir):
663-
return "out-of-tree libunwind"
664-
665-
# Check for libunwind library (any extension).
666-
for filename in os.listdir(llvm_lib_dir):
667-
if filename.startswith("libunwind.") or filename.startswith("unwind."):
668-
return None
669-
670-
return "out-of-tree libunwind"
671-
672-
return skipTestIfFn(is_out_of_tree_libunwind)(func)
673-
674-
675650
def skipIfRemote(func):
676651
"""Decorate the item to skip tests if testing remotely."""
677652
return unittest.skipIf(lldb.remote_platform, "skip on remote platform")(func)

lldb/test/API/functionalities/unwind/libunwind_ret_injection/Makefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)