[lld] [LLD][COFF] Process all live import symbols in getSymbols() (PR #109117)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 10:58:23 PDT 2024
https://github.com/cjacek updated https://github.com/llvm/llvm-project/pull/109117
>From 53d418ca6de01dd3af0e00f167eff2393e55f764 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Wed, 18 Sep 2024 19:53:53 +0200
Subject: [PATCH] [LLD][COFF] Process all live import symbols in MapFile's
getSymbols()
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.
---
lld/COFF/MapFile.cpp | 14 ++++----------
lld/test/COFF/export-imp.test | 11 +++++++++++
2 files changed, 15 insertions(+), 10 deletions(-)
create mode 100644 lld/test/COFF/export-imp.test
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