From 0b35a803185c813dee854b1ee12591a8dec2a7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 30 Nov 2022 10:38:18 +0200 Subject: [PATCH] go link: use external linker when in race mode 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. --- go/private/actions/link.bzl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/go/private/actions/link.bzl b/go/private/actions/link.bzl index 0a2207ddd..28c84696d 100644 --- a/go/private/actions/link.bzl +++ b/go/private/actions/link.bzl @@ -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,