[lld] [LLD][COFF][NFC] Create import thunks in ImportFile::parse. (PR #107929)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 15:43:30 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld
Author: Jacek Caban (cjacek)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/107929.diff
5 Files Affected:
- (modified) lld/COFF/InputFiles.cpp (+20-2)
- (modified) lld/COFF/SymbolTable.cpp (+2-2)
- (modified) lld/COFF/SymbolTable.h (+2-1)
- (modified) lld/COFF/Symbols.cpp (+3-15)
- (modified) lld/COFF/Symbols.h (+1-1)
``````````diff
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index fa2d230075d9d3..dbb2630aef5354 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -1069,9 +1069,27 @@ void ImportFile::parse() {
// DLL functions just like regular non-DLL functions.)
if (hdr->getType() == llvm::COFF::IMPORT_CODE) {
if (ctx.config.machine != ARM64EC) {
- thunkSym = ctx.symtab.addImportThunk(name, impSym, hdr->Machine);
+ ImportThunkChunk *chunk;
+ switch (hdr->Machine) {
+ case AMD64:
+ chunk = make<ImportThunkChunkX64>(ctx, impSym);
+ break;
+ case I386:
+ chunk = make<ImportThunkChunkX86>(ctx, impSym);
+ break;
+ case ARM64:
+ chunk = make<ImportThunkChunkARM64>(ctx, impSym);
+ break;
+ case ARMNT:
+ chunk = make<ImportThunkChunkARM>(ctx, impSym);
+ break;
+ default:
+ llvm_unreachable("unknown machine type");
+ }
+ thunkSym = ctx.symtab.addImportThunk(name, impSym, chunk);
} else {
- thunkSym = ctx.symtab.addImportThunk(name, impSym, AMD64);
+ thunkSym = ctx.symtab.addImportThunk(
+ name, impSym, make<ImportThunkChunkX64>(ctx, impSym));
// FIXME: Add aux IAT symbols.
}
}
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index bb7583bb9a7df4..c9b3d78e3de17a 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -784,11 +784,11 @@ DefinedImportData *SymbolTable::addImportData(StringRef n, ImportFile *f) {
}
Symbol *SymbolTable::addImportThunk(StringRef name, DefinedImportData *id,
- uint16_t machine) {
+ ImportThunkChunk *chunk) {
auto [s, wasInserted] = insert(name, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || s->isLazy()) {
- replaceSymbol<DefinedImportThunk>(s, ctx, name, id, machine);
+ replaceSymbol<DefinedImportThunk>(s, ctx, name, id, chunk);
return s;
}
diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h
index 51c6c79ec14463..3a277fc700e864 100644
--- a/lld/COFF/SymbolTable.h
+++ b/lld/COFF/SymbolTable.h
@@ -28,6 +28,7 @@ class COFFLinkerContext;
class Defined;
class DefinedAbsolute;
class DefinedRegular;
+class ImportThunkChunk;
class LazyArchive;
class SectionChunk;
class Symbol;
@@ -104,7 +105,7 @@ class SymbolTable {
CommonChunk *c = nullptr);
DefinedImportData *addImportData(StringRef n, ImportFile *f);
Symbol *addImportThunk(StringRef name, DefinedImportData *s,
- uint16_t machine);
+ ImportThunkChunk *chunk);
void addLibcall(StringRef name);
void addEntryThunk(Symbol *from, Symbol *to);
void initializeEntryThunks();
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index b098abb80d6f1e..5f4d797f74a2dd 100644
--- a/lld/COFF/Symbols.cpp
+++ b/lld/COFF/Symbols.cpp
@@ -107,22 +107,10 @@ COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
uint64_t DefinedAbsolute::getRVA() { return va - ctx.config.imageBase; }
-static Chunk *makeImportThunk(COFFLinkerContext &ctx, DefinedImportData *s,
- uint16_t machine) {
- if (machine == AMD64)
- return make<ImportThunkChunkX64>(ctx, s);
- if (machine == I386)
- return make<ImportThunkChunkX86>(ctx, s);
- if (machine == ARM64)
- return make<ImportThunkChunkARM64>(ctx, s);
- assert(machine == ARMNT);
- return make<ImportThunkChunkARM>(ctx, s);
-}
-
DefinedImportThunk::DefinedImportThunk(COFFLinkerContext &ctx, StringRef name,
- DefinedImportData *s, uint16_t machine)
- : Defined(DefinedImportThunkKind, name), wrappedSym(s),
- data(makeImportThunk(ctx, s, machine)) {}
+ DefinedImportData *s,
+ ImportThunkChunk *chunk)
+ : Defined(DefinedImportThunkKind, name), wrappedSym(s), data(chunk) {}
Defined *Undefined::getWeakAlias() {
// A weak alias may be a weak alias to another symbol, so check recursively.
diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index c427a062dc82b2..724330e4bab958 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -388,7 +388,7 @@ class DefinedImportData : public Defined {
class DefinedImportThunk : public Defined {
public:
DefinedImportThunk(COFFLinkerContext &ctx, StringRef name,
- DefinedImportData *s, uint16_t machine);
+ DefinedImportData *s, ImportThunkChunk *chunk);
static bool classof(const Symbol *s) {
return s->kind() == DefinedImportThunkKind;
``````````
</details>
https://github.com/llvm/llvm-project/pull/107929
More information about the llvm-commits
mailing list