qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org, laurent@vivier.eu
Subject: [PATCH v5 13/20] linux-user/aarch64: Add vdso
Date: Tue, 29 Aug 2023 15:02:21 -0700	[thread overview]
Message-ID: <20230829220228.928506-14-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org>

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c           |   7 ++++
 linux-user/aarch64/meson.build |  33 +++++++++++++++
 linux-user/aarch64/vdso-be.so  | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso-le.so  | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso.S      |  73 +++++++++++++++++++++++++++++++++
 linux-user/aarch64/vdso.ld     |  72 ++++++++++++++++++++++++++++++++
 linux-user/meson.build         |   1 +
 7 files changed, 186 insertions(+)
 create mode 100644 linux-user/aarch64/meson.build
 create mode 100755 linux-user/aarch64/vdso-be.so
 create mode 100755 linux-user/aarch64/vdso-le.so
 create mode 100644 linux-user/aarch64/vdso.S
 create mode 100644 linux-user/aarch64/vdso.ld

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b421f04675..8316868bd2 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -768,6 +768,13 @@ static uint32_t get_elf_hwcap2(void)
 
 #undef GET_FEATURE_ID
 
+#if TARGET_BIG_ENDIAN
+# include "vdso-be.c.inc"
+#else
+# include "vdso-le.c.inc"
+#endif
+#define vdso_image_info()    &vdso_image_info
+
 #endif /* not TARGET_AARCH64 */
 #endif /* TARGET_ARM */
 
diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build
new file mode 100644
index 0000000000..b769c87570
--- /dev/null
+++ b/linux-user/aarch64/meson.build
@@ -0,0 +1,33 @@
+# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it
+# is always true as far as source_set.apply() is concerned.  Always build
+# both header files and include the right one via #if.
+
+vdso_cmd = [
+    build_vdso_cmd,
+    '-B', meson.project_build_root(),
+    '-C', meson.current_source_dir(),
+    '-T', 'aarch64-linux-user',
+    '-o', '@OUTPUT@',
+    '--',
+    '-nostdlib', '-shared',
+    '-Wl,-h,linux-vdso.so.1',
+    '-Wl,--build-id=sha1',
+    '-Wl,--hash-style=both',
+    '-Wl,-T,@INPUT1@',
+    '@INPUT0@'
+]
+
+vdso_le_so = custom_target(output: 'vdso-le.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mlittle-endian'])
+
+vdso_be_so = custom_target(output: 'vdso-be.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mbig-endian'])
+
+gen = [
+  gen_vdso.process(vdso_le_so, extra_args: ['-r', '__kernel_rt_sigreturn']),
+  gen_vdso.process(vdso_be_so, extra_args: ['-r', '__kernel_rt_sigreturn']),
+]
+
+linux_user_ss.add(when: 'TARGET_AARCH64', if_true: gen)
diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so
new file mode 100755
index 0000000000000000000000000000000000000000..b19563b648cc3e33a45b9394695d747f55c11db7
GIT binary patch
literal 3216
zcmc&$O>A355T57v+5{-Ysi=q)1g#XIswz)u5h$n}>|m!!<)$HRMcT{OwO?YViH)9L
zih~5?z=Z>%s3*h$7jXfJb1N?G0i;U3Re&lXl@n4Wq>3KOr9bY>?#y~^Y=p#tN%nm^
z-^}dn+ud2e5A%iTRLTP@K3u}SLugCJ*oV)vHVIoG18H~$^{v<fV@J+N4|=197KCBc
zDaVlE2R(y7jfK(7Duo>9^IFFKH#BtTHHOQ{@AI9wplKX>5uW8hLCPZyyWXO)_afvt
zPLSS@;?mf*9GW`;SFwXaoUePPPkDT@e|7!-C&$uv?_9aC^5d7czWDXKi@WpeN3fmy
zrx<A*6rbJ+>g`AO2vOhEfH@8NmszJhLP@nW06fX~F5^>-dY|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
zhxSc`V&%PrW0ddd)H_JfH|0(?Nd8gO={Lk(TXrEBI?c+ri~=%W(nqijh#%(r8a|Rh
HMjQVaBo8Se

literal 0
HcmV?d00001

diff --git a/linux-user/aarch64/vdso-le.so b/linux-user/aarch64/vdso-le.so
new file mode 100755
index 0000000000000000000000000000000000000000..4bd7bf1587b9dc652784efc34f67be6514f46a10
GIT binary patch
literal 3216
zcmcguL2MgU5FKYzk|v=|3KfxpXptgRRj>+0LWOd$gY72BNkeGV(#x;0H@0bFqxB|r
zDgixk;Y1K8ZU%9ID-u*(=z#+gH&jr?C8tW2K#(5b)Yi=G&a>A)TY-ec*nj8$H#2|!
z{y#JO-^~^B1E~~&9QvAiBciklwuhl1*h$*Q&v80P4>3H*Ev;gkPwHggm`30swMk;T
zGAR={>8b`86H!~|wRv~(Du=(NTR~auS~{=IA7z;kxT=M|q<>!Lvw1eOA_9j$u^H#K
zkK5_R716pbm?J$V>5DHJi~P$^cZTvA|Eu|5{&?}o=EzQE<+n#zL<i)-bRlA)ophIU
zqCf9<8Zy4BWAP_+O~-ORLT%YNrjdxzW#yyFCzaprMDwL(flT*wtmd?<;~AAlTL1sk
zWtWF&jBe^WWUqy?+yuX^IL_lu#wX}bM|9#O$13{Qta%<&{Cf+J+s6BdL)muhx%6=!
zqN^c9h+)A*M{sFk_YI{}G#rJu=!yJe@6^p-KWKgU-Ng&z+4fUM?`1yUA!9Cie%)I$
z6)y;C>t18ET-@rRrL{)s5@ZRm?=^d<ADCvX;(Nh{U#GQNeWUfvX1UpL`Tr~x<`-Aa
zn-lKy?sG5jVtDoV$tb12Prm*AVTtF*xgl2Nod#I`{tspdc_rr{l$vr*2_`yeZclR)
z!a1g{EYo1?iPY5Ckr0#k9OE`4N=#<j`RUl<t3R^+jq8s2IUFD8AJ4_c)rm+JStmao
zUJdd)uHo=ov}K_dIea>8Bt}f;aF))<!CB;RG$3!|B8N{N`P+{Vb@R9%AEu=Ib7(&y
zZ~OH}x^=G~AEj-L?|!_O55VR12NUu~&O}bp-nWAxzIUETf0RB;@S8OMp>Xy)9ee+$
z!uj{Um(+z6uXE1Y|19H4`Tr{8Np+;6xLrryR@|-^A1S`4UX)4;OIHe)Yi@(4%QW30
zlYM<LvoQZMrym!7lbbX7<;+6P%w?C!oGzT1%@oX;eEzlES#vfsTgaLI4D9B8H^U#C
z%3a-mQzOW2ZmkE!H<$;0#H;Al8-Yh|d8=Mrua&|M>oP9}MRF_k4YyisRwF#{BV^O_
zo3%#0Z(z#gdR4RP7uP*gEwd&@<OW_V;641WByl143Zy0C5?taSPWV0mdy+d+hY>!A
zJ8%xJkZ^Z_J?hqRmdZC3{!t&mw<Gg#jWQMN@%=r)nBee_Is$%_WpRQ%_)9F5Zw~yU
z-hiXdVt&{m9Z$0DU;K@SJ?av;$c1eC2ql_T8SHTn0mr=q`nsJM(ktBS#QdYqfk*YD
z=O2E+&#}GSSujRD1jqUjBY1x-V3j+vCfGmdo(O&H8^#jDaeLHP@MBO^Zu@^n?Qw@d
zodL)CF^%m%?i)J7cUAE%eKEOL9_9xBlcL15pBv6L1oUxH1OAIR$bI|#CKyYyA5ll|
H{e%7AHUTDw

literal 0
HcmV?d00001

diff --git a/linux-user/aarch64/vdso.S b/linux-user/aarch64/vdso.S
new file mode 100644
index 0000000000..e436e60fd9
--- /dev/null
+++ b/linux-user/aarch64/vdso.S
@@ -0,0 +1,73 @@
+/*
+ * aarch64 linux replacement vdso.
+ *
+ * Copyright 2023 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <asm/unistd.h>
+
+/* ??? These are in include/elf.h, which is not ready for inclusion in asm. */
+#define NT_GNU_PROPERTY_TYPE_0  5
+#define GNU_PROPERTY_AARCH64_FEATURE_1_AND      0xc0000000
+#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI      (1U << 0)
+#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC      (1U << 1)
+
+#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \
+    (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC)
+
+	.section .note.gnu.property
+	.align	3
+	.long	2f - 1f
+	.long	6f - 3f
+	.long	NT_GNU_PROPERTY_TYPE_0
+1:	.string	"GNU"
+2:	.align	3
+3:	.long	GNU_PROPERTY_AARCH64_FEATURE_1_AND
+	.long	5f - 4f
+4:	.long	GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT
+5:	.align	3
+6:
+
+	.text
+
+.macro endf name
+	.globl	\name
+	.type	\name, @function
+	.size	\name, . - \name
+.endm
+
+.macro vdso_syscall name, nr
+\name:
+	bti	c
+	mov	x8, #\nr
+	svc	#0
+	ret
+endf	\name
+.endm
+
+	.cfi_startproc
+
+vdso_syscall __kernel_gettimeofday, __NR_gettimeofday
+vdso_syscall __kernel_clock_gettime, __NR_clock_gettime
+vdso_syscall __kernel_clock_getres, __NR_clock_getres
+
+	.cfi_endproc
+
+
+/*
+ * TODO: The kernel makes a big deal of turning off the .cfi directives,
+ * because they cause libgcc to crash, but that's because they're wrong.
+ *
+ * For now, elide the unwind info for __kernel_rt_sigreturn and rely on
+ * the libgcc fallback routine as we have always done.  This requires
+ * that the code sequence used be exact.
+ */
+__kernel_rt_sigreturn:
+	/* No BTI C insn here -- we arrive via RET. */
+	mov	x8, #__NR_rt_sigreturn
+	svc	#0
+endf	__kernel_rt_sigreturn
+
+/* TODO: Add elf note for LINUX_VERSION_CODE */
diff --git a/linux-user/aarch64/vdso.ld b/linux-user/aarch64/vdso.ld
new file mode 100644
index 0000000000..4c12f33352
--- /dev/null
+++ b/linux-user/aarch64/vdso.ld
@@ -0,0 +1,72 @@
+/*
+ * Linker script for linux aarch64 replacement vdso.
+ *
+ * Copyright 2021 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+VERSION {
+        LINUX_2.6.39 {
+        global:
+                __kernel_rt_sigreturn;
+                __kernel_gettimeofday;
+                __kernel_clock_gettime;
+                __kernel_clock_getres;
+
+        local: *;
+        };
+}
+
+
+PHDRS {
+        phdr            PT_PHDR         FLAGS(4) PHDRS;
+        load            PT_LOAD         FLAGS(7) FILEHDR PHDRS;
+        dynamic         PT_DYNAMIC      FLAGS(4);
+        eh_frame_hdr    PT_GNU_EH_FRAME;
+        note            PT_NOTE         FLAGS(4);
+}
+
+SECTIONS {
+        /*
+         * We can't 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*) }         :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   =0xd503201f
+}
diff --git a/linux-user/meson.build b/linux-user/meson.build
index 099e5c4fe0..1b265ed365 100644
--- a/linux-user/meson.build
+++ b/linux-user/meson.build
@@ -36,6 +36,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c',
 gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc',
                      arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@'])
 
+subdir('aarch64')
 subdir('alpha')
 subdir('arm')
 subdir('hppa')
-- 
2.34.1



  parent reply	other threads:[~2023-08-29 23:25 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 22:02 [PATCH v5 00/20] linux-user: Implement VDSOs Richard Henderson
2023-08-29 22:02 ` [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain Richard Henderson
2023-08-30  9:43   ` gaosong
2023-09-04 14:02   ` Alex Bennée
2023-09-04 23:08     ` Richard Henderson
2023-09-05  9:23   ` Alex Bennée
2023-08-29 22:02 ` [PATCH v5 02/20] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Richard Henderson
2023-09-04 14:27   ` Alex Bennée
2023-08-29 22:02 ` [PATCH v5 03/20] linux-user: Tidy loader_exec Richard Henderson
2023-09-04 14:54   ` Alex Bennée
2023-08-29 22:02 ` [PATCH v5 04/20] linux-user: Do not clobber bprm_buf swapping ehdr Richard Henderson
2023-09-04 14:58   ` Alex Bennée
2023-08-29 22:02 ` [PATCH v5 05/20] linux-user: Use ImageSource in load_elf_image Richard Henderson
2023-08-29 22:02 ` [PATCH v5 06/20] linux-user: Use ImageSource in load_symbols Richard Henderson
2023-08-29 22:02 ` [PATCH v5 07/20] linux-user: Replace bprm->fd with bprm->src.fd Richard Henderson
2023-08-29 22:02 ` [PATCH v5 08/20] linux-user: Load vdso image if available Richard Henderson
2023-08-30 14:22   ` Philippe Mathieu-Daudé
2023-08-30 16:17     ` Richard Henderson
2023-08-30 20:56       ` Philippe Mathieu-Daudé
2023-08-30 22:08         ` Richard Henderson
2023-08-29 22:02 ` [PATCH v5 09/20] linux-user: Add gen-vdso tool Richard Henderson
2023-08-29 22:02 ` [PATCH v5 10/20] linux-user: Add build-vdso.sh tool Richard Henderson
2023-08-29 22:02 ` [PATCH v5 11/20] linux-user/i386: Add vdso Richard Henderson
2023-08-29 22:02 ` [PATCH v5 12/20] linux-user/x86_64: " Richard Henderson
2023-08-29 22:02 ` Richard Henderson [this message]
2023-08-29 22:02 ` [PATCH v5 14/20] linux-user/arm: " Richard Henderson
2023-08-29 22:02 ` [PATCH v5 15/20] linux-user/hppa: " Richard Henderson
2023-08-29 22:02 ` [PATCH v5 16/20] linux-user/riscv: " Richard Henderson
2023-09-19  4:47   ` Alistair Francis
2023-08-29 22:02 ` [PATCH v5 17/20] linux-user/loongarch64: " Richard Henderson
2023-08-29 22:02 ` [PATCH v5 18/20] linux-user/ppc: " Richard Henderson
2023-08-29 22:02 ` [PATCH v5 19/20] linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD Richard Henderson
2023-08-30 14:14   ` Philippe Mathieu-Daudé
2023-08-29 22:02 ` [PATCH v5 20/20] linux-user/s390x: Add vdso Richard Henderson
2023-09-04 15:00   ` Alex Bennée
2023-09-06 17:56     ` Richard Henderson
2023-09-07  6:17       ` Philippe Mathieu-Daudé
2023-09-07  9:20       ` Alex Bennée
2023-08-30 14:52 ` [PATCH v5 00/20] linux-user: Implement VDSOs Helge Deller
2023-08-30 16:20   ` Richard Henderson
2023-08-31  7:57     ` Alex Bennée
2023-09-01 14:21       ` Helge Deller
2023-09-04 12:51         ` Alex Bennée

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=20230829220228.928506-14-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).