[llvm-commits] [llvm] r58066 - in /llvm/trunk: include/llvm/CodeGen/MachineCodeEmitter.h lib/Target/X86/X86CodeEmitter.cpp lib/Target/X86/X86Relocations.h

Dan Gohman gohman at apple.com
Thu Oct 23 18:57:54 PDT 2008


Author: djg
Date: Thu Oct 23 20:57:54 2008
New Revision: 58066

URL: http://llvm.org/viewvc/llvm-project?rev=58066&view=rev
Log:
Fix constant-offset emission for x86-64 absolute addresses. This
fixes a bunch of test-suite JIT failures on x86-64 in
-relocation-model=static mode.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h
    llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp
    llvm/trunk/lib/Target/X86/X86Relocations.h

Modified: llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h?rev=58066&r1=58065&r2=58066&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h Thu Oct 23 20:57:54 2008
@@ -125,6 +125,42 @@
     }
   }
 
+  /// emitDWordLE - This callback is invoked when a 64-bit word needs to be
+  /// written to the output stream in little-endian format.
+  ///
+  void emitDWordLE(uint64_t W) {
+    if (CurBufferPtr+8 <= BufferEnd) {
+      *CurBufferPtr++ = (unsigned char)(W >>  0);
+      *CurBufferPtr++ = (unsigned char)(W >>  8);
+      *CurBufferPtr++ = (unsigned char)(W >> 16);
+      *CurBufferPtr++ = (unsigned char)(W >> 24);
+      *CurBufferPtr++ = (unsigned char)(W >> 32);
+      *CurBufferPtr++ = (unsigned char)(W >> 40);
+      *CurBufferPtr++ = (unsigned char)(W >> 48);
+      *CurBufferPtr++ = (unsigned char)(W >> 56);
+    } else {
+      CurBufferPtr = BufferEnd;
+    }
+  }
+  
+  /// emitDWordBE - This callback is invoked when a 64-bit word needs to be
+  /// written to the output stream in big-endian format.
+  ///
+  void emitDWordBE(uint64_t W) {
+    if (CurBufferPtr+8 <= BufferEnd) {
+      *CurBufferPtr++ = (unsigned char)(W >> 56);
+      *CurBufferPtr++ = (unsigned char)(W >> 48);
+      *CurBufferPtr++ = (unsigned char)(W >> 40);
+      *CurBufferPtr++ = (unsigned char)(W >> 32);
+      *CurBufferPtr++ = (unsigned char)(W >> 24);
+      *CurBufferPtr++ = (unsigned char)(W >> 16);
+      *CurBufferPtr++ = (unsigned char)(W >>  8);
+      *CurBufferPtr++ = (unsigned char)(W >>  0);
+    } else {
+      CurBufferPtr = BufferEnd;
+    }
+  }
+
   /// emitAlignment - Move the CurBufferPtr pointer up the the specified
   /// alignment (saturated to BufferEnd of course).
   void emitAlignment(unsigned Alignment) {

Modified: llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp?rev=58066&r1=58065&r2=58066&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp Thu Oct 23 20:57:54 2008
@@ -72,10 +72,10 @@
   private:
     void emitPCRelativeBlockAddress(MachineBasicBlock *MBB);
     void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
-                           int Disp = 0, intptr_t PCAdj = 0,
+                           intptr_t Disp = 0, intptr_t PCAdj = 0,
                            bool NeedStub = false, bool IsLazy = false);
     void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
-    void emitConstPoolAddress(unsigned CPI, unsigned Reloc, int Disp = 0,
+    void emitConstPoolAddress(unsigned CPI, unsigned Reloc, intptr_t Disp = 0,
                               intptr_t PCAdj = 0);
     void emitJumpTableAddress(unsigned JTI, unsigned Reloc,
                               intptr_t PCAdj = 0);
@@ -152,7 +152,8 @@
 /// this is part of a "take the address of a global" instruction.
 ///
 void Emitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
-                                int Disp /* = 0 */, intptr_t PCAdj /* = 0 */,
+                                intptr_t Disp /* = 0 */,
+                                intptr_t PCAdj /* = 0 */,
                                 bool NeedStub /* = false */,
                                 bool isLazy /* = false */) {
   intptr_t RelocCST = 0;
@@ -166,9 +167,11 @@
     : MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
                                GV, RelocCST, NeedStub);
   MCE.addRelocation(MR);
+  // The relocated value will be added to the displacement
   if (Reloc == X86::reloc_absolute_dword)
-    MCE.emitWordLE(0);
-  MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
+    MCE.emitDWordLE(Disp);
+  else
+    MCE.emitWordLE((int32_t)Disp);
 }
 
 /// emitExternalSymbolAddress - Arrange for the address of an external symbol to
@@ -179,15 +182,16 @@
   MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                                  Reloc, ES, RelocCST));
   if (Reloc == X86::reloc_absolute_dword)
+    MCE.emitDWordLE(0);
+  else
     MCE.emitWordLE(0);
-  MCE.emitWordLE(0);
 }
 
 /// emitConstPoolAddress - Arrange for the address of an constant pool
 /// to be emitted to the current location in the function, and allow it to be PC
 /// relative.
 void Emitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc,
-                                   int Disp /* = 0 */,
+                                   intptr_t Disp /* = 0 */,
                                    intptr_t PCAdj /* = 0 */) {
   intptr_t RelocCST = 0;
   if (Reloc == X86::reloc_picrel_word)
@@ -196,9 +200,11 @@
     RelocCST = PCAdj;
   MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
                                                     Reloc, CPI, RelocCST));
+  // The relocated value will be added to the displacement
   if (Reloc == X86::reloc_absolute_dword)
-    MCE.emitWordLE(0);
-  MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
+    MCE.emitDWordLE(Disp);
+  else
+    MCE.emitWordLE((int32_t)Disp);
 }
 
 /// emitJumpTableAddress - Arrange for the address of a jump table to
@@ -213,9 +219,11 @@
     RelocCST = PCAdj;
   MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
                                                     Reloc, JTI, RelocCST));
+  // The relocated value will be added to the displacement
   if (Reloc == X86::reloc_absolute_dword)
+    MCE.emitDWordLE(0);
+  else
     MCE.emitWordLE(0);
-  MCE.emitWordLE(0); // The relocated value will be added to the displacement
 }
 
 unsigned Emitter::getX86RegNum(unsigned RegNo) const {
@@ -554,7 +562,7 @@
                TM.getSubtarget<X86Subtarget>().isTargetDarwin())) ||
           Opcode == X86::TAILJMPd;
         emitGlobalAddress(MO.getGlobal(), X86::reloc_pcrel_word,
-                          0, 0, NeedStub);
+                          MO.getOffset(), 0, NeedStub);
       } else if (MO.isSymbol()) {
         emitExternalSymbolAddress(MO.getSymbolName(), X86::reloc_pcrel_word);
       } else if (MO.isImm()) {

Modified: llvm/trunk/lib/Target/X86/X86Relocations.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Relocations.h?rev=58066&r1=58065&r2=58066&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86Relocations.h (original)
+++ llvm/trunk/lib/Target/X86/X86Relocations.h Thu Oct 23 20:57:54 2008
@@ -18,6 +18,9 @@
 
 namespace llvm {
   namespace X86 {
+    /// RelocationType - An enum for the x86 relocation codes. Note that
+    /// the terminology here doesn't follow x86 convention - word means
+    /// 32-bit and dword means 64-bit.
     enum RelocationType {
       // reloc_pcrel_word - PC relative relocation, add the relocated value to
       // the value already in memory, after we adjust it for where the PC is.





More information about the llvm-commits mailing list