diff options
author | George Burgess IV <gbiv@google.com> | 2023-07-11 09:41:31 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-07-12 08:12:23 +0000 |
commit | 25005ff0c8b6e4ce30f4f934c420a3b7411c64ee (patch) | |
tree | 716b650734033f0df2b0f7b97d05f74bf42d63b4 | |
parent | c283de4032ddc8acda707bce5b18ab48c7008143 (diff) | |
download | toolchain-utils-25005ff0c8b6e4ce30f4f934c420a3b7411c64ee.tar.gz |
compiler_wrapper: add flag to skip automatic sysroot logic
Adding `--sysroot` and the implicit library path here breaks glibc's
build when `llvm-libunwind` is installed. Since glibc is a special
package, it seems OK to let it own its own destiny WRT gathering the
proper includes & linking to libraries properly.
BUG=b:290144273
TEST=emerge glibc
Change-Id: I4f814b39334147631a0fdcb67ad1f0e067e1d674
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/4678360
Reviewed-by: Jordan Abrahams-Whitehead <ajordanr@google.com>
Tested-by: George Burgess <gbiv@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
-rw-r--r-- | compiler_wrapper/sysroot_flag.go | 24 | ||||
-rw-r--r-- | compiler_wrapper/sysroot_flag_test.go | 26 |
2 files changed, 47 insertions, 3 deletions
diff --git a/compiler_wrapper/sysroot_flag.go b/compiler_wrapper/sysroot_flag.go index 597153a9..0256abcd 100644 --- a/compiler_wrapper/sysroot_flag.go +++ b/compiler_wrapper/sysroot_flag.go @@ -9,19 +9,37 @@ import ( "strings" ) +const skipSysrootAutodetectionFlag = "--cros-skip-wrapper-sysroot-autodetection" + func processSysrootFlag(builder *commandBuilder) { + hadSkipSysrootMagicFlag := false fromUser := false userSysroot := "" - for _, arg := range builder.args { - if arg.fromUser && strings.HasPrefix(arg.value, "--sysroot=") { + builder.transformArgs(func(arg builderArg) string { + switch { + // In rare cases (e.g., glibc), we want all sysroot autodetection logic to be + // disabled. This flag can be passed to disable that. + case arg.value == skipSysrootAutodetectionFlag: + hadSkipSysrootMagicFlag = true + return "" + + case arg.fromUser && strings.HasPrefix(arg.value, "--sysroot="): fromUser = true sysrootArg := strings.Split(arg.value, "=") if len(sysrootArg) == 2 { userSysroot = sysrootArg[1] } - break + return arg.value + + default: + return arg.value } + }) + + if hadSkipSysrootMagicFlag { + return } + sysroot, syrootPresent := builder.env.getenv("SYSROOT") if syrootPresent { builder.updateEnv("SYSROOT=") diff --git a/compiler_wrapper/sysroot_flag_test.go b/compiler_wrapper/sysroot_flag_test.go index 9fea6848..bca8d1b0 100644 --- a/compiler_wrapper/sysroot_flag_test.go +++ b/compiler_wrapper/sysroot_flag_test.go @@ -6,9 +6,35 @@ package main import ( "path" + "regexp" "testing" ) +func TestOmitSysrootGivenSysrootSuppressionFlag(t *testing.T) { + escapedAutodetectionFlag := regexp.QuoteMeta(skipSysrootAutodetectionFlag) + withTestContext(t, func(ctx *testContext) { + runWithCompiler := func(compiler string) { + cmd := ctx.must(callCompiler(ctx, ctx.cfg, + ctx.newCommand(compiler, skipSysrootAutodetectionFlag, mainCc))) + if err := verifyArgOrder(cmd, mainCc); err != nil { + t.Error(err) + } + if err := verifyArgCount(cmd, 0, "--sysroot.*"); err != nil { + t.Error(err) + } + if err := verifyArgCount(cmd, 0, "-L.*"); err != nil { + t.Error(err) + } + if err := verifyArgCount(cmd, 0, escapedAutodetectionFlag); err != nil { + t.Error(err) + } + } + + runWithCompiler(gccX86_64) + runWithCompiler(clangX86_64) + }) +} + func TestOmitSysrootGivenUserDefinedSysroot(t *testing.T) { withTestContext(t, func(ctx *testContext) { runWithCompiler := func(compiler string) { |