llvm.org GIT mirror llvm / 8231133
[yaml2obj][ELF] Make symbols optional for relocations Some kinds of relocations do not have symbols, like R_X86_64_RELATIVE for instance. I would like to test this case in D36554 but currently can't because symbols are required by yaml2obj. The other option is using the empty symbol but that doesn't seem quite right to me. This change makes the Symbol field of Relocation optional and in the case where the user does not specify a symbol name the Symbol index is 0. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D37276 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312192 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 2 years ago
5 changed file(s) with 54 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
160160 llvm::yaml::Hex64 Offset;
161161 int64_t Addend;
162162 ELF_REL Type;
163 StringRef Symbol;
163 Optional Symbol;
164164 };
165165
166166 struct RelocationSection : Section {
852852 assert(Object && "The IO context is not initialized");
853853
854854 IO.mapRequired("Offset", Rel.Offset);
855 IO.mapRequired("Symbol", Rel.Symbol);
855 IO.mapOptional("Symbol", Rel.Symbol);
856856
857857 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
858858 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
0 # This test succeeds but produces an invalid relocation. This test
1 # documents this behavoir.
2 # RUN: yaml2obj %s > %t
3 # RUN: llvm-readobj -relocations %t | FileCheck %s
4
5 !ELF
6 FileHeader:
7 Class: ELFCLASS64
8 Data: ELFDATA2LSB
9 Type: ET_EXEC
10 Machine: EM_X86_64
11 Sections:
12 - Name: .text
13 Type: SHT_PROGBITS
14 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
15 Content: "00000000"
16 - Name: .rel.text
17 Type: SHT_REL
18 Link: .symtab
19 Info: .text
20 Relocations:
21 - Offset: 0x1000
22 Type: R_X86_64_PC32
23
24 #CHECK: Relocations [
25 #CHECK-NEXT: Section (2) .rel.text {
26 #CHECK-NEXT: 0x1000 R_X86_64_PC32 - 0x0
27 #CHECK-NEXT: }
28 #CHECK-NEXT:]
0 # Just make sure this isn't an error even though it has no Symbol
1 # RUN: yaml2obj %s
2
3 !ELF
4 FileHeader:
5 Class: ELFCLASS64
6 Data: ELFDATA2LSB
7 Type: ET_EXEC
8 Machine: EM_X86_64
9 Sections:
10 - Name: .text
11 Type: SHT_PROGBITS
12 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
13 Content: "00000000"
14 - Name: .rel.text
15 Type: SHT_REL
16 Link: .symtab
17 Info: .text
18 Relocations:
19 - Offset: 0x1000
20 Type: R_X86_64_RELATIVE
458458 // Some special relocation, R_ARM_v4BX for instance, does not have
459459 // an external reference. So it ignores the return value of lookup()
460460 // here.
461 SymN2I.lookup(Rel.Symbol, SymIdx);
461 if (Rel.Symbol)
462 SymN2I.lookup(*Rel.Symbol, SymIdx);
462463
463464 if (IsRela) {
464465 Elf_Rela REntry;