summaryrefslogtreecommitdiff
path: root/tools/gold/gold-plugin.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-02-22 22:15:44 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-02-22 22:15:44 +0000
commitca4286295f7db200724cb488a04ad15441a8ba99 (patch)
tree2726818e04828f543df88701df67cd84b37fa7d1 /tools/gold/gold-plugin.cpp
parentbc989d462d0b95e275a17d62251c759d0342dbaa (diff)
downloadllvm-ca4286295f7db200724cb488a04ad15441a8ba99.tar.gz
llvm-ca4286295f7db200724cb488a04ad15441a8ba99.tar.bz2
llvm-ca4286295f7db200724cb488a04ad15441a8ba99.tar.xz
Add an option to the gold plugin to make it emit a file with the public api
list that can in turn be passed to -internalize pass through -internalize-public-api-file. Pass gold -plugin-opt=generate-api-file to produce "apifile.txt" in the current directory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65295 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold/gold-plugin.cpp')
-rw-r--r--tools/gold/gold-plugin.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index 2ff6aa0309..9ad045061f 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -22,6 +22,7 @@
#include <cerrno>
#include <cstdlib>
#include <cstring>
+#include <fstream>
#include <list>
#include <vector>
@@ -42,6 +43,8 @@ namespace {
int api_version = 0;
int gold_version = 0;
+ bool generate_api_file = false;
+
struct claimed_file {
lto_module_t M;
void *handle;
@@ -96,7 +99,11 @@ ld_plugin_status onload(ld_plugin_tv *tv) {
//output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC;
break;
case LDPT_OPTION:
- (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
+ if (strcmp("generate-api-file", tv->tv_u.tv_string) == 0) {
+ generate_api_file = true;
+ } else {
+ (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
+ }
break;
case LDPT_REGISTER_CLAIM_FILE_HOOK: {
ld_plugin_register_claim_file callback;
@@ -285,6 +292,15 @@ ld_plugin_status all_symbols_read_hook(void) {
E = Modules.end(); I != E; ++I)
lto_codegen_add_module(cg, I->M);
+ std::ofstream api_file;
+ if (generate_api_file) {
+ api_file.open("apifile.txt", std::ofstream::out | std::ofstream::trunc);
+ if (!api_file.is_open()) {
+ (*message)(LDPL_FATAL, "Unable to open apifile.txt for writing.");
+ abort();
+ }
+ }
+
// If we don't preserve any symbols, libLTO will assume that all symbols are
// needed. Keep all symbols unless we're producing a final executable.
if (output_type == LTO_CODEGEN_PIC_MODEL_STATIC) {
@@ -298,10 +314,16 @@ ld_plugin_status all_symbols_read_hook(void) {
I->syms[i].resolution == LDPR_RESOLVED_IR)) {
lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name);
anySymbolsPreserved = true;
+
+ if (generate_api_file)
+ api_file << I->syms[i].name << "\n";
}
}
}
+ if (generate_api_file)
+ api_file.close();
+
if (!anySymbolsPreserved) {
// This entire file is unnecessary!
lto_codegen_dispose(cg);