[llvm] r206177 - Teach llvm-lto to respect the given RelocModel.

James Molloy james.molloy at arm.com
Mon Apr 14 06:54:17 PDT 2014


Author: jamesm
Date: Mon Apr 14 08:54:16 2014
New Revision: 206177

URL: http://llvm.org/viewvc/llvm-project?rev=206177&view=rev
Log:
Teach llvm-lto to respect the given RelocModel.

Patch by Nick Tomlinson!


Modified:
    llvm/trunk/include/llvm-c/lto.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/tools/llvm-lto/llvm-lto.cpp

Modified: llvm/trunk/include/llvm-c/lto.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/lto.h?rev=206177&r1=206176&r2=206177&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/lto.h (original)
+++ llvm/trunk/include/llvm-c/lto.h Mon Apr 14 08:54:16 2014
@@ -79,7 +79,8 @@ typedef enum {
 typedef enum {
     LTO_CODEGEN_PIC_MODEL_STATIC         = 0,
     LTO_CODEGEN_PIC_MODEL_DYNAMIC        = 1,
-    LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
+    LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2,
+    LTO_CODEGEN_PIC_MODEL_DEFAULT        = 3
 } lto_codegen_model;
 
 /** opaque reference to a loaded object module */

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=206177&r1=206176&r2=206177&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Mon Apr 14 08:54:16 2014
@@ -65,7 +65,7 @@ const char* LTOCodeGenerator::getVersion
 LTOCodeGenerator::LTOCodeGenerator()
     : Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)),
       TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false),
-      CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL),
+      CodeModel(LTO_CODEGEN_PIC_MODEL_DEFAULT), NativeObjectFile(NULL),
       DiagHandler(NULL), DiagContext(NULL) {
   initializeLTOPasses();
 }
@@ -161,6 +161,7 @@ void LTOCodeGenerator::setCodePICModel(l
   case LTO_CODEGEN_PIC_MODEL_STATIC:
   case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
   case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
+  case LTO_CODEGEN_PIC_MODEL_DEFAULT:
     CodeModel = model;
     return;
   }
@@ -295,6 +296,9 @@ bool LTOCodeGenerator::determineTarget(s
   case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
     RelocModel = Reloc::DynamicNoPIC;
     break;
+  case LTO_CODEGEN_PIC_MODEL_DEFAULT:
+    // RelocModel is already the default, so leave it that way.
+    break;
   }
 
   // construct LTOModule, hand over ownership of module and target

Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=206177&r1=206176&r2=206177&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Mon Apr 14 08:54:16 2014
@@ -83,7 +83,20 @@ int main(int argc, char **argv) {
 
   LTOCodeGenerator CodeGen;
 
-  CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
+  switch (RelocModel) {
+  case Reloc::Static:
+    CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_STATIC);
+    break;
+  case Reloc::PIC_:
+    CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
+    break;
+  case Reloc::DynamicNoPIC:
+    CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC);
+    break;
+  default:
+    CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DEFAULT);
+  }
+
   CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF);
   CodeGen.setTargetOptions(Options);
 





More information about the llvm-commits mailing list