[ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"

This is PR33889,

Patch adds support of combination of linkerscript and
-symbol-ordering-file option.

If no sorting commands are present in script inside section declaration
and no --sort-section option specified, code uses sorting from ordering 
file if any exist.

Differential revision: https://reviews.llvm.org/D35843

llvm-svn: 310045
This commit is contained in:
George Rimar
2017-08-04 10:25:29 +00:00
parent 1c17001235
commit d6bcde389a
7 changed files with 102 additions and 31 deletions

View File

@@ -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 *,