[llvm] 1649c00 - [yaml2obj] - Add a way to set sh_entsize for relocation sections.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 03:51:56 PST 2020
Author: Georgii Rymar
Date: 2020-01-30T14:51:33+03:00
New Revision: 1649c0098a2f94c25acd4976416d7d35aa2bc7b9
URL: https://github.com/llvm/llvm-project/commit/1649c0098a2f94c25acd4976416d7d35aa2bc7b9
DIFF: https://github.com/llvm/llvm-project/commit/1649c0098a2f94c25acd4976416d7d35aa2bc7b9.diff
LOG: [yaml2obj] - Add a way to set sh_entsize for relocation sections.
We are missing ability to override the sh_entsize field for
SHT_REL[A] sections. It would be useful for writing test cases.
Differential revision: https://reviews.llvm.org/D73621
Added:
llvm/test/tools/yaml2obj/ELF/reloc-sec-entry-size.yaml
Modified:
llvm/lib/ObjectYAML/ELFEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index ee7d5f616a73..7a51cbc87659 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -796,8 +796,12 @@ void ELFState<ELFT>::writeSectionContent(
"Section type is not SHT_REL nor SHT_RELA");
bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
- SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
- SHeader.sh_size = SHeader.sh_entsize * Section.Relocations.size();
+ if (Section.EntSize)
+ SHeader.sh_entsize = *Section.EntSize;
+ else
+ SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
+ SHeader.sh_size = (IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)) *
+ Section.Relocations.size();
// For relocation section set link to .symtab by default.
unsigned Link = 0;
diff --git a/llvm/test/tools/yaml2obj/ELF/reloc-sec-entry-size.yaml b/llvm/test/tools/yaml2obj/ELF/reloc-sec-entry-size.yaml
new file mode 100644
index 000000000000..0a4089a969fa
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/ELF/reloc-sec-entry-size.yaml
@@ -0,0 +1,73 @@
+## Test how yaml2obj sets values for sh_entsize fields of relocation sections.
+
+# RUN: yaml2obj --docnum=1 %s -o %t64
+# RUN: llvm-readelf --sections %t64 | FileCheck %s --check-prefix=ELF64
+
+# RUN: yaml2obj --docnum=2 %s -o %t32
+# RUN: llvm-readelf --sections %t32 | FileCheck %s --check-prefix=ELF32
+
+# ELF64: Name Type Address Off Size ES
+# ELF64: .rela.default RELA 0000000000000000 000040 000000 18
+# ELF64: .rel.default REL 0000000000000000 000040 000000 10
+# ELF64: .relr.default RELR 0000000000000000 000040 000000 08
+# ELF64: .rela.custom RELA 0000000000000000 000040 000000 ff
+# ELF64: .rel.custom REL 0000000000000000 000040 000000 ff
+# ELF64: .relr.custom RELR 0000000000000000 000040 000000 ff
+
+# ELF32: Name Type Address Off Size ES
+# ELF32: .rela.default RELA 00000000 000034 000000 0c
+# ELF32: .rel.default REL 00000000 000034 000000 08
+# ELF32: .relr.default RELR 00000000 000034 000000 04
+# ELF32: .rela.custom RELA 00000000 000034 000000 ff
+# ELF32: .rel.custom REL 00000000 000034 000000 ff
+# ELF32: .relr.custom RELR 00000000 000034 000000 ff
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+## Check default sh_entsize field values.
+ - Name: .rela.default
+ Type: SHT_RELA
+ - Name: .rel.default
+ Type: SHT_REL
+ - Name: .relr.default
+ Type: SHT_RELR
+## Check we can set sh_entsize fields to arbitrary values.
+ - Name: .rela.custom
+ Type: SHT_RELA
+ EntSize: 0xFF
+ - Name: .rel.custom
+ Type: SHT_REL
+ EntSize: 0xFF
+ - Name: .relr.custom
+ Type: SHT_RELR
+ EntSize: 0xFF
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_386
+Sections:
+## Check default sh_entsizes field values.
+ - Name: .rela.default
+ Type: SHT_RELA
+ - Name: .rel.default
+ Type: SHT_REL
+ - Name: .relr.default
+ Type: SHT_RELR
+## Check we can set sh_entsize fields to arbitrary values.
+ - Name: .rela.custom
+ Type: SHT_RELA
+ EntSize: 0xFF
+ - Name: .rel.custom
+ Type: SHT_REL
+ EntSize: 0xFF
+ - Name: .relr.custom
+ Type: SHT_RELR
+ EntSize: 0xFF
More information about the llvm-commits
mailing list