[llvm] a02b386 - [obj2yaml] - SHT_DYNAMIC and SHT_REL* sections: stop dumping sh_entsize field when it has the default value.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 19 07:26:17 PDT 2020
Author: Georgii Rymar
Date: 2020-03-19T17:25:53+03:00
New Revision: a02b38698b409c4bb93fc22782a769674c63e28f
URL: https://github.com/llvm/llvm-project/commit/a02b38698b409c4bb93fc22782a769674c63e28f
DIFF: https://github.com/llvm/llvm-project/commit/a02b38698b409c4bb93fc22782a769674c63e28f.diff
LOG: [obj2yaml] - SHT_DYNAMIC and SHT_REL* sections: stop dumping sh_entsize field when it has the default value.
Currently obj2yaml always emits the `EntSize` property when `sh_entsize != 0`.
It is not correct. For example, for `SHT_DYNAMIC` section, `EntSize == 0`
is abnormal, while `sizeof(ELFT::Dyn)` is the expected default.
To reduce the output produces we should not dump default values.
yaml2obj tests that shows `sh_entsize` values produced are:
1) For `SHT_REL*` sections: `yaml2obj\ELF\reloc-sec-entry-size.yaml`
2) For `SHT_DYNAMIC`: `yaml2obj\ELF\dynamic-section.yaml`
Differential revision: https://reviews.llvm.org/D76227
Added:
llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml
Modified:
llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml
llvm/test/Object/obj2yaml.test
llvm/test/tools/obj2yaml/dynamic-section.test
llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml
llvm/test/tools/obj2yaml/no-symbol-reloc.test
llvm/test/tools/obj2yaml/relocation-type.yaml
llvm/test/tools/obj2yaml/relr-section.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml b/llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml
index 40eec9497130..17b638da0eb8 100644
--- a/llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml
+++ b/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
diff --git a/llvm/test/Object/obj2yaml.test b/llvm/test/Object/obj2yaml.test
index 748e713d1a95..a5f008ffd238 100644
--- a/llvm/test/Object/obj2yaml.test
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/dynamic-section.test b/llvm/test/tools/obj2yaml/dynamic-section.test
index 69a27fec1a2c..65eb335746a8 100644
--- a/llvm/test/tools/obj2yaml/dynamic-section.test
+++ b/llvm/test/tools/obj2yaml/dynamic-section.test
@@ -1,6 +1,6 @@
-## Check we can use obj2yaml to yamalize the object containing
-## .dynamic section. Check that resulting section has the
-## proper attributes and dynamic tags.
+## Check we can use obj2yaml to yamalize the object containing .dynamic
+## section. Check that resulting section has the proper attributes and
+## dynamic tags and that we do not dump the default sh_entsize.
# RUN: yaml2obj -DENTSIZE=0x10 %s -o %t1
# RUN: obj2yaml %t1 | FileCheck %s
@@ -10,7 +10,6 @@
# 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
diff --git a/llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml b/llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml
index 512b71ea4d83..e476242eb1c6 100644
--- a/llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml b/llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml
new file mode 100644
index 000000000000..8863ac8c9e9b
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/elf-reladyn-section-shinfo.yaml
@@ -0,0 +1,43 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj --sections %t | FileCheck %s
+# RUN: obj2yaml %t | FileCheck %s --check-prefix=YAML
+
+## .rela.dyn is a dynamic relocation section that normally has
+## no value in sh_info field. Check we are able to use
+## yaml2obj/obj2yaml without needing to explicitly set it.
+
+# CHECK: Name: .rela.dyn
+# CHECK-NEXT: Type: SHT_RELA
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Link:
+# CHECK-NEXT: Info: 0
+# 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: - Name:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+ Entry: 0x0000000000001000
+Sections:
+ - Name: .rela.dyn
+ Type: SHT_RELA
+ Flags: [ SHF_ALLOC ]
+ Link: .dynsym
+# Add at least one symbol to trigger the .dynsym emission.
+DynamicSymbols:
+ - Name: bar
+ Binding: STB_GLOBAL
diff --git a/llvm/test/tools/obj2yaml/no-symbol-reloc.test b/llvm/test/tools/obj2yaml/no-symbol-reloc.test
index 97800491a7af..8940f6a9e8b7 100644
--- a/llvm/test/tools/obj2yaml/no-symbol-reloc.test
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/relocation-type.yaml b/llvm/test/tools/obj2yaml/relocation-type.yaml
index 6ab8e9c462ea..d069abe68eda 100644
--- a/llvm/test/tools/obj2yaml/relocation-type.yaml
+++ b/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]]
diff --git a/llvm/test/tools/obj2yaml/relr-section.yaml b/llvm/test/tools/obj2yaml/relr-section.yaml
index 11ca6ff896c0..3134fcc22abe 100644
--- a/llvm/test/tools/obj2yaml/relr-section.yaml
+++ b/llvm/test/tools/obj2yaml/relr-section.yaml
@@ -1,72 +1,68 @@
-## 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.
-
-# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=LSB %s -o %t.32le
-# RUN: obj2yaml %t.32le | FileCheck %s --check-prefix=ELF32LE
-# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=MSB %s -o %t.32be
-# RUN: obj2yaml %t.32be | FileCheck %s --check-prefix=ELF32BE
-# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=LSB %s -o %t.64le
-# RUN: obj2yaml %t.64le | FileCheck %s --check-prefix=ELF64LE
-# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=MSB %s -o %t.64be
-# RUN: obj2yaml %t.64be | FileCheck %s --check-prefix=ELF64BE
-
-# 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
-FileHeader:
- Class: ELFCLASS[[BITS]]
- Data: ELFDATA2[[ENCODE]]
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .relr.dyn
- Type: SHT_RELR
- Content: "1122334455667788"
-
-## Test we use the "Content" property when a SHT_RELR section is truncated.
-
-# RUN: yaml2obj --docnum=2 %s -o %t.content
-# RUN: obj2yaml %t.content | FileCheck %s --check-prefix=CONTENT
-
-# CONTENT: - Name: .relr.dyn
-# CONTENT-NEXT: Type: SHT_RELR
-# CONTENT-NEXT: EntSize: 0x0000000000000008
-# CONTENT-NEXT: Content: '11223344556677'
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2MSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .relr.dyn
- Type: SHT_RELR
- Content: "11223344556677"
+## Test how we dump SHT_RELR sections for 32 and 64-bit targets.
+
+## Test we use the "Entries" property when it is possible to
+## dump values correctly. Also, 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
+# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=MSB %s -o %t.32be
+# RUN: obj2yaml %t.32be | FileCheck %s --check-prefix=ELF32BE
+# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=LSB %s -o %t.64le
+# RUN: obj2yaml %t.64le | FileCheck %s --check-prefix=ELF64LE
+# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=MSB %s -o %t.64be
+# RUN: obj2yaml %t.64be | FileCheck %s --check-prefix=ELF64BE
+
+# ELF64LE: Sections:
+# ELF64LE-NEXT: - Name: .relr.dyn
+# ELF64LE-NEXT: Type: SHT_RELR
+# ELF64LE-NEXT: Entries: [ 0x8877665544332211 ]
+
+# ELF32LE: Sections:
+# ELF32LE-NEXT: - Name: .relr.dyn
+# ELF32LE-NEXT: Type: SHT_RELR
+# ELF32LE-NEXT: Entries: [ 0x0000000044332211, 0x0000000088776655 ]
+
+# ELF64BE: Sections:
+# ELF64BE-NEXT: - Name: .relr.dyn
+# ELF64BE-NEXT: Type: SHT_RELR
+# ELF64BE-NEXT: Entries: [ 0x1122334455667788 ]
+
+# ELF32BE: Sections:
+# ELF32BE-NEXT: - Name: .relr.dyn
+# ELF32BE-NEXT: Type: SHT_RELR
+# ELF32BE-NEXT: Entries: [ 0x0000000011223344, 0x0000000055667788 ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS[[BITS]]
+ Data: ELFDATA2[[ENCODE]]
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .relr.dyn
+ Type: SHT_RELR
+ Content: "1122334455667788"
+
+## Test we use the "Content" property when a SHT_RELR section is truncated.
+
+# RUN: yaml2obj --docnum=2 %s -o %t.content
+# RUN: obj2yaml %t.content | FileCheck %s --check-prefix=CONTENT
+
+# CONTENT: - Name: .relr.dyn
+# CONTENT-NEXT: Type: SHT_RELR
+# CONTENT-NEXT: Content: '11223344556677'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .relr.dyn
+ Type: SHT_RELR
+ Content: "11223344556677"
## Test we are able to dump a SHT_RELR section when sh_entsize is invalid.
## Here we use 0xFE as a value instead of expected 0x8.
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index e6bdc1f5dc0f..b7fb99fa3431 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -521,6 +521,22 @@ Error ELFDumper<ELFT>::dumpRelocation(const RelT *Rel, const Elf_Shdr *SymTab,
return Error::success();
}
+template <class ELFT>
+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 <class ELFT>
Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
ELFYAML::Section &S) {
@@ -532,7 +548,8 @@ Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
if (Shdr->sh_addr)
S.Address = static_cast<uint64_t>(Shdr->sh_addr);
S.AddressAlign = Shdr->sh_addralign;
- if (Shdr->sh_entsize)
+
+ if (Shdr->sh_entsize != getDefaultShEntSize<ELFT>(S.Type))
S.EntSize = static_cast<llvm::yaml::Hex64>(Shdr->sh_entsize);
auto NameOrErr = getUniquedSectionName(Shdr);
More information about the llvm-commits
mailing list