llvm.org GIT mirror llvm / edd00e4
Enable debug fission for thinLTO linked via gold-plugin Summary: This enables debug fission on implicit ThinLTO when linked with gold. It will put the .dwo files in a directory specified by user. Reviewers: tejohnson, pcc, dblaikie Reviewed By: pcc Subscribers: JDevlieghere, mehdi_amini, inglorion Differential Revision: https://reviews.llvm.org/D44792 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329988 91177308-0d34-0410-b5e6-96231b3b80d8 Yunlian Jiang 2 years ago
6 changed file(s) with 150 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7171
7272 /// Sample PGO profile path.
7373 std::string SampleProfile;
74
75 /// The directory to store .dwo files.
76 std::string DwoDir;
77
78 /// The objcopy binary used to extract dwo files.
79 std::string Objcopy;
7480
7581 /// Optimization remarks file path.
7682 std::string RemarksFilename = "";
135135 AddString(Conf.AAPipeline);
136136 AddString(Conf.OverrideTriple);
137137 AddString(Conf.DefaultTriple);
138 AddString(Conf.DwoDir);
138139
139140 // Include the hash for the current module
140141 auto ModHash = Index.getModuleHash(ModuleID);
2929 #include "llvm/Passes/PassBuilder.h"
3030 #include "llvm/Support/Error.h"
3131 #include "llvm/Support/FileSystem.h"
32 #include "llvm/Support/MemoryBuffer.h"
33 #include "llvm/Support/Path.h"
34 #include "llvm/Support/Program.h"
35 #include "llvm/Support/raw_ostream.h"
3236 #include "llvm/Support/TargetRegistry.h"
3337 #include "llvm/Support/ThreadPool.h"
3438 #include "llvm/Target/TargetMachine.h"
278282 return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
279283 }
280284
285 void codegenWithSplitDwarf(Config &Conf, TargetMachine *TM,
286 AddStreamFn AddStream, unsigned Task, Module &Mod) {
287 SmallString<128> TempFile;
288 int FD = -1;
289 if (auto EC =
290 sys::fs::createTemporaryFile("lto-llvm-fission", "o", FD, TempFile))
291 report_fatal_error("Could not create temporary file " +
292 TempFile.str() + ": " + EC.message());
293 llvm::raw_fd_ostream OS(FD, true);
294 SmallString<1024> DwarfFile(Conf.DwoDir);
295 std::string DwoName = sys::path::filename(Mod.getModuleIdentifier()).str() +
296 "-" + std::to_string(Task) + "-";
297 size_t index = TempFile.str().rfind("lto-llvm-fission");
298 StringRef TempID = TempFile.str().substr(index + 17, 6);
299 DwoName += TempID.str() + ".dwo";
300 sys::path::append(DwarfFile, DwoName);
301 TM->Options.MCOptions.SplitDwarfFile = DwarfFile.str().str();
302
303 legacy::PassManager CodeGenPasses;
304 if (TM->addPassesToEmitFile(CodeGenPasses, OS, Conf.CGFileType))
305 report_fatal_error("Failed to setup codegen");
306 CodeGenPasses.run(Mod);
307
308 if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
309 report_fatal_error("Failed to create directory " +
310 Conf.DwoDir + ": " + EC.message());
311
312 SmallVector ExtractArgs, StripArgs;
313 ExtractArgs.push_back(Conf.Objcopy.c_str());
314 ExtractArgs.push_back("--extract-dwo");
315 ExtractArgs.push_back(TempFile.c_str());
316 ExtractArgs.push_back(TM->Options.MCOptions.SplitDwarfFile.c_str());
317 ExtractArgs.push_back(nullptr);
318 StripArgs.push_back(Conf.Objcopy.c_str());
319 StripArgs.push_back("--strip-dwo");
320 StripArgs.push_back(TempFile.c_str());
321 StripArgs.push_back(nullptr);
322
323 if (auto Ret = sys::ExecuteAndWait(Conf.Objcopy, ExtractArgs.data())) {
324 report_fatal_error("Failed to extract dwo from " + TempFile.str() +
325 ". Exit code " + std::to_string(Ret));
326 }
327 if (auto Ret = sys::ExecuteAndWait(Conf.Objcopy, StripArgs.data())) {
328 report_fatal_error("Failed to strip dwo from " + TempFile.str() +
329 ". Exit code " + std::to_string(Ret));
330 }
331
332 auto Stream = AddStream(Task);
333 auto Buffer = MemoryBuffer::getFile(TempFile);
334 if (auto EC = Buffer.getError())
335 report_fatal_error("Failed to load file " +
336 TempFile.str() + ": " + EC.message());
337 *Stream->OS << Buffer.get()->getBuffer();
338 if (auto EC = sys::fs::remove(TempFile))
339 report_fatal_error("Failed to delete file " +
340 TempFile.str() + ": " + EC.message());
341 }
342
281343 void codegen(Config &Conf, TargetMachine *TM, AddStreamFn AddStream,
282344 unsigned Task, Module &Mod) {
283345 if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod))
284346 return;
347
348 if (!Conf.DwoDir.empty()) {
349 codegenWithSplitDwarf(Conf, TM, AddStream, Task, Mod);
350 return;
351 }
285352
286353 auto Stream = AddStream(Task);
287354 legacy::PassManager CodeGenPasses;
133133 ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
134134 ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
135135 ToolSubst('%opt-viewer', opt_viewer_cmd),
136 ToolSubst('%llvm-objcopy', FindTool('llvm-objcopy')),
136137 ]
137138
138139 # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
0 ; RUN: rm -rf %t && mkdir -p %t
1 ; RUN: opt -module-summary %s -o %t/split-dwarf.o
2 ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
3 ; RUN: -m elf_x86_64 \
4 ; RUN: --plugin-opt=thinlto \
5 ; RUN: --plugin-opt=objcopy=%llvm-objcopy \
6 ; RUN: --plugin-opt=dwo_dir=%t/dwo_dir \
7 ; RUN: %t/split-dwarf.o --shared -o %t/split-dwarf
8
9 ; RUN: llvm-dwarfdump -debug-info %t/split-dwarf | FileCheck %s
10 ; CHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/split-dwarf.{{.*}}
11 ; CHECK-NOT: DW_TAG_subprogram
12 ; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/split-dwarf.* | FileCheck --check-prefix DWOCHECK %s
13 ; DWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/split-dwarf.o{{.*}}
14 ; DWOCHECK: DW_AT_name{{.*}}split-dwarf.c
15 ; DWOCHECK: DW_TAG_subprogram
16
17 ; RUN:rm -rf %t/dwo_dir
18 ; RUN: opt %s -o %t/split-dwarf.o
19 ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
20 ; RUN: -m elf_x86_64 \
21 ; RUN: --plugin-opt=thinlto \
22 ; RUN: --plugin-opt=objcopy=%llvm-objcopy \
23 ; RUN: --plugin-opt=dwo_dir=%t/dwo_dir \
24 ; RUN: %t/split-dwarf.o --shared -o %t/split-dwarf
25
26 ; RUN: llvm-dwarfdump -debug-info %t/split-dwarf | FileCheck --check-prefix LTOCHECK %s
27 ; LTOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/ld-temp.{{.*}}
28 ; LTOCHECK-NOT: DW_TAG_subprogram
29 ; RUN: llvm-dwarfdump -debug-info %t/dwo_dir/ld-temp.* | FileCheck --check-prefix LTODWOCHECK %s
30 ; LTODWOCHECK: DW_AT_GNU_dwo_name{{.*}}dwo_dir/ld-temp.o{{.*}}
31 ; LTODWOCHECK: DW_AT_name{{.*}}split-dwarf.c
32 ; LTODWOCHECK: DW_TAG_subprogram
33
34 ; ModuleID = 'split-dwarf.c'
35 source_filename = "split-dwarf.c"
36 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
37 target triple = "x86_64-unknown-linux-gnu"
38
39 ; Function Attrs: noinline nounwind optnone uwtable
40 define dso_local i32 @split_dwarf() #0 !dbg !7 {
41 entry:
42 ret i32 0, !dbg !11
43 }
44
45 attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
46
47 !llvm.dbg.cu = !{!0}
48 !llvm.module.flags = !{!3, !4, !5}
49 !llvm.ident = !{!6}
50
51 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (https://github.com/llvm-mirror/clang.git b641d31365414ba3ea0305fdaa80369a9efb6bd9) (https://github.com/llvm-mirror/llvm.git 6165a776d1a8bb181be93f2dc97088f7a1abc405)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
52 !1 = !DIFile(filename: "split-dwarf.c", directory: "/usr/local/google/home/yunlian/dwp/build/bin")
53 !2 = !{}
54 !3 = !{i32 2, !"Dwarf Version", i32 4}
55 !4 = !{i32 2, !"Debug Info Version", i32 3}
56 !5 = !{i32 1, !"wchar_size", i32 4}
57 !6 = !{!"clang version 7.0.0 (https://github.com/llvm-mirror/clang.git b641d31365414ba3ea0305fdaa80369a9efb6bd9) (https://github.com/llvm-mirror/llvm.git 6165a776d1a8bb181be93f2dc97088f7a1abc405)"}
58 !7 = distinct !DISubprogram(name: "split_dwarf", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, variables: !2)
59 !8 = !DISubroutineType(types: !9)
60 !9 = !{!10}
61 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
62 !11 = !DILocation(line: 2, column: 2, scope: !7)
198198 static bool new_pass_manager = false;
199199 // Debug new pass manager
200200 static bool debug_pass_manager = false;
201 // Objcopy for debug fission.
202 static std::string objcopy;
203 // Directory to store the .dwo files.
204 static std::string dwo_dir;
201205
202206 static void process_plugin_option(const char *opt_)
203207 {
261265 new_pass_manager = true;
262266 } else if (opt == "debug-pass-manager") {
263267 debug_pass_manager = true;
268 } else if (opt.startswith("objcopy=")) {
269 objcopy = opt.substr(strlen("objcopy="));
270 } else if (opt.startswith("dwo_dir=")) {
271 dwo_dir = opt.substr(strlen("dwo_dir="));
264272 } else {
265273 // Save this option to pass to the code generator.
266274 // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
868876
869877 if (!options::sample_profile.empty())
870878 Conf.SampleProfile = options::sample_profile;
879
880 Conf.DwoDir = options::dwo_dir;
881
882 Conf.Objcopy = options::objcopy;
871883
872884 // Use new pass manager if set in driver
873885 Conf.UseNewPM = options::new_pass_manager;