From b63c6b97f8f5d357f383d8227316733c758c7ddd Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Mon, 14 Aug 2023 18:56:17 -0700 Subject: [PATCH] linux-user/s390x: Add vdso MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Acked-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 + linux-user/s390x/Makefile.vdso | 11 +++++ linux-user/s390x/meson.build | 6 +++ linux-user/s390x/signal.c | 4 +- linux-user/s390x/vdso-asmoffset.h | 2 + linux-user/s390x/vdso.S | 61 +++++++++++++++++++++++++ linux-user/s390x/vdso.ld | 72 ++++++++++++++++++++++++++++++ linux-user/s390x/vdso.so | Bin 0 -> 3464 bytes 8 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 linux-user/s390x/Makefile.vdso create mode 100644 linux-user/s390x/vdso-asmoffset.h create mode 100644 linux-user/s390x/vdso.S create mode 100644 linux-user/s390x/vdso.ld create mode 100755 linux-user/s390x/vdso.so diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 26602516aa..a1583883fa 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1894,6 +1894,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 +#define VDSO_HEADER "vdso.c.inc" + #endif /* TARGET_S390X */ #ifdef TARGET_RISCV diff --git a/linux-user/s390x/Makefile.vdso b/linux-user/s390x/Makefile.vdso new file mode 100644 index 0000000000..e82bf9e29f --- /dev/null +++ b/linux-user/s390x/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/s390x-linux-user/config-target.mak + +SUBDIR = $(SRC_PATH)/linux-user/s390x +VPATH += $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ -nostdlib -shared -Wl,-h,linux-vdso64.so.1 \ + -Wl,--build-id=sha1 -Wl,--hash-style=both \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/s390x/meson.build b/linux-user/s390x/meson.build index 0781ccea1d..a7a25ed9ce 100644 --- a/linux-user/s390x/meson.build +++ b/linux-user/s390x/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc = gen_vdso.process('vdso.so', extra_args: [ + '-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn' + ]) +linux_user_ss.add(when: 'TARGET_S390X', if_true: vdso_inc) diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index 0f8b8e04bf..b40f738a70 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -21,14 +21,12 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "vdso-asmoffset.h" #define __NUM_GPRS 16 #define __NUM_FPRS 16 #define __NUM_ACRS 16 -/* Minimum stack frame size */ -#define STACK_FRAME_OVERHEAD 160 - #define _SIGCONTEXT_NSIG 64 #define _SIGCONTEXT_NSIG_BPW 64 /* FIXME: 31-bit mode -> 32 */ #define _SIGCONTEXT_NSIG_WORDS (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW) diff --git a/linux-user/s390x/vdso-asmoffset.h b/linux-user/s390x/vdso-asmoffset.h new file mode 100644 index 0000000000..27a062d6c1 --- /dev/null +++ b/linux-user/s390x/vdso-asmoffset.h @@ -0,0 +1,2 @@ +/* Minimum stack frame size */ +#define STACK_FRAME_OVERHEAD 160 diff --git a/linux-user/s390x/vdso.S b/linux-user/s390x/vdso.S new file mode 100644 index 0000000000..3332492477 --- /dev/null +++ b/linux-user/s390x/vdso.S @@ -0,0 +1,61 @@ +/* + * s390x linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "vdso-asmoffset.h" + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro raw_syscall n + .ifne \n < 0x100 + svc \n + .else + lghi %r1, \n + svc 0 + .endif +.endm + +.macro vdso_syscall name, nr +\name: + .cfi_startproc + aghi %r15, -(STACK_FRAME_OVERHEAD + 16) + .cfi_adjust_cfa_offset STACK_FRAME_OVERHEAD + 16 + stg %r14, STACK_FRAME_OVERHEAD(%r15) + .cfi_rel_offset %r14, STACK_FRAME_OVERHEAD + raw_syscall \nr + lg %r14, STACK_FRAME_OVERHEAD(%r15) + aghi %r15, STACK_FRAME_OVERHEAD + 16 + .cfi_restore %r14 + .cfi_adjust_cfa_offset -(STACK_FRAME_OVERHEAD + 16) + br %r14 + .cfi_endproc +endf \name +.endm + +vdso_syscall __kernel_gettimeofday, __NR_gettimeofday +vdso_syscall __kernel_clock_gettime, __NR_clock_gettime +vdso_syscall __kernel_clock_getres, __NR_clock_getres +vdso_syscall __kernel_getcpu, __NR_getcpu + +/* + * TODO unwind info, though we're ok without it. + * The kernel supplies bogus empty unwind info, and it is likely ignored + * by all users. Without it we get the fallback signal frame handling. + */ + +__kernel_sigreturn: + raw_syscall __NR_sigreturn +endf __kernel_sigreturn + +__kernel_rt_sigreturn: + raw_syscall __NR_rt_sigreturn +endf __kernel_rt_sigreturn diff --git a/linux-user/s390x/vdso.ld b/linux-user/s390x/vdso.ld new file mode 100644 index 0000000000..d3f1d1b164 --- /dev/null +++ b/linux-user/s390x/vdso.ld @@ -0,0 +1,72 @@ +/* + * Linker script for linux s390x replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6.29 { + global: + __kernel_gettimeofday; + __kernel_clock_gettime; + __kernel_clock_getres; + __kernel_getcpu; + __kernel_rt_sigreturn; + __kernel_sigreturn; + /* + * QEMU handles syscall restart internally, so we don't + * need the __kernel_restart_syscall entry point. + */ + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} diff --git a/linux-user/s390x/vdso.so b/linux-user/s390x/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..64130f6f335269b03291653d006225b365be9cd9 GIT binary patch literal 3464 zcmc&%U1%It6#iysH$Q7hQ<18qYK0;qI$)Fr>}21H;Q+7OupPV2ZD2FPks68pW*8JudQwTzW1Ka z#NgA%-}?T&v8(X?rJ&Uemi=lFMfFAyE>_CxiFIK)Tv!s{7UovaPOQ}+S~#(ijNA2U zD~MKF&BWA-EbDT;xw7`aYNZ|Sf7ok>-h(I}D$O7DhrRvY@T0n38S6uE^e6M&-9=)0!Y%f!IfnaNjo7rz>?{f_}Sq2{rFChdO)!14|JFYtZs>5kvL9MAl8 z@lpr-@+HOD&C597do8hV-tJ`c*w&Z3f$x#DFaLc0L$1Y^aLqX(dZ^)=b)McAu3oFQ zPARzN{BZf4F?QBDt%CyB=$+9+1=s8+*(S!$`!B6$F3_)MXdM)|MnC0z&~PC-n&b1# z*hQyAM+lB%bR<;=(q`7@)b;O3=BMiLP@+32T|1cAQ~G!;v8VJdOzh@9={ZhsqjzVM z`6-=!JF#0j=uaFgjU7I85WYWEn)eIS{^ab~;etOsF$;gHcw~I6=pUJ!e6ld-&y9^2 z3x1*r-LhdcCnYW^<=9%aQtDx*Y@tFX11TQhwbvU_`B`}FsHM3kznWnbz^kk`%Z>Vi z`q5r*z^jy_GQ4VY#jBOuHEoYt+Oit7+V!xR8u%4>LCs%ml^cOytF)34yeL?UcqRQO z48g2_IcH>F3Y-2!U~iPWt#gUb7g@K4DbDWM^_+NA^D{r5eD@y6wgv>;%OZY zTXxPb`#@OtFBT*}fi#!(Lh_4l2rI4UYb!`R@kkiQe`~Xe=YC6A^|f2Y6UO;0Ch$2g zm+&{g<$+vz=f13F4=^`#2a~Gx|2d^_Mt#e!`+vf63p~C!4-l zU>*zrEn;~dju)L2#yJUO*!f?w;#ufKr-ap+YQxS?x#hXKApajS_j0eT{zxFb{^%^Q dYips8dIiEK%mR5{!mjP(`{h1gkwAut{|A0ldjbFe literal 0 HcmV?d00001 -- 2.50.1