From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org, laurent@vivier.eu
Subject: [PATCH v2 23/36] linux-user/x86_64: Add vdso
Date: Tue, 6 Jul 2021 16:49:19 -0700 [thread overview]
Message-ID: <20210706234932.356913-24-richard.henderson@linaro.org> (raw)
In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org>
Building the vdso itself is not actually wired up to anything, since
we require a cross-compiler. Just check in that file for now.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 4 +-
linux-user/x86_64/Makefile.vdso | 5 ++
linux-user/x86_64/meson.build | 6 ++
linux-user/x86_64/vdso.S | 122 ++++++++++++++++++++++++++++++++
linux-user/x86_64/vdso.ld | 74 +++++++++++++++++++
linux-user/x86_64/vdso.so | Bin 0 -> 6008 bytes
6 files changed, 209 insertions(+), 2 deletions(-)
create mode 100644 linux-user/x86_64/Makefile.vdso
create mode 100644 linux-user/x86_64/vdso.S
create mode 100644 linux-user/x86_64/vdso.ld
create mode 100755 linux-user/x86_64/vdso.so
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7a598f9f76..43c985f318 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -284,12 +284,12 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
#define DLINFO_ARCH_ITEMS 1
#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry);
+#endif /* TARGET_X86_64 */
+
#include "vdso.c.inc"
#define vdso_image_info() &vdso_image_info
-#endif /* TARGET_X86_64 */
-
#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.vdso
new file mode 100644
index 0000000000..532c9d6964
--- /dev/null
+++ b/linux-user/x86_64/Makefile.vdso
@@ -0,0 +1,5 @@
+CROSS_CC ?= $(CC)
+
+vdso.so: vdso.S vdso.ld Makefile.vdso
+ $(CROSS_CC) -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=sha1 \
+ -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both vdso.S -o $@
diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build
index 203af9a60c..f6a0015953 100644
--- a/linux-user/x86_64/meson.build
+++ b/linux-user/x86_64/meson.build
@@ -3,3 +3,9 @@ syscall_nr_generators += {
arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
output: '@BASENAME@_nr.h')
}
+
+gen = [
+ gen_vdso.process('vdso.so')
+]
+
+linux_user_ss.add(when: 'TARGET_X86_64', if_true: gen)
diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S
new file mode 100644
index 0000000000..bbd75a79aa
--- /dev/null
+++ b/linux-user/x86_64/vdso.S
@@ -0,0 +1,122 @@
+/*
+ * x86-64 linux replacement vdso.
+ *
+ * Copyright 2021 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <asm/unistd.h>
+
+ .globl __vdso_clock_gettime
+ .type __vdso_clock_gettime, @function
+ .balign 16
+ .cfi_startproc
+__vdso_clock_gettime:
+ mov $__NR_clock_gettime, %eax
+ syscall
+ ret
+ .cfi_endproc
+ .size __vdso_clock_gettime, . - __vdso_clock_gettime
+
+clock_gettime = __vdso_clock_gettime
+ .weak clock_gettime
+
+ .globl __vdso_clock_getres
+ .type __vdso_clock_getres, @function
+ .balign 16
+ .cfi_startproc
+__vdso_clock_getres:
+ mov $__NR_clock_getres, %eax
+ syscall
+ ret
+ .cfi_endproc
+ .size __vdso_clock_getres, . - __vdso_clock_getres
+
+clock_getres = __vdso_clock_getres
+ .weak clock_getres
+
+ .globl __vdso_gettimeofday
+ .type __vdso_gettimeofday, @function
+ .balign 16
+ .cfi_startproc
+__vdso_gettimeofday:
+ mov $__NR_gettimeofday, %eax
+ syscall
+ ret
+ .cfi_endproc
+ .size __vdso_gettimeofday, . - __vdso_gettimeofday
+
+gettimeofday = __vdso_gettimeofday
+ .weak gettimeofday
+
+
+ .globl __vdso_time
+ .type __vdso_time, @function
+ .balign 16
+ .cfi_startproc
+__vdso_time:
+ mov $__NR_time, %eax
+ syscall
+ ret
+ .cfi_endproc
+ .size __vdso_time, . - __vdso_time
+
+time = __vdso_time
+ .weak time
+
+
+ .globl __vdso_getcpu
+ .type __vdso_getcpu, @function
+ .balign 16
+ .cfi_startproc
+__vdso_getcpu:
+ /*
+ * ??? There is no syscall number for this allocated on x64.
+ * We can handle this several ways:
+ *
+ * (1) Invent a syscall number for use within qemu.
+ * It should be easy enough to pick a number that
+ * is well out of the way of the kernel numbers.
+ *
+ * (2) Force the emulated cpu to support the rdtscp insn,
+ * and initialize the TSC_AUX value the appropriate value.
+ *
+ * (3) Pretend that we're always running on cpu 0.
+ *
+ * This last is the one that's implemented here, with the
+ * tiny bit of extra code to support rdtscp in place.
+ */
+ xor %ecx, %ecx /* rdtscp w/ tsc_aux = 0 */
+
+ /* if (cpu != NULL) *cpu = (ecx & 0xfff); */
+ test %rdi, %rdi
+ jz 1f
+ mov %ecx, %eax
+ and $0xfff, %eax
+ mov %eax, (%rdi)
+
+ /* if (node != NULL) *node = (ecx >> 12); */
+1: test %rsi, %rsi
+ jz 2f
+ shr $12, %ecx
+ mov %ecx, (%rsi)
+
+2: xor %eax, %eax
+ ret
+ .cfi_endproc
+ .size __vdso_getcpu, . - __vdso_getcpu
+
+getcpu = __vdso_getcpu
+ .weak getcpu
+
+/*
+ * ??? Perhaps add elf notes. E.g.
+ *
+ * #include <linux/elfnote.h>
+ * ELFNOTE_START(Linux, 0, "a")
+ * .long LINUX_VERSION_CODE
+ * ELFNOTE_END
+ *
+ * but what version number would we set for QEMU?
+ */
diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld
new file mode 100644
index 0000000000..6630193079
--- /dev/null
+++ b/linux-user/x86_64/vdso.ld
@@ -0,0 +1,74 @@
+/*
+ * Linker script for linux x86-64 replacement vdso.
+ *
+ * Copyright 2021 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+VERSION {
+ LINUX_2.6 {
+ global:
+ clock_gettime;
+ __vdso_clock_gettime;
+ gettimeofday;
+ __vdso_gettimeofday;
+ getcpu;
+ __vdso_getcpu;
+ time;
+ __vdso_time;
+ clock_getres;
+ __vdso_clock_getres;
+
+ local: *;
+ };
+}
+
+
+PHDRS {
+ phdr PT_PHDR FLAGS(4) PHDRS;
+ data PT_LOAD FLAGS(6) FILEHDR PHDRS;
+ text PT_LOAD FLAGS(5);
+ dynamic PT_DYNAMIC FLAGS(4);
+ eh_frame_hdr PT_GNU_EH_FRAME;
+ note PT_NOTE FLAGS(4);
+}
+
+SECTIONS {
+ /* ??? We can't really prelink to any address without knowing
+ something about the virtual memory space of the host, since
+ that leaks over into the available memory space of the guest. */
+ . = 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*) } :data :note
+ .dynamic : { *(.dynamic) } :data :dynamic
+ .dynsym : { *(.dynsym) } :data
+ .data : {
+ /* There ought not be any real read-write data.
+ But since we manipulated the segment layout,
+ we have to put these sections somewhere. */
+ *(.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) } :data :eh_frame_hdr
+ .eh_frame : { *(.eh_frame) } :data
+
+ . = ALIGN(4096);
+ .text : { *(.text*) } :text =0x90909090
+}
diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so
new file mode 100755
index 0000000000000000000000000000000000000000..0397ef0f4f3c1e7006146a1113d49ba93b7f5042
GIT binary patch
literal 6008
zcmeHL&1+m$6hD*6bW%;4w2CP4BTB81(jh6O1S%zMlQ_{f#6U1z)R$>ynhDL!#F>{e
zBc*~EB_e)+D;LFL*V5(etQ1Pyzn}<i#QFh6bYXCzj^{V;{Khx8PhALZoHM!k-TS-e
z+>dkbd%SaAn>;?%6^jWaE{CPr8VHzi>!?3K4UusflWqFHUv?;pbZZ&6ZWm{5Xkw4)
zfrjm0$=yWILlj#N?3!KHCQm$N0}{!1DUWs5Z9Ogqn^pzu=Q?Na_*vME*?L?&pnVV`
zbRj^L_ia2EcSA{q2we#9K`n7D&&|xsOK11)tzA92?}KkI-@3ef_h>r#@}PF9=L1<V
zr2TCes{H(WqXZnX4qLvgS)0DE!!auN1t4X^`wbs9{IwB`7dT(!H*1@@{Alg3xDd1Z
zuL0-wl<4a1e()TJmEWcOki$P_`U4LCkm<YpsOh`o95($CXPimXcX?b3tjAqvUiqE!
zQ$wLmp4S%i$8CJ98}gzS?APUS4SKcUoN@N_gH~m`7MvT;9A}O7B(*?b%VR_xeJB`f
z^T1eQDkqnykFhSyfBA~s8octwz(*J7-W$ok`NGCGeeXX0`iIqv=O6jxSn=)Q>wETG
zIh`vkywwoTJD07LyrtFB(phgg=ld&#+&yGDS0QIAr8C(~ja=A9`<K?%Wp$;vUfqYG
zQ~Eb5$ERoJ7rgzcgSx)1$e(to#O!zJvmg5K+&!v=&lL99rTts$pT^M#!TCU9gYiRn
z=Hc5L>d0Be+lpDm?-Z+wzbL+=*rN{qSP{Z;Vz16gtU3@I>`nII-GF1o+-qvXvjR7w
zW!2#(l*>CD)|_>?Rpl0y<6Y5aM>-zpc%b8fjt4p(=y;&xfsP0M=N_nktq$l<T<d@0
zjix8+cbxX3)4ti>9=(~~X!zSVZ#>=T*XSUb-q`XJpMT%GxnuO|HC6pPiR-sD<KnPh
zT)(;*pSSaIVZ7STcMId*c0SRHf7|(OtvI-yPfAq$8pjtoKJ*=lYb3>dK)5Tek=0tH
z{-5z4^$}ylBKE7F?JD<<kN6@gzQs3wRNVNC@=<Xw;uVbJ#<zz|-;F1yjd%4^HqH=&
z6&1!VHLYWOH|{-ZygU9W<)h+Z<Riel<A^tLa^}d1>0=rbYM#WKOnXyvM@~$7>4~{e
z@MqCxR1j%_qZ^NgLeIz;wHbR#s!}WXnbV4XIlw$?#gd<sRJK;k6jqj+71fp0a&bMC
z&s6dO<Cg>GT&`SMDHYoqURF}MymzLYDdfC-RyEm@l%K2m>XCmhNFpKLXa0uIA#t}e
zMYq#_QrpM}AU^=%^Gei9-4y1TcrWal$guVz@4)%_ToZ>v_NdaH`6$Hoc*JPW=bt#C
zeGsmX_T0yQ?c36v744ZPBjWjhxb^`n@~rjIo_RGQ^Jvt!?XW3WUn4X>-#bL^lk;;P
zBJw`S!Li+XKiPX{%w~fBp~L+fEsI*gnrP4W7!kRRu+VShidqTV^L<A=Pens_{;JvY
zel!yx(6tMK_d!^AZ^(t`CI?(J#Rc0~pK{2Ra(?<1c`N!>t1YST3aS@cOi*#pZ>Q2x
M_6IFb{!jLQ0P{>E*#H0l
literal 0
HcmV?d00001
--
2.25.1
next prev parent reply other threads:[~2021-07-07 0:08 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-06 23:48 [PATCH v2 00/36] linux-user: Signal trampolines and vdsos Richard Henderson
2021-07-06 23:48 ` [PATCH v2 01/36] linux-user: Add infrastructure for a signal trampoline page Richard Henderson
2021-07-06 23:48 ` [PATCH v2 02/36] linux-user: Fix style problems in linuxload.c Richard Henderson
2021-07-07 19:22 ` Laurent Vivier
2021-07-06 23:48 ` [PATCH v2 03/36] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Richard Henderson
2021-07-06 23:49 ` [PATCH v2 04/36] linux-user: Tidy loader_exec Richard Henderson
2021-07-07 8:21 ` Philippe Mathieu-Daudé
2021-07-06 23:49 ` [PATCH v2 05/36] linux-user: Do not clobber bprm_buf swapping ehdr Richard Henderson
2021-07-06 23:49 ` [PATCH v2 06/36] linux-user: Use ImageSource in load_elf_image Richard Henderson
2021-07-06 23:49 ` [PATCH v2 07/36] linux-user: Use ImageSource in load_symbols Richard Henderson
2021-07-06 23:49 ` [PATCH v2 08/36] linux-user: Replace bprm->fd with bprm->src.fd Richard Henderson
2021-07-06 23:49 ` [PATCH v2 09/36] linux-user: Introduce imgsrc_mmap Richard Henderson
2021-07-06 23:49 ` [PATCH v2 10/36] linux-user: Load vdso image if available Richard Henderson
2021-07-06 23:49 ` [PATCH v2 11/36] linux-user: Add gen-vdso tool Richard Henderson
2021-07-06 23:49 ` [PATCH v2 12/36] linux-user/aarch64: Add vdso and use it for rt_sigreturn Richard Henderson
2021-07-06 23:49 ` [PATCH v2 13/36] linux-user/arm: Drop v1 signal frames Richard Henderson
2021-07-07 8:19 ` Philippe Mathieu-Daudé
2021-07-07 17:35 ` Peter Maydell
2021-07-06 23:49 ` [PATCH v2 14/36] linux-user/arm: Drop "_v2" from symbols in signal.c Richard Henderson
2021-07-07 8:19 ` Philippe Mathieu-Daudé
2021-07-06 23:49 ` [PATCH v2 15/36] target/arm: Add isar_feature_aa32_a32 Richard Henderson
2021-07-06 23:49 ` [PATCH v2 16/36] linux-user/arm: Add vdso and use it for rt_sigreturn Richard Henderson
2021-07-06 23:49 ` [PATCH v2 17/36] linux-user/alpha: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 18/36] linux-user/cris: " Richard Henderson
2021-07-06 23:49 ` [PATCH v2 19/36] linux-user/hexagon: " Richard Henderson
2021-07-12 23:08 ` Taylor Simpson
2021-07-06 23:49 ` [PATCH v2 20/36] linux-user/hppa: Add vdso and use it for rt_sigreturn Richard Henderson
2021-07-06 23:49 ` [PATCH v2 21/36] linux-user/x86_64: Raise SIGSEGV if SA_RESTORER not set Richard Henderson
2021-07-06 23:49 ` [PATCH v2 22/36] linux-user/i386: Add vdso and use it for sigreturn Richard Henderson
2021-07-07 20:28 ` Richard Henderson
2021-07-06 23:49 ` Richard Henderson [this message]
2021-07-06 23:49 ` [PATCH v2 24/36] linux-user/m68k: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 25/36] linux-user/microblaze: " Richard Henderson
2021-07-06 23:49 ` [PATCH v2 26/36] linux-user/mips: Tidy install_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 27/36] linux-user/mips: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 28/36] linux-user/nios2: Document non-use of setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 29/36] linux-user/openrisc: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 30/36] target/ppc: Simplify encode_trampoline Richard Henderson
2021-07-06 23:49 ` [PATCH v2 31/36] linux-user/ppc: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 32/36] linux-user/riscv: Add vdso and use it for sigreturn Richard Henderson
2021-07-06 23:49 ` Richard Henderson
2021-07-06 23:49 ` [PATCH v2 33/36] linux-user/s390x: Implement setup_sigtramp Richard Henderson
2021-07-06 23:49 ` [PATCH v2 34/36] linux-user/sh4: " Richard Henderson
2021-07-06 23:49 ` [PATCH v2 35/36] linux-user/sparc: " Richard Henderson
2021-07-06 23:49 ` [PATCH v2 36/36] linux-user/xtensa: " Richard Henderson
2021-07-08 10:55 ` [PATCH v2 00/36] linux-user: Signal trampolines and vdsos Philippe Mathieu-Daudé
2021-09-01 9:36 ` Peter Maydell
2021-09-03 13:39 ` Alex Bennée
2021-09-03 15:39 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210706234932.356913-24-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.