Fix using -plugin-opt=apiflie when also using -plugin-opt=emit-llvm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215378 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-08-11 19:06:54 +00:00
parent 7c0fa0cfab
commit b2d2f28351
2 changed files with 33 additions and 18 deletions

View File

@ -2,8 +2,10 @@
; RUN: ld -plugin %llvmshlibdir/LLVMgold.so \
; RUN: --plugin-opt=emit-llvm \
; RUN: --plugin-opt=generate-api-file \
; RUN: -shared %t.o -o %t2.o
; RUN: llvm-dis %t2.o -o - | FileCheck %s
; RUN: FileCheck --check-prefix=API %s < %T/../apifile.txt
; RUN: ld -plugin %llvmshlibdir/LLVMgold.so \
; RUN: -m elf_x86_64 --plugin-opt=also-emit-llvm \
@ -51,3 +53,9 @@ define linkonce_odr void @f6() unnamed_addr {
ret void
}
@g6 = global void()* @f6
; API: f3
; API: f5
; API: g5
; API: g6

View File

@ -390,20 +390,9 @@ static bool mustPreserve(ld_plugin_symbol &Sym) {
/// gold informs us that all symbols have been read. At this point, we use
/// get_symbols to see if any of our definitions have been overridden by a
/// native object file. Then, perform optimization and codegen.
static ld_plugin_status all_symbols_read_hook(void) {
// FIXME: raw_fd_ostream should be able to represent an unopened file.
std::unique_ptr<raw_fd_ostream> api_file;
static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *apiFile) {
assert(CodeGen);
if (options::generate_api_file) {
std::string Error;
api_file.reset(new raw_fd_ostream("apifile.txt", Error, sys::fs::F_None));
if (!Error.empty())
message(LDPL_FATAL, "Unable to open apifile.txt for writing: %s",
Error.c_str());
}
for (claimed_file &F : Modules) {
if (F.syms.empty())
continue;
@ -413,7 +402,7 @@ static ld_plugin_status all_symbols_read_hook(void) {
CodeGen->addMustPreserveSymbol(Sym.name);
if (options::generate_api_file)
(*api_file) << Sym.name << "\n";
(*apiFile) << Sym.name << "\n";
}
}
}
@ -434,10 +423,8 @@ static ld_plugin_status all_symbols_read_hook(void) {
std::string Error;
if (!CodeGen->writeMergedModules(path.c_str(), Error))
message(LDPL_FATAL, "Failed to write the output file.");
if (options::generate_bc_file == options::BC_ONLY) {
delete CodeGen;
exit(0);
}
if (options::generate_bc_file == options::BC_ONLY)
return LDPS_OK;
}
std::string ObjPath;
@ -450,7 +437,6 @@ static ld_plugin_status all_symbols_read_hook(void) {
ObjPath = Temp;
}
delete CodeGen;
for (claimed_file &F : Modules) {
for (ld_plugin_symbol &Sym : F.syms)
free(Sym.name);
@ -474,6 +460,27 @@ static ld_plugin_status all_symbols_read_hook(void) {
return LDPS_OK;
}
static ld_plugin_status all_symbols_read_hook(void) {
ld_plugin_status Ret;
if (!options::generate_api_file) {
Ret = allSymbolsReadHook(nullptr);
} else {
std::string Error;
raw_fd_ostream apiFile("apifile.txt", Error, sys::fs::F_None);
if (!Error.empty())
message(LDPL_FATAL, "Unable to open apifile.txt for writing: %s",
Error.c_str());
Ret = allSymbolsReadHook(&apiFile);
}
delete CodeGen;
if (options::generate_bc_file == options::BC_ONLY)
exit(0);
return Ret;
}
static ld_plugin_status cleanup_hook(void) {
for (std::string &Name : Cleanup) {
std::error_code EC = sys::fs::remove(Name);