summaryrefslogtreecommitdiff
path: root/lld/ELF/Writer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/Writer.cpp')
-rw-r--r--lld/ELF/Writer.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 69fcad390d61..9383ac46c8e7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -315,8 +315,7 @@ template <class ELFT> void elf::createSyntheticSections() {
// If there is a SECTIONS command and a .data.rel.ro section name use name
// .data.rel.ro.bss so that we match in the .data.rel.ro output section.
// This makes sure our relro is contiguous.
- bool hasDataRelRo =
- script->hasSectionsCommand && findSection(".data.rel.ro", 0);
+ bool hasDataRelRo = script->hasSectionsCommand && findSection(".data.rel.ro");
in.bssRelRo = std::make_unique<BssSection>(
hasDataRelRo ? ".data.rel.ro.bss" : ".bss.rel.ro", 0, 1);
add(*in.bssRelRo);
@@ -327,12 +326,12 @@ template <class ELFT> void elf::createSyntheticSections() {
in.mipsRldMap = std::make_unique<MipsRldMapSection>();
add(*in.mipsRldMap);
}
- if (auto *sec = MipsAbiFlagsSection<ELFT>::create())
- add(*sec);
- if (auto *sec = MipsOptionsSection<ELFT>::create())
- add(*sec);
- if (auto *sec = MipsReginfoSection<ELFT>::create())
- add(*sec);
+ if ((in.mipsAbiFlags = MipsAbiFlagsSection<ELFT>::create()))
+ add(*in.mipsAbiFlags);
+ if ((in.mipsOptions = MipsOptionsSection<ELFT>::create()))
+ add(*in.mipsOptions);
+ if ((in.mipsReginfo = MipsReginfoSection<ELFT>::create()))
+ add(*in.mipsReginfo);
}
StringRef relaDynName = config->isRela ? ".rela.dyn" : ".rel.dyn";
@@ -1430,22 +1429,19 @@ template <class ELFT> void Writer<ELFT>::sortInputSections() {
template <class ELFT> void Writer<ELFT>::sortSections() {
llvm::TimeTraceScope timeScope("Sort sections");
- script->adjustSectionsBeforeSorting();
// Don't sort if using -r. It is not necessary and we want to preserve the
// relative order for SHF_LINK_ORDER sections.
- if (config->relocatable)
+ if (config->relocatable) {
+ script->adjustOutputSections();
return;
+ }
sortInputSections();
- for (SectionCommand *cmd : script->sectionCommands) {
- auto *os = dyn_cast<OutputSection>(cmd);
- if (!os)
- continue;
- os->sortRank = getSectionRank(os);
- }
-
+ for (SectionCommand *cmd : script->sectionCommands)
+ if (auto *osec = dyn_cast_or_null<OutputSection>(cmd))
+ osec->sortRank = getSectionRank(osec);
if (!script->hasSectionsCommand) {
// We know that all the OutputSections are contiguous in this case.
auto isSection = [](SectionCommand *cmd) {
@@ -1455,14 +1451,15 @@ template <class ELFT> void Writer<ELFT>::sortSections() {
llvm::find_if(script->sectionCommands, isSection),
llvm::find_if(llvm::reverse(script->sectionCommands), isSection).base(),
compareSections);
-
- // Process INSERT commands. From this point onwards the order of
- // script->sectionCommands is fixed.
- script->processInsertCommands();
- return;
}
+ // Process INSERT commands and update output section attributes. From this
+ // point onwards the order of script->sectionCommands is fixed.
script->processInsertCommands();
+ script->adjustOutputSections();
+
+ if (!script->hasSectionsCommand)
+ return;
// Orphan sections are sections present in the input files which are
// not explicitly placed into the output file by the linker script.
@@ -1571,8 +1568,8 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
// Link order may be distributed across several InputSectionDescriptions.
// Sorting is performed separately.
- std::vector<InputSection **> scriptSections;
- std::vector<InputSection *> sections;
+ SmallVector<InputSection **, 0> scriptSections;
+ SmallVector<InputSection *, 0> sections;
for (SectionCommand *cmd : sec->commands) {
auto *isd = dyn_cast<InputSectionDescription>(cmd);
if (!isd)
@@ -2086,11 +2083,16 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Dynamic section must be the last one in this list and dynamic
// symbol table section (dynSymTab) must be the first one.
for (Partition &part : partitions) {
+ if (part.relaDyn) {
+ // Compute DT_RELACOUNT to be used by part.dynamic.
+ part.relaDyn->partitionRels();
+ finalizeSynthetic(part.relaDyn.get());
+ }
+
finalizeSynthetic(part.dynSymTab.get());
finalizeSynthetic(part.gnuHashTab.get());
finalizeSynthetic(part.hashTab.get());
finalizeSynthetic(part.verDef.get());
- finalizeSynthetic(part.relaDyn.get());
finalizeSynthetic(part.relrDyn.get());
finalizeSynthetic(part.ehFrameHdr.get());
finalizeSynthetic(part.verSym.get());