diff options
Diffstat (limited to 'compiler_wrapper/stackprotector_flags_test.go')
-rw-r--r-- | compiler_wrapper/stackprotector_flags_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/compiler_wrapper/stackprotector_flags_test.go b/compiler_wrapper/stackprotector_flags_test.go new file mode 100644 index 00000000..1a50a9b0 --- /dev/null +++ b/compiler_wrapper/stackprotector_flags_test.go @@ -0,0 +1,53 @@ +package main + +import ( + "testing" +) + +func TestAddStrongStackProtectorFlag(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + initStackProtectorStrongConfig(ctx.cfg) + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, mainCc))) + if err := verifyArgOrder(cmd, "-fstack-protector-strong", mainCc); err != nil { + t.Error(err) + } + }) +} + +func TestAddNoStackProtectorFlagWhenKernelDefined(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + initStackProtectorStrongConfig(ctx.cfg) + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-D__KERNEL__", mainCc))) + if err := verifyArgOrder(cmd, "-fno-stack-protector", mainCc); err != nil { + t.Error(err) + } + }) +} + +func TestOmitNoStackProtectorFlagWhenAlreadyInCommonFlags(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + ctx.cfg.commonFlags = []string{"-fno-stack-protector"} + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, mainCc))) + if err := verifyArgCount(cmd, 1, "-fno-stack-protector"); err != nil { + t.Error(err) + } + }) +} + +func TestAddStrongStackProtectorFlagForEabiEvenIfNoStackProtectorGiven(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + initStackProtectorStrongConfig(ctx.cfg) + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64Eabi, "-fno-stack-protector", mainCc))) + if err := verifyArgCount(cmd, 1, "-fstack-protector-strong"); err != nil { + t.Error(err) + } + }) +} + +func initStackProtectorStrongConfig(cfg *config) { + cfg.commonFlags = []string{"-fstack-protector-strong"} +} |