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/compile: OSX Builds -ldflags processing looks to not include dash character #50662

Closed
karlmutch opened this issue Jan 18, 2022 · 2 comments
Closed

Comments

@karlmutch
Copy link

@karlmutch karlmutch commented Jan 18, 2022

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

go version go1.18beta1 darwin/amd64

Does this issue reproduce with the latest release?

N/A (1.18 Beta1)

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/karlmutch/Library/Caches/go-build"
GOENV="/Users/karlmutch/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/karlmutch/projects/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/karlmutch/projects"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/karlmutch/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/karlmutch/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/karlmutch/projects/src/github.com/xxxxxx/xxx-xxxx/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hv/zjrtcfqs64g1bhyh8wvx919r0000gp/T/go-build3854253269=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Perform a static build using the following

go build -ldflags="-extldflags=static" -tags="osusergo netgo" ./cmd/kvserver

What did you expect to see?

#github.com/shirou/gopsutil/disk
iostat_darwin.c:28:2: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:132:1: note: 'IOMasterPort' has been explicitly marked deprecated here

What did you see instead?

 github.com/shirou/gopsutil/disk
iostat_darwin.c:28:2: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:132:1: note: 'IOMasterPort' has been explicitly marked deprecated here
# github.com/fetchrobotics/sage-kernel/cmd/kvserver
/Users/karlmutch/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
clang: error: no such file or directory: 'static'; did you mean '-static'?
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 18, 2022

The value that you pass as an argument to -extldflags is passed directly to the external linker. You wrote -extldflags=static so the external linker is invoked with static. That doesn't work.

You probably want -extldflags=-static.

@karlmutch
Copy link
Author

@karlmutch karlmutch commented Jan 18, 2022

@ianlancetaylor I had discounted that because of ...

go build -ldflags="-extldflags=-static" -tags="osusergo netgo" ./cmd/kvserver
...
# github.com/fetchrobotics/sage-kernel/cmd/kvserver
/Users/karlmutch/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

That and on my Linux builds the - was not needed. However I could also be conflating the missing C runtime library. Not sure which issue to choose in this case.

Looks like I cannot reopen the ticket, will create a new one related to the missing library as the other alternative I could have chosen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants