Skip to content

Commit 1649c00

Browse files
author
Georgii Rymar
committed
[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
1 parent 827f49e commit 1649c00

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,12 @@ void ELFState<ELFT>::writeSectionContent(
796796
"Section type is not SHT_REL nor SHT_RELA");
797797

798798
bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
799-
SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
800-
SHeader.sh_size = SHeader.sh_entsize * Section.Relocations.size();
799+
if (Section.EntSize)
800+
SHeader.sh_entsize = *Section.EntSize;
801+
else
802+
SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
803+
SHeader.sh_size = (IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel)) *
804+
Section.Relocations.size();
801805

802806
// For relocation section set link to .symtab by default.
803807
unsigned Link = 0;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Test how yaml2obj sets values for sh_entsize fields of relocation sections.
2+
3+
# RUN: yaml2obj --docnum=1 %s -o %t64
4+
# RUN: llvm-readelf --sections %t64 | FileCheck %s --check-prefix=ELF64
5+
6+
# RUN: yaml2obj --docnum=2 %s -o %t32
7+
# RUN: llvm-readelf --sections %t32 | FileCheck %s --check-prefix=ELF32
8+
9+
# ELF64: Name Type Address Off Size ES
10+
# ELF64: .rela.default RELA 0000000000000000 000040 000000 18
11+
# ELF64: .rel.default REL 0000000000000000 000040 000000 10
12+
# ELF64: .relr.default RELR 0000000000000000 000040 000000 08
13+
# ELF64: .rela.custom RELA 0000000000000000 000040 000000 ff
14+
# ELF64: .rel.custom REL 0000000000000000 000040 000000 ff
15+
# ELF64: .relr.custom RELR 0000000000000000 000040 000000 ff
16+
17+
# ELF32: Name Type Address Off Size ES
18+
# ELF32: .rela.default RELA 00000000 000034 000000 0c
19+
# ELF32: .rel.default REL 00000000 000034 000000 08
20+
# ELF32: .relr.default RELR 00000000 000034 000000 04
21+
# ELF32: .rela.custom RELA 00000000 000034 000000 ff
22+
# ELF32: .rel.custom REL 00000000 000034 000000 ff
23+
# ELF32: .relr.custom RELR 00000000 000034 000000 ff
24+
25+
--- !ELF
26+
FileHeader:
27+
Class: ELFCLASS64
28+
Data: ELFDATA2LSB
29+
Type: ET_REL
30+
Machine: EM_X86_64
31+
Sections:
32+
## Check default sh_entsize field values.
33+
- Name: .rela.default
34+
Type: SHT_RELA
35+
- Name: .rel.default
36+
Type: SHT_REL
37+
- Name: .relr.default
38+
Type: SHT_RELR
39+
## Check we can set sh_entsize fields to arbitrary values.
40+
- Name: .rela.custom
41+
Type: SHT_RELA
42+
EntSize: 0xFF
43+
- Name: .rel.custom
44+
Type: SHT_REL
45+
EntSize: 0xFF
46+
- Name: .relr.custom
47+
Type: SHT_RELR
48+
EntSize: 0xFF
49+
50+
--- !ELF
51+
FileHeader:
52+
Class: ELFCLASS32
53+
Data: ELFDATA2LSB
54+
Type: ET_REL
55+
Machine: EM_386
56+
Sections:
57+
## Check default sh_entsizes field values.
58+
- Name: .rela.default
59+
Type: SHT_RELA
60+
- Name: .rel.default
61+
Type: SHT_REL
62+
- Name: .relr.default
63+
Type: SHT_RELR
64+
## Check we can set sh_entsize fields to arbitrary values.
65+
- Name: .rela.custom
66+
Type: SHT_RELA
67+
EntSize: 0xFF
68+
- Name: .rel.custom
69+
Type: SHT_REL
70+
EntSize: 0xFF
71+
- Name: .relr.custom
72+
Type: SHT_RELR
73+
EntSize: 0xFF

0 commit comments

Comments
 (0)