diff options
| author | James Henderson <jh7370@my.bristol.ac.uk> | 2019-03-12 17:00:25 +0000 |
|---|---|---|
| committer | James Henderson <jh7370@my.bristol.ac.uk> | 2019-03-12 17:00:25 +0000 |
| commit | 9bc817a0ae7d629417e369c0612b6312b7437dfa (patch) | |
| tree | da86078606248c98ca2a51053feabff3a426cbd6 /llvm/test/tools | |
| parent | 149bc099f61a81a37751622c1b6d405fddb46204 (diff) | |
| download | bcm5719-llvm-9bc817a0ae7d629417e369c0612b6312b7437dfa.tar.gz bcm5719-llvm-9bc817a0ae7d629417e369c0612b6312b7437dfa.zip | |
[yaml2obj]Allow explicit symbol indexes in relocations and emit error for bad names
Prior to this change, the "Symbol" field of a relocation would always be
assumed to be a symbol name, and if no such symbol existed, the
relocation would reference index 0. This confused me when I tried to use
a literal symbol index in the field: since "0x1" was not a known symbol
name, the symbol index was set as 0. This change falls back to treating
unknown symbol names as integers, and emits an error if the name is not
found and the string is not an integer.
Note that the Symbol field is optional, so if a relocation doesn't
reference a symbol, it shouldn't be specified. The new error required a
number of test updates.
Reviewed by: grimar, ruiu
Differential Revision: https://reviews.llvm.org/D58510
llvm-svn: 355938
Diffstat (limited to 'llvm/test/tools')
4 files changed, 63 insertions, 17 deletions
diff --git a/llvm/test/tools/llvm-objdump/X86/disasm-zeroes-relocations.test b/llvm/test/tools/llvm-objdump/X86/disasm-zeroes-relocations.test index 7bdc7fd7f34..ad8b025ab50 100644 --- a/llvm/test/tools/llvm-objdump/X86/disasm-zeroes-relocations.test +++ b/llvm/test/tools/llvm-objdump/X86/disasm-zeroes-relocations.test @@ -50,3 +50,6 @@ Sections: - Offset: 0x0000000000000008 Symbol: x Type: R_X86_64_64 +Symbols: + Global: + - Name: x diff --git a/llvm/test/tools/sanstats/elf.test b/llvm/test/tools/sanstats/elf.test index 54878a1d526..67e6e4ae1c1 100644 --- a/llvm/test/tools/sanstats/elf.test +++ b/llvm/test/tools/sanstats/elf.test @@ -85,46 +85,34 @@ Sections: Info: .debug_info Relocations: - Offset: 0x0000000000000006 - Symbol: '' Type: R_X86_64_32 - Offset: 0x000000000000000C - Symbol: '' Type: R_X86_64_32 - Offset: 0x0000000000000012 - Symbol: '' Type: R_X86_64_32 Addend: 55 - Offset: 0x0000000000000016 - Symbol: '' Type: R_X86_64_32 - Offset: 0x000000000000001A - Symbol: '' Type: R_X86_64_32 Addend: 59 - Offset: 0x000000000000001E - Symbol: '' Type: R_X86_64_64 - Offset: 0x000000000000002B - Symbol: '' Type: R_X86_64_64 - Offset: 0x0000000000000039 - Symbol: '' Type: R_X86_64_32 Addend: 64 - Offset: 0x0000000000000040 - Symbol: '' Type: R_X86_64_64 Addend: 16 - Offset: 0x000000000000004E - Symbol: '' Type: R_X86_64_32 Addend: 67 - Offset: 0x0000000000000055 - Symbol: '' Type: R_X86_64_64 Addend: 32 - Offset: 0x0000000000000063 - Symbol: '' Type: R_X86_64_32 Addend: 70 - Name: .debug_ranges @@ -142,7 +130,6 @@ Sections: Info: .debug_pubnames Relocations: - Offset: 0x0000000000000006 - Symbol: '' Type: R_X86_64_32 - Name: .comment Type: SHT_PROGBITS @@ -165,14 +152,11 @@ Sections: Info: .eh_frame Relocations: - Offset: 0x0000000000000020 - Symbol: '' Type: R_X86_64_PC32 - Offset: 0x000000000000003C - Symbol: '' Type: R_X86_64_PC32 Addend: 16 - Offset: 0x0000000000000058 - Symbol: '' Type: R_X86_64_PC32 Addend: 32 - Name: .debug_line @@ -186,7 +170,6 @@ Sections: Info: .debug_line Relocations: - Offset: 0x0000000000000027 - Symbol: '' Type: R_X86_64_64 Symbols: Local: diff --git a/llvm/test/tools/yaml2obj/relocation-explicit-symbol-index.yaml b/llvm/test/tools/yaml2obj/relocation-explicit-symbol-index.yaml new file mode 100644 index 00000000000..ac16643b9b0 --- /dev/null +++ b/llvm/test/tools/yaml2obj/relocation-explicit-symbol-index.yaml @@ -0,0 +1,36 @@ +# Test that a relocation's symbol can be an integer. +# RUN: yaml2obj %s > %t +# LLVM tools (both llvm-readobj and llvm-objdump) reject relocations with +# invalid symbol indexes, so inspect the hex contents instead. +# RUN: llvm-readobj -x .rela.text %t | FileCheck %s + +# CHECK: Hex dump of section '.rela.text': +# CHECK-NEXT: 0x00000000 00000000 00000000 02000000 42000000 +# Symbol index 0x42 --^ +# CHECK-NEXT: 0x00000010 00000000 00000000 00000000 00000000 +# CHECK-NEXT: 0x00000020 02000000 01000000 00000000 00000000 +# Symbol index 0x01 --^ + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + - Name: .rela.text + Type: SHT_RELA + Info: .text + Link: .symtab + Relocations: + - Type: R_X86_64_PC32 + Offset: 0 + Symbol: 0x42 + - Type: R_X86_64_PC32 + Offset: 0 + Symbol: 0x1 +Symbols: + Global: + - Name: foo diff --git a/llvm/test/tools/yaml2obj/relocation-missing-symbol.yaml b/llvm/test/tools/yaml2obj/relocation-missing-symbol.yaml new file mode 100644 index 00000000000..7edbf188a21 --- /dev/null +++ b/llvm/test/tools/yaml2obj/relocation-missing-symbol.yaml @@ -0,0 +1,24 @@ +# Show that yaml2obj rejects a symbol reference from a relocation if the symbol +# does not exist. + +# RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s + +# CHECK: Unknown symbol referenced: 'does_not_exist' at YAML section '.rela.text' + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + - Name: .rela.text + Type: SHT_RELA + Info: .text + Link: .symtab + Relocations: + - Type: R_X86_64_PC32 + Offset: 0 + Symbol: does_not_exist |

