1
0
mirror of https://github.com/golang/go synced 2024-11-17 23:14:49 -07:00

cmd/link: return correct default linker for the platform

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 <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Mikaël Urankar <mikael.urankar@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
This commit is contained in:
Dmitri Goutnik 2022-09-22 06:59:42 -05:00
parent 8826bdd143
commit 15e26698cc

View File

@ -473,8 +473,16 @@ func loadinternal(ctxt *Link, name string) *sym.Library {
// extld returns the current external linker.
func (ctxt *Link) extld() []string {
if len(flagExtld) == 0 {
// 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
}