Skip to content

Commit 4daf792

Browse files
mknyszekgopherbot
authored andcommitted
cmd/link/internal/ld: work around FreeBSD 14.1 cmd/cgo test link failure
On FreeBSD 14.1 we fail to link against C code with internal linking. The symptom is apparently undefined symbols, but explicitly pointing the linker at compiler-rt for -libgcc fixes the issue. This looks a lot like the workaround on OpenBSD, but the symptom is different. --print-libgcc-file-name produces libclang_rt.builtins-x86_64.a which appears to be an insufficient subset of libcompiler_rt.a. For #61095. Change-Id: Iff5affbc923d69c89d671a69d8f4ecaadac42177 Cq-Include-Trybots: luci.golang.try:gotip-freebsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/go/+/632975 Auto-Submit: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent bdedc5c commit 4daf792

File tree

1 file changed

+7
-0
lines changed
  • src/cmd/link/internal/ld

1 file changed

+7
-0
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ func (ctxt *Link) loadlib() {
632632
if *flagLibGCC == "" {
633633
*flagLibGCC = ctxt.findLibPathCmd("--print-libgcc-file-name", "libgcc")
634634
}
635+
if runtime.GOOS == "freebsd" && strings.HasPrefix(filepath.Base(*flagLibGCC), "libclang_rt.builtins") {
636+
// On newer versions of FreeBSD, libgcc is returned as something like
637+
// /usr/lib/clang/18/lib/freebsd/libclang_rt.builtins-x86_64.a.
638+
// Unfortunately this ends up missing a bunch of symbols we need from
639+
// libcompiler_rt.
640+
*flagLibGCC = ctxt.findLibPathCmd("--print-file-name=libcompiler_rt.a", "libcompiler_rt")
641+
}
635642
if runtime.GOOS == "openbsd" && *flagLibGCC == "libgcc.a" {
636643
// On OpenBSD `clang --print-libgcc-file-name` returns "libgcc.a".
637644
// In this case we fail to load libgcc.a and can encounter link

0 commit comments

Comments
 (0)