diff options
Diffstat (limited to 'lld/ELF/InputSection.cpp')
-rw-r--r-- | lld/ELF/InputSection.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 2f3cec3edec..ff084cd521a 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -44,6 +44,29 @@ std::string lld::toString(const InputSectionBase *Sec) { return (toString(Sec->File) + ":(" + Sec->Name + ")").str(); } +template <class ELFT> DenseMap<SectionBase *, int> elf::buildSectionOrder() { + // 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. + DenseMap<StringRef, int> SymbolOrder; + int Priority = -Config->SymbolOrderingFile.size(); + for (StringRef S : Config->SymbolOrderingFile) + SymbolOrder.insert({S, Priority++}); + + // Build a map from sections to their priorities. + DenseMap<SectionBase *, int> SectionOrder; + for (ObjFile<ELFT> *File : ObjFile<ELFT>::Instances) { + for (SymbolBody *Body : File->getSymbols()) { + auto *D = dyn_cast<DefinedRegular>(Body); + if (!D || !D->Section) + continue; + int &Priority = SectionOrder[D->Section]; + Priority = std::min(Priority, SymbolOrder.lookup(D->getName())); + } + } + return SectionOrder; +} + template <class ELFT> static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> *File, const typename ELFT::Shdr *Hdr) { @@ -982,6 +1005,11 @@ uint64_t MergeInputSection::getOffset(uint64_t Offset) const { return Piece.OutputOff + Addend; } +template DenseMap<SectionBase *, int> elf::buildSectionOrder<ELF32LE>(); +template DenseMap<SectionBase *, int> elf::buildSectionOrder<ELF32BE>(); +template DenseMap<SectionBase *, int> elf::buildSectionOrder<ELF64LE>(); +template DenseMap<SectionBase *, int> elf::buildSectionOrder<ELF64BE>(); + template InputSection::InputSection(ObjFile<ELF32LE> *, const ELF32LE::Shdr *, StringRef); template InputSection::InputSection(ObjFile<ELF32BE> *, const ELF32BE::Shdr *, |