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

Nate Begeman natebegeman at mac.com
Fri Jan 26 14:40:07 PST 2007



Changes in directory llvm/lib/Target/PowerPC:

PPCMachOWriter.cpp updated: 1.14 -> 1.15
---
Log message:

Handle multiple functions, properly mangle symbols, and fix support for
scattered relocations.


---
Diffs of the changes:  (+23 -12)

 PPCMachOWriter.cpp |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)


Index: llvm/lib/Target/PowerPC/PPCMachOWriter.cpp
diff -u llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.14 llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.15
--- llvm/lib/Target/PowerPC/PPCMachOWriter.cpp:1.14	Tue Jan 23 21:40:33 2007
+++ llvm/lib/Target/PowerPC/PPCMachOWriter.cpp	Fri Jan 26 16:39:48 2007
@@ -27,7 +27,7 @@
       : MachOWriter(O, TM) {}
 
     virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &From,
-                                     MachOSection &To);
+                                     MachOSection &To, bool Scattered);
 
     // Constants for the relocation r_type field.
     // see <mach-o/ppc/reloc.h>
@@ -59,7 +59,8 @@
 /// by that relocation type.
 void PPCMachOWriter::GetTargetRelocation(MachineRelocation &MR,
                                          MachOSection &From,
-                                         MachOSection &To) {
+                                         MachOSection &To,
+                                         bool Scattered) {
   uint64_t Addr = 0;
 
   // Keep track of whether or not this is an externally defined relocation.
@@ -77,18 +78,30 @@
   case PPC::reloc_vanilla:
     {
       // FIXME: need to handle 64 bit vanilla relocs
-      MachORelocation VANILLA(MR.getMachineCodeOffset(), To.Index, false, 2,
-                              isExtern, PPC_RELOC_VANILLA);
+      MachORelocation VANILLA(MR.getMachineCodeOffset(), To.Index, false, 2, 
+                              isExtern, PPC_RELOC_VANILLA, Scattered,
+                              (intptr_t)MR.getResultPointer());
       ++From.nreloc;
-
       OutputBuffer RelocOut(From.RelocBuffer, is64Bit, isLittleEndian);
-      RelocOut.outword(VANILLA.r_address);
-      RelocOut.outword(VANILLA.getPackedFields());
-
       OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
-      SecOut.fixword(Addr, MR.getMachineCodeOffset());
-      break;
+
+      if (Scattered) {
+        RelocOut.outword(VANILLA.getPackedFields());
+        RelocOut.outword(VANILLA.getAddress());
+      } else {
+        RelocOut.outword(VANILLA.getAddress());
+        RelocOut.outword(VANILLA.getPackedFields());
+      }
+      
+      intptr_t SymbolOffset;
+      if (Scattered)
+        SymbolOffset = Addr + MR.getConstantVal();
+      else
+        SymbolOffset = Addr;
+      printf("vanilla fixup: sec_%x[%x] = %x\n", From.Index, unsigned(MR.getMachineCodeOffset()), (unsigned)SymbolOffset);
+      SecOut.fixword(SymbolOffset, MR.getMachineCodeOffset());
     }
+    break;
   case PPC::reloc_pcrel_bx:
     {
       Addr -= MR.getMachineCodeOffset();
@@ -124,7 +137,6 @@
       RelocOut.outword(HA16.getPackedFields());
       RelocOut.outword(PAIR.r_address);
       RelocOut.outword(PAIR.getPackedFields());
-      printf("ha16: %x\n", (unsigned)Addr);
       Addr += 0x8000;
 
       OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
@@ -145,7 +157,6 @@
       RelocOut.outword(LO16.getPackedFields());
       RelocOut.outword(PAIR.r_address);
       RelocOut.outword(PAIR.getPackedFields());
-      printf("lo16: %x\n", (unsigned)Addr);
 
       OutputBuffer SecOut(From.SectionData, is64Bit, isLittleEndian);
       SecOut.fixhalf(Addr, MR.getMachineCodeOffset() + 2);






More information about the llvm-commits mailing list