[llvm-commits] [llvm] r76347 - in /llvm/trunk: include/llvm/Target/TargetELFWriterInfo.h lib/CodeGen/ELFCodeEmitter.cpp lib/CodeGen/ELFWriter.cpp lib/CodeGen/ELFWriter.h lib/Target/X86/X86ELFWriterInfo.cpp lib/Target/X86/X86ELFWriterInfo.h

Bruno Cardoso Lopes bruno.cardoso at gmail.com
Sat Jul 18 16:24:01 PDT 2009


Author: bruno
Date: Sat Jul 18 18:24:01 2009
New Revision: 76347

URL: http://llvm.org/viewvc/llvm-project?rev=76347&view=rev
Log:
Use R_X86_64_32S to handle Jump Table Index relocation entries. Hide TAI usage inside getSection* functions

Modified:
    llvm/trunk/include/llvm/Target/TargetELFWriterInfo.h
    llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.h
    llvm/trunk/lib/Target/X86/X86ELFWriterInfo.cpp
    llvm/trunk/lib/Target/X86/X86ELFWriterInfo.h

Modified: llvm/trunk/include/llvm/Target/TargetELFWriterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetELFWriterInfo.h?rev=76347&r1=76346&r2=76347&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetELFWriterInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetELFWriterInfo.h Sat Jul 18 18:24:01 2009
@@ -89,6 +89,14 @@
                      : (hasRelocationAddend() ? 12 : 8);
     }
 
+    /// hasCustomJumpTableIndexRelTy - Returns true if the target has a
+    /// specific relocation type for a jump table index.
+    virtual bool hasCustomJumpTableIndexRelTy() const { return false; }
+
+    /// getJumpTableIndexRelTy - Returns the target specific relocation type
+    /// for a jump table index.
+    virtual unsigned getJumpTableIndexRelTy() const { return 0; }
+
     /// getRelocationType - Returns the target specific ELF Relocation type.
     /// 'MachineRelTy' contains the object code independent relocation type
     virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;

Modified: llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp?rev=76347&r1=76346&r2=76347&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp Sat Jul 18 18:24:01 2009
@@ -101,8 +101,8 @@
       MR.setResultPointer((void*)Addr);
     } else if (MR.isJumpTableIndex()) {
       Addr = getJumpTableEntryAddress(MR.getJumpTableIndex());
-      MR.setResultPointer((void*)Addr);
       MR.setConstantVal(JumpTableSectionIdx);
+      MR.setResultPointer((void*)Addr);
     } else {
       llvm_unreachable("Unhandled relocation type");
     }
@@ -128,25 +128,19 @@
   assert(TM.getRelocationModel() != Reloc::PIC_ &&
          "PIC codegen not yet handled for elf constant pools!");
 
-  const TargetAsmInfo *TAI = TM.getTargetAsmInfo();
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
     MachineConstantPoolEntry CPE = CP[i];
 
-    // Get the right ELF Section for this constant pool entry
-    std::string CstPoolName =
-      TAI->SelectSectionForMachineConst(CPE.getType())->getName();
-    ELFSection &CstPoolSection =
-      EW.getConstantPoolSection(CstPoolName, CPE.getAlignment());
-
     // Record the constant pool location and the section index
-    CPLocations.push_back(CstPoolSection.size());
-    CPSections.push_back(CstPoolSection.SectionIdx);
+    ELFSection &CstPool = EW.getConstantPoolSection(CPE);
+    CPLocations.push_back(CstPool.size());
+    CPSections.push_back(CstPool.SectionIdx);
 
     if (CPE.isMachineConstantPoolEntry())
       assert("CPE.isMachineConstantPoolEntry not supported yet");
 
     // Emit the constant to constant pool section
-    EW.EmitGlobalConstant(CPE.Val.ConstVal, CstPoolSection);
+    EW.EmitGlobalConstant(CPE.Val.ConstVal, CstPool);
   }
 }
 
@@ -160,13 +154,10 @@
   assert(TM.getRelocationModel() != Reloc::PIC_ &&
          "PIC codegen not yet handled for elf jump tables!");
 
-  const TargetAsmInfo *TAI = TM.getTargetAsmInfo();
   const TargetELFWriterInfo *TEW = TM.getELFWriterInfo();
 
   // Get the ELF Section to emit the jump table
-  unsigned Align = TM.getTargetData()->getPointerABIAlignment();
-  std::string JTName(TAI->getJumpTableDataSection());
-  ELFSection &JTSection = EW.getJumpTableSection(JTName, Align);
+  ELFSection &JTSection = EW.getJumpTableSection();
   JumpTableSectionIdx = JTSection.SectionIdx;
 
   // Entries in the JT Section are relocated against the text section

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=76347&r1=76346&r2=76347&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Sat Jul 18 18:24:01 2009
@@ -145,6 +145,24 @@
   return false;
 }
 
