Skip to content

Commit 5c34634

Browse files
[sframe] Add assembler option --gsframe
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. With it in place, clang can produce sframe-sections that successfully link with gnu-ld. LLD support is pending some discussion.
1 parent 251edd1 commit 5c34634

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ CODEGENOPT(StackSizeSection , 1, 0, Benign) ///< Set when -fstack-size-section
120120
///< Set when -femit-compact-unwind-non-canonical is enabled.
121121
CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0, Benign)
122122

123+
CODEGENOPT(EmitSFrameUnwind, 1, 0, Benign) ///< Set when -sframe is enabled.
124+
123125
///< Set when -fxray-always-emit-customevents is enabled.
124126
CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0, Benign)
125127

clang/include/clang/Driver/Options.td

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,11 +4701,13 @@ def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">,
47014701
NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
47024702
NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
47034703
MarshallingInfoEnum<CodeGenOpts<"EmitDwarfUnwind">, "Default">;
4704-
defm emit_compact_unwind_non_canonical : BoolFOption<"emit-compact-unwind-non-canonical",
4705-
CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse,
4706-
PosFlag<SetTrue, [], [ClangOption, CC1Option, CC1AsOption],
4707-
"Try emitting Compact-Unwind for non-canonical entries. Maybe overridden by other constraints">,
4708-
NegFlag<SetFalse>>;
4704+
defm emit_compact_unwind_non_canonical
4705+
: BoolFOption<"emit-compact-unwind-non-canonical",
4706+
CodeGenOpts<"EmitCompactUnwindNonCanonical">, DefaultFalse,
4707+
PosFlag<SetTrue, [], [ClangOption, CC1Option, CC1AsOption],
4708+
"Try emitting Compact-Unwind for non-canonical "
4709+
"entries. Maybe overridden by other constraints">,
4710+
NegFlag<SetFalse>>;
47094711
def g_Flag : Flag<["-"], "g">, Group<g_Group>,
47104712
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
47114713
HelpText<"Generate source-level debug information">;
@@ -7729,6 +7731,11 @@ def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
77297731
def crel : Flag<["--"], "crel">,
77307732
HelpText<"Enable CREL relocation format (ELF only)">,
77317733
MarshallingInfoFlag<CodeGenOpts<"Crel">>;
7734+
// The leading 'g' is misleading. This is an unwind tables option, not
7735+
// a debug option. But uses this name for gnu compatibility.
7736+
def gsframe : Flag<["--"], "gsframe">,
7737+
HelpText<"Generate .sframe unwind sections (ELF only)">,
7738+
MarshallingInfoFlag<CodeGenOpts<"EmitSFrameUnwind">>;
77327739
def mmapsyms_implicit : Flag<["-"], "mmapsyms=implicit">,
77337740
HelpText<"Allow mapping symbol at section beginning to be implicit, "
77347741
"lowering number of mapping symbols at the expense of some "

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
500500
Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
501501
Options.MCOptions.EmitCompactUnwindNonCanonical =
502502
CodeGenOpts.EmitCompactUnwindNonCanonical;
503+
Options.MCOptions.EmitSFrameUnwind = CodeGenOpts.EmitSFrameUnwind;
503504
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
504505
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
505506
Options.MCOptions.MCUseDwarfDirectory =

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
26172617
llvm::codegenoptions::DebugInfoConstructor,
26182618
DwarfVersion, llvm::DebuggerKind::Default);
26192619
}
2620+
} else if (Value == "--gsframe") {
2621+
CmdArgs.push_back("--gsframe");
26202622
} else if (Value.starts_with("-mcpu") || Value.starts_with("-mfpu") ||
26212623
Value.starts_with("-mhwdiv") || Value.starts_with("-march")) {
26222624
// Do nothing, we'll validate it later.
@@ -5920,6 +5922,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59205922
else if (UnwindTables)
59215923
CmdArgs.push_back("-funwind-tables=1");
59225924

5925+
// Sframe unwind tables are independent of the other types, and only defined
5926+
// for these two targets.
5927+
if (Arg *A = Args.getLastArg(options::OPT_gsframe)) {
5928+
if ((Triple.isAArch64() || Triple.isX86()) && Triple.isOSBinFormatELF())
5929+
CmdArgs.push_back("--gsframe");
5930+
else
5931+
D.Diag(diag::err_drv_unsupported_opt_for_target)
5932+
<< A->getOption().getName() << TripleStr;
5933+
}
5934+
59235935
// Prepare `-aux-target-cpu` and `-aux-target-feature` unless
59245936
// `--gpu-use-aux-triple-only` is specified.
59255937
if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&

clang/tools/driver/cc1as_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ struct AssemblerInvocation {
163163
LLVM_PREFERRED_TYPE(bool)
164164
unsigned EmitCompactUnwindNonCanonical : 1;
165165

166+
// Whether to emit sframe unwind sections.
167+
LLVM_PREFERRED_TYPE(bool)
168+
unsigned EmitSFrameUnwind : 1;
169+
166170
LLVM_PREFERRED_TYPE(bool)
167171
unsigned Crel : 1;
168172
LLVM_PREFERRED_TYPE(bool)
@@ -388,6 +392,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
388392

389393
Opts.EmitCompactUnwindNonCanonical =
390394
Args.hasArg(OPT_femit_compact_unwind_non_canonical);
395+
Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe);
391396
Opts.Crel = Args.hasArg(OPT_crel);
392397
Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit);
393398
Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
@@ -450,6 +455,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
450455
MCOptions.MCRelaxAll = Opts.RelaxAll;
451456
MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
452457
MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical;
458+
MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind;
453459
MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels;
454460
MCOptions.Crel = Opts.Crel;
455461
MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms;

0 commit comments

Comments
 (0)