[PATCH] D93854: [obj2yaml,yaml2obj] - Fix issues with creating/dumping group sections.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 28 01:32:22 PST 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
grimar requested review of this revision.
Herald added a project: LLVM.
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).
Depends on D93753 <https://reviews.llvm.org/D93753>
https://reviews.llvm.org/D93854
Files:
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/test/tools/obj2yaml/ELF/section-group.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Index: llvm/tools/obj2yaml/elf2yaml.cpp
===================================================================
--- llvm/tools/obj2yaml/elf2yaml.cpp
+++ llvm/tools/obj2yaml/elf2yaml.cpp
@@ -724,6 +724,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:
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=<none>]]
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/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 =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93854.313837.patch
Type: text/x-patch
Size: 2823 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201228/db41c592/attachment.bin>
More information about the llvm-commits
mailing list