Skip to content

Commit 49ec508

Browse files
committed
[ELF] Pass Ctx & to Writer. NFC
1 parent 3320400 commit 49ec508

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3210,5 +3210,5 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
32103210
}
32113211

32123212
// Write the result to the file.
3213-
writeResult<ELFT>();
3213+
writeResult<ELFT>(ctx);
32143214
}

lld/ELF/Writer.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ template <class ELFT> class Writer {
4949
public:
5050
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
5151

52-
Writer() : buffer(errorHandler().outputBuffer) {}
52+
Writer(Ctx &ctx) : ctx(ctx), buffer(errorHandler().outputBuffer) {}
5353

5454
void run();
5555

@@ -80,6 +80,7 @@ template <class ELFT> class Writer {
8080
void writeSectionsBinary();
8181
void writeBuildId();
8282

83+
Ctx &ctx;
8384
std::unique_ptr<FileOutputBuffer> &buffer;
8485

8586
void addRelIpltSymbols();
@@ -91,8 +92,8 @@ template <class ELFT> class Writer {
9192
};
9293
} // anonymous namespace
9394

94-
template <class ELFT> void elf::writeResult() {
95-
Writer<ELFT>().run();
95+
template <class ELFT> void elf::writeResult(Ctx &ctx) {
96+
Writer<ELFT>(ctx).run();
9697
}
9798

9899
static void removeEmptyPTLoad(SmallVector<PhdrEntry *, 0> &phdrs) {
@@ -2409,8 +2410,8 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
24092410
(config->zSeparate == SeparateSegmentKind::Code && prev &&
24102411
(prev->p_flags & PF_X) != (p->p_flags & PF_X)) ||
24112412
cmd->type == SHT_LLVM_PART_EHDR)
2412-
cmd->addrExpr = [] {
2413-
return alignToPowerOf2(ctx.script->getDot(), config->maxPageSize);
2413+
cmd->addrExpr = [&ctx = this->ctx] {
2414+
return alignToPowerOf2(ctx.script->getDot(), ctx.arg.maxPageSize);
24142415
};
24152416
// PT_TLS is at the start of the first RW PT_LOAD. If `p` includes PT_TLS,
24162417
// it must be the RW. Align to p_align(PT_TLS) to make sure
@@ -2426,15 +2427,15 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
24262427
// bug, musl (TLS Variant 1 architectures) before 1.1.23 handled TLS
24272428
// blocks correctly. We need to keep the workaround for a while.
24282429
else if (ctx.tlsPhdr && ctx.tlsPhdr->firstSec == p->firstSec)
2429-
cmd->addrExpr = [] {
2430-
return alignToPowerOf2(ctx.script->getDot(), config->maxPageSize) +
2431-
alignToPowerOf2(ctx.script->getDot() % config->maxPageSize,
2430+
cmd->addrExpr = [&ctx = this->ctx] {
2431+
return alignToPowerOf2(ctx.script->getDot(), ctx.arg.maxPageSize) +
2432+
alignToPowerOf2(ctx.script->getDot() % ctx.arg.maxPageSize,
24322433
ctx.tlsPhdr->p_align);
24332434
};
24342435
else
2435-
cmd->addrExpr = [] {
2436-
return alignToPowerOf2(ctx.script->getDot(), config->maxPageSize) +
2437-
ctx.script->getDot() % config->maxPageSize;
2436+
cmd->addrExpr = [&ctx = this->ctx] {
2437+
return alignToPowerOf2(ctx.script->getDot(), ctx.arg.maxPageSize) +
2438+
ctx.script->getDot() % ctx.arg.maxPageSize;
24382439
};
24392440
}
24402441
};
@@ -2766,7 +2767,7 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
27662767

27672768
// Open a result file.
27682769
template <class ELFT> void Writer<ELFT>::openFile() {
2769-
uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX;
2770+
uint64_t maxSize = ctx.arg.is64 ? INT64_MAX : UINT32_MAX;
27702771
if (fileSize != size_t(fileSize) || maxSize < fileSize) {
27712772
std::string msg;
27722773
raw_string_ostream s(msg);
@@ -2778,17 +2779,17 @@ template <class ELFT> void Writer<ELFT>::openFile() {
27782779
return;
27792780
}
27802781

2781-
unlinkAsync(config->outputFile);
2782+
unlinkAsync(ctx.arg.outputFile);
27822783
unsigned flags = 0;
2783-
if (!config->relocatable)
2784+
if (!ctx.arg.relocatable)
27842785
flags |= FileOutputBuffer::F_executable;
2785-
if (!config->mmapOutputFile)
2786+
if (!ctx.arg.mmapOutputFile)
27862787
flags |= FileOutputBuffer::F_no_mmap;
27872788
Expected<std::unique_ptr<FileOutputBuffer>> bufferOrErr =
2788-
FileOutputBuffer::create(config->outputFile, fileSize, flags);
2789+
FileOutputBuffer::create(ctx.arg.outputFile, fileSize, flags);
27892790

27902791
if (!bufferOrErr) {
2791-
error("failed to open " + config->outputFile + ": " +
2792+
error("failed to open " + ctx.arg.outputFile + ": " +
27922793
llvm::toString(bufferOrErr.takeError()));
27932794
return;
27942795
}
@@ -2936,7 +2937,7 @@ template <class ELFT> void Writer<ELFT>::writeBuildId() {
29362937
part.buildId->writeBuildId(output);
29372938
}
29382939

2939-
template void elf::writeResult<ELF32LE>();
2940-
template void elf::writeResult<ELF32BE>();
2941-
template void elf::writeResult<ELF64LE>();
2942-
template void elf::writeResult<ELF64BE>();
2940+
template void elf::writeResult<ELF32LE>(Ctx &);
2941+
template void elf::writeResult<ELF32BE>(Ctx &);
2942+
template void elf::writeResult<ELF64LE>(Ctx &);
2943+
template void elf::writeResult<ELF64BE>(Ctx &);

lld/ELF/Writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace lld::elf {
1717
class InputFile;
1818
class OutputSection;
1919
void copySectionsIntoPartitions();
20-
template <class ELFT> void writeResult();
20+
template <class ELFT> void writeResult(Ctx &ctx);
2121

2222
// This describes a program header entry.
2323
// Each contains type, access flags and range of output sections that will be

0 commit comments

Comments
 (0)