diff options
author | Davide Italiano <davide@freebsd.org> | 2017-02-13 14:39:51 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-02-13 14:39:51 +0000 |
commit | 20a895c4be01769a37dfffb3c6b513a7bc9b8d17 (patch) | |
tree | 0d058e60ecffe0ec589820c57cbf353de50d20e3 /llvm/lib/LTO/LTOBackend.cpp | |
parent | ce2cb2d9684aa8d17aa75c4aebbcc25e720da521 (diff) | |
download | bcm5719-llvm-20a895c4be01769a37dfffb3c6b513a7bc9b8d17.tar.gz bcm5719-llvm-20a895c4be01769a37dfffb3c6b513a7bc9b8d17.zip |
[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.
llvm-svn: 294953
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 1afdc13045b..00959cbea69 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -340,6 +340,16 @@ Expected<const Target *> initAndLookupTarget(Config &C, Module &Mod) { } +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, AddStreamFn AddStream, 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, AddStreamFn AddStream, splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel, std::move(Mod)); } + finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); return Error::success(); } |