diff options
| author | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-06-11 17:49:23 +0000 | 
|---|---|---|
| committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-06-11 17:49:23 +0000 | 
| commit | 7289ba91651025808071e90d79e1619e9a88aa08 (patch) | |
| tree | b1cc366f18271da31a72f09388b8d4d180b6b170 | |
| parent | d3ba0ac2a523f8dd25c1c77a52eab094872d66a2 (diff) | |
| download | bcm5719-llvm-7289ba91651025808071e90d79e1619e9a88aa08.tar.gz bcm5719-llvm-7289ba91651025808071e90d79e1619e9a88aa08.zip  | |
Driver: add support for `-gz` and `-gz=`
These options control the behaviour of the compression of debug info
sections on ELF targets.  Our behaviour slightly diverges from the
behaviour of GCC.  `-gz` maps to the `-compress-debug-sections` rather
than `-compress-debug-sections=zlib` or
`-compress-debug-sections=zlib-gnu`.  This small divergence allows us to
be compatible across versions of binutils (=zlib support was introduced
in 2.26, while earlier versions only support =zlib-gnu).  This also
allows users to not have to worry about the version of the assembler
they may be using if they are not using the IAS.  Previously, users
would have had to go through the internal option
`-compress-debug-sectionss` and pass that through to the assembler,
which is no longer needed.
llvm-svn: 305165
| -rw-r--r-- | clang/include/clang/Driver/CC1Options.td | 7 | ||||
| -rw-r--r-- | clang/include/clang/Driver/Options.td | 4 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 33 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Gnu.cpp | 19 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 19 | ||||
| -rw-r--r-- | clang/test/Driver/compress.c | 30 | ||||
| -rw-r--r-- | clang/tools/driver/cc1as_main.cpp | 19 | 
7 files changed, 122 insertions, 9 deletions
diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 1132d1345f6..319d8f58467 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -134,7 +134,6 @@ def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">,  //===----------------------------------------------------------------------===//  let Flags = [CC1Option, CC1AsOption, NoDriverOption] in { -  def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;  def debug_info_macro : Flag<["-"], "debug-info-macro">,    HelpText<"Emit macro debug information">; @@ -144,14 +143,16 @@ def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,    HelpText<"The compilation directory to embed in the debug info.">;  def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,    HelpText<"The string to embed in the Dwarf debug flags record.">; +def compress_debug_sections : Flag<["-"], "compress-debug-sections">, +    HelpText<"DWARF debug sections compression">; +def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">, +    HelpText<"DWARF debug sections compression type">;  def mno_exec_stack : Flag<["-"], "mnoexecstack">,    HelpText<"Mark the file as not needing an executable stack">;  def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,    HelpText<"Make assembler warnings fatal">;  def mrelax_relocations : Flag<["--"], "mrelax-relocations">,      HelpText<"Use relaxable elf relocations">; -def compress_debug_sections : Flag<["-"], "compress-debug-sections">, -    HelpText<"Compress DWARF debug sections using zlib">;  def msave_temp_labels : Flag<["-"], "msave-temp-labels">,    HelpText<"Save temporary labels in the symbol table. "             "Note this may change .s semantics and shouldn't generally be used " diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6c51976e98f..e47739e41ae 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1563,6 +1563,10 @@ def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>;  def gmodules : Flag <["-"], "gmodules">, Group<gN_Group>,    HelpText<"Generate debug info with external references to clang modules"             " or precompiled headers">; +def gz : Flag<["-"], "gz">, Group<g_flags_Group>, +    HelpText<"DWARF debug sections compression type">; +def gz_EQ : Joined<["-"], "gz=">, Group<g_flags_Group>, +    HelpText<"DWARF debug sections compression type">;  def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;  def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,    HelpText<"Display available options">; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 87ca065a46a..1e7ff67edda 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -910,6 +910,34 @@ static void RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs,    }  } +static void RenderDebugInfoCompressionArgs(const ArgList &Args, +                                           ArgStringList &CmdArgs, +                                           const Driver &D) { +  const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ); +  if (!A) +    return; + +  if (A->getOption().getID() == options::OPT_gz) { +    CmdArgs.push_back("-compress-debug-sections"); +    return; +  } + +  StringRef Value = A->getValue(); +  if (Value == "none") { +    CmdArgs.push_back("-compress-debug-sections=none"); +  } else if (Value == "zlib" || Value == "zlib-gnu") { +    if (!llvm::zlib::isAvailable()) { +      D.Diag(diag::warn_debug_compression_unavailable); +    } else { +      CmdArgs.push_back( +          Args.MakeArgString("-compress-debug-sections=" + Twine(Value))); +    } +  } else { +    D.Diag(diag::err_drv_unsupported_option_argument) +        << A->getOption().getName() << Value; +  } +} +  static const char *RelocationModelName(llvm::Reloc::Model Model) {    switch (Model) {    case llvm::Reloc::Static: @@ -2810,6 +2838,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,      CmdArgs.push_back("-generate-type-units");    } +  RenderDebugInfoCompressionArgs(Args, CmdArgs, D); +    bool UseSeparateSections = isUseSeparateSections(Triple);    if (Args.hasFlag(options::OPT_ffunction_sections, @@ -4913,6 +4943,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,    const llvm::Triple &Triple = getToolChain().getEffectiveTriple();    const std::string &TripleStr = Triple.getTriple(); +  const auto &D = getToolChain().getDriver();    // Don't warn about "clang -w -c foo.s"    Args.ClaimAllArgs(options::OPT_w); @@ -5000,6 +5031,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,    }    RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DwarfVersion,                            llvm::DebuggerKind::Default); +  RenderDebugInfoCompressionArgs(Args, CmdArgs, D); +    // Handle -fPIC et al -- the relocation-model affects the assembler    // for some targets. diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index d50f8e21f62..c9d15ea00d8 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -650,6 +650,8 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,                                                const InputInfoList &Inputs,                                                const ArgList &Args,                                                const char *LinkingOutput) const { +  const auto &D = getToolChain().getDriver(); +    claimNoWarnArgs(Args);    ArgStringList CmdArgs; @@ -660,6 +662,23 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,    std::tie(RelocationModel, PICLevel, IsPIE) =        ParsePICArgs(getToolChain(), Args); +  if (const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ)) { +    if (A->getOption().getID() == options::OPT_gz) { +      CmdArgs.push_back("-compress-debug-sections"); +    } else { +      StringRef Value = A->getValue(); +      if (Value == "none") { +        CmdArgs.push_back("-compress-debug-sections=none"); +      } else if (Value == "zlib" || Value == "zlib-gnu") { +        CmdArgs.push_back( +            Args.MakeArgString("-compress-debug-sections=" + Twine(Value))); +      } else { +        D.Diag(diag::err_drv_unsupported_option_argument) +            << A->getOption().getName() << Value; +      } +    } +  } +    switch (getToolChain().getArch()) {    default:      break; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index bb635b7ad71..4fd4872f385 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -739,9 +739,22 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,    Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);    Opts.CallFEntry = Args.hasArg(OPT_mfentry);    Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info); -  // TODO: map this from -gz in the driver and give it a named value -  if (Args.hasArg(OPT_compress_debug_sections)) -    Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU); + +  if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, +                                     OPT_compress_debug_sections_EQ)) { +    if (A->getOption().getID() == OPT_compress_debug_sections) { +      // TODO: be more clever about the compression type auto-detection +      Opts.setCompressDebugSections(llvm::DebugCompressionType::GNU); +    } else { +      auto DCT = llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue()) +                     .Case("none", llvm::DebugCompressionType::None) +                     .Case("zlib", llvm::DebugCompressionType::Z) +                     .Case("zlib-gnu", llvm::DebugCompressionType::GNU) +                     .Default(llvm::DebugCompressionType::None); +      Opts.setCompressDebugSections(DCT); +    } +  } +    Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);    Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);    for (auto A : Args.filtered(OPT_mlink_bitcode_file, OPT_mlink_cuda_bitcode)) { diff --git a/clang/test/Driver/compress.c b/clang/test/Driver/compress.c index e7ee83bce50..5c25f42c55c 100644 --- a/clang/test/Driver/compress.c +++ b/clang/test/Driver/compress.c @@ -18,3 +18,33 @@  // CHECK-MULTIPLE: "-compress-debug-sections"  // CHECK-MULTIPLE: "--compress-debug-sections" +// RUN: %clang -### -fintegrated-as -gz -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// RUN: %clang -### -fno-integrated-as -gz -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// RUN: %clang -### -fno-integrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s +// CHECK-OPT_GZ: "-compress-debug-sections" + +// RUN: %clang -### -fintegrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// RUN: %clang -### -fno-integrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// RUN: %clang -### -fno-integrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s +// CHECK-OPT_GZ_EQ_NONE: "-compress-debug-sections=none" + +// RUN: %clang -### -fintegrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// RUN: %clang -### -fintegrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// RUN: %clang -### -fno-integrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// RUN: %clang -### -fno-integrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s +// CHECK-OPT_GZ_EQ_ZLIB: "-compress-debug-sections=zlib" + +// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// RUN: %clang -### -fno-integrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// RUN: %clang -### -fno-integrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s +// CHECK-OPT_GZ_EQ_ZLIB_GNU: "-compress-debug-sections=zlib-gnu" + +// RUN: %clang -### -fintegrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// RUN: %clang -### -fintegrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// RUN: %clang -### -fno-integrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// RUN: %clang -### -fno-integrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s +// CHECK-OPT_GZ_EQ_INVALID: error: unsupported argument 'invalid' to option 'gz=' + diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 37c14f4a26e..2fc2b508ef2 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -202,9 +202,22 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,    Opts.SaveTemporaryLabels = Args.hasArg(OPT_msave_temp_labels);    // Any DebugInfoKind implies GenDwarfForAssembly.    Opts.GenDwarfForAssembly = Args.hasArg(OPT_debug_info_kind_EQ); -  // TODO: base this on -gz instead -  if (Args.hasArg(OPT_compress_debug_sections)) -    Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; + +  if (const Arg *A = Args.getLastArg(OPT_compress_debug_sections, +                                     OPT_compress_debug_sections_EQ)) { +    if (A->getOption().getID() == OPT_compress_debug_sections) { +      // TODO: be more clever about the compression type auto-detection +      Opts.CompressDebugSections = llvm::DebugCompressionType::GNU; +    } else { +      Opts.CompressDebugSections = +          llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue()) +              .Case("none", llvm::DebugCompressionType::None) +              .Case("zlib", llvm::DebugCompressionType::Z) +              .Case("zlib-gnu", llvm::DebugCompressionType::GNU) +              .Default(llvm::DebugCompressionType::None); +    } +  } +    Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);    Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);    Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);  | 

