[lld] [LLD][COFF] Remove no longer needed symtabEC from COFFLinkerContext (NFC) (PR #135094)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 11 06:56:14 PDT 2025
https://github.com/cjacek updated https://github.com/llvm/llvm-project/pull/135094
>From 0c0002fde44995c1e7ffe03f54eda7cabc93072d Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek at codeweavers.com>
Date: Mon, 7 Apr 2025 20:01:35 +0200
Subject: [PATCH] [LLD][COFF] Remove no longer needed symtabEC from
COFFLinkerContext (NFC)
With #135093, we may just use symtab instead.
---
lld/COFF/COFFLinkerContext.h | 4 ---
lld/COFF/DLL.cpp | 4 +--
lld/COFF/Driver.cpp | 22 +++++++----------
lld/COFF/InputFiles.cpp | 4 +--
lld/COFF/Writer.cpp | 47 +++++++++++++++++-------------------
5 files changed, 35 insertions(+), 46 deletions(-)
diff --git a/lld/COFF/COFFLinkerContext.h b/lld/COFF/COFFLinkerContext.h
index 613184d05d818..2c5f6415e5d4b 100644
--- a/lld/COFF/COFFLinkerContext.h
+++ b/lld/COFF/COFFLinkerContext.h
@@ -35,10 +35,6 @@ class COFFLinkerContext : public CommonLinkerContext {
// A native ARM64 symbol table on ARM64X target.
std::optional<SymbolTable> hybridSymtab;
- // Pointer to the ARM64EC symbol table: either symtab for an ARM64EC target or
- // hybridSymtab for an ARM64X target.
- SymbolTable *symtabEC = nullptr;
-
// Returns the appropriate symbol table for the specified machine type.
SymbolTable &getSymtab(llvm::COFF::MachineTypes machine) {
if (hybridSymtab && machine == ARM64)
diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp
index 198b6e1cddd1e..0440507b71756 100644
--- a/lld/COFF/DLL.cpp
+++ b/lld/COFF/DLL.cpp
@@ -848,7 +848,7 @@ void IdataContents::create(COFFLinkerContext &ctx) {
: make<NullChunk>(ctx));
addresses.push_back(addressesTerminator ? addressesTerminator
: make<NullChunk>(ctx));
- if (ctx.symtabEC) {
+ if (ctx.symtab.isEC()) {
auxIat.push_back(make<NullChunk>(ctx));
auxIatCopy.push_back(make<NullChunk>(ctx));
}
@@ -998,7 +998,7 @@ void DelayLoadContents::create() {
// Terminate with null values.
addresses.push_back(make<NullChunk>(ctx, 8));
names.push_back(make<NullChunk>(ctx, 8));
- if (ctx.symtabEC) {
+ if (ctx.symtab.isEC()) {
auxIat.push_back(make<NullChunk>(ctx, 8));
auxIatCopy.push_back(make<NullChunk>(ctx, 8));
}
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index d9e70a5be3261..e3ff647209e72 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -659,12 +659,9 @@ void LinkerDriver::setMachine(MachineTypes machine) {
if (machine != ARM64X) {
ctx.symtab.machine = machine;
- if (machine == ARM64EC)
- ctx.symtabEC = &ctx.symtab;
} else {
ctx.symtab.machine = ARM64EC;
ctx.hybridSymtab.emplace(ctx, ARM64);
- ctx.symtabEC = &ctx.symtab;
}
addWinSysRootLibSearchPaths();
@@ -1320,7 +1317,7 @@ void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
expName = saver().save("EXP+" + *mangledName);
else
expName = saver().save("EXP+" + name);
- sym = ctx.symtabEC->addGCRoot(expName);
+ sym = ctx.symtab.addGCRoot(expName);
if (auto undef = dyn_cast<Undefined>(sym)) {
if (!undef->getWeakAlias()) {
auto thunk = make<ECExportThunkChunk>(def);
@@ -1332,13 +1329,13 @@ void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
void LinkerDriver::createECExportThunks() {
// Check if EXP+ symbols have corresponding $hp_target symbols and use them
// to create export thunks when available.
- for (Symbol *s : ctx.symtabEC->expSymbols) {
+ for (Symbol *s : ctx.symtab.expSymbols) {
if (!s->isUsedInRegularObj)
continue;
assert(s->getName().starts_with("EXP+"));
std::string targetName =
(s->getName().substr(strlen("EXP+")) + "$hp_target").str();
- Symbol *sym = ctx.symtabEC->find(targetName);
+ Symbol *sym = ctx.symtab.find(targetName);
if (!sym)
continue;
Defined *targetSym;
@@ -1360,10 +1357,9 @@ void LinkerDriver::createECExportThunks() {
}
}
- if (ctx.symtabEC->entry)
- maybeCreateECExportThunk(ctx.symtabEC->entry->getName(),
- ctx.symtabEC->entry);
- for (Export &e : ctx.symtabEC->exports) {
+ if (ctx.symtab.entry)
+ maybeCreateECExportThunk(ctx.symtab.entry->getName(), ctx.symtab.entry);
+ for (Export &e : ctx.symtab.exports) {
if (!e.data)
maybeCreateECExportThunk(e.extName.empty() ? e.name : e.extName, e.sym);
}
@@ -1372,7 +1368,7 @@ void LinkerDriver::createECExportThunks() {
void LinkerDriver::pullArm64ECIcallHelper() {
if (!ctx.config.arm64ECIcallHelper)
ctx.config.arm64ECIcallHelper =
- ctx.symtabEC->addGCRoot("__icall_helper_arm64ec");
+ ctx.symtab.addGCRoot("__icall_helper_arm64ec");
}
// In MinGW, if no symbols are chosen to be exported, then all symbols are
@@ -2753,8 +2749,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (auto *arg = args.getLastArg(OPT_print_symbol_order))
config->printSymbolOrder = arg->getValue();
- if (ctx.symtabEC)
- ctx.symtabEC->initializeECThunks();
+ if (ctx.symtab.isEC())
+ ctx.symtab.initializeECThunks();
ctx.forEachSymtab([](SymbolTable &symtab) { symtab.initializeLoadConfig(); });
// Identify unreferenced COMDAT sections.
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 7916e3fd4ea1f..7fb42bb681939 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -129,12 +129,12 @@ void ArchiveFile::parse() {
file = CHECK(Archive::create(mb), this);
// Try to read symbols from ECSYMBOLS section on ARM64EC.
- if (ctx.symtabEC) {
+ if (ctx.symtab.isEC()) {
iterator_range<Archive::symbol_iterator> symbols =
CHECK(file->ec_symbols(), this);
if (!symbols.empty()) {
for (const Archive::Symbol &sym : symbols)
- ctx.symtabEC->addLazyArchive(this, sym);
+ ctx.symtab.addLazyArchive(this, sym);
// Read both EC and native symbols on ARM64X.
if (!ctx.hybridSymtab)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 31c686761d74f..a5582cc8074d1 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -581,7 +581,7 @@ bool Writer::createThunks(OutputSection *os, int margin) {
// Create a code map for CHPE metadata.
void Writer::createECCodeMap() {
- if (!ctx.symtabEC)
+ if (!ctx.symtab.isEC())
return;
// Clear the map in case we were're recomputing the map after adding
@@ -617,8 +617,7 @@ void Writer::createECCodeMap() {
closeRange();
- Symbol *tableCountSym =
- ctx.symtabEC->findUnderscore("__hybrid_code_map_count");
+ Symbol *tableCountSym = ctx.symtab.findUnderscore("__hybrid_code_map_count");
cast<DefinedAbsolute>(tableCountSym)->setVA(codeMap.size());
}
@@ -2234,11 +2233,10 @@ void Writer::maybeAddRVATable(SymbolRVASet tableSymbols, StringRef tableSym,
// Create CHPE metadata chunks.
void Writer::createECChunks() {
- SymbolTable *symtab = ctx.symtabEC;
- if (!symtab)
+ if (!ctx.symtab.isEC())
return;
- for (Symbol *s : symtab->expSymbols) {
+ for (Symbol *s : ctx.symtab.expSymbols) {
auto sym = dyn_cast<Defined>(s);
if (!sym || !sym->getChunk())
continue;
@@ -2257,9 +2255,9 @@ void Writer::createECChunks() {
// we should use the #foo$hp_target symbol as the redirection target.
// First, try to look up the $hp_target symbol. If it can't be found,
// assume it's a regular function and look for #foo instead.
- Symbol *targetSym = symtab->find((targetName + "$hp_target").str());
+ Symbol *targetSym = ctx.symtab.find((targetName + "$hp_target").str());
if (!targetSym)
- targetSym = symtab->find(targetName);
+ targetSym = ctx.symtab.find(targetName);
Defined *t = dyn_cast_or_null<Defined>(targetSym);
if (t && isArm64EC(t->getChunk()->getMachine()))
exportThunks.push_back({chunk, t});
@@ -2268,20 +2266,20 @@ void Writer::createECChunks() {
auto codeMapChunk = make<ECCodeMapChunk>(codeMap);
rdataSec->addChunk(codeMapChunk);
- Symbol *codeMapSym = symtab->findUnderscore("__hybrid_code_map");
+ Symbol *codeMapSym = ctx.symtab.findUnderscore("__hybrid_code_map");
replaceSymbol<DefinedSynthetic>(codeMapSym, codeMapSym->getName(),
codeMapChunk);
CHPECodeRangesChunk *ranges = make<CHPECodeRangesChunk>(exportThunks);
rdataSec->addChunk(ranges);
Symbol *rangesSym =
- symtab->findUnderscore("__x64_code_ranges_to_entry_points");
+ ctx.symtab.findUnderscore("__x64_code_ranges_to_entry_points");
replaceSymbol<DefinedSynthetic>(rangesSym, rangesSym->getName(), ranges);
CHPERedirectionChunk *entryPoints = make<CHPERedirectionChunk>(exportThunks);
a64xrmSec->addChunk(entryPoints);
Symbol *entryPointsSym =
- symtab->findUnderscore("__arm64x_redirection_metadata");
+ ctx.symtab.findUnderscore("__arm64x_redirection_metadata");
replaceSymbol<DefinedSynthetic>(entryPointsSym, entryPointsSym->getName(),
entryPoints);
}
@@ -2385,8 +2383,7 @@ void Writer::setSectionPermissions() {
// Set symbols used by ARM64EC metadata.
void Writer::setECSymbols() {
- SymbolTable *symtab = ctx.symtabEC;
- if (!symtab)
+ if (!ctx.symtab.isEC())
return;
llvm::stable_sort(exportThunks, [](const std::pair<Chunk *, Defined *> &a,
@@ -2395,45 +2392,45 @@ void Writer::setECSymbols() {
});
ChunkRange &chpePdata = ctx.hybridSymtab ? hybridPdata : pdata;
- Symbol *rfeTableSym = symtab->findUnderscore("__arm64x_extra_rfe_table");
+ Symbol *rfeTableSym = ctx.symtab.findUnderscore("__arm64x_extra_rfe_table");
replaceSymbol<DefinedSynthetic>(rfeTableSym, "__arm64x_extra_rfe_table",
chpePdata.first);
if (chpePdata.first) {
Symbol *rfeSizeSym =
- symtab->findUnderscore("__arm64x_extra_rfe_table_size");
+ ctx.symtab.findUnderscore("__arm64x_extra_rfe_table_size");
cast<DefinedAbsolute>(rfeSizeSym)
->setVA(chpePdata.last->getRVA() + chpePdata.last->getSize() -
chpePdata.first->getRVA());
}
Symbol *rangesCountSym =
- symtab->findUnderscore("__x64_code_ranges_to_entry_points_count");
+ ctx.symtab.findUnderscore("__x64_code_ranges_to_entry_points_count");
cast<DefinedAbsolute>(rangesCountSym)->setVA(exportThunks.size());
Symbol *entryPointCountSym =
- symtab->findUnderscore("__arm64x_redirection_metadata_count");
+ ctx.symtab.findUnderscore("__arm64x_redirection_metadata_count");
cast<DefinedAbsolute>(entryPointCountSym)->setVA(exportThunks.size());
- Symbol *iatSym = symtab->findUnderscore("__hybrid_auxiliary_iat");
+ Symbol *iatSym = ctx.symtab.findUnderscore("__hybrid_auxiliary_iat");
replaceSymbol<DefinedSynthetic>(iatSym, "__hybrid_auxiliary_iat",
idata.auxIat.empty() ? nullptr
: idata.auxIat.front());
- Symbol *iatCopySym = symtab->findUnderscore("__hybrid_auxiliary_iat_copy");
+ Symbol *iatCopySym = ctx.symtab.findUnderscore("__hybrid_auxiliary_iat_copy");
replaceSymbol<DefinedSynthetic>(
iatCopySym, "__hybrid_auxiliary_iat_copy",
idata.auxIatCopy.empty() ? nullptr : idata.auxIatCopy.front());
Symbol *delayIatSym =
- symtab->findUnderscore("__hybrid_auxiliary_delayload_iat");
+ ctx.symtab.findUnderscore("__hybrid_auxiliary_delayload_iat");
replaceSymbol<DefinedSynthetic>(
delayIatSym, "__hybrid_auxiliary_delayload_iat",
delayIdata.getAuxIat().empty() ? nullptr
: delayIdata.getAuxIat().front());
Symbol *delayIatCopySym =
- symtab->findUnderscore("__hybrid_auxiliary_delayload_iat_copy");
+ ctx.symtab.findUnderscore("__hybrid_auxiliary_delayload_iat_copy");
replaceSymbol<DefinedSynthetic>(
delayIatCopySym, "__hybrid_auxiliary_delayload_iat_copy",
delayIdata.getAuxIatCopy().empty() ? nullptr
@@ -2448,16 +2445,16 @@ void Writer::setECSymbols() {
if (auto thunkChunk =
dyn_cast<ECExportThunkChunk>(altEntrySym->getChunk()))
altEntrySym = thunkChunk->target;
- symtab->findUnderscore("__arm64x_native_entrypoint")
+ ctx.symtab.findUnderscore("__arm64x_native_entrypoint")
->replaceKeepingName(altEntrySym, sizeof(SymbolUnion));
}
- if (symtab->edataStart)
+ if (ctx.symtab.edataStart)
ctx.dynamicRelocs->set(
dataDirOffset64 + EXPORT_TABLE * sizeof(data_directory) +
offsetof(data_directory, Size),
- symtab->edataEnd->getRVA() - symtab->edataStart->getRVA() +
- symtab->edataEnd->getSize());
+ ctx.symtab.edataEnd->getRVA() - ctx.symtab.edataStart->getRVA() +
+ ctx.symtab.edataEnd->getSize());
if (hybridPdata.first) {
ctx.dynamicRelocs->set(
dataDirOffset64 + EXCEPTION_TABLE * sizeof(data_directory) +
More information about the llvm-commits
mailing list