golang/go

cmd/link: -race doesn't work by default on FreeBSD with cgo

开放

#73,788 创建于 2025年5月19日

 (6 条评论) (0 个反应) (0 位负责人)Go (19,008 个派生)batch import

仓库指标

星标
 (133,883 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

On our freebsd-amd64 builders (14.2-RELEASE-p2):

package main

/*
int foo(void) { return 42; }
*/
import "C"
import "fmt"

func main() {
        fmt.Println(C.foo())
}
$ go build cgo.go
$ ./cgo
42
$ go build -race cgo.go
$ ./cgo
This sanitizer is not compatible with enabled ASLR and binaries compiled with PIE
$ go build -race -ldflags=-linkmode=internal cgo.go
$ ./cgo
42

i.e., using cgo defaults to external linking, but it seems that external linking breaks -race mode.

cc @golang/freebsd

贡献者指南