Index: llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml =================================================================== --- llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml +++ llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml @@ -5,7 +5,6 @@ # CHECK-NEXT: Type: SHT_RELA # CHECK-NEXT: Link: .symtab # CHECK-NEXT: AddressAlign: 0x0000000000000008 -# CHECK-NEXT: EntSize: 0x0000000000000018 # CHECK-NEXT: Info: .text # CHECK-NEXT: Relocations: # CHECK-NEXT: - Symbol: main Index: llvm/test/Object/obj2yaml.test =================================================================== --- llvm/test/Object/obj2yaml.test +++ llvm/test/Object/obj2yaml.test @@ -362,7 +362,6 @@ # ELF-MIPSEL-NEXT: Type: SHT_REL # ELF-MIPSEL-NEXT: Link: .symtab # ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004 -# ELF-MIPSEL-NEXT: EntSize: 0x0000000000000008 # ELF-MIPSEL-NEXT: Info: .text # ELF-MIPSEL-NEXT: Relocations: # ELF-MIPSEL-NEXT: - Symbol: _gp_disp @@ -483,7 +482,6 @@ # ELF-MIPS64EL-NEXT: Type: SHT_RELA # ELF-MIPS64EL-NEXT: Link: .symtab # ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000008 -# ELF-MIPS64EL-NEXT: EntSize: 0x0000000000000018 # ELF-MIPS64EL-NEXT: Info: .data # ELF-MIPS64EL-NEXT: Relocations: # ELF-MIPS64EL-NEXT: - Symbol: zed @@ -552,7 +550,6 @@ # ELF-X86-64-NEXT: Address: 0x0000000000000038 # ELF-X86-64-NEXT: Link: .symtab # ELF-X86-64-NEXT: AddressAlign: 0x0000000000000008 -# ELF-X86-64-NEXT: EntSize: 0x0000000000000018 # ELF-X86-64-NEXT: Info: .text # ELF-X86-64-NEXT: Relocations: # ELF-X86-64-NEXT: - Offset: 0x000000000000000D Index: llvm/test/tools/obj2yaml/dynamic-section.test =================================================================== --- llvm/test/tools/obj2yaml/dynamic-section.test +++ llvm/test/tools/obj2yaml/dynamic-section.test @@ -3,14 +3,14 @@ ## Check we can use obj2yaml to yamalize the object containing ## .dynamic section. Check that resulting section has the -## proper attributes and dynamic tags. +## proper attributes and dynamic tags and that we do not dump +## the default sh_entsize. # CHECK: Sections: # CHECK-NEXT: - Name: .dynamic # CHECK-NEXT: Type: SHT_DYNAMIC # CHECK-NEXT: Address: 0x0000000000001000 # CHECK-NEXT: AddressAlign: 0x0000000000002000 -# CHECK-NEXT: EntSize: 0x0000000000000010 # CHECK-NEXT: Entries: # CHECK-NEXT: - Tag: DT_NULL # CHECK-NEXT: Value: 0x0000000000000000 Index: llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml +++ llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml @@ -10,9 +10,8 @@ # CHECK-NEXT: Type: ET_REL # CHECK-NEXT: Machine: EM_PPC64 # CHECK-NEXT: Sections: -# CHECK-NEXT: - Name: .rela.text -# CHECK-NEXT: Type: SHT_RELA -# CHECK-NEXT: EntSize: 0x0000000000000018 +# CHECK-NEXT: - Name: .rela.text +# CHECK-NEXT: Type: SHT_RELA # CHECK-NEXT: Relocations: # CHECK-NEXT: - Type: R_PPC64_NONE # CHECK-NEXT: - Type: R_PPC64_ADDR32 Index: llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml +++ llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml @@ -19,11 +19,11 @@ # CHECK-NEXT: AddressAlignment: # CHECK-NEXT: EntrySize: -# YAML: - Name: .rela.dyn -# YAML-NEXT: Type: SHT_RELA -# YAML-NEXT: Flags: [ SHF_ALLOC ] -# YAML-NEXT: Link: .dynsym -# YAML-NEXT: EntSize: 0x0000000000000018 +# YAML: - Name: .rela.dyn +# YAML-NEXT: Type: SHT_RELA +# YAML-NEXT: Flags: [ SHF_ALLOC ] +# YAML-NEXT: Link: .dynsym +# YAML-NEXT: - Name: --- !ELF FileHeader: @@ -37,7 +37,6 @@ Type: SHT_RELA Flags: [ SHF_ALLOC ] Link: .dynsym - EntSize: 0x0000000000000018 # Add at least one symbol to trigger the .dynsym emission. DynamicSymbols: - Name: bar 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 @@ -16,7 +16,6 @@ # CHECK-NEXT: Flags: [ SHF_ALLOC, SHF_EXECINSTR ] # CHECK-NEXT: - Name: .rela.text # CHECK-NEXT: Type: SHT_RELA -# CHECK-NEXT: EntSize: 0x0000000000000018 # CHECK-NEXT: Info: .text # CHECK-NEXT: Relocations: # CHECK-NEXT: - Type: R_X86_64_NONE Index: llvm/test/tools/obj2yaml/relocation-type.yaml =================================================================== --- llvm/test/tools/obj2yaml/relocation-type.yaml +++ llvm/test/tools/obj2yaml/relocation-type.yaml @@ -13,7 +13,6 @@ # CHECK-NEXT: Sections: # CHECK-NEXT: - Name: .rela.text # CHECK-NEXT: Type: SHT_RELA -# CHECK-NEXT: EntSize: 0x0000000000000018 # CHECK-NEXT: Relocations: # CHECK-NEXT: - Offset: 0x0000000000000009 # CHECK-NEXT: Type: [[FIRST]] Index: llvm/test/tools/obj2yaml/relr-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/relr-section.yaml +++ llvm/test/tools/obj2yaml/relr-section.yaml @@ -1,7 +1,8 @@ ## Test how we dump SHT_RELR sections for 32 and 64-bit targets. ## Test we use the "Entries" property when it is possible do -## dump values correctly. +## dump values correctly. Check we do not dump sh_entsize when +## it has the default value. # RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=LSB %s -o %t.32le # RUN: obj2yaml %t.32le | FileCheck %s --check-prefix=ELF32LE @@ -15,25 +16,21 @@ # ELF64LE: Sections: # ELF64LE-NEXT: - Name: .relr.dyn # ELF64LE-NEXT: Type: SHT_RELR -# ELF64LE-NEXT: EntSize: 0x0000000000000008 # ELF64LE-NEXT: Entries: [ 0x8877665544332211 ] # ELF32LE: Sections: # ELF32LE-NEXT: - Name: .relr.dyn # ELF32LE-NEXT: Type: SHT_RELR -# ELF32LE-NEXT: EntSize: 0x0000000000000004 # ELF32LE-NEXT: Entries: [ 0x0000000044332211, 0x0000000088776655 ] # ELF64BE: Sections: # ELF64BE-NEXT: - Name: .relr.dyn # ELF64BE-NEXT: Type: SHT_RELR -# ELF64BE-NEXT: EntSize: 0x0000000000000008 # ELF64BE-NEXT: Entries: [ 0x1122334455667788 ] # ELF32BE: Sections: # ELF32BE-NEXT: - Name: .relr.dyn # ELF32BE-NEXT: Type: SHT_RELR -# ELF32BE-NEXT: EntSize: 0x0000000000000004 # ELF32BE-NEXT: Entries: [ 0x0000000011223344, 0x0000000055667788 ] --- !ELF @@ -54,7 +51,6 @@ # CONTENT: - Name: .relr.dyn # CONTENT-NEXT: Type: SHT_RELR -# CONTENT-NEXT: EntSize: 0x0000000000000008 # CONTENT-NEXT: Content: '11223344556677' --- !ELF Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -521,6 +521,22 @@ return Error::success(); } +template +static unsigned getDefaultShEntSize(ELFYAML::ELF_SHT SecType) { + switch (SecType) { + case ELF::SHT_REL: + return sizeof(typename ELFT::Rel); + case ELF::SHT_RELA: + return sizeof(typename ELFT::Rela); + case ELF::SHT_RELR: + return sizeof(typename ELFT::Relr); + case ELF::SHT_DYNAMIC: + return sizeof(typename ELFT::Dyn); + default: + return 0; + } +} + template Error ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S) { @@ -532,7 +548,8 @@ if (Shdr->sh_addr) S.Address = static_cast(Shdr->sh_addr); S.AddressAlign = Shdr->sh_addralign; - if (Shdr->sh_entsize) + + if (Shdr->sh_entsize != getDefaultShEntSize(S.Type)) S.EntSize = static_cast(Shdr->sh_entsize); auto NameOrErr = getUniquedSectionName(Shdr);