Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1275,7 +1275,10 @@ SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; - SHeader.sh_entsize = 4; + if (Section.EntSize) + SHeader.sh_entsize = *Section.EntSize; + else + SHeader.sh_entsize = sizeof(typename ELFT::Word); if (Section.Signature) SHeader.sh_info = Index: llvm/test/tools/obj2yaml/ELF/section-group.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/section-group.yaml +++ llvm/test/tools/obj2yaml/ELF/section-group.yaml @@ -1,13 +1,15 @@ ## Checks that the tool is able to read section groups from ELF. +## Check how groups sections are dumped. +## Check we don't dump the "EntSize" key when sh_entsize == 4. + # RUN: yaml2obj %s -o %t1.o # RUN: obj2yaml %t1.o | FileCheck %s -DSEC=.rodata -# CHECK: - Name: .group -# CHECK-NEXT: Type: SHT_GROUP -# CHECK-NEXT: Link: .symtab -# CHECK-NEXT: EntSize: 0x4 -# CHECK-NEXT: Info: signature +# CHECK: - Name: .group +# CHECK-NEXT: Type: SHT_GROUP +# CHECK-NEXT: Link: .symtab +# CHECK-NEXT: Info: signature # CHECK-NEXT: Members: # CHECK-NEXT: - SectionOrType: GRP_COMDAT # CHECK-NEXT: - SectionOrType: [[SEC]] @@ -19,10 +21,11 @@ Data: ELFDATA2LSB Type: ET_REL Sections: - - Name: .group - Type: SHT_GROUP - Link: .symtab - Info: [[INFO=signature]] + - Name: .group + Type: SHT_GROUP + Link: .symtab + Info: [[INFO=signature]] + EntSize: [[ENTSIZE=]] Members: - SectionOrType: GRP_COMDAT - SectionOrType: [[SEC=.rodata]] @@ -33,6 +36,14 @@ Type: STT_OBJECT Section: .rodata +## Document that yaml2obj can't dump the SHT_GROUP section when its sh_entsize != 4. + +# RUN: yaml2obj %s -DENTSIZE=0xfe -o %t1.entsize.o +# RUN: not obj2yaml %t1.entsize.o 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t1.entsize.o --check-prefix=ENTSIZE + +# ENTSIZE: Error reading file: [[FILE]]: section [index 1] has invalid sh_entsize: expected 4, but got 254 + ## Check we are able to dump members of the SHT_GROUP section even when ## one of them has section index 0. Index: llvm/test/tools/yaml2obj/ELF/group.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/group.yaml +++ llvm/test/tools/yaml2obj/ELF/group.yaml @@ -19,6 +19,7 @@ Type: SHT_GROUP Link: 0x1 Info: 0x2 + EntSize: [[ENTSIZE=]] Size: [[SIZE=]] Content: [[CONTENT=]] Members: [[MEMBERS=]] @@ -68,10 +69,19 @@ # MEMBERS-ERR: error: "Members" cannot be used with "Content" or "Size" ## Check we create an empty section when none of "Size", "Content" or "Members" are specified. +## Check that the default value of sh_entsize is 4. # RUN: yaml2obj %s -o %t.empty.o # RUN: llvm-readelf --sections --section-data %t.empty.o | \ # RUN: FileCheck %s --check-prefix=EMPTY-SEC -# EMPTY-SEC: [Nr] Name Type Address Off Size -# EMPTY-SEC: [ 1] .group GROUP 0000000000000000 000040 000000 +# EMPTY-SEC: [Nr] Name Type Address Off Size ES Flg +# EMPTY-SEC: [ 1] .group GROUP 0000000000000000 000040 000000 04 1 + +## Check that we are able to set an arbitrary entry size for the group section. + +# RUN: yaml2obj %s -DENTSIZE=0xFE -o %t.entsize.o +# RUN: llvm-readelf --sections %t.entsize.o | FileCheck %s --check-prefix=ENTSIZE + +# ENTSIZE: [Nr] Name Type Address Off Size ES Flg +# ENTSIZE: [ 1] .group GROUP 0000000000000000 000040 000000 fe 1 Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -725,6 +725,8 @@ static unsigned getDefaultShEntSize(ELFYAML::ELF_SHT SecType, StringRef SecName) { switch (SecType) { + case ELF::SHT_GROUP: + return sizeof(typename ELFT::Word); case ELF::SHT_REL: return sizeof(typename ELFT::Rel); case ELF::SHT_RELA: