From c08e01d98e72f2e9dffd73a7fd3d011f2a251ac9 Mon Sep 17 00:00:00 2001 From: Manoj Gupta Date: Fri, 11 Oct 2019 10:49:21 -0700 Subject: compiler_wrapper: Disable new pass manager with sanitizers+coverage. Useing sanitizers and coverage together in new pass manager causes clang to crash. Avoid the crash by disabling new pass manager in these cases. BUG=chromium:1013622 TEST=go test Change-Id: Ifc787e9f288891e3e1b68c791f0ddaa508d8c816 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1856379 Tested-by: Manoj Gupta Reviewed-by: George Burgess --- compiler_wrapper/cros_hardened_config_test.go | 12 ++ compiler_wrapper/sanitizer_flags.go | 26 ++-- compiler_wrapper/sanitizer_flags_test.go | 31 +++++ .../clang_sanitizer_args.json | 99 ++++++++++++++ .../cros_hardened_golden/clang_sanitizer_args.json | 145 +++++++++++++++++++++ .../cros_hardened_golden/gcc_sanitizer_args.json | 119 +++++++++++++++++ .../clang_sanitizer_args.json | 123 +++++++++++++++++ .../gcc_sanitizer_args.json | 107 +++++++++++++++ 8 files changed, 653 insertions(+), 9 deletions(-) diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go index 16e51358..10d8bf6f 100644 --- a/compiler_wrapper/cros_hardened_config_test.go +++ b/compiler_wrapper/cros_hardened_config_test.go @@ -515,6 +515,18 @@ func createSanitizerGoldenInputs(compiler string) goldenFile { WrapperCmd: newGoldenCmd(wrapperPath, "-fsanitize=fuzzer", mainCc), Cmds: okResults, }, + { + WrapperCmd: newGoldenCmd(wrapperPath, "-fsanitize=address", "-fprofile-instr-generate", mainCc), + Cmds: okResults, + }, + { + WrapperCmd: newGoldenCmd(wrapperPath, "-fsanitize=address", mainCc), + Cmds: okResults, + }, + { + WrapperCmd: newGoldenCmd(wrapperPath, "-fprofile-instr-generate", mainCc), + Cmds: okResults, + }, }, } } diff --git a/compiler_wrapper/sanitizer_flags.go b/compiler_wrapper/sanitizer_flags.go index 32f2cb78..fe8d1503 100644 --- a/compiler_wrapper/sanitizer_flags.go +++ b/compiler_wrapper/sanitizer_flags.go @@ -9,15 +9,20 @@ import ( ) func processSanitizerFlags(builder *commandBuilder) { + hasCoverageFlags := false hasSanitizeFlags := false hasSanitizeFuzzerFlags := false for _, arg := range builder.args { // TODO: This should probably be -fsanitize= to not match on // e.g. -fsanitize-blacklist - if arg.fromUser && strings.HasPrefix(arg.value, "-fsanitize") { - hasSanitizeFlags = true - if strings.Contains(arg.value, "fuzzer") { - hasSanitizeFuzzerFlags = true + if arg.fromUser { + if strings.HasPrefix(arg.value, "-fsanitize") { + hasSanitizeFlags = true + if strings.Contains(arg.value, "fuzzer") { + hasSanitizeFuzzerFlags = true + } + } else if arg.value == "-fprofile-instr-generate" { + hasCoverageFlags = true } } } @@ -39,12 +44,15 @@ func processSanitizerFlags(builder *commandBuilder) { } return arg.value }) - if hasSanitizeFuzzerFlags && builder.target.compilerType == clangType { - fuzzerFlagsToAdd := []string{ - // TODO: This flag should be removed once fuzzer works with new pass manager - "-fno-experimental-new-pass-manager", + if builder.target.compilerType == clangType { + // hasSanitizeFlags && hasCoverageFlags is to work around crbug.com/1013622 + if hasSanitizeFuzzerFlags || (hasSanitizeFlags && hasCoverageFlags) { + fuzzerFlagsToAdd := []string{ + // TODO: This flag should be removed once fuzzer works with new pass manager + "-fno-experimental-new-pass-manager", + } + builder.addPreUserArgs(fuzzerFlagsToAdd...) } - builder.addPreUserArgs(fuzzerFlagsToAdd...) } } } diff --git a/compiler_wrapper/sanitizer_flags_test.go b/compiler_wrapper/sanitizer_flags_test.go index 741f7732..8f50a900 100644 --- a/compiler_wrapper/sanitizer_flags_test.go +++ b/compiler_wrapper/sanitizer_flags_test.go @@ -119,3 +119,34 @@ func TestOmitFuzzerFlagsForGcc(t *testing.T) { } }) } + +func TestAddSanitizerCoverageFlagsForClang(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(clangX86_64, "-fsanitize=address", "-fprofile-instr-generate", mainCc))) + if err := verifyArgOrder(cmd, "-fno-experimental-new-pass-manager", + "-fsanitize=address", "-fprofile-instr-generate", mainCc); err != nil { + t.Error(err) + } + }) +} + +func TestOmitSanitizerCoverageFlagsForClang(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(clangX86_64, "-fsanitize=address", mainCc))) + if err := verifyArgCount(cmd, 0, "-fno-experimental-new-pass-manager"); err != nil { + t.Error(err) + } + }) +} + +func TestKeepSanitizerCoverageFlagsForClang(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(clangX86_64, "-fprofile-instr-generate", mainCc))) + if err := verifyArgCount(cmd, 0, "-fno-experimental-new-pass-manager"); err != nil { + t.Error(err) + } + }) +} diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/clang_sanitizer_args.json b/compiler_wrapper/testdata/cros_clang_host_golden/clang_sanitizer_args.json index 7e7e54c0..be1a2922 100644 --- a/compiler_wrapper/testdata/cros_clang_host_golden/clang_sanitizer_args.json +++ b/compiler_wrapper/testdata/cros_clang_host_golden/clang_sanitizer_args.json @@ -163,5 +163,104 @@ } } ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/tmp/stable/clang", + "args": [ + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-fuse-ld=lld", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-fno-experimental-new-pass-manager", + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/tmp/stable/clang", + "args": [ + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-fuse-ld=lld", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-fsanitize=address", + "main.cc" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/tmp/stable/clang", + "args": [ + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-fuse-ld=lld", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-fprofile-instr-generate", + "main.cc" + ] + } + } + ] } ] diff --git a/compiler_wrapper/testdata/cros_hardened_golden/clang_sanitizer_args.json b/compiler_wrapper/testdata/cros_hardened_golden/clang_sanitizer_args.json index 9fa1f4f2..39094948 100644 --- a/compiler_wrapper/testdata/cros_hardened_golden/clang_sanitizer_args.json +++ b/compiler_wrapper/testdata/cros_hardened_golden/clang_sanitizer_args.json @@ -238,5 +238,150 @@ } } ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fuse-ld=lld", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-fno-omit-frame-pointer", + "-fno-experimental-new-pass-manager", + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fuse-ld=lld", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-fno-omit-frame-pointer", + "-fsanitize=address", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-grecord-gcc-switches", + "-fno-addrsig", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fuse-ld=lld", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-D_FORTIFY_SOURCE=2", + "-fno-omit-frame-pointer", + "-fprofile-instr-generate", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] } ] diff --git a/compiler_wrapper/testdata/cros_hardened_golden/gcc_sanitizer_args.json b/compiler_wrapper/testdata/cros_hardened_golden/gcc_sanitizer_args.json index bddac1d2..a63aa25c 100644 --- a/compiler_wrapper/testdata/cros_hardened_golden/gcc_sanitizer_args.json +++ b/compiler_wrapper/testdata/cros_hardened_golden/gcc_sanitizer_args.json @@ -197,5 +197,124 @@ } } ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-fno-reorder-blocks-and-partition", + "-Wno-unused-local-typedefs", + "-Wno-maybe-uninitialized", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-D_FORTIFY_SOURCE=2", + "-fno-omit-frame-pointer", + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fsanitize=address", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-fno-reorder-blocks-and-partition", + "-Wno-unused-local-typedefs", + "-Wno-maybe-uninitialized", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-D_FORTIFY_SOURCE=2", + "-fno-omit-frame-pointer", + "-fsanitize=address", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-fno-reorder-blocks-and-partition", + "-Wno-unused-local-typedefs", + "-Wno-maybe-uninitialized", + "-fstack-protector-strong", + "-fPIE", + "-pie", + "-D_FORTIFY_SOURCE=2", + "-fno-omit-frame-pointer", + "-fprofile-instr-generate", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] } ] diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/clang_sanitizer_args.json b/compiler_wrapper/testdata/cros_nonhardened_golden/clang_sanitizer_args.json index 05209ee3..386e82d6 100644 --- a/compiler_wrapper/testdata/cros_nonhardened_golden/clang_sanitizer_args.json +++ b/compiler_wrapper/testdata/cros_nonhardened_golden/clang_sanitizer_args.json @@ -203,5 +203,128 @@ } } ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fno-experimental-new-pass-manager", + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fsanitize=address", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fsanitize=address", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-clang", + "args": [ + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "../../usr/bin/clang", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Qunused-arguments", + "-Wno-tautological-constant-compare", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-unknown-warning-option", + "-Wno-section", + "-static-libgcc", + "-fprofile-instr-generate", + "main.cc", + "-B../../bin", + "-target", + "x86_64-cros-linux-gnu" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002", + "CCACHE_CPP2=yes" + ] + } + } + ] } ] diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/gcc_sanitizer_args.json b/compiler_wrapper/testdata/cros_nonhardened_golden/gcc_sanitizer_args.json index 639dc524..7091f608 100644 --- a/compiler_wrapper/testdata/cros_nonhardened_golden/gcc_sanitizer_args.json +++ b/compiler_wrapper/testdata/cros_nonhardened_golden/gcc_sanitizer_args.json @@ -177,5 +177,112 @@ } } ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Wno-maybe-uninitialized", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wtrampolines", + "-fsanitize=address", + "-fprofile-instr-generate", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fsanitize=address", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Wno-maybe-uninitialized", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wtrampolines", + "-fsanitize=address", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] + }, + { + "wd": "/tmp/stable", + "wrapper": { + "cmd": { + "path": "./x86_64-cros-linux-gnu-gcc", + "args": [ + "-fprofile-instr-generate", + "main.cc" + ] + } + }, + "cmds": [ + { + "cmd": { + "path": "/usr/bin/ccache", + "args": [ + "./x86_64-cros-linux-gnu-gcc.real", + "--sysroot=/usr/x86_64-cros-linux-gnu", + "-Wno-maybe-uninitialized", + "-Wno-unused-local-typedefs", + "-Wno-deprecated-declarations", + "-Wtrampolines", + "-fprofile-instr-generate", + "main.cc", + "-mno-movbe" + ], + "env_updates": [ + "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu", + "CCACHE_DIR=/var/cache/distfiles/ccache", + "CCACHE_UMASK=002" + ] + } + } + ] } ] -- cgit v1.2.3