[lld] 912e821 - [LLD][COFF] Process all live import symbols in MapFile's getSymbols() (#109117)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 04:20:04 PDT 2024
Author: Jacek Caban
Date: 2024-09-19T13:20:01+02:00
New Revision: 912e821ab3d415dc8421f53738ebabcc7f1dac2d
URL: https://github.com/llvm/llvm-project/commit/912e821ab3d415dc8421f53738ebabcc7f1dac2d
DIFF: https://github.com/llvm/llvm-project/commit/912e821ab3d415dc8421f53738ebabcc7f1dac2d.diff
LOG: [LLD][COFF] Process all live import symbols in MapFile's getSymbols() (#109117)
The current logic assumes that the import file is pulled by object
files, and the loop for import files only needs to handle cases where
the `__imp_` symbol is implicitly pulled by an import thunk. This is
fragile, as the symbol may also be pulled through other means, such as
the -export argument in tests. Additionally, this logic is insufficient
for ARM64EC, which exposes multiple symbols through an import file, and
referencing any one of them causes all of them to be defined.
With this change, import symbols are added to `syms` more often, but we
ensure that output symbols remain unique later in the process
Added:
lld/test/COFF/export-imp.test
Modified:
lld/COFF/MapFile.cpp
Removed:
################################################################################
diff --git a/lld/COFF/MapFile.cpp b/lld/COFF/MapFile.cpp
index 751a2238e701f7..7c9c1711214550 100644
--- a/lld/COFF/MapFile.cpp
+++ b/lld/COFF/MapFile.cpp
@@ -122,16 +122,10 @@ static void getSymbols(const COFFLinkerContext &ctx,
if (!file->live)
continue;
- if (!file->thunkSym)
- continue;
-
- if (!file->thunkSym->isLive())
- continue;
-
- syms.push_back(file->thunkSym);
-
- if (auto *impSym = dyn_cast_or_null<Defined>(file->impSym))
- syms.push_back(impSym);
+ if (file->impSym)
+ syms.push_back(file->impSym);
+ if (file->thunkSym && file->thunkSym->isLive())
+ syms.push_back(file->thunkSym);
}
sortUniqueSymbols(syms, ctx.config.imageBase);
diff --git a/lld/test/COFF/export-imp.test b/lld/test/COFF/export-imp.test
new file mode 100644
index 00000000000000..db71ef74641639
--- /dev/null
+++ b/lld/test/COFF/export-imp.test
@@ -0,0 +1,11 @@
+; REQUIRES: x86
+
+; RUN: llvm-lib -machine:amd64 -out:%t.imp.lib -def:%s
+; RUN: lld-link -machine:amd64 -out:%t.dll %t.imp.lib -dll -noentry -export:__imp_func,DATA -map
+
+; FileCheck %s < %t.imp.map
+; CHECK: 0001:00000098 __imp_func 0000000180001098 export-imp-thunk.test.tmp.imp:imp.dll
+
+LIBRARY imp.dll
+EXPORTS
+ func
More information about the llvm-commits
mailing list