[llvm-commits] CVS: llvm/include/llvm/CodeGen/MachOWriter.h

Nate Begeman natebegeman at mac.com
Sun Sep 10 16:04:00 PDT 2006



Changes in directory llvm/include/llvm/CodeGen:

MachOWriter.h updated: 1.6 -> 1.7
---
Log message:

Behold, more work on relocations.  Things are looking pretty good now.


---
Diffs of the changes:  (+36 -11)

 MachOWriter.h |   47 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 11 deletions(-)


Index: llvm/include/llvm/CodeGen/MachOWriter.h
diff -u llvm/include/llvm/CodeGen/MachOWriter.h:1.6 llvm/include/llvm/CodeGen/MachOWriter.h:1.7
--- llvm/include/llvm/CodeGen/MachOWriter.h:1.6	Fri Sep  8 17:42:09 2006
+++ llvm/include/llvm/CodeGen/MachOWriter.h	Sun Sep 10 18:03:44 2006
@@ -344,6 +344,10 @@
       /// SectionData - The actual data for this section which we are building
       /// up for emission to the file.
       DataBuffer SectionData;
+
+      /// RelocBuffer - A buffer to hold the mach-o relocations before we write
+      /// them out at the appropriate location in the file.
+      DataBuffer RelocBuffer;
       
       /// Relocations - The relocations that we have encountered so far in this 
       /// section that we will need to convert to MachORelocation entries when
@@ -421,7 +425,7 @@
       }
 
       MachOSection(const std::string &seg, const std::string &sect)
-        : sectname(sect), segname(seg), addr(0), size(0), offset(0), align(0),
+        : sectname(sect), segname(seg), addr(0), size(0), offset(0), align(2),
           reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0),
           reserved3(0) { }
     };
@@ -449,10 +453,13 @@
       SN->flags = MachOSection::S_REGULAR | Flags;
       return *SN;
     }
-    MachOSection &getTextSection() {
-      return getSection("__TEXT", "__text", 
-                        MachOSection::S_ATTR_PURE_INSTRUCTIONS |
-                        MachOSection::S_ATTR_SOME_INSTRUCTIONS);
+    MachOSection &getTextSection(bool isCode = true) {
+      if (isCode)
+        return getSection("__TEXT", "__text", 
+                          MachOSection::S_ATTR_PURE_INSTRUCTIONS |
+                          MachOSection::S_ATTR_SOME_INSTRUCTIONS);
+      else
+        return getSection("__TEXT", "__text");
     }
     MachOSection &getBSSSection() {
       return getSection("__DATA", "__bss", MachOSection::S_ZEROFILL);
@@ -479,6 +486,12 @@
       }
       return getSection("__TEXT", "__const");
     }
+    MachOSection &getJumpTableSection() {
+      if (TM.getRelocationModel() == Reloc::PIC_)
+        return getTextSection(false);
+      else
+        return getSection("__TEXT", "__const");
+    }
     
     /// MachOSymTab - This struct contains information about the offsets and 
     /// size of symbol table information.
@@ -563,10 +576,6 @@
     /// local symbols first in the list).
     std::vector<MachOSym> SymbolTable;
     
-    /// RelocBuffer - A buffer to hold the mach-o relocations before we write
-    /// them out at the appropriate location in the file.
-    DataBuffer RelocBuffer;
-    
     /// SymT - A buffer to hold the symbol table before we write it out at the
     /// appropriate location in the file.
     DataBuffer SymT;
@@ -666,15 +675,31 @@
         outbyte(Output, 0);
       
     }
+    void fixhalf(DataBuffer &Output, unsigned short X, unsigned Offset) {
+      unsigned char *P = &Output[Offset];
+      P[0] = (X >> (isLittleEndian ?  0 : 8)) & 255;
+      P[1] = (X >> (isLittleEndian ?  8 : 0)) & 255;
+    }
+    void fixword(DataBuffer &Output, unsigned X, unsigned Offset) {
+      unsigned char *P = &Output[Offset];
+      P[0] = (X >> (isLittleEndian ?  0 : 24)) & 255;
+      P[1] = (X >> (isLittleEndian ?  8 : 16)) & 255;
+      P[2] = (X >> (isLittleEndian ? 16 :  8)) & 255;
+      P[3] = (X >> (isLittleEndian ? 24 :  0)) & 255;
+    }
+
   private:
     void AddSymbolToSection(MachOSection &MOS, GlobalVariable *GV);
     void EmitGlobal(GlobalVariable *GV);
     void EmitHeaderAndLoadCommands();
     void EmitSections();
     void BufferSymbolAndStringTable();
+    void CalculateRelocations(MachOSection &MOS, unsigned RelOffset);
 
-    virtual void GetTargetRelocation(MachOSection &MOS, MachineRelocation &MR, 
-                                     uint64_t Addr) = 0;
+    virtual MachineRelocation GetJTRelocation(unsigned Offset,
+                                              MachineBasicBlock *MBB) = 0;
+    virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &MOS,
+                                     unsigned ToIndex) = 0;
   };
 }
 






More information about the llvm-commits mailing list