golang/go

cmd/link: cannot cross compile a linux plugin on macOS

Open

#22,462 创建于 2017年10月27日

在 GitHub 查看
 (18 评论) (10 反应) (0 负责人)Go (19,008 fork)batch import
DocumentationNeedsFixOS-Darwincompiler/runtimehelp wanted

仓库指标

Star
 (133,883 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

macOS Sierra 10.12.6 with latest Xcode 9.0.1 and Command Line Tools installed.

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mmazurskiy/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fh/7zp6kdcj3rgdd_7_nmw439_st0zyrt/T/go-build968645272=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

func Process() {
}
GOOS=linux go build -buildmode=plugin -i -v -o build/bin/p1 github.com/atlassian/smith/cmd/p1
github.com/atlassian/smith/cmd/p1
# github.com/atlassian/smith/cmd/p1
warning: unable to find runtime/cgo.a
/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
GOOS=linux go build -buildmode=plugin -i -v -ldflags="-v" -o build/bin/p1 github.com/atlassian/smith/cmd/p1
github.com/atlassian/smith/cmd/p1
# github.com/atlassian/smith/cmd/p1
HEADER = -H4 -T0x401000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime.a in /usr/local/Cellar/go/1.9.2/libexec/pkg/linux_amd64_dynlink/runtime.a
searching for runtime/cgo.a in $WORK/runtime/cgo.a
searching for runtime/cgo.a in /usr/local/Cellar/go/1.9.2/libexec/pkg/linux_amd64_dynlink/runtime/cgo.a
warning: unable to find runtime/cgo.a
 0.00 deadcode
 0.01 pclntab=165547 bytes, funcdata total 31135 bytes
 0.01 dodata
 0.01 dwarf
 0.01 symsize = 0
 0.02 reloc
 0.02 asmb
 0.02 codeblk
 0.02 rodatblk
 0.02 datblk
 0.02 sym
 0.02 symsize = 22368
 0.02 symsize = 102000
 0.02 dwarf
 0.03 headr
 0.03 host link: "clang" "-m64" "-gdwarf-2" "-Wl,-z,relro" "-shared" "-Wl,-znow" "-Wl,-znocopyreloc" "-o" "/var/folders/fh/7zp6kdcj3rgdd_7_nmw439_st0zyrt/T/go-build232503875/github.com/atlassian/smith/cmd/p1/_obj/exe/a.out.so" "-rdynamic" "-Qunused-arguments" "/var/folders/fh/7zp6kdcj3rgdd_7_nmw439_st0zyrt/T/go-link-110686925/go.o"
/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

With explicit CGO_ENABLED=1 I get:

CGO_ENABLED=1 GOOS=linux go build -buildmode=plugin -i -v -ldflags="-v" -o build/bin/p1 github.com/atlassian/smith/cmd/p1
runtime/cgo
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What did you expect to see?

Successfully compiled plugin.

What did you see instead?

Failures.

贡献者指南