Skip to content

Commit 554b519

Browse files
Georgii Rymarmemfrob
Georgii Rymar
authored and
memfrob
committed
[lib/ObjectYAML] - Make ELFYAML::Relocation::Offset optional.
Currently `yaml2obj` require `Offset` field in a relocation description. There are many cases when `Offset` is insignificant in a context of a test case. Making `Offset` optional allows to simplify our test cases. This is what this patch does. Also, with this patch `obj2yaml` does not dump a zero offset of a relocation. Differential revision: https://reviews.llvm.org/D75608
1 parent 7bb6ec8 commit 554b519

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+341
-684
lines changed

lld/test/ELF/Inputs/shf-info-link.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ Sections:
1313
Link: .symtab
1414
Info: .text
1515
Relocations:
16-
- Offset: 0x0000000000000000
17-
Symbol: foo
18-
Type: R_X86_64_64
16+
- Symbol: foo
17+
Type: R_X86_64_64
1918
Symbols:
2019
- Name: foo
2120
Binding: STB_GLOBAL

lld/test/ELF/arm-thumb-undefined-weak-narrow.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ Sections:
2929
Link: .symtab
3030
Info: .text
3131
Relocations:
32-
- Offset: 0
33-
Symbol: undefined_weak
32+
- Symbol: undefined_weak
3433
Type: R_ARM_THM_JUMP11
3534

3635
Symbols:

lld/test/ELF/arm-v4bx.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ Sections:
2626
AddressAlign: 0x0000000000000004
2727
Info: .text
2828
Relocations:
29-
- Offset: 0x0000000000000000
30-
Type: R_ARM_V4BX
29+
- Type: R_ARM_V4BX
3130
Symbols:
3231
- Name: .text
3332
Type: STT_SECTION

lld/test/ELF/debug-relocation-none.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Sections:
2828
Link: .symtab
2929
Info: .text
3030
Relocations:
31-
- Offset: 0x0000000000000000
32-
Symbol: bar
31+
- Symbol: bar
3332
Type: R_X86_64_64
3433
- Name: .debug_line
3534
Type: SHT_PROGBITS

lld/test/ELF/i386-pc16.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Sections:
2525
Info: .text
2626
AddressAlign: 0x04
2727
Relocations:
28-
- Offset: 0
29-
Symbol: _start
28+
- Symbol: _start
3029
Type: R_386_16
3130
- Offset: 4
3231
Symbol: _start

lld/test/ELF/icf11.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ Sections:
3232
Link: .symtab
3333
Info: .text.foo
3434
Relocations:
35-
- Offset: 0x0000000000000000
36-
Type: R_X86_64_NONE
35+
- Type: R_X86_64_NONE
3736
- Name: .rela.text.bar
3837
Type: SHT_RELA
3938
Link: .symtab
4039
Info: .text.bar
4140
Relocations:
42-
- Offset: 0
43-
Symbol: zed
41+
- Symbol: zed
4442
Type: R_X86_64_64
4543
Symbols:
4644
- Name: zed

lld/test/ELF/invalid/bad-reloc-target.test

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Sections:
1717
Link: .symtab
1818
Info: 0
1919
Relocations:
20-
- Offset: 0x0000000000000000
21-
Symbol: foo
20+
- Symbol: foo
2221
Type: R_X86_64_64
2322
Symbols:
2423
- Name: foo
@@ -43,8 +42,7 @@ Sections:
4342
Link: .symtab
4443
Info: 99
4544
Relocations:
46-
- Offset: 0x0000000000000000
47-
Symbol: foo
45+
- Symbol: foo
4846
Type: R_X86_64_64
4947
Symbols:
5048
- Name: foo
@@ -70,6 +68,5 @@ Sections:
7068
Type: SHT_RELA
7169
Info: .text
7270
Relocations:
73-
- Offset: 0x0000000000000000
74-
Symbol: 255
71+
- Symbol: 255
7572
Type: R_X86_64_64

lld/test/ELF/invalid/invalid-debug-relocations.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ Sections:
2626
Link: .symtab
2727
Info: .debug_info
2828
Relocations:
29-
- Offset: 0
30-
Symbol: _start
29+
- Symbol: _start
3130
Type: 0xFF
3231
- Offset: 4
3332
Symbol: _start

