diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-02-13 09:45:59 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-02-13 09:45:59 +0000 |
commit | 591047f7149c2e57113c60ed194bc9534a7c1cce (patch) | |
tree | 810d7a46f7eb595a09f31f252d4bcf0a28f87f1c /lib/MC/MCAssembler.cpp | |
parent | f6346769b344f9b134f0661e8bd2b4245f6490ea (diff) |
MCAssembler: Fix pcrel relocations. Oh and,
--
ddunbar@ozzy:tmp$ clang -m32 -integrated-as hello.c && ./a.out
hello world!
--
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96096 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCAssembler.cpp')
-rw-r--r-- | lib/MC/MCAssembler.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c974834494..653fbf285f 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -64,6 +64,17 @@ static unsigned getFixupKindLog2Size(MCFixupKind Kind) { } } +static bool isFixupKindPCRel(MCFixupKind Kind) { + switch (Kind) { + default: + return false; + case X86::reloc_pcrel_1byte: + case X86::reloc_pcrel_4byte: + case X86::reloc_riprel_4byte: + return true; + } +} + class MachObjectWriter { // See <mach-o/loader.h>. enum { @@ -447,6 +458,10 @@ public: // The value which goes in the fixup is current value of the expression. Fixup.FixedValue = Value - Value2 + Target.getConstant(); + if (isFixupKindPCRel(Fixup.Kind)) { + Fixup.FixedValue -= Address + (1 << Log2Size); + IsPCRel = 1; + } MachRelocationEntry MRE; MRE.Word0 = ((Address << 0) | @@ -515,10 +530,11 @@ public: // // FIXME: O(N) Index = 1; - for (MCAssembler::iterator it = Asm.begin(), - ie = Asm.end(); it != ie; ++it, ++Index) + MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); + for (; it != ie; ++it, ++Index) if (&*it == SD->getFragment()->getParent()) break; + assert(it != ie && "Unable to find section index!"); Value = SD->getFragment()->getAddress() + SD->getOffset(); } @@ -530,6 +546,11 @@ public: unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind); + if (isFixupKindPCRel(Fixup.Kind)) { + Fixup.FixedValue -= Address + (1<<Log2Size); + IsPCRel = 1; + } + // struct relocation_info (8 bytes) MachRelocationEntry MRE; MRE.Word0 = Address; |