diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1396,6 +1396,11 @@ SN2I.lookup(".dynsym", Link)) SHeader.sh_link = Link; + if (Section.EntSize) + SHeader.sh_entsize = *Section.EntSize; + else + SHeader.sh_entsize = sizeof(typename ELFT::Word); + if (Section.Content || Section.Size) { SHeader.sh_size = writeContent(CBA, Section.Content, Section.Size); return; diff --git a/llvm/test/tools/obj2yaml/ELF/hash-section.yaml b/llvm/test/tools/obj2yaml/ELF/hash-section.yaml --- a/llvm/test/tools/obj2yaml/ELF/hash-section.yaml +++ b/llvm/test/tools/obj2yaml/ELF/hash-section.yaml @@ -74,3 +74,40 @@ - Name: .oversized Type: SHT_HASH Content: '0100000002000000030000000400000000' + +## Check how we dump the "EntSize" field. When the sh_entsize is 4, +## we don't print it, because it is the default value for the SHT_HASH section. + +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=ENT-SIZE + +# ENT-SIZE: - Name: .hash.entsize.0 +# ENT-SIZE-NEXT: Type: SHT_HASH +# ENT-SIZE-NEXT: EntSize: 0x0000000000000000 +# ENT-SIZE-NEXT: Content: '' +# ENT-SIZE-NEXT: - Name: .hash.entsize.4.default +# ENT-SIZE-NEXT: Type: SHT_HASH +# ENT-SIZE-NEXT: Content: '' +# ENT-SIZE-NEXT: - Name: .hash.entsize.255 +# ENT-SIZE-NEXT: Type: SHT_HASH +# ENT-SIZE-NEXT: EntSize: 0x00000000000000FF +# ENT-SIZE-NEXT: Content: '' + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .hash.entsize.0 + Type: SHT_HASH + EntSize: 0 + Size: 0 + - Name: .hash.entsize.4.default + Type: SHT_HASH + EntSize: 4 + Size: 0 + - Name: .hash.entsize.255 + Type: SHT_HASH + EntSize: 255 + Size: 0 diff --git a/llvm/test/tools/yaml2obj/ELF/hash-section.yaml b/llvm/test/tools/yaml2obj/ELF/hash-section.yaml --- a/llvm/test/tools/yaml2obj/ELF/hash-section.yaml +++ b/llvm/test/tools/yaml2obj/ELF/hash-section.yaml @@ -1,9 +1,11 @@ ## Check how yaml2obj produces SHT_HASH sections. ## Check we can describe a SHT_HASH section using the "Content" tag. +## Check default values of section fields. # RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=CONTENT +# RUN: llvm-readobj --sections --section-data %t1 | \ +# RUN: FileCheck %s -DENTSIZE=4 --check-prefix=CONTENT # CONTENT: Name: .hash # CONTENT-NEXT: Type: SHT_HASH @@ -15,7 +17,7 @@ # CONTENT-NEXT: Link: 1 # CONTENT-NEXT: Info: 0 # CONTENT-NEXT: AddressAlignment: 0 -# CONTENT-NEXT: EntrySize: 0 +# CONTENT-NEXT: EntrySize: [[ENTSIZE]]{{$}} # CONTENT-NEXT: SectionData ( # CONTENT-NEXT: 0000: 01000000 02000000 03000000 04000000 # CONTENT-NEXT: 0010: 05000000 @@ -33,6 +35,13 @@ - Name: .hash Type: SHT_HASH Content: '0100000002000000030000000400000005000000' + EntSize: [[ENTSIZE=]] + +## Check we can set an arbitrary entry size for the SHT_HASH section. + +# RUN: yaml2obj --docnum=1 -DENTSIZE=0xFF %s -o %t1.entsize +# RUN: llvm-readobj --sections --section-data %t1.entsize | \ +# RUN: FileCheck %s -DENTSIZE=255 --check-prefix=CONTENT ## Check we can describe a SHT_HASH section using "Bucket" and "Chain" tags. @@ -280,7 +289,7 @@ # OVERRIDE-NEXT: Link: 0 # OVERRIDE-NEXT: Info: 0 # OVERRIDE-NEXT: AddressAlignment: 0 -# OVERRIDE-NEXT: EntrySize: 0 +# OVERRIDE-NEXT: EntrySize: 4 # OVERRIDE-NEXT: SectionData ( # OVERRIDE-NEXT: 0000: AA000000 BB000000 01000000 02000000 # OVERRIDE-NEXT: 0010: 03000000 04000000 05000000 diff --git a/llvm/test/tools/yaml2obj/ELF/section-headers-exclude.yaml b/llvm/test/tools/yaml2obj/ELF/section-headers-exclude.yaml --- a/llvm/test/tools/yaml2obj/ELF/section-headers-exclude.yaml +++ b/llvm/test/tools/yaml2obj/ELF/section-headers-exclude.yaml @@ -406,7 +406,7 @@ # RUN: llvm-readelf %t8 --section-headers | FileCheck %s --check-prefix=LINK-HASH # LINK-HASH: [Nr] Name Type Address Off Size ES Flg Lk Inf Al -# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 00 0 0 0 +# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 04 0 0 0 # LINK-HASH-NEXT: [ 2] .gnu_hash GNU_HASH 0000000000000000 000040 000000 00 0 0 0 --- !ELF diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -659,6 +659,8 @@ return sizeof(typename ELFT::Relr); case ELF::SHT_DYNAMIC: return sizeof(typename ELFT::Dyn); + case ELF::SHT_HASH: + return sizeof(typename ELFT::Word); default: if (SecName == ".debug_str") return 1;