-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Allow overriding EC alias symbols with alternate names #113456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-lld-coff Author: Jacek Caban (cjacek) ChangesFull diff: https://github.com/llvm/llvm-project/pull/113456.diff 2 Files Affected:
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
|
Similar to the handling of lazy symbols, EC aliases behave like undefined symbols in this context. |
I just noticed that we may need special-casing |
More experimentation with MSVC revealed that |
Fixed a typo in test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.