diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -940,15 +940,13 @@ for (const Elf_Shdr &Sec : *SectionsOrErr) { switch (Sec.sh_type) { case ELF::SHT_DYNSYM: { - if (DotDynSymSec) - return createError("More than one dynamic symbol table!"); - DotDynSymSec = &Sec; + if (!DotDynSymSec) + DotDynSymSec = &Sec; break; } case ELF::SHT_SYMTAB: { - if (DotSymtabSec) - return createError("More than one static symbol table!"); - DotSymtabSec = &Sec; + if (!DotSymtabSec) + DotSymtabSec = &Sec; break; } case ELF::SHT_SYMTAB_SHNDX: { diff --git a/llvm/test/Object/multiple-sections.yaml b/llvm/test/Object/multiple-sections.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/Object/multiple-sections.yaml @@ -0,0 +1,83 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: llvm-readelf --headers %t.o | FileCheck %s + +# CHECK: ELF Header: + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: C3 + - Name: .symtab2 + Type: SHT_SYMTAB + Flags: [ ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .versym + Type: SHT_GNU_versym + Flags: [ ] + AddressAlign: 0x0000000000000001 + Entries: [ ] + - Name: .versym2 + Type: SHT_GNU_versym + Flags: [ ] + AddressAlign: 0x0000000000000001 + Entries: [ ] + - Name: .verdef + Type: SHT_GNU_verdef + Flags: [ ] + AddressAlign: 0x0000000000000001 + Info: 0x0000000000000000 + Entries: + - Name: .verdef2 + Type: SHT_GNU_verdef + Flags: [ ] + AddressAlign: 0x0000000000000001 + Info: 0x0000000000000000 + Entries: + - Name: .verneed + Type: SHT_GNU_verneed + Flags: [ ] + AddressAlign: 0x0000000000000001 + Info: 0x0000000000000000 + Dependencies: + - Name: .verneed2 + Type: SHT_GNU_verneed + Flags: [ ] + AddressAlign: 0x0000000000000001 + Info: 0x0000000000000000 + Dependencies: + - Name: .llvm.call-graph-profile + Type: SHT_LLVM_CALL_GRAPH_PROFILE + Flags: [ ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .llvm.call-graph-profile2 + Type: SHT_LLVM_CALL_GRAPH_PROFILE + Flags: [ ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .llvm_addrsig + Type: SHT_LLVM_ADDRSIG + Flags: [ ] + AddressAlign: 0x0000000000000001 + Content: '' + - Name: .llvm_addrsig2 + Type: SHT_LLVM_ADDRSIG + Flags: [ ] + AddressAlign: 0x0000000000000001 + Content: '' +Symbols: + - Name: f + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Size: 0x0000000000000001 +... diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1399,14 +1399,12 @@ for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) { switch (Sec.sh_type) { case ELF::SHT_SYMTAB: - if (DotSymtabSec != nullptr) - reportError("Multiple SHT_SYMTAB"); - DotSymtabSec = &Sec; + if (!DotSymtabSec) + DotSymtabSec = &Sec; break; case ELF::SHT_DYNSYM: - if (DynSymRegion.Size) - reportError("Multiple SHT_DYNSYM"); - DynSymRegion = createDRIFrom(&Sec); + if (!DynSymRegion.Size) + DynSymRegion = createDRIFrom(&Sec); // This is only used (if Elf_Shdr present)for naming section in GNU style DynSymtabName = unwrapOrError(Obj->getSectionName(&Sec)); DynamicStringTable = unwrapOrError(Obj->getStringTableForSymtab(Sec)); @@ -1415,29 +1413,24 @@ ShndxTable = unwrapOrError(Obj->getSHNDXTable(Sec)); break; case ELF::SHT_GNU_versym: - if (SymbolVersionSection != nullptr) - reportError("Multiple SHT_GNU_versym"); - SymbolVersionSection = &Sec; + if (!SymbolVersionSection) + SymbolVersionSection = &Sec; break; case ELF::SHT_GNU_verdef: - if (SymbolVersionDefSection != nullptr) - reportError("Multiple SHT_GNU_verdef"); - SymbolVersionDefSection = &Sec; + if (!SymbolVersionDefSection) + SymbolVersionDefSection = &Sec; break; case ELF::SHT_GNU_verneed: - if (SymbolVersionNeedSection != nullptr) - reportError("Multiple SHT_GNU_verneed"); - SymbolVersionNeedSection = &Sec; + if (!SymbolVersionNeedSection) + SymbolVersionNeedSection = &Sec; break; case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: - if (DotCGProfileSec != nullptr) - reportError("Multiple .llvm.call-graph-profile"); - DotCGProfileSec = &Sec; + if (!DotCGProfileSec) + DotCGProfileSec = &Sec; break; case ELF::SHT_LLVM_ADDRSIG: - if (DotAddrsigSec != nullptr) - reportError("Multiple .llvm_addrsig"); - DotAddrsigSec = &Sec; + if (!DotAddrsigSec) + DotAddrsigSec = &Sec; break; } }