Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go command rejects references to .tbd files #44263

Closed
kevinAlbs opened this issue Feb 15, 2021 · 2 comments
Closed

cmd/go: go command rejects references to .tbd files #44263

kevinAlbs opened this issue Feb 15, 2021 · 2 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kevinAlbs
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.15.8 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kevin.albertson/Library/Caches/go-build"
GOENV="/Users/kevin.albertson/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kevin.albertson/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kevin.albertson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pv/p1jss0l97mq0ddr7rjbcbdt00000gp/T/go-build829854566=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am using cgo to link to a dylib with pkg-config.

$ brew install dlib
$ pkg-config --cflags --libs dlib-1
-I/usr/local/Cellar/dlib/19.21/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -L/usr/local/Cellar/dlib/19.21/lib -ldlib /usr/local/lib/libpng.dylib /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libz.tbd /usr/local/lib/libjpeg.dylib /usr/local/opt/openblas/lib/libopenblas.dylib /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libsqlite3.tbd

My cgo program attempts to link to it as follows:

// dlib.go
package dlib

// #cgo pkg-config: dlib-1
import "C"

The linker inputs /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libz.tbd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libsqlite3.tbd are rejected:

$ go build -o dlib dlib.go
go build command-line-arguments: invalid flag in pkg-config --libs: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libz.tbd

The dylib specifies a dependency on a .tbd file, which is a macOS text based stub-library, and describes the interface to a dylib or framework. I can work around this by specifying the environment variable CGO_LDFLAGS_ALLOW='^.*tbd$'.

Since it is a valid input to the linker, I think the allow-list for linker flags could add tbd to the list of permitted direct inputs. If that sounds reasonable, I'd be more than happy to submit a PR with a test.

@seankhliao seankhliao changed the title cgo does not accept tbd linker inputs on macOS cmd/link: cgo does not accept tbd linker inputs on macOS Feb 15, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 15, 2021
@ianlancetaylor ianlancetaylor changed the title cmd/link: cgo does not accept tbd linker inputs on macOS cmd/go: go command rejects references to .tbd files Feb 15, 2021
@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 15, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Feb 15, 2021
@ianlancetaylor
Copy link
Contributor

The file to fix is cmd/go/internal/work/security.go.

@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 15, 2021
kevinAlbs added a commit to kevinAlbs/go that referenced this issue Feb 15, 2021
A .tbd file is a macOS text-based stub library and is a valid input to
the macOS linker. This change adds .tbd to the allow-list for acceptable
linker flags.

Fixes golang#44263
@gopherbot
Copy link

Change https://golang.org/cl/292269 mentions this issue: cmd/go: permit .tbd files as a linker flag

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants