-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link, cmd/dist: wrong loader/interpreter used with cross-compiled toolchain for ppc64le #53813
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
Comments
Could you show the commands you run for building and copying the toolchain? Is it just |
I did GOOS=linux GOARCH=ppc64le ./make.bash on the x86 host. |
Thanks. During make.bash, cmd/dist writes The linker already does not use cmd/dist also writes in internal/buildcfg/zbootstrap.go |
This doesn't need to target Go 1.19. I think it needs more work to ship a cross-compiled binary release, and we're probably not going to do it for Go 1.19. |
On a related note, I noticed this line in cmd/link/internal/ppc64/obj.go:
This is wrong for ppc64le, which is what the default should be since linux/ppc64 doesn't generate pie or dynamic binaries. It didn't seem worthy of its own issue since it has always been this way so this field must never be used, but it should still contain the correct string. It could be fixed along with the fix for this issue in Go 1.20. Probably when using the external linker the interpreter is set in a different way, and that's the way pies were generated up until @pmur s recent changes to the internal linker. |
@laboger thanks. Yes, this should be fixed. Feel free to send a CL. What should it be? This string is still used in some cases, for example, when cross compiling (not with a cross-compiled toolchain, but like |
The C cross toolchain on my machine uses |
Yes, it should be 2 since ppc64le is ELF v2. I can create a CL. |
Change https://go.dev/cl/417614 mentions this issue: |
Thanks for the CL for the default. I just ran into the GO_LDSO cross-compilation issue too, and I'm going to send a general fix for Go 1.20. |
The setting of the path for the dynamic loader when building for linux/ppc64le ELF v2 was incorrectly set to the path for PPC64 ELF v1. This has not caused issues in the common cases because this string can be set based on the default GO_LDSO setting. It does result in an incorrect value when cross compiling binaries with -buildmode=pie. Updates #53813 Change-Id: I84de1c97b42e0434760b76a57c5a05e055fbb730 Reviewed-on: https://go-review.googlesource.com/c/go/+/417614 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
The setting of the path for the dynamic loader when building for linux/ppc64le ELF v2 was incorrectly set to the path for PPC64 ELF v1. This has not caused issues in the common cases because this string can be set based on the default GO_LDSO setting. It does result in an incorrect value when cross compiling binaries with -buildmode=pie. Updates golang#53813 Change-Id: I84de1c97b42e0434760b76a57c5a05e055fbb730 Reviewed-on: https://go-review.googlesource.com/c/go/+/417614 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
With #54197, if you don't explicitly set GO_LDSO when running make.bash, the resulting linker will use |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Built a cross toolchain on x86 host targeting ppc64le. By default CGO_ENABLED=0 for cross builds.
Moved the toolchain to a ppc64le machine. Many tests work fine except those that use -buildmode=pie. In those cases the test fails.
What did you expect to see?
Tests using -buildmode=pie work.
What did you see instead?
$ go build -buildmode=pie hello.go
$ ./hello
bash: ./hello: No such file or directory
$ file hello
hello: ELF 64-bit LSB shared object, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, with debug_info, not stripped
Same result if I set GO_LDSO=/libd64/ld64.so.2 before the go build command above.
If I set GO_LDSO=/lib64/ld64.so.2 when building the cross toolchain then it uses the correct path to the loader.
Also, if I build a cross compiled toolchain with a cross gcc on the build machine and set CGO_ENABLED=1, then the go binary is built dynamic but is unusable for the same reason.. With CGO_ENABLED=0, the go binary is static so doesn't have that problem.
The text was updated successfully, but these errors were encountered: