[llvm] r294953 - [LTO] Make sure we flush buffers to work around linker shenanigans.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 13 06:39:52 PST 2017
Author: davide
Date: Mon Feb 13 08:39:51 2017
New Revision: 294953
URL: http://llvm.org/viewvc/llvm-project?rev=294953&view=rev
Log:
[LTO] Make sure we flush buffers to work around linker shenanigans.
lld, at least, doesn't call global destructors by default (unless
--full-shutdown is passed) because it's, allegedly, expensive.
Modified:
llvm/trunk/lib/LTO/LTOBackend.cpp
Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=294953&r1=294952&r2=294953&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Mon Feb 13 08:39:51 2017
@@ -340,6 +340,16 @@ Expected<const Target *> initAndLookupTa
}
+static void
+finalizeOptimizationRemarks(std::unique_ptr<tool_output_file> DiagOutputFile) {
+ // Make sure we flush the diagnostic remarks file in case the linker doesn't
+ // call the global destructors before exiting.
+ if (!DiagOutputFile)
+ return;
+ DiagOutputFile->keep();
+ DiagOutputFile->os().flush();
+}
+
static void handleAsmUndefinedRefs(Module &Mod, TargetMachine &TM) {
// Collect the list of undefined symbols used in asm and update
// llvm.compiler.used to prevent optimization to drop these from the output.
@@ -371,10 +381,14 @@ Error lto::backend(Config &C, AddStreamF
Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
if (!DiagFileOrErr)
return DiagFileOrErr.takeError();
+ auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
- if (!C.CodeGenOnly)
- if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, CombinedIndex))
+ if (!C.CodeGenOnly) {
+ if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, CombinedIndex)) {
+ finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
return Error::success();
+ }
+ }
if (ParallelCodeGenParallelismLevel == 1) {
codegen(C, TM.get(), AddStream, 0, *Mod);
@@ -382,6 +396,7 @@ Error lto::backend(Config &C, AddStreamF
splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel,
std::move(Mod));
}
+ finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
return Error::success();
}
More information about the llvm-commits
mailing list