llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (Sterling-Augustine) <details> <summary>Changes</summary> This plumbs the option --gsframe through the various levels needed to support it in the assembler. This is the final step in assembler-level sframe support for x86. With it in place, clang produces sframe-sections that successfully link with gnu-ld. LLD support is pending some discussion. --- Full diff: https://github.com/llvm/llvm-project/pull/165322.diff 5 Files Affected: - (modified) clang/include/clang/Basic/CodeGenOptions.def (+2) - (modified) clang/include/clang/Driver/Options.td (+12-5) - (modified) clang/lib/CodeGen/BackendUtil.cpp (+1) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+12) - (modified) clang/tools/driver/cc1as_main.cpp (+6) ``````````diff diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 90e1f8d1eb5e9..99199c3a6c34c 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -120,6 +120,8 @@ CODEGENOPT(StackSizeSection , 1, 0, Benign) ///< Set when -fstack-size-section ///< Set when -femit-compact-unwind-non-canonical is enabled. CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0, Benign) +CODEGENOPT(EmitSFrameUnwind, 1, 0, Benign) ///< Set when -sframe is enabled. + ///< Set when -fxray-always-emit-customevents is enabled. CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0, Benign) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 93aeb22b18e92..06365cef77bf0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4701,11 +4701,13 @@ def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">, NormalizedValues<["Always", "NoCompactUnwind", "Default"]>, NormalizedValuesScope<"llvm::EmitDwarfUnwindType">, MarshallingInfoEnum<CodeGenOpts<"EmitDwarfUnwind">, "Default">; -defm emit_compact_unwind_non_canonical : BoolFOption<"emit-compact-unwind-non-canonical", - CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse, - PosFlag<SetTrue, [], [ClangOption, CC1Option, CC1AsOption], - "Try emitting Compact-Unwind for non-canonical entries. Maybe overridden by other constraints">, - NegFlag<SetFalse>>; +defm emit_compact_unwind_non_canonical + : BoolFOption<"emit-compact-unwind-non-canonical", + CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse, + PosFlag<SetTrue, [], [ClangOption, CC1Option, CC1AsOption], + "Try emitting Compact-Unwind for non-canonical " + "entries. Maybe overridden by other constraints">, + NegFlag<SetFalse>>; def g_Flag : Flag<["-"], "g">, Group<g_Group>, Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>, HelpText<"Generate source-level debug information">; @@ -7729,6 +7731,11 @@ def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">, def crel : Flag<["--"], "crel">, HelpText<"Enable CREL relocation format (ELF only)">, MarshallingInfoFlag<CodeGenOpts<"Crel">>; +// The leading 'g' is misleading. This is an unwind tables option, not +// a debug option. But uses this name for gnu compatibility. +def gsframe : Flag<["--"], "gsframe">, + HelpText<"Generate .sframe unwind sections (ELF only)">, + MarshallingInfoFlag<CodeGenOpts<"EmitSFrameUnwind">>; def mmapsyms_implicit : Flag<["-"], "mmapsyms=implicit">, HelpText<"Allow mapping symbol at section beginning to be implicit, " "lowering number of mapping symbols at the expense of some " diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 468c930acacbd..4b988103e3cd1 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -500,6 +500,7 @@ static bool initTargetOptions(const CompilerInstance &CI, Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind(); Options.MCOptions.EmitCompactUnwindNonCanonical = CodeGenOpts.EmitCompactUnwindNonCanonical; + Options.MCOptions.EmitSFrameUnwind = CodeGenOpts.EmitSFrameUnwind; Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; Options.MCOptions.MCUseDwarfDirectory = diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 79edc561c551f..a033e8f708306 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2617,6 +2617,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, llvm::codegenoptions::DebugInfoConstructor, DwarfVersion, llvm::DebuggerKind::Default); } + } else if (Value == "--gsframe") { + CmdArgs.push_back("--gsframe"); } else if (Value.starts_with("-mcpu") || Value.starts_with("-mfpu") || Value.starts_with("-mhwdiv") || Value.starts_with("-march")) { // Do nothing, we'll validate it later. @@ -5920,6 +5922,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, else if (UnwindTables) CmdArgs.push_back("-funwind-tables=1"); + // Sframe unwind tables are independent of the other types, and only defined + // for these two targets. + if (Arg *A = Args.getLastArg(options::OPT_gsframe)) { + if ((Triple.isAArch64() || Triple.isX86()) && Triple.isOSBinFormatELF()) + CmdArgs.push_back("--gsframe"); + else + D.Diag(diag::err_drv_unsupported_opt_for_target) + << A->getOption().getName() << TripleStr; + } + // Prepare `-aux-target-cpu` and `-aux-target-feature` unless // `--gpu-use-aux-triple-only` is specified. if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) && diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 50da2f8449a22..3187a5b5c571b 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -163,6 +163,10 @@ struct AssemblerInvocation { LLVM_PREFERRED_TYPE(bool) unsigned EmitCompactUnwindNonCanonical : 1; + // Whether to emit sframe unwind sections. + LLVM_PREFERRED_TYPE(bool) + unsigned EmitSFrameUnwind : 1; + LLVM_PREFERRED_TYPE(bool) unsigned Crel : 1; LLVM_PREFERRED_TYPE(bool) @@ -388,6 +392,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Opts.EmitCompactUnwindNonCanonical = Args.hasArg(OPT_femit_compact_unwind_non_canonical); + Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe); Opts.Crel = Args.hasArg(OPT_crel); Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit); Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no); @@ -450,6 +455,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, MCOptions.MCRelaxAll = Opts.RelaxAll; MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; + MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind; MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels; MCOptions.Crel = Opts.Crel; MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms; `````````` </details> https://github.com/llvm/llvm-project/pull/165322 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
