[llvm] r215378 - Fix using -plugin-opt=apiflie when also using -plugin-opt=emit-llvm.
Rafael Espindola
rafael.espindola at gmail.com
Mon Aug 11 12:06:54 PDT 2014
Author: rafael
Date: Mon Aug 11 14:06:54 2014
New Revision: 215378
URL: http://llvm.org/viewvc/llvm-project?rev=215378&view=rev
Log:
Fix using -plugin-opt=apiflie when also using -plugin-opt=emit-llvm.
Modified:
llvm/trunk/test/tools/gold/emit-llvm.ll
llvm/trunk/tools/gold/gold-plugin.cpp
Modified: llvm/trunk/test/tools/gold/emit-llvm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/emit-llvm.ll?rev=215378&r1=215377&r2=215378&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/emit-llvm.ll (original)
+++ llvm/trunk/test/tools/gold/emit-llvm.ll Mon Aug 11 14:06:54 2014
@@ -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_a
ret void
}
@g6 = global void()* @f6
+
+
+; API: f3
+; API: f5
+; API: g5
+; API: g6
Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=215378&r1=215377&r2=215378&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon Aug 11 14:06:54 2014
@@ -390,20 +390,9 @@ static bool mustPreserve(ld_plugin_symbo
/// 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
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
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
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
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);
More information about the llvm-commits
mailing list