-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLD][COFF] Move delayLoadHelper and tailMergeUnwindInfoChunk to SymbolTable (NFC) #124729
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…olTable (NFC) In preparation for ARM64X delay-load import support (llvm#124600).
Split from #124600. |
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-lld Author: Jacek Caban (cjacek) ChangesIn preparation for ARM64X delay-load import support (#124600). Full diff: https://github.com/llvm/llvm-project/pull/124729.diff 6 Files Affected:
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index cd280aa09964d7..0c7c4e91402f18 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -164,7 +164,6 @@ struct Configuration {
bool noimplib = false;
std::set<std::string> delayLoads;
std::map<std::string, int> dllOrder;
- Symbol *delayLoadHelper = nullptr;
Symbol *arm64ECIcallHelper = nullptr;
llvm::DenseSet<llvm::StringRef> saveTempsArgs;
diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp
index b6fbd5a484b5e7..534cd47be1051f 100644
--- a/lld/COFF/DLL.cpp
+++ b/lld/COFF/DLL.cpp
@@ -911,12 +911,9 @@ uint64_t DelayLoadContents::getDirSize() {
return dirs.size() * sizeof(delay_import_directory_table_entry);
}
-void DelayLoadContents::create(Defined *h) {
- helper = h;
+void DelayLoadContents::create() {
std::vector<std::vector<DefinedImportData *>> v = binImports(ctx, imports);
- Chunk *unwind = newTailMergeUnwindInfoChunk();
-
// Create .didat contents for each DLL.
for (std::vector<DefinedImportData *> &syms : v) {
// Create the delay import table header.
@@ -924,8 +921,8 @@ void DelayLoadContents::create(Defined *h) {
auto *dir = make<DelayDirectoryChunk>(dllNames.back());
size_t base = addresses.size();
- Chunk *tm = newTailMergeChunk(dir);
- Chunk *pdataChunk = unwind ? newTailMergePDataChunk(tm, unwind) : nullptr;
+ Chunk *tm = newTailMergeChunk(ctx.symtab, dir);
+ Chunk *pdataChunk = newTailMergePDataChunk(ctx.symtab, tm);
for (DefinedImportData *s : syms) {
Chunk *t = newThunkChunk(s, tm);
auto *a = make<DelayAddressChunk>(ctx, t);
@@ -982,15 +979,18 @@ void DelayLoadContents::create(Defined *h) {
dirs.push_back(dir);
}
- if (unwind)
- unwindinfo.push_back(unwind);
+ ctx.forEachSymtab([&](SymbolTable &symtab) {
+ if (symtab.tailMergeUnwindInfoChunk)
+ unwindinfo.push_back(symtab.tailMergeUnwindInfoChunk);
+ });
// Add null terminator.
dirs.push_back(
make<NullChunk>(sizeof(delay_import_directory_table_entry), 4));
}
-Chunk *DelayLoadContents::newTailMergeChunk(Chunk *dir) {
- switch (ctx.config.machine) {
+Chunk *DelayLoadContents::newTailMergeChunk(SymbolTable &symtab, Chunk *dir) {
+ auto helper = cast<Defined>(symtab.delayLoadHelper);
+ switch (symtab.machine) {
case AMD64:
case ARM64EC:
return make<TailMergeChunkX64>(dir, helper);
@@ -1005,21 +1005,14 @@ Chunk *DelayLoadContents::newTailMergeChunk(Chunk *dir) {
}
}
-Chunk *DelayLoadContents::newTailMergeUnwindInfoChunk() {
- switch (ctx.config.machine) {
- case AMD64:
- case ARM64EC:
- return make<TailMergeUnwindInfoX64>();
- // FIXME: Add support for other architectures.
- default:
- return nullptr; // Just don't generate unwind info.
- }
-}
-Chunk *DelayLoadContents::newTailMergePDataChunk(Chunk *tm, Chunk *unwind) {
- switch (ctx.config.machine) {
+Chunk *DelayLoadContents::newTailMergePDataChunk(SymbolTable &symtab,
+ Chunk *tm) {
+ switch (symtab.machine) {
case AMD64:
case ARM64EC:
- return make<TailMergePDataChunkX64>(tm, unwind);
+ if (!symtab.tailMergeUnwindInfoChunk)
+ symtab.tailMergeUnwindInfoChunk = make<TailMergeUnwindInfoX64>();
+ return make<TailMergePDataChunkX64>(tm, symtab.tailMergeUnwindInfoChunk);
// FIXME: Add support for other architectures.
default:
return nullptr; // Just don't generate unwind info.
@@ -1028,7 +1021,7 @@ Chunk *DelayLoadContents::newTailMergePDataChunk(Chunk *tm, Chunk *unwind) {
Chunk *DelayLoadContents::newThunkChunk(DefinedImportData *s,
Chunk *tailMerge) {
- switch (ctx.config.machine) {
+ switch (s->file->getMachineType()) {
case AMD64:
case ARM64EC:
return make<ThunkChunkX64>(s, tailMerge);
diff --git a/lld/COFF/DLL.h b/lld/COFF/DLL.h
index 724a323d62d205..5105b79f15d31a 100644
--- a/lld/COFF/DLL.h
+++ b/lld/COFF/DLL.h
@@ -42,7 +42,7 @@ class DelayLoadContents {
DelayLoadContents(COFFLinkerContext &ctx) : ctx(ctx) {}
void add(DefinedImportData *sym) { imports.push_back(sym); }
bool empty() { return imports.empty(); }
- void create(Defined *helper);
+ void create();
std::vector<Chunk *> getChunks();
std::vector<Chunk *> getDataChunks();
ArrayRef<Chunk *> getCodeChunks() { return thunks; }
@@ -56,11 +56,9 @@ class DelayLoadContents {
private:
Chunk *newThunkChunk(DefinedImportData *s, Chunk *tailMerge);
- Chunk *newTailMergeChunk(Chunk *dir);
- Chunk *newTailMergePDataChunk(Chunk *tm, Chunk *unwind);
- Chunk *newTailMergeUnwindInfoChunk();
+ Chunk *newTailMergeChunk(SymbolTable &symtab, Chunk *dir);
+ Chunk *newTailMergePDataChunk(SymbolTable &symtab, Chunk *tm);
- Defined *helper;
std::vector<DefinedImportData *> imports;
std::vector<Chunk *> dirs;
std::vector<Chunk *> moduleHandles;
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6eea11f5f451fd..ac3ac57bd17f44 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2353,12 +2353,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
llvm::TimeTraceScope timeScope("Delay load");
for (auto *arg : args.filtered(OPT_delayload)) {
config->delayLoads.insert(StringRef(arg->getValue()).lower());
- if (config->machine == I386) {
- config->delayLoadHelper = ctx.symtab.addGCRoot("___delayLoadHelper2@8");
- } else {
- config->delayLoadHelper =
- ctx.symtab.addGCRoot("__delayLoadHelper2", true);
- }
+ ctx.forEachSymtab([&](SymbolTable &symtab) {
+ if (symtab.machine == I386) {
+ symtab.delayLoadHelper = symtab.addGCRoot("___delayLoadHelper2@8");
+ } else {
+ symtab.delayLoadHelper = symtab.addGCRoot("__delayLoadHelper2", true);
+ }
+ });
}
}
diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h
index c8d7251838842f..ff6e8487f07344 100644
--- a/lld/COFF/SymbolTable.h
+++ b/lld/COFF/SymbolTable.h
@@ -158,6 +158,9 @@ class SymbolTable {
Chunk *edataStart = nullptr;
Chunk *edataEnd = nullptr;
+ Symbol *delayLoadHelper = nullptr;
+ Chunk *tailMergeUnwindInfoChunk = nullptr;
+
void fixupExports();
void assignExportOrdinals();
void parseModuleDefs(StringRef path);
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index bef2ced9f2957d..2bdaeb58ab432d 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1307,8 +1307,7 @@ void Writer::appendImportThunks() {
}
if (!delayIdata.empty()) {
- Defined *helper = cast<Defined>(ctx.config.delayLoadHelper);
- delayIdata.create(helper);
+ delayIdata.create();
for (Chunk *c : delayIdata.getChunks())
didatSec->addChunk(c);
for (Chunk *c : delayIdata.getDataChunks())
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In preparation for ARM64X delay-load import support (#124600).