Make it possible to set the target triple and expose that with an option in the
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 9 Aug 2010 21:09:46 +0000 (21:09 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 9 Aug 2010 21:09:46 +0000 (21:09 +0000)
gold plugin.

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

include/llvm-c/lto.h
tools/gold/gold-plugin.cpp
tools/lto/LTOModule.cpp
tools/lto/LTOModule.h
tools/lto/lto.cpp
tools/lto/lto.exports

index 93f37605a41b4df03306516ba58fb85441496f02..d16a38bd3be1a403dfd935422e2a48c691108dde 100644 (file)
@@ -135,6 +135,12 @@ lto_module_dispose(lto_module_t mod);
 extern const char*
 lto_module_get_target_triple(lto_module_t mod);
 
+/**
+ * Sets triple string with which the object will be codegened.
+ */
+extern void
+lto_module_set_target_triple(lto_module_t mod, const char *triple);
+
 
 /**
  * Returns the number of symbols in the object module.
index 2d0f5bd3af3ad762590c54c1774806de29cb26c8..e7161a64a8e48feb0f7744e568ba5dff46de51ad 100644 (file)
@@ -68,6 +68,7 @@ namespace options {
   static std::string as_path;
   static std::vector<std::string> pass_through;
   static std::string extra_library_path;
+  static std::string triple;
   // Additional options to pass into the code generator.
   // Note: This array will contain all plugin options which are not claimed
   // as plugin exclusive to pass to the code generator.
@@ -95,6 +96,8 @@ namespace options {
     } else if (opt.startswith("pass-through=")) {
       llvm::StringRef item = opt.substr(strlen("pass-through="));
       pass_through.push_back(item.str());
+    } else if (opt == "mtriple=") {
+      triple = opt.substr(strlen("mtriple="));
     } else if (opt == "emit-llvm") {
       generate_bc_file = BC_ONLY;
     } else if (opt == "also-emit-llvm") {
@@ -270,6 +273,10 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
                lto_get_error_message());
     return LDPS_ERR;
   }
+
+  if (!options::triple.empty())
+    lto_module_set_target_triple(cf.M, options::triple.c_str());
+
   cf.handle = file->handle;
   unsigned sym_count = lto_module_get_num_symbols(cf.M);
   cf.syms.reserve(sym_count);
index 0870205a778b35748b99a661811b371bddba276d..d386bacdfc9326c8bb99755569d0276d9d2feede 100644 (file)
@@ -153,6 +153,11 @@ const char* LTOModule::getTargetTriple()
     return _module->getTargetTriple().c_str();
 }
 
+void LTOModule::setTargetTriple(const char *triple)
+{
+    _module->setTargetTriple(triple);
+}
+
 void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler)
 {
     // add to list of defined symbols
index 7f475d40aa0a88edf6aeaf241a52e8e0069fc899..a19acc0d7378ec30995a6c50c56f5a547a8d8d5c 100644 (file)
@@ -55,6 +55,7 @@ struct LTOModule {
                                            std::string& errMsg);
 
     const char*              getTargetTriple();
+    void                     setTargetTriple(const char*);
     uint32_t                 getSymbolCount();
     lto_symbol_attributes    getSymbolAttributes(uint32_t index);
     const char*              getSymbolName(uint32_t index);
index cc841bdf034d563239893c302a8dd223716bceac..a299dd187d617d526b8daf2787d43032663507c8 100644 (file)
@@ -120,6 +120,14 @@ const char* lto_module_get_target_triple(lto_module_t mod)
     return mod->getTargetTriple();
 }
 
+//
+// sets triple string with which the object will be codegened.
+//
+void lto_module_set_target_triple(lto_module_t mod, const char *triple)
+{
+    return mod->setTargetTriple(triple);
+}
+
 
 //
 // returns the number of symbols in the object module
index 9011cf602b1ad834685ddf7dc13a0c39787b57f6..a686b788457b1f15bbd17f6cbf98cb386ae3d582 100644 (file)
@@ -6,6 +6,7 @@ lto_module_get_num_symbols
 lto_module_get_symbol_attribute
 lto_module_get_symbol_name
 lto_module_get_target_triple
+lto_module_set_target_triple
 lto_module_is_object_file
 lto_module_is_object_file_for_target
 lto_module_is_object_file_in_memory