From ea2cb09d2a0e05a65260467c961cb7b4c2b589d1 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 21 Apr 2017 23:35:36 +0000 Subject: [PATCH] Move Split DWARF handling to an MC option/command line argument rather than using metadata Since Split DWARF needs to name the actual .dwo file that is generated, it can't be known at the time the llvm::Module is produced as it may be merged with other Modules before the object is generated and that object may be generated with any name. By passing the Split DWARF file name when LLVM is producing object code the .dwo file name in the object file can match correctly. The support for Split DWARF for implicit modules remains the same - using metadata to store the dwo name and dwo id so that potentially multiple skeleton CUs referring to different dwo files can be generated from one llvm::Module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301063 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 2 ++ include/clang/Frontend/CodeGenOptions.def | 1 + lib/CodeGen/BackendUtil.cpp | 2 ++ lib/CodeGen/CGDebugInfo.cpp | 12 +++++++----- lib/Driver/ToolChains/Clang.cpp | 3 +-- lib/Frontend/CompilerInvocation.cpp | 1 + test/CodeGen/split-debug-filename.c | 5 +++++ test/Driver/split-debug.c | 16 ++++++++-------- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index ba09bccfe1..63348c094c 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -573,6 +573,8 @@ def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">, HelpText<"Weakly link in the blocks runtime">; def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">, HelpText<"Assume all functions with C linkage do not unwind">; +def enable_split_dwarf : Flag<["-"], "enable-split-dwarf">, + HelpText<"Use split dwarf/Fission">; def split_dwarf_file : Separate<["-"], "split-dwarf-file">, HelpText<"File name to use for split dwarf debug info output">; def fno_wchar : Flag<["-"], "fno-wchar">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index 9565b22e70..0b7d466ab3 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -199,6 +199,7 @@ CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain CODEGENOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should ///< contain explicit imports for ///< anonymous namespaces +CODEGENOPT(EnableSplitDwarf, 1, 0) ///< Whether to enable split DWARF CODEGENOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in the ///< skeleton CU to allow for symbolication ///< of inline stack frames without .dwo files. diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 20059d922f..7de0eaca19 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -407,6 +407,8 @@ static void initTargetOptions(llvm::TargetOptions &Options, Options.EmulatedTLS = CodeGenOpts.EmulatedTLS; Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning(); + if (CodeGenOpts.EnableSplitDwarf) + Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile; Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm; diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 2f6a2b95fb..dd32a44393 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -528,12 +528,14 @@ void CGDebugInfo::CreateCompileUnit() { // Create new compile unit. // FIXME - Eliminate TheCU. TheCU = DBuilder.createCompileUnit( - LangTag, DBuilder.createFile(remapDIPath(MainFileName), - remapDIPath(getCurrentDirname()), CSKind, - Checksum), + LangTag, + DBuilder.createFile(remapDIPath(MainFileName), + remapDIPath(getCurrentDirname()), CSKind, Checksum), Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers, - CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */, - CGM.getCodeGenOpts().SplitDwarfInlining, + CGM.getCodeGenOpts().EnableSplitDwarf + ? "" + : CGM.getCodeGenOpts().SplitDwarfFile, + EmissionKind, 0 /* DWOid */, CGM.getCodeGenOpts().SplitDwarfInlining, CGM.getCodeGenOpts().DebugInfoForProfiling); } diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 49708e7d72..6e1e4ccf44 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -2778,8 +2778,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fno-split-dwarf-inlining"); if (DebugInfoKind == codegenoptions::NoDebugInfo) DebugInfoKind = codegenoptions::LimitedDebugInfo; - CmdArgs.push_back("-backend-option"); - CmdArgs.push_back("-split-dwarf=Enable"); + CmdArgs.push_back("-enable-split-dwarf"); } // After we've dealt with all combinations of things that could diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 0e0eb40eb3..8cdb8298ee 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -519,6 +519,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro); Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables); Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std); + Opts.EnableSplitDwarf = Args.hasArg(OPT_enable_split_dwarf); Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); Opts.SplitDwarfInlining = !Args.hasArg(OPT_fno_split_dwarf_inlining); Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs); diff --git a/test/CodeGen/split-debug-filename.c b/test/CodeGen/split-debug-filename.c index 43daeada96..9ca7b0f328 100644 --- a/test/CodeGen/split-debug-filename.c +++ b/test/CodeGen/split-debug-filename.c @@ -1,7 +1,12 @@ // RUN: %clang_cc1 -debug-info-kind=limited -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -debug-info-kind=limited -enable-split-dwarf -split-dwarf-file foo.dwo -S -emit-llvm -o - %s | FileCheck --check-prefix=VANILLA %s int main (void) { return 0; } // Testing to ensure that the dwo name gets output into the compile unit. // CHECK: !DICompileUnit({{.*}}, splitDebugFilename: "foo.dwo" + +// Testing to ensure that the dwo name is not output into the compile unit if +// it's for vanilla split-dwarf rather than split-dwarf for implicit modules. +// VANILLA-NOT: splitDebugFilename diff --git a/test/Driver/split-debug.c b/test/Driver/split-debug.c index eaa1e990c0..c12164b4e2 100644 --- a/test/Driver/split-debug.c +++ b/test/Driver/split-debug.c @@ -36,53 +36,53 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -gmlt -fno-split-dwarf-inlining -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-GMLT-WITH-SPLIT < %t %s // -// CHECK-GMLT-WITH-SPLIT: "-split-dwarf=Enable" +// CHECK-GMLT-WITH-SPLIT: "-enable-split-dwarf" // CHECK-GMLT-WITH-SPLIT: "-debug-info-kind=line-tables-only" // CHECK-GMLT-WITH-SPLIT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-GMLT < %t %s // -// CHECK-SPLIT-WITH-GMLT: "-split-dwarf=Enable" +// CHECK-SPLIT-WITH-GMLT: "-enable-split-dwarf" // CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=line-tables-only" // CHECK-SPLIT-WITH-GMLT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-NOINL < %t %s // -// CHECK-SPLIT-WITH-NOINL: "-split-dwarf=Enable" +// CHECK-SPLIT-WITH-NOINL: "-enable-split-dwarf" // CHECK-SPLIT-WITH-NOINL: "-debug-info-kind=limited" // CHECK-SPLIT-WITH-NOINL: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -gmlt -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-GMLT-OVER-SPLIT < %t %s // -// CHECK-GMLT-OVER-SPLIT-NOT: "-split-dwarf=Enable" +// CHECK-GMLT-OVER-SPLIT-NOT: "-enable-split-dwarf" // CHECK-GMLT-OVER-SPLIT: "-debug-info-kind=line-tables-only" // CHECK-GMLT-OVER-SPLIT-NOT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-GMLT < %t %s // -// CHECK-SPLIT-OVER-GMLT: "-split-dwarf=Enable" "-debug-info-kind=limited" +// CHECK-SPLIT-OVER-GMLT: "-enable-split-dwarf" "-debug-info-kind=limited" // CHECK-SPLIT-OVER-GMLT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -g0 -fno-split-dwarf-inlining -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s // -// CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf=Enable" +// CHECK-G0-OVER-SPLIT-NOT: "-enable-split-dwarf" // CHECK-G0-OVER-SPLIT-NOT: "-debug-info-kind // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -g0 -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s // -// CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf=Enable" +// CHECK-G0-OVER-SPLIT-NOT: "-enable-split-dwarf" // CHECK-G0-OVER-SPLIT-NOT: "-debug-info-kind // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-file" // RUN: %clang -target x86_64-unknown-linux-gnu -g0 -gsplit-dwarf -S -### %s 2> %t // RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-G0 < %t %s // -// CHECK-SPLIT-OVER-G0: "-split-dwarf=Enable" "-debug-info-kind=limited" +// CHECK-SPLIT-OVER-G0: "-enable-split-dwarf" "-debug-info-kind=limited" // CHECK-SPLIT-OVER-G0: "-split-dwarf-file" -- 2.40.0