Skip to content

Commit

Permalink
[RuntimeDyld] Fix x86-64 MachO GOT relocation handling.
Browse files Browse the repository at this point in the history
For GOT relocations the addend should modify the offset to the
GOT entry, not the value of the entry itself. Teach RuntimeDyldMachO
to do The Right Thing here.

Fixes <rdar://problem/16961886>.
 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209154 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed May 19, 2014
1 parent 8ad418b commit b96f71f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ relocation_iterator RuntimeDyldMachO::processRelocationRef(
RelType == MachO::X86_64_RELOC_GOT_LOAD)) {
assert(IsPCRel);
assert(Size == 2);

// FIXME: Teach the generic code above not to prematurely conflate
// relocation addends and symbol offsets.
Value.Addend -= Addend;
StubMap::const_iterator i = Stubs.find(Value);
uint8_t *Addr;
if (i != Stubs.end()) {
Expand All @@ -581,7 +585,8 @@ relocation_iterator RuntimeDyldMachO::processRelocationRef(
Stubs[Value] = Section.StubOffset;
uint8_t *GOTEntry = Section.Address + Section.StubOffset;
RelocationEntry GOTRE(SectionID, Section.StubOffset,
MachO::X86_64_RELOC_UNSIGNED, 0, false, 3);
MachO::X86_64_RELOC_UNSIGNED, Value.Addend, false,
3);
if (Value.SymbolName)
addRelocationForSymbol(GOTRE, Value.SymbolName);
else
Expand All @@ -590,7 +595,7 @@ relocation_iterator RuntimeDyldMachO::processRelocationRef(
Addr = GOTEntry;
}
RelocationEntry TargetRE(SectionID, Offset,
MachO::X86_64_RELOC_UNSIGNED, Value.Addend, true,
MachO::X86_64_RELOC_UNSIGNED, Addend, true,
2);
resolveRelocation(TargetRE, (uint64_t)Addr);
} else if (Arch == Triple::arm && (RelType & 0xf) == MachO::ARM_RELOC_BR24) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
RUN: llvm-rtdyld -printline %p/Inputs/arm_secdiff_reloc.o
RUN: llvm-rtdyld %p/Inputs/x86_64_macho_pic_globals_GOT.o

0 comments on commit b96f71f

Please sign in to comment.