Skip to content

Commit 66e03db

Browse files
committedOct 28, 2021
Revert "Reland "[ARM] __cxa_end_cleanup should be called instead of _UnwindResume.""
This reverts commit b6420e5.
1 parent b6420e5 commit 66e03db

File tree

9 files changed

+106
-158
lines changed

9 files changed

+106
-158
lines changed
 

‎libcxxabi/src/cxa_exception.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,8 @@ unwinding with _Unwind_Resume.
341341
According to ARM EHABI 8.4.1, __cxa_end_cleanup() should not clobber any
342342
register, thus we have to write this function in assembly so that we can save
343343
{r1, r2, r3}. We don't have to save r0 because it is the return value and the
344-
first argument to _Unwind_Resume(). In addition, we are saving lr in order to
345-
align the stack to 16 bytes and lr will be used to identify the caller and its
346-
frame information. _Unwind_Resume never return and we need to keep the original
347-
lr so just branch to it.
344+
first argument to _Unwind_Resume(). In addition, we are saving r4 in order to
345+
align the stack to 16 bytes, even though it is a callee-save register.
348346
*/
349347
__attribute__((used)) static _Unwind_Exception *
350348
__cxa_end_cleanup_impl()
@@ -374,16 +372,18 @@ __cxa_end_cleanup_impl()
374372
return &exception_header->unwindHeader;
375373
}
376374

377-
asm(" .pushsection .text.__cxa_end_cleanup,\"ax\",%progbits\n"
375+
asm (
376+
" .pushsection .text.__cxa_end_cleanup,\"ax\",%progbits\n"
378377
" .globl __cxa_end_cleanup\n"
379378
" .type __cxa_end_cleanup,%function\n"
380379
"__cxa_end_cleanup:\n"
381-
" push {r1, r2, r3, lr}\n"
380+
" push {r1, r2, r3, r4}\n"
382381
" bl __cxa_end_cleanup_impl\n"
383382
" pop {r1, r2, r3, r4}\n"
384-
" mov lr, r4\n"
385-
" b _Unwind_Resume\n"
386-
" .popsection");
383+
" bl _Unwind_Resume\n"
384+
" bl abort\n"
385+
" .popsection"
386+
);
387387
#endif // defined(_LIBCXXABI_ARM_EHABI)
388388

