Teach libObject about some more ELF relocations. llvm-objdump -r now knows

every relocation in C++ hello world built with debug info.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163271 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2012-09-05 23:48:54 +00:00
parent 408853ea16
commit 033d182589
2 changed files with 30 additions and 6 deletions

View File

@ -1711,15 +1711,15 @@ error_code ELFObjectFile<target_endianness, is64Bits>
int64_t addend = 0;
uint16_t symbol_index = 0;
switch (sec->sh_type) {
default :
default:
return object_error::parse_failed;
case ELF::SHT_REL : {
case ELF::SHT_REL: {
type = getRel(Rel)->getType();
symbol_index = getRel(Rel)->getSymbol();
// TODO: Read implicit addend from section data.
break;
}
case ELF::SHT_RELA : {
case ELF::SHT_RELA: {
type = getRela(Rel)->getType();
symbol_index = getRela(Rel)->getSymbol();
addend = getRela(Rel)->r_addend;
@ -1733,9 +1733,8 @@ error_code ELFObjectFile<target_endianness, is64Bits>
switch (Header->e_machine) {
case ELF::EM_X86_64:
switch (type) {
case ELF::R_X86_64_32S:
res = symname;
break;
case ELF::R_X86_64_PC8:
case ELF::R_X86_64_PC16:
case ELF::R_X86_64_PC32: {
std::string fmtbuf;
raw_string_ostream fmt(fmtbuf);
@ -1744,6 +1743,18 @@ error_code ELFObjectFile<target_endianness, is64Bits>
Result.append(fmtbuf.begin(), fmtbuf.end());
}
break;
case ELF::R_X86_64_8:
case ELF::R_X86_64_16:
case ELF::R_X86_64_32:
case ELF::R_X86_64_32S:
case ELF::R_X86_64_64: {
std::string fmtbuf;
raw_string_ostream fmt(fmtbuf);
fmt << symname << (addend < 0 ? "" : "+") << addend;
fmt.flush();
Result.append(fmtbuf.begin(), fmtbuf.end());
}
break;
default:
res = "Unknown";
}

View File

@ -9,6 +9,9 @@ RUN: | FileCheck %s -check-prefix ELF-x86-64
RUN: llvm-objdump -r %p/Inputs/trivial-object-test.elf-hexagon \
RUN: | FileCheck %s -check-prefix ELF-hexagon
RUN: llvm-objdump -r %p/Inputs/relocations.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF-complex-x86-64
COFF-i386: .text
COFF-i386: IMAGE_REL_I386_DIR32 L_.str
COFF-i386: IMAGE_REL_I386_REL32 _puts
@ -36,3 +39,13 @@ ELF-hexagon: R_HEX_HI16 puts
ELF-hexagon: R_HEX_LO16 puts
ELF-hexagon: R_HEX_B15_PCREL testf
ELF-hexagon: R_HEX_B22_PCREL puts
ELF-complex-x86-64: .text
ELF-complex-x86-64-NEXT: R_X86_64_8 .data-4
ELF-complex-x86-64-NEXT: R_X86_64_16 .data-4
ELF-complex-x86-64-NEXT: R_X86_64_32 .data-4
ELF-complex-x86-64-NEXT: R_X86_64_32S .data-4
ELF-complex-x86-64-NEXT: R_X86_64_64 .data-4
ELF-complex-x86-64-NEXT: R_X86_64_PC32 .data-4-P
ELF-complex-x86-64-NEXT: R_X86_64_32 .data+0
ELF-complex-x86-64-NEXT: R_X86_64_32 .data+4