summaryrefslogtreecommitdiffstats
path: root/tools/gold
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-02-16 11:19:44 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-02-16 11:19:44 +0000
commit5a287d7a03ebf56c85de05968548aa2826a5886b (patch)
tree674bfc37b1e87c91cd98602d8d1f79fc09f25928 /tools/gold
parenteb1dc98aa7a2d9411c9dd4cd194fd484ed20d1ba (diff)
downloadexternal_llvm-5a287d7a03ebf56c85de05968548aa2826a5886b.zip
external_llvm-5a287d7a03ebf56c85de05968548aa2826a5886b.tar.gz
external_llvm-5a287d7a03ebf56c85de05968548aa2826a5886b.tar.bz2
Add a debug obj-path option to make it easy to keep the .o produce by LTO.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold')
-rw-r--r--tools/gold/gold-plugin.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index 01816ae..33156ed 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -72,6 +72,7 @@ namespace options {
static bool generate_api_file = false;
static generate_bc generate_bc_file = BC_NO;
static std::string bc_path;
+ static std::string obj_path;
static std::string as_path;
static std::vector<std::string> as_args;
static std::vector<std::string> pass_through;
@@ -112,6 +113,8 @@ namespace options {
pass_through.push_back(item.str());
} else if (opt.startswith("mtriple=")) {
triple = opt.substr(strlen("mtriple="));
+ } else if (opt.startswith("obj-path=")) {
+ obj_path = opt.substr(strlen("obj-path="));
} else if (opt == "emit-llvm") {
generate_bc_file = BC_ONLY;
} else if (opt == "also-emit-llvm") {
@@ -471,23 +474,29 @@ static ld_plugin_status all_symbols_read_hook(void) {
std::string ErrMsg;
- sys::Path uniqueObjPath("/tmp/llvmgold.o");
- if (uniqueObjPath.createTemporaryFileOnDisk(true, &ErrMsg)) {
- (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
- return LDPS_ERR;
- }
- tool_output_file objFile(uniqueObjPath.c_str(), ErrMsg,
- raw_fd_ostream::F_Binary);
- if (!ErrMsg.empty()) {
- (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
- return LDPS_ERR;
+ const char *objPath;
+ if (!options::obj_path.empty()) {
+ objPath = options::obj_path.c_str();
+ } else {
+ sys::Path uniqueObjPath("/tmp/llvmgold.o");
+ if (uniqueObjPath.createTemporaryFileOnDisk(true, &ErrMsg)) {
+ (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
+ return LDPS_ERR;
+ }
+ objPath = uniqueObjPath.c_str();
}
+ tool_output_file objFile(objPath, ErrMsg,
+ raw_fd_ostream::F_Binary);
+ if (!ErrMsg.empty()) {
+ (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
+ return LDPS_ERR;
+ }
objFile.os().write(buffer, bufsize);
objFile.os().close();
if (objFile.os().has_error()) {
(*message)(LDPL_ERROR, "Error writing output file '%s'",
- uniqueObjPath.c_str());
+ objPath);
objFile.os().clear_error();
return LDPS_ERR;
}
@@ -495,9 +504,9 @@ static ld_plugin_status all_symbols_read_hook(void) {
lto_codegen_dispose(cg);
- if ((*add_input_file)(uniqueObjPath.c_str()) != LDPS_OK) {
+ if ((*add_input_file)(objPath) != LDPS_OK) {
(*message)(LDPL_ERROR, "Unable to add .o file to the link.");
- (*message)(LDPL_ERROR, "File left behind in: %s", uniqueObjPath.c_str());
+ (*message)(LDPL_ERROR, "File left behind in: %s", objPath);
return LDPS_ERR;
}
@@ -525,7 +534,8 @@ static ld_plugin_status all_symbols_read_hook(void) {
}
}
- Cleanup.push_back(uniqueObjPath);
+ if (options::obj_path.empty())
+ Cleanup.push_back(sys::Path(objPath));
return LDPS_OK;
}