aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/sanitizer_flags_test.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-11-13 00:20:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-11-13 00:20:25 +0000
commit517424dcc11380511bc34f4a081f119104ff9e80 (patch)
tree77dc031614745bb406dbd90cea9a082a1b5cdd54 /compiler_wrapper/sanitizer_flags_test.go
parent4d310bf178aa94bdc46c1b86b9937312ddac644a (diff)
parent40214b48188358a80b7478bfff21d4814dd9177c (diff)
downloadtoolchain-utils-android14-platform-release.tar.gz
Change-Id: I709f9d23cce32c5c2c81fc2d5869983d17b416ed
Diffstat (limited to 'compiler_wrapper/sanitizer_flags_test.go')
-rw-r--r--compiler_wrapper/sanitizer_flags_test.go42
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)