+/// Get jump table section on the section name returned by TAI
+ELFSection &ELFWriter::getJumpTableSection() {
+  unsigned Align = TM.getTargetData()->getPointerABIAlignment();
+  return getSection(TAI->getJumpTableDataSection(),
+                    ELFSection::SHT_PROGBITS,
+                    ELFSection::SHF_ALLOC, Align);
+}
+
+///  Get a constant pool section based on the section name returned by TAI
+ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
+  std::string CstPoolName =
+    TAI->SelectSectionForMachineConst(CPE.getType())->getName();
+  return getSection(CstPoolName,
+                    ELFSection::SHT_PROGBITS,
+                    ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC,
+                    CPE.getAlignment());
+}
+
 // getGlobalELFVisibility - Returns the ELF specific visibility type
 unsigned ELFWriter::getGlobalELFVisibility(const GlobalValue *GV) {
   switch (GV->getVisibility()) {
@@ -513,9 +531,14 @@
           Addend = TEW->getDefaultAddendForRelTy(RelType);
         }
       } else {
-        // Get the symbol index for the section symbol referenced
-        // by the relocation
+        // Get the symbol index for the section symbol
         unsigned SectionIdx = MR.getConstantVal();
+
+        // Handle Jump Table Index relocation
+        if ((SectionIdx == getJumpTableSection().SectionIdx) &&
+            TEW->hasCustomJumpTableIndexRelTy())
+          RelType = TEW->getJumpTableIndexRelTy();
+
         SymIdx = SectionList[SectionIdx]->getSymbolTableIndex();
         Addend = (uint64_t)MR.getResultPointer();
       }

Modified: llvm/trunk/lib/CodeGen/ELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.h?rev=76347&r1=76346&r2=76347&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.h (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.h Sat Jul 18 18:24:01 2009
@@ -29,6 +29,7 @@
   class GlobalVariable;
   class Mangler;
   class MachineCodeEmitter;
+  class MachineConstantPoolEntry;
   class ObjectCodeEmitter;
   class TargetAsmInfo;
   class TargetELFWriterInfo;
@@ -170,18 +171,6 @@
                         ELFSection::SHF_EXECINSTR | ELFSection::SHF_ALLOC);
     }
 
-    /// Get jump table section on the section name returned by TAI
-    ELFSection &getJumpTableSection(std::string SName, unsigned Align) {
-      return getSection(SName, ELFSection::SHT_PROGBITS,
-                        ELFSection::SHF_ALLOC, Align);
-    }
-
-    /// Get a constant pool section based on the section name returned by TAI
-    ELFSection &getConstantPoolSection(std::string SName, unsigned Align) {
-      return getSection(SName, ELFSection::SHT_PROGBITS,
-                        ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC, Align);
-    }
-
     /// Return the relocation section of section 'S'. 'RelA' is true
     /// if the relocation section contains entries with addends.
     ELFSection &getRelocSection(std::string SName, bool RelA, unsigned Align) {
@@ -224,6 +213,9 @@
       return getSection("", ELFSection::SHT_NULL, 0);
     }
 
+    ELFSection &getJumpTableSection();
+    ELFSection &getConstantPoolSection(MachineConstantPoolEntry &CPE);
+
     // Helpers for obtaining ELF specific info.
     unsigned getGlobalELFBinding(const GlobalValue *GV);
     unsigned getGlobalELFType(const GlobalValue *GV);

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ELFWriterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ELFWriterInfo.cpp Sat Jul 18 18:24:01 2009
@@ -84,6 +84,7 @@
     switch(RelTy) {
       case R_X86_64_PC32:
       case R_X86_64_32:
+      case R_X86_64_32S:
         return 32;
       case R_X86_64_64:
         return 64;

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ELFWriterInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86ELFWriterInfo.h Sat Jul 18 18:24:01 2009
@@ -49,6 +49,16 @@
     /// ELF relocation entry.
     virtual bool hasRelocationAddend() const { return is64Bit ? true : false; }
 
+    /// hasCustomJumpTableIndexRelTy - Returns true if the target has a
+    /// specific relocation type for a jump table index.
+    virtual bool hasCustomJumpTableIndexRelTy() const {
+      return is64Bit ? true : false;
+    }
+
+    /// getJumpTableIndexRelTy - Returns the target specific relocation type
+    /// for a jump table index.
+    virtual unsigned getJumpTableIndexRelTy() const { return R_X86_64_32S; }
+
     /// getAddendForRelTy - Gets the addend value for an ELF relocation entry
     /// based on the target relocation type
     virtual long int getDefaultAddendForRelTy(unsigned RelTy) const;





More information about the llvm-commits mailing list