From 15e26698cc206661063c07cf7f0353391604001e Mon Sep 17 00:00:00 2001 From: Dmitri Goutnik Date: Thu, 22 Sep 2022 06:59:42 -0500 Subject: [PATCH] cmd/link: return correct default linker for the platform MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If no external linker was passed with -extld, link currently assumes that it is "gcc" which is not correct for platforms that use clang toolchain. Return "clang" for platforms that use it, this fixes dir tests on freebsd/riscv64. For #53466 Change-Id: Ie3bce1b9581839d0b3b2129908355cd30ae9a713 Reviewed-on: https://go-review.googlesource.com/c/go/+/432756 Run-TryBot: Cherry Mui Reviewed-by: Cherry Mui Reviewed-by: Joel Sing Reviewed-by: Mikaël Urankar TryBot-Result: Gopher Robot Reviewed-by: Joedian Reid --- src/cmd/link/internal/ld/lib.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index d971234d87..89bd966f59 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -473,7 +473,15 @@ func loadinternal(ctxt *Link, name string) *sym.Library { // extld returns the current external linker. func (ctxt *Link) extld() []string { if len(flagExtld) == 0 { - flagExtld = []string{"gcc"} + // Return the default external linker for the platform. + // This only matters when link tool is called directly without explicit -extld, + // go tool already passes the correct linker in other cases. + switch buildcfg.GOOS { + case "darwin", "freebsd", "openbsd": + flagExtld = []string{"clang"} + default: + flagExtld = []string{"gcc"} + } } return flagExtld } -- 2.50.0