Messages in this thread Patch in this message | | | Date | Thu, 1 Jul 2021 20:05:47 +0000 | Subject | [PATCH] riscv: allow building the kernel with medany and lld | From | Saleem Abdulrasool <> |
| |
The current implementation of the `__rt_sigaction` reference computed an absolute offset relative to the mapped base of the VDSO. While this can be handled in the medlow model, the medany model cannot handle this as it is meant to be position independent. The current implementation relied on the BFD linker relaxing the pc-relative relocation into an absolute relocation as it was a near-zero address allowing it to be referenced relative to `zero`. The constant offsets relative to the image base should be just that - constants. However, this takes a slightly more tricky approach of rebasing the address against the text base (`PAGE_OFFSET`) and then accounting for the image base at runtime to allow us to compute the VDSO relative address for the stub function. This allows the symbolic resolution to remain within the range of the pc-relative relocation, allowing the kernel to build with LLVM/lld.
Thanks to Palmer Dabbelt for his assistance with this!
Signed-off-by: Saleem Abdulrasool <abdulras@google.com> --- arch/riscv/include/asm/vdso.h | 2 +- arch/riscv/kernel/vdso/Makefile | 2 +- arch/riscv/kernel/vdso/so2s.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h index 1453a2f563bc..1240d3790abf 100644 --- a/arch/riscv/include/asm/vdso.h +++ b/arch/riscv/include/asm/vdso.h @@ -26,7 +26,7 @@ struct vdso_data { #define VDSO_SYMBOL(base, name) \ ({ \ extern const char __vdso_##name[]; \ - (void __user *)((unsigned long)(base) + __vdso_##name); \ + (void __user *)((unsigned long)(base) + __vdso_##name - PAGE_OFFSET); \ }) asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index 24d936c147cd..384f1cc8e044 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -68,7 +68,7 @@ quiet_cmd_vdsold = VDSOLD $@ # Extracts symbol offsets from the VDSO, converting them into an assembly file # that contains the same symbols at the same offsets. quiet_cmd_so2s = SO2S $@ - cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh > $@ + cmd_so2s = $(NM) -D $< | $(srctree)/$(src)/so2s.sh $(CONFIG_PAGE_OFFSET) > $@ # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@ diff --git a/arch/riscv/kernel/vdso/so2s.sh b/arch/riscv/kernel/vdso/so2s.sh index e64cb6d9440e..9e5afc2fcc07 100755 --- a/arch/riscv/kernel/vdso/so2s.sh +++ b/arch/riscv/kernel/vdso/so2s.sh @@ -2,5 +2,5 @@ # SPDX-License-Identifier: GPL-2.0+ # Copyright 2020 Palmer Dabbelt <palmerdabbelt@google.com> -sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,0x\1!' \ +sed 's!\([0-9a-f]*\) T \([a-z0-9_]*\)\(@@LINUX_4.15\)*!.global \2\n.set \2,'${1}'+0x\1!' \ | grep '^\.' -- 2.32.0.93.g670b81a890-goog
| |