aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-14 15:15:21 -0700
committerTobias Bosch <tbosch@google.com>2019-08-15 22:43:02 +0000
commit47f580fe94bc41a39c010559c78d918d6fabc2db (patch)
tree647875f5d14254992055c299de93490218e459b1
parent5fa6d24a85e04ee967f277369ba3714a4a6efe3b (diff)
downloadtoolchain-utils-47f580fe94bc41a39c010559c78d918d6fabc2db.tar.gz
Pass the old wrapper path as a linker argument
BUG=chromium:773875 TEST=unit test and comparison to old wrapper Change-Id: I97cff81f2b42a01f82ba66668693b17a27c14672 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1754130 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
-rwxr-xr-xcompiler_wrapper/build.py4
-rw-r--r--compiler_wrapper/bundle.README3
-rw-r--r--compiler_wrapper/config.go26
-rw-r--r--compiler_wrapper/config_test.go18
-rw-r--r--compiler_wrapper/cros_hardened_config_test.go6
-rw-r--r--compiler_wrapper/cros_host_config_test.go8
-rw-r--r--compiler_wrapper/cros_nonhardened_config_test.go4
-rw-r--r--compiler_wrapper/main.go2
-rw-r--r--compiler_wrapper/testutil_test.go8
9 files changed, 53 insertions, 26 deletions
diff --git a/compiler_wrapper/build.py b/compiler_wrapper/build.py
index 33259281..40e8aa64 100755
--- a/compiler_wrapper/build.py
+++ b/compiler_wrapper/build.py
@@ -21,6 +21,7 @@ def parse_args():
required=True,
choices=['cros.hardened', 'cros.nonhardened', 'cros.host'])
parser.add_argument('--use_ccache', required=True, choices=['true', 'false'])
+ parser.add_argument('--old_wrapper_path', required=True)
parser.add_argument('--output_file', required=True, type=str)
return parser.parse_args()
@@ -30,7 +31,8 @@ def calc_go_args(args):
# build a fully static binary in go.
ldFlags = [
'-X', 'main.ConfigName=' + args.config, '-X',
- 'main.UseCCache=' + args.use_ccache, "-extldflags '-static'"
+ 'main.UseCCache=' + args.use_ccache, '-X',
+ 'main.OldWrapperPath=' + args.old_wrapper_path, "-extldflags '-static'"
]
return [
'go', 'build', '-o',
diff --git a/compiler_wrapper/bundle.README b/compiler_wrapper/bundle.README
index a969d934..530d04ea 100644
--- a/compiler_wrapper/bundle.README
+++ b/compiler_wrapper/bundle.README
@@ -5,7 +5,8 @@ found in the LICENSE file.
Toolchain utils compiler wrapper sources.
Build the wrapper:
-./build --config=<config name> --use_ccache=<bool> --output_file=<file>
+./build --config=<config name> --use_ccache=<bool> \
+ --old_wrapper_path=<path> --output_file=<file>
ATTENTION:
The files in this folder are generated. Do not modify manually!
diff --git a/compiler_wrapper/config.go b/compiler_wrapper/config.go
index 7567d0e2..70d08c15 100644
--- a/compiler_wrapper/config.go
+++ b/compiler_wrapper/config.go
@@ -29,6 +29,10 @@ type config struct {
newWarningsDir string
}
+// OldWrapperPath can be set via a linker flag.
+// Value fills config.oldWrapperPath.
+var OldWrapperPath = ""
+
// UseCCache can be set via a linker flag.
// Value will be passed to strconv.ParseBool.
// E.g. go build -ldflags '-X config.UseCCache=true'.
@@ -46,33 +50,33 @@ func getRealConfig() (*config, error) {
if err != nil {
return nil, wrapErrorwithSourceLocf(err, "invalid format for UseCCache")
}
- config, err := getConfig(useCCache, ConfigName)
+ config, err := getConfig(useCCache, ConfigName, OldWrapperPath)
if err != nil {
return nil, err
}
return config, nil
}
-func getConfig(useCCache bool, configName string) (*config, error) {
+func getConfig(useCCache bool, configName string, oldWrapperPath string) (*config, error) {
switch configName {
case "cros.hardened":
- return getCrosHardenedConfig(useCCache), nil
+ return getCrosHardenedConfig(useCCache, oldWrapperPath), nil
case "cros.nonhardened":
- return getCrosNonHardenedConfig(useCCache), nil
+ return getCrosNonHardenedConfig(useCCache, oldWrapperPath), nil
case "cros.host":
- return getCrosHostConfig(), nil
+ return getCrosHostConfig(oldWrapperPath), nil
default:
return nil, newErrorwithSourceLocf("unknown config name: %s", configName)
}
}
// Full hardening.
-func getCrosHardenedConfig(useCCache bool) *config {
+func getCrosHardenedConfig(useCCache bool, oldWrapperPath string) *config {
// Temporarily disable function splitting because of chromium:434751.
return &config{
useCCache: useCCache,
rootRelPath: "../../../../..",
- oldWrapperPath: "./sysroot_wrapper.hardened.old",
+ oldWrapperPath: oldWrapperPath,
commonFlags: []string{
"-fstack-protector-strong",
"-fPIE",
@@ -104,11 +108,11 @@ func getCrosHardenedConfig(useCCache bool) *config {
}
// Flags to be added to non-hardened toolchain.
-func getCrosNonHardenedConfig(useCCache bool) *config {
+func getCrosNonHardenedConfig(useCCache bool, oldWrapperPath string) *config {
return &config{
useCCache: useCCache,
rootRelPath: "../../../../..",
- oldWrapperPath: "./sysroot_wrapper.old",
+ oldWrapperPath: oldWrapperPath,
commonFlags: []string{},
gccFlags: []string{
"-Wno-maybe-uninitialized",
@@ -132,12 +136,12 @@ func getCrosNonHardenedConfig(useCCache bool) *config {
}
// Flags to be added to host toolchain.
-func getCrosHostConfig() *config {
+func getCrosHostConfig(oldWrapperPath string) *config {
return &config{
isHostWrapper: true,
useCCache: false,
rootRelPath: "../..",
- oldWrapperPath: "./host_wrapper.old",
+ oldWrapperPath: oldWrapperPath,
commonFlags: []string{},
gccFlags: []string{
"-Wno-maybe-uninitialized",
diff --git a/compiler_wrapper/config_test.go b/compiler_wrapper/config_test.go
index 6b2deff7..bdcf5069 100644
--- a/compiler_wrapper/config_test.go
+++ b/compiler_wrapper/config_test.go
@@ -77,6 +77,23 @@ func TestRealConfigWithConfigNameFlag(t *testing.T) {
}
}
+func TestRealConfigWithOldWrapperPath(t *testing.T) {
+ resetGlobals()
+ defer resetGlobals()
+ UseCCache = "false"
+ ConfigName = "cros.hardened"
+
+ OldWrapperPath = "somepath"
+
+ cfg, err := getRealConfig()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if cfg.oldWrapperPath != "somepath" {
+ t.Fatalf("OldWrapperPath: Expected somepath, got %s", cfg.oldWrapperPath)
+ }
+}
+
func isSysrootHardened(cfg *config) bool {
for _, arg := range cfg.commonFlags {
if arg == "-pie" {
@@ -88,6 +105,7 @@ func isSysrootHardened(cfg *config) bool {
func resetGlobals() {
// Set all global variables to a defined state.
+ OldWrapperPath = ""
ConfigName = "unknown"
UseCCache = "unknown"
}
diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go
index 5ae2f7e1..b87320b5 100644
--- a/compiler_wrapper/cros_hardened_config_test.go
+++ b/compiler_wrapper/cros_hardened_config_test.go
@@ -14,14 +14,14 @@ import (
"testing"
)
-const oldHardenedWrapperPathForTest = "/usr/x86_64-pc-linux-gnu/x86_64-cros-linux-gnu/gcc-bin/4.9.x/sysroot_wrapper.hardened"
+const oldHardenedWrapperPathForTest = "$CHROOT/usr/x86_64-pc-linux-gnu/x86_64-cros-linux-gnu/gcc-bin/4.9.x/sysroot_wrapper.hardened"
const crosHardenedGoldenDir = "testdata/cros_hardened_golden"
const crosHardenedNoCCacheGoldenDir = "testdata/cros_hardened_noccache_golden"
func TestCrosHardenedConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := true
- ctx.updateConfig(oldHardenedWrapperPathForTest, getCrosHardenedConfig(useCCache))
+ ctx.updateConfig(getCrosHardenedConfig(useCCache, oldHardenedWrapperPathForTest))
runGoldenRecords(ctx, crosHardenedGoldenDir, createSyswrapperGoldenInputs(ctx))
})
@@ -30,7 +30,7 @@ func TestCrosHardenedConfig(t *testing.T) {
func TestCrosHardenedConfigWithoutCCache(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := false
- ctx.updateConfig(oldHardenedWrapperPathForTest, getCrosHardenedConfig(useCCache))
+ ctx.updateConfig(getCrosHardenedConfig(useCCache, oldHardenedWrapperPathForTest))
// Create a copy of the old wrapper where the CCACHE_DEFAULT is false.
if ctx.cfg.oldWrapperPath != "" {
diff --git a/compiler_wrapper/cros_host_config_test.go b/compiler_wrapper/cros_host_config_test.go
index a68cedd7..61f1b867 100644
--- a/compiler_wrapper/cros_host_config_test.go
+++ b/compiler_wrapper/cros_host_config_test.go
@@ -9,14 +9,14 @@ import (
"testing"
)
-const oldClangHostWrapperPathForTest = "/usr/bin/clang_host_wrapper"
-const oldGccHostWrapperPathForTest = "../src/third_party/chromiumos-overlay/sys-devel/gcc/files/host_wrapper"
+const oldClangHostWrapperPathForTest = "$CHROOT/usr/bin/clang_host_wrapper"
+const oldGccHostWrapperPathForTest = "$CHROOT/../src/third_party/chromiumos-overlay/sys-devel/gcc/files/host_wrapper"
const crosClangHostGoldenDir = "testdata/cros_clang_host_golden"
const crosGccHostGoldenDir = "testdata/cros_gcc_host_golden"
func TestCrosClangHostConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
- ctx.updateConfig(oldClangHostWrapperPathForTest, getCrosHostConfig())
+ ctx.updateConfig(getCrosHostConfig(oldClangHostWrapperPathForTest))
gomaPath := path.Join(ctx.tempDir, "gomacc")
ctx.writeFile(gomaPath, "")
@@ -39,7 +39,7 @@ func TestCrosClangHostConfig(t *testing.T) {
func TestCrosGccHostConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
- ctx.updateConfig(oldGccHostWrapperPathForTest, getCrosHostConfig())
+ ctx.updateConfig(getCrosHostConfig(oldGccHostWrapperPathForTest))
gomaPath := path.Join(ctx.tempDir, "gomacc")
ctx.writeFile(gomaPath, "")
diff --git a/compiler_wrapper/cros_nonhardened_config_test.go b/compiler_wrapper/cros_nonhardened_config_test.go
index 41e3d7c9..e876d309 100644
--- a/compiler_wrapper/cros_nonhardened_config_test.go
+++ b/compiler_wrapper/cros_nonhardened_config_test.go
@@ -8,13 +8,13 @@ import (
"testing"
)
-const oldNonHardenedWrapperPathForTest = "/usr/x86_64-pc-linux-gnu/arm-none-eabi/gcc-bin/4.9.x/sysroot_wrapper"
+const oldNonHardenedWrapperPathForTest = "$CHROOT/usr/x86_64-pc-linux-gnu/arm-none-eabi/gcc-bin/4.9.x/sysroot_wrapper"
const crosNonHardenedGoldenDir = "testdata/cros_nonhardened_golden"
func TestCrosNonHardenedConfig(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
useCCache := true
- ctx.updateConfig(oldNonHardenedWrapperPathForTest, getCrosNonHardenedConfig(useCCache))
+ ctx.updateConfig(getCrosNonHardenedConfig(useCCache, oldNonHardenedWrapperPathForTest))
runGoldenRecords(ctx, crosNonHardenedGoldenDir, createSyswrapperGoldenInputs(ctx))
})
diff --git a/compiler_wrapper/main.go b/compiler_wrapper/main.go
index 780e9155..3fcf3a66 100644
--- a/compiler_wrapper/main.go
+++ b/compiler_wrapper/main.go
@@ -6,6 +6,8 @@
// - main.UseCCache: Whether to use ccache.
// - main.ConfigName: Name of the configuration to use.
// See config.go for the supported values.
+// - main.OldWrapperPath: Path to the old wrapper to compare commands
+// against. Comparison is deactivated if empty.
//
// The script ./build simplifies the call to `go build`.
// E.g. ./build --use_ccache=true --config=cros.hardened will build a
diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go
index fa321a07..0dbf817e 100644
--- a/compiler_wrapper/testutil_test.go
+++ b/compiler_wrapper/testutil_test.go
@@ -58,7 +58,7 @@ func withTestContext(t *testing.T, work func(ctx *testContext)) {
env: nil,
cfg: &config{},
}
- ctx.updateConfig("", &config{})
+ ctx.updateConfig(&config{})
work(&ctx)
}
@@ -140,12 +140,12 @@ func (ctx *testContext) mustFail(exitCode int) string {
return ctx.stderrString()
}
-func (ctx *testContext) updateConfig(wrapperChrootPath string, cfg *config) {
+func (ctx *testContext) updateConfig(cfg *config) {
*ctx.cfg = *cfg
ctx.cfg.mockOldWrapperCmds = true
ctx.cfg.newWarningsDir = filepath.Join(ctx.tempDir, "fatal_clang_warnings")
- if *crosRootDirFlag != "" && wrapperChrootPath != "" {
- ctx.cfg.oldWrapperPath = filepath.Join(*crosRootDirFlag, wrapperChrootPath)
+ if *crosRootDirFlag != "" && ctx.cfg.oldWrapperPath != "" {
+ ctx.cfg.oldWrapperPath = strings.Replace(ctx.cfg.oldWrapperPath, "$CHROOT", *crosRootDirFlag, -1)
} else {
ctx.cfg.oldWrapperPath = ""
}