More Mach-O writer improvements.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34740 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/PowerPC/PPCMachOWriterInfo.cpp b/lib/Target/PowerPC/PPCMachOWriterInfo.cpp
index de3960d..5e2dc9e 100644
--- a/lib/Target/PowerPC/PPCMachOWriterInfo.cpp
+++ b/lib/Target/PowerPC/PPCMachOWriterInfo.cpp
@@ -35,13 +35,11 @@
                                                  unsigned ToIdx,
                                                  OutputBuffer &RelocOut,
                                                  OutputBuffer &SecOut,
-                                                 bool Scattered) const {
+                                                 bool Scattered,
+                                                 bool isExtern) const {
   unsigned NumRelocs = 0;
   uint64_t Addr = 0;
 
-  // Keep track of whether or not this is an externally defined relocation.
-  bool     isExtern = false;
-
   // Get the address of whatever it is we're relocating, if possible.
   if (!isExtern)
     Addr = (uintptr_t)MR.getResultPointer() + ToAddr;
@@ -83,12 +81,24 @@
     break;
   case PPC::reloc_pcrel_bx:
     {
+      // FIXME: Presumably someday we will need to branch to other, non-extern
+      // functions too.  Need to figure out some way to distinguish between
+      // target is BB and target is function.
+      if (isExtern) {
+        MachORelocation BR24(MR.getMachineCodeOffset(), ToIdx, true, 2, 
+                             isExtern, PPC_RELOC_BR24, Scattered, 
+                             (intptr_t)MR.getMachineCodeOffset());
+        RelocOut.outword(BR24.getAddress());
+        RelocOut.outword(BR24.getPackedFields());
+        ++NumRelocs;
+      }
+
       Addr -= MR.getMachineCodeOffset();
       Addr >>= 2;
       Addr &= 0xFFFFFF;
       Addr <<= 2;
       Addr |= (SecOut[MR.getMachineCodeOffset()] << 24);
-
+      Addr |= (SecOut[MR.getMachineCodeOffset()+3] & 0x3);
       SecOut.fixword(Addr, MR.getMachineCodeOffset());
       break;
     }