-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: support PIE when using the external linker #6940
Comments
do you any special setup? I was puzzled by the fact that those tests used the external linking mode. you can take a look at the source code embedded in pkg/runtime/crash_cgo_test.go, and copy them out and "go run" them to see you can reproduce the problem. Status changed to WaitingForReply. |
Well, can reproduce the problem with that embedded code. $ go build 3.go # command-line-arguments /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/go-link-Nhb93l/go.o: relocation R_X86_64_32 against `type.*' can not be used when making a shared object; recompile with -fPIC /var/tmp/go-link-Nhb93l/go.o: could not read symbols: Bad value collect2: error: ld returned 1 exit status /home/peter/projects/go/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit status 0x100 About environment: this is hardened gentoo linux. Portage 2.2.7 (hardened/linux/amd64, gcc-4.7.3, glibc-2.17, 3.11.7-hardened x86_64) ================================================================= System uname: Linux-3.11.7-hardened-x86_64-Intel-R-_Core-TM-_i7-3520M_CPU_@_2.90GHz-with-gentoo-2.2 KiB Mem: 16291304 total, 1754736 free ld GNU ld (GNU Binutils) 2.23.1 app-shells/bash: 4.2_p45 dev-java/java-config: 2.1.12-r1 dev-lang/python: 2.7.5-r3, 3.2.5-r3, 3.3.3 dev-util/cmake: 2.8.11.2 sys-apps/baselayout: 2.2 sys-apps/openrc: 0.12.4 sys-apps/sandbox: 2.6-r1 sys-devel/autoconf: 2.13, 2.69 sys-devel/automake: 1.10.3, 1.11.6, 1.13.4, 1.14 sys-devel/binutils: 2.23.1 sys-devel/gcc: 4.4.7, 4.5.4, 4.7.3-r1 sys-devel/gcc-config: 1.7.3 sys-devel/libtool: 2.4.2 sys-devel/make: 3.82-r4 sys-kernel/linux-headers: 3.9 (virtual/os-headers) sys-libs/glibc: 2.17 If you need I can try to create you relatively small chroot with this problem reproduced, or point me and I'll try to do what I can. Unfortunately ATM I don't understand this external linkage working. Attachments:
|
That's true, pie is enabled by default. It's not visible in the output though becase it's defined in spec. $ go build -x 3.go WORK=/tmp/go-build510371387 mkdir -p $WORK/command-line-arguments/_obj/ cd /tmp /home/peter/projects/go/go/pkg/tool/linux_amd64/cgo -objdir ./go-build510371387/command-line-arguments/_obj/ -- -I ./go-build510371387/command-line-arguments/_obj/ 3.go /home/peter/projects/go/go/pkg/tool/linux_amd64/6c -F -V -w -I ./go-build510371387/command-line-arguments/_obj/ -I /home/peter/projects/go/go/pkg/linux_amd64 -o ./go-build510371387/command-line-arguments/_obj/_cgo_defun.6 -D GOOS_linux -D GOARCH_amd64 ./go-build510371387/command-line-arguments/_obj/_cgo_defun.c gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -print-libgcc-file-name gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -I ./go-build510371387/command-line-arguments/_obj/ -o ./go-build510371387/command-line-arguments/_obj/_cgo_main.o -c ./go-build510371387/command-line-arguments/_obj/_cgo_main.c gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -I ./go-build510371387/command-line-arguments/_obj/ -o ./go-build510371387/command-line-arguments/_obj/_cgo_export.o -c ./go-build510371387/command-line-arguments/_obj/_cgo_export.c gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -I ./go-build510371387/command-line-arguments/_obj/ -o ./go-build510371387/command-line-arguments/_obj/3.cgo2.o -c ./go-build510371387/command-line-arguments/_obj/3.cgo2.c gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -o ./go-build510371387/command-line-arguments/_obj/_cgo_.o ./go-build510371387/command-line-arguments/_obj/_cgo_main.o ./go-build510371387/command-line-arguments/_obj/_cgo_export.o ./go-build510371387/command-line-arguments/_obj/3.cgo2.o /home/peter/projects/go/go/pkg/tool/linux_amd64/cgo -objdir ./go-build510371387/command-line-arguments/_obj/ -dynimport ./go-build510371387/command-line-arguments/_obj/_cgo_.o -dynout ./go-build510371387/command-line-arguments/_obj/_cgo_import.c /home/peter/projects/go/go/pkg/tool/linux_amd64/6c -F -V -w -I ./go-build510371387/command-line-arguments/_obj/ -I /home/peter/projects/go/go/pkg/linux_amd64 -o ./go-build510371387/command-line-arguments/_obj/_cgo_import.6 -D GOOS_linux -D GOARCH_amd64 ./go-build510371387/command-line-arguments/_obj/_cgo_import.c gcc -I . -g -O2 -fPIC -m64 -pthread -fmessage-length=0 -o ./go-build510371387/command-line-arguments/_obj/_all.o ./go-build510371387/command-line-arguments/_obj/_cgo_export.o ./go-build510371387/command-line-arguments/_obj/3.cgo2.o -Wl,-r -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/libgcc.a /home/peter/projects/go/go/pkg/tool/linux_amd64/6g -o ./go-build510371387/command-line-arguments/_obj/_go_.6 -p command-line-arguments -D _/tmp -I ./go-build510371387 ./go-build510371387/command-line-arguments/_obj/_cgo_gotypes.go ./go-build510371387/command-line-arguments/_obj/3.cgo1.go /home/peter/projects/go/go/pkg/tool/linux_amd64/pack grcP ./go-build510371387 ./go-build510371387/command-line-arguments.a ./go-build510371387/command-line-arguments/_obj/_go_.6 ./go-build510371387/command-line-arguments/_obj/_cgo_import.6 ./go-build510371387/command-line-arguments/_obj/_cgo_defun.6 ./go-build510371387/command-line-arguments/_obj/_all.o cd . /home/peter/projects/go/go/pkg/tool/linux_amd64/6l -o 3 -L $WORK $WORK/command-line-arguments.a # command-line-arguments /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/go-link-hxLIUS/go.o: relocation R_X86_64_32 against `type.*' can not be used when making a shared object; recompile with -fPIC /var/tmp/go-link-hxLIUS/go.o: could not read symbols: Bad value collect2: error: ld returned 1 exit status /home/peter/projects/go/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit status 0x100 |
If you have questions about PaX in general, please ask on the mailing list [email protected]. This particular issue is about generating code that can be linked into a PIE. There has been no progress on that. |
I don't have questions about PaX in general. I have posted about this subject in the mailing list https://groups.google.com/forum/#!topic/golang-nuts/Mie3Yfawksc. I am curious about the timeline of having fully compatible PaX and go. If there is something I can do to expedite this I would be happy to try and help. |
Given we can build actual shared libraries out of Go code now, building pie executables shouldn't be that hard. I'm not sure what changes are required though. |
-buildmode=pie is a thing now, so it would be possible to use that. OTOH, I don't actually understand what breaks when it is not used and the system linker assumes it by default... |
I've just run into something similar, but I think this specific bug is closed. We even test cgo with -linkmode=external -extldflags "-pie" now. |
These patches are for two issues: * Enabling Go to build on Alpine by disabling PIC per: golang/go#6940 https://github.com/docker-library/golang/blob/master/1.7/alpine/no-pic.patch * Fixing Go 1.4 bug appearing on macOS 10.12.1 per: golang/go#16352 (comment)
These patches are for two issues: * Enabling Go to build on Alpine by disabling PIC per: golang/go#6940 https://github.com/docker-library/golang/blob/master/1.7/alpine/no-pic.patch * Fixing Go 1.4 bug appearing on macOS 10.12.1 per: golang/go#16352 (comment)
by peter.volkov:
The text was updated successfully, but these errors were encountered: