[lld] [LLD][COFF] Use archive's ECSYMBOLS on ARM64EC target when available. (PR #106904)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 1 05:38:40 PDT 2024
https://github.com/cjacek created https://github.com/llvm/llvm-project/pull/106904
None
>From d49a6df9b8b07b7ef46e978180f27327ca484957 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Fri, 22 Sep 2023 17:50:03 +0200
Subject: [PATCH] [LLD][COFF] Use archive's ECSYMBOLS on ARM64EC target when
available.
---
lld/COFF/InputFiles.cpp | 14 ++++++++++++
lld/test/COFF/arm64ec-lib.test | 41 ++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
create mode 100644 lld/test/COFF/arm64ec-lib.test
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 3ecd4d241f2cd4..e1ea4ebeabc9b8 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -100,6 +100,20 @@ void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file.
file = CHECK(Archive::create(mb), this);
+ // Try to read symbols from ECSYMBOLS section on ARM64EC.
+ if (isArm64EC(ctx.config.machine)) {
+ iterator_range<Archive::symbol_iterator> symbols =
+ CHECK(file->ec_symbols(), this);
+ if (!symbols.empty()) {
+ for (const Archive::Symbol &sym : symbols)
+ ctx.symtab.addLazyArchive(this, sym);
+
+ // Read both EC and native symbols on ARM64X.
+ if (ctx.config.machine != ARM64X)
+ return;
+ }
+ }
+
// Read the symbol table to construct Lazy objects.
for (const Archive::Symbol &sym : file->symbols())
ctx.symtab.addLazyArchive(this, sym);
diff --git a/lld/test/COFF/arm64ec-lib.test b/lld/test/COFF/arm64ec-lib.test
new file mode 100644
index 00000000000000..1f9515aa99668b
--- /dev/null
+++ b/lld/test/COFF/arm64ec-lib.test
@@ -0,0 +1,41 @@
+REQUIRES: aarch64, x86
+RUN: split-file %s %t.dir && cd %t.dir
+
+RUN: llvm-mc -filetype=obj -triple=arm64ec-windows symref.s -o symref-arm64ec.obj
+RUN: llvm-mc -filetype=obj -triple=arm64ec-windows nsymref.s -o nsymref-arm64ec.obj
+RUN: llvm-mc -filetype=obj -triple=aarch64-windows nsymref.s -o nsymref-aarch64.obj
+RUN: llvm-mc -filetype=obj -triple=arm64ec-windows sym.s -o sym-arm64ec.obj
+RUN: llvm-mc -filetype=obj -triple=x86_64-windows sym.s -o sym-x86_64.obj
+RUN: llvm-mc -filetype=obj -triple=aarch64-windows nsym.s -o sym-aarch64.obj
+RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %S/Inputs/loadconfig-arm64ec.s -o loadconfig-arm64ec.obj
+
+RUN: llvm-lib -machine:arm64ec -out:sym-arm64ec.lib sym-arm64ec.obj sym-aarch64.obj
+RUN: llvm-lib -machine:amd64 -out:sym-x86_64.lib sym-x86_64.obj
+
+RUN: lld-link -machine:arm64ec -dll -noentry -out:test.dll symref-arm64ec.obj sym-arm64ec.lib loadconfig-arm64ec.obj
+RUN: lld-link -machine:arm64ec -dll -noentry -out:test2.dll symref-arm64ec.obj sym-x86_64.lib loadconfig-arm64ec.obj
+RUN: lld-link -machine:arm64x -dll -noentry -out:test3.dll symref-arm64ec.obj nsymref-aarch64.obj sym-arm64ec.lib loadconfig-arm64ec.obj
+
+RUN: not lld-link -machine:arm64ec -dll -noentry -out:test-err.dll nsymref-arm64ec.obj sym-arm64ec.lib loadconfig-arm64ec.obj 2>&1 |\
+RUN: FileCheck --check-prefix=ERR %s
+ERR: error: undefined symbol: nsym
+
+#--- symref.s
+ .data
+ .rva sym
+
+#--- nsymref.s
+ .data
+ .rva nsym
+
+#--- sym.s
+ .data
+ .globl sym
+sym:
+ .word 0
+
+#--- nsym.s
+ .data
+ .globl nsym
+nsym:
+ .word 0
More information about the llvm-commits
mailing list