Author: Georgii Rymar Date: 2021-01-12T14:07:42+03:00 New Revision: 60df7c08b1f4447309c0c07fec1c8bc7267562fc
URL: https://github.com/llvm/llvm-project/commit/60df7c08b1f4447309c0c07fec1c8bc7267562fc DIFF: https://github.com/llvm/llvm-project/commit/60df7c08b1f4447309c0c07fec1c8bc7267562fc.diff LOG: [obj2yaml,yaml2obj] - Fix issues with creating/dumping group sections. We have the following issues related to group sections: 1) yaml2obj is unable to set the custom `sh_entsize` value, because the `EntSize` key is currently ignored. 2) obj2yaml is unable to dump the group section which `sh_entsize != 4`. 3) obj2yaml always dumps the "EntSize" for group sections, though usually we are trying to omit dumping default values when dumping keys. I.e. we should not print the "EntSize" key when `sh_entsize` == 4. This patch fixes (1),(3) and adds the test case to document the behavior of (2). Differential revision: https://reviews.llvm.org/D93854 Added: Modified: llvm/lib/ObjectYAML/ELFEmitter.cpp llvm/test/tools/obj2yaml/ELF/section-group.yaml llvm/test/tools/yaml2obj/ELF/group.yaml llvm/tools/obj2yaml/elf2yaml.cpp Removed: ################################################################################ diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 010a881379f3..181b130de621 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1275,7 +1275,10 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader, 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 = diff --git a/llvm/test/tools/obj2yaml/ELF/section-group.yaml b/llvm/test/tools/obj2yaml/ELF/section-group.yaml index 33044ceeb36c..bdd65908992d 100644 --- a/llvm/test/tools/obj2yaml/ELF/section-group.yaml +++ b/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 @@ FileHeader: 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=<none>]] Members: - SectionOrType: GRP_COMDAT - SectionOrType: [[SEC=.rodata]] @@ -33,6 +36,14 @@ Symbols: 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. diff --git a/llvm/test/tools/yaml2obj/ELF/group.yaml b/llvm/test/tools/yaml2obj/ELF/group.yaml index 56794d9f14d7..1f061ade5769 100644 --- a/llvm/test/tools/yaml2obj/ELF/group.yaml +++ b/llvm/test/tools/yaml2obj/ELF/group.yaml @@ -19,6 +19,7 @@ Sections: Type: SHT_GROUP Link: 0x1 Info: 0x2 + EntSize: [[ENTSIZE=<none>]] Size: [[SIZE=<none>]] Content: [[CONTENT=<none>]] Members: [[MEMBERS=<none>]] @@ -68,10 +69,19 @@ Sections: # 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 diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index dacbaaf482c0..f29b1ebca7de 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -725,6 +725,8 @@ template <class ELFT> 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: _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits