diff options
author | Tobias Bosch <tbosch@google.com> | 2019-06-20 17:47:19 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-06-25 14:47:26 +0000 |
commit | aa31116c1d7c2491245604f0564e0693f22dfd71 (patch) | |
tree | 4fd8fb92a9a459bb718f8d0c943a05632defbd08 /compiler_wrapper/config.go | |
parent | b9992bba3b4e752f10410c624a500762d090fa2b (diff) | |
download | toolchain-utils-aa31116c1d7c2491245604f0564e0693f22dfd71.tar.gz |
Allow to pass in the use_ccache via go build.
Removes usage of go build tags in favor of passing in
configuration via -ldflags -X ...
BUG=chromium:773875
TEST=unit test
Change-Id: I4e8a58e1679b2858e9d4620d6b9c7a35ad08a6ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1670987
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper/config.go')
-rw-r--r-- | compiler_wrapper/config.go | 146 |
1 files changed, 97 insertions, 49 deletions
diff --git a/compiler_wrapper/config.go b/compiler_wrapper/config.go index 909edf0a..1e78fbef 100644 --- a/compiler_wrapper/config.go +++ b/compiler_wrapper/config.go @@ -1,6 +1,13 @@ package main +import ( + "fmt" + "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. @@ -14,57 +21,98 @@ type config struct { overrideOldWrapperConfig bool } +// 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, fmt.Errorf("Parse error for UseCCache: %s", err) + } + 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, fmt.Errorf("Unknown config name: %s", configName) + } +} + // Full hardening. -// Temporarily disable function splitting because of chromium:434751. -var crosHardenedConfig = config{ - rootRelPath: "../../../../..", - oldWrapperPath: "./sysroot_wrapper.hardened.old", - commonFlags: []string{ - "-fPIE", - "-D_FORTIFY_SOURCE=2", - "-fstack-protector-strong", - "-pie", - "-fno-omit-frame-pointer", - }, - gccFlags: []string{ - "-Wno-unused-local-typedefs", - "-Wno-maybe-uninitialized", - "-fno-reorder-blocks-and-partition", - }, - // 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{ - "-Wno-tautological-unsigned-enum-zero-compare", - "-Qunused-arguments", - "-grecord-gcc-switches", - "-Wno-section", - "-Wno-unknown-warning-option", - "-fno-addrsig", - "-Wno-tautological-constant-compare", - }, +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{ + "-fPIE", + "-D_FORTIFY_SOURCE=2", + "-fstack-protector-strong", + "-pie", + "-fno-omit-frame-pointer", + }, + gccFlags: []string{ + "-Wno-unused-local-typedefs", + "-Wno-maybe-uninitialized", + "-fno-reorder-blocks-and-partition", + }, + // 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{ + "-Wno-tautological-unsigned-enum-zero-compare", + "-Qunused-arguments", + "-grecord-gcc-switches", + "-Wno-section", + "-Wno-unknown-warning-option", + "-fno-addrsig", + "-Wno-tautological-constant-compare", + }, + } } // Flags to be added to non-hardened toolchain. -var crosNonHardenedConfig = config{ - rootRelPath: "../../../../..", - oldWrapperPath: "./sysroot_wrapper.old", - commonFlags: []string{}, - gccFlags: []string{ - "-Wno-unused-local-typedefs", - "-Wno-maybe-uninitialized", - "-Wtrampolines", - "-Wno-deprecated-declarations", - }, - // 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{ - "-Wno-unknown-warning-option", - "-Qunused-arguments", - "-Wno-section", - "-Wno-tautological-unsigned-enum-zero-compare", - "-Wno-tautological-constant-compare", - }, +func getCrosNonHardenedConfig(useCCache bool) *config { + return &config{ + useCCache: useCCache, + rootRelPath: "../../../../..", + oldWrapperPath: "./sysroot_wrapper.old", + commonFlags: []string{}, + gccFlags: []string{ + "-Wno-unused-local-typedefs", + "-Wno-maybe-uninitialized", + "-Wtrampolines", + "-Wno-deprecated-declarations", + }, + // 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{ + "-Wno-unknown-warning-option", + "-Qunused-arguments", + "-Wno-section", + "-Wno-tautological-unsigned-enum-zero-compare", + "-Wno-tautological-constant-compare", + }, + } } |