From patchwork Wed Aug 16 18:03:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714035 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2490832wrp; Wed, 16 Aug 2023 11:04:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE88oTghoYkaqXSGIFE7vtBadG1hlT1KfiN9IOxO5W+ym8z5f30zZ/VWaJEgtnrwqPOB7oW X-Received: by 2002:a05:620a:1708:b0:76c:d6eb:df89 with SMTP id az8-20020a05620a170800b0076cd6ebdf89mr3333338qkb.28.1692209088154; Wed, 16 Aug 2023 11:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692209088; cv=none; d=google.com; s=arc-20160816; b=aLBGlBKminTMtdIZcndoQ1JU1a3ekLyX3f2rRHV/LvNlrwhBZWUcA9Eceo4qc/b4Sz c/8IdV2+da1pjyN1EY1NLrfKuX7rzujYo9r55tWxrnD/mosDRHgl/YDp4dheFd0WxSOW UmPG5oXT5snETvf2dgmz0A4owkkjTVA7qldzaOKiF2CmHQxpoeYkgNwXFIwjrrjHbNuK WDOEhejvwKpMPSW0XC+fkPA4uUhrscNFMkFJ2Jo85I1KBdcxMfd61R+E266SLePWIWnk 1alg8uozLh71oWNrqTEQniRC4FthlB54dswgDY/Kn9CJHD7q13zffnmfGaH1tDWXpngs DjWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=M478cD9e19CcONyDKO+nZ894P/ANoM0KduR/gS2DCkU=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=KVzXL5hBAnJUDQcJMAAJ3/trg1kq9xPID3D5+K2PCnyhDH0GGvycSYycPU654LQdCz zaZFOoqIXcQUPjrHR9KYw60cut2gLnpV9PXDx2UoIJ2Q1YLo/8nhApshX8ZuKzd+Fi1y 9Y3QgE9CwsXpxBmlRKrLTxYBCuD/I6gV865QRdakIHUj50i2XRqL/i5Z4neRQ55wB/tq TBgEJQrcbKoW8S+Fz1XzpQsojlFeHFG4mCuFyKSE9kO6n0jSLM1KI18cOHK3hjPKFnlW 7oHnpP76PHt6ICIBEYB0ewuzFNN605YHcJlY3pec2KffMf4Hc/Wkdmm1a495qAmjyUuR wQ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=caI9R65H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s12-20020a05620a0bcc00b00766534d6a57si9457103qki.520.2023.08.16.11.04.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 11:04:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=caI9R65H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWKs7-0002Qe-DS; Wed, 16 Aug 2023 14:03:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWKs5-0002Oz-Qj for qemu-devel@nongnu.org; Wed, 16 Aug 2023 14:03:53 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWKs2-0001LT-If for qemu-devel@nongnu.org; Wed, 16 Aug 2023 14:03:53 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bbff6b2679so44768385ad.1 for ; Wed, 16 Aug 2023 11:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692209029; x=1692813829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M478cD9e19CcONyDKO+nZ894P/ANoM0KduR/gS2DCkU=; b=caI9R65HoEX81wObwUFzgmuxDK8MftLo5Hf74fWrmn1VSsr2qk3To45/CzPE2ElKZY 46HOBRVCl53vOdGbBlcb3CUxVio2//y+RSO5mTeJ11wneKiYVTafQN4Jiua0bnP8O+lT 9R4PEq5jBhrpIAuNtz6mbc/Nk5sNu3XFFRSQV6R/OC60oU0fHvlQGsWx3LLKTGZXy8fe q6rdVCsvXIv6bswjhrjQEFdNRi8ohlRAJeVbHm7wEFw8yQuJDdWGGEP9h7pzsSUXy4t0 knW8bFeExjyE6+w9o8rUSxSVrHMvsUrTM96sA5whMRhP4J8o/icCDMcszZQF9FD6lrVi gxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692209029; x=1692813829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M478cD9e19CcONyDKO+nZ894P/ANoM0KduR/gS2DCkU=; b=hTbrhxQ2y/PMKS1lnAxrozNRsXKcsSF+cquZI6GzNuHEMnSEJAUoiopT+TivIQXy51 IBCmSAc5fnIsedO+5yoXn8pNitJ//YW+VK6ad330FJPezrLYdKepJuVA6/zepUs82cRX L/NCld36q2ocXh6YDlJ8rCBNIQMTrg0bGpBTMW8rOB4YXSw2D87jenZsPK9C6cLS9mph 5R166Hj79brLZ8gPpnHOVpICEFdO+OGD8LF6I3rjejQLZ64p3xoBzh864YXpa7GrV8Gl YC5IqPyv9iGxg6aiWBW+kVnSc96rxUZpVbF0KdkyK9UvnUnnZVXOOu1NaKfX/YwTVLI+ zNzg== X-Gm-Message-State: AOJu0YyMrZGt2gfjoaGJLfeMddPeWcT8qaFumMffF5PePbA6A2MG4/5K V+HcyGW6EihsQiZq5nyEGZjxYoHHwEu4MlcgW58= X-Received: by 2002:a17:903:2584:b0:1bd:d162:5dc6 with SMTP id jb4-20020a170903258400b001bdd1625dc6mr2072140plb.14.1692209028995; Wed, 16 Aug 2023 11:03:48 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id g14-20020a170902868e00b001bc2831e1a9sm13446584plo.90.2023.08.16.11.03.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 11:03:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 11/18] linux-user/aarch64: Add vdso Date: Wed, 16 Aug 2023 11:03:31 -0700 Message-Id: <20230816180338.572576-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816180338.572576-1-richard.henderson@linaro.org> References: <20230816180338.572576-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++ linux-user/aarch64/Makefile.vdso | 12 +++++ linux-user/aarch64/meson.build | 12 +++++ 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 + 8 files changed, 174 insertions(+) create mode 100644 linux-user/aarch64/Makefile.vdso 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 e8a2375ba8..98cb1ff053 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -588,10 +588,14 @@ static const char *get_elf_platform(void) #define ELF_CLASS ELFCLASS64 #if TARGET_BIG_ENDIAN # define ELF_PLATFORM "aarch64_be" +# include "vdso-be.c.inc" #else # define ELF_PLATFORM "aarch64" +# include "vdso-le.c.inc" #endif +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/aarch64/Makefile.vdso b/linux-user/aarch64/Makefile.vdso new file mode 100644 index 0000000000..53c19e1ce9 --- /dev/null +++ b/linux-user/aarch64/Makefile.vdso @@ -0,0 +1,12 @@ +CROSS_CC ?= aarch64-linux-gnu-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both -Wl,--build-id=sha1 \ + -Wl,-z,max-page-size=4096 + +all: vdso-le.so vdso-be.so + +vdso-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian vdso.S -o $@ + +vdso-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian vdso.S -o $@ diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..35e50c9b2c --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,12 @@ +# ??? There does not seem to be a way to do +# when: ['TARGET_AARCH64', !'TARGET_WORDS_BIGENDIAN'] +# so we'd need to add TARGET_WORDS_LITTLEENDIAN. +# In the meantime, build both files for aarch64 and aarch64_be, +# only one of which will be included. + +gen = [ + gen_vdso.process('vdso-be.so', extra_args: ['-r', '__kernel_rt_sigreturn']), + gen_vdso.process('vdso-le.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..311f192d88149f744ee05c2492e8e8de6c5b5ec4 GIT binary patch literal 3216 zcmc&$L2nyH6rS~N;}lA9Dk>rcL6IUEgoN5dk&tN3_h#N3uPqxPao{Dh-+bS^ zH#0jkZ@h2k3rne#r=0of3)B;WY0295@hi;c)jpL~8TBCe7)oH(wY8;%# zNLzi>Gq`121T#caC_J9mApu==4D`^_-fN7P<6l=Ha$L~14uhy3;y^+2mx8LdZrcY@ zbb^uJ_Idjv~$3@CLUuRf3-)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$>F#?`YZTeC@Qz(f1>vI zhCrVI$Nu5QjvtQ=9pM|QcurqTzAJa~K>SfrV%o|BcN+rwIIRi)T^!`OeSag2CD{*X Jpo>qi{}(kpCh`CP 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 + +/* ??? 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 e4cb70ed2d..dd24389052 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -35,6 +35,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')