Index: llvm/test/Object/obj2yaml.test =================================================================== --- llvm/test/Object/obj2yaml.test +++ llvm/test/Object/obj2yaml.test @@ -416,6 +416,17 @@ # ELF-MIPSEL-NEXT: GPRSize: REG_32 # ELF-MIPSEL-NEXT: CPR1Size: REG_32 # ELF-MIPSEL-NEXT: Flags1: [ ODDSPREG ] +# ELF-MIPSEL-NEXT: - Name: .shstrtab +# ELF-MIPSEL-NEXT: Type: SHT_STRTAB +# ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000001 +# ELF-MIPSEL-NEXT: - Name: .symtab +# ELF-MIPSEL-NEXT: Type: SHT_SYMTAB +# ELF-MIPSEL-NEXT: Link: .strtab +# ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004 +# ELF-MIPSEL-NEXT: EntSize: 0x0000000000000010 +# ELF-MIPSEL-NEXT: - Name: .strtab +# ELF-MIPSEL-NEXT: Type: SHT_STRTAB +# ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000001 # ELF-MIPSEL-NEXT: Symbols: # ELF-MIPSEL-NEXT: - Name: trivial.ll # ELF-MIPSEL-NEXT: Type: STT_FILE @@ -503,6 +514,17 @@ # ELF-MIPS64EL-NEXT: - Name: .pdr # ELF-MIPS64EL-NEXT: Type: SHT_PROGBITS # ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000004 +# ELF-MIPS64EL-NEXT: - Name: .shstrtab +# ELF-MIPS64EL-NEXT: Type: SHT_STRTAB +# ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000001 +# ELF-MIPS64EL-NEXT: - Name: .symtab +# ELF-MIPS64EL-NEXT: Type: SHT_SYMTAB +# ELF-MIPS64EL-NEXT: Link: .strtab +# ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000008 +# ELF-MIPS64EL-NEXT: EntSize: 0x0000000000000018 +# ELF-MIPS64EL-NEXT: - Name: .strtab +# ELF-MIPS64EL-NEXT: Type: SHT_STRTAB +# ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000001 # ELF-MIPS64EL-NEXT: Symbols: # ELF-MIPS64EL-NEXT: - Name: .text # ELF-MIPS64EL-NEXT: Type: STT_SECTION @@ -568,6 +590,17 @@ # ELF-X86-64-NEXT: Symbol: SomeOtherFunction # ELF-X86-64-NEXT: Type: R_X86_64_PC32 # ELF-X86-64-NEXT: Addend: -4 +# ELF-X86-64-NEXT: - Name: .symtab +# ELF-X86-64-NEXT: Type: SHT_SYMTAB +# ELF-X86-64-NEXT: Link: .strtab +# ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008 +# ELF-X86-64-NEXT: EntSize: 0x0000000000000018 +# ELF-X86-64-NEXT: - Name: .strtab +# ELF-X86-64-NEXT: Type: SHT_STRTAB +# ELF-X86-64-NEXT: AddressAlign: 0x0000000000000001 +# ELF-X86-64-NEXT: - Name: .shstrtab +# ELF-X86-64-NEXT: Type: SHT_STRTAB +# ELF-X86-64-NEXT: AddressAlign: 0x0000000000000001 # ELF-X86-64-NEXT: Symbols: # ELF-X86-64-NEXT: - Name: trivial-object-test.s # ELF-X86-64-NEXT: Type: STT_FILE @@ -675,6 +708,17 @@ # ELF-AVR-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ] # ELF-AVR-NEXT: Address: 0x0000000000800060 # ELF-AVR-NEXT: AddressAlign: 0x0000000000000001 +# ELF-AVR-NEXT: - Name: .shstrtab +# ELF-AVR-NEXT: Type: SHT_STRTAB +# ELF-AVR-NEXT: AddressAlign: 0x0000000000000001 +# ELF-AVR-NEXT: - Name: .symtab +# ELF-AVR-NEXT: Type: SHT_SYMTAB +# ELF-AVR-NEXT: Link: .strtab +# ELF-AVR-NEXT: AddressAlign: 0x0000000000000004 +# ELF-AVR-NEXT: EntSize: 0x0000000000000010 +# ELF-AVR-NEXT: - Name: .strtab +# ELF-AVR-NEXT: Type: SHT_STRTAB +# ELF-AVR-NEXT: AddressAlign: 0x0000000000000001 # ELF-AVR-NEXT: Symbols: # ELF-AVR-NEXT: - Name: .text # ELF-AVR-NEXT: Type: STT_SECTION Index: llvm/test/tools/obj2yaml/call-graph-profile-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/call-graph-profile-section.yaml +++ llvm/test/tools/obj2yaml/call-graph-profile-section.yaml @@ -23,7 +23,7 @@ # BASIC-NEXT: - From: bar # BASIC-NEXT: To: foo # BASIC-NEXT: Weight: 98 -# BASIC-NEXT: Symbols: +# BASIC-NEXT: - Name: ## TODO: we should really improve yaml2obj somehow to be able to collapse ## the following four YAML descriptions into a single one. @@ -184,6 +184,17 @@ # INVALID-NEXT: - From: foo # INVALID-NEXT: To: bar # INVALID-NEXT: Weight: 0 +# INVALID-NEXT: - Name: .symtab +# INVALID-NEXT: Type: SHT_SYMTAB +# INVALID-NEXT: Link: .strtab +# INVALID-NEXT: AddressAlign: 0x0000000000000008 +# INVALID-NEXT: EntSize: 0x0000000000000010 +# INVALID-NEXT: - Name: .strtab +# INVALID-NEXT: Type: SHT_STRTAB +# INVALID-NEXT: AddressAlign: 0x0000000000000001 +# INVALID-NEXT: - Name: .shstrtab +# INVALID-NEXT: Type: SHT_STRTAB +# INVALID-NEXT: AddressAlign: 0x0000000000000001 # INVALID-NEXT: Symbols: # INVALID-NEXT: - Name: foo # INVALID-NEXT: - Name: bar Index: llvm/test/tools/obj2yaml/duplicate-symbol-and-section-names.test =================================================================== --- llvm/test/tools/obj2yaml/duplicate-symbol-and-section-names.test +++ llvm/test/tools/obj2yaml/duplicate-symbol-and-section-names.test @@ -41,7 +41,7 @@ # CASE1-NEXT: Type: SHT_PROGBITS # CASE1-NEXT: - Name: '.bar [2]' # CASE1-NEXT: Type: SHT_PROGBITS -# CASE1-NEXT: Symbols: +# CASE1: Symbols: # CASE1-NEXT: - Name: localfoo # CASE1-NEXT: - Name: 'localfoo [1]' # CASE1-NEXT: - Name: 'localfoo [2]' @@ -90,7 +90,7 @@ # CASE2-NEXT: - Offset: 0x0000000000000004 # CASE2-NEXT: Symbol: foo # CASE2-NEXT: Type: R_X86_64_PC32 -# CASE2-NEXT: Symbols: +# CASE2: Symbols: # CASE2-NEXT: - Name: foo # CASE2-NEXT: - Name: 'foo [1]' @@ -125,13 +125,7 @@ # RUN: yaml2obj --docnum=3 %s -o %t3 # RUN: obj2yaml %t3 | FileCheck %s --check-prefix=CASE3 -# CASE3: --- !ELF -# CASE3-NEXT: FileHeader: -# CASE3-NEXT: Class: ELFCLASS64 -# CASE3-NEXT: Data: ELFDATA2LSB -# CASE3-NEXT: Type: ET_DYN -# CASE3-NEXT: Machine: EM_X86_64 -# CASE3-NEXT: Symbols: +# CASE3: Symbols: # CASE3-NEXT: - Name: foo # CASE3-NEXT: Binding: STB_GLOBAL # CASE3-NEXT: DynamicSymbols: Index: llvm/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml +++ llvm/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml @@ -3,14 +3,7 @@ ## Check obj2yaml is able to dump the STB_GNU_UNIQUE symbol. -# CHECK: --- !ELF -# CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: OSABI: ELFOSABI_GNU -# CHECK-NEXT: Type: ET_REL -# CHECK-NEXT: Machine: EM_X86_64 -# CHECK-NEXT: Symbols: +# CHECK: Symbols: # CHECK-NEXT: - Name: foo # CHECK-NEXT: Type: STT_OBJECT # CHECK-NEXT: Binding: STB_GNU_UNIQUE Index: llvm/test/tools/obj2yaml/elf-no-symtab.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-no-symtab.yaml +++ llvm/test/tools/obj2yaml/elf-no-symtab.yaml @@ -10,7 +10,8 @@ # NOSYMTAB-NEXT: Data: ELFDATA2LSB # NOSYMTAB-NEXT: Type: ET_DYN # NOSYMTAB-NEXT: Machine: EM_X86_64 -# NOSYMTAB-NEXT: ... +# NOSYMTAB-NOT: Symbols: +# NOSYMTAB: ... --- !ELF FileHeader: @@ -31,7 +32,7 @@ # SYMTAB-NEXT: Data: ELFDATA2LSB # SYMTAB-NEXT: Type: ET_DYN # SYMTAB-NEXT: Machine: EM_X86_64 -# SYMTAB-NEXT: Symbols: [] +# SYMTAB: Symbols: [] # SYMTAB-NEXT: ... --- !ELF Index: llvm/test/tools/obj2yaml/elf-null-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-null-section.yaml +++ llvm/test/tools/obj2yaml/elf-null-section.yaml @@ -21,7 +21,7 @@ # FIRST-SEC-NEXT: Info: 0x0000000000000002 # FIRST-SEC-NEXT: - Name: .foo # FIRST-SEC-NEXT: Type: SHT_PROGBITS -# FIRST-SEC-NEXT: ... +# FIRST-SEC-NEXT: - Name: --- !ELF FileHeader: @@ -64,7 +64,7 @@ # SECOND-SEC-NEXT: EntSize: 0x0000000000000005 # SECOND-SEC-NEXT: Content: '00000000' # SECOND-SEC-NEXT: Info: 0x0000000000000002 -# SECOND-SEC-NEXT: ... +# SECOND-SEC-NEXT: - Name: --- !ELF FileHeader: @@ -100,7 +100,7 @@ # NULL-SEC-NEXT: Sections: # NULL-SEC-NEXT: - Name: .foo # NULL-SEC-NEXT: Type: SHT_PROGBITS -# NULL-SEC-NEXT: ... +# NULL-SEC-NEXT: - Name: --- !ELF FileHeader: @@ -129,7 +129,7 @@ # NULL-SEC-MIDDLE-NEXT: - Name: .foo # NULL-SEC-MIDDLE-NEXT: Type: SHT_PROGBITS # NULL-SEC-MIDDLE-NEXT: - Type: SHT_NULL -# NULL-SEC-MIDDLE-NEXT: ... +# NULL-SEC-MIDDLE-NEXT: - Name: --- !ELF FileHeader: Index: llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml +++ llvm/test/tools/obj2yaml/elf-sht-symtab-shndx.yaml @@ -19,6 +19,17 @@ # CASE1-NEXT: Link: .symtab # CASE1-NEXT: EntSize: 0x0000000000000004 # CASE1-NEXT: Entries: [ 0, 1, 2 ] +# CASE1-NEXT: - Name: .symtab +# CASE1-NEXT: Type: SHT_SYMTAB +# CASE1-NEXT: Link: .strtab +# CASE1-NEXT: AddressAlign: 0x0000000000000008 +# CASE1-NEXT: EntSize: 0x0000000000000018 +# CASE1-NEXT: - Name: .strtab +# CASE1-NEXT: Type: SHT_STRTAB +# CASE1-NEXT: AddressAlign: 0x0000000000000001 +# CASE1-NEXT: - Name: .shstrtab +# CASE1-NEXT: Type: SHT_STRTAB +# CASE1-NEXT: AddressAlign: 0x0000000000000001 # CASE1-NEXT: Symbols: # CASE1-NEXT: - Name: bar # CASE1-NEXT: Type: STT_SECTION Index: llvm/test/tools/obj2yaml/elf-symbol-visibility.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-symbol-visibility.yaml +++ llvm/test/tools/obj2yaml/elf-symbol-visibility.yaml @@ -2,13 +2,7 @@ # RUN: yaml2obj %s | obj2yaml - | FileCheck %s -# CHECK: --- !ELF -# CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: Type: ET_REL -# CHECK-NEXT: Machine: EM_X86_64 -# CHECK-NEXT: Symbols: +# CHECK: Symbols: # CHECK-NEXT: - Name: default # CHECK-NEXT: - Name: internal # CHECK-NEXT: Other: [ STV_INTERNAL ] Index: llvm/test/tools/obj2yaml/implicit-sections-order.yaml =================================================================== --- /dev/null +++ llvm/test/tools/obj2yaml/implicit-sections-order.yaml @@ -0,0 +1,110 @@ +## Check how obj2yaml dumps SHT_STRTAB/SHT_SYMTAB/SHT_DYNSYM sections. + +# RUN: yaml2obj %s -o %t.so +# RUN: llvm-readelf -S %t.so | FileCheck %s --check-prefix=SECTIONS +# RUN: obj2yaml %t.so | FileCheck %s --check-prefix=OUTPUT + +## Check the information about sections using an independent tool. + +# SECTIONS: Section Headers: +# SECTIONS-NEXT: [Nr] Name Type Address +# SECTIONS-NEXT: [ 0] NULL +# SECTIONS-NEXT: [ 1] .foo.1 PROGBITS +# SECTIONS-NEXT: [ 2] .dynsym DYNSYM 0000000000001000 +# SECTIONS-NEXT: [ 3] .foo.2 PROGBITS +# SECTIONS-NEXT: [ 4] .dynstr STRTAB 0000000000002000 +# SECTIONS-NEXT: [ 5] .foo.3 PROGBITS +# SECTIONS-NEXT: [ 6] .symtab SYMTAB 0000000000003000 +# SECTIONS-NEXT: [ 7] .foo.4 PROGBITS +# SECTIONS-NEXT: [ 8] .strtab STRTAB 0000000000004000 +# SECTIONS-NEXT: [ 9] .foo.5 PROGBITS +# SECTIONS-NEXT: [10] .shstrtab STRTAB 0000000000005000 +# SECTIONS-NEXT: [11] .foo.6 PROGBITS + +## We check that sections order in a YAML output is preserved. +## Also, their virtual addresses were preserved. + +# OUTPUT: --- !ELF +# OUTPUT-NEXT: FileHeader: +# OUTPUT-NEXT: Class: ELFCLASS64 +# OUTPUT-NEXT: Data: ELFDATA2LSB +# OUTPUT-NEXT: Type: ET_DYN +# OUTPUT-NEXT: Machine: EM_X86_64 +# OUTPUT-NEXT: Sections: +# OUTPUT-NEXT: - Name: .foo.1 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: - Name: .dynsym +# OUTPUT-NEXT: Type: SHT_DYNSYM +# OUTPUT-NEXT: Flags: [ SHF_ALLOC ] +# OUTPUT-NEXT: Address: 0x0000000000001000 +# OUTPUT-NEXT: Link: .dynstr +# OUTPUT-NEXT: EntSize: 0x0000000000000018 +# OUTPUT-NEXT: - Name: .foo.2 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: - Name: .dynstr +# OUTPUT-NEXT: Type: SHT_STRTAB +# OUTPUT-NEXT: Flags: [ SHF_ALLOC ] +# OUTPUT-NEXT: Address: 0x0000000000002000 +# OUTPUT-NEXT: - Name: .foo.3 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: - Name: .symtab +# OUTPUT-NEXT: Type: SHT_SYMTAB +# OUTPUT-NEXT: Address: 0x0000000000003000 +# OUTPUT-NEXT: Link: .strtab +# OUTPUT-NEXT: EntSize: 0x0000000000000018 +# OUTPUT-NEXT: - Name: .foo.4 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: - Name: .strtab +# OUTPUT-NEXT: Type: SHT_STRTAB +# OUTPUT-NEXT: Address: 0x0000000000004000 +# OUTPUT-NEXT: - Name: .foo.5 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: - Name: .shstrtab +# OUTPUT-NEXT: Type: SHT_STRTAB +# OUTPUT-NEXT: Address: 0x0000000000005000 +# OUTPUT-NEXT: - Name: .foo.6 +# OUTPUT-NEXT: Type: SHT_PROGBITS +# OUTPUT-NEXT: Symbols: +# OUTPUT-NEXT: - Name: foo +# OUTPUT-NEXT: DynamicSymbols: +# OUTPUT-NEXT: - Name: bar +# OUTPUT-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - Name: .foo.1 + Type: SHT_PROGBITS + - Name: .dynsym + Type: SHT_DYNSYM + Address: 0x1000 + - Name: .foo.2 + Type: SHT_PROGBITS + - Name: .dynstr + Type: SHT_STRTAB + Address: 0x2000 + - Name: .foo.3 + Type: SHT_PROGBITS + - Name: .symtab + Type: SHT_SYMTAB + Address: 0x3000 + - Name: .foo.4 + Type: SHT_PROGBITS + - Name: .strtab + Type: SHT_STRTAB + Address: 0x4000 + - Name: .foo.5 + Type: SHT_PROGBITS + - Name: .shstrtab + Type: SHT_STRTAB + Address: 0x5000 + - Name: .foo.6 + Type: SHT_PROGBITS +Symbols: + - Name: foo +DynamicSymbols: + - Name: bar Index: llvm/test/tools/obj2yaml/invalid-section-name.yaml =================================================================== --- llvm/test/tools/obj2yaml/invalid-section-name.yaml +++ llvm/test/tools/obj2yaml/invalid-section-name.yaml @@ -15,6 +15,11 @@ # CHECK-NEXT: Sections: # CHECK-NEXT: - Name: "{{.*}}" # CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: - Name: "{{.*}}" +# CHECK-NEXT: Type: SHT_STRTAB +# CHECK-NEXT: - Name: "{{.*}}" +# CHECK-NEXT: Type: SHT_STRTAB +# CHECK-NEXT: AddressAlign: 0x0000000000000001 # CHECK-NEXT: ... --- !ELF Index: llvm/test/tools/obj2yaml/no-symbol-reloc.test =================================================================== --- llvm/test/tools/obj2yaml/no-symbol-reloc.test +++ llvm/test/tools/obj2yaml/no-symbol-reloc.test @@ -23,7 +23,7 @@ # CHECK-NEXT: Type: R_X86_64_NONE # CHECK-NEXT: - Offset: 0x0000000000000004 # CHECK-NEXT: Type: R_X86_64_NONE -# CHECK-NEXT: ... +# CHECK-NEXT: - Name: --- !ELF FileHeader: Index: llvm/test/tools/obj2yaml/versym-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/versym-section.yaml +++ llvm/test/tools/obj2yaml/versym-section.yaml @@ -19,7 +19,8 @@ # CHECK-NEXT: AddressAlign: 0x0000000000000002 # CHECK-NEXT: EntSize: 0x0000000000000002 # CHECK-NEXT: Entries: [ 0, 3, 4 ] -# CHECK-NEXT: DynamicSymbols: +# CHECK-NEXT: - Name: +# CHECK: DynamicSymbols: # CHECK-NEXT: - Name: f1 # CHECK-NEXT: Binding: STB_GLOBAL # CHECK-NEXT: - Name: f2 Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -239,9 +239,17 @@ } case ELF::SHT_STRTAB: case ELF::SHT_SYMTAB: - case ELF::SHT_DYNSYM: - // Do not dump these sections. + case ELF::SHT_DYNSYM: { + // We do not really want to dump these sections because they are added + // implicitly. But we want to create placeholders here to print them. + // That allows us to save their correct positions in a binary after a + // futher yaml2obj call. + auto S = std::make_unique(); + if (Error E = dumpCommonSection(&Sec, *S.get())) + return std::move(E); + Y->Chunks.push_back(std::move(S)); break; + } case ELF::SHT_SYMTAB_SHNDX: { Expected SecOrErr = dumpSymtabShndxSection(&Sec);