Skip to content

Commit e7d6b0d

Browse files
committed
[LLD][COFF] Allow overriding EC alias symbols with alternate names
1 parent 98bc529 commit e7d6b0d

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

lld/COFF/Driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,9 +2518,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
25182518
Symbol *sym = ctx.symtab.find(from);
25192519
if (!sym)
25202520
continue;
2521-
if (auto *u = dyn_cast<Undefined>(sym))
2522-
if (!u->weakAlias)
2521+
if (auto *u = dyn_cast<Undefined>(sym)) {
2522+
if (!u->weakAlias || u->isECAlias(ctx.config.machine))
25232523
u->setWeakAlias(ctx.symtab.addUndefined(to));
2524+
}
25242525
}
25252526

25262527
// If any inputs are bitcode files, the LTO code generator may create

lld/test/COFF/arm64ec-altnames.s

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.obj
4+
# RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig.obj
5+
6+
# RUN: lld-link -machine:arm64ec -dll -noentry -out:%t1.dll %t.obj %t-loadconfig.obj "-alternatename:#func=altsym"
7+
8+
# RUN: llvm-objdump -d %t1.dll | FileCheck --check-prefix=DISASM %s
9+
# DISASM: 0000000180001000 <.text>:
10+
# DISASM-NEXT: 180001000: 52800020 mov w0, #0x1 // =1
11+
# DISASM-NEXT: 180001004: d65f03c0 ret
12+
# DISASM-NOT: .thnk
13+
14+
# RUN: llvm-readobj --hex-dump=.test %t1.dll | FileCheck --check-prefix=TESTSEC %s
15+
# TESTSEC: 0x180004000 00100000 00100000
16+
17+
# RUN: lld-link -machine:arm64ec -dll -noentry -out:%t2.dll %t.obj %t-loadconfig.obj -alternatename:func=altsym
18+
19+
# RUN: llvm-objdump -d %t2.dll | FileCheck --check-prefix=DISASM2 %s
20+
# DISASM2: Disassembly of section .text:
21+
# DISASM2-EMPTY:
22+
# DISASM2-NEXT: 0000000180001000 <.text>:
23+
# DISASM2-NEXT: 180001000: 52800020 mov w0, #0x1 // =1
24+
# DISASM2-NEXT: 180001004: d65f03c0 ret
25+
# DISASM2-EMPTY:
26+
# DISASM2-NEXT: Disassembly of section .thnk:
27+
# DISASM2-EMPTY:
28+
# DISASM2-NEXT: 0000000180005000 <.thnk>:
29+
# DISASM2-NEXT: 180005000: 52800040 mov w0, #0x2 // =2
30+
# DISASM2-NEXT: 180005004: d65f03c0 ret
31+
32+
# RUN: llvm-readobj --hex-dump=.test %t2.dll | FileCheck --check-prefix=TESTSEC2 %s
33+
# TESTSEC2: 0x180004000 00100000 00500000
34+
35+
.weak_anti_dep func
36+
.set func, "#func"
37+
.weak_anti_dep "#func"
38+
.set "#func", thunksym
39+
40+
.section .test, "r"
41+
.rva func
42+
.rva "#func"
43+
44+
.section .thnk,"xr",discard,thunksym
45+
thunksym:
46+
mov w0, #2
47+
ret
48+
49+
.section .text,"xr",discard,altsym
50+
.globl altsym
51+
altsym:
52+
mov w0, #1
53+
ret

0 commit comments

Comments
 (0)