Remove ScriptConfiguration class and move the members to LinkerScript class.
ScriptConfiguration was a class to contain parsed results of
linker scripts. LinkerScript is a class to interpret it.
That ditinction was needed because we haven't instantiated
LinkerScript early (because, IIRC, LinkerScript class was a
ELFT template function). So, when we parse linker scripts,
we couldn't directly store the result to a LinkerScript instance.
Now, that limitation is gone. We instantiate LinkerScript
at the very beginning of our main function. We can directly
store parse results to a LinkerScript instance.
llvm-svn: 315403
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0cc506e..cdc2c0e 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -161,7 +161,7 @@
addReservedSymbols();
// Create output sections.
- if (Script->Opt.HasSections) {
+ if (Script->HasSections) {
// If linker script contains SECTIONS commands, let it create sections.
Script->processCommands(Factory);
@@ -466,7 +466,7 @@
template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
// Create one STT_SECTION symbol for each output section we might
// have a relocation with.
- for (BaseCommand *Base : Script->Opt.Commands) {
+ for (BaseCommand *Base : Script->Commands) {
auto *Sec = dyn_cast<OutputSection>(Base);
if (!Sec)
continue;
@@ -813,7 +813,7 @@
addOptionalRegular<ELFT>(Name, Out::ElfHeader, 0, STV_HIDDEN);
// If linker script do layout we do not need to create any standart symbols.
- if (Script->Opt.HasSections)
+ if (Script->HasSections)
return;
auto Add = [](StringRef S, int64_t Pos) {
@@ -849,7 +849,7 @@
// Sort sections by priority.
DenseMap<SectionBase *, int> SectionOrder = buildSectionOrder();
- for (BaseCommand *Base : Script->Opt.Commands)
+ for (BaseCommand *Base : Script->Commands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
Sec->sort([&](InputSectionBase *S) { return SectionOrder.lookup(S); });
}
@@ -876,8 +876,7 @@
Factory.addInputSec(IS, getOutputSectionName(IS->Name)))
Vec.push_back(Sec);
- Script->Opt.Commands.insert(Script->Opt.Commands.begin(), Vec.begin(),
- Vec.end());
+ Script->Commands.insert(Script->Commands.begin(), Vec.begin(), Vec.end());
Script->fabricateDefaultCommands();
sortBySymbolsOrder();
@@ -1052,15 +1051,15 @@
if (Config->Relocatable)
return;
- for (BaseCommand *Base : Script->Opt.Commands)
+ for (BaseCommand *Base : Script->Commands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
Sec->SortRank = getSectionRank(Sec);
- if (!Script->Opt.HasSections) {
+ if (!Script->HasSections) {
// We know that all the OutputSections are contiguous in
// this case.
- auto E = Script->Opt.Commands.end();
- auto I = Script->Opt.Commands.begin();
+ auto E = Script->Commands.end();
+ auto I = Script->Commands.begin();
auto IsSection = [](BaseCommand *Base) { return isa<OutputSection>(Base); };
I = std::find_if(I, E, IsSection);
E = std::find_if(llvm::make_reverse_iterator(E),
@@ -1101,7 +1100,7 @@
// a PT_LOAD.
//
// There is some ambiguity as to where exactly a new entry should be
- // inserted, because Opt.Commands contains not only output section
+ // inserted, because Commands contains not only output section
// commands but also other types of commands such as symbol assignment
// expressions. There's no correct answer here due to the lack of the
// formal specification of the linker script. We use heuristics to
@@ -1109,8 +1108,8 @@
// after another commands. For the details, look at shouldSkip
// function.
- auto I = Script->Opt.Commands.begin();
- auto E = Script->Opt.Commands.end();
+ auto I = Script->Commands.begin();
+ auto E = Script->Commands.end();
auto NonScriptI = std::find_if(I, E, [](BaseCommand *Base) {
if (auto *Sec = dyn_cast<OutputSection>(Base))
return Sec->Live && Sec->SectionIndex == INT_MAX;
@@ -1241,7 +1240,7 @@
// addresses of each section by section name. Add such symbols.
if (!Config->Relocatable) {
addStartEndSymbols();
- for (BaseCommand *Base : Script->Opt.Commands)
+ for (BaseCommand *Base : Script->Commands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
addStartStopSymbols(Sec);
}
@@ -1305,7 +1304,7 @@
// Now that we have the final list, create a list of all the
// OutputSections for convenience.
- for (BaseCommand *Base : Script->Opt.Commands)
+ for (BaseCommand *Base : Script->Commands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
OutputSections.push_back(Sec);
@@ -1356,7 +1355,7 @@
InX::Dynamic},
[](SyntheticSection *SS) { SS->finalizeContents(); });
- if (!Script->Opt.HasSections && !Config->Relocatable)
+ if (!Script->HasSections && !Config->Relocatable)
fixSectionAlignments();
// Some architectures use small displacements for jump instructions.
@@ -1441,7 +1440,7 @@
}
template <class ELFT> OutputSection *Writer<ELFT>::findSection(StringRef Name) {
- for (BaseCommand *Base : Script->Opt.Commands)
+ for (BaseCommand *Base : Script->Commands)
if (auto *Sec = dyn_cast<OutputSection>(Base))
if (Sec->Name == Name)
return Sec;
@@ -1682,7 +1681,7 @@
for (OutputSection *Sec : OutputSections) {
Off = setOffset(Sec, Off);
- if (Script->Opt.HasSections)
+ if (Script->HasSections)
continue;
// If this is a last section of the last executable segment and that
// segment is the last loadable segment, align the offset of the
@@ -1861,7 +1860,7 @@
// We'll leave other pages in segments as-is because the rest will be
// overwritten by output sections.
template <class ELFT> void Writer<ELFT>::writeTrapInstr() {
- if (Script->Opt.HasSections)
+ if (Script->HasSections)
return;
// Fill the last page.