lld/test/ELF/invalid/invalid-relocation-aarch64.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ Sections:
1919
Link: .symtab
2020
Info: .text
2121
Relocations:
22-
- Offset: 0x0000000000000000
23-
Symbol: foo
22+
- Symbol: foo
2423
Type: 0x400
25-
- Offset: 0x0000000000000000
26-
Symbol: foo
24+
- Symbol: foo
2725
Type: 0x401
2826
Symbols:
2927
- Name: foo

lld/test/ELF/invalid/invalid-relocation-x64.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ Sections:
2222
Link: .symtab
2323
Info: .text
2424
Relocations:
25-
- Offset: 0x0000000000000000
26-
Symbol: foo
25+
- Symbol: foo
2726
Type: 0x98
28-
- Offset: 0x0000000000000000
29-
Symbol: foo
27+
- Symbol: foo
3028
Type: 0x99
3129
Symbols:
3230
- Name: foo

lld/test/ELF/invalid/reloc-section-reordered.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Sections:
2020
Info: .text
2121
AddressAlign: 0x04
2222
Relocations:
23-
- Offset: 0
24-
Symbol: .text
23+
- Symbol: .text
2524
Type: R_X86_64_NONE
2625
- Type: SHT_PROGBITS
2726
Name: .text

lld/test/ELF/relocation-b-aarch64.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ Sections:
3030
Link: .symtab
3131
Info: .text
3232
Relocations:
33-
- Offset: 0
34-
Symbol: bar
33+
- Symbol: bar
3534
Type: R_AARCH64_JUMP26
3635
- Offset: 4
3736
Symbol: foo

lld/test/ELF/relocation-group.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ Sections:
3535
Link: .symtab
3636
Info: .text.foo
3737
Relocations:
38-
- Offset: 0x0000000000000000
39-
Symbol: foo
38+
- Symbol: foo
4039
Type: R_X86_64_64
4140
Symbols:
4241
- Name: foo

lld/test/ELF/shf-info-link.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Sections:
2424
Link: .symtab
2525
Info: .text
2626
Relocations:
27-
- Offset: 0x0000000000000000
28-
Symbol: foo
27+
- Symbol: foo
2928
Type: R_X86_64_64
3029
Symbols:
3130
- Name: foo

lld/test/ELF/sht-group-empty.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ Sections:
3737
Link: .symtab
3838
Info: .text.foo
3939
Relocations:
40-
- Offset: 0x0000000000000000
41-
Symbol: foo
40+
- Symbol: foo
4241
Type: R_X86_64_64
4342
- Name: .rela.text.bar
4443
Type: SHT_RELA
4544
Flags: [ SHF_INFO_LINK, SHF_GROUP ]
4645
Link: .symtab
4746
Info: .text.bar
4847
Relocations:
49-
- Offset: 0x0000000000000000
50-
Symbol: bar
48+
- Symbol: bar
5149
Type: R_X86_64_64
5250
Symbols:
5351
- Name: foo

lld/test/ELF/undef-broken-debug.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ Sections:
2525
Link: .symtab
2626
Info: .text
2727
Relocations:
28-
- Offset: 0x0000000000000000
29-
Symbol: bar
30-
Type: R_X86_64_64
28+
- Symbol: bar
29+
Type: R_X86_64_64
3130
- Name: .debug_line
3231
Type: SHT_PROGBITS
3332
Content: 3300000002001C0000000101FB0E0D000101010100000001000001006162632E7300000000000009020000000000000000140208000101

lld/test/ELF/undef-not-suggest.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ Sections:
3333
Relocations:
3434
## Relocation which references ".text.foo". Check we don't suggest the
3535
## section symbol for ".data", which has an empty name.
36-
- Offset: 0x0
36+
- Type: R_X86_64_64
3737
## .text.foo
3838
Symbol: 1
39-
Type: R_X86_64_64
4039
## Relocation which references "foo". Check we don't suggest "for".
41-
- Offset: 0x8
40+
- Type: R_X86_64_64
4241
Symbol: foo
43-
Type: R_X86_64_64
4442
- Name: .data
4543
Type: SHT_PROGBITS
4644
Symbols:

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
15681568
const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
15691569
assert(Object && "The IO context is not initialized");
15701570

1571-
IO.mapRequired("Offset", Rel.Offset);
1571+
IO.mapOptional("Offset", Rel.Offset, (Hex64)0);
15721572
IO.mapOptional("Symbol", Rel.Symbol);
15731573

15741574
if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&

