[llvm] r332884 - LTO: Replace split dwarf implementation that uses objcopy with one that uses direct emission.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon May 21 13:26:49 PDT 2018
Author: pcc
Date: Mon May 21 13:26:49 2018
New Revision: 332884
URL: http://llvm.org/viewvc/llvm-project?rev=332884&view=rev
Log:
LTO: Replace split dwarf implementation that uses objcopy with one that uses direct emission.
Part of PR37466.
Differential Revision: https://reviews.llvm.org/D47091
Modified:
llvm/trunk/include/llvm/LTO/Config.h
llvm/trunk/lib/LTO/LTOBackend.cpp
llvm/trunk/test/tools/gold/X86/split-dwarf.ll
llvm/trunk/tools/gold/gold-plugin.cpp
Modified: llvm/trunk/include/llvm/LTO/Config.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/Config.h?rev=332884&r1=332883&r2=332884&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/Config.h (original)
+++ llvm/trunk/include/llvm/LTO/Config.h Mon May 21 13:26:49 2018
@@ -76,9 +76,6 @@ struct Config {
/// The directory to store .dwo files.
std::string DwoDir;
- /// The objcopy binary used to extract dwo files.
- std::string Objcopy;
-
/// Optimization remarks file path.
std::string RemarksFilename = "";
Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=332884&r1=332883&r2=332884&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Mon May 21 13:26:49 2018
@@ -285,80 +285,36 @@ bool opt(Config &Conf, TargetMachine *TM
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
}
-void codegenWithSplitDwarf(Config &Conf, TargetMachine *TM,
- AddStreamFn AddStream, unsigned Task, Module &Mod) {
- SmallString<128> TempFile;
- int FD = -1;
- if (auto EC =
- sys::fs::createTemporaryFile("lto-llvm-fission", "o", FD, TempFile))
- report_fatal_error("Could not create temporary file " +
- TempFile.str() + ": " + EC.message());
- llvm::raw_fd_ostream OS(FD, true);
- SmallString<1024> DwarfFile(Conf.DwoDir);
- std::string DwoName = sys::path::filename(Mod.getModuleIdentifier()).str() +
- "-" + std::to_string(Task) + "-";
- size_t index = TempFile.str().rfind("lto-llvm-fission");
- StringRef TempID = TempFile.str().substr(index + 17, 6);
- DwoName += TempID.str() + ".dwo";
- sys::path::append(DwarfFile, DwoName);
- TM->Options.MCOptions.SplitDwarfFile = DwarfFile.str().str();
-
- legacy::PassManager CodeGenPasses;
- if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, Conf.CGFileType))
- report_fatal_error("Failed to setup codegen");
- CodeGenPasses.run(Mod);
-
- if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
- report_fatal_error("Failed to create directory " +
- Conf.DwoDir + ": " + EC.message());
-
- SmallVector<const char*, 5> ExtractArgs, StripArgs;
- ExtractArgs.push_back(Conf.Objcopy.c_str());
- ExtractArgs.push_back("--extract-dwo");
- ExtractArgs.push_back(TempFile.c_str());
- ExtractArgs.push_back(TM->Options.MCOptions.SplitDwarfFile.c_str());
- ExtractArgs.push_back(nullptr);
- StripArgs.push_back(Conf.Objcopy.c_str());
- StripArgs.push_back("--strip-dwo");
- StripArgs.push_back(TempFile.c_str());
- StripArgs.push_back(nullptr);
-
- if (auto Ret = sys::ExecuteAndWait(Conf.Objcopy, ExtractArgs.data())) {
- report_fatal_error("Failed to extract dwo from " + TempFile.str() +
- ". Exit code " + std::to_string(Ret));
- }
- if (auto Ret = sys::ExecuteAndWait(Conf.Objcopy, StripArgs.data())) {
- report_fatal_error("Failed to strip dwo from " + TempFile.str() +
- ". Exit code " + std::to_string(Ret));
- }
-
- auto Stream = AddStream(Task);
- auto Buffer = MemoryBuffer::getFile(TempFile);
- if (auto EC = Buffer.getError())
- report_fatal_error("Failed to load file " +
- TempFile.str() + ": " + EC.message());
- *Stream->OS << Buffer.get()->getBuffer();
- if (auto EC = sys::fs::remove(TempFile))
- report_fatal_error("Failed to delete file " +
- TempFile.str() + ": " + EC.message());
-}
-
void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream,
unsigned Task, Module &Mod) {
if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod))
return;
+ std::unique_ptr<ToolOutputFile> DwoOut;
if (!Conf.DwoDir.empty()) {
- codegenWithSplitDwarf(Conf, TM, AddStream, Task, Mod);
- return;
+ std::error_code EC;
+ if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
+ report_fatal_error("Failed to create directory " + Conf.DwoDir + ": " +
+ EC.message());
+
+ SmallString<1024> DwoFile(Conf.DwoDir);
+ sys::path::append(DwoFile, std::to_string(Task) + ".dwo");
+ TM->Options.MCOptions.SplitDwarfFile = DwoFile.str().str();
+ DwoOut = make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::F_None);
+ if (EC)
+ report_fatal_error("Failed to open " + DwoFile + ": " + EC.message());
}
auto Stream = AddStream(Task);
legacy::PassManager CodeGenPasses;
- if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, nullptr,
+ if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS,
+ DwoOut ? &DwoOut->os() : nullptr,
Conf.CGFileType))
report_fatal_error("Failed to setup codegen");
CodeGenPasses.run(Mod);
+
+ if (DwoOut)
+ DwoOut->keep();
}
void splitCodeGen(Config &C, TargetMachine *TM, AddStreamFn AddStream,
Modified: llvm/trunk/test/tools/gold/X86/split-dwarf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/split-dwarf.ll?rev=332884&r1=332883&r2=332884&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/split-dwarf.ll (original)
+++ llvm/trunk/test/tools/gold/X86/split-dwarf.ll Mon May 21 13:26:49 2018
@@ -3,15 +3,14 @@
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
; RUN: -m elf_x86_64 \
; RUN: --plugin-opt=thinlto \
-; RUN: --plugin-opt=objcopy=%llvm-objcopy \
; RUN: --plugin-opt=dwo_dir=%t/dwo_dir \
; RUN: %t/split-dwarf.o --shared -o %t/split-dwarf
; RUN: llvm-dwarfdump -debug-info %t/split-dwarf | FileCheck %s
-; CHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/split-dwarf.{{.*}}
+; CHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/1.dwo
; CHECK-NOT: DW_TAG_subprogram
-; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/split-dwarf.* | FileCheck --check-prefix DWOCHECK %s
-; DWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/split-dwarf.o{{.*}}
+; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/1.dwo | FileCheck --check-prefix DWOCHECK %s
+; DWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/1.dwo
; DWOCHECK: DW_AT_name{{.*}}split-dwarf.c
; DWOCHECK: DW_TAG_subprogram
@@ -20,15 +19,14 @@
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
; RUN: -m elf_x86_64 \
; RUN: --plugin-opt=thinlto \
-; RUN: --plugin-opt=objcopy=%llvm-objcopy \
; RUN: --plugin-opt=dwo_dir=%t/dwo_dir \
; RUN: %t/split-dwarf.o --shared -o %t/split-dwarf
; RUN: llvm-dwarfdump -debug-info %t/split-dwarf | FileCheck --check-prefix LTOCHECK %s
-; LTOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/ld-temp.{{.*}}
+; LTOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/0.dwo
; LTOCHECK-NOT: DW_TAG_subprogram
-; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/ld-temp.* | FileCheck --check-prefix LTODWOCHECK %s
-; LTODWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/ld-temp.o{{.*}}
+; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/0.dwo | FileCheck --check-prefix LTODWOCHECK %s
+; LTODWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/0.dwo
; LTODWOCHECK: DW_AT_name{{.*}}split-dwarf.c
; LTODWOCHECK: DW_TAG_subprogram
Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=332884&r1=332883&r2=332884&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon May 21 13:26:49 2018
@@ -199,8 +199,6 @@ namespace options {
static bool new_pass_manager = false;
// Debug new pass manager
static bool debug_pass_manager = false;
- // Objcopy for debug fission.
- static std::string objcopy;
// Directory to store the .dwo files.
static std::string dwo_dir;
/// Statistics output filename.
@@ -272,8 +270,6 @@ namespace options {
new_pass_manager = true;
} else if (opt == "debug-pass-manager") {
debug_pass_manager = true;
- } else if (opt.startswith("objcopy=")) {
- objcopy = opt.substr(strlen("objcopy="));
} else if (opt.startswith("dwo_dir=")) {
dwo_dir = opt.substr(strlen("dwo_dir="));
} else if (opt.startswith("opt-remarks-filename=")) {
@@ -892,8 +888,6 @@ static std::unique_ptr<LTO> createLTO(In
Conf.DwoDir = options::dwo_dir;
- Conf.Objcopy = options::objcopy;
-
// Set up optimization remarks handling.
Conf.RemarksFilename = options::OptRemarksFilename;
Conf.RemarksWithHotness = options::OptRemarksWithHotness;
More information about the llvm-commits
mailing list