[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPCMachOWriter.cpp

Nate Begeman natebegeman at mac.com
Sun Dec 10 18:21:03 PST 2006



Changes in directory llvm/lib/Target/PowerPC:

PPCMachOWriter.cpp updated: 1.7 -> 1.8
---
Log message:

Properly mangles symbol table names
Supports constant pools
Supports relocations to jump tables
Supports relocations within the data segment (global = address of global)
Allocates memory in a non-hacky for all non-code objects.


---
Diffs of the changes:  (+29 -27)

 PPCMachOWriter.cpp |   56 +++++++++++++++++++++++++++--------------------------
 1 files changed, 29 insertions(+), 27 deletions(-)


Index: llvm/lib/Target/PowerPC/PPCMachOWriter.cpp
diff -u llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.7 llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.8
--- llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.7	Thu Nov  2 17:39:53 2006
+++ llvm/lib/Target/PowerPC/PPCMachOWriter.cpp	Sun Dec 10 20:20:45 2006
@@ -31,8 +31,8 @@
       Header.cpusubtype = MachOHeader::CPU_SUBTYPE_POWERPC_ALL;
     }
 
-    virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &MOS,
-                                     unsigned ToIndex);
+    virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &From,
+                                     MachOSection &To);
     virtual MachineRelocation GetJTRelocation(unsigned Offset,
                                               MachineBasicBlock *MBB);
     
@@ -69,8 +69,8 @@
 /// MachOSection, and rewrite the instruction at the section offset if required 
 /// by that relocation type.
 void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
-                                         MachOSection &MOS,
-                                         unsigned ToIndex) {
+                                         MachOSection &From,
+                                         MachOSection &To) {
   uint64_t Addr = 0;
   
   // Keep track of whether or not this is an externally defined relocation.
@@ -78,7 +78,7 @@
   
   // Get the address of whatever it is we're relocating, if possible.
   if (!isExtern)
-    Addr = (uintptr_t)MR.getResultPointer();
+    Addr = (uintptr_t)MR.getResultPointer() + To.addr;
     
   switch ((PPC::RelocationType)MR.getRelocationType()) {
   default: assert(0 && "Unknown PPC relocation type!");
@@ -88,57 +88,59 @@
   case PPC::reloc_vanilla:
     {
       // FIXME: need to handle 64 bit vanilla relocs
-      MachORelocation VANILLA(MR.getMachineCodeOffset(), ToIndex, false, 2, 
+      MachORelocation VANILLA(MR.getMachineCodeOffset(), To.Index, false, 2, 
                               isExtern, PPC_RELOC_VANILLA);
-      outword(MOS.RelocBuffer, VANILLA.r_address);
-      outword(MOS.RelocBuffer, VANILLA.getPackedFields());
+      ++From.nreloc;
+      outword(From.RelocBuffer, VANILLA.r_address);
+      outword(From.RelocBuffer, VANILLA.getPackedFields());
     }
-    MOS.nreloc += 1;
-    fixword(MOS.SectionData, Addr, MR.getMachineCodeOffset());
+    fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
     break;
   case PPC::reloc_pcrel_bx:
     Addr -= MR.getMachineCodeOffset();
     Addr >>= 2;
     Addr &= 0xFFFFFF;
     Addr <<= 2;
-    Addr |= (MOS.SectionData[MR.getMachineCodeOffset()] << 24);
-    fixword(MOS.SectionData, Addr, MR.getMachineCodeOffset());
+    Addr |= (From.SectionData[MR.getMachineCodeOffset()] << 24);
+    fixword(From.SectionData, Addr, MR.getMachineCodeOffset());
     break;
   case PPC::reloc_pcrel_bcx:
     Addr -= MR.getMachineCodeOffset();
     Addr &= 0xFFFC;
-    fixhalf(MOS.SectionData, Addr, MR.getMachineCodeOffset() + 2);
+    fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
     break;
   case PPC::reloc_absolute_high:
     {
-      MachORelocation HA16(MR.getMachineCodeOffset(), ToIndex, false, 2,
+      MachORelocation HA16(MR.getMachineCodeOffset(), To.Index, false, 2,
                            isExtern, PPC_RELOC_HA16);
       MachORelocation PAIR(Addr & 0xFFFF, 0xFFFFFF, false, 2, isExtern,
                            PPC_RELOC_PAIR);
-      outword(MOS.RelocBuffer, HA16.r_address);
-      outword(MOS.RelocBuffer, HA16.getPackedFields());
-      outword(MOS.RelocBuffer, PAIR.r_address);
-      outword(MOS.RelocBuffer, PAIR.getPackedFields());
+      ++From.nreloc;
+      ++From.nreloc;
+      outword(From.RelocBuffer, HA16.r_address);
+      outword(From.RelocBuffer, HA16.getPackedFields());
+      outword(From.RelocBuffer, PAIR.r_address);
+      outword(From.RelocBuffer, PAIR.getPackedFields());
     }
     printf("ha16: %x\n", (unsigned)Addr);
-    MOS.nreloc += 2;
     Addr += 0x8000;
-    fixhalf(MOS.SectionData, Addr >> 16, MR.getMachineCodeOffset() + 2);
+    fixhalf(From.SectionData, Addr >> 16, MR.getMachineCodeOffset() + 2);
     break;
   case PPC::reloc_absolute_low:
     {
-      MachORelocation LO16(MR.getMachineCodeOffset(), ToIndex, false, 2,
+      MachORelocation LO16(MR.getMachineCodeOffset(), To.Index, false, 2,
                            isExtern, PPC_RELOC_LO16);
       MachORelocation PAIR(Addr >> 16, 0xFFFFFF, false, 2, isExtern,
                            PPC_RELOC_PAIR);
-      outword(MOS.RelocBuffer, LO16.r_address);
-      outword(MOS.RelocBuffer, LO16.getPackedFields());
-      outword(MOS.RelocBuffer, PAIR.r_address);
-      outword(MOS.RelocBuffer, PAIR.getPackedFields());
+      ++From.nreloc;
+      ++From.nreloc;
+      outword(From.RelocBuffer, LO16.r_address);
+      outword(From.RelocBuffer, LO16.getPackedFields());
+      outword(From.RelocBuffer, PAIR.r_address);
+      outword(From.RelocBuffer, PAIR.getPackedFields());
     }
     printf("lo16: %x\n", (unsigned)Addr);
-    MOS.nreloc += 2;
-    fixhalf(MOS.SectionData, Addr, MR.getMachineCodeOffset() + 2);
+    fixhalf(From.SectionData, Addr, MR.getMachineCodeOffset() + 2);
     break;
   }
 }






More information about the llvm-commits mailing list