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/link: Unable to cross-compile darwin/amd64 PIE on Linux #35831

Closed
Matir opened this issue Nov 25, 2019 · 1 comment
Closed

cmd/link: Unable to cross-compile darwin/amd64 PIE on Linux #35831

Matir opened this issue Nov 25, 2019 · 1 comment

Comments

@Matir
Copy link

Matir commented Nov 25, 2019

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

$ go version
go version go1.13.4 linux/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="/home/matir/.cache/go-build"
GOENV="/home/matir/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/matir/Projects/Go:/usr/share/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/matir/tmp/repro/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/matir/tmp/repro/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build817158144=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ cat test.go                                                                                                          ✘ 2 
package main

import "fmt"

func main() {
	fmt.Println("Hello world!")
}
GOOS=darwin ./go/bin/go build -buildmode=pie -ldflags="-v" ./test.go
# command-line-arguments
HEADER = -H1 -T0x1001000 -R0x1000
 0.00 deadcode
 0.01 symsize = 0
 0.03 pclntab=481762 bytes, funcdata total 114944 bytes
 0.04 dodata
 0.04 symsize = 0
 0.04 symsize = 0
 0.04 dynreloc
 0.04 dwarf
 0.06 asmb
 0.06 codeblk
 0.08 datblk
 0.10 reloc
 0.13 sym
 0.13 headr
 0.19 host link: "gcc" "-m64" "-Wl,-headerpad,1144" "-o" "/tmp/go-build300671719/b001/exe/a.out" "-Wl,--compress-debug-sections=zlib-gnu" "/tmp/go-link-648714504/go.o"
/home/matir/tmp/repro/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find 1144: No such file or directory
/tmp/go-link-648714504/go.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status

What did you expect to see?

A successful build of test.go for Darwin.

What did you see instead?

A failed build due to passing a mac-only flag to gcc on a native host.

@ianlancetaylor
Copy link
Contributor

In order to cross-build a PIE from GNU/Linux to Darwin, you must set CC to a Darwin C cross-compiler, which will need to be able to see a set of Darwin libraries.

@golang golang locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants