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 hasSanitizeFlags := false 13 for _, arg := range builder.args { 14 // TODO: This should probably be -fsanitize= to not match on 15 // e.g. -fsanitize-blocklist 16 if arg.fromUser { 17 if strings.HasPrefix(arg.value, "-fsanitize") { 18 hasSanitizeFlags = true 19 } 20 } 21 } 22 if hasSanitizeFlags { 23 // Flags not supported by sanitizers (ASan etc.) 24 unsupportedSanitizerFlags := map[string]bool{ 25 "-D_FORTIFY_SOURCE=1": true, 26 "-D_FORTIFY_SOURCE=2": true, 27 "-Wl,--no-undefined": true, 28 "-Wl,-z,defs": true, 29 } 30 31 builder.transformArgs(func(arg builderArg) string { 32 // TODO: This is a bug in the old wrapper to not filter 33 // non user args for gcc. Fix this once we don't compare to the old wrapper anymore. 34 if (builder.target.compilerType != gccType || arg.fromUser) && 35 unsupportedSanitizerFlags[arg.value] { 36 return "" 37 } 38 return arg.value 39 }) 40 } 41} 42