[llvm-commits] [lld] r171703 - in /lld/trunk: lib/ReaderWriter/ELF/X86_64Reference.cpp test/elf/Inputs/relocs.x86-64 test/elf/x86_64-kinds.test
Michael J. Spencer
bigcheesegs at gmail.com
Sun Jan 6 22:58:54 PST 2013
Author: mspencer
Date: Mon Jan 7 00:58:53 2013
New Revision: 171703
URL: http://llvm.org/viewvc/llvm-project?rev=171703&view=rev
Log:
[ELF] Add common x86_64 relocation types.
Added:
lld/trunk/test/elf/Inputs/relocs.x86-64
Modified:
lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp
lld/trunk/test/elf/x86_64-kinds.test
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp?rev=171703&r1=171702&r2=171703&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64Reference.cpp Mon Jan 7 00:58:53 2013
@@ -17,9 +17,42 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+using namespace llvm::ELF;
+
+namespace {
+/// \brief R_X86_64_PC32 - word32: S + A - P
+int relocPC32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ uint32_t result = (uint32_t)((S + A) - P);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result +
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ return 0;
+}
+
+/// \brief R_X86_64_32 - word32: S + A
+int reloc32(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (uint32_t)(S + A);
+ *reinterpret_cast<llvm::support::ulittle32_t *>(location) = result |
+ (uint32_t)*reinterpret_cast<llvm::support::ulittle32_t *>(location);
+ // TODO: Make sure that the result zero extends to the 64bit value.
+ return 0;
+}
+
+/// \brief R_X86_64_32S - word32: S + A
+int reloc32S(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int32_t result = (int32_t)(S + A);
+ *reinterpret_cast<llvm::support::little32_t *>(location) = result |
+ (int32_t)*reinterpret_cast<llvm::support::little32_t *>(location);
+ // TODO: Make sure that the result sign extends to the 64bit value.
+ return 0;
+}
+} // end anon namespace
+
namespace lld {
namespace elf {
X86_64KindHandler::X86_64KindHandler(){
+ _fixupHandler[R_X86_64_PC32] = relocPC32;
+ _fixupHandler[R_X86_64_32] = reloc32;
+ _fixupHandler[R_X86_64_32S] = reloc32S;
}
X86_64KindHandler::~X86_64KindHandler() {
@@ -28,11 +61,17 @@
Reference::Kind X86_64KindHandler::stringToKind(StringRef str) {
return llvm::StringSwitch<Reference::Kind>(str)
.Case("none", none)
+ .Case("R_X86_64_PC32", R_X86_64_PC32)
+ .Case("R_X86_64_32S", R_X86_64_32S)
.Default(invalid);
}
StringRef X86_64KindHandler::kindToString(Reference::Kind kind) {
switch ((int32_t)kind) {
+ case R_X86_64_PC32:
+ return "R_X86_64_PC32";
+ case R_X86_64_32S:
+ return "R_X86_64_32S";
default:
return "none";
}
Added: lld/trunk/test/elf/Inputs/relocs.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/relocs.x86-64?rev=171703&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/relocs.x86-64 (added) and lld/trunk/test/elf/Inputs/relocs.x86-64 Mon Jan 7 00:58:53 2013 differ
Modified: lld/trunk/test/elf/x86_64-kinds.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/x86_64-kinds.test?rev=171703&r1=171702&r2=171703&view=diff
==============================================================================
--- lld/trunk/test/elf/x86_64-kinds.test (original)
+++ lld/trunk/test/elf/x86_64-kinds.test Mon Jan 7 00:58:53 2013
@@ -1,4 +1,17 @@
-RUN: lld -flavor ld -target x86_64-linux -o %t | llvm-objdump -p %t \
+RUN: lld -flavor ld -target x86_64-linux -o %t && llvm-objdump -p %t \
RUN: | FileCheck %s
CHECK: ELF64-x86-64
+
+RUN: lld -flavor ld -target x86_64-linux -o %t1 %p/Inputs/relocs.x86-64 \
+RUN: && llvm-objdump -d %t1 | FileCheck %s -check-prefix=RELOCS
+
+// R_X86_64_32S
+RELOCS: c7 04 25
+RELOCS-NOT: 00 00 00 00
+RELOCS: 05 00 00 00 movl
+
+// R_X86_64_PC32
+RELOCS: e8
+RELOCS-NOT: 00 00 00 00
+RELOCS: callq
More information about the llvm-commits
mailing list