Skip to content

Commit f5e625a

Browse files
committed
IRGen: move the EnableStackProtector option from IRGenOptions to SILOptions.
... because we need it in the SIL pass pipeline, too. Also, add Swift bridging for that option.
1 parent a49dc5d commit f5e625a

File tree

9 files changed

+24
-13
lines changed

9 files changed

+24
-13
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ import OptimizerBridging
1414

1515
struct Options {
1616
let _bridged: BridgedPassContext
17+
18+
var enableStackProtection: Bool {
19+
SILOptions_enableStackProtection(_bridged) != 0
20+
}
1721
}

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ enum class ReflectionMetadataMode : unsigned {
9494
Runtime, ///< Make reflection metadata fully available.
9595
};
9696

97-
enum class StackProtectorMode : bool { NoStackProtector, StackProtector };
98-
9997
using clang::PointerAuthSchema;
10098

10199
struct PointerAuthOptions : clang::PointerAuthOptions {
@@ -285,8 +283,6 @@ class IRGenOptions {
285283
/// Whether we should run swift specific LLVM optimizations after IRGen.
286284
unsigned DisableSwiftSpecificLLVMOptzns : 1;
287285

288-
unsigned EnableStackProtector : 1;
289-
290286
/// Special codegen for playgrounds.
291287
unsigned Playground : 1;
292288

@@ -464,7 +460,7 @@ class IRGenOptions {
464460
DebugInfoFormat(IRGenDebugInfoFormat::None),
465461
DisableClangModuleSkeletonCUs(false), UseJIT(false),
466462
DisableLLVMOptzns(false), DisableSwiftSpecificLLVMOptzns(false),
467-
EnableStackProtector(false), Playground(false),
463+
Playground(false),
468464
EmitStackPromotionChecks(false), UseSingleModuleLLVMEmission(false),
469465
FunctionSections(false), PrintInlineTree(false),
470466
EmbedMode(IRGenEmbedMode::None), LLVMLTOKind(IRGenLLVMLTOKind::None),
@@ -550,9 +546,6 @@ class IRGenOptions {
550546
bool hasMultipleIRGenThreads() const { return !UseSingleModuleLLVMEmission && NumThreads > 1; }
551547
bool shouldPerformIRGenerationInParallel() const { return !UseSingleModuleLLVMEmission && NumThreads != 0; }
552548
bool hasMultipleIGMs() const { return hasMultipleIRGenThreads(); }
553-
StackProtectorMode getStackProtectorMode() const {
554-
return StackProtectorMode(EnableStackProtector);
555-
}
556549
};
557550

558551
} // end namespace swift

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class SILOptions {
128128
/// Enables experimental performance annotations.
129129
bool EnablePerformanceAnnotations = false;
130130

131+
/// Enables the emission of stack protectors in functions.
132+
bool EnableStackProtection = false;
133+
131134
/// Controls whether or not paranoid verification checks are run.
132135
bool VerifyAll = false;
133136

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ PassContext_nextDefaultWitnessTableInModule(BridgedDefaultWitnessTable table);
184184
OptionalBridgedFunction
185185
PassContext_loadFunction(BridgedPassContext context, llvm::StringRef name);
186186

187+
SwiftInt SILOptions_enableStackProtection(BridgedPassContext context);
188+
187189
SWIFT_END_NULLABILITY_ANNOTATIONS
188190

189191
#endif

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
17621762
}
17631763
Opts.EnablePerformanceAnnotations |=
17641764
Args.hasArg(OPT_ExperimentalPerformanceAnnotations);
1765+
Opts.EnableStackProtection =
1766+
Args.hasFlag(OPT_enable_stack_protector, OPT_disable_stack_protector,
1767+
Opts.EnableStackProtection);
17651768
Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
17661769
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
17671770
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
@@ -2410,10 +2413,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
24102413
OPT_enable_new_llvm_pass_manager,
24112414
Opts.LegacyPassManager);
24122415

2413-
Opts.EnableStackProtector =
2414-
Args.hasFlag(OPT_enable_stack_protector, OPT_disable_stack_protector,
2415-
Opts.EnableStackProtector);
2416-
24172416
return false;
24182417
}
24192418

lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,9 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded(
32013201
}
32023202

32033203
StackProtectorMode IRGenModule::shouldEmitStackProtector(SILFunction *f) {
3204-
return IRGen.Opts.getStackProtectorMode();
3204+
const SILOptions &opts = IRGen.SIL.getOptions();
3205+
return (opts.EnableStackProtection) ?
3206+
StackProtectorMode::StackProtector : StackProtectorMode::NoStackProtector;
32053207
}
32063208

32073209
/// Find the entry point for a SIL function.

lib/IRGen/IRGen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace irgen {
4444
/// store vectors of spare bits.
4545
using SpareBitVector = ClusteredBitVector;
4646

47+
enum class StackProtectorMode : bool { NoStackProtector, StackProtector };
48+
4749
class Size;
4850

4951
enum IsPOD_t : bool { IsNotPOD, IsPOD };

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,3 +1633,8 @@ PassContext_loadFunction(BridgedPassContext context, StringRef name) {
16331633
SILFunction *f = mod->loadFunction(name, SILModule::LinkingMode::LinkNormal);
16341634
return {f};
16351635
}
1636+
1637+
SwiftInt SILOptions_enableStackProtection(BridgedPassContext context) {
1638+
SILModule *mod = castToPassInvocation(context)->getPassManager()->getModule();
1639+
return mod->getOptions().EnableStackProtection;
1640+
}

tools/sil-opt/SILOpt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ int main(int argc, char **argv) {
598598
SILOpts.OptRecordPasses = RemarksPasses;
599599
SILOpts.checkSILModuleLeaks = true;
600600
SILOpts.EnablePerformanceAnnotations = true;
601+
SILOpts.EnableStackProtection = true;
601602

602603
SILOpts.VerifyExclusivity = VerifyExclusivity;
603604
if (EnforceExclusivity.getNumOccurrences() != 0) {

0 commit comments

Comments
 (0)