diff options
Diffstat (limited to 'compiler_wrapper')
-rwxr-xr-x | compiler_wrapper/build.py | 12 | ||||
-rwxr-xr-x | compiler_wrapper/bundle.py | 15 | ||||
-rw-r--r-- | compiler_wrapper/env.go | 2 | ||||
-rw-r--r-- | compiler_wrapper/go_exec.go | 23 | ||||
-rw-r--r-- | compiler_wrapper/goldenutil_test.go | 12 | ||||
-rw-r--r-- | compiler_wrapper/libc_exec.go | 7 | ||||
-rw-r--r-- | compiler_wrapper/testdata/android_golden/bisect.json | 6 | ||||
-rw-r--r-- | compiler_wrapper/testdata/cros_clang_host_golden/bisect.json | 6 | ||||
-rw-r--r-- | compiler_wrapper/testdata/cros_hardened_golden/bisect.json | 6 | ||||
-rw-r--r-- | compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json | 6 | ||||
-rw-r--r-- | compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json | 6 | ||||
-rw-r--r-- | compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json | 6 | ||||
-rwxr-xr-x | compiler_wrapper/update_compiler_wrapper.sh | 29 |
13 files changed, 99 insertions, 37 deletions
diff --git a/compiler_wrapper/build.py b/compiler_wrapper/build.py index 763b3e64..037b940f 100755 --- a/compiler_wrapper/build.py +++ b/compiler_wrapper/build.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -39,10 +39,16 @@ def calc_go_args(args, version): '-X', 'main.Version=' + version, ] + + # If the wrapper is intended for Chrome OS, we need to use libc's exec. + extra_args = [] + if 'cros' in args.config: + extra_args = ['-tags', 'libc_exec'] + return [ 'go', 'build', '-o', os.path.abspath(args.output_file), '-ldflags', ' '.join(ldFlags) - ] + ] + extra_args def read_version(build_dir): @@ -52,7 +58,7 @@ def read_version(build_dir): return r.read() last_commit_msg = subprocess.check_output( - ['git', '-C', build_dir, 'log', '-1', '--pretty=%B']) + ['git', '-C', build_dir, 'log', '-1', '--pretty=%B'], encoding='utf-8') # Use last found change id to support reverts as well. change_ids = re.findall(r'Change-Id: (\w+)', last_commit_msg) if not change_ids: diff --git a/compiler_wrapper/bundle.py b/compiler_wrapper/bundle.py index c1fa53e0..173625f4 100755 --- a/compiler_wrapper/bundle.py +++ b/compiler_wrapper/bundle.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be @@ -32,7 +32,7 @@ def copy_files(input_dir, output_dir): def read_change_id(input_dir): last_commit_msg = subprocess.check_output( - ['git', '-C', input_dir, 'log', '-1', '--pretty=%B']) + ['git', '-C', input_dir, 'log', '-1', '--pretty=%B'], encoding='utf-8') # Use last found change id to support reverts as well. change_ids = re.findall(r'Change-Id: (\w+)', last_commit_msg) if not change_ids: @@ -41,14 +41,15 @@ def read_change_id(input_dir): def write_readme(input_dir, output_dir, change_id): - with open(os.path.join(input_dir, 'bundle.README'), 'r') as r, \ - open(os.path.join(output_dir, 'README'), 'w') as w: - content = r.read() - w.write(content.format(change_id=change_id)) + with open( + os.path.join(input_dir, 'bundle.README'), 'r', encoding='utf-8') as r: + with open(os.path.join(output_dir, 'README'), 'w', encoding='utf-8') as w: + content = r.read() + w.write(content.format(change_id=change_id)) def write_version(output_dir, change_id): - with open(os.path.join(output_dir, 'VERSION'), 'w') as w: + with open(os.path.join(output_dir, 'VERSION'), 'w', encoding='utf-8') as w: w.write(change_id) diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index 4d83b17a..56b3a913 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -71,7 +71,7 @@ func (env *processEnv) stderr() io.Writer { } func (env *processEnv) exec(cmd *command) error { - return libcExec(env, cmd) + return execCmd(env, cmd) } func (env *processEnv) run(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { diff --git a/compiler_wrapper/go_exec.go b/compiler_wrapper/go_exec.go new file mode 100644 index 00000000..2f2e5ad9 --- /dev/null +++ b/compiler_wrapper/go_exec.go @@ -0,0 +1,23 @@ +// Copyright 2020 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. + +// +build !libc_exec + +package main + +import ( + "os/exec" + "syscall" +) + +// Implement exec for users that don't need to dynamically link with glibc +// See b/144783188 and libc_exec.go. + +func execCmd(env env, cmd *command) error { + execCmd := exec.Command(cmd.Path, cmd.Args...) + mergedEnv := mergeEnvValues(env.environ(), cmd.EnvUpdates) + + ret := syscall.Exec(execCmd.Path, execCmd.Args, mergedEnv) + return newErrorwithSourceLocf("exec error: %v", ret) +} diff --git a/compiler_wrapper/goldenutil_test.go b/compiler_wrapper/goldenutil_test.go index 23e003c5..2b391d73 100644 --- a/compiler_wrapper/goldenutil_test.go +++ b/compiler_wrapper/goldenutil_test.go @@ -14,7 +14,6 @@ import ( "os" "path/filepath" "regexp" - "runtime" "strings" ) @@ -128,6 +127,11 @@ func fillGoldenResults(ctx *testContext, files []goldenFile) []goldenFile { } cmdResult := record.Cmds[len(newCmds)] cmdResult.Cmd = cmd + if numEnvUpdates := len(cmdResult.Cmd.EnvUpdates); numEnvUpdates > 0 { + if strings.HasPrefix(cmdResult.Cmd.EnvUpdates[numEnvUpdates-1], "PYTHONPATH") { + cmdResult.Cmd.EnvUpdates[numEnvUpdates-1] = "PYTHONPATH=/somepath/test_binary" + } + } newCmds = append(newCmds, cmdResult) io.WriteString(stdout, cmdResult.Stdout) io.WriteString(stderr, cmdResult.Stderr) @@ -146,13 +150,7 @@ func fillGoldenResults(ctx *testContext, files []goldenFile) []goldenFile { // Create an empty wrapper at the given path. // Needed as we are resolving symlinks which stats the wrapper file. ctx.writeFile(record.WrapperCmd.Cmd.Path, "") - // Assign a fixed path to os.Args[0] to pass the test. - tmp := os.Args[0] - // callCompiler verifies os.Args[0] exists, so use a real file. - _, file, _, _ := runtime.Caller(1) - os.Args[0] = file record.WrapperCmd.ExitCode = callCompiler(ctx, ctx.cfg, record.WrapperCmd.Cmd) - os.Args[0] = tmp if hasInternalError(ctx.stderrString()) { ctx.t.Errorf("found an internal error for wrapperCmd %#v and env #%v. Got: %s", record.WrapperCmd.Cmd, record.Env, ctx.stderrString()) diff --git a/compiler_wrapper/libc_exec.go b/compiler_wrapper/libc_exec.go index 268221dc..f8db9d86 100644 --- a/compiler_wrapper/libc_exec.go +++ b/compiler_wrapper/libc_exec.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// +build libc_exec + package main // #include <errno.h> @@ -26,7 +28,10 @@ import ( // LD_PRELOAD to work properly (e.g. gentoo sandbox). // Note that this changes the go binary to be a dynamically linked one. // See crbug.com/1000863 for details. -func libcExec(env env, cmd *command) error { +// To use this version of exec, please add '-tags libc_exec' when building Go binary. +// Without the tags, libc_exec.go will be used. + +func execCmd(env env, cmd *command) error { freeList := []unsafe.Pointer{} defer func() { for _, ptr := range freeList { diff --git a/compiler_wrapper/testdata/android_golden/bisect.json b/compiler_wrapper/testdata/android_golden/bisect.json index be07da68..25df7f17 100644 --- a/compiler_wrapper/testdata/android_golden/bisect.json +++ b/compiler_wrapper/testdata/android_golden/bisect.json @@ -27,7 +27,7 @@ "main.cc" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -62,7 +62,7 @@ "main.cc" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -100,7 +100,7 @@ "main.cc" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json b/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json index ad4feac3..28adfee2 100644 --- a/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json +++ b/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json @@ -41,7 +41,7 @@ "-Wno-implicit-int-float-conversion" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -90,7 +90,7 @@ "-Wno-implicit-int-float-conversion" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -142,7 +142,7 @@ "-Wno-implicit-int-float-conversion" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/testdata/cros_hardened_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_golden/bisect.json index 6e1d4981..b00f9740 100644 --- a/compiler_wrapper/testdata/cros_hardened_golden/bisect.json +++ b/compiler_wrapper/testdata/cros_hardened_golden/bisect.json @@ -55,7 +55,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -118,7 +118,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -184,7 +184,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json index 6e1d4981..b00f9740 100644 --- a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json +++ b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json @@ -55,7 +55,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -118,7 +118,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -184,7 +184,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json index 3fafcf01..5075f843 100644 --- a/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json +++ b/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json @@ -50,7 +50,7 @@ "x86_64-cros-linux-gnu" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -108,7 +108,7 @@ "x86_64-cros-linux-gnu" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -169,7 +169,7 @@ "x86_64-cros-linux-gnu" ], "env_updates": [ - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json b/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json index 7d2acdac..cb5dea01 100644 --- a/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json +++ b/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json @@ -47,7 +47,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -102,7 +102,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] } } @@ -160,7 +160,7 @@ "CCACHE_DIR=/var/cache/distfiles/ccache", "CCACHE_UMASK=002", "CCACHE_CPP2=yes", - "PYTHONPATH=/media/storage/jiancai/chromeos/src/third_party/toolchain-utils/compiler_wrapper" + "PYTHONPATH=/somepath/test_binary" ] }, "stdout": "somemessage", diff --git a/compiler_wrapper/update_compiler_wrapper.sh b/compiler_wrapper/update_compiler_wrapper.sh new file mode 100755 index 00000000..93de2be4 --- /dev/null +++ b/compiler_wrapper/update_compiler_wrapper.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# This script rebuilds and installs compiler wrappers + +if [[ ! -e /etc/cros_chroot_version ]]; then + echo "Please run this script inside chroot" + exit 1 +fi +set -e +cd "$(dirname "$(readlink -m "$0")")" +echo "Updated files:" +# Update the host wrapper +./build.py --config=cros.host --use_ccache=false --use_llvm_next=false --output_file=./clang_host_wrapper +sudo mv ./clang_host_wrapper /usr/bin/clang_host_wrapper +echo "/usr/bin/clang_host_wrapper" +sudo cp ../binary_search_tool/bisect_driver.py /usr/bin +echo "/usr/bin/clang_host_wrapper/bisect_driver.py" +# Update the target wrappers +for GCC in cross-x86_64-cros-linux-gnu/gcc cross-armv7a-cros-linux-gnueabihf/gcc cross-aarch64-cros-linux-gnu/gcc; do + FILES="$(equery f $GCC)" + ./build.py --config=cros.hardened --use_ccache=false --use_llvm_next=false --output_file=./sysroot_wrapper.hardened.noccache + sudo mv ./sysroot_wrapper.hardened.noccache "$(grep sysroot_wrapper.hardened.noccache <<< "${FILES}")" + echo "$(grep sysroot_wrapper.hardened.noccache <<< "${FILES}")" + ./build.py --config=cros.hardened --use_ccache=true --use_llvm_next=false --output_file=./sysroot_wrapper.hardened.ccache + sudo mv ./sysroot_wrapper.hardened.ccache "$(grep sysroot_wrapper.hardened.ccache <<< "${FILES}")" + echo "$(grep sysroot_wrapper.hardened.ccache <<< "${FILES}")" + sudo cp ../binary_search_tool/bisect_driver.py "$(grep bisect_driver.py <<< "${FILES}")" + echo "$(grep bisect_driver.py <<< "${FILES}")" +done |