From 1d617acef9f102629b736db06a5b5def0e116297 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 17 Oct 2011 23:05:52 +0000 Subject: [PATCH] Wire up support for the controlling the extended dwarf .file directive. With r142300 but not this patch, clang -S may emit .s files that assemblers other than llvm-mc can't parse. llvm-svn: 142301 --- clang/include/clang/Driver/CC1Options.td | 2 ++ clang/include/clang/Driver/Options.td | 2 ++ clang/include/clang/Frontend/CodeGenOptions.h | 2 ++ clang/lib/CodeGen/BackendUtil.cpp | 2 ++ clang/lib/Driver/Tools.cpp | 15 +++++++++++++++ clang/lib/Frontend/CompilerInvocation.cpp | 3 +++ clang/tools/driver/cc1as_main.cpp | 4 +++- 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 4473d46e2b32..0599e05fc73f 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -117,6 +117,8 @@ def fforbid_guard_variables : Flag<"-fforbid-guard-variables">, def g : Flag<"-g">, HelpText<"Generate source level debug information">; def fno_dwarf2_cfi_asm : Flag<"-fno-dwarf2-cfi-asm">, HelpText<"Don't use the cfi directives">; +def fno_dwarf_directory_asm : Flag<"-fno-dwarf-directory-asm">, + HelpText<"Don't separate directory and filename in .file directives">; def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">, HelpText<"Generate runtime checks for undefined behavior.">; def flimit_debug_info : Flag<"-flimit-debug-info">, diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1c6635da1a52..c8295ea63d28 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -301,6 +301,8 @@ def fdiagnostics_show_category_EQ : Joined<"-fdiagnostics-show-category=">, Grou def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, Group; def fdwarf2_cfi_asm : Flag<"-fdwarf2-cfi-asm">, Group; def fno_dwarf2_cfi_asm : Flag<"-fno-dwarf2-cfi-asm">, Group; +def fdwarf_directory_asm : Flag<"-fdwarf-directory-asm">, Group; +def fno_dwarf_directory_asm : Flag<"-fno-dwarf-directory-asm">, Group; def felide_constructors : Flag<"-felide-constructors">, Group; def feliminate_unused_debug_symbols : Flag<"-feliminate-unused-debug-symbols">, Group; def femit_all_decls : Flag<"-femit-all-decls">, Group; diff --git a/clang/include/clang/Frontend/CodeGenOptions.h b/clang/include/clang/Frontend/CodeGenOptions.h index 4874c17c7996..ecfe49fa4600 100644 --- a/clang/include/clang/Frontend/CodeGenOptions.h +++ b/clang/include/clang/Frontend/CodeGenOptions.h @@ -71,6 +71,8 @@ public: unsigned MergeAllConstants : 1; /// Merge identical constants. unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled. unsigned NoDwarf2CFIAsm : 1; /// Set when -fno-dwarf2-cfi-asm is enabled. + unsigned NoDwarfDirectoryAsm : 1; /// Set when -fno-dwarf-directory-asm is + /// enabled. unsigned NoExecStack : 1; /// Set when -Wa,--noexecstack is enabled. unsigned NoGlobalMerge : 1; /// Set when -mno-global-merge is enabled. unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled. diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b9e3ed9edd19..8bd67ba3f0ba 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -305,6 +305,8 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, TM->setMCSaveTempLabels(true); if (CodeGenOpts.NoDwarf2CFIAsm) TM->setMCUseCFI(false); + if (CodeGenOpts.NoDwarfDirectoryAsm) + TM->setMCUseDwarfDirectory(false); if (CodeGenOpts.NoExecStack) TM->setMCNoExecStack(true); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 20b02f541e5e..3a6d737dec22 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1060,6 +1060,18 @@ static bool ShouldDisableCFI(const ArgList &Args, return false; } +static bool ShouldDisableDwarfDirectory(const ArgList &Args, + const ToolChain &TC) { + bool IsIADefault = TC.IsIntegratedAssemblerDefault(); + bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as, + options::OPT_no_integrated_as, + IsIADefault); + bool UseDwarfDirectory = Args.hasFlag(options::OPT_fdwarf_directory_asm, + options::OPT_fno_dwarf_directory_asm, + UseIntegratedAs); + return !UseDwarfDirectory; +} + /// \brief Check whether the given input tree contains any compilation actions. static bool ContainsCompileAction(const Action *A) { if (isa(A)) @@ -1614,6 +1626,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (ShouldDisableCFI(Args, getToolChain())) CmdArgs.push_back("-fno-dwarf2-cfi-asm"); + if (ShouldDisableDwarfDirectory(Args, getToolChain())) + CmdArgs.push_back("-fno-dwarf-directory-asm"); + if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { CmdArgs.push_back("-ftemplate-depth"); CmdArgs.push_back(A->getValue(Args)); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 1debf3b35318..6a7d2ac10d44 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -231,6 +231,8 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts, Res.push_back("-msave-temp-labels"); if (Opts.NoDwarf2CFIAsm) Res.push_back("-fno-dwarf2-cfi-asm"); + if (Opts.NoDwarfDirectoryAsm) + Res.push_back("-fno-dwarf-directory-asm"); if (Opts.SoftFloat) Res.push_back("-msoft-float"); if (Opts.UnwindTables) @@ -1051,6 +1053,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels); Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm); + Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); Opts.SoftFloat = Args.hasArg(OPT_msoft_float); Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations) || Args.hasArg(OPT_cl_fast_relaxed_math); diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 7cc42aa62768..4215a328c553 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -292,7 +292,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, } Str.reset(TheTarget->createAsmStreamer(Ctx, *Out, /*asmverbose*/true, /*useLoc*/ true, - /*useCFI*/ true, IP, CE, MAB, + /*useCFI*/ true, + /*useDwarfDirectory*/ true, + IP, CE, MAB, Opts.ShowInst)); } else if (Opts.OutputType == AssemblerInvocation::FT_Null) { Str.reset(createNullStreamer(Ctx));