summaryrefslogtreecommitdiffstats
path: root/tools/gold/gold-plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gold/gold-plugin.cpp')
-rw-r--r--tools/gold/gold-plugin.cpp48
1 files changed, 19 insertions, 29 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index ad2774a..7ce1760 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -64,7 +64,7 @@ namespace {
std::string output_name = "";
std::list<claimed_file> Modules;
std::vector<sys::Path> Cleanup;
- lto_code_gen_t code_gen;
+ lto_code_gen_t code_gen = NULL;
}
namespace options {
@@ -73,8 +73,6 @@ namespace options {
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;
static std::string extra_library_path;
static std::string triple;
@@ -96,16 +94,6 @@ namespace options {
generate_api_file = true;
} else if (opt.startswith("mcpu=")) {
mcpu = opt.substr(strlen("mcpu="));
- } else if (opt.startswith("as=")) {
- if (!as_path.empty()) {
- (*message)(LDPL_WARNING, "Path to as specified twice. "
- "Discarding %s", opt_);
- } else {
- as_path = opt.substr(strlen("as="));
- }
- } else if (opt.startswith("as-arg=")) {
- llvm::StringRef item = opt.substr(strlen("as-arg="));
- as_args.push_back(item.str());
} else if (opt.startswith("extra-library-path=")) {
extra_library_path = opt.substr(strlen("extra_library_path="));
} else if (opt.startswith("pass-through=")) {
@@ -196,6 +184,8 @@ ld_plugin_status onload(ld_plugin_tv *tv) {
if ((*callback)(all_symbols_read_hook) != LDPS_OK)
return LDPS_ERR;
+
+ code_gen = lto_codegen_create();
} break;
case LDPT_REGISTER_CLEANUP_HOOK: {
ld_plugin_register_cleanup callback;
@@ -236,8 +226,6 @@ ld_plugin_status onload(ld_plugin_tv *tv) {
return LDPS_ERR;
}
- code_gen = lto_codegen_create();
-
return LDPS_OK;
}
@@ -322,6 +310,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
cf.syms.push_back(ld_plugin_symbol());
ld_plugin_symbol &sym = cf.syms.back();
sym.name = const_cast<char *>(lto_module_get_symbol_name(M, i));
+ sym.name = strdup(sym.name);
sym.version = NULL;
int scope = attrs & LTO_SYMBOL_SCOPE_MASK;
@@ -379,7 +368,11 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
}
}
- lto_codegen_add_module(code_gen, M);
+ if (code_gen)
+ lto_codegen_add_module(code_gen, M);
+
+ lto_module_dispose(M);
+
return LDPS_OK;
}
@@ -389,6 +382,8 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
/// codegen.
static ld_plugin_status all_symbols_read_hook(void) {
std::ofstream api_file;
+ assert(code_gen);
+
if (options::generate_api_file) {
api_file.open("apifile.txt", std::ofstream::out | std::ofstream::trunc);
if (!api_file.is_open()) {
@@ -425,18 +420,6 @@ static ld_plugin_status all_symbols_read_hook(void) {
lto_codegen_set_pic_model(code_gen, output_type);
lto_codegen_set_debug_model(code_gen, LTO_DEBUG_MODEL_DWARF);
- if (!options::as_path.empty()) {
- sys::Path p = sys::Program::FindProgramByName(options::as_path);
- lto_codegen_set_assembler_path(code_gen, p.c_str());
- }
- if (!options::as_args.empty()) {
- std::vector<const char *> as_args_p;
- for (std::vector<std::string>::iterator I = options::as_args.begin(),
- E = options::as_args.end(); I != E; ++I) {
- as_args_p.push_back(I->c_str());
- }
- lto_codegen_set_assembler_args(code_gen, &as_args_p[0], as_args_p.size());
- }
if (!options::mcpu.empty())
lto_codegen_set_cpu(code_gen, options::mcpu.c_str());
@@ -469,10 +452,10 @@ static ld_plugin_status all_symbols_read_hook(void) {
std::string ErrMsg;
const char *objPath;
+ sys::Path uniqueObjPath("/tmp/llvmgold.o");
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;
@@ -497,6 +480,13 @@ static ld_plugin_status all_symbols_read_hook(void) {
objFile.keep();
lto_codegen_dispose(code_gen);
+ for (std::list<claimed_file>::iterator I = Modules.begin(),
+ E = Modules.end(); I != E; ++I) {
+ for (unsigned i = 0; i != I->syms.size(); ++i) {
+ ld_plugin_symbol &sym = I->syms[i];
+ free(sym.name);
+ }
+ }
if ((*add_input_file)(objPath) != LDPS_OK) {
(*message)(LDPL_ERROR, "Unable to add .o file to the link.");
OpenPOWER on IntegriCloud