Skip to content

Commit

Permalink
go link: use external linker when in race mode
Browse files Browse the repository at this point in the history
As of clang 15.0.3 (via zig v0.10), when building with `race = "on"` on
x86_64 Linux, we observe the following:

    runtime/cgo(.text): relocation target memset not defined

Using an external linker when in race mode fixes that. Previously
`linkmode=external` was set for windows-only race builds, now lets just
apply it indiscriminately.

From my past experience, reporting a Go linker error when the external
linker works has a high chance to get the ticket closed as unactionable;
so it makes sense to just use an external linker, when it works.
  • Loading branch information
motiejus committed Nov 30, 2022
1 parent 7b72c4f commit 08b5b9e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions go/private/actions/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ def emit_link(
tool_args.add("-msan")
if ((go.mode.static and not go.mode.pure) or
go.mode.link != LINKMODE_NORMAL or
go.mode.goos == "windows" and (go.mode.race or go.mode.msan)):
go.mode.race or
go.mode.goos == "windows" and go.mode.msan)):
# Force external linking for the following conditions:
# * Mode is static but not pure: -static must be passed to the C
# linker if the binary contains cgo code. See #2168, #2216.
# * Non-normal build mode: may not be strictly necessary, especially
# for modes like "pie".
# * Race or msan build for Windows: Go linker has pairwise
# incompatibilities with mingw, and we get link errors in race mode.
# Using the C linker avoids that. Race and msan always require a
# a C toolchain. See #2614.
# * Msan build for Windows: Go linker has pairwise incompatibilities
# with mingw. Using the C linker avoids that. Race and msan always
# require a C toolchain. See #2614.
# * Race builds (previously Windows, later +linux): we get linker
# errors during build with Go's internal linker.
tool_args.add("-linkmode", "external")
if go.mode.pure:
# Force internal linking in pure mode. We don't have a C toolchain,
Expand Down

0 comments on commit 08b5b9e

Please sign in to comment.