-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: regression for supporting PIE on Alpine X86_64 platform #18243
Comments
I find that the root-cause is that go internal link provide a non-existed interpreter for Alpine
if i force using external linker then the issue won't appear
since go is using external linker for PIE before 1.8, i think the issue as a regression. |
If Alpine uses a non-standard path to the dynamic linker, you will need to use |
yes, Alpine uses: |
If at all possible we should avoid adding alpine as a GOOS value. But we could add an environment variable to make.bash to set the default dynamic interpreter, and/or we could add some code to cmd/dist that tries to guess the default dynamic interpreter by compiling and linking a C program and examining the resulting executable. |
sounds doable! it would be good if golang can remove dependence on GCC (i mean after installed) and according development libraries since Alpine is pursuing a small size OS image |
Go doesn't depend on GCC. You can choose to build static binaries, and you don't need GCC to do so. |
Yes, static binaries don't need GCC and I believe Go will finally remove all the dependence on GCC. Go is already trying to remove depend on GCC for X86 platform (such as internal linker for PIE) but for other platforms such as arm64, it still requires external (GCC) linker. Even for Alpine X86 which expects "PIE", Go internal linker has this bug and users have to use GCC linker. |
default-buildmode-pie.patch has been removed since is addressed upstream by golang/go@53aec79 set-external-linker.patch adresses golang/go#18243
Is there any standard that defines the path to the dynamic linker? I would expect that |
@ncopa Standard dynamic linker paths are defined by the ELF ABI Supplement for the relevant processor. I don't know what dynamic linker path Android uses, if any, but as far as I can see the Go cmd/link tool has no special support for choosing a different dynamic linker on Android, other than the previously mentioned -I option. |
default-buildmode-pie.patch has been removed since is addressed upstream by golang/go@53aec79 set-external-linker.patch adresses golang/go#18243
CL https://golang.org/cl/41628 mentions this issue. |
Updates #19938 Updates #18243 Change-Id: Ib6e704c0a5d596bdfaa6493902d2528bec55bf16 Reviewed-on: https://go-review.googlesource.com/41628 Reviewed-by: Ian Lance Taylor <[email protected]>
CL https://golang.org/cl/41675 mentions this issue. |
s/arm64/amd64/ in previous typo CL 41628 Updates #19938 Updates #18243 Change-Id: I282244ee3c94535f229a87b6246382385ff64428 Reviewed-on: https://go-review.googlesource.com/41675 Reviewed-by: Brad Fitzpatrick <[email protected]>
CL https://golang.org/cl/41678 mentions this issue. |
…s on Alpine In an effort to at least understand the complete set of things not working on Alpine Linux, I've been trying to get the build passing again, even with tests disabled. The race detector is broken on Alpine. That is #14481 (and #9918). So disable those tests for now. Also, internal linking with PIE doesn't work on Alpine yet. That is #18243. So disable that test for now. With this CL, all.bash almost passes. There's some cgo test failing still, but there's no bug yet, so that can be a separate CL. Change-Id: I3ffbb0e787ed54cb82f298b6bd5bf3ccfbc82622 Reviewed-on: https://go-review.googlesource.com/41678 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
Updates #18243 Change-Id: I1fe0af65dbd52c3e8e0a245e4cbbdfca100971b4 Reviewed-on: https://go-review.googlesource.com/41759 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]>
CL https://golang.org/cl/41759 mentions this issue. |
CL https://golang.org/cl/41798 mentions this issue. |
Updates golang/go#18243 Change-Id: I76989c3f6b592fb2b68df86c853896f7a2ff7a25 Reviewed-on: https://go-review.googlesource.com/41798 Reviewed-by: Brad Fitzpatrick <[email protected]>
set-external-linker.patch adresses golang/go#18243
set-external-linker.patch adresses golang/go#18243
I think the right fix here is for make.bash to auto-detect the desired default dynamic linker, and pass it in as we currently handle things like |
Not sure if this is the right place to ask this question. I understand the two basic problems with go on Alpine are to get the correct dynamic linker in the executable and to link in the right startup code to read the sysargs correctly. But I don't understand why Alpine wants to default to -buildmode=pie for all executables? It seems like in those cases where golang would build a static executable, that should be OK for Alpine, it is only when golang builds a dynamic executable that it should be building it pie-like. |
Musl supports static PIE executables. We would like to default all executables (dynamic and static) to be PIE. This is due to the fact that ASLR works for main binary only when compiled in PIE mode. |
@ianlancetaylor I can take a crack at it |
how would you want this to change https://github.com/golang/go/blob/master/src/cmd/link/internal/amd64/obj.go#L70 a compile time variable or something? |
@jessfraz I think it would be fine to make that a compile-time variable, along the lines of |
Sweet sounds good I can work on a patch
…On Jul 18, 2017 18:04, "Ian Lance Taylor" ***@***.***> wrote:
@jessfraz <https://github.com/jessfraz> I think it would be fine to make
that a compile-time variable, along the lines of DefaultGOROOT and
friends in cmd/internal/objabi/zbootstrap.go.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18243 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABYNbN2Zcix1xCe8DEDvGpCQWwUnTqBFks5sPSwCgaJpZM4LHq4i>
.
|
CL https://golang.org/cl/50070 mentions this issue. |
@jessfraz Please don't hard code the dynamic linker name in the script as it's architecture specific. And you might want to check for musl c-library instead of alpine linux for wider compatibility. |
Is there a standard way to do that?
…On Jul 19, 2017 15:44, "Timo Teräs" ***@***.***> wrote:
@jessfraz <https://github.com/jessfraz> Please don't hard code the
dynamic linker name in the script as it's architecture specific. And you
might want to check for musl c-library instead of alpine linux for wider
compatibility.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18243 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABYNbEXM-BnKm_tame5GsclBoNI7u65-ks5sPlyxgaJpZM4LHq4i>
.
|
also just curious as to why alpine does not use the default interpreter path? |
Thinking more the issue, if cross-building in Go is to be supported, you really need to know the target specific dynamic linker name. In alpine we patch it currently like: https://git.alpinelinux.org/cgit/aports/tree/community/go/set-external-linker.patch However, it would probably make sense to add a new The default interpreter path is supported via compatibility package
|
@richfelker Maybe you can share insight on the interpreter name choice? |
mark this issue. |
@deanchina, I don't understand. What do you mean by "mark", and who are you addressing? |
@fabled: I'm not sure what exactly you're looking for. The particular name choices are made so as to allow arbitrary arch/ABI combinations to exist in the same root filesystem. This matters especially for machines that support both 32- and 64-bit arch variants (also ILP32-on-64 ones) or multiple ABIs, but it's also intended to support execution of foreign binaries via something like qemu-user+binfmt_misc, or even exotic things like advanced multi-arch kernels on machines with multiple non-same-ISA cpus on the same board sharing memory and process space. As for why it's different from glibc (aside from the above considerations and glibc's naming clashing between archs), it's so you can have both musl and glibc present in the same root fs. "ld-linux" is part of glibc and can't be used with musl, so reusing the same name would have precluded having both installed. |
Add an environment variable to make.bash to allow setting the default dynamic linker/loader. This fixes alpine builds to use /lib/ld-musl-x86_64.so.1: $ ldd ../bin/go /lib/ld-musl-x86_64.so.1 (0x5608dfadd000) libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x5608dfadd000) Also re-enable the internal linker tests that were previously disabled for alpine (CL 41759, CL 41678). Fixes golang#18243 Updates golang#19938 This resurrects CL 50070 which was authored by Jessie Frazelle. Co-authored-by: Jessie Frazelle <[email protected]> Change-Id: I132b5282045a3d60c8568e3b002a7f075eac2d93
Add an environment variable to make.bash to allow setting the default dynamic linker/loader. This fixes alpine builds to use /lib/ld-musl-x86_64.so.1: $ readelf -l ../bin/go | grep 'interpreter:' | sed -e 's/^.*interpreter: \(.*\)[]]/\1/' /lib/ld-musl-x86_64.so.1 Also re-enable the internal linker tests that were previously disabled for alpine (CL 41759, CL 41678). Fixes golang#18243 Updates golang#19938 This resurrects CL 50070 which was authored by Jessie Frazelle. Change-Id: I132b5282045a3d60c8568e3b002a7f075eac2d93
Change https://golang.org/cl/163977 mentions this issue: |
With the current solution, would it be possible to use the same instance of go to cross-compile binaries for different architectures (with different dynamic linkers/loaders)? |
It was pointed out on IRC by kaey that this patch is no longer needed, make.bash has special handling for Alpine nowadays. Just a cleanup change, thus no pkgrel bump. See: golang/go#18243
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8beta1 linux/amd64
What operating system and processor architecture are you using (
go env
)?Alpine X86_64
What did you do?
What did you expect to see?
hello, world
What did you see instead?
sh: ./helloworld: not found
The text was updated successfully, but these errors were encountered: