[PATCH] D33496: [LLD][ELF] Move creation of .ARM.exidx sentinel before LinkerScript creation
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 07:00:30 PDT 2017
peter.smith updated this revision to Diff 100238.
peter.smith added a comment.
Updated patch to just append the .ARM.exidx sentinel section to an existing LinkerScript InputSectionDescription.
To do the insertion I've moved the LinkerScript::inputSectionRanges() function from https://reviews.llvm.org/D33500 so we can use it do the insertion and updated https://reviews.llvm.org/D33500.
https://reviews.llvm.org/D33496
Files:
ELF/LinkerScript.cpp
ELF/LinkerScript.h
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1195,8 +1195,6 @@
if (ErrorCount)
return;
- // So far we have added sections from input object files.
- // This function adds linker-created Out::* sections.
addPredefinedSections();
removeUnusedSyntheticSections(OutputSections);
@@ -1264,8 +1262,17 @@
// ARM ABI requires .ARM.exidx to be terminated by some piece of data.
// We have the terminater synthetic section class. Add that at the end.
auto *OS = dyn_cast_or_null<OutputSection>(findSection(".ARM.exidx"));
- if (OS && !OS->Sections.empty() && !Config->Relocatable)
- OS->addSection(make<ARMExidxSentinelSection>());
+ if (!OS || OS->Sections.empty() || Config->Relocatable)
+ return;
+
+ auto *Sentinel = make<ARMExidxSentinelSection>();
+ OS->addSection(Sentinel);
+ // If there are linker script commands existing at this point then add the
+ // sentinel to these too.
+ std::vector<std::vector<InputSection *> *> Ranges =
+ Script->inputSectionRanges(OS->Name);
+ if (!Ranges.empty())
+ Ranges.back()->push_back(Sentinel);
}
// The linker is expected to define SECNAME_start and SECNAME_end
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -258,6 +258,8 @@
std::vector<OutputSection *> *OutputSections;
void fabricateDefaultCommands();
+ std::vector<std::vector<InputSection *> *>
+ inputSectionRanges(StringRef S);
void addOrphanSections(OutputSectionFactory &Factory);
void removeEmptyCommands();
void adjustSectionsBeforeSorting();
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -510,6 +510,28 @@
}
}
+// For an OutputSection S, return the InputSectionDescriptions that are
+// associated with S. The intention is that callers can iterate over
+// InputSectionDescription::Sections and insert sections such as Thunks.
+std::vector<std::vector<InputSection *> *>
+LinkerScript::inputSectionRanges(StringRef S) {
+ std::vector<std::vector<InputSection *> *> Ranges;
+ auto OutCmdPos = std::find_if(
+ Opt.Commands.begin(), Opt.Commands.end(), [=](BaseCommand *Cmd) {
+ if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))
+ return (OSCmd->Name == S);
+ return false;
+ });
+ if (OutCmdPos == Opt.Commands.end())
+ return Ranges;
+ auto *OutCmd = cast<OutputSectionCommand>(*OutCmdPos);
+ for (auto *BaseCmd : OutCmd->Commands) {
+ if (auto *ISD = dyn_cast<InputSectionDescription>(BaseCmd))
+ Ranges.push_back(&ISD->Sections);
+ }
+ return Ranges;
+}
+
uint64_t LinkerScript::advance(uint64_t Size, unsigned Align) {
bool IsTbss = (CurOutSec->Flags & SHF_TLS) && CurOutSec->Type == SHT_NOBITS;
uint64_t Start = IsTbss ? Dot + ThreadBssOffset : Dot;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33496.100238.patch
Type: text/x-patch
Size: 2982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/c530d4f3/attachment.bin>
More information about the llvm-commits
mailing list