From 337f903c6c40da9cc57b0af5ccca2560330b9cbe Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 14 Nov 2016 14:13:32 +0000 Subject: [PATCH] Factor out placeOrphanSections. NFC. llvm-svn: 286824 --- lld/ELF/LinkerScript.cpp | 16 +++++++++------- lld/ELF/LinkerScript.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 0cd4f82..2cb1662 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -583,14 +583,11 @@ static bool shouldSkip(const BaseCommand &Cmd) { return Assign->Name != "."; } +// Orphan sections are sections present in the input files which are not +// explicitly placed into the output file by the linker script. This just +// places them in the order already decided in OutputSections. template -void LinkerScript::assignAddresses(std::vector> &Phdrs) { - // Orphan sections are sections present in the input files which - // are not explicitly placed into the output file by the linker script. - // We place orphan sections at end of file. - // Other linkers places them using some heuristics as described in - // https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections. - +void LinkerScript::placeOrphanSections() { // The OutputSections are already in the correct order. // This loops creates or moves commands as needed so that they are in the // correct order. @@ -622,6 +619,11 @@ void LinkerScript::assignAddresses(std::vector> &Phdrs) { // Continue from where we found it. CmdIndex = (Pos - Opt.Commands.begin()) + 1; } +} + +template +void LinkerScript::assignAddresses(std::vector> &Phdrs) { + placeOrphanSections(); // Assign addresses as instructed by linker script SECTIONS sub-commands. Dot = 0; diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 1840978..3056ae9 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -229,6 +229,7 @@ public: bool hasLMA(StringRef Name); bool shouldKeep(InputSectionBase *S); void assignOffsets(OutputSectionCommand *Cmd); + void placeOrphanSections(); void assignAddresses(std::vector> &Phdrs); bool hasPhdrsCommands(); uint64_t getOutputSectionAddress(StringRef Name) override; -- 2.7.4