aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/sanitizer_flags.go
blob: 1823dcb19b5864aced7323a94ce11c37181d810f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	"strings"
)

func processSanitizerFlags(builder *commandBuilder) {
	filterSanitizerFlags := 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") {
			filterSanitizerFlags = true
			break
		}
	}
	if filterSanitizerFlags {
		// Flags not supported by sanitizers (ASan etc.)
		var unsupportedSanitizerFlags = map[string]bool{
			"-D_FORTIFY_SOURCE=1": true,
			"-D_FORTIFY_SOURCE=2": true,
			"-Wl,--no-undefined":  true,
			"-Wl,-z,defs":         true,
		}

		builder.transformArgs(func(arg builderArg) string {
			if unsupportedSanitizerFlags[arg.value] {
				return ""
			}
			return arg.value
		})
	}
}