cmd/link: add more clang driver flags when testing flag

This changes does 2 things:

- Move `-L` to `prefixesToKeep` since it allows providing a custom
default libs search path.

- Allow various flags that impact the behaviour of the clang driver.

The latter allows for LLVM only toolchains to be compatible with
linkerFlagSupported checks.

The end goal of this PR is to allow fully hermetic toolchains,
especially pure LLVM ones, to be used to cross-compile CGO.

Fixes #76825

Change-Id: I2311c9566ce9c7e8f6b325258af58eb333663cf0
GitHub-Last-Rev: 74342aae35
GitHub-Pull-Request: golang/go#76858
Reviewed-on: https://go-review.googlesource.com/c/go/+/730561
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Corentin Kerisit 2025-12-16 23:53:01 +00:00 committed by Gopher Robot
parent b8bccb9798
commit 99d7121934

View file

@ -2208,20 +2208,30 @@ func trimLinkerArgv(argv []string) []string {
flagsWithNextArgSkip := []string{
"-F",
"-l",
"-L",
"-framework",
"-Wl,-framework",
"-Wl,-rpath",
"-Wl,-undefined",
}
flagsWithNextArgKeep := []string{
"-B",
"-L",
"-arch",
"-isysroot",
"--sysroot",
"-target",
"--target",
"-resource-dir",
"-rtlib",
"--rtlib",
"-stdlib",
"--stdlib",
"-unwindlib",
"--unwindlib",
}
prefixesToKeep := []string{
"-B",
"-L",
"-f",
"-m",
"-p",
@ -2231,6 +2241,13 @@ func trimLinkerArgv(argv []string) []string {
"--sysroot",
"-target",
"--target",
"-resource-dir",
"-rtlib",
"--rtlib",
"-stdlib",
"--stdlib",
"-unwindlib",
"--unwindlib",
}
var flags []string