Make OutputSections and OutputSectionCommands globals.
This is similar to what we do for InputSections and makes them easier
to access.
llvm-svn: 305337
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 8624c5d..fff1242 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -458,7 +458,7 @@
// For each OutputSection that needs a VA fabricate an OutputSectionCommand
// with an InputSectionDescription describing the InputSections
- for (OutputSection *Sec : *OutputSections) {
+ for (OutputSection *Sec : OutputSections) {
auto *OSCmd = createOutputSectionCommand(Sec->Name, "<internal>");
OSCmd->Sec = Sec;
SecToCommand[Sec] = OSCmd;
@@ -680,8 +680,8 @@
auto Pos = std::remove_if(
Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) {
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
- return std::find(OutputSections->begin(), OutputSections->end(),
- Cmd->Sec) == OutputSections->end();
+ return std::find(OutputSections.begin(), OutputSections.end(),
+ Cmd->Sec) == OutputSections.end();
return false;
});
Opt.Commands.erase(Pos, Opt.Commands.end());
@@ -715,7 +715,7 @@
auto *OutSec = make<OutputSection>(Cmd->Name, SHT_PROGBITS, Flags);
OutSec->SectionIndex = I;
- OutputSections->push_back(OutSec);
+ OutputSections.push_back(OutSec);
Cmd->Sec = OutSec;
SecToCommand[OutSec] = Cmd;
}
@@ -826,7 +826,7 @@
++CmdIndex;
}
- for (OutputSection *Sec : *OutputSections) {
+ for (OutputSection *Sec : OutputSections) {
StringRef Name = Sec->Name;
// Find the last spot where we can insert a command and still get the
@@ -921,9 +921,7 @@
return false;
}
-void LinkerScript::assignAddresses(
- std::vector<PhdrEntry> &Phdrs,
- ArrayRef<OutputSectionCommand *> OutputSectionCommands) {
+void LinkerScript::assignAddresses(std::vector<PhdrEntry> &Phdrs) {
// Assign addresses as instructed by linker script SECTIONS sub-commands.
Dot = 0;
ErrorOnMissingSection = true;
@@ -955,8 +953,7 @@
}
// Creates program headers as instructed by PHDRS linker script command.
-std::vector<PhdrEntry> LinkerScript::createPhdrs(
- ArrayRef<OutputSectionCommand *> OutputSectionCommands) {
+std::vector<PhdrEntry> LinkerScript::createPhdrs() {
std::vector<PhdrEntry> Ret;
// Process PHDRS and FILEHDR keywords because they are not
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 8a5eb37..fed456f 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -267,15 +267,13 @@
ExprValue getSymbolValue(const Twine &Loc, StringRef S);
bool isDefined(StringRef S);
- std::vector<OutputSection *> *OutputSections;
void fabricateDefaultCommands();
void addOrphanSections(OutputSectionFactory &Factory);
void removeEmptyCommands();
void adjustSectionsBeforeSorting();
void adjustSectionsAfterSorting();
- std::vector<PhdrEntry>
- createPhdrs(ArrayRef<OutputSectionCommand *> OutputSectionCommands);
+ std::vector<PhdrEntry> createPhdrs();
bool ignoreInterpSection();
bool hasLMA(OutputSection *Sec);
@@ -283,8 +281,7 @@
void assignOffsets(OutputSectionCommand *Cmd);
void placeOrphanSections();
void processNonSectionCommands();
- void assignAddresses(std::vector<PhdrEntry> &Phdrs,
- ArrayRef<OutputSectionCommand *> OutputSectionCommands);
+ void assignAddresses(std::vector<PhdrEntry> &Phdrs);
void addSymbol(SymbolAssignment *Cmd);
void processCommands(OutputSectionFactory &Factory);
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 008871f..6f04a04 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -41,6 +41,9 @@
OutputSection *Out::InitArray;
OutputSection *Out::FiniArray;
+std::vector<OutputSection *> elf::OutputSections;
+std::vector<OutputSectionCommand *> elf::OutputSectionCommands;
+
uint32_t OutputSection::getPhdrFlags() const {
uint32_t Ret = PF_R;
if (Flags & SHF_WRITE)
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index 7b093fb..d5f7783 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -150,6 +150,8 @@
uint64_t getHeaderSize();
void reportDiscarded(InputSectionBase *IS);
+extern std::vector<OutputSection *> OutputSections;
+extern std::vector<OutputSectionCommand *> OutputSectionCommands;
} // namespace elf
} // namespace lld
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 1112ad2..d9a450f 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -73,8 +73,6 @@
std::unique_ptr<FileOutputBuffer> Buffer;
- std::vector<OutputSection *> OutputSections;
- std::vector<OutputSectionCommand *> OutputSectionCommands;
OutputSectionFactory Factory{OutputSections};
void addRelIpltSymbols();
@@ -174,7 +172,6 @@
addReservedSymbols();
// Create output sections.
- Script->OutputSections = &OutputSections;
if (Script->Opt.HasSections) {
// If linker script contains SECTIONS commands, let it create sections.
Script->processCommands(Factory);
@@ -215,7 +212,7 @@
OutputSectionCommands.begin(), OutputSectionCommands.end(),
[](OutputSectionCommand *Cmd) { Cmd->maybeCompress<ELFT>(); });
- Script->assignAddresses(Phdrs, OutputSectionCommands);
+ Script->assignAddresses(Phdrs);
// Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
// 0 sized region. This has to be done late since only after assignAddresses
@@ -1174,9 +1171,7 @@
// The headers have to be created before finalize as that can influence the
// image base and the dynamic section on mips includes the image base.
if (!Config->Relocatable && !Config->OFormatBinary) {
- Phdrs = Script->hasPhdrsCommands()
- ? Script->createPhdrs(OutputSectionCommands)
- : createPhdrs();
+ Phdrs = Script->hasPhdrsCommands() ? Script->createPhdrs() : createPhdrs();
addPtArmExid(Phdrs);
Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
}