From 6db9c3f4c4d510a9920b801933e9d5858a52bb05 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Sun, 20 Oct 2019 14:47:17 +0000 Subject: [PATCH] [yaml2obj][obj2yaml] - Do not create a symbol table by default. This patch tries to resolve problems faced in D68943 and uses some of the code written by Konrad Wilhelm Kleine in that patch. Previously, yaml2obj tool always created a .symtab section. This patch changes that. With it we only create it when have a "Symbols:" tag in the YAML document or when we need to create it because it is used by another section(s). obj2yaml follows the new behavior and does not print "Symbols:" anymore when there is no symbol table. Differential revision: https://reviews.llvm.org/D69041 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375361 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ObjectYAML/ELFYAML.h | 2 +- lib/ObjectYAML/ELFEmitter.cpp | 29 ++++++++++++--- test/Object/invalid.test | 8 ++-- test/Object/objdump-sectionheaders.test | 1 - .../tools/llvm-objcopy/ELF/add-section-remove.test | 3 +- test/tools/llvm-objcopy/ELF/add-section.test | 3 +- test/tools/llvm-objcopy/ELF/add-symbol.test | 3 ++ .../tools/llvm-objcopy/ELF/basic-only-section.test | 4 +- .../llvm-objcopy/ELF/explicit-keep-remove.test | 3 +- .../ELF/explicit-only-section-remove.test | 4 +- test/tools/llvm-objcopy/ELF/invalid-e_shoff.test | 1 + test/tools/llvm-objcopy/ELF/keep-only-section.test | 8 +--- test/tools/llvm-objcopy/ELF/no-strip-all.test | 1 + .../llvm-objcopy/ELF/no-symbol-relocation.test | 1 - test/tools/llvm-objcopy/ELF/null-symbol.test | 1 + test/tools/llvm-objcopy/ELF/only-section-many.test | 4 +- .../ELF/preserve-segment-contents-ehdr-phdrs.test | 1 + test/tools/llvm-objcopy/ELF/remove-section.test | 1 + .../llvm-objcopy/ELF/rename-section-multiple.test | 3 +- test/tools/llvm-objcopy/ELF/rename-section.test | 3 +- .../ELF/segment-shift-section-remove.test | 3 ++ .../ELF/segment-test-remove-section.test | 3 ++ test/tools/llvm-objcopy/ELF/shstrtab-optimize.test | 2 +- .../ELF/strip-unneeded-remove-debug-keep-link.test | 9 ++--- .../ELF/symtab-error-on-remove-strtab.test | 1 + test/tools/llvm-objcopy/ELF/symtab-link.test | 1 + test/tools/llvm-objcopy/ELF/wildcard-syntax.test | 2 + test/tools/llvm-objdump/full-contents.test | 1 + test/tools/llvm-objdump/relocations-elf.test | 1 - test/tools/llvm-readobj/check-output-order.test | 1 + test/tools/llvm-readobj/elf-dynamic-malformed.test | 5 +++ test/tools/llvm-readobj/elf-file-headers.test | 18 ++++----- test/tools/llvm-readobj/elf-hidden-versym.test | 2 +- test/tools/llvm-readobj/elf-invalid-shstrndx.test | 2 +- .../tools/llvm-readobj/elf-invalid-versioning.test | 2 +- test/tools/llvm-readobj/elf-no-phdrs.test | 2 +- test/tools/llvm-readobj/elf-no-relocs.test | 2 - test/tools/llvm-readobj/elf-relr-relocs.test | 2 + test/tools/llvm-readobj/elf-versioninfo.test | 6 +-- .../llvm-readobj/elf-wrong-shstrtab-type.test | 2 +- .../llvm-readobj/reloc-types-elf-aarch64.test | 1 - test/tools/llvm-readobj/reloc-types-elf-arm.test | 1 - test/tools/llvm-readobj/reloc-types-elf-lanai.test | 1 - test/tools/llvm-readobj/reloc-types-elf-mips.test | 1 - .../tools/llvm-readobj/reloc-types-elf-mips64.test | 1 - test/tools/obj2yaml/elf-llvm-addrsig-section.yaml | 2 - test/tools/obj2yaml/elf-no-symtab.yaml | 43 ++++++++++++++++++++++ test/tools/obj2yaml/elf-sht-symtab-shndx.yaml | 1 + test/tools/obj2yaml/no-symbol-reloc.test | 1 + test/tools/obj2yaml/section-group.test | 1 + test/tools/yaml2obj/dynamic-symbols.yaml | 2 +- test/tools/yaml2obj/elf-comdat-broken-info.yaml | 1 - test/tools/yaml2obj/elf-custom-null-section.yaml | 10 ++--- test/tools/yaml2obj/elf-header-sh-fields.yaml | 6 +-- test/tools/yaml2obj/elf-sht-symtab-shndx.yaml | 1 - test/tools/yaml2obj/implicit-sections-types.test | 2 + test/tools/yaml2obj/implicit-sections.test | 27 ++++++++++++++ .../yaml2obj/invalid-symboless-relocation.yaml | 1 - test/tools/yaml2obj/reloc-sec-info.yaml | 1 - test/tools/yaml2obj/symboless-relocation.yaml | 1 - .../yaml2obj/symtab-implicit-sections-flags.yaml | 1 + tools/obj2yaml/elf2yaml.cpp | 8 +++- 62 files changed, 178 insertions(+), 87 deletions(-) create mode 100644 test/tools/obj2yaml/elf-no-symtab.yaml diff --git a/include/llvm/ObjectYAML/ELFYAML.h b/include/llvm/ObjectYAML/ELFYAML.h index ef2b4fba031..0898a0e7d53 100644 --- a/include/llvm/ObjectYAML/ELFYAML.h +++ b/include/llvm/ObjectYAML/ELFYAML.h @@ -376,7 +376,7 @@ struct Object { // cleaner and nicer if we read them from the YAML as a separate // top-level key, which automatically ensures that invariants like there // being a single SHT_SYMTAB section are upheld. - std::vector Symbols; + Optional> Symbols; std::vector DynamicSymbols; }; diff --git a/lib/ObjectYAML/ELFEmitter.cpp b/lib/ObjectYAML/ELFEmitter.cpp index f9c31f335f1..e0faed256f6 100644 --- a/lib/ObjectYAML/ELFEmitter.cpp +++ b/lib/ObjectYAML/ELFEmitter.cpp @@ -200,10 +200,17 @@ template ELFState::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH) : Doc(D), ErrHandler(EH) { StringSet<> DocSections; - for (std::unique_ptr &D : Doc.Sections) + for (std::unique_ptr &D : Doc.Sections) { if (!D->Name.empty()) DocSections.insert(D->Name); + // Some sections wants to link to .symtab by default. + // That means we want to create the symbol table for them. + if (D->Type == llvm::ELF::SHT_REL || D->Type == llvm::ELF::SHT_RELA) + if (!Doc.Symbols && D->Link.empty()) + Doc.Symbols.emplace(); + } + // Insert SHT_NULL section implicitly when it is not defined in YAML. if (Doc.Sections.empty() || Doc.Sections.front()->Type != ELF::SHT_NULL) Doc.Sections.insert( @@ -211,7 +218,11 @@ ELFState::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH) std::make_unique( ELFYAML::Section::SectionKind::RawContent, /*IsImplicit=*/true)); - std::vector ImplicitSections = {".symtab", ".strtab", ".shstrtab"}; + std::vector ImplicitSections; + if (Doc.Symbols) + ImplicitSections.push_back(".symtab"); + ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"}); + if (!Doc.DynamicSymbols.empty()) ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"}); @@ -508,7 +519,11 @@ void ELFState::initSymtabSectionHeader(Elf_Shdr &SHeader, ELFYAML::Section *YAMLSec) { bool IsStatic = STType == SymtabType::Static; - const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols; + ArrayRef Symbols; + if (IsStatic && Doc.Symbols) + Symbols = *Doc.Symbols; + else if (!IsStatic) + Symbols = Doc.DynamicSymbols; ELFYAML::RawContentSection *RawSec = dyn_cast_or_null(YAMLSec); @@ -1044,14 +1059,16 @@ template void ELFState::buildSymbolIndexes() { } }; - Build(Doc.Symbols, SymN2I); + if (Doc.Symbols) + Build(*Doc.Symbols, SymN2I); Build(Doc.DynamicSymbols, DynSymN2I); } template void ELFState::finalizeStrings() { // Add the regular symbol names to .strtab section. - for (const ELFYAML::Symbol &Sym : Doc.Symbols) - DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name)); + if (Doc.Symbols) + for (const ELFYAML::Symbol &Sym : *Doc.Symbols) + DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name)); DotStrtab.finalize(); // Add the dynamic symbol names to .dynstr section. diff --git a/test/Object/invalid.test b/test/Object/invalid.test index cbf770afbdc..56372bf37c2 100644 --- a/test/Object/invalid.test +++ b/test/Object/invalid.test @@ -226,6 +226,7 @@ Sections: Type: SHT_SYMTAB_SHNDX Entries: [ 0, 1 ] Link: .symtab +Symbols: [] ## Check that llvm-readobj reports an error if the e_phentsize field is broken. @@ -274,8 +275,8 @@ Sections: Type: SHT_RELA ShOffset: 0x10000 -## Check that llvm-objdump reports an error when .shstrtab has a broken sh_offset -## so large that sh_offset + sh_size overflows the platform address size type. +## Check that llvm-objdump reports an error when we try to print symbols and +## .shstrtab has a broken sh_offset so large that sh_offset + sh_size overflows the platform address size type. # RUN: yaml2obj %s --docnum=14 -o %t14 # RUN: not llvm-readobj --symbols %t14 2>&1 | FileCheck -DFILE=%t14 --check-prefix=INVALID-SECTION-SIZE2 %s @@ -292,6 +293,7 @@ Sections: - Name: .shstrtab Type: SHT_STRTAB ShOffset: 0xFFFFFFFF +Symbols: [] ## Check that llvm-readobj reports an error when trying to dump sections ## when the e_shnum field is broken (is greater than the actual number of sections). @@ -565,7 +567,7 @@ Sections: # RUN: yaml2obj --docnum=26 %s -o %t26 # RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM1 %s -# INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x78) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff) +# INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x58) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff) --- !ELF FileHeader: diff --git a/test/Object/objdump-sectionheaders.test b/test/Object/objdump-sectionheaders.test index 434d73e77ad..fba4fa79980 100644 --- a/test/Object/objdump-sectionheaders.test +++ b/test/Object/objdump-sectionheaders.test @@ -37,6 +37,5 @@ Sections: - Name: .rela.text Type: SHT_RELA Address: 0x0000000000000038 - Link: .symtab Info: .text Relocations: diff --git a/test/tools/llvm-objcopy/ELF/add-section-remove.test b/test/tools/llvm-objcopy/ELF/add-section-remove.test index fe462dba1e8..ad41d74947d 100644 --- a/test/tools/llvm-objcopy/ELF/add-section-remove.test +++ b/test/tools/llvm-objcopy/ELF/add-section-remove.test @@ -23,11 +23,10 @@ Sections: Flags: [ SHF_ALLOC ] Content: "32323232" -# CHECK: SectionHeaderCount: 7 +# CHECK: SectionHeaderCount: 6 # CHECK: Name: .test1 # CHECK: Name: .test3 -# CHECK: Name: .symtab # CHECK: Name: .strtab # CHECK: Name: .shstrtab # CHECK: Name: .test2 diff --git a/test/tools/llvm-objcopy/ELF/add-section.test b/test/tools/llvm-objcopy/ELF/add-section.test index 4acbd9ae4e2..e930d2754b8 100644 --- a/test/tools/llvm-objcopy/ELF/add-section.test +++ b/test/tools/llvm-objcopy/ELF/add-section.test @@ -24,11 +24,10 @@ Sections: Flags: [ SHF_ALLOC ] Content: "32323232" -# CHECK: SectionHeaderCount: 7 +# CHECK: SectionHeaderCount: 6 # CHECK: Name: .test1 # CHECK: Name: .test3 -# CHECK: Name: .symtab # CHECK: Name: .strtab # CHECK: Name: .shstrtab # CHECK: Name: .test2 diff --git a/test/tools/llvm-objcopy/ELF/add-symbol.test b/test/tools/llvm-objcopy/ELF/add-symbol.test index fd838602ba7..a9002d42971 100644 --- a/test/tools/llvm-objcopy/ELF/add-symbol.test +++ b/test/tools/llvm-objcopy/ELF/add-symbol.test @@ -58,6 +58,9 @@ ProgramHeaders: Align: 0x1000 Sections: - Section: .data +## TODO (grimar): llvm-objcopy seems produce a broken output without +## the following line, i.e. when there is no symbol table in the input. +Symbols: [] # CHECK: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND # CHECK-NEXT: 1: 00000001 0 NOTYPE GLOBAL DEFAULT ABS abs1 diff --git a/test/tools/llvm-objcopy/ELF/basic-only-section.test b/test/tools/llvm-objcopy/ELF/basic-only-section.test index e47a97ac6d7..f95ea389116 100644 --- a/test/tools/llvm-objcopy/ELF/basic-only-section.test +++ b/test/tools/llvm-objcopy/ELF/basic-only-section.test @@ -15,9 +15,7 @@ Sections: Type: SHT_PROGBITS Flags: [ ] -# CHECK: SectionHeaderCount: 5 +# CHECK: SectionHeaderCount: 3 # CHECK: Name: .test -# CHECK: Name: .symtab -# CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/explicit-keep-remove.test b/test/tools/llvm-objcopy/ELF/explicit-keep-remove.test index 98ad3ae7592..6512afac0cf 100644 --- a/test/tools/llvm-objcopy/ELF/explicit-keep-remove.test +++ b/test/tools/llvm-objcopy/ELF/explicit-keep-remove.test @@ -13,9 +13,8 @@ Sections: Type: SHT_PROGBITS Flags: [ ] -# CHECK: SectionHeaderCount: 5 +# CHECK: SectionHeaderCount: 4 # CHECK: Name: .test -# CHECK: Name: .symtab # CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test b/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test index 8a152e57a5d..5baf845abe7 100644 --- a/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test +++ b/test/tools/llvm-objcopy/ELF/explicit-only-section-remove.test @@ -13,9 +13,7 @@ Sections: Type: SHT_PROGBITS Flags: [ ] -# CHECK: SectionHeaderCount: 5 +# CHECK: SectionHeaderCount: 3 # CHECK: Name: .test -# CHECK: Name: .symtab -# CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test b/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test index fc2e08484b2..9d50922f196 100644 --- a/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test +++ b/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test @@ -28,5 +28,6 @@ FileHeader: Sections: - Name: .foo Type: SHT_PROGBITS +Symbols: [] # CASE2: error: '[[INPUT]]': section header table goes past the end of the file: e_shoff = 0x40000000 diff --git a/test/tools/llvm-objcopy/ELF/keep-only-section.test b/test/tools/llvm-objcopy/ELF/keep-only-section.test index 7ea8468fe5f..75b5bbd77d4 100644 --- a/test/tools/llvm-objcopy/ELF/keep-only-section.test +++ b/test/tools/llvm-objcopy/ELF/keep-only-section.test @@ -20,19 +20,15 @@ Sections: - Name: .test3 Type: SHT_PROGBITS -# CHECK: SectionHeaderCount: 6 +# CHECK: SectionHeaderCount: 4 # CHECK: Name: .test # CHECK: Name: .test2 -# CHECK: Name: .symtab -# CHECK: Name: .strtab # CHECK: Name: .shstrtab -# REGEX: SectionHeaderCount: 7 +# REGEX: SectionHeaderCount: 5 # REGEX: Name: .test # REGEX: Name: .test2 # REGEX: Name: .test3 -# REGEX: Name: .symtab -# REGEX: Name: .strtab # REGEX: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/no-strip-all.test b/test/tools/llvm-objcopy/ELF/no-strip-all.test index a0158d4b834..90b4c15765f 100644 --- a/test/tools/llvm-objcopy/ELF/no-strip-all.test +++ b/test/tools/llvm-objcopy/ELF/no-strip-all.test @@ -37,6 +37,7 @@ Sections: - Name: .alloc Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] +Symbols: [] # ALL: SectionHeaderCount: 3 # ALL: Name: .alloc diff --git a/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test b/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test index 9def536c239..4b13dda6484 100644 --- a/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test +++ b/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test @@ -17,7 +17,6 @@ Sections: Content: "0000000000000000" - Name: .rel.text Type: SHT_REL - Link: .symtab Info: .text Relocations: - Offset: 0x1000 diff --git a/test/tools/llvm-objcopy/ELF/null-symbol.test b/test/tools/llvm-objcopy/ELF/null-symbol.test index 94f5ab5d8c2..b7ac3e8cf1e 100644 --- a/test/tools/llvm-objcopy/ELF/null-symbol.test +++ b/test/tools/llvm-objcopy/ELF/null-symbol.test @@ -15,6 +15,7 @@ Sections: Address: 0x1000 AddressAlign: 0x0000000000000010 Size: 8 +Symbols: [] #CHECK: Symbols [ #CHECK-NEXT: Symbol { diff --git a/test/tools/llvm-objcopy/ELF/only-section-many.test b/test/tools/llvm-objcopy/ELF/only-section-many.test index 43ccff1c2c2..9f1f77d04d0 100644 --- a/test/tools/llvm-objcopy/ELF/only-section-many.test +++ b/test/tools/llvm-objcopy/ELF/only-section-many.test @@ -19,10 +19,8 @@ Sections: Type: SHT_PROGBITS Flags: [ ] -# CHECK: SectionHeaderCount: 6 +# CHECK: SectionHeaderCount: 4 # CHECK: Name: .test1 # CHECK: Name: .test2 -# CHECK: Name: .symtab -# CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/preserve-segment-contents-ehdr-phdrs.test b/test/tools/llvm-objcopy/ELF/preserve-segment-contents-ehdr-phdrs.test index 4afd2c9285e..c6824c4cb47 100644 --- a/test/tools/llvm-objcopy/ELF/preserve-segment-contents-ehdr-phdrs.test +++ b/test/tools/llvm-objcopy/ELF/preserve-segment-contents-ehdr-phdrs.test @@ -39,3 +39,4 @@ ProgramHeaders: - Type: PT_LOAD Sections: - Section: .keep_me +Symbols: [] diff --git a/test/tools/llvm-objcopy/ELF/remove-section.test b/test/tools/llvm-objcopy/ELF/remove-section.test index 8f8b98e90f0..927485a6002 100644 --- a/test/tools/llvm-objcopy/ELF/remove-section.test +++ b/test/tools/llvm-objcopy/ELF/remove-section.test @@ -30,6 +30,7 @@ Sections: - Name: .test3 Type: SHT_PROGBITS Flags: [ ] +Symbols: [] # CHECK: SectionHeaderCount: 6 diff --git a/test/tools/llvm-objcopy/ELF/rename-section-multiple.test b/test/tools/llvm-objcopy/ELF/rename-section-multiple.test index e614f656053..c508ac80c30 100644 --- a/test/tools/llvm-objcopy/ELF/rename-section-multiple.test +++ b/test/tools/llvm-objcopy/ELF/rename-section-multiple.test @@ -22,7 +22,7 @@ Sections: Flags: [ SHF_ALLOC ] Content: "37373737" -# CHECK: SectionHeaderCount: 7 +# CHECK: SectionHeaderCount: 6 # CHECK: Name: .test2 # CHECK: SectionData ( @@ -36,6 +36,5 @@ Sections: # CHECK: SectionData ( # CHECK-NEXT: 0000: 37373737 # CHECK-NEXT: ) -# CHECK: Name: .symtab # CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/rename-section.test b/test/tools/llvm-objcopy/ELF/rename-section.test index 3829b5b0da8..c8a1eafaa30 100644 --- a/test/tools/llvm-objcopy/ELF/rename-section.test +++ b/test/tools/llvm-objcopy/ELF/rename-section.test @@ -16,13 +16,12 @@ Sections: Flags: [ SHF_ALLOC ] Content: "c3c3c3c3" -# CHECK: SectionHeaderCount: 5 +# CHECK: SectionHeaderCount: 4 # CHECK: Name: .bar # CHECK: SectionData ( # CHECK-NEXT: 0000: C3C3C3C3 # CHECK-NEXT: ) -# CHECK: Name: .symtab # CHECK: Name: .strtab # CHECK: Name: .shstrtab diff --git a/test/tools/llvm-objcopy/ELF/segment-shift-section-remove.test b/test/tools/llvm-objcopy/ELF/segment-shift-section-remove.test index cef783cb9b2..9a50a10bc24 100644 --- a/test/tools/llvm-objcopy/ELF/segment-shift-section-remove.test +++ b/test/tools/llvm-objcopy/ELF/segment-shift-section-remove.test @@ -40,6 +40,9 @@ ProgramHeaders: PAddr: 0x3000 Sections: - Section: .text3 +## TODO (grimar): without the following line (i.e. without an empty symbol table), +## llvm-objcopy adds an empty .strtab section. It doesn't look correct. +Symbols: [] #CHECK: SectionHeaderCount: 4 diff --git a/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test b/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test index 60cd5f3483d..ca83e58f53a 100644 --- a/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test +++ b/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test @@ -42,6 +42,9 @@ ProgramHeaders: - Section: .text - Section: .text2 - Section: .text3 +## TODO (grimar): without the following line (i.e. without an empty symbol table), +## llvm-objcopy adds an empty .strtab section. It doesn't look correct. +Symbols: [] # Make sure that when we remove a section we overwrite it with zeros # DATA: {{^[^[:blank:]]+}} 00 00 00 00 diff --git a/test/tools/llvm-objcopy/ELF/shstrtab-optimize.test b/test/tools/llvm-objcopy/ELF/shstrtab-optimize.test index 24b546cbaf5..8b1da2141aa 100644 --- a/test/tools/llvm-objcopy/ELF/shstrtab-optimize.test +++ b/test/tools/llvm-objcopy/ELF/shstrtab-optimize.test @@ -11,7 +11,7 @@ # CHECK-NEXT: ] # CHECK-NEXT: Address: # CHECK-NEXT: Offset: -# CHECK-NEXT: Size: 36 +# CHECK-NEXT: Size: 28 !ELF FileHeader: diff --git a/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test b/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test index b6a72f965bd..948bfea2d9c 100644 --- a/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test +++ b/test/tools/llvm-objcopy/ELF/strip-unneeded-remove-debug-keep-link.test @@ -20,11 +20,10 @@ Sections: - Name: .debugfoo Type: SHT_PROGBITS -# CHECK: There are 6 section headers +# CHECK: There are 5 section headers # CHECK: [ 0] # CHECK-NEXT: [ 1] .text -# CHECK-NEXT: [ 2] .symtab -# CHECK-NEXT: [ 3] .strtab -# CHECK-NEXT: [ 4] .shstrtab -# CHECK-NEXT: [ 5] .gnu_debuglink +# CHECK-NEXT: [ 2] .strtab +# CHECK-NEXT: [ 3] .shstrtab +# CHECK-NEXT: [ 4] .gnu_debuglink diff --git a/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test b/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test index 7c9a46062d9..4aac930e469 100644 --- a/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test +++ b/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test @@ -9,6 +9,7 @@ FileHeader: Data: ELFDATA2LSB Type: ET_REL Machine: EM_X86_64 +Symbols: [] # ERR1: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab' # ERR2: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab' diff --git a/test/tools/llvm-objcopy/ELF/symtab-link.test b/test/tools/llvm-objcopy/ELF/symtab-link.test index 68b8f78dde9..8297529cb65 100644 --- a/test/tools/llvm-objcopy/ELF/symtab-link.test +++ b/test/tools/llvm-objcopy/ELF/symtab-link.test @@ -16,6 +16,7 @@ Sections: Link: .symtab Type: SHT_PROGBITS Flags: [ ] +Symbols: [] # CHECK: Name: .foo # CHECK-NEXT: Type: diff --git a/test/tools/llvm-objcopy/ELF/wildcard-syntax.test b/test/tools/llvm-objcopy/ELF/wildcard-syntax.test index 05642896727..685ba160704 100644 --- a/test/tools/llvm-objcopy/ELF/wildcard-syntax.test +++ b/test/tools/llvm-objcopy/ELF/wildcard-syntax.test @@ -57,6 +57,7 @@ Sections: Type: SHT_PROGBITS - Name: .bar Type: SHT_PROGBITS +Symbols: [] ## Use a separate test file with special characters for the following tests. @@ -128,6 +129,7 @@ Sections: Type: SHT_PROGBITS - Name: .foo Type: SHT_PROGBITS +Symbols: [] # WARN: warning: invalid glob pattern: ][] diff --git a/test/tools/llvm-objdump/full-contents.test b/test/tools/llvm-objdump/full-contents.test index e4939f2aade..29cc9fdb800 100644 --- a/test/tools/llvm-objdump/full-contents.test +++ b/test/tools/llvm-objdump/full-contents.test @@ -64,3 +64,4 @@ Sections: Type: SHT_PROGBITS Flags: [ ] Content: '11112222' +Symbols: [] diff --git a/test/tools/llvm-objdump/relocations-elf.test b/test/tools/llvm-objdump/relocations-elf.test index 87fe55c0411..b79ab9eee04 100644 --- a/test/tools/llvm-objdump/relocations-elf.test +++ b/test/tools/llvm-objdump/relocations-elf.test @@ -86,7 +86,6 @@ FileHeader: Sections: - Name: .rela.foo Type: SHT_RELA - Link: .symtab Info: 0x255 Relocations: - Offset: 0x1 diff --git a/test/tools/llvm-readobj/check-output-order.test b/test/tools/llvm-readobj/check-output-order.test index 7097d7faa3d..36fce3ac642 100644 --- a/test/tools/llvm-readobj/check-output-order.test +++ b/test/tools/llvm-readobj/check-output-order.test @@ -39,6 +39,7 @@ Sections: Entries: - Tag: DT_NULL Value: 0 +Symbols: [] ProgramHeaders: - Type: PT_DYNAMIC Sections: diff --git a/test/tools/llvm-readobj/elf-dynamic-malformed.test b/test/tools/llvm-readobj/elf-dynamic-malformed.test index afdcbe6b6b5..1a31fa39e9f 100644 --- a/test/tools/llvm-readobj/elf-dynamic-malformed.test +++ b/test/tools/llvm-readobj/elf-dynamic-malformed.test @@ -34,6 +34,7 @@ Sections: Type: SHT_DYNAMIC Address: 0x1000 Content: "01234567" +Symbols: [] ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 @@ -76,6 +77,7 @@ Sections: Value: 0 - Tag: DT_NULL Value: 0 +Symbols: [] ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 @@ -143,6 +145,7 @@ Sections: Value: 1 - Tag: DT_NULL Value: 0 +Symbols: [] ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 @@ -189,6 +192,7 @@ Sections: Value: 1 - Tag: DT_NULL Value: 0x0 +Symbols: [] ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 @@ -231,6 +235,7 @@ Sections: Value: 0x1000000 - Tag: DT_NULL Value: 0x0 +Symbols: [] ProgramHeaders: - Type: PT_LOAD VAddr: 0x1000 diff --git a/test/tools/llvm-readobj/elf-file-headers.test b/test/tools/llvm-readobj/elf-file-headers.test index ce7711c8b2d..1cb3563a077 100644 --- a/test/tools/llvm-readobj/elf-file-headers.test +++ b/test/tools/llvm-readobj/elf-file-headers.test @@ -21,15 +21,15 @@ # I386-NEXT: Version: 1 # I386-NEXT: Entry: 0x0 # I386-NEXT: ProgramHeaderOffset: 0x0 -# I386-NEXT: SectionHeaderOffset: 0x64 +# I386-NEXT: SectionHeaderOffset: 0x48 # I386-NEXT: Flags [ (0x0) # I386-NEXT: ] # I386-NEXT: HeaderSize: 52 # I386-NEXT: ProgramHeaderEntrySize: 0 # I386-NEXT: ProgramHeaderCount: 0 # I386-NEXT: SectionHeaderEntrySize: 40 -# I386-NEXT: SectionHeaderCount: 4 -# I386-NEXT: StringTableSectionIndex: 3 +# I386-NEXT: SectionHeaderCount: 3 +# I386-NEXT: StringTableSectionIndex: 2 # I386-NEXT:} # I386-NOT:{{.}} @@ -65,15 +65,15 @@ FileHeader: # X86-64-NEXT: Version: 1 # X86-64-NEXT: Entry: 0x0 # X86-64-NEXT: ProgramHeaderOffset: 0x0 -# X86-64-NEXT: SectionHeaderOffset: 0x78 +# X86-64-NEXT: SectionHeaderOffset: 0x58 # X86-64-NEXT: Flags [ (0x0) # X86-64-NEXT: ] # X86-64-NEXT: HeaderSize: 64 # X86-64-NEXT: ProgramHeaderEntrySize: 0 # X86-64-NEXT: ProgramHeaderCount: 0 # X86-64-NEXT: SectionHeaderEntrySize: 64 -# X86-64-NEXT: SectionHeaderCount: 4 -# X86-64-NEXT: StringTableSectionIndex: 3 +# X86-64-NEXT: SectionHeaderCount: 3 +# X86-64-NEXT: StringTableSectionIndex: 2 # X86-64-NEXT:} # X86-64-NOT:{{.}} @@ -116,14 +116,14 @@ FileHeader: # LANAI-NEXT: Version: 1 # LANAI-NEXT: Entry: 0x0 # LANAI-NEXT: ProgramHeaderOffset: 0x0 -# LANAI-NEXT: SectionHeaderOffset: 0x64 +# LANAI-NEXT: SectionHeaderOffset: 0x48 # LANAI-NEXT: Flags [ (0x0) # LANAI-NEXT: ] # LANAI-NEXT: HeaderSize: 52 # LANAI-NEXT: ProgramHeaderEntrySize: 0 # LANAI-NEXT: ProgramHeaderCount: 0 # LANAI-NEXT: SectionHeaderEntrySize: 40 -# LANAI-NEXT: SectionHeaderCount: 4 -# LANAI-NEXT: StringTableSectionIndex: 3 +# LANAI-NEXT: SectionHeaderCount: 3 +# LANAI-NEXT: StringTableSectionIndex: 2 # LANAI-NEXT:} # LANAI-NOT:{{.}} diff --git a/test/tools/llvm-readobj/elf-hidden-versym.test b/test/tools/llvm-readobj/elf-hidden-versym.test index b6cf05aad48..0dcee4ab09d 100644 --- a/test/tools/llvm-readobj/elf-hidden-versym.test +++ b/test/tools/llvm-readobj/elf-hidden-versym.test @@ -2,7 +2,7 @@ # RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=HIDDEN # HIDDEN: Version symbols section '.gnu.version' contains 2 entries: -# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 6 (.dynsym) +# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym) # HIDDEN-NEXT: 000: 0 (*local*) 3h(hiddensym) --- !ELF diff --git a/test/tools/llvm-readobj/elf-invalid-shstrndx.test b/test/tools/llvm-readobj/elf-invalid-shstrndx.test index ba899141f23..f57f7e83c9a 100644 --- a/test/tools/llvm-readobj/elf-invalid-shstrndx.test +++ b/test/tools/llvm-readobj/elf-invalid-shstrndx.test @@ -4,7 +4,7 @@ # GNU: ELF Header: # GNU: Section header string table index: 255 -# GNU-NEXT: There are 4 section headers, starting at offset 0x78: +# GNU-NEXT: There are 3 section headers, starting at offset 0x58: # GNU: Section Headers: # GNU-NEXT: [Nr] Name # GNU-EMPTY: diff --git a/test/tools/llvm-readobj/elf-invalid-versioning.test b/test/tools/llvm-readobj/elf-invalid-versioning.test index ae1b2ad6c51..e963d6905c2 100644 --- a/test/tools/llvm-readobj/elf-invalid-versioning.test +++ b/test/tools/llvm-readobj/elf-invalid-versioning.test @@ -2,7 +2,7 @@ # RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=INVALID # INVALID: Version symbols section '.gnu.version' contains 2 entries: -# INVALID-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 6 (.dynsym) +# INVALID-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym) # INVALID-NEXT: 000: 0 (*local*) 3 (*invalid*) --- !ELF diff --git a/test/tools/llvm-readobj/elf-no-phdrs.test b/test/tools/llvm-readobj/elf-no-phdrs.test index 4bb0067c2d6..f01569596ac 100644 --- a/test/tools/llvm-readobj/elf-no-phdrs.test +++ b/test/tools/llvm-readobj/elf-no-phdrs.test @@ -14,7 +14,7 @@ # GNU-EMPTY: # GNU-NEXT: Section to Segment mapping: # GNU-NEXT: Segment Sections... -# GNU-NEXT: None .symtab .strtab .shstrtab +# GNU-NEXT: None .strtab .shstrtab --- !ELF FileHeader: diff --git a/test/tools/llvm-readobj/elf-no-relocs.test b/test/tools/llvm-readobj/elf-no-relocs.test index df80b903f4c..c632e9751dd 100644 --- a/test/tools/llvm-readobj/elf-no-relocs.test +++ b/test/tools/llvm-readobj/elf-no-relocs.test @@ -41,8 +41,6 @@ Sections: - Name: .rela.text Type: SHT_RELA Info: .text - Link: .symtab - Name: .rel.text Type: SHT_REL Info: .text - Link: .symtab diff --git a/test/tools/llvm-readobj/elf-relr-relocs.test b/test/tools/llvm-readobj/elf-relr-relocs.test index 3badb736ae9..9d3b5de9928 100644 --- a/test/tools/llvm-readobj/elf-relr-relocs.test +++ b/test/tools/llvm-readobj/elf-relr-relocs.test @@ -91,6 +91,7 @@ Sections: Link: .symtab AddressAlign: 0x0000000000000001 Content: 600D0100000000000301000000000000000002000000000001050F00000000000900405005700A00 +Symbols: [] ... # RUN: yaml2obj -docnum 2 %s \ @@ -169,4 +170,5 @@ Sections: Link: .symtab AddressAlign: 0x00000001 Content: 600D0100030100000000020001050F0009004050 +Symbols: [] ... diff --git a/test/tools/llvm-readobj/elf-versioninfo.test b/test/tools/llvm-readobj/elf-versioninfo.test index 46b43430269..393889c772a 100644 --- a/test/tools/llvm-readobj/elf-versioninfo.test +++ b/test/tools/llvm-readobj/elf-versioninfo.test @@ -164,12 +164,12 @@ DynamicSymbols: # LLVM-NEXT: ] # GNU: Version symbols section '.gnu.version' contains 6 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 7 (.dynsym) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 6 (.dynsym) # GNU-NEXT: 000: 0 (*local*) 2 (VERSION1) 3 (VERSION2) 4 (v1) # GNU-NEXT: 004: 5 (v2) 6 (v3) # GNU-EMPTY: # GNU-NEXT: Version definition section '.gnu.version_d' contains 3 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 8 (.dynstr) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 7 (.dynstr) # GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: VERSION1 # GNU-NEXT: 0x001c: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: VERSION2 # GNU-NEXT: 0x0038: Parent 1: VERSION1 @@ -177,7 +177,7 @@ DynamicSymbols: # GNU-NEXT: 0x0038: Parent 1: VERSION1 # GNU-EMPTY: # GNU-NEXT: Version needs section '.gnu.version_r' contains 2 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00008c Link: 8 (.dynstr) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00008c Link: 7 (.dynstr) # GNU-NEXT: 0x0000: Version: 1 File: verneed1.so.0 Cnt: 2 # GNU-NEXT: 0x0010: Name: v1 Flags: none Version: 4 # GNU-NEXT: 0x0020: Name: v2 Flags: none Version: 5 diff --git a/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test b/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test index 6a600dc3b69..cc40f49d4a5 100644 --- a/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test +++ b/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test @@ -15,7 +15,7 @@ # GNU: Section Headers: # GNU: [Nr] Name Type Address Off Size ES Flg Lk Inf Al # GNU: warning: '[[FILE]]': invalid sh_type for string table section [index 1]: expected SHT_STRTAB, but got SHT_PROGBITS -# GNU: [ 1] .shstrtab PROGBITS 0000000000000000 000040 00001b 00 0 0 0 +# GNU: [ 1] .shstrtab PROGBITS 0000000000000000 000040 000013 00 0 0 0 ## Test we report multiple identical warnings (one for each object) when dumping an archive. diff --git a/test/tools/llvm-readobj/reloc-types-elf-aarch64.test b/test/tools/llvm-readobj/reloc-types-elf-aarch64.test index f50668c3539..fdd3b97b6b2 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-aarch64.test +++ b/test/tools/llvm-readobj/reloc-types-elf-aarch64.test @@ -140,7 +140,6 @@ Sections: Content: 00 - Name: .rela.text Type: SHT_RELA - Link: .symtab AddressAlign: 0x0000000000000008 EntSize: 0x0000000000000018 Info: .text diff --git a/test/tools/llvm-readobj/reloc-types-elf-arm.test b/test/tools/llvm-readobj/reloc-types-elf-arm.test index 6e29637d357..ac6bda68587 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-arm.test +++ b/test/tools/llvm-readobj/reloc-types-elf-arm.test @@ -149,7 +149,6 @@ Sections: Content: 00 - Name: .rel.text Type: SHT_REL - Link: .symtab AddressAlign: 0x0000000000000004 EntSize: 0x0000000000000008 Info: .text diff --git a/test/tools/llvm-readobj/reloc-types-elf-lanai.test b/test/tools/llvm-readobj/reloc-types-elf-lanai.test index 270e2c397d3..b5804c9aa57 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-lanai.test +++ b/test/tools/llvm-readobj/reloc-types-elf-lanai.test @@ -26,7 +26,6 @@ Sections: Content: 00 - Name: .rela.text Type: SHT_RELA - Link: .symtab AddressAlign: 0x0000000000000004 EntSize: 0x000000000000000C Info: .text diff --git a/test/tools/llvm-readobj/reloc-types-elf-mips.test b/test/tools/llvm-readobj/reloc-types-elf-mips.test index b948a3d5a6d..16dfd2f77dd 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-mips.test +++ b/test/tools/llvm-readobj/reloc-types-elf-mips.test @@ -70,7 +70,6 @@ Sections: Content: 00 - Name: .rel.text Type: SHT_REL - Link: .symtab AddressAlign: 0x0000000000000004 EntSize: 0x0000000000000008 Info: .text diff --git a/test/tools/llvm-readobj/reloc-types-elf-mips64.test b/test/tools/llvm-readobj/reloc-types-elf-mips64.test index f04064217bc..f1fefb26974 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-mips64.test +++ b/test/tools/llvm-readobj/reloc-types-elf-mips64.test @@ -70,7 +70,6 @@ Sections: Content: 00 - Name: .rela.text Type: SHT_RELA - Link: .symtab AddressAlign: 0x0000000000000008 EntSize: 0x0000000000000018 Info: .text diff --git a/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml b/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml index 6f21c3212bd..9519d1f05ba 100644 --- a/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml +++ b/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml @@ -62,7 +62,6 @@ Symbols: # INVALID-ENTRY: - Name: .llvm_addrsig # INVALID-ENTRY-NEXT: Type: SHT_LLVM_ADDRSIG -# INVALID-ENTRY-NEXT: Link: .symtab # INVALID-ENTRY-NEXT: Content: FFFFFFFFFF --- !ELF @@ -83,7 +82,6 @@ Sections: # EMPTY: - Name: .llvm_addrsig # EMPTY-NEXT: Type: SHT_LLVM_ADDRSIG -# EMPTY-NEXT: Link: .symtab # EMPTY-NEXT: Symbols: [] --- !ELF diff --git a/test/tools/obj2yaml/elf-no-symtab.yaml b/test/tools/obj2yaml/elf-no-symtab.yaml new file mode 100644 index 00000000000..cab5953fb7d --- /dev/null +++ b/test/tools/obj2yaml/elf-no-symtab.yaml @@ -0,0 +1,43 @@ +## Check that obj2yaml doesn't create a "Symbols" tag for the objects +## without a symbol table. + +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=NOSYMTAB + +# NOSYMTAB: --- !ELF +# NOSYMTAB-NEXT: FileHeader: +# NOSYMTAB-NEXT: Class: ELFCLASS64 +# NOSYMTAB-NEXT: Data: ELFDATA2LSB +# NOSYMTAB-NEXT: Type: ET_DYN +# NOSYMTAB-NEXT: Machine: EM_X86_64 +# NOSYMTAB-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 + +## Check that obj2yaml creates a "Symbols" tag for the objects +## that have a symbol table. + +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=SYMTAB + +# SYMTAB: --- !ELF +# SYMTAB-NEXT: FileHeader: +# SYMTAB-NEXT: Class: ELFCLASS64 +# SYMTAB-NEXT: Data: ELFDATA2LSB +# SYMTAB-NEXT: Type: ET_DYN +# SYMTAB-NEXT: Machine: EM_X86_64 +# SYMTAB-NEXT: Symbols: [] +# SYMTAB-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Symbols: [] diff --git a/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml b/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml index e926019655d..735ad6ed4ab 100644 --- a/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml +++ b/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml @@ -142,6 +142,7 @@ Sections: Type: SHT_SYMTAB_SHNDX Entries: [ 0 ] Link: .symtab +Symbols: [] ## Check that yaml2obj can't dump the object if SHT_SYMTAB_SHNDX is ## not associated with a SHT_SYMTAB section (this case is illegal). diff --git a/test/tools/obj2yaml/no-symbol-reloc.test b/test/tools/obj2yaml/no-symbol-reloc.test index 351aad3f7f6..f2f1c385ce8 100644 --- a/test/tools/obj2yaml/no-symbol-reloc.test +++ b/test/tools/obj2yaml/no-symbol-reloc.test @@ -26,6 +26,7 @@ # CHECK-NEXT: - Offset: 0x0000000000000004 # CHECK-NEXT: Symbol: '' # CHECK-NEXT: Type: R_X86_64_NONE +# CHECK-NEXT: Symbols: [] # CHECK-NEXT: ... --- !ELF diff --git a/test/tools/obj2yaml/section-group.test b/test/tools/obj2yaml/section-group.test index cd520cb1b36..111bffda8e5 100644 --- a/test/tools/obj2yaml/section-group.test +++ b/test/tools/obj2yaml/section-group.test @@ -66,5 +66,6 @@ Sections: Info: 0xFF Members: - SectionOrType: GRP_COMDAT +Symbols: [] # ERR: Error reading file: {{.*}}2.o: unable to get symbol from section [index 2]: invalid symbol index (255) diff --git a/test/tools/yaml2obj/dynamic-symbols.yaml b/test/tools/yaml2obj/dynamic-symbols.yaml index 9ecb1c278f6..7eb58fa6189 100644 --- a/test/tools/yaml2obj/dynamic-symbols.yaml +++ b/test/tools/yaml2obj/dynamic-symbols.yaml @@ -52,7 +52,7 @@ DynamicSymbols: # NUM: Name: bar # NUM: Section: -# NUM-SAME: .symtab (0x2) +# NUM-SAME: .strtab (0x2) # NUM: error: '[[FILE]]': invalid section index: 255 diff --git a/test/tools/yaml2obj/elf-comdat-broken-info.yaml b/test/tools/yaml2obj/elf-comdat-broken-info.yaml index 929213660a1..6f2f7acd492 100644 --- a/test/tools/yaml2obj/elf-comdat-broken-info.yaml +++ b/test/tools/yaml2obj/elf-comdat-broken-info.yaml @@ -12,7 +12,6 @@ FileHeader: Sections: - Name: .group Type: SHT_GROUP - Link: .symtab Info: 12345 Members: - SectionOrType: GRP_COMDAT diff --git a/test/tools/yaml2obj/elf-custom-null-section.yaml b/test/tools/yaml2obj/elf-custom-null-section.yaml index 90cc6f03f99..e8cbb4edb63 100644 --- a/test/tools/yaml2obj/elf-custom-null-section.yaml +++ b/test/tools/yaml2obj/elf-custom-null-section.yaml @@ -8,9 +8,8 @@ # DEFAULT: Section Headers: # DEFAULT-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al # DEFAULT-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 -# DEFAULT-NEXT: [ 1] .symtab SYMTAB 0000000000000000 000040 000018 18 2 1 8 -# DEFAULT-NEXT: [ 2] .strtab STRTAB 0000000000000000 000058 000001 00 0 0 1 -# DEFAULT-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000059 00001b 00 0 0 1 +# DEFAULT-NEXT: [ 1] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1 +# DEFAULT-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000041 000013 00 0 0 1 --- !ELF FileHeader: @@ -105,9 +104,8 @@ Sections: # OTHER-SECTION-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al # OTHER-SECTION-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 # OTHER-SECTION-NEXT: [ 1] foo PROGBITS 0000000000000000 000040 000000 00 0 0 0 -# OTHER-SECTION-NEXT: [ 2] .symtab SYMTAB 0000000000000000 000040 000018 18 3 1 8 -# OTHER-SECTION-NEXT: [ 3] .strtab STRTAB 0000000000000000 000058 000001 00 0 0 1 -# OTHER-SECTION-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000059 00001f 00 0 0 1 +# OTHER-SECTION-NEXT: [ 2] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1 +# OTHER-SECTION-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000041 000017 00 0 0 1 --- !ELF FileHeader: diff --git a/test/tools/yaml2obj/elf-header-sh-fields.yaml b/test/tools/yaml2obj/elf-header-sh-fields.yaml index 6ae98b2c7fb..821b7741885 100644 --- a/test/tools/yaml2obj/elf-header-sh-fields.yaml +++ b/test/tools/yaml2obj/elf-header-sh-fields.yaml @@ -6,10 +6,10 @@ # RUN: yaml2obj --docnum=1 %s -o %t1 # RUN: llvm-readelf --file-headers %t1 | FileCheck %s --check-prefix=DEFAULT -# DEFAULT: Start of section headers: 120 (bytes into file) +# DEFAULT: Start of section headers: 88 (bytes into file) # DEFAULT: Size of section headers: 64 (bytes) -# DEFAULT: Number of section headers: 4 -# DEFAULT: Section header string table index: 3 +# DEFAULT: Number of section headers: 3 +# DEFAULT: Section header string table index: 2 --- !ELF FileHeader: diff --git a/test/tools/yaml2obj/elf-sht-symtab-shndx.yaml b/test/tools/yaml2obj/elf-sht-symtab-shndx.yaml index 6e20912d76d..612087a305c 100644 --- a/test/tools/yaml2obj/elf-sht-symtab-shndx.yaml +++ b/test/tools/yaml2obj/elf-sht-symtab-shndx.yaml @@ -126,4 +126,3 @@ Sections: Type: SHT_SYMTAB_SHNDX Entries: [ 0 ] EntSize: 2 - Link: .symtab diff --git a/test/tools/yaml2obj/implicit-sections-types.test b/test/tools/yaml2obj/implicit-sections-types.test index 8360fa73d82..2860fa3db5d 100644 --- a/test/tools/yaml2obj/implicit-sections-types.test +++ b/test/tools/yaml2obj/implicit-sections-types.test @@ -24,6 +24,8 @@ FileHeader: Data: ELFDATA2LSB Type: ET_DYN Machine: EM_X86_64 +## Needed to force the creation of the .symtab. +Symbols: [] ## Needed to force the creation of the .dynsym and .dynstr. DynamicSymbols: - Name: foo diff --git a/test/tools/yaml2obj/implicit-sections.test b/test/tools/yaml2obj/implicit-sections.test index 77e9e1c2f63..cde17c23287 100644 --- a/test/tools/yaml2obj/implicit-sections.test +++ b/test/tools/yaml2obj/implicit-sections.test @@ -84,3 +84,30 @@ Sections: - Name: .text.foo Type: SHT_PROGBITS Address: 0x200 + +## Check we don't add a symbol table when no "Symbols" key is specified. + +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: llvm-readelf -S %t3 | FileCheck /dev/null --implicit-check-not=.symtab + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 + +## Check we add a symbol table when "Symbols" key is specified. + +# RUN: yaml2obj --docnum=4 %s -o %t4 +# RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=SYMTAB + +# SYMTAB: .symtab + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Symbols: [] diff --git a/test/tools/yaml2obj/invalid-symboless-relocation.yaml b/test/tools/yaml2obj/invalid-symboless-relocation.yaml index 716778e16f8..9ec956fcf8c 100644 --- a/test/tools/yaml2obj/invalid-symboless-relocation.yaml +++ b/test/tools/yaml2obj/invalid-symboless-relocation.yaml @@ -16,7 +16,6 @@ Sections: Content: "00000000" - Name: .rel.text Type: SHT_REL - Link: .symtab Info: .text Relocations: - Offset: 0x1000 diff --git a/test/tools/yaml2obj/reloc-sec-info.yaml b/test/tools/yaml2obj/reloc-sec-info.yaml index 801fe02e05f..bbbdc859d54 100644 --- a/test/tools/yaml2obj/reloc-sec-info.yaml +++ b/test/tools/yaml2obj/reloc-sec-info.yaml @@ -20,7 +20,6 @@ FileHeader: Sections: - Name: .rela.text Type: SHT_RELA - Link: .symtab Info: 12345 Relocations: diff --git a/test/tools/yaml2obj/symboless-relocation.yaml b/test/tools/yaml2obj/symboless-relocation.yaml index 99f7af61095..680e03e5c14 100644 --- a/test/tools/yaml2obj/symboless-relocation.yaml +++ b/test/tools/yaml2obj/symboless-relocation.yaml @@ -14,7 +14,6 @@ Sections: Content: "00000000" - Name: .rel.text Type: SHT_REL - Link: .symtab Info: .text Relocations: - Offset: 0x1000 diff --git a/test/tools/yaml2obj/symtab-implicit-sections-flags.yaml b/test/tools/yaml2obj/symtab-implicit-sections-flags.yaml index 55ea02ab883..d56c0dafd15 100644 --- a/test/tools/yaml2obj/symtab-implicit-sections-flags.yaml +++ b/test/tools/yaml2obj/symtab-implicit-sections-flags.yaml @@ -77,3 +77,4 @@ FileHeader: Data: ELFDATA2LSB Type: ET_DYN Machine: EM_X86_64 +Symbols: [] diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 2c17b9570e1..35c33960c37 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -200,9 +200,13 @@ template Expected ELFDumper::dump() { return TableOrErr.takeError(); ShndxTable = *TableOrErr; } - if (SymTab) - if (Error E = dumpSymbols(SymTab, Y->Symbols)) + + if (SymTab) { + Y->Symbols.emplace(); + if (Error E = dumpSymbols(SymTab, *Y->Symbols)) return std::move(E); + } + if (DynSymTab) if (Error E = dumpSymbols(DynSymTab, Y->DynamicSymbols)) return std::move(E); -- 2.11.4.GIT