[llvm-commits] [llvm] r96096 - /llvm/trunk/lib/MC/MCAssembler.cpp
Daniel Dunbar
daniel at zuster.org
Sat Feb 13 01:45:59 PST 2010
Author: ddunbar
Date: Sat Feb 13 03:45:59 2010
New Revision: 96096
URL: http://llvm.org/viewvc/llvm-project?rev=96096&view=rev
Log:
MCAssembler: Fix pcrel relocations. Oh and,
--
ddunbar at ozzy:tmp$ clang -m32 -integrated-as hello.c && ./a.out
hello world!
--
Modified:
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=96096&r1=96095&r2=96096&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Sat Feb 13 03:45:59 2010
@@ -64,6 +64,17 @@
}
}
+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 @@
// 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 @@
//
// 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 @@
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;
More information about the llvm-commits
mailing list