summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index dd67fdb38ab..ae21039f34c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -204,8 +204,7 @@ void LinkerScript<ELFT>::assignAddresses(
// https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections.
for (OutputSectionBase<ELFT> *Sec : Sections) {
StringRef Name = Sec->getName();
- auto I = std::find(Opt.SectionOrder.begin(), Opt.SectionOrder.end(), Name);
- if (I == Opt.SectionOrder.end())
+ if (getSectionOrder(Name) == (uint32_t)-1)
Opt.Commands.push_back({SectionKind, {}, Name});
}
@@ -249,15 +248,23 @@ ArrayRef<uint8_t> LinkerScript<ELFT>::getFiller(StringRef Name) {
return I->second;
}
-// A compartor to sort output sections. Returns -1 or 1 if both
-// A and B are mentioned in linker scripts. Otherwise, returns 0
-// to use the default rule which is implemented in Writer.cpp.
+template <class ELFT>
+uint32_t LinkerScript<ELFT>::getSectionOrder(StringRef Name) {
+ auto Begin = Opt.Commands.begin();
+ auto End = Opt.Commands.end();
+ auto I = std::find_if(Begin, End, [&](SectionsCommand &N) {
+ return N.Kind == SectionKind && N.SectionName == Name;
+ });
+ return I == End ? (uint32_t)-1 : (I - Begin);
+}
+
+// A compartor to sort output sections. Returns -1 or 1 if
+// A or B are mentioned in linker script. Otherwise, returns 0.
template <class ELFT>
int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
- auto E = Opt.SectionOrder.end();
- auto I = std::find(Opt.SectionOrder.begin(), E, A);
- auto J = std::find(Opt.SectionOrder.begin(), E, B);
- if (I == E || J == E)
+ uint32_t I = getSectionOrder(A);
+ uint32_t J = getSectionOrder(B);
+ if (I == (uint32_t)-1 && J == (uint32_t)-1)
return 0;
return I < J ? -1 : 1;
}
@@ -509,7 +516,6 @@ void ScriptParser::readLocationCounterValue() {
void ScriptParser::readOutputSectionDescription() {
StringRef OutSec = next();
- Opt.SectionOrder.push_back(OutSec);
Opt.Commands.push_back({SectionKind, {}, OutSec});
expect(":");
expect("{");
OpenPOWER on IntegriCloud