diff options
Diffstat (limited to 'compiler_wrapper/sanitizer_flags_test.go')
-rw-r--r-- | compiler_wrapper/sanitizer_flags_test.go | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/compiler_wrapper/sanitizer_flags_test.go b/compiler_wrapper/sanitizer_flags_test.go index a401d58e..b4b1fd83 100644 --- a/compiler_wrapper/sanitizer_flags_test.go +++ b/compiler_wrapper/sanitizer_flags_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Copyright 2019 The ChromiumOS Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,28 @@ import ( "testing" ) +func TestFortifyIsKeptIfSanitizerIsTrivial(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=return", "-D_FORTIFY_SOURCE=1", mainCc))) + if err := verifyArgCount(cmd, 1, "-D_FORTIFY_SOURCE=1"); err != nil { + t.Error(err) + } + + cmd = ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=return,address", "-D_FORTIFY_SOURCE=1", mainCc))) + if err := verifyArgCount(cmd, 0, "-D_FORTIFY_SOURCE=1"); err != nil { + t.Error(err) + } + + cmd = ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=address,return", "-D_FORTIFY_SOURCE=1", mainCc))) + if err := verifyArgCount(cmd, 0, "-D_FORTIFY_SOURCE=1"); err != nil { + t.Error(err) + } + }) +} + func TestFilterUnsupportedSanitizerFlagsIfSanitizeGiven(t *testing.T) { withTestContext(t, func(ctx *testContext) { cmd := ctx.must(callCompiler(ctx, ctx.cfg, @@ -23,6 +45,15 @@ func TestFilterUnsupportedSanitizerFlagsIfSanitizeGiven(t *testing.T) { } cmd = ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", "-Wl,-z -Wl,defs", mainCc))) + if err := verifyArgCount(cmd, 0, "-Wl,-z"); err != nil { + t.Error(err) + } + if err := verifyArgCount(cmd, 0, "-Wl,defs"); err != nil { + t.Error(err) + } + + cmd = ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", "-D_FORTIFY_SOURCE=1", mainCc))) if err := verifyArgCount(cmd, 0, "-D_FORTIFY_SOURCE=1"); err != nil { t.Error(err) @@ -75,6 +106,15 @@ func TestKeepSanitizerFlagsIfNoSanitizeGiven(t *testing.T) { } cmd = ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-Wl,-z", "-Wl,defs", mainCc))) + if err := verifyArgCount(cmd, 1, "-Wl,-z"); err != nil { + t.Error(err) + } + if err := verifyArgCount(cmd, 1, "-Wl,defs"); err != nil { + t.Error(err) + } + + cmd = ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, "-D_FORTIFY_SOURCE=1", mainCc))) if err := verifyArgCount(cmd, 1, "-D_FORTIFY_SOURCE=1"); err != nil { t.Error(err) |