Skip to content

Commit a88603f

Browse files
committed
powerpc/vdso: Don't use r30 to avoid breaking Go lang
The Go runtime uses r30 for some special value called 'g'. It assumes that value will remain unchanged even when calling VDSO functions. Although r30 is non-volatile across function calls, the callee is free to use it, as long as the callee saves the value and restores it before returning. It used to be true by accident that the VDSO didn't use r30, because the VDSO was hand-written asm. When we switched to building the VDSO from C the compiler started using r30, at least in some builds, leading to crashes in Go. eg: ~/go/src$ ./all.bash Building Go cmd/dist using /usr/lib/go-1.16. (go1.16.2 linux/ppc64le) Building Go toolchain1 using /usr/lib/go-1.16. go build os/exec: /usr/lib/go-1.16/pkg/tool/linux_ppc64le/compile: signal: segmentation fault go build reflect: /usr/lib/go-1.16/pkg/tool/linux_ppc64le/compile: signal: segmentation fault go tool dist: FAILED: /usr/lib/go-1.16/bin/go install -gcflags=-l -tags=math_big_pure_go compiler_bootstrap bootstrap/cmd/...: exit status 1 There are patches in flight to fix Go[1], but until they are released and widely deployed we can workaround it in the VDSO by avoiding use of r30. Note this only works with GCC, clang does not support -ffixed-rN. 1: https://go-review.googlesource.com/c/go/+/328110 Fixes: ab037dd ("powerpc/vdso: Switch VDSO to generic C implementation.") Cc: [email protected] # v5.11+ Reported-by: Paul Menzel <[email protected]> Tested-by: Paul Menzel <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 333cf50 commit a88603f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/powerpc/kernel/vdso64/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ KASAN_SANITIZE := n
2727

2828
ccflags-y := -shared -fno-common -fno-builtin -nostdlib \
2929
-Wl,-soname=linux-vdso64.so.1 -Wl,--hash-style=both
30+
31+
# Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true
32+
# by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is
33+
# compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code
34+
# generation is minimal, it will just use r29 instead.
35+
ccflags-y += $(call cc-option, -ffixed-r30)
36+
3037
asflags-y := -D__VDSO64__ -s
3138

3239
targets += vdso64.lds

0 commit comments

Comments
 (0)