summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputSection.cpp5
-rw-r--r--lld/ELF/LinkerScript.cpp13
-rw-r--r--lld/ELF/LinkerScript.h7
3 files changed, 16 insertions, 9 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 4593cc4cf34..35f4df42134 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -46,6 +46,10 @@ std::string lld::toString(const InputSectionBase *Sec) {
}
DenseMap<SectionBase *, int> elf::buildSectionOrder() {
+ DenseMap<SectionBase *, int> SectionOrder;
+ if (Config->SymbolOrderingFile.empty())
+ return SectionOrder;
+
// Build a map from symbols to their priorities. Symbols that didn't
// appear in the symbol ordering file have the lowest priority 0.
// All explicitly mentioned symbols have negative (higher) priorities.
@@ -55,7 +59,6 @@ DenseMap<SectionBase *, int> elf::buildSectionOrder() {
SymbolOrder.insert({S, Priority++});
// Build a map from sections to their priorities.
- DenseMap<SectionBase *, int> SectionOrder;
for (InputFile *File : ObjectFiles) {
for (SymbolBody *Body : File->getSymbols()) {
auto *D = dyn_cast<DefinedRegular>(Body);
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index b75802f4036..31fe3b9be49 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -274,9 +274,9 @@ static void sortInputSections(
// Compute and remember which sections the InputSectionDescription matches.
std::vector<InputSection *>
-LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
+LinkerScript::computeInputSections(const InputSectionDescription *Cmd,
+ const DenseMap<SectionBase *, int> &Order) {
std::vector<InputSection *> Ret;
- DenseMap<SectionBase *, int> Order = buildSectionOrder();
// Collects all sections that satisfy constraints of Cmd.
for (const SectionPattern &Pat : Cmd->SectionPatterns) {
@@ -326,13 +326,13 @@ void LinkerScript::discard(ArrayRef<InputSection *> V) {
}
}
-std::vector<InputSection *>
-LinkerScript::createInputSectionList(OutputSection &OutCmd) {
+std::vector<InputSection *> LinkerScript::createInputSectionList(
+ OutputSection &OutCmd, const DenseMap<SectionBase *, int> &Order) {
std::vector<InputSection *> Ret;
for (BaseCommand *Base : OutCmd.SectionCommands) {
if (auto *Cmd = dyn_cast<InputSectionDescription>(Base)) {
- Cmd->Sections = computeInputSections(Cmd);
+ Cmd->Sections = computeInputSections(Cmd, Order);
Ret.insert(Ret.end(), Cmd->Sections.begin(), Cmd->Sections.end());
}
}
@@ -359,6 +359,7 @@ void LinkerScript::processSectionCommands() {
Ctx = make_unique<AddressState>();
Ctx->OutSec = Aether;
+ DenseMap<SectionBase *, int> Order = buildSectionOrder();
// Add input sections to output sections.
for (size_t I = 0; I < SectionCommands.size(); ++I) {
// Handle symbol assignments outside of any output section.
@@ -368,7 +369,7 @@ void LinkerScript::processSectionCommands() {
}
if (auto *Sec = dyn_cast<OutputSection>(SectionCommands[I])) {
- std::vector<InputSection *> V = createInputSectionList(*Sec);
+ std::vector<InputSection *> V = createInputSectionList(*Sec, Order);
// The output section name `/DISCARD/' is special.
// Any input section assigned to it is discarded.
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 03c83922189..1afb27cd3f5 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -205,9 +205,12 @@ class LinkerScript final {
void setDot(Expr E, const Twine &Loc, bool InSec);
std::vector<InputSection *>
- computeInputSections(const InputSectionDescription *);
+ computeInputSections(const InputSectionDescription *,
+ const llvm::DenseMap<SectionBase *, int> &Order);
- std::vector<InputSection *> createInputSectionList(OutputSection &Cmd);
+ std::vector<InputSection *>
+ createInputSectionList(OutputSection &Cmd,
+ const llvm::DenseMap<SectionBase *, int> &Order);
std::vector<size_t> getPhdrIndices(OutputSection *Sec);
OpenPOWER on IntegriCloud