[lld] [LLD][COFF] Allow overriding EC alias symbols with alternate names (PR #113456)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 23 06:28:37 PDT 2024
https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/113456
None
>From e7d6b0d2ac2a56870e8def90f4398a25459cc0d5 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Mon, 18 Sep 2023 19:21:21 +0200
Subject: [PATCH] [LLD][COFF] Allow overriding EC alias symbols with alternate
names
---
lld/COFF/Driver.cpp | 5 +--
lld/test/COFF/arm64ec-altnames.s | 53 ++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 2 deletions(-)
create mode 100644 lld/test/COFF/arm64ec-altnames.s
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index e7f768789271fa..f9c78482e8aa79 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2518,9 +2518,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
Symbol *sym = ctx.symtab.find(from);
if (!sym)
continue;
- if (auto *u = dyn_cast<Undefined>(sym))
- if (!u->weakAlias)
+ if (auto *u = dyn_cast<Undefined>(sym)) {
+ if (!u->weakAlias || u->isECAlias(ctx.config.machine))
u->setWeakAlias(ctx.symtab.addUndefined(to));
+ }
}
// If any inputs are bitcode files, the LTO code generator may create
diff --git a/lld/test/COFF/arm64ec-altnames.s b/lld/test/COFF/arm64ec-altnames.s
new file mode 100644
index 00000000000000..a346ced7f5b7ad
--- /dev/null
+++ b/lld/test/COFF/arm64ec-altnames.s
@@ -0,0 +1,53 @@
+# REQUIRES: aarch64
+
+# RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.obj
+# RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o %t-loadconfig.obj
+
+# RUN: lld-link -machine:arm64ec -dll -noentry -out:%t1.dll %t.obj %t-loadconfig.obj "-alternatename:#func=altsym"
+
+# RUN: llvm-objdump -d %t1.dll | FileCheck --check-prefix=DISASM %s
+# DISASM: 0000000180001000 <.text>:
+# DISASM-NEXT: 180001000: 52800020 mov w0, #0x1 // =1
+# DISASM-NEXT: 180001004: d65f03c0 ret
+# DISASM-NOT: .thnk
+
+# RUN: llvm-readobj --hex-dump=.test %t1.dll | FileCheck --check-prefix=TESTSEC %s
+# TESTSEC: 0x180004000 00100000 00100000
+
+# RUN: lld-link -machine:arm64ec -dll -noentry -out:%t2.dll %t.obj %t-loadconfig.obj -alternatename:func=altsym
+
+# RUN: llvm-objdump -d %t2.dll | FileCheck --check-prefix=DISASM2 %s
+# DISASM2: Disassembly of section .text:
+# DISASM2-EMPTY:
+# DISASM2-NEXT: 0000000180001000 <.text>:
+# DISASM2-NEXT: 180001000: 52800020 mov w0, #0x1 // =1
+# DISASM2-NEXT: 180001004: d65f03c0 ret
+# DISASM2-EMPTY:
+# DISASM2-NEXT: Disassembly of section .thnk:
+# DISASM2-EMPTY:
+# DISASM2-NEXT: 0000000180005000 <.thnk>:
+# DISASM2-NEXT: 180005000: 52800040 mov w0, #0x2 // =2
+# DISASM2-NEXT: 180005004: d65f03c0 ret
+
+# RUN: llvm-readobj --hex-dump=.test %t2.dll | FileCheck --check-prefix=TESTSEC2 %s
+# TESTSEC2: 0x180004000 00100000 00500000
+
+ .weak_anti_dep func
+.set func, "#func"
+ .weak_anti_dep "#func"
+.set "#func", thunksym
+
+ .section .test, "r"
+ .rva func
+ .rva "#func"
+
+ .section .thnk,"xr",discard,thunksym
+thunksym:
+ mov w0, #2
+ ret
+
+ .section .text,"xr",discard,altsym
+ .globl altsym
+altsym:
+ mov w0, #1
+ ret
More information about the llvm-commits
mailing list