case X86_64_RELOC_SIGNED_4:
case X86_64_RELOC_GOT_LOAD:
return read32le(loc);
- case X86_64_RELOC_UNSIGNED:
- return read64le(loc);
default:
error("TODO: Unhandled relocation type " + std::to_string(type));
return 0;
// since the RIP has advanced by 4 at this point.
write32le(loc, val - 4);
break;
- case X86_64_RELOC_UNSIGNED:
- write64le(loc, val);
- break;
default:
llvm_unreachable(
"getImplicitAddend should have flagged all unhandled relocation types");
fatal("TODO: Scattered relocations not supported");
auto rel = reinterpret_cast<const relocation_info &>(anyRel);
+ if (!rel.r_pcrel)
+ fatal("TODO: Only pcrel relocations are supported");
Reloc r;
r.type = rel.r_type;
- r.pcrel = rel.r_pcrel;
uint32_t secRelOffset = rel.r_address;
uint64_t rawAddend =
target->getImplicitAddend(buf + sec.offset + secRelOffset, r.type);
r.target = symbols[rel.r_symbolnum];
r.addend = rawAddend;
} else {
- if (!rel.r_pcrel)
- fatal("TODO: Only pcrel section relocations are supported");
-
if (rel.r_symbolnum == 0 || rel.r_symbolnum > subsections.size())
fatal("invalid section index in relocation for offset " +
std::to_string(r.offset) + " in section " + sec.sectname +
}
uint64_t val = va + r.addend;
- if (r.pcrel)
+ if (1) // TODO: handle non-pcrel relocations
val -= getVA() + r.offset;
target->relocateOne(buf + r.offset, r.type, val);
}
struct Reloc {
uint8_t type;
- bool pcrel;
+ // Adding this offset to the address of the target symbol or subsection gives
+ // the destination that this relocation refers to.
+ uint32_t addend;
// The offset from the start of the subsection that this relocation belongs
// to.
uint32_t offset;
- // Adding this offset to the address of the target symbol or subsection gives
- // the destination that this relocation refers to.
- uint64_t addend;
llvm::PointerUnion<Symbol *, InputSection *> target;
};
class TargetInfo {
public:
virtual ~TargetInfo() = default;
-
virtual uint64_t getImplicitAddend(const uint8_t *loc,
uint8_t type) const = 0;
virtual void relocateOne(uint8_t *loc, uint8_t type, uint64_t val) const = 0;
+++ /dev/null
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
-# RUN: lld -flavor darwinnew -o %t %t.o
-# RUN: llvm-objdump --full-contents %t | FileCheck %s
-# CHECK: Contents of section foo:
-# CHECK: 2000 08200000 00000000
-# CHECK: Contents of section bar:
-# CHECK: 2008 11311111 01000000
-
-.globl _main, _foo, _bar
-
-.section __DATA,foo
-_foo:
-.quad _bar
-
-.section __DATA,bar
-_bar:
-## The unsigned relocation should support 64-bit addends
-.quad _foo + 0x111111111
-
-.text
-_main:
- mov $0, %rax
- ret