Skip to content

Commit 845a443

Browse files
committed
[LLD][COFF] Store reference to SymbolTable instead of COFFLinkerContext in InputFile (NFC)
This change prepares for the introduction of separate hybrid namespaces. Hybrid images will require two SymbolTable instances, making it necessary to associate InputFile objects with the relevant one.
1 parent 8630a7b commit 845a443

File tree

9 files changed

+133
-122
lines changed

9 files changed

+133
-122
lines changed

lld/COFF/Chunks.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SectionChunk::SectionChunk(ObjFile *f, const coff_section *h, Kind k)
5656
// files will be built with -ffunction-sections or /Gy, so most things worth
5757
// stripping will be in a comdat.
5858
if (file)
59-
live = !file->ctx.config.doGC || !isCOMDAT();
59+
live = !file->symtab.ctx.config.doGC || !isCOMDAT();
6060
else
6161
live = true;
6262
}
@@ -129,7 +129,7 @@ void SectionChunk::applyRelX64(uint8_t *off, uint16_t type, OutputSection *os,
129129
case IMAGE_REL_AMD64_REL32_4: add32(off, s - p - 8); break;
130130
case IMAGE_REL_AMD64_REL32_5: add32(off, s - p - 9); break;
131131
case IMAGE_REL_AMD64_SECTION:
132-
applySecIdx(off, os, file->ctx.outputSections.size());
132+
applySecIdx(off, os, file->symtab.ctx.outputSections.size());
133133
break;
134134
case IMAGE_REL_AMD64_SECREL: applySecRel(this, off, os, s); break;
135135
default:
@@ -149,7 +149,7 @@ void SectionChunk::applyRelX86(uint8_t *off, uint16_t type, OutputSection *os,
149149
case IMAGE_REL_I386_DIR32NB: add32(off, s); break;
150150
case IMAGE_REL_I386_REL32: add32(off, s - p - 4); break;
151151
case IMAGE_REL_I386_SECTION:
152-
applySecIdx(off, os, file->ctx.outputSections.size());
152+
applySecIdx(off, os, file->symtab.ctx.outputSections.size());
153153
break;
154154
case IMAGE_REL_I386_SECREL: applySecRel(this, off, os, s); break;
155155
default:
@@ -225,7 +225,7 @@ void SectionChunk::applyRelARM(uint8_t *off, uint16_t type, OutputSection *os,
225225
case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(off, sx - p - 4); break;
226226
case IMAGE_REL_ARM_BLX23T: applyBranch24T(off, sx - p - 4); break;
227227
case IMAGE_REL_ARM_SECTION:
228-
applySecIdx(off, os, file->ctx.outputSections.size());
228+
applySecIdx(off, os, file->symtab.ctx.outputSections.size());
229229
break;
230230
case IMAGE_REL_ARM_SECREL: applySecRel(this, off, os, s); break;
231231
case IMAGE_REL_ARM_REL32: add32(off, sx - p - 4); break;
@@ -346,7 +346,7 @@ void SectionChunk::applyRelARM64(uint8_t *off, uint16_t type, OutputSection *os,
346346
case IMAGE_REL_ARM64_SECREL_HIGH12A: applySecRelHigh12A(this, off, os, s); break;
347347
case IMAGE_REL_ARM64_SECREL_LOW12L: applySecRelLdr(this, off, os, s); break;
348348
case IMAGE_REL_ARM64_SECTION:
349-
applySecIdx(off, os, file->ctx.outputSections.size());
349+
applySecIdx(off, os, file->symtab.ctx.outputSections.size());
350350
break;
351351
case IMAGE_REL_ARM64_REL32: add32(off, s - p - 4); break;
352352
default:
@@ -427,23 +427,24 @@ void SectionChunk::applyRelocation(uint8_t *off,
427427
// section is needed to compute SECREL and SECTION relocations used in debug
428428
// info.
429429
Chunk *c = sym ? sym->getChunk() : nullptr;
430-
OutputSection *os = c ? file->ctx.getOutputSection(c) : nullptr;
430+
COFFLinkerContext &ctx = file->symtab.ctx;
431+
OutputSection *os = c ? ctx.getOutputSection(c) : nullptr;
431432

432433
// Skip the relocation if it refers to a discarded section, and diagnose it
433434
// as an error if appropriate. If a symbol was discarded early, it may be
434435
// null. If it was discarded late, the output section will be null, unless
435436
// it was an absolute or synthetic symbol.
436437
if (!sym ||
437438
(!os && !isa<DefinedAbsolute>(sym) && !isa<DefinedSynthetic>(sym))) {
438-
maybeReportRelocationToDiscarded(this, sym, rel, file->ctx.config.mingw);
439+
maybeReportRelocationToDiscarded(this, sym, rel, ctx.config.mingw);
439440
return;
440441
}
441442

442443
uint64_t s = sym->getRVA();
443444

444445
// Compute the RVA of the relocation for relative relocations.
445446
uint64_t p = rva + rel.VirtualAddress;
446-
uint64_t imageBase = file->ctx.config.imageBase;
447+
uint64_t imageBase = ctx.config.imageBase;
447448
switch (getArch()) {
448449
case Triple::x86_64:
449450
applyRelX64(off, rel.Type, os, s, p, imageBase);
@@ -669,7 +670,7 @@ void SectionChunk::getRuntimePseudoRelocs(
669670
toString(file));
670671
continue;
671672
}
672-
int addressSizeInBits = file->ctx.config.is64() ? 64 : 32;
673+
int addressSizeInBits = file->symtab.ctx.config.is64() ? 64 : 32;
673674
if (sizeInBits < addressSizeInBits) {
674675
warn("runtime pseudo relocation in " + toString(file) + " against " +
675676
"symbol " + target->getName() + " is too narrow (only " +
@@ -1098,7 +1099,7 @@ void CHPERedirectionChunk::writeTo(uint8_t *buf) const {
10981099
}
10991100

11001101
ImportThunkChunkARM64EC::ImportThunkChunkARM64EC(ImportFile *file)
1101-
: ImportThunkChunk(file->ctx, file->impSym), file(file) {}
1102+
: ImportThunkChunk(file->symtab.ctx, file->impSym), file(file) {}
11021103

11031104
size_t ImportThunkChunkARM64EC::getSize() const {
11041105
if (!extended)
@@ -1122,7 +1123,7 @@ void ImportThunkChunkARM64EC::writeTo(uint8_t *buf) const {
11221123
applyArm64Addr(buf + 8, exitThunkRVA, rva + 8, 12);
11231124
applyArm64Imm(buf + 12, exitThunkRVA & 0xfff, 0);
11241125

1125-
Defined *helper = cast<Defined>(file->ctx.config.arm64ECIcallHelper);
1126+
Defined *helper = cast<Defined>(file->symtab.ctx.config.arm64ECIcallHelper);
11261127
if (extended) {
11271128
// Replace last instruction with an inline range extension thunk.
11281129
memcpy(buf + 16, arm64Thunk, sizeof(arm64Thunk));
@@ -1136,7 +1137,7 @@ void ImportThunkChunkARM64EC::writeTo(uint8_t *buf) const {
11361137
bool ImportThunkChunkARM64EC::verifyRanges() {
11371138
if (extended)
11381139
return true;
1139-
auto helper = cast<Defined>(file->ctx.config.arm64ECIcallHelper);
1140+
auto helper = cast<Defined>(file->symtab.ctx.config.arm64ECIcallHelper);
11401141
return isInt<28>(helper->getRVA() - rva - 16);
11411142
}
11421143

lld/COFF/DLL.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ class AuxImportChunk : public NonSectionChunk {
160160
void writeTo(uint8_t *buf) const override {
161161
uint64_t impchkVA = 0;
162162
if (file->impchkThunk)
163-
impchkVA = file->impchkThunk->getRVA() + file->ctx.config.imageBase;
163+
impchkVA =
164+
file->impchkThunk->getRVA() + file->symtab.ctx.config.imageBase;
164165
write64le(buf, impchkVA);
165166
}
166167

167168
void getBaserels(std::vector<Baserel> *res) override {
168169
if (file->impchkThunk)
169-
res->emplace_back(rva, file->ctx.config.machine);
170+
res->emplace_back(rva, file->symtab.ctx.config.machine);
170171
}
171172

172173
private:

lld/COFF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
241241
break;
242242
case file_magic::pecoff_executable:
243243
if (ctx.config.mingw) {
244-
ctx.symtab.addFile(make<DLLFile>(ctx, mbref));
244+
ctx.symtab.addFile(make<DLLFile>(ctx.symtab, mbref));
245245
break;
246246
}
247247
if (filename.ends_with_insensitive(".dll")) {

0 commit comments

Comments
 (0)