summaryrefslogtreecommitdiff
path: root/tools/gold/gold-plugin.cpp
diff options
context:
space:
mode:
authorShuxin Yang <shuxin.llvm@gmail.com>2013-08-12 18:29:43 +0000
committerShuxin Yang <shuxin.llvm@gmail.com>2013-08-12 18:29:43 +0000
commit67d135ae40b121a138e334a175d0e02dbb54eeca (patch)
tree8e7ef892ab3d66802b5f53af56ba6a36a5911742 /tools/gold/gold-plugin.cpp
parent353476cbbb80881a754a90abc13851a884a4e26c (diff)
downloadllvm-67d135ae40b121a138e334a175d0e02dbb54eeca.tar.gz
llvm-67d135ae40b121a138e334a175d0e02dbb54eeca.tar.bz2
llvm-67d135ae40b121a138e334a175d0e02dbb54eeca.tar.xz
Misc enhancements to LTO:
1. Add some helper classes for partitions. They are designed in a way such that the top-level LTO driver will not see much difference with or without partitioning. 2. Introduce work-dir. Now all intermediate files generated during LTO phases will be saved under work-dir. User can specify the workdir via -lto-workdir=/path/to/dir. By default the work-dir will be erased before linker exit. To keep the workdir, do -lto-keep, or -lto-keep=1. TODO: Erase the workdir, if the linker exit prematurely. We are currently not able to remove directory on signal. The support routines simply ignore directory. 3. Add one new API lto_codegen_get_files_need_remove(). Linker and LTO plugin will communicate via this API about which files (including directories) need to removed before linker exit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188188 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold/gold-plugin.cpp')
-rw-r--r--tools/gold/gold-plugin.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index 77717098d6..7918324702 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -74,7 +74,6 @@ 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 extra_library_path;
static std::string triple;
static std::string mcpu;
@@ -99,8 +98,6 @@ namespace options {
extra_library_path = opt.substr(strlen("extra_library_path="));
} 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") {
@@ -425,6 +422,14 @@ static ld_plugin_status all_symbols_read_hook(void) {
(*message)(LDPL_ERROR, "Could not produce a combined object file\n");
}
+ // Get files that need to be removed in cleanup_hook.
+ const char *ToRm;
+ lto_codegen_get_files_need_remove(code_gen, &ToRm);
+ while (*ToRm) {
+ Cleanup.push_back(std::string(ToRm));
+ ToRm += strlen(ToRm) + 1;
+ }
+
lto_codegen_dispose(code_gen);
for (std::list<claimed_file>::iterator I = Modules.begin(),
E = Modules.end(); I != E; ++I) {
@@ -446,17 +451,28 @@ static ld_plugin_status all_symbols_read_hook(void) {
return LDPS_ERR;
}
- if (options::obj_path.empty())
- Cleanup.push_back(objPath);
-
return LDPS_OK;
}
static ld_plugin_status cleanup_hook(void) {
for (int i = 0, e = Cleanup.size(); i != e; ++i) {
- error_code EC = sys::fs::remove(Cleanup[i]);
+ const char *FN = Cleanup[i].c_str();
+ sys::fs::file_status Stat;
+ error_code EC = sys::fs::status(Twine(FN), Stat);
+ if (EC) {
+ (*message)(LDPL_ERROR, "Failed to stat '%s': %s", FN,
+ EC.message().c_str());
+ continue;
+ }
+
+ uint32_t Dummy;
+ if (sys::fs::is_directory(FN))
+ EC = sys::fs::remove_all(Twine(FN), Dummy);
+ else
+ EC = sys::fs::remove(Twine(FN));
+
if (EC)
- (*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(),
+ (*message)(LDPL_ERROR, "Failed to remove '%s': %s", FN,
EC.message().c_str());
}