diff options
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.cpp | 8 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.h | 4 | ||||
-rw-r--r-- | lld/test/elf/Inputs/no-unique-section-names.x86-64 | bin | 0 -> 2128 bytes | |||
-rw-r--r-- | lld/test/elf/no-unique-section-names.test | 19 |
4 files changed, 25 insertions, 6 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.cpp b/lld/lib/ReaderWriter/ELF/ELFFile.cpp index fd2ef716e67..34d1735c974 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp @@ -143,7 +143,7 @@ std::error_code ELFFile<ELFT>::createAtomizableSections() { auto rai(_objFile->begin_rela(§ion)); auto rae(_objFile->end_rela(§ion)); - _relocationAddendReferences[*sectionName] = make_range(rai, rae); + _relocationAddendReferences[sHdr] = make_range(rai, rae); totalRelocs += std::distance(rai, rae); } else if (section.sh_type == llvm::ELF::SHT_REL) { auto sHdr = _objFile->getSection(section.sh_info); @@ -155,7 +155,7 @@ std::error_code ELFFile<ELFT>::createAtomizableSections() { auto ri(_objFile->begin_rel(§ion)); auto re(_objFile->end_rel(§ion)); - _relocationReferences[*sectionName] = make_range(ri, re); + _relocationReferences[sHdr] = make_range(ri, re); totalRelocs += std::distance(ri, re); } else { _sectionSymbols[§ion]; @@ -554,12 +554,12 @@ ELFDefinedAtom<ELFT> *ELFFile<ELFT>::createDefinedAtomAndAssignRelocations( unsigned int referenceStart = _references.size(); // Add Rela (those with r_addend) references: - auto rari = _relocationAddendReferences.find(sectionName); + auto rari = _relocationAddendReferences.find(section); if (rari != _relocationAddendReferences.end()) createRelocationReferences(symbol, symContent, rari->second); // Add Rel references. - auto rri = _relocationReferences.find(sectionName); + auto rri = _relocationReferences.find(section); if (rri != _relocationReferences.end()) createRelocationReferences(symbol, symContent, secContent, rri->second); diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index 93ade6b0cc3..b9ee5afe12f 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -345,10 +345,10 @@ protected: /// list of relocations references. In ELF, if a section named, ".text" has /// relocations will also have a section named ".rel.text" or ".rela.text" /// which will hold the entries. - std::unordered_map<StringRef, range<Elf_Rela_Iter>> + std::unordered_map<const Elf_Shdr *, range<Elf_Rela_Iter>> _relocationAddendReferences; MergedSectionMapT _mergedSectionMap; - std::unordered_map<StringRef, range<Elf_Rel_Iter>> _relocationReferences; + std::unordered_map<const Elf_Shdr *, range<Elf_Rel_Iter>> _relocationReferences; std::vector<ELFReference<ELFT> *> _references; llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping; llvm::DenseMap<const ELFReference<ELFT> *, const Elf_Sym *> diff --git a/lld/test/elf/Inputs/no-unique-section-names.x86-64 b/lld/test/elf/Inputs/no-unique-section-names.x86-64 Binary files differnew file mode 100644 index 00000000000..fd92f5f0c6e --- /dev/null +++ b/lld/test/elf/Inputs/no-unique-section-names.x86-64 diff --git a/lld/test/elf/no-unique-section-names.test b/lld/test/elf/no-unique-section-names.test new file mode 100644 index 00000000000..042f6d496be --- /dev/null +++ b/lld/test/elf/no-unique-section-names.test @@ -0,0 +1,19 @@ +# Check handling object files with non-unique named sections. + +RUN: lld -flavor gnu -target x86_64-linux -shared -o %t \ +RUN: %p/Inputs/no-unique-section-names.x86-64 +RUN: llvm-objdump -s %p/Inputs/no-unique-section-names.x86-64 %t \ +RUN: | FileCheck %s + +CHECK: Contents of section .group: +CHECK-NEXT: 0000 01000000 08000000 +CHECK-NEXT: Contents of section .text: +CHECK-NEXT: 0000 [[A1:[0-9a-f]+]] [[A2:[0-9a-f]+]] [[A3:[0-9a-f]+]] +CHECK-NEXT: Contents of section .group: +CHECK-NEXT: 0000 01000000 0a000000 +CHECK-NEXT: Contents of section .text: +CHECK-NEXT: 0000 [[B1:[0-9a-f]+]] [[B2:[0-9a-f]+]] [[B3:[0-9a-f]+]] + +CHECK: Contents of section .text: +CHECK: {{[0-9a-f]+}} [[A1]] [[A2]] [[A3]] +CHECK-NEXT: {{[0-9a-f]+}} [[B1]] [[B2]] [[B3]] |