Teach llvm-lto to respect the given RelocModel.
authorJames Molloy <james.molloy@arm.com>
Mon, 14 Apr 2014 13:54:16 +0000 (13:54 +0000)
committerJames Molloy <james.molloy@arm.com>
Mon, 14 Apr 2014 13:54:16 +0000 (13:54 +0000)
Patch by Nick Tomlinson!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206177 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 049c4d75175bb991d950d820252381e5b1688d24..808de033184c9aaf9974d43b40a98c77bac12847 100644 (file)
@@ -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 */
index 7fe143bd5d6c712ce7e7ff48813a9ae35720f3ad..2ba90fad8484b3d5a95aef2bd4639452f918ea54 100644 (file)
@@ -65,7 +65,7 @@ const char* LTOCodeGenerator::getVersionString() {
 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(lto_codegen_model model) {
   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(std::string &errMsg) {
   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
index ec3f0fa23333bae4bfe25ba2edb95f2647515f0d..05ffbf31910e89d4d683c675fe0ba70edfa4d9bf 100644 (file)
@@ -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);