Skip to content

Commit bb0a6f2

Browse files
committed
[ELF] Pass Ctx to LinkerScript. NFC
1 parent 6b56a27 commit bb0a6f2

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

lld/ELF/Driver.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,33 @@ namespace elf {
148148
bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
149149
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput) {
150150
// This driver-specific context will be freed later by unsafeLldMain().
151-
auto *ctx = new CommonLinkerContext;
151+
auto *context = new CommonLinkerContext;
152152

153-
ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
154-
ctx->e.cleanupCallback = []() {
153+
context->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
154+
context->e.cleanupCallback = []() {
155155
elf::ctx.reset();
156156
elf::ctx.partitions.emplace_back();
157157
symtab = SymbolTable();
158158

159159
SharedFile::vernauxNum = 0;
160160
};
161-
ctx->e.logName = args::getFilenameWithoutExe(args[0]);
162-
ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
163-
"--error-limit=0 to see all errors)";
161+
context->e.logName = args::getFilenameWithoutExe(args[0]);
162+
context->e.errorLimitExceededMsg =
163+
"too many errors emitted, stopping now (use "
164+
"--error-limit=0 to see all errors)";
164165

165166
config = ConfigWrapper();
166167

167-
LinkerScript script;
168-
elf::ctx.script = &script;
169-
elf::ctx.symAux.emplace_back();
168+
LinkerScript script(ctx);
169+
ctx.script = &script;
170+
ctx.symAux.emplace_back();
170171

171-
elf::ctx.partitions.clear();
172-
elf::ctx.partitions.emplace_back();
172+
ctx.partitions.clear();
173+
ctx.partitions.emplace_back();
173174

174175
config->progName = args[0];
175176

176-
elf::ctx.driver.linkerMain(args);
177+
ctx.driver.linkerMain(args);
177178

178179
return errorCount() == 0;
179180
}

lld/ELF/LinkerScript.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ void LinkerScript::processSymbolAssignments() {
834834
// `st` captures the local AddressState and makes it accessible deliberately.
835835
// This is needed as there are some cases where we cannot just thread the
836836
// current state through to a lambda function created by the script parser.
837-
AddressState st;
837+
AddressState st(*this);
838838
state = &st;
839839
st.outSec = aether;
840840

@@ -1468,8 +1468,8 @@ void LinkerScript::allocateHeaders(SmallVector<PhdrEntry *, 0> &phdrs) {
14681468
[](const PhdrEntry *e) { return e->p_type == PT_PHDR; });
14691469
}
14701470

1471-
LinkerScript::AddressState::AddressState() {
1472-
for (auto &mri : ctx.script->memoryRegions) {
1471+
LinkerScript::AddressState::AddressState(const LinkerScript &script) {
1472+
for (auto &mri : script.memoryRegions) {
14731473
MemoryRegion *mr = mri.second;
14741474
mr->curPos = (mr->origin)().getValue();
14751475
}
@@ -1495,7 +1495,7 @@ LinkerScript::assignAddresses() {
14951495
}
14961496

14971497
OutputSection *changedOsec = nullptr;
1498-
AddressState st;
1498+
AddressState st(*this);
14991499
state = &st;
15001500
errorOnMissingSection = true;
15011501
st.outSec = aether;

lld/ELF/LinkerScript.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,15 @@ class LinkerScript final {
290290
// that must be reinitialized for each call to the above functions, and must
291291
// not be used outside of the scope of a call to the above functions.
292292
struct AddressState {
293-
AddressState();
293+
AddressState(const LinkerScript &);
294294
OutputSection *outSec = nullptr;
295295
MemoryRegion *memRegion = nullptr;
296296
MemoryRegion *lmaRegion = nullptr;
297297
uint64_t lmaOffset = 0;
298298
uint64_t tbssAddr = 0;
299299
};
300300

301+
Ctx &ctx;
301302
llvm::DenseMap<llvm::CachedHashStringRef, OutputDesc *> nameToOutputSection;
302303

303304
StringRef getOutputSectionName(const InputSectionBase *s) const;
@@ -335,6 +336,7 @@ class LinkerScript final {
335336
uint64_t dot = 0;
336337

337338
public:
339+
LinkerScript(Ctx &ctx) : ctx(ctx) {}
338340
OutputDesc *createOutputSection(StringRef name, StringRef location);
339341
OutputDesc *getOrCreateOutputSection(StringRef name);
340342

0 commit comments

Comments
 (0)