llvm/test/Object/AArch64/yaml2obj-elf-aarch64-rel.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
# CHECK-NEXT: EntSize: 0x0000000000000018
99
# CHECK-NEXT: Info: .text
1010
# CHECK-NEXT: Relocations:
11-
# CHECK-NEXT: - Offset: 0x0000000000000000
12-
# CHECK-NEXT: Symbol: main
11+
# CHECK-NEXT: - Symbol: main
1312
# CHECK-NEXT: Type: R_AARCH64_ABS64
1413
# CHECK-NEXT: - Offset: 0x0000000000000008
1514
# CHECK-NEXT: Symbol: main
@@ -33,8 +32,7 @@ Sections:
3332
Info: .text
3433
AddressAlign: 0x08
3534
Relocations:
36-
- Offset: 0
37-
Symbol: main
35+
- Symbol: main
3836
Type: R_AARCH64_ABS64
3937
Addend: 0
4038
- Offset: 8

llvm/test/Object/AMDGPU/elf64-relocs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ Sections:
3737
Info: .text
3838
AddressAlign: 0x08
3939
Relocations:
40-
- Offset: 0x0
41-
Type: R_AMDGPU_NONE
40+
- Type: R_AMDGPU_NONE
4241
- Offset: 0x2
4342
Type: R_AMDGPU_ABS32_LO
4443
- Offset: 0x4

llvm/test/Object/Lanai/yaml2obj-elf-lanai-rel.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Sections:
3131
Info: .text
3232
AddressAlign: 0x04
3333
Relocations:
34-
- Offset: 0x0
35-
Symbol: main
34+
- Symbol: main
3635
Type: R_LANAI_32
3736
- Offset: 0x4
3837
Type: R_LANAI_NONE

llvm/test/Object/X86/yaml2obj-elf-x86-rel.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Sections:
2525
Info: .text
2626
AddressAlign: 0x04
2727
Relocations:
28-
- Offset: 0
29-
Symbol: main
28+
- Symbol: main
3029
Type: R_386_32
3130

3231
Symbols:

llvm/test/Object/invalid-alignment.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ Sections:
2525
Type: SHT_RELA
2626
Info: .foo
2727
Relocations:
28-
- Offset: 0
29-
Type: R_X86_64_NONE
28+
- Type: R_X86_64_NONE

llvm/test/Object/obj2yaml.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@
365365
# ELF-MIPSEL-NEXT: EntSize: 0x0000000000000008
366366
# ELF-MIPSEL-NEXT: Info: .text
367367
# ELF-MIPSEL-NEXT: Relocations:
368-
# ELF-MIPSEL-NEXT: - Offset: 0x0000000000000000
369-
# ELF-MIPSEL-NEXT: Symbol: _gp_disp
368+
# ELF-MIPSEL-NEXT: - Symbol: _gp_disp
370369
# ELF-MIPSEL-NEXT: Type: R_MIPS_HI16
371370
# ELF-MIPSEL-NEXT: - Offset: 0x0000000000000004
372371
# ELF-MIPSEL-NEXT: Symbol: _gp_disp
@@ -487,8 +486,7 @@
487486
# ELF-MIPS64EL-NEXT: EntSize: 0x0000000000000018
488487
# ELF-MIPS64EL-NEXT: Info: .data
489488
# ELF-MIPS64EL-NEXT: Relocations:
490-
# ELF-MIPS64EL-NEXT: - Offset: 0
491-
# ELF-MIPS64EL-NEXT: Symbol: zed
489+
# ELF-MIPS64EL-NEXT: - Symbol: zed
492490
# ELF-MIPS64EL-NEXT: Type: R_MIPS_64
493491
# ELF-MIPS64EL-NEXT: - Name: .bss
494492
# ELF-MIPS64EL-NEXT: Type: SHT_NOBITS

llvm/test/Object/objdump-relocations.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ Sections:
2626
Link: .symtab
2727
Info: .text
2828
Relocations:
29-
- Offset: 0x0
30-
Symbol: .section
29+
- Symbol: .section
3130
Type: R_386_32
3231
- Offset: 0x1
3332
Symbol: symbol
@@ -62,8 +61,7 @@ Sections:
6261
Link: .symtab
6362
Info: .text
6463
Relocations:
65-
- Offset: 0x0
66-
Symbol: .section
64+
- Symbol: .section
6765
Type: R_X86_64_32S
6866
- Offset: 0x1
6967
Symbol: symbol

0 commit comments

Comments
 (0)