Skip to content

Commit d403f33

Browse files
authored
[LLD][COFF] Mark personality functions as live in both symbol tables on ARM64X (#129295)
1 parent 8eba022 commit d403f33

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

lld/COFF/Driver.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,14 +2766,16 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27662766
// For now, just manually try to retain the known possible personality
27672767
// functions. This doesn't bring in more object files, but only marks
27682768
// functions that already have been included to be retained.
2769-
for (const char *n : {"__gxx_personality_v0", "__gcc_personality_v0",
2770-
"rust_eh_personality"}) {
2771-
Defined *d = dyn_cast_or_null<Defined>(ctx.symtab.findUnderscore(n));
2772-
if (d && !d->isGCRoot) {
2773-
d->isGCRoot = true;
2774-
config->gcroot.push_back(d);
2769+
ctx.forEachSymtab([&](SymbolTable &symtab) {
2770+
for (const char *n : {"__gxx_personality_v0", "__gcc_personality_v0",
2771+
"rust_eh_personality"}) {
2772+
Defined *d = dyn_cast_or_null<Defined>(symtab.findUnderscore(n));
2773+
if (d && !d->isGCRoot) {
2774+
d->isGCRoot = true;
2775+
config->gcroot.push_back(d);
2776+
}
27752777
}
2776-
}
2778+
});
27772779
}
27782780

27792781
markLive(ctx);

lld/test/COFF/gc-dwarf-eh-arm64x.s

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -triple=aarch64-windows-gnu %s -filetype=obj -o %t-arm64.obj
4+
# RUN: llvm-mc -triple=arm64ec-windows-gnu %s -filetype=obj -o %t-arm64ec.obj
5+
# RUN: lld-link -machine:arm64x -lldmingw -out:%t.exe -opt:ref -entry:main %t-arm64.obj %t-arm64ec.obj -verbose 2>&1 | FileCheck %s
6+
# CHECK: Discarded unused
7+
8+
# Check that __gxx_personality_v0 is not discarded and is present in the output.
9+
10+
# RUN: llvm-objdump -d %t.exe | FileCheck --check-prefix=DISASM %s
11+
# DISASM: 0000000140001000 <.text>:
12+
# DISASM-NEXT: 140001000: 52800000 mov w0, #0x0 // =0
13+
# DISASM-NEXT: 140001004: d65f03c0 ret
14+
# DISASM-NEXT: 140001008: 52800020 mov w0, #0x1 // =1
15+
# DISASM-NEXT: 14000100c: d65f03c0 ret
16+
# DISASM-NEXT: ...
17+
# DISASM-NEXT: 140002000: 52800000 mov w0, #0x0 // =0
18+
# DISASM-NEXT: 140002004: d65f03c0 ret
19+
# DISASM-NEXT: 140002008: 52800020 mov w0, #0x1 // =1
20+
# DISASM-NEXT: 14000200c: d65f03c0 ret
21+
22+
.def main; .scl 2; .type 32; .endef
23+
.section .text,"xr",one_only,main
24+
.globl main
25+
main:
26+
.cfi_startproc
27+
.cfi_personality 0, __gxx_personality_v0
28+
mov w0, #0
29+
ret
30+
.cfi_endproc
31+
32+
.def __gxx_personality_v0; .scl 2; .type 32; .endef
33+
.section .text,"xr",one_only,__gxx_personality_v0
34+
.globl __gxx_personality_v0
35+
__gxx_personality_v0:
36+
mov w0, #1
37+
ret
38+
39+
.def unused; .scl 2; .type 32; .endef
40+
.section .text,"xr",one_only,unused
41+
.globl unused
42+
unused:
43+
.cfi_startproc
44+
.cfi_personality 0, __gxx_personality_v0
45+
mov w0, #2
46+
ret
47+
.cfi_endproc

0 commit comments

Comments
 (0)