From 5a287d7a03ebf56c85de05968548aa2826a5886b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 16 Feb 2011 11:19:44 +0000 Subject: 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 --- tools/gold/gold-plugin.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'tools/gold/gold-plugin.cpp') diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 01816aeafc..33156edc89 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 as_args; static std::vector 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; } -- cgit v1.2.3