[lld] [LLD][COFF] Allow overriding EC alias symbols with alternate names (PR #113456)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 06:29:11 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-coff

Author: Jacek Caban (cjacek)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/113456.diff


2 Files Affected:

- (modified) lld/COFF/Driver.cpp (+3-2) 
- (added) lld/test/COFF/arm64ec-altnames.s (+53) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/113456


More information about the llvm-commits mailing list