1// Copyright 2019 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package main 6 7import ( 8 "strings" 9) 10 11func processSanitizerFlags(builder *commandBuilder) { 12 hasCoverageFlags := false 13 hasSanitizeFlags := false 14 hasSanitizeFuzzerFlags := false 15 for _, arg := range builder.args { 16 // TODO: This should probably be -fsanitize= to not match on 17 // e.g. -fsanitize-blacklist 18 if arg.fromUser { 19 if strings.HasPrefix(arg.value, "-fsanitize") { 20 hasSanitizeFlags = true 21 if strings.Contains(arg.value, "fuzzer") { 22 hasSanitizeFuzzerFlags = true 23 } 24 } else if arg.value == "-fprofile-instr-generate" { 25 hasCoverageFlags = true 26 } 27 } 28 } 29 if hasSanitizeFlags { 30 // Flags not supported by sanitizers (ASan etc.) 31 unsupportedSanitizerFlags := map[string]bool{ 32 "-D_FORTIFY_SOURCE=1": true, 33 "-D_FORTIFY_SOURCE=2": true, 34 "-Wl,--no-undefined": true, 35 "-Wl,-z,defs": true, 36 } 37 38 builder.transformArgs(func(arg builderArg) string { 39 // TODO: This is a bug in the old wrapper to not filter 40 // non user args for gcc. Fix this once we don't compare to the old wrapper anymore. 41 if (builder.target.compilerType != gccType || arg.fromUser) && 42 unsupportedSanitizerFlags[arg.value] { 43 return "" 44 } 45 return arg.value 46 }) 47 if builder.target.compilerType == clangType { 48 // hasSanitizeFlags && hasCoverageFlags is to work around crbug.com/1013622 49 if hasSanitizeFuzzerFlags || (hasSanitizeFlags && hasCoverageFlags) { 50 fuzzerFlagsToAdd := []string{ 51 // TODO: This flag should be removed once fuzzer works with new pass manager 52 "-fno-experimental-new-pass-manager", 53 } 54 builder.addPreUserArgs(fuzzerFlagsToAdd...) 55 } 56 } 57 } 58} 59