summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-03-13 09:18:11 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-03-13 09:18:11 +0000
commit796684b451b42c72a1c963ea8e1aa47e974c5cc4 (patch)
tree819cd07bb6089a47b69686897e34aca1e42b4fb3 /lld/ELF/LinkerScript.cpp
parentebc1d1fddec15d941c88e07bf98e67557b5fda88 (diff)
downloadbcm5719-llvm-796684b451b42c72a1c963ea8e1aa47e974c5cc4.tar.gz
bcm5719-llvm-796684b451b42c72a1c963ea8e1aa47e974c5cc4.zip
[ELF] - Implement INSERT BEFORE.
This finishes PR35877. INSERT BEFORE used similar to INSERT AFTER, it inserts sections before the given target section. Differential revision: https://reviews.llvm.org/D44380 llvm-svn: 327378
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index fcfe0783300..fd101a0b0cd 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -207,18 +207,26 @@ static void declareSymbol(SymbolAssignment *Cmd) {
// the list of script commands to mix sections inserted into.
void LinkerScript::processInsertCommands() {
std::vector<BaseCommand *> V;
+ auto Insert = [&](std::vector<BaseCommand *> &From) {
+ V.insert(V.end(), From.begin(), From.end());
+ From.clear();
+ };
+
for (BaseCommand *Base : SectionCommands) {
- V.push_back(Base);
- if (auto *Cmd = dyn_cast<OutputSection>(Base)) {
- std::vector<BaseCommand *> &W = InsertAfterCommands[Cmd->Name];
- V.insert(V.end(), W.begin(), W.end());
- W.clear();
+ if (auto *OS = dyn_cast<OutputSection>(Base)) {
+ Insert(InsertBeforeCommands[OS->Name]);
+ V.push_back(Base);
+ Insert(InsertAfterCommands[OS->Name]);
+ continue;
}
+ V.push_back(Base);
}
- for (std::pair<StringRef, std::vector<BaseCommand *>> &P :
- InsertAfterCommands)
- if (!P.second.empty())
- error("unable to INSERT AFTER " + P.first + ": section not defined");
+
+ for (auto &Cmds : {InsertBeforeCommands, InsertAfterCommands})
+ for (const std::pair<StringRef, std::vector<BaseCommand *>> &P : Cmds)
+ if (!P.second.empty())
+ error("unable to INSERT AFTER/BEFORE " + P.first +
+ ": section not defined");
SectionCommands = std::move(V);
}
OpenPOWER on IntegriCloud