mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
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
This commit is contained in:
parent
bc989d462d
commit
ca4286295f
@ -22,6 +22,7 @@
|
|||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -42,6 +43,8 @@ namespace {
|
|||||||
int api_version = 0;
|
int api_version = 0;
|
||||||
int gold_version = 0;
|
int gold_version = 0;
|
||||||
|
|
||||||
|
bool generate_api_file = false;
|
||||||
|
|
||||||
struct claimed_file {
|
struct claimed_file {
|
||||||
lto_module_t M;
|
lto_module_t M;
|
||||||
void *handle;
|
void *handle;
|
||||||
@ -96,7 +99,11 @@ ld_plugin_status onload(ld_plugin_tv *tv) {
|
|||||||
//output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC;
|
//output_type = LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC;
|
||||||
break;
|
break;
|
||||||
case LDPT_OPTION:
|
case LDPT_OPTION:
|
||||||
|
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);
|
(*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case LDPT_REGISTER_CLAIM_FILE_HOOK: {
|
case LDPT_REGISTER_CLAIM_FILE_HOOK: {
|
||||||
ld_plugin_register_claim_file callback;
|
ld_plugin_register_claim_file callback;
|
||||||
@ -285,6 +292,15 @@ ld_plugin_status all_symbols_read_hook(void) {
|
|||||||
E = Modules.end(); I != E; ++I)
|
E = Modules.end(); I != E; ++I)
|
||||||
lto_codegen_add_module(cg, I->M);
|
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
|
// 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.
|
// needed. Keep all symbols unless we're producing a final executable.
|
||||||
if (output_type == LTO_CODEGEN_PIC_MODEL_STATIC) {
|
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)) {
|
I->syms[i].resolution == LDPR_RESOLVED_IR)) {
|
||||||
lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name);
|
lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name);
|
||||||
anySymbolsPreserved = true;
|
anySymbolsPreserved = true;
|
||||||
|
|
||||||
|
if (generate_api_file)
|
||||||
|
api_file << I->syms[i].name << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (generate_api_file)
|
||||||
|
api_file.close();
|
||||||
|
|
||||||
if (!anySymbolsPreserved) {
|
if (!anySymbolsPreserved) {
|
||||||
// This entire file is unnecessary!
|
// This entire file is unnecessary!
|
||||||
lto_codegen_dispose(cg);
|
lto_codegen_dispose(cg);
|
||||||
|
Loading…
Reference in New Issue
Block a user