Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hermetic toolchain linking before Go 1.21 #3692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions go/private/mode.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def extld_from_cc_toolchain(go):
if not go.cgo_tools:
return []
elif go.mode.link in (LINKMODE_SHARED, LINKMODE_PLUGIN, LINKMODE_C_SHARED, LINKMODE_PIE):
return ["-extld", go.cgo_tools.ld_dynamic_lib_path]
# NOTE: Use '=' to help distinguish between `extld` and `extldflags` in
# cgoAbsLinkFlags.
return ["-extld=" + go.cgo_tools.ld_dynamic_lib_path]
elif go.mode.link == LINKMODE_C_ARCHIVE:
if go.mode.goos in ["darwin", "ios"]:
# TODO(jayconrod): on macOS, set -extar. At this time, wrapped_ar is
Expand All @@ -255,4 +257,6 @@ def extld_from_cc_toolchain(go):
# on macOS, Bazel returns wrapped_ar, which is not executable.
# /usr/bin/ar (the default) should be visible though, and we have a
# hack in link.go to strip out non-reproducible stuff.
return ["-extld", go.cgo_tools.ld_executable_path]
# NOTE: Use '=' to help distinguish between `extld` and `extldflags` in
# cgoAbsLinkFlags.
return ["-extld=" + go.cgo_tools.ld_executable_path]
5 changes: 5 additions & 0 deletions go/tools/builders/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var (
cgoEnvVars = []string{"CGO_CFLAGS", "CGO_CXXFLAGS", "CGO_CPPFLAGS", "CGO_LDFLAGS"}
// cgoAbsEnvFlags are all the flags that need absolute path in cgoEnvVars
cgoAbsEnvFlags = []string{"-I", "-L", "-isysroot", "-isystem", "-iquote", "-include", "-gcc-toolchain", "--sysroot", "-resource-dir", "-fsanitize-blacklist", "-fsanitize-ignorelist"}
// cgoAbsLinkFlags are all the flags in the generated link command that need absolute paths.
// Need absolute path for -extld because of https://github.com/golang/go/issues/59952.
// Can be reverted after dropping support for Go versions older than 1.21.0.
// Also see note for `-extld=` vs `-extld` in go/private/mode.bzl.
cgoAbsLinkFlags = []string{"-extld="}
)

// env holds a small amount of Go environment and toolchain information
Expand Down
1 change: 1 addition & 0 deletions go/tools/builders/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func link(args []string) error {
if err != nil {
return err
}
absArgs(args, cgoAbsLinkFlags)
builderArgs, toolArgs := splitArgs(args)
stamps := multiFlag{}
xdefs := multiFlag{}
Expand Down