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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"strconv"
)
type config struct {
// Whether to use ccache.
useCCache bool
// Flags to add to gcc and clang.
commonFlags []string
// Flags to add to gcc only.
gccFlags []string
// Flags to add to clang only.
clangFlags []string
// Toolchain root path relative to the wrapper binary.
rootRelPath string
// Path of the old wrapper using the toolchain root.
oldWrapperPath string
// Whether to mock out the calls that the old wrapper does.
mockOldWrapperCmds bool
// Directory to store errors that were prevented with -Wno-error.
newWarningsDir string
}
// UseCCache can be set via a linker flag.
// Value will be passed to strconv.ParseBool.
// E.g. go build -ldflags '-X config.UseCCache=true'.
var UseCCache = "unknown"
// ConfigName can be set via a linker flag.
// Value has to be one of:
// - "cros.hardened"
// - "cros.nonhardened"
var ConfigName = "unknown"
// Returns the configuration matching the UseCCache and ConfigName.
func getRealConfig() (*config, error) {
useCCache, err := strconv.ParseBool(UseCCache)
if err != nil {
return nil, wrapErrorwithSourceLocf(err, "invalid format for UseCCache")
}
config, err := getConfig(useCCache, ConfigName)
if err != nil {
return nil, err
}
return config, nil
}
func getConfig(useCCache bool, configName string) (*config, error) {
switch configName {
case "cros.hardened":
return getCrosHardenedConfig(useCCache), nil
case "cros.nonhardened":
return getCrosNonHardenedConfig(useCCache), nil
default:
return nil, newErrorwithSourceLocf("unknown config name: %s", configName)
}
}
// Full hardening.
func getCrosHardenedConfig(useCCache bool) *config {
// Temporarily disable function splitting because of chromium:434751.
return &config{
useCCache: useCCache,
rootRelPath: "../../../../..",
oldWrapperPath: "./sysroot_wrapper.hardened.old",
commonFlags: []string{
"-fstack-protector-strong",
"-fPIE",
"-pie",
"-D_FORTIFY_SOURCE=2",
"-fno-omit-frame-pointer",
},
gccFlags: []string{
"-fno-reorder-blocks-and-partition",
"-Wno-unused-local-typedefs",
"-Wno-maybe-uninitialized",
},
// Temporarily disable tautological-*-compare chromium:778316.
// Temporarily add no-unknown-warning-option to deal with old clang versions.
// Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
// Disable "-faddrsig" since it produces object files that strip doesn't understand, chromium:915742.
clangFlags: []string{
"-Qunused-arguments",
"-grecord-gcc-switches",
"-fno-addrsig",
"-Wno-tautological-constant-compare",
"-Wno-tautological-unsigned-enum-zero-compare",
"-Wno-unknown-warning-option",
"-Wno-section",
},
newWarningsDir: "/tmp/fatal_clang_warnings",
}
}
// Flags to be added to non-hardened toolchain.
func getCrosNonHardenedConfig(useCCache bool) *config {
return &config{
useCCache: useCCache,
rootRelPath: "../../../../..",
oldWrapperPath: "./sysroot_wrapper.old",
commonFlags: []string{},
gccFlags: []string{
"-Wno-maybe-uninitialized",
"-Wno-unused-local-typedefs",
"-Wno-deprecated-declarations",
"-Wtrampolines",
},
// Temporarily disable tautological-*-compare chromium:778316.
// Temporarily add no-unknown-warning-option to deal with old clang versions.
// Temporarily disable Wsection since kernel gets a bunch of these. chromium:778867
clangFlags: []string{
"-Qunused-arguments",
"-Wno-tautological-constant-compare",
"-Wno-tautological-unsigned-enum-zero-compare",
"-Wno-unknown-warning-option",
"-Wno-section",
},
newWarningsDir: "/tmp/fatal_clang_warnings",
}
}
|