Skip to content

Commit 25b637f

Browse files
committed
Revise unwind-table emission, enabling them for most popular targets
Based on the clang 19 logic (but not 100% accurate). There's an interesting special case - Darwin on arm64 apparently uses *synchronous* tables.
1 parent 2b1f361 commit 25b637f

15 files changed

+44
-30
lines changed

.github/actions/4d-test-libs/action.yml

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ runs:
2424
excludes+='|^std.internal.math.gammafunction'
2525
# FIXME: failing unittest(s) with enabled optimizations
2626
excludes+='|^std.math.exponential(-shared)?$'
27-
# FIXME: subtest rt_trap_exceptions fails
28-
excludes+='|^druntime-test-exceptions-debug$'
2927
# FIXME: sporadically hanging
3028
excludes+='|^core.thread-shared$'
3129
fi

gen/abi/aarch64.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ struct AArch64TargetABI : TargetABI {
5757
public:
5858
AArch64TargetABI() {}
5959

60+
llvm::UWTableKind defaultUnwindTableKind() override {
61+
return isDarwin() ? llvm::UWTableKind::Sync : llvm::UWTableKind::Async;
62+
}
63+
6064
bool returnInArg(TypeFunction *tf, bool) override {
6165
Type *rt = tf->next->toBasetype();
6266
if (rt->ty == TY::Tstruct || rt->ty == TY::Tsarray) {

gen/abi/abi.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "dmd/globals.h"
2020
#include "gen/dvalue.h"
2121
#include "llvm/IR/CallingConv.h"
22+
#include "llvm/Support/CodeGen.h" // for UWTableKind
2223
#include <vector>
2324

2425
class Type;
@@ -110,12 +111,10 @@ struct TargetABI {
110111
return name;
111112
}
112113

113-
/// Returns true if all functions require the LLVM uwtable attribute.
114-
virtual bool needsUnwindTables() {
115-
// Condensed logic of Clang implementations of
116-
// `clang::ToolChain::IsUnwindTablesDefault()` based on early Clang 5.0.
117-
return global.params.targetTriple->getArch() == llvm::Triple::x86_64 ||
118-
global.params.targetTriple->getOS() == llvm::Triple::NetBSD;
114+
/// Returns the default unwind-table kind for all functions.
115+
/// Analogous to clang's ToolChain::getDefaultUnwindTableLevel().
116+
virtual llvm::UWTableKind defaultUnwindTableKind() {
117+
return llvm::UWTableKind::None;
119118
}
120119

121120
/// Returns true if the target is darwin-based.

gen/abi/arm.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct ArmTargetABI : TargetABI {
2626
CompositeToArray64 compositeToArray64;
2727
IntegerRewrite integerRewrite;
2828

29+
llvm::UWTableKind defaultUnwindTableKind() override {
30+
const auto &triple = *global.params.targetTriple;
31+
return triple.isOSLinux() || triple.isOSOpenBSD()
32+
? llvm::UWTableKind::None
33+
: llvm::UWTableKind::Async;
34+
}
35+
2936
bool returnInArg(TypeFunction *tf, bool) override {
3037
// AAPCS 5.4 wants composites > 4-bytes returned by arg except for
3138
// Homogeneous Aggregates of up-to 4 float types (6.1.2.1) - an HFA.

gen/abi/nvptx.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ struct NVPTXTargetABI : TargetABI {
4444
pointerRewite.applyTo(arg);
4545
}
4646
}
47-
// There are no exceptions at all, so no need for unwind tables.
48-
bool needsUnwindTables() override {
49-
return false;
50-
}
5147
};
5248

5349
TargetABI *createNVPTXABI() { return new NVPTXTargetABI(); }

gen/abi/ppc.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ struct PPCTargetABI : TargetABI {
3636

3737
explicit PPCTargetABI(const bool Is64Bit) : Is64Bit(Is64Bit) {}
3838

39+
llvm::UWTableKind defaultUnwindTableKind() override {
40+
return llvm::UWTableKind::Async;
41+
}
42+
3943
bool returnInArg(TypeFunction *tf, bool) override {
4044
Type *rt = tf->next->toBasetype();
4145

gen/abi/ppc64le.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ struct PPC64LETargetABI : TargetABI {
2929

3030
explicit PPC64LETargetABI() : hfvaToArray(8) {}
3131

32+
llvm::UWTableKind defaultUnwindTableKind() override {
33+
return llvm::UWTableKind::Async;
34+
}
35+
3236
bool passByVal(TypeFunction *, Type *t) override {
3337
t = t->toBasetype();
3438
return isPOD(t) &&

gen/abi/riscv64.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ struct RISCV64TargetABI : TargetABI {
158158
IntegerRewrite integerRewrite;
159159

160160
public:
161+
llvm::UWTableKind defaultUnwindTableKind() override {
162+
return global.params.targetTriple->isOSLinux() ? llvm::UWTableKind::Async
163+
: llvm::UWTableKind::None;
164+
}
165+
161166
Type *vaListType() override {
162167
// va_list is void*
163168
return pointerTo(Type::tvoid);

gen/abi/spirv.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ struct SPIRVTargetABI : TargetABI {
5050
pointerRewite.applyTo(arg);
5151
}
5252
}
53-
// There are no exceptions at all, so no need for unwind tables.
54-
bool needsUnwindTables() override {
55-
return false;
56-
}
5753
};
5854

5955
TargetABI *createSPIRVABI() { return new SPIRVTargetABI(); }

gen/abi/win64.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ struct Win64TargetABI : TargetABI {
116116
return name;
117117
}
118118

119+
llvm::UWTableKind defaultUnwindTableKind() override {
120+
return llvm::UWTableKind::Async;
121+
}
122+
119123
bool returnInArg(TypeFunction *tf, bool needsThis) override {
120124
Type *rt = tf->next->toBasetype();
121125

gen/abi/x86-64.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ struct X86_64TargetABI : TargetABI {
146146
ImplicitByvalRewrite byvalRewrite;
147147
IndirectByvalRewrite indirectByvalRewrite;
148148

149+
llvm::UWTableKind defaultUnwindTableKind() override {
150+
return llvm::UWTableKind::Async;
151+
}
152+
149153
bool returnInArg(TypeFunction *tf, bool needsThis) override;
150154

151155
bool preferPassByRef(Type *t) override;

gen/abi/x86.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ struct X86TargetABI : TargetABI {
8484
return name;
8585
}
8686

87+
llvm::UWTableKind defaultUnwindTableKind() override {
88+
return isMSVC ? llvm::UWTableKind::None : llvm::UWTableKind::Async;
89+
}
90+
8791
// Helper folding the magic __c_complex_{float,double,real} enums to the basic
8892
// complex type.
8993
static Type *getExtraLoweredReturnType(TypeFunction *tf) {

gen/functions.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,7 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
11481148
}
11491149

11501150
// function attributes
1151-
if (gABI->needsUnwindTables()) {
1152-
func->setUWTableKind(llvm::UWTableKind::Default);
1153-
}
1151+
func->setUWTableKind(gABI->defaultUnwindTableKind());
11541152
if (opts::isAnySanitizerEnabled() &&
11551153
!opts::functionIsInSanitizerBlacklist(fd)) {
11561154
// Get the @noSanitize mask

gen/modules.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,8 @@ void addCoverageAnalysis(Module *m) {
286286
ctor =
287287
LLFunction::Create(ctorTy, LLGlobalValue::InternalLinkage,
288288
getIRMangledFuncName(ctorname, LINK::d), &gIR->module);
289+
ctor->setUWTableKind(gABI->defaultUnwindTableKind());
289290
ctor->setCallingConv(gABI->callingConv(LINK::d));
290-
// Set function attributes. See functions.cpp:DtoDefineFunction()
291-
if (global.params.targetTriple->getArch() == llvm::Triple::x86_64) {
292-
ctor->setUWTableKind(llvm::UWTableKind::Default);
293-
}
294291

295292
llvm::BasicBlock *bb = llvm::BasicBlock::Create(gIR->context(), "", ctor);
296293
IRBuilder<> builder(bb);

gen/runtime.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,7 @@ struct LazyFunctionDeclarer {
269269

270270
fn->setAttributes(attrs);
271271

272-
// On x86_64, always set 'uwtable' for System V ABI compatibility.
273-
// FIXME: Move to better place (abi-x86-64.cpp?)
274-
// NOTE: There are several occurances if this line.
275-
if (global.params.targetTriple->getArch() == llvm::Triple::x86_64) {
276-
fn->setUWTableKind(llvm::UWTableKind::Default);
277-
}
278-
272+
fn->setUWTableKind(gABI->defaultUnwindTableKind());
279273
fn->setCallingConv(gABI->callingConv(dty, false));
280274
}
281275
}

0 commit comments

Comments
 (0)