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: unknown ARM relocation type 7 when building for Windows arm64 #47758

Closed
dennisameling opened this issue Aug 17, 2021 · 5 comments
Closed
Labels
arch-arm64 FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@dennisameling
Copy link

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

Applies to both cross-compiling from an amd64 host as well as running on arm64 natively
go version go1.17 windows/amd64
go version go1.17 windows/arm64

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
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Dennis\AppData\Local\go-build
set GOENV=C:\Users\Dennis\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Dennis\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Dennis\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Dennis\AppData\Local\Temp\go-build1699668303=/tmp/go-build -gno-record-gcc-switches

What did you do?

git clone https://github.com/dennisameling/git-lfs
git checkout windows-arm64
make GOOS=windows GOARCH=arm64 -B

What did you expect to see?

No error code (build succeeds without errors)

What did you see instead?

$ make GOOS=windows GOARCH=arm64 -B
go generate
GOOS= GOARCH= go generate github.com/git-lfs/git-lfs/commands
GOOS=windows GOARCH=arm64 go build -ldflags="-X github.com/git-lfs/git-lfs/config.GitCommit=8ba10b75 -s -w " -gcflags="all=-trimpath="$HOME" " -asmflags="all=-trimpath="$HOME"" -trimpath -o ./bin/git-lfs.exe
# github.com/git-lfs/git-lfs/v2
C:\Users\Dennis\AppData\Local\go-build\2c\2c8908329c80a83c86a22acb8be7a907d08d2d78f50b5a8274f1522330e51571-d(resource.syso): 241734: unknown ARM64 relocation type 7
make: *** [Makefile:255: bin/git-lfs.exe] Error 2

Please note that I was able to reproduce this both on my amd64 and arm64 Windows machines, as well as in GitHub Actions (building for amd64 and 386 works without problems) https://github.com/dennisameling/git-lfs/runs/3350555869?check_suite_focus=true. I'm happy to provide more details/logs if needed. Thanks in advance!

@andig
Copy link
Contributor

andig commented Aug 18, 2021

FWIW: building on OSX arm64 doesn't error

@mknyszek mknyszek changed the title 241734: unknown ARM relocation type 7 when building for Windows arm64 cmd/link: unknown ARM relocation type 7 when building for Windows arm64 Aug 18, 2021
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 18, 2021
@mknyszek mknyszek added this to the Go1.17.1 milestone Aug 18, 2021
@mknyszek
Copy link
Contributor

This looks like maybe a linker issue to me? CC @cherrymui @thanm

@cherrymui
Copy link
Member

It seems the error is from loading a native object file. Do you have a native object file (like a .syso file) in your build? If so, what does it contain? We currently do not support internal linking on Windows/ARM64, so it doesn't really support linking against a native object. Depending on the specific case, it might be possible to add some limited support.

If you build natively (or have a C cross toolchain available), could you try adding -ldflags=-linkmode=external to use external linking?

cc @rsc

@thanm
Copy link
Contributor

thanm commented Aug 18, 2021

It appears that this project is using

https://github.com/josephspurrier/goversioninfo

which is (according to the comments) based largely on

https://github.com/akavel/rsrc

however from looking at

#42866 (comment)

the best practice is to use LLVM windres (see also comments in https://go-review.googlesource.com/c/go/+/268337 )

@dennisameling
Copy link
Author

Thank you very much for your help. I had a look at https://github.com/josephspurrier/goversioninfo - turns out they added ARM(64) support a few days ago, which has to be activated manually with a flag:

//go:generate goversioninfo -arm=true

After doing that, I was able to build for Windows arm64 successfully 🎉

.\git-lfs.exe
git-lfs/2.13.0 (GitHub; windows arm64; go 1.17)

Sorry for having bothered you with this - really appreciate your help @cherrymui @thanm!

@golang golang locked and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm64 FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

6 participants