diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2012-09-05 23:48:54 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2012-09-05 23:48:54 +0000 |
commit | 033d182589aa46719a47f38fc7021e41aa5b6d43 (patch) | |
tree | 8666d0265789a1d2096a451a10c01cf5157086ad | |
parent | 408853ea162b6b68d3e8defc7f96afad1942dd11 (diff) | |
download | external_llvm-033d182589aa46719a47f38fc7021e41aa5b6d43.zip external_llvm-033d182589aa46719a47f38fc7021e41aa5b6d43.tar.gz external_llvm-033d182589aa46719a47f38fc7021e41aa5b6d43.tar.bz2 |
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
-rw-r--r-- | include/llvm/Object/ELF.h | 23 | ||||
-rw-r--r-- | test/Object/objdump-relocations.test | 13 |
2 files changed, 30 insertions, 6 deletions
diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 4ee2f91..d672e96 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -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"; } diff --git a/test/Object/objdump-relocations.test b/test/Object/objdump-relocations.test index a394a23..6d35a26 100644 --- a/test/Object/objdump-relocations.test +++ b/test/Object/objdump-relocations.test @@ -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 |