389389
/*

‎llvm/include/llvm/ADT/Triple.h

-13
Original file line numberDiff line numberDiff line change
@@ -721,19 +721,6 @@ class Triple {
721721
return getArch() == Triple::arm || getArch() == Triple::armeb;
722722
}
723723

724-
/// Tests whether the target supports the EHABI exception
725-
/// handling standard.
726-
bool isTargetEHABICompatible() const {
727-
return isARM() &&
728-
(getEnvironment() == Triple::EABI ||
729-
getEnvironment() == Triple::GNUEABI ||
730-
getEnvironment() == Triple::MuslEABI ||
731-
getEnvironment() == Triple::EABIHF ||
732-
getEnvironment() == Triple::GNUEABIHF ||
733-
getEnvironment() == Triple::MuslEABIHF || isAndroid()) &&
734-
isOSBinFormatELF();
735-
}
736-
737724
/// Tests whether the target is AArch64 (little and big endian).
738725
bool isAArch64() const {
739726
return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be ||

‎llvm/include/llvm/IR/RuntimeLibcalls.def

-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ HANDLE_LIBCALL(MEMSET_ELEMENT_UNORDERED_ATOMIC_16, "__llvm_memset_element_unorde
432432

433433
// Exception handling
434434
HANDLE_LIBCALL(UNWIND_RESUME, "_Unwind_Resume")
435-
HANDLE_LIBCALL(CXA_END_CLEANUP, "__cxa_end_cleanup")
436435

437436
// Note: there are two sets of atomics libcalls; see
438437
// <https://llvm.org/docs/Atomics.html> for more info on the

‎llvm/lib/CodeGen/DwarfEHPrepare.cpp

+31-48
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "llvm/ADT/BitVector.h"
1515
#include "llvm/ADT/SmallVector.h"
1616
#include "llvm/ADT/Statistic.h"
17-
#include "llvm/ADT/Triple.h"
1817
#include "llvm/Analysis/CFG.h"
1918
#include "llvm/Analysis/DomTreeUpdater.h"
2019
#include "llvm/Analysis/EHPersonalities.h"
@@ -55,11 +54,13 @@ namespace {
5554
class DwarfEHPrepare {
5655
CodeGenOpt::Level OptLevel;
5756

57+
// RewindFunction - _Unwind_Resume or the target equivalent.
58+
FunctionCallee &RewindFunction;
59+
5860
Function &F;
5961
const TargetLowering &TLI;
6062
DomTreeUpdater *DTU;
6163
const TargetTransformInfo *TTI;
62-
const Triple &TargetTriple;
6364

6465
/// Return the exception object from the value passed into
6566
/// the 'resume' instruction (typically an aggregate). Clean up any dead
@@ -77,11 +78,11 @@ class DwarfEHPrepare {
7778
bool InsertUnwindResumeCalls();
7879

7980
public:
80-
DwarfEHPrepare(CodeGenOpt::Level OptLevel_, Function &F_,
81-
const TargetLowering &TLI_, DomTreeUpdater *DTU_,
82-
const TargetTransformInfo *TTI_, const Triple &TargetTriple_)
83-
: OptLevel(OptLevel_), F(F_), TLI(TLI_), DTU(DTU_), TTI(TTI_),
84-
TargetTriple(TargetTriple_) {}
81+
DwarfEHPrepare(CodeGenOpt::Level OptLevel_, FunctionCallee &RewindFunction_,
82+
Function &F_, const TargetLowering &TLI_, DomTreeUpdater *DTU_,
83+
const TargetTransformInfo *TTI_)
84+
: OptLevel(OptLevel_), RewindFunction(RewindFunction_), F(F_), TLI(TLI_),
85+
DTU(DTU_), TTI(TTI_) {}
8586

8687
bool run();
8788
};
@@ -210,28 +211,13 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
210211
if (ResumesLeft == 0)
211212
return true; // We pruned them all.
212213

213-
// RewindFunction - _Unwind_Resume or the target equivalent.
214-
FunctionCallee RewindFunction;
215-
CallingConv::ID RewindFunctionCallingConv;
216-
FunctionType *FTy;
217-
const char *RewindName;
218-
bool DoesRewindFunctionNeedExceptionObject;
219-
220-
if ((Pers == EHPersonality::GNU_CXX || Pers == EHPersonality::GNU_CXX_SjLj) &&
221-
TargetTriple.isTargetEHABICompatible()) {
222-
RewindName = TLI.getLibcallName(RTLIB::CXA_END_CLEANUP);
223-
FTy = FunctionType::get(Type::getVoidTy(Ctx), false);
224-
RewindFunctionCallingConv =
225-
TLI.getLibcallCallingConv(RTLIB::CXA_END_CLEANUP);
226-
DoesRewindFunctionNeedExceptionObject = false;
227-
} else {
228-
RewindName = TLI.getLibcallName(RTLIB::UNWIND_RESUME);
229-
FTy =
214+
// Find the rewind function if we didn't already.
215+
if (!RewindFunction) {
216+
FunctionType *FTy =
230217
FunctionType::get(Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false);
231-
RewindFunctionCallingConv = TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME);
232-
DoesRewindFunctionNeedExceptionObject = true;
218+
const char *RewindName = TLI.getLibcallName(RTLIB::UNWIND_RESUME);
219+
RewindFunction = F.getParent()->getOrInsertFunction(RewindName, FTy);
233220
}
234-
RewindFunction = F.getParent()->getOrInsertFunction(RewindName, FTy);
235221

236222
// Create the basic block where the _Unwind_Resume call will live.
237223
if (ResumesLeft == 1) {
@@ -240,14 +226,10 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
240226
ResumeInst *RI = Resumes.front();
241227
BasicBlock *UnwindBB = RI->getParent();
242228
Value *ExnObj = GetExceptionObject(RI);
243-
llvm::SmallVector<Value *, 1> RewindFunctionArgs;
244-
if (DoesRewindFunctionNeedExceptionObject)
245-
RewindFunctionArgs.push_back(ExnObj);
246229

247-
// Call the rewind function.
248-
CallInst *CI =
249-
CallInst::Create(RewindFunction, RewindFunctionArgs, "", UnwindBB);
250-
CI->setCallingConv(RewindFunctionCallingConv);
230+
// Call the _Unwind_Resume function.
231+
CallInst *CI = CallInst::Create(RewindFunction, ExnObj, "", UnwindBB);
232+
CI->setCallingConv(TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME));
251233

252234
// We never expect _Unwind_Resume to return.
253235
CI->setDoesNotReturn();
@@ -258,8 +240,6 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
258240
std::vector<DominatorTree::UpdateType> Updates;
259241
Updates.reserve(Resumes.size());
260242

261-
llvm::SmallVector<Value *, 1> RewindFunctionArgs;
262-
263243
BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &F);
264244
PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesLeft, "exn.obj",
265245
UnwindBB);
@@ -277,13 +257,9 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
277257
++NumResumesLowered;
278258
}
279259

280-
if (DoesRewindFunctionNeedExceptionObject)
281-
RewindFunctionArgs.push_back(PN);
282-
283260
// Call the function.
284-
CallInst *CI =
285-
CallInst::Create(RewindFunction, RewindFunctionArgs, "", UnwindBB);
286-
CI->setCallingConv(RewindFunctionCallingConv);
261+
CallInst *CI = CallInst::Create(RewindFunction, PN, "", UnwindBB);
262+
CI->setCallingConv(TLI.getLibcallCallingConv(RTLIB::UNWIND_RESUME));
287263

288264
// We never expect _Unwind_Resume to return.
289265
CI->setDoesNotReturn();
@@ -301,20 +277,22 @@ bool DwarfEHPrepare::run() {
301277
return Changed;
302278
}
303279

304-
static bool prepareDwarfEH(CodeGenOpt::Level OptLevel, Function &F,
280+
static bool prepareDwarfEH(CodeGenOpt::Level OptLevel,
281+
FunctionCallee &RewindFunction, Function &F,
305282
const TargetLowering &TLI, DominatorTree *DT,
306-
const TargetTransformInfo *TTI,
307-
const Triple &TargetTriple) {
283+
const TargetTransformInfo *TTI) {
308284
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
309285

310-
return DwarfEHPrepare(OptLevel, F, TLI, DT ? &DTU : nullptr, TTI,
311-
TargetTriple)
286+
return DwarfEHPrepare(OptLevel, RewindFunction, F, TLI, DT ? &DTU : nullptr,
287+
TTI)
312288
.run();
313289
}
314290

315291
namespace {
316292

317293
class DwarfEHPrepareLegacyPass : public FunctionPass {
294+
// RewindFunction - _Unwind_Resume or the target equivalent.
295+
FunctionCallee RewindFunction = nullptr;
318296

319297
CodeGenOpt::Level OptLevel;
320298

@@ -337,7 +315,12 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
337315
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
338316
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
339317
}
340-
return prepareDwarfEH(OptLevel, F, TLI, DT, TTI, TM.getTargetTriple());
318+
return prepareDwarfEH(OptLevel, RewindFunction, F, TLI, DT, TTI);
319+
}
320+
321+
bool doFinalization(Module &M) override {
322+
RewindFunction = nullptr;
323+
return false;
341324
}
342325

343326
void getAnalysisUsage(AnalysisUsage &AU) const override {

‎llvm/lib/Target/ARM/ARMSubtarget.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,14 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
792792
// ARM Targets that support EHABI exception handling standard
793793
// Darwin uses SjLj. Other targets might need more checks.
794794
bool isTargetEHABICompatible() const {
795-
return TargetTriple.isTargetEHABICompatible();
795+
return (TargetTriple.getEnvironment() == Triple::EABI ||
796+
TargetTriple.getEnvironment() == Triple::GNUEABI ||
797+
TargetTriple.getEnvironment() == Triple::MuslEABI ||
798+
TargetTriple.getEnvironment() == Triple::EABIHF ||
799+
TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
800+
TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
801+
isTargetAndroid()) &&
802+
!isTargetDarwin() && !isTargetWindows();
796803
}
797804

798805
bool isTargetHardFloat() const;

‎llvm/test/CodeGen/ARM/debug-frame.ll

+37-31
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,29 @@ declare void @_ZSt9terminatev()
197197

198198
; CHECK-V7-FP-LABEL: _Z4testiiiiiddddd:
199199
; CHECK-V7-FP: .cfi_startproc
200-
; CHECK-V7-FP: push {r11, lr}
201-
; CHECK-V7-FP: .cfi_def_cfa_offset 8
200+
; CHECK-V7-FP: push {r4, r10, r11, lr}
201+
; CHECK-V7-FP: .cfi_def_cfa_offset 16
202202
; CHECK-V7-FP: .cfi_offset lr, -4
203203
; CHECK-V7-FP: .cfi_offset r11, -8
204-
; CHECK-V7-FP: mov r11, sp
205-
; CHECK-V7-FP: .cfi_def_cfa_register r11
204+
; CHECK-V7-FP: .cfi_offset r10, -12
205+
; CHECK-V7-FP: .cfi_offset r4, -16
206+
; CHECK-V7-FP: add r11, sp, #8
207+
; CHECK-V7-FP: .cfi_def_cfa r11, 8
206208
; CHECK-V7-FP: vpush {d8, d9, d10, d11, d12}
207-
; CHECK-V7-FP: .cfi_offset d12, -16
208-
; CHECK-V7-FP: .cfi_offset d11, -24
209-
; CHECK-V7-FP: .cfi_offset d10, -32
210-
; CHECK-V7-FP: .cfi_offset d9, -40
211-
; CHECK-V7-FP: .cfi_offset d8, -48
209+
; CHECK-V7-FP: .cfi_offset d12, -24
210+
; CHECK-V7-FP: .cfi_offset d11, -32
211+
; CHECK-V7-FP: .cfi_offset d10, -40
212+
; CHECK-V7-FP: .cfi_offset d9, -48
213+
; CHECK-V7-FP: .cfi_offset d8, -56
212214
; CHECK-V7-FP: sub sp, sp, #24
213215
; CHECK-V7-FP: .cfi_endproc
214216

215217
; CHECK-V7-FP-ELIM-LABEL: _Z4testiiiiiddddd:
216218
; CHECK-V7-FP-ELIM: .cfi_startproc
217-
; CHECK-V7-FP-ELIM: push {r11, lr}
219+
; CHECK-V7-FP-ELIM: push {r4, lr}
218220
; CHECK-V7-FP-ELIM: .cfi_def_cfa_offset 8
219221
; CHECK-V7-FP-ELIM: .cfi_offset lr, -4
220-
; CHECK-V7-FP-ELIM: .cfi_offset r11, -8
222+
; CHECK-V7-FP-ELIM: .cfi_offset r4, -8
221223
; CHECK-V7-FP-ELIM: vpush {d8, d9, d10, d11, d12}
222224
; CHECK-V7-FP-ELIM: .cfi_def_cfa_offset 48
223225
; CHECK-V7-FP-ELIM: .cfi_offset d12, -16
@@ -258,27 +260,29 @@ declare void @_ZSt9terminatev()
258260

259261
; CHECK-THUMB-V7-FP-LABEL: _Z4testiiiiiddddd:
260262
; CHECK-THUMB-V7-FP: .cfi_startproc
261-
; CHECK-THUMB-V7-FP: push {r7, lr}
262-
; CHECK-THUMB-V7-FP: .cfi_def_cfa_offset 8
263+
; CHECK-THUMB-V7-FP: push {r4, r6, r7, lr}
264+
; CHECK-THUMB-V7-FP: .cfi_def_cfa_offset 16
263265
; CHECK-THUMB-V7-FP: .cfi_offset lr, -4
264266
; CHECK-THUMB-V7-FP: .cfi_offset r7, -8
265-
; CHECK-THUMB-V7-FP: mov r7, sp
266-
; CHECK-THUMB-V7-FP: .cfi_def_cfa_register r7
267+
; CHECK-THUMB-V7-FP: .cfi_offset r6, -12
268+
; CHECK-THUMB-V7-FP: .cfi_offset r4, -16
269+
; CHECK-THUMB-V7-FP: add r7, sp, #8
270+
; CHECK-THUMB-V7-FP: .cfi_def_cfa r7, 8
267271
; CHECK-THUMB-V7-FP: vpush {d8, d9, d10, d11, d12}
268-
; CHECK-THUMB-V7-FP: .cfi_offset d12, -16
269-
; CHECK-THUMB-V7-FP: .cfi_offset d11, -24
270-
; CHECK-THUMB-V7-FP: .cfi_offset d10, -32
271-
; CHECK-THUMB-V7-FP: .cfi_offset d9, -40
272-
; CHECK-THUMB-V7-FP: .cfi_offset d8, -48
272+
; CHECK-THUMB-V7-FP: .cfi_offset d12, -24
273+
; CHECK-THUMB-V7-FP: .cfi_offset d11, -32
274+
; CHECK-THUMB-V7-FP: .cfi_offset d10, -40
275+
; CHECK-THUMB-V7-FP: .cfi_offset d9, -48
276+
; CHECK-THUMB-V7-FP: .cfi_offset d8, -56
273277
; CHECK-THUMB-V7-FP: sub sp, #24
274278
; CHECK-THUMB-V7-FP: .cfi_endproc
275279

276280
; CHECK-THUMB-V7-FP-ELIM-LABEL: _Z4testiiiiiddddd:
277281
; CHECK-THUMB-V7-FP-ELIM: .cfi_startproc
278-
; CHECK-THUMB-V7-FP-ELIM: push {r7, lr}
282+
; CHECK-THUMB-V7-FP-ELIM: push {r4, lr}
279283
; CHECK-THUMB-V7-FP-ELIM: .cfi_def_cfa_offset 8
280284
; CHECK-THUMB-V7-FP-ELIM: .cfi_offset lr, -4
281-
; CHECK-THUMB-V7-FP-ELIM: .cfi_offset r7, -8
285+
; CHECK-THUMB-V7-FP-ELIM: .cfi_offset r4, -8
282286
; CHECK-THUMB-V7-FP-ELIM: vpush {d8, d9, d10, d11, d12}
283287
; CHECK-THUMB-V7-FP-ELIM: .cfi_def_cfa_offset 48
284288
; CHECK-THUMB-V7-FP-ELIM: .cfi_offset d12, -16
@@ -292,18 +296,20 @@ declare void @_ZSt9terminatev()
292296

293297
; CHECK-THUMB-V7-FP-NOIAS-LABEL: _Z4testiiiiiddddd:
294298
; CHECK-THUMB-V7-FP-NOIAS: .cfi_startproc
295-
; CHECK-THUMB-V7-FP-NOIAS: push {r7, lr}
296-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_def_cfa_offset 8
299+
; CHECK-THUMB-V7-FP-NOIAS: push {r4, r6, r7, lr}
300+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_def_cfa_offset 16
297301
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 14, -4
298302
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 7, -8
299-
; CHECK-THUMB-V7-FP-NOIAS: mov r7, sp
300-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_def_cfa_register 7
303+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 6, -12
304+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 4, -16
305+
; CHECK-THUMB-V7-FP-NOIAS: add r7, sp, #8
306+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_def_cfa 7, 8
301307
; CHECK-THUMB-V7-FP-NOIAS: vpush {d8, d9, d10, d11, d12}
302-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 268, -16
303-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 267, -24
304-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 266, -32
305-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 265, -40
306-
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 264, -48
308+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 268, -24
309+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 267, -32
310+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 266, -40
311+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 265, -48
312+
; CHECK-THUMB-V7-FP-NOIAS: .cfi_offset 264, -56
307313
; CHECK-THUMB-V7-FP-NOIAS: sub sp, #24
308314
; CHECK-THUMB-V7-FP-NOIAS: .cfi_endproc
309315

‎llvm/test/CodeGen/ARM/eh-resume.ll ‎llvm/test/CodeGen/ARM/eh-resume-darwin.ll

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
; RUN: llc < %s -mtriple=armv7-apple-watchos -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=IOS
33
; RUN: llc < %s -mtriple=armv7k-apple-ios -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=WATCHABI
44
; RUN: llc < %s -mtriple=armv7k-apple-watchos -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=WATCHABI
5-
; RUN: llc < %s -mtriple=armv7-none-gnueabihf -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=EABI
6-
; RUN: llc < %s -mtriple=armv7-none-none -arm-atomic-cfg-tidy=0 | FileCheck %s -check-prefix=ABI
75

86
declare void @func()
97

@@ -25,5 +23,3 @@ lpad:
2523

2624
; IOS: __Unwind_SjLj_Resume
2725
; WATCHABI: __Unwind_Resume
28-
; EABI: __cxa_end_cleanup
29-
; ABI: _Unwind_Resume

‎llvm/test/CodeGen/ARM/eh-resume2.ll

-32
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.