From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040162; cv=none; d=zohomail.com; s=zohoarc; b=lU2mSO+5ckgrurb8bHYzfxgiXkNn7kq48UjIpzEKIrP9bIawOrbus3jpULNXvKgGHOWtd3NSVNdN3j0GHXflicqmxmfptIhhwYByG5vw7/dkfboTqaV+CZJum9GA7XlUcyNDMibqarY4NVQwdLKmvzqsheQzjuF2QTsXSJNv0gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040162; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; b=IPk6kO2PzaFvIXLjxEsmbBHUROAWkd3p1NW9d8h9H7v7/wKMd51wAaJZ/x7KgKSWWEazLcymjaJnUgNDtgTVSLzXPGTSKQ0seVi6FCnK039z1mHItbAFyeQyJ+F2r63E0sozrV5lNomSMxsDMP7L2CwJYpenXM2mDNQ+3oAgVB8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040162220743.3066655779347; Fri, 29 Sep 2023 19:16:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWB-0000C1-5o; Fri, 29 Sep 2023 22:15:43 -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 1qmPW9-0000Bo-OS for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:41 -0400 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW1-0001yX-SN for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:41 -0400 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-57ba5f05395so6223512eaf.1 for ; Fri, 29 Sep 2023 19:15:33 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040132; x=1696644932; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; b=ILkOYx9W4q8+vgYvxfdkSw/4s3T53uoWMiFQZQfnc/P/9BQ/K37R6aMAgPT6y1HKDt OSJMp/vsXYUNdadiaOnuwT20br3vCOtQ+8vEO5kXqjx8sm3yH7c6P6/oZ+woofWmpef0 z8coif0Boqew4xIbsPl+CtK8nm+/OU+cCFXo/K0pP3LkRR8ywVgAdW3bpoOyl0BnHKrB x65emOclKa177bX5JWqV67RBguLmD1q3z6gMQQB/qtDYhj4DTVXTOlK1mQvVDu5DM6i4 6AvDWLN+C0Mo4+4gOkW8sYidT8GHVYA/Ee3r96t3yvL5J5YTE5FCwEVBJb9cgHypjatB zftQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040132; x=1696644932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; b=NJURDa/Hl1wcOUy5MJ1aTzCzH+mPq853cBFIaR0mqvHTZq4mX2nVTUCgpxz+c5URdA cLuaUjDWMFlNgadnmWWAu9AgX9xBE0rUhSCLPpXf8EnWZGlUAqN/O9am7WhUldtiZYIR v3Okule5FAO2fs5gd7wrlKCCtswJTvSXXSpF4MYxogHtWQgIuwAIXvtkn9WLeXaEwaYg A0hGL8a78AhDi9Vt6YlQZw6N1Ko/eJVCRq1jLdYQQzSJzIYBXU6JkI1pbg4fL1uH074G BhGeG2YtemZ8OQ25tEQTjlniSXyFuFJqNnXqoLKH0D/GVYYE5NZwhlqoe6OQuz+OFrai 5S/w== X-Gm-Message-State: AOJu0Yy7E3NPq1XCh2R2RUQrsSQgCsX0vLJBPhG+/aHSI+k0Ji8d0kBR N7qfgocaNbF9kOXinn6vxLes+UFZhOgLMSBLUCs= X-Google-Smtp-Source: AGHT+IF1+Sk/mycVguP+vHwE3VV3MqaxoeL9lZhMXRehKFRJmV07aK7nzo/evApsDZNSgPXC8mSnDQ== X-Received: by 2002:a05:6358:9192:b0:145:794e:ac30 with SMTP id j18-20020a056358919200b00145794eac30mr6795743rwa.17.1696040132183; Fri, 29 Sep 2023 19:15:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 01/19] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Fri, 29 Sep 2023 19:15:11 -0700 Message-Id: <20230930021529.987950-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c32; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc32.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040164658100002 Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/loader.h | 61 +++++++++++++++++++++++----- linux-user/linuxload.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 9 deletions(-) diff --git a/linux-user/loader.h b/linux-user/loader.h index 324e5c872a..da6591fff0 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -18,6 +18,48 @@ #ifndef LINUX_USER_LOADER_H #define LINUX_USER_LOADER_H =20 +typedef struct { + const void *cache; + unsigned int cache_size; + int fd; +} ImageSource; + +/** + * imgsrc_read: Read from ImageSource + * @dst: destination for read + * @offset: offset within file for read + * @len: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into @dst, using the cache when possible. + */ +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp); + +/** + * imgsrc_read_alloc: Read from ImageSource + * @offset: offset within file for read + * @size: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into newly allocated memory, using the cache when possible. + */ +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp); + +/** + * imgsrc_mmap: Map from ImageSource + * + * If @src has a file descriptor, pass on to target_mmap. Otherwise, + * this is "mapping" from a host buffer, which resolves to memcpy. + * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is + * retained for clarity. + */ +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset); + /* * Read a good amount of data initially, to hopefully get all the * program headers loaded. @@ -29,15 +71,16 @@ * used when loading binaries. */ struct linux_binprm { - char buf[BPRM_BUF_SIZE] __attribute__((aligned)); - abi_ulong p; - int fd; - int e_uid, e_gid; - int argc, envc; - char **argv; - char **envp; - char *filename; /* Name of binary */ - int (*core_dump)(int, const CPUArchState *); /* coredump routine */ + char buf[BPRM_BUF_SIZE] __attribute__((aligned)); + ImageSource src; + abi_ulong p; + int fd; + int e_uid, e_gid; + int argc, envc; + char **argv; + char **envp; + char *filename; /* Name of binary */ + int (*core_dump)(int, const CPUArchState *); /* coredump routine */ }; =20 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 745cce70ab..3536dd8104 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -3,7 +3,9 @@ #include "qemu/osdep.h" #include "qemu.h" #include "user-internals.h" +#include "user-mmap.h" #include "loader.h" +#include "qapi/error.h" =20 #define NGROUPS 32 =20 @@ -76,6 +78,10 @@ static int prepare_binprm(struct linux_binprm *bprm) /* Make sure the rest of the loader won't read garbage. */ memset(bprm->buf + retval, 0, BPRM_BUF_SIZE - retval); } + + bprm->src.cache =3D bprm->buf; + bprm->src.cache_size =3D retval; + return retval; } =20 @@ -139,6 +145,7 @@ int loader_exec(int fdexec, const char *filename, char = **argv, char **envp, int retval; =20 bprm->fd =3D fdexec; + bprm->src.fd =3D fdexec; bprm->filename =3D (char *)filename; bprm->argc =3D count(argv); bprm->argv =3D argv; @@ -173,3 +180,86 @@ int loader_exec(int fdexec, const char *filename, char= **argv, char **envp, =20 return retval; } + +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + ssize_t ret; + + if (offset + len <=3D img->cache_size) { + memcpy(dst, img->cache + offset, len); + return true; + } + + if (img->fd < 0) { + error_setg(errp, "read past end of buffer"); + return false; + } + + ret =3D pread(img->fd, dst, len, offset); + if (ret =3D=3D len) { + return true; + } + if (ret < 0) { + error_setg_errno(errp, errno, "Error reading file header"); + } else { + error_setg(errp, "Incomplete read of file header"); + } + return false; +} + +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + void *alloc =3D g_malloc(len); + bool ok =3D imgsrc_read(alloc, offset, len, img, errp); + + if (!ok) { + g_free(alloc); + alloc =3D NULL; + } + return alloc; +} + +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset) +{ + const int prot_write =3D PROT_READ | PROT_WRITE; + abi_long ret; + void *haddr; + + assert(flags =3D=3D (MAP_PRIVATE | MAP_FIXED)); + + if (src->fd >=3D 0) { + return target_mmap(start, len, prot, flags, src->fd, offset); + } + + /* + * This case is for the vdso; we don't expect bad images. + * The mmap may extend beyond the end of the image, especially + * to the end of the page. Zero fill. + */ + assert(offset < src->cache_size); + + ret =3D target_mmap(start, len, prot_write, flags | MAP_ANON, -1, 0); + if (ret =3D=3D -1) { + return ret; + } + + haddr =3D lock_user(VERIFY_WRITE, start, len, 0); + assert(haddr !=3D NULL); + if (offset + len <=3D src->cache_size) { + memcpy(haddr, src->cache + offset, len); + } else { + size_t rest =3D src->cache_size - offset; + memcpy(haddr, src->cache + offset, rest); + memset(haddr + rest, 0, len - rest); + } + unlock_user(haddr, start, len); + + if (prot !=3D prot_write) { + target_mprotect(start, len, prot); + } + + return ret; +} --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040258; cv=none; d=zohomail.com; s=zohoarc; b=kUhbIN9iHUdtYgzU/ClCpBim9yQvFWsEHCWmbqANYDdS0+HbVfdzo6WoSOYat2bywA7P/27KPgu+W9SCExMkGHmItv3kq/E1dwuzIt1R9NIFqq+FVErVI1/7tkqiHZRBUqukaqR3WdIpbD51FBMW1XLB2CsZ4qmlgfINkf6b5uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=AD1sy2thQcfIQExnzwLq7PLkU6Hx7n+Izvom9ixTdKJwgDe7F818lKbN2Vh+kPn8vfpWeVBxbd+PPUkGmqCsn92HD/jOvf2KqbNDfuKAvtR2pZE18ATDkuyAHi/sxKPqE7sRYEVUjec9WJGE7rTLqG1h0yUv5Fp6gYO6Nc/Kx4U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040258235170.1385379424555; Fri, 29 Sep 2023 19:17:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWN-0000G5-7P; Fri, 29 Sep 2023 22:15: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 1qmPWB-0000C0-3l for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW3-0001yh-Eq for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:42 -0400 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-57d086365f7so3244352eaf.0 for ; Fri, 29 Sep 2023 19:15:35 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040133; x=1696644933; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=lTSXnstiUUa+YvcwiwLyH46SpdnYn0WvLHWje1DuMdehoHYom+kmGWkyoh6uNtySPn fP1/gwZddyqQkR6lwntvXyL4IGpQvUxECTifiA8yLViA5iAsmhqSOBh8kEqcKEtwkzix Baj0PV469geaN6p49h9drlc4kpLQ63yLD4oyBnjO+GpEm7ckgbbm8ySXYNvUS9d9sRrw NECr0yKqM/N9lgyHlz8ZL2O7iz22WpXvFVeVIpfBBRY/O0rJRqdJ9wQgBmA563dSGO9e 93Q26vlExSNehRz+bi/uhp20YTOuQ79dX5Zq6SkWHtCBWbJDl48H+t/VsafCHfUmLV8E OWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040133; x=1696644933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=NzcujD7FTO36+F/IC5DFrWq43ZTrzOsnQ67oWQDqyYXn3domD9YNpvzLf/yfajMMoE YS7yiQRof5Du7klYtTs1UkHPYTAS2PCE/2yfPKqrdZJ+us3JqAXJ3HB0X1WQBYjpoFz9 mjP05LgujFblbJuSXuev2+M0yPJQS/q9mIrMR9kchNDWb+adfuAN5Z/k5CSk+DubmScy PunuTmJ0jqzCxkYIRUmeYCoBjEL18t7xcZR1xdaPDUUKWEq/H7P+eemXMtR63K3YZckg at1AcC4jI8cM/WUtLoM/lOWN3qAZRnU+wgq1Lf2cHAlTmEP3ipDPR3izifrS6N+A5aQl 5+sA== X-Gm-Message-State: AOJu0YwtaJeqsBbAzzOvxkiR+jL06JMgR2rbzmFgmKBpBVvncs47Ez3P FI6o239bJViaDudOpitv56d8AKGDB9x2n9fu8+o= X-Google-Smtp-Source: AGHT+IHpnivAN1sZtQWvydxBfqBw13rbL3KhqE5D9hyt9FmRFisq0XW7BTUta9zXZ3xabyMYTXAfWg== X-Received: by 2002:a05:6358:7e49:b0:142:dfc2:a441 with SMTP id p9-20020a0563587e4900b00142dfc2a441mr6732370rwm.8.1696040133172; Fri, 29 Sep 2023 19:15:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 02/19] linux-user: Tidy loader_exec Date: Fri, 29 Sep 2023 19:15:12 -0700 Message-Id: <20230930021529.987950-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc30.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040260128100003 Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3536dd8104..5b7e9ab983 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -154,31 +154,31 @@ int loader_exec(int fdexec, const char *filename, cha= r **argv, char **envp, =20 retval =3D prepare_binprm(bprm); =20 - if (retval >=3D 0) { - if (bprm->buf[0] =3D=3D 0x7f - && bprm->buf[1] =3D=3D 'E' - && bprm->buf[2] =3D=3D 'L' - && bprm->buf[3] =3D=3D 'F') { - retval =3D load_elf_binary(bprm, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] =3D=3D 'b' - && bprm->buf[1] =3D=3D 'F' - && bprm->buf[2] =3D=3D 'L' - && bprm->buf[3] =3D=3D 'T') { - retval =3D load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >=3D 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] =3D=3D 0x7f + && bprm->buf[1] =3D=3D 'E' + && bprm->buf[2] =3D=3D 'L' + && bprm->buf[3] =3D=3D 'F') { + retval =3D load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] =3D=3D 'b' + && bprm->buf[1] =3D=3D 'F' + && bprm->buf[2] =3D=3D 'L' + && bprm->buf[3] =3D=3D 'T') { + retval =3D load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } =20 - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } =20 bool imgsrc_read(void *dst, off_t offset, size_t len, --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040259; cv=none; d=zohomail.com; s=zohoarc; b=W7PIL2UQoBb3M9hTp8hJQoxVOvK15fB0e4qqJbDfbHJoXrYhz5nfcCPcQrxcGw78iDV9SscORDTOfKFPl0LwhwZUfx4BJDsZYXPG4VlJXqKBYVlP3UXsRW6ks+Z5PWxR+wyFiwBMN0lKR5XWtxT/EvfoNYPp+t0bg75KAves04E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040259; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N6Gi1W2NSeoXsGrs8c4mvQh099VY+s2zRGNYCJyf/Qs=; b=Yt02iUJ1IYUY42FxiHPp9af9u5Vu1S8DEolwNnzgnBbUf1XZ0VG8uolnjjZBcJsZ8X6csiHrnwCf90Za4Hdckpj7LmP8fVSlTgjwM0f2rX/0dQEQUuChPasPXBrDTkV3bBxV5WfMSgHfmq0E9Y4+ja8CZpOKQpYy16uk0WV6QwU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040259872758.5430809306434; Fri, 29 Sep 2023 19:17:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWH-0000Dy-7t; Fri, 29 Sep 2023 22:15:49 -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 1qmPWB-0000C2-70 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW4-0001ym-MM for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:42 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-692a885f129so10682191b3a.0 for ; Fri, 29 Sep 2023 19:15:35 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040134; x=1696644934; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N6Gi1W2NSeoXsGrs8c4mvQh099VY+s2zRGNYCJyf/Qs=; b=zUi+DDIeqHCzcKhsnhdy1aAvNO/QWvGU865QF0nTz7gBSaFeGtLc7PNG/LXY1zcpUX FlHQnhXJBeAekfDZ/JGSLYCgJQDt6cEuZppluDkqIyyM5NzjR1ebEE1R3Pi8SrEaBMLI dm1m1iu2E+85+JHI7Ho5Nn4w8fAPYu72UqX5oE8qQH5BjglyorFcV42FDwwf0yTwwF6K B2n2pM7K9Bk2Yesu48ES3ps9APQU/afa6JljySiyzn3oH70HrhkazfgmyzHgqSIV2WvK a8K8vPnaRP5q1JnL4L/FPKb+sws/ou9JU9MWe7Zx4OhFEmu11QawCyGFpICT8Ngbq8t4 nQIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040134; x=1696644934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N6Gi1W2NSeoXsGrs8c4mvQh099VY+s2zRGNYCJyf/Qs=; b=jSFYXdJKmQy2g/ZTfFs9B+/k3Zn5FE9KjEpwZJ7VLvgfG1EcaWcsTr762OgsSlqQCd cPr10OFHaXrqbxtDjmdav1wmzne1mQWTz4Q+JmFp4iLuT6XxY4kngbWZ/SgUC2TOCcYO SJZu3doTuqqVdsv9dyEIf2lJzqMvwjcSTMnifLYPN3aLrf1fP8lyRksmurjmGGq1ZjyP 0fKCVsX45foSGCINVZqz7tMVamhCNsMRBtnalTCATZErgH+xJlRzsTfu115JztdtrFtr nedv076TdZXJV8avjNERZKckQPwk/kHDAiOlg98G+euAJWJ7qfyt2Yf3wpeqf+a8ZElT jN4Q== X-Gm-Message-State: AOJu0YyZyqQDk9J5R6TmmNPz7VA0qQV4UOtEdN4NEb6BygMSXkrrYdmQ J0Xkaxxk+q7PFvzdQsdg+MN4FMVSbDDtPxGrKdE= X-Google-Smtp-Source: AGHT+IFbcm3E0IJLvxCfXs7rkZDdZtowgTKpbaVMEzH6ZIABRQAv/eDgtzf5OnVnDad6gFaWAYfOhQ== X-Received: by 2002:a05:6a20:7f8a:b0:131:b3fa:eaaa with SMTP id d10-20020a056a207f8a00b00131b3faeaaamr7316302pzj.61.1696040134158; Fri, 29 Sep 2023 19:15:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 03/19] linux-user: Do not clobber bprm_buf swapping ehdr Date: Fri, 29 Sep 2023 19:15:13 -0700 Message-Id: <20230930021529.987950-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040260090100001 Rearrange the allocation of storage for ehdr between load_elf_image and load_elf_binary. The same set of copies are done, but we don't modify bprm_buf, which will be important later. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/elfload.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index db75cd4b33..e5c014611c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3164,16 +3164,17 @@ static bool parse_elf_properties(int image_fd, On return: INFO values will be filled in, as necessary or available. */ =20 static void load_elf_image(const char *image_name, int image_fd, - struct image_info *info, char **pinterp_name, + struct image_info *info, struct elfhdr *ehdr, + char **pinterp_name, char bprm_buf[BPRM_BUF_SIZE]) { - struct elfhdr *ehdr =3D (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval, prot_exec; Error *err =3D NULL; =20 /* First of all, some simple consistency checks */ + memcpy(ehdr, bprm_buf, sizeof(*ehdr)); if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -3488,6 +3489,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { + struct elfhdr ehdr; int fd, retval; Error *err =3D NULL; =20 @@ -3509,7 +3511,7 @@ static void load_elf_interp(const char *filename, str= uct image_info *info, memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); } =20 - load_elf_image(filename, fd, info, NULL, bprm_buf); + load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); } =20 static int symfind(const void *s0, const void *s1) @@ -3702,8 +3704,14 @@ uint32_t get_elf_eflags(int fd) =20 int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) { + /* + * We need a copy of the elf header for passing to create_elf_tables. + * We will have overwritten the original when we re-use bprm->buf + * while loading the interpreter. Allocate the storage for this now + * and let elf_load_image do any swapping that may be required. + */ + struct elfhdr ehdr; struct image_info interp_info; - struct elfhdr elf_ex; char *elf_interpreter =3D NULL; char *scratch; =20 @@ -3713,12 +3721,7 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) #endif =20 load_elf_image(bprm->filename, bprm->fd, info, - &elf_interpreter, bprm->buf); - - /* ??? We need a copy of the elf header for passing to create_elf_tabl= es. - If we do nothing, we'll have overwritten this when we re-use bprm->= buf - when we load the interpreter. */ - elf_ex =3D *(struct elfhdr *)bprm->buf; + &ehdr, &elf_interpreter, bprm->buf); =20 /* Do this so that we can load the interpreter, if need be. We will change some of these later */ @@ -3805,7 +3808,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXE= C); } =20 - bprm->p =3D create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex, + bprm->p =3D create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, (elf_interpreter ? &interp_info : NU= LL)); info->start_stack =3D bprm->p; =20 --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040264; cv=none; d=zohomail.com; s=zohoarc; b=cBZHhPjHgXR7Jf+5vRc1d4F1y0NFzyL/ajH1aQFpTJcievCHkV7yJ2B/dhZxuBcPdprFhhvaT0Hl0RN3dq3MhFR/SBfayQv1ehsPyR0t386OTYE7g2tWrc4mTV8SAE94ovAYvbJBd+6mdT7G/tAN+uzO4u0lTLpF2JXwtOHHsQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040264; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3GQfx2V/upEzxWxysHJFBgJWu6/9LTGY0tXytH+OWrA=; b=buGvnkBhpofOVi/jyDYWlRhvU8j8hPuq55bZY4qVcOZymzmGEo82eQePCEoW4kJeNiEfPqPji17kUeeZ9dEOd3aFFWCYA+0df/Wls3Cbf1CY9iGuINVEvV9T+ERnRKwn+AiBsIEytRWh8sG3ROPz9UZpKRQsQdSDG4lccVmjWec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040264894396.5383052826438; Fri, 29 Sep 2023 19:17:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWH-0000Dx-7v; Fri, 29 Sep 2023 22:15:49 -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 1qmPWC-0000CK-Ci for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:44 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW4-0001yu-E3 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2777a5e22b5so6723311a91.1 for ; Fri, 29 Sep 2023 19:15:36 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040135; x=1696644935; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3GQfx2V/upEzxWxysHJFBgJWu6/9LTGY0tXytH+OWrA=; b=IxlP9yOuJsdv4jKutLVIy16d9EL5pJSebm9a7nbsl4qOGQOPaS0T3muLQ0ltUO3sCy /Ez47puVc7kg4fHaIWPIxw38pA62VSIXIkQW+Ehe/9jcUF6i2aSXjuVdHeYLkK92LVBv BgXAsi2gFY1WSsk71quaFvDJoyfBu1/0nmMY/Z6Suz51Z3FqlAM6iJPnu+mJUsA2WkEB eNu5b0QIRVuVN0bWvPAvz8X03AvAvDWaN82pEEJsT2Z+YWg7CK16eZ0by0n6UcvO2LIk 6yIHycAkofTpcIcba26kNCA9mLZhBvlFjHOqYkTCIwD7j3S9COXfy9vej1+ill6W4Aa6 6L+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040135; x=1696644935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3GQfx2V/upEzxWxysHJFBgJWu6/9LTGY0tXytH+OWrA=; b=HvaJaxRHGAUe+UT7u+mDrt5CMubuWl9whOtftVAiyyLDXZh4uSYI2yuB7jKIPzOtf1 bQReN5/joVh9ORRra3e66TFawmq0iSQBN4UknxiTEO0D2G1ovsPBXKDmTUpMxWYve/tM 8YzsVCnH08p84f2QOO59jAT21uJilt79Nw+T6eh+rJ/XCq5gi0mgJPNUwmUCN/OeDWFc Cey/uWYoaWWO03e0pp9AmH++sArMoOeuZ9qGQ4+33K5Rr9pDpxnYGjhM0jedhzpvPcl2 DNUEYyBWIcAqvKdmCiOiJwatrQgM87bDHVOUT1W2KhvnIJRiEGlYrxJKWGI7LNIERpPS GnmQ== X-Gm-Message-State: AOJu0Yzj6rAT+9UXuhNKA7+xuZgwmh/IWzLZY4tAjL8ve82gT82swcVG WHnTnv6f09iivEZ45zfA8ZVWQWee8o406Lkd5Sg= X-Google-Smtp-Source: AGHT+IFqd3txIRfAGXkdLt/f9bJsaIa8BxN87IIhml6qwodQCc5nLQeVJaCxxPoaDIyJQpOYBDuAgg== X-Received: by 2002:a17:90b:1292:b0:274:84e4:4ef8 with SMTP id fw18-20020a17090b129200b0027484e44ef8mr6309916pjb.32.1696040135025; Fri, 29 Sep 2023 19:15:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 04/19] linux-user: Use ImageSource in load_elf_image Date: Fri, 29 Sep 2023 19:15:14 -0700 Message-Id: <20230930021529.987950-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040266267100001 Content-Type: text/plain; charset="utf-8" Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/elfload.c | 128 +++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 79 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e5c014611c..d6f1b8d2b1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3067,10 +3067,9 @@ static bool parse_elf_property(const uint32_t *data,= int *off, int datasz, } =20 /* Process NT_GNU_PROPERTY_TYPE_0. */ -static bool parse_elf_properties(int image_fd, +static bool parse_elf_properties(const ImageSource *src, struct image_info *info, const struct elf_phdr *phdr, - char bprm_buf[BPRM_BUF_SIZE], Error **errp) { union { @@ -3098,14 +3097,8 @@ static bool parse_elf_properties(int image_fd, return false; } =20 - if (phdr->p_offset + n <=3D BPRM_BUF_SIZE) { - memcpy(¬e, bprm_buf + phdr->p_offset, n); - } else { - ssize_t len =3D pread(image_fd, ¬e, n, phdr->p_offset); - if (len !=3D n) { - error_setg_errno(errp, errno, "Error reading file header"); - return false; - } + if (!imgsrc_read(¬e, phdr->p_offset, n, src, errp)) { + return false; } =20 /* @@ -3151,30 +3144,34 @@ static bool parse_elf_properties(int image_fd, } } =20 -/* Load an ELF image into the address space. +/** + * load_elf_image: Load an ELF image into the address space. + * @image_name: the filename of the image, to use in error messages. + * @src: the ImageSource from which to read. + * @info: info collected from the loaded image. + * @ehdr: the ELF header, not yet bswapped. + * @pinterp_name: record any PT_INTERP string found. + * + * On return: @info values will be filled in, as necessary or available. + */ =20 - IMAGE_NAME is the filename of the image, to use in error messages. - IMAGE_FD is the open file descriptor for the image. - - BPRM_BUF is a copy of the beginning of the file; this of course - contains the elf file header at offset 0. It is assumed that this - buffer is sufficiently aligned to present no problems to the host - in accessing data at aligned offsets within the buffer. - - On return: INFO values will be filled in, as necessary or available. */ - -static void load_elf_image(const char *image_name, int image_fd, +static void load_elf_image(const char *image_name, const ImageSource *src, struct image_info *info, struct elfhdr *ehdr, - char **pinterp_name, - char bprm_buf[BPRM_BUF_SIZE]) + char **pinterp_name) { - struct elf_phdr *phdr; + g_autofree struct elf_phdr *phdr =3D NULL; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval, prot_exec; + int i, prot_exec; Error *err =3D NULL; =20 - /* First of all, some simple consistency checks */ - memcpy(ehdr, bprm_buf, sizeof(*ehdr)); + /* + * First of all, some simple consistency checks. + * Note that we rely on the bswapped ehdr staying in bprm_buf, + * for later use by load_elf_binary and create_elf_tables. + */ + if (!imgsrc_read(ehdr, 0, sizeof(*ehdr), src, &err)) { + goto exit_errmsg; + } if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -3185,15 +3182,11 @@ static void load_elf_image(const char *image_name, = int image_fd, goto exit_errmsg; } =20 - i =3D ehdr->e_phnum * sizeof(struct elf_phdr); - if (ehdr->e_phoff + i <=3D BPRM_BUF_SIZE) { - phdr =3D (struct elf_phdr *)(bprm_buf + ehdr->e_phoff); - } else { - phdr =3D (struct elf_phdr *) alloca(i); - retval =3D pread(image_fd, phdr, i, ehdr->e_phoff); - if (retval !=3D i) { - goto exit_read; - } + phdr =3D imgsrc_read_alloc(ehdr->e_phoff, + ehdr->e_phnum * sizeof(struct elf_phdr), + src, &err); + if (phdr =3D=3D NULL) { + goto exit_errmsg; } bswap_phdr(phdr, ehdr->e_phnum); =20 @@ -3230,17 +3223,10 @@ static void load_elf_image(const char *image_name, = int image_fd, goto exit_errmsg; } =20 - interp_name =3D g_malloc(eppnt->p_filesz); - - if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval =3D pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval !=3D eppnt->p_filesz) { - goto exit_read; - } + interp_name =3D imgsrc_read_alloc(eppnt->p_offset, eppnt->p_fi= lesz, + src, &err); + if (interp_name =3D=3D NULL) { + goto exit_errmsg; } if (interp_name[eppnt->p_filesz - 1] !=3D 0) { error_setg(&err, "Invalid PT_INTERP entry"); @@ -3248,7 +3234,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, } *pinterp_name =3D g_steal_pointer(&interp_name); } else if (eppnt->p_type =3D=3D PT_GNU_PROPERTY) { - if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &er= r)) { + if (!parse_elf_properties(src, info, eppnt, &err)) { goto exit_errmsg; } } else if (eppnt->p_type =3D=3D PT_GNU_STACK) { @@ -3401,9 +3387,9 @@ static void load_elf_image(const char *image_name, in= t image_fd, * but no backing file segment. */ if (eppnt->p_filesz !=3D 0) { - error =3D target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + error =3D imgsrc_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, elf_prot, MAP_PRIVATE | MAP_FIXED, - image_fd, eppnt->p_offset - vaddr_po); + src, eppnt->p_offset - vaddr_po); if (error =3D=3D -1) { goto exit_mmap; } @@ -3435,20 +3421,11 @@ static void load_elf_image(const char *image_name, = int image_fd, #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; - if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { - error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); + + if (!imgsrc_read(&abiflags, eppnt->p_offset, sizeof(abiflags), + src, &err)) { goto exit_errmsg; } - if (eppnt->p_offset + eppnt->p_filesz <=3D BPRM_BUF_SIZE) { - memcpy(&abiflags, bprm_buf + eppnt->p_offset, - sizeof(Mips_elf_abiflags_v0)); - } else { - retval =3D pread(image_fd, &abiflags, sizeof(Mips_elf_abif= lags_v0), - eppnt->p_offset); - if (retval !=3D sizeof(Mips_elf_abiflags_v0)) { - goto exit_read; - } - } bswap_mips_abiflags(&abiflags); info->fp_abi =3D abiflags.fp_abi; #endif @@ -3461,23 +3438,16 @@ static void load_elf_image(const char *image_name, = int image_fd, } =20 if (qemu_log_enabled()) { - load_symbols(ehdr, image_fd, load_bias); + load_symbols(ehdr, src->fd, load_bias); } =20 - debuginfo_report_elf(image_name, image_fd, load_bias); + debuginfo_report_elf(image_name, src->fd, load_bias); =20 mmap_unlock(); =20 - close(image_fd); + close(src->fd); return; =20 - exit_read: - if (retval >=3D 0) { - error_setg(&err, "Incomplete read of file header"); - } else { - error_setg_errno(&err, errno, "Error reading file header"); - } - goto exit_errmsg; exit_mmap: error_setg_errno(&err, errno, "Error mapping file"); goto exit_errmsg; @@ -3490,6 +3460,7 @@ static void load_elf_interp(const char *filename, str= uct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { struct elfhdr ehdr; + ImageSource src; int fd, retval; Error *err =3D NULL; =20 @@ -3507,11 +3478,11 @@ static void load_elf_interp(const char *filename, s= truct image_info *info, exit(-1); } =20 - if (retval < BPRM_BUF_SIZE) { - memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); - } + src.fd =3D fd; + src.cache =3D bprm_buf; + src.cache_size =3D retval; =20 - load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); + load_elf_image(filename, &src, info, &ehdr, NULL); } =20 static int symfind(const void *s0, const void *s1) @@ -3720,8 +3691,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) interp_info.fp_abi =3D MIPS_ABI_FP_UNKNOWN; #endif =20 - load_elf_image(bprm->filename, bprm->fd, info, - &ehdr, &elf_interpreter, bprm->buf); + load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpret= er); =20 /* Do this so that we can load the interpreter, if need be. We will change some of these later */ --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040184; cv=none; d=zohomail.com; s=zohoarc; b=ml6QItXsVcdap1qn/rkw0q8f7E4A5PG6KnsEJYqwL+qpVNfRWEGvKzg/7x8mJutj72alsAX8wqyWV1PuxHjEqk5to//LiMZwxtXC9qq1SgcNB6BUivgNtK/EC0Fc70c2D1NsbXk844e78Y9eRvMYd7ucqaq1gNUqAq5uD2vt1Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040184; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kZLkhD4Ob1/Y3qD3OMY7JWNNP8AXZZHIk5RVf2/dQ8w=; b=EEbvpjnIj+4oFaogDLnh2V6xb/jGi9OYY+6Gn5SdrJkcwQQCWu6DP3axfU+oHoSKE8y8PfWOBjsapj4ZhR0ywxLPCtXUYrAZrHkrCF24LtcRPRYJAqHjO12D3PiNY08o4S7ubsUFz+oZ+RSepL4eD0/o4MkLl+G1uvGJs/VOWKw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040184494657.5742759699813; Fri, 29 Sep 2023 19:16:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWJ-0000FF-9r; Fri, 29 Sep 2023 22:15:52 -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 1qmPWC-0000CL-Cr for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:44 -0400 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW5-0001z5-B0 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-57bab4e9e1aso6009778eaf.3 for ; Fri, 29 Sep 2023 19:15:36 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040136; x=1696644936; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kZLkhD4Ob1/Y3qD3OMY7JWNNP8AXZZHIk5RVf2/dQ8w=; b=LizXQ2pOyXyTELlSIabQu/67fUknh/s9UWuGi/kVg0+swFpH1UFQ0/4YhKeenMZ8jC AaGoKrUTQFO9vFc+oRkIxbA3vyu9d6JAhh1xIEPEmjr/pwaK9h3AZwdt0l+DoMTJiFI2 BTJaSvXxpd834ajIDgyhCd/bQJ/XZpAT0DdWIqlFy/gCM7yVNot/zczQUsHKARzcw0lo i56WtUaB6WWukTrRVsL18nYVWZeIEFX3GG00hnw6Rz+VV7DG+MAL9Wvw7kRn/WEmSE3I 1va0uYNyn15WXNZ4XJW7OQj8u5E7hnjRTxTpIZziCkwOzA6Nyr+FieU5xhQ9YRHFHBKw waSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040136; x=1696644936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kZLkhD4Ob1/Y3qD3OMY7JWNNP8AXZZHIk5RVf2/dQ8w=; b=E3+bHyfCT0rmTA2ZYGTdowlsDu2eCZBNchtgwlJ/rVfSIoKHTIkS0mJcaWP2EkO/ay a6n8QqAixP7t30i7L8MP5xxrz+6n4RNhgFI1dGElio/j5toidzZuJUo1BUmTEkIiEPV9 rzvgTeXgeqCZC5vyF8j6h1aRkHcLOULwzB5JTJGGWQt45Vd2cX/qfeTq4BmCTtAKjfw1 QdVHOqAdXIusCGO/eRg10QGONoqClkz2gAAEFztEXH8lMEiWjV3zOM4Cfmgi/F8Q+RLO Fjv9MUaZr8Yi6wR0V39yVTywfeY5E+52a2ysDiqcGbhmHwXtkTwxSGECWXuuREA5Xf2R 8umQ== X-Gm-Message-State: AOJu0YwnQEpYmOA0YlO2d9HsKl8WFOPR36Z+uAAzMn56e/wjQkbuF/Pj 7EfXviIdKCJ77cKsQF4KsT3qcRxjd9bBDGR9s3w= X-Google-Smtp-Source: AGHT+IExS4e/d5Fzy/BIH0omCYgYe2Dty/p/V/tEBaatOMGvdAtXsgJ2kN51LM2k2GSuR82v+X/fXg== X-Received: by 2002:a05:6358:7e07:b0:132:d333:4a5c with SMTP id o7-20020a0563587e0700b00132d3334a5cmr6982929rwm.10.1696040136016; Fri, 29 Sep 2023 19:15:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 05/19] linux-user: Use ImageSource in load_symbols Date: Fri, 29 Sep 2023 19:15:15 -0700 Message-Id: <20230930021529.987950-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c2a; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2a.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040184869100001 Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/elfload.c | 87 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d6f1b8d2b1..ed276edb3c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2193,7 +2193,8 @@ static inline void bswap_mips_abiflags(Mips_elf_abifl= ags_v0 *abiflags) { } #ifdef USE_ELF_CORE_DUMP static int elf_core_dump(int, const CPUArchState *); #endif /* USE_ELF_CORE_DUMP */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias); +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias); =20 /* Verify the portions of EHDR within E_IDENT for the target. This can be performed before bswapping the entire header. */ @@ -3438,7 +3439,7 @@ static void load_elf_image(const char *image_name, co= nst ImageSource *src, } =20 if (qemu_log_enabled()) { - load_symbols(ehdr, src->fd, load_bias); + load_symbols(ehdr, src, load_bias); } =20 debuginfo_report_elf(image_name, src->fd, load_bias); @@ -3529,19 +3530,20 @@ static int symcmp(const void *s0, const void *s1) } =20 /* Best attempt to load symbols from this ELF object. */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias) { int i, shnum, nsyms, sym_idx =3D 0, str_idx =3D 0; - uint64_t segsz; - struct elf_shdr *shdr; + g_autofree struct elf_shdr *shdr =3D NULL; char *strings =3D NULL; - struct syminfo *s =3D NULL; - struct elf_sym *new_syms, *syms =3D NULL; + struct elf_sym *syms =3D NULL; + struct elf_sym *new_syms; + uint64_t segsz; =20 shnum =3D hdr->e_shnum; - i =3D shnum * sizeof(struct elf_shdr); - shdr =3D (struct elf_shdr *)alloca(i); - if (pread(fd, shdr, i, hdr->e_shoff) !=3D i) { + shdr =3D imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shd= r), + src, NULL); + if (shdr =3D=3D NULL) { return; } =20 @@ -3559,31 +3561,33 @@ static void load_symbols(struct elfhdr *hdr, int fd= , abi_ulong load_bias) =20 found: /* Now know where the strtab and symtab are. Snarf them. */ - s =3D g_try_new(struct syminfo, 1); - if (!s) { - goto give_up; - } =20 segsz =3D shdr[str_idx].sh_size; - s->disas_strtab =3D strings =3D g_try_malloc(segsz); - if (!strings || - pread(fd, strings, segsz, shdr[str_idx].sh_offset) !=3D segsz) { + strings =3D g_try_malloc(segsz); + if (!strings) { + goto give_up; + } + if (!imgsrc_read(strings, shdr[str_idx].sh_offset, segsz, src, NULL)) { goto give_up; } =20 segsz =3D shdr[sym_idx].sh_size; - syms =3D g_try_malloc(segsz); - if (!syms || pread(fd, syms, segsz, shdr[sym_idx].sh_offset) !=3D segs= z) { - goto give_up; - } - if (segsz / sizeof(struct elf_sym) > INT_MAX) { - /* Implausibly large symbol table: give up rather than ploughing - * on with the number of symbols calculation overflowing + /* + * Implausibly large symbol table: give up rather than ploughing + * on with the number of symbols calculation overflowing. */ goto give_up; } nsyms =3D segsz / sizeof(struct elf_sym); + syms =3D g_try_malloc(segsz); + if (!syms) { + goto give_up; + } + if (!imgsrc_read(syms, shdr[sym_idx].sh_offset, segsz, src, NULL)) { + goto give_up; + } + for (i =3D 0; i < nsyms; ) { bswap_sym(syms + i); /* Throw away entries which we do not need. */ @@ -3608,10 +3612,12 @@ static void load_symbols(struct elfhdr *hdr, int fd= , abi_ulong load_bias) goto give_up; } =20 - /* Attempt to free the storage associated with the local symbols - that we threw away. Whether or not this has any effect on the - memory allocation depends on the malloc implementation and how - many symbols we managed to discard. */ + /* + * Attempt to free the storage associated with the local symbols + * that we threw away. Whether or not this has any effect on the + * memory allocation depends on the malloc implementation and how + * many symbols we managed to discard. + */ new_syms =3D g_try_renew(struct elf_sym, syms, nsyms); if (new_syms =3D=3D NULL) { goto give_up; @@ -3620,20 +3626,23 @@ static void load_symbols(struct elfhdr *hdr, int fd= , abi_ulong load_bias) =20 qsort(syms, nsyms, sizeof(*syms), symcmp); =20 - s->disas_num_syms =3D nsyms; -#if ELF_CLASS =3D=3D ELFCLASS32 - s->disas_symtab.elf32 =3D syms; -#else - s->disas_symtab.elf64 =3D syms; -#endif - s->lookup_symbol =3D lookup_symbolxx; - s->next =3D syminfos; - syminfos =3D s; + { + struct syminfo *s =3D g_new(struct syminfo, 1); =20 + s->disas_strtab =3D strings; + s->disas_num_syms =3D nsyms; +#if ELF_CLASS =3D=3D ELFCLASS32 + s->disas_symtab.elf32 =3D syms; +#else + s->disas_symtab.elf64 =3D syms; +#endif + s->lookup_symbol =3D lookup_symbolxx; + s->next =3D syminfos; + syminfos =3D s; + } return; =20 -give_up: - g_free(s); + give_up: g_free(strings); g_free(syms); } --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040219; cv=none; d=zohomail.com; s=zohoarc; b=fGWOyjop5J4hQXpamusBvK30M5rPFZSJxy25UofLEAlOrY+Hq+y5Cikk2+qR/T/P5h+BvJ5gaw1AczWM16Wax1O/d9S3BYy1GHHCytaIvdM7SWzDZY0h06BhSvLEe6Q9a/Sj1h9n2M4sVZR+zROibgWBaR0esL1HDYshSdnJyIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040219; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ouERXhFg7ctw5OaSYt/bZqEXdIR4bSp1DDI90gb5MGQ=; b=Jzme5CVPyssRqhWgt6PyrgQDUJPbPT5F4Yd6wFe9Y/ClhFTDNLLV41NduDDF4rgmHPoxlz/NsIpi/KSR23WJOoV5oIV3Nn2p9FQxf0njMiSkId+CEkbw+IlnpW+L8dYYB7ylPbOfG8p9sfKD/f1zG/frctF85fw1QAp+pSvbsRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040219673781.5978675672097; Fri, 29 Sep 2023 19:16:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWL-0000FP-5U; Fri, 29 Sep 2023 22:15:53 -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 1qmPWE-0000Cw-FI for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:48 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW7-0001zE-Dv for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:45 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-27740ce6c76so7673020a91.0 for ; Fri, 29 Sep 2023 19:15:38 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040137; x=1696644937; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ouERXhFg7ctw5OaSYt/bZqEXdIR4bSp1DDI90gb5MGQ=; b=a2u5zah1GknLt1Scgd+y0T5fWvaGZlVm04DxmbA99Iu6NjknTTaOH8d6DvEfrSYJQn eANlANGa2BqYqCIJTgzq7m1ODR1UaaInkThvRxyZB5gdK2fuI2njwmeg+uYOvxWxKuhR s6F1zvdhmJMRyZPufbSFC1VfkqrCawZfg85x5F963Ym4DVsy0RTgQxVd+pJHGfToCteQ nZBc3+m3rAt5SdBi3FQK3cMUMnNA3nREHemnyssXQEkMA/hzx8I6tFfeJTIU2e1a3gkk PkcqzhS8QAu0CoWnSlgQZLdKGEZRccahG32n38RUbPeG8eOt8QG8YqswewbkobuIV22k sP9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040137; x=1696644937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ouERXhFg7ctw5OaSYt/bZqEXdIR4bSp1DDI90gb5MGQ=; b=xK2EgH6QOP+UudWr322Mf8iyfKT73V08jua+KjZLF7NY+GdX4Y4Y9eDdqYi+PJz4ZJ yn0JtiZXLIXusS8kPaVcqWBo1UtMCS5DBzDDVmn+5/lRQk4YqqqN/+b7Uwd4afpAopYl RrzVhlj4K7gY4HhZaXckav8IV/v4VFDN4ha5cdFzs5K1ETv08vr/hA/kL8NTdN9QRol4 EqfJQ1DZGtvRhl8bc7Dm4oG/3Ze+N4+QDs9lIiJFz8vw5AAHd1rw17OGh5/S5HkbJ25+ 58hn6fnK46yPehKLWbUgqgsOP/mSDM/X1LOmZflKanbi7X2dY1FR59o9512QsbPa4tE1 11Rg== X-Gm-Message-State: AOJu0YzexV485zjVMMA5wr9dyr3DnfZOmgenup94+Iyvh4P3IbHXWdOs VEJHLzfjmIbScYCM3OrHljmVXBSn07ZjGfGRyrE= X-Google-Smtp-Source: AGHT+IFMqylJTvX7RGWQYUQvZn0yPlqocDaSFkBYcBTnBiRhT4dAJO4AcxPmKBcK8PNsxISaZr4qUA== X-Received: by 2002:a17:90a:17af:b0:273:ec96:b6f9 with SMTP id q44-20020a17090a17af00b00273ec96b6f9mr5739703pja.25.1696040136945; Fri, 29 Sep 2023 19:15:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 06/19] linux-user: Replace bprm->fd with bprm->src.fd Date: Fri, 29 Sep 2023 19:15:16 -0700 Message-Id: <20230930021529.987950-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040221829100003 There are only a couple of uses of bprm->fd remaining. Migrate to the other field. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/loader.h | 1 - linux-user/flatload.c | 8 ++++---- linux-user/linuxload.c | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/linux-user/loader.h b/linux-user/loader.h index da6591fff0..a0834290e7 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -74,7 +74,6 @@ struct linux_binprm { char buf[BPRM_BUF_SIZE] __attribute__((aligned)); ImageSource src; abi_ulong p; - int fd; int e_uid, e_gid; int argc, envc; char **argv; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 4331a11bf0..0811f32aaf 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -463,7 +463,7 @@ static int load_flat_file(struct linux_binprm * bprm, DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); =20 textpos =3D target_mmap(0, text_len, PROT_READ|PROT_EXEC, - MAP_PRIVATE, bprm->fd, 0); + MAP_PRIVATE, bprm->src.fd, 0); if (textpos =3D=3D -1) { fprintf(stderr, "Unable to mmap process text\n"); return -1; @@ -490,7 +490,7 @@ static int load_flat_file(struct linux_binprm * bprm, } else #endif { - result =3D target_pread(bprm->fd, datapos, + result =3D target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), fpos); } @@ -540,10 +540,10 @@ static int load_flat_file(struct linux_binprm * bprm, else #endif { - result =3D target_pread(bprm->fd, textpos, + result =3D target_pread(bprm->src.fd, textpos, text_len, 0); if (result >=3D 0) { - result =3D target_pread(bprm->fd, datapos, + result =3D target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), ntohl(hdr->data_start)); } diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 5b7e9ab983..4a794f8cea 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -39,7 +39,7 @@ static int prepare_binprm(struct linux_binprm *bprm) int mode; int retval; =20 - if (fstat(bprm->fd, &st) < 0) { + if (fstat(bprm->src.fd, &st) < 0) { return -errno; } =20 @@ -69,7 +69,7 @@ static int prepare_binprm(struct linux_binprm *bprm) bprm->e_gid =3D st.st_gid; } =20 - retval =3D read(bprm->fd, bprm->buf, BPRM_BUF_SIZE); + retval =3D read(bprm->src.fd, bprm->buf, BPRM_BUF_SIZE); if (retval < 0) { perror("prepare_binprm"); exit(-1); @@ -144,7 +144,6 @@ int loader_exec(int fdexec, const char *filename, char = **argv, char **envp, { int retval; =20 - bprm->fd =3D fdexec; bprm->src.fd =3D fdexec; bprm->filename =3D (char *)filename; bprm->argc =3D count(argv); --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040289; cv=none; d=zohomail.com; s=zohoarc; b=YJ0CaGvaEgdnXinzJ/YmKVdfJSioZHZIJaqZXObwWdvSmqYsZzAjjLfXN3I/3YHtLh0d1n+sr4KIwef/SrOgXNVVxjHlHvhrZ4zKsTLbHHNm3SaIWVYxIvSR/eReMTIlKYc3uD/LVyEB5jggbtShB4vpHyIc7C/rDx7cUUpLHfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040289; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kBtp0SzKAXBPku+nusoqYBCwaytEH/E/j+wssjalB2E=; b=gCJgCDLQ10rS87h1/iRt79Y6u3KudzMwYnMO2LeIgzXCJnBNcb734LaO2mI/zoN5BEP3UJovcnyOZU36Qj6Az5rsBUJbHpnf8CWzlVul7Cb/o3uPgrx1tuWwSOodwTGzCENKG8oXPZqBiPYZYoSsPSxquHTddlsZgRXj0y/rKGw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040289215436.8866622015331; Fri, 29 Sep 2023 19:18:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWI-0000Em-Ij; Fri, 29 Sep 2023 22:15:50 -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 1qmPWD-0000Cu-RT for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:46 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW7-0001zL-E1 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:45 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-27752a1e180so8110472a91.1 for ; Fri, 29 Sep 2023 19:15:38 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040138; x=1696644938; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kBtp0SzKAXBPku+nusoqYBCwaytEH/E/j+wssjalB2E=; b=zBj0WiQ+agYpsHiOYYjw0TCYPxz1tDuNC2flpaDyd4jdkhb+U6AiGFsa7Pcg4BxQ4q emP/Ewh/igogsGENLLwCEn6RVJcKyNTtKSPVuIwI4GW2xGT5FiYJMdq5PsjoDTu/H17t mnkaOoMnnhIQFUgGPREvWUamSKrDoKwoxsY9BbQ2oAjtrY72H6fcisOvWaazKAuSRN5n RBx1Yw4zc/Iy1aI8x6TvLCTgqIHIQunByuRg63Fx/8vWbrf5EVf164pjVMvi6CaL1l5N qZ8iRLyLvTQm3WfNQwcAt2obyv5ZDJUlNOPQbk3mMr17BCV5k+DWZiCdv+1e+tyTc0zg umvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040138; x=1696644938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kBtp0SzKAXBPku+nusoqYBCwaytEH/E/j+wssjalB2E=; b=arTT/6JY82IkLsK9uC9kcYAsIS0Qsn4cwmkQsCASwQWIvoafbOBqCPrOnccLlSkQbn quCzpz9QR2LZZdmD7MvWmd/aHlaFwHRWya6W3xFZtPhmpMj40aWGnZ94FBuYb1TPrio7 yLo5LcIwpiCSp4FSjGtfURmbsMSLW5AeO0WsM3xHIrfTLFzbBSBgDxjocQKYwP3aHeBm 3JkdtPs0u/3uU0E5RaykTmiK98CWS/4KqE8ErqtuaBHKTop4a0VVjEWu886x1c//0aZE kM8OZ+57ctOAHzd/2H7Vj+ap4UlRpps6HdZdJWtXUr42Q0PhAXc8N+GuOreyAruuZMZf 2yvg== X-Gm-Message-State: AOJu0Yze0/HaUgBAonogGYLo6THr2t86YX38RhDKHrBhNwD3ac8E9Bpf geSES/xe4TX8c7Xs+RajsdkCyhBnNifHw2CdlCY= X-Google-Smtp-Source: AGHT+IGNOqy4+VEf4whtltaon80lHFXjg0pmT5A5RKo19UiOCCjHZU26sOmrFJmRlXiBP1zH6EBm6w== X-Received: by 2002:a17:90b:34c:b0:274:6f67:e7a8 with SMTP id fh12-20020a17090b034c00b002746f67e7a8mr5648465pjb.45.1696040137772; Fri, 29 Sep 2023 19:15:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 07/19] linux-user: Load vdso image if available Date: Fri, 29 Sep 2023 19:15:17 -0700 Message-Id: <20230930021529.987950-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040290798100002 Content-Type: text/plain; charset="utf-8" The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/elfload.c | 90 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ed276edb3c..9c97d14b7e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -33,6 +33,19 @@ #undef ELF_ARCH #endif =20 +#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 +#endif + +typedef struct { + const uint8_t *image; + const uint32_t *relocs; + unsigned image_size; + unsigned reloc_count; + unsigned sigreturn_ofs; + unsigned rt_sigreturn_ofs; +} VdsoImageInfo; + #define ELF_OSABI ELFOSABI_SYSV =20 /* from personality.h */ @@ -2436,7 +2449,8 @@ static abi_ulong loader_build_fdpic_loadmap(struct im= age_info *info, abi_ulong s static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, struct elfhdr *exec, struct image_info *info, - struct image_info *interp_info) + struct image_info *interp_info, + struct image_info *vdso_info) { abi_ulong sp; abi_ulong u_argc, u_argv, u_envp, u_auxv; @@ -2524,10 +2538,15 @@ static abi_ulong create_elf_tables(abi_ulong p, int= argc, int envc, } =20 size =3D (DLINFO_ITEMS + 1) * 2; - if (k_base_platform) + if (k_base_platform) { size +=3D 2; - if (k_platform) + } + if (k_platform) { size +=3D 2; + } + if (vdso_info) { + size +=3D 2; + } #ifdef DLINFO_ARCH_ITEMS size +=3D DLINFO_ARCH_ITEMS * 2; #endif @@ -2609,6 +2628,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int a= rgc, int envc, if (u_platform) { NEW_AUX_ENT(AT_PLATFORM, u_platform); } + if (vdso_info) { + NEW_AUX_ENT(AT_SYSINFO_EHDR, vdso_info->load_addr); + } NEW_AUX_ENT (AT_NULL, 0); #undef NEW_AUX_ENT =20 @@ -3486,6 +3508,52 @@ static void load_elf_interp(const char *filename, st= ruct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } =20 +#ifdef VDSO_HEADER +#include VDSO_HEADER +#define vdso_image_info() &vdso_image_info +#else +#define vdso_image_info() NULL +#endif + +static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vd= so) +{ + ImageSource src; + struct elfhdr ehdr; + abi_ulong load_bias, load_addr; + + src.fd =3D -1; + src.cache =3D vdso->image; + src.cache_size =3D vdso->image_size; + + load_elf_image("", &src, info, &ehdr, NULL); + load_addr =3D info->load_addr; + load_bias =3D info->load_bias; + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one built for QEMU is not, since + * that requires close control of the guest address space. + * We pre-processed the image to locate all of the addresses that need + * to be updated. + */ + for (unsigned i =3D 0, n =3D vdso->reloc_count; i < n; i++) { + abi_ulong *addr =3D g2h_untagged(load_addr + vdso->relocs[i]); + *addr =3D tswapal(tswapal(*addr) + load_bias); + } + + /* Install signal trampolines, if present. */ + if (vdso->sigreturn_ofs) { + default_sigreturn =3D load_addr + vdso->sigreturn_ofs; + } + if (vdso->rt_sigreturn_ofs) { + default_rt_sigreturn =3D load_addr + vdso->rt_sigreturn_ofs; + } + + /* Remove write from VDSO segment. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ | PROT_EXEC); +} + static int symfind(const void *s0, const void *s1) { struct elf_sym *sym =3D (struct elf_sym *)s1; @@ -3691,7 +3759,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) * and let elf_load_image do any swapping that may be required. */ struct elfhdr ehdr; - struct image_info interp_info; + struct image_info interp_info, vdso_info; char *elf_interpreter =3D NULL; char *scratch; =20 @@ -3772,10 +3840,13 @@ int load_elf_binary(struct linux_binprm *bprm, stru= ct image_info *info) } =20 /* - * TODO: load a vdso, which would also contain the signal trampolines. - * Otherwise, allocate a private page to hold them. + * Load a vdso if available, which will amongst other things contain t= he + * signal trampolines. Otherwise, allocate a separate page for them. */ - if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { + const VdsoImageInfo *vdso =3D vdso_image_info(); + if (vdso) { + load_elf_vdso(&vdso_info, vdso); + } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { abi_long tramp_page =3D target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -3787,8 +3858,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXE= C); } =20 - bprm->p =3D create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, - info, (elf_interpreter ? &interp_info : NU= LL)); + bprm->p =3D create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, = info, + elf_interpreter ? &interp_info : NULL, + vdso ? &vdso_info : NULL); info->start_stack =3D bprm->p; =20 /* If we have an interpreter, set that as the program's entry point. --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040249; cv=none; d=zohomail.com; s=zohoarc; b=e3KBjCcccfOgNLjfU2vrsd8iUPX8/wwiLsgWnhWuhUjeNug7hHncoKZhBD53Q81vpX0EC9l2BsYjGEc8/HzJDp775vSrvvf4MRxf/G+uNM/cD9fB/W2+5BYsXDDLIMunn+rZ2kSREUG1Hxn5gjY0xTMBKKwD90vmegy82/kJzHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040249; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; b=Mxawn0EGLQ45E1e67FiL6k5xsxSickLBMIs4ASuCCtw0XzgFo14iXxTaK6/eFfSNO9zGCbjlXDt/AxySREfgXlmGfoCc06xiyw5M7kGfcgeb+W5VDilGZK7HiHwsKJuWFeNGeHViNwexhTeeUOjf+6+yhlkBn4b3Bf7u+l9z8zs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040249059971.7115057180482; Fri, 29 Sep 2023 19:17:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWV-0000OS-Ns; Fri, 29 Sep 2023 22:16:03 -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 1qmPWQ-0000Ih-Qu for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:58 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW8-0001zS-BG for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:58 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c1ff5b741cso133471705ad.2 for ; Fri, 29 Sep 2023 19:15:39 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040139; x=1696644939; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; b=n1J3cL1pPfHcisHgOYr5mcw5yFpHkFTwqYtaXbZR7euFYaGZ7R4E0Dow/zDE/uJOSp B0MSxca3Cw5H5E5hPPI9nCpJGX5DiGzPMc4BoO+cirpexaetNUgKafGuvit9N8HTCvYG 3BSYj609r1tjSamMy9FGcU2k9x5hs2zazzfhH/kGr0hJRynFr4/4OJNzeZYc5/qme7Wf 0L1AtQ0RWeOOa8yer6CKLveh+NDGsvD1Rgtp7yWy8F2J358B4RWVpXbCb1hPkitCqMVM dvvEpbE49DU6mDqTrT9F+Lb2tK1dollyoWWF+e4U/itP0aAiHy/O+mfHNfbvDi1MPP8L dDOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040139; x=1696644939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; b=pCyocWkBFUQxcyIdIlNfDgKlAKTauE+MQXD4TdnIrquKA2EYd0FFSVOPivichsAOcL z49NBkolWo9cZJrffGv3skFW9eRMvt1ptZ7v+GZ10jIxQvCfQONNdniTIUfQwHAWDEm0 6XjsJOToqZXRkNFDeLd0+Z99NGQ8Rra6DV3hyzkVySoQ/trI7WiAFgSi82sOXIDxeINn O2akg/oWdYEG1IAWHuHLBxlpwyxpvOx6+yEO0xObK6JiVyll0Q0YDfzeKo2gGMRZQJwr qleCR4iutIH7mHha8h5I37k3WOWwjKIqMv/eKBmMtcU4pFiG/GZTyEF4RvwHEPkwDGfB OWFQ== X-Gm-Message-State: AOJu0YyPkKIXDZUAdWNUIAQWSaKDXYcm8XjqntX75UYFkWkNleJ6xvNB Q/rmXA3mnMqjwnMMid/5zWlru3PdINLat9VGkRc= X-Google-Smtp-Source: AGHT+IFLxpcQEgZo2zxdnib/zW9m3c6ldiz/vL6Eue5wqqo/doaR6lT56xnPNt5TlKeid7O34W1/2Q== X-Received: by 2002:a05:6a20:5607:b0:157:eb32:e739 with SMTP id ir7-20020a056a20560700b00157eb32e739mr5591115pzc.32.1696040138684; Fri, 29 Sep 2023 19:15:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 08/19] linux-user: Add gen-vdso tool Date: Fri, 29 Sep 2023 19:15:18 -0700 Message-Id: <20230930021529.987950-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040250167100003 Content-Type: text/plain; charset="utf-8" This tool will be used for post-processing the linked vdso image, turning it into something that is easy to include into elfload.c. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/gen-vdso.c | 223 ++++++++++++++++++++++++ linux-user/gen-vdso-elfn.c.inc | 307 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 linux-user/gen-vdso.c create mode 100644 linux-user/gen-vdso-elfn.c.inc diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c new file mode 100644 index 0000000000..a6c61d2f6e --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,223 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "elf.h" + + +#define bswap_(p) _Generic(*(p), \ + uint16_t: __builtin_bswap16, \ + uint32_t: __builtin_bswap32, \ + uint64_t: __builtin_bswap64, \ + int16_t: __builtin_bswap16, \ + int32_t: __builtin_bswap32, \ + int64_t: __builtin_bswap64) +#define bswaps(p) (*(p) =3D bswap_(p)(*(p))) + +static void output_reloc(FILE *outf, void *buf, void *loc) +{ + fprintf(outf, " 0x%08lx,\n", (unsigned long)(loc - buf)); +} + +static const char *sigreturn_sym; +static const char *rt_sigreturn_sym; + +static unsigned sigreturn_addr; +static unsigned rt_sigreturn_addr; + +#define N 32 +#define elfN(x) elf32_##x +#define ElfN(x) Elf32_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + +#define N 64 +#define elfN(x) elf64_##x +#define ElfN(x) Elf64_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + + +int main(int argc, char **argv) +{ + FILE *inf, *outf; + long total_len; + const char *prefix =3D "vdso"; + const char *inf_name; + const char *outf_name =3D NULL; + unsigned char *buf; + bool need_bswap; + + while (1) { + int opt =3D getopt(argc, argv, "o:p:r:s:"); + if (opt < 0) { + break; + } + switch (opt) { + case 'o': + outf_name =3D optarg; + break; + case 'p': + prefix =3D optarg; + break; + case 'r': + rt_sigreturn_sym =3D optarg; + break; + case 's': + sigreturn_sym =3D optarg; + break; + default: + usage: + fprintf(stderr, "usage: [-p prefix] [-r rt-sigreturn-name] " + "[-s sigreturn-name] -o output-file input-file\n"); + return EXIT_FAILURE; + } + } + + if (optind >=3D argc || outf_name =3D=3D NULL) { + goto usage; + } + inf_name =3D argv[optind]; + + /* + * Open the input and output files. + */ + inf =3D fopen(inf_name, "rb"); + if (inf =3D=3D NULL) { + goto perror_inf; + } + outf =3D fopen(outf_name, "w"); + if (outf =3D=3D NULL) { + goto perror_outf; + } + + /* + * Read the input file into a buffer. + * We expect the vdso to be small, on the order of one page, + * therefore we do not expect a partial read. + */ + fseek(inf, 0, SEEK_END); + total_len =3D ftell(inf); + fseek(inf, 0, SEEK_SET); + + buf =3D malloc(total_len); + if (buf =3D=3D NULL) { + goto perror_inf; + } + + errno =3D 0; + if (fread(buf, 1, total_len, inf) !=3D total_len) { + if (errno) { + goto perror_inf; + } + fprintf(stderr, "%s: incomplete read\n", inf_name); + return EXIT_FAILURE; + } + fclose(inf); + + /* + * Write out the vdso image now, before we make local changes. + */ + + fprintf(outf, + "/* Automatically generated from linux-user/gen-vdso.c. */\n" + "\n" + "static const uint8_t %s_image[] =3D {", + prefix); + for (long i =3D 0; i < total_len; ++i) { + if (i % 12 =3D=3D 0) { + fputs("\n ", outf); + } + fprintf(outf, " 0x%02x,", buf[i]); + } + fprintf(outf, "\n};\n\n"); + + /* + * Identify which elf flavor we're processing. + * The first 16 bytes of the file are e_ident. + */ + + if (buf[EI_MAG0] !=3D ELFMAG0 || buf[EI_MAG1] !=3D ELFMAG1 || + buf[EI_MAG2] !=3D ELFMAG2 || buf[EI_MAG3] !=3D ELFMAG3) { + fprintf(stderr, "%s: not an elf file\n", inf_name); + return EXIT_FAILURE; + } + switch (buf[EI_DATA]) { + case ELFDATA2LSB: + need_bswap =3D BYTE_ORDER !=3D LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + need_bswap =3D BYTE_ORDER !=3D BIG_ENDIAN; + break; + default: + fprintf(stderr, "%s: invalid elf EI_DATA (%u)\n", + inf_name, buf[EI_DATA]); + return EXIT_FAILURE; + } + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one we built for QEMU is not, + * since that requires close control of the guest address space. + * + * Output relocation addresses as we go. + */ + + fprintf(outf, "static const unsigned %s_relocs[] =3D {\n", prefix); + + switch (buf[EI_CLASS]) { + case ELFCLASS32: + elf32_process(outf, buf, need_bswap); + break; + case ELFCLASS64: + elf64_process(outf, buf, need_bswap); + break; + default: + fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n", + inf_name, buf[EI_CLASS]); + return EXIT_FAILURE; + } + + fprintf(outf, "};\n\n"); /* end vdso_relocs. */ + + fprintf(outf, "static const VdsoImageInfo %s_image_info =3D {\n", pref= ix); + fprintf(outf, " .image =3D %s_image,\n", prefix); + fprintf(outf, " .relocs =3D %s_relocs,\n", prefix); + fprintf(outf, " .image_size =3D sizeof(%s_image),\n", prefix); + fprintf(outf, " .reloc_count =3D ARRAY_SIZE(%s_relocs),\n", prefix); + fprintf(outf, " .sigreturn_ofs =3D 0x%x,\n", sigreturn_addr); + fprintf(outf, " .rt_sigreturn_ofs =3D 0x%x,\n", rt_sigreturn_addr); + fprintf(outf, "};\n"); + + /* + * Everything should have gone well. + */ + if (fclose(outf)) { + goto perror_outf; + } + return EXIT_SUCCESS; + + perror_inf: + perror(inf_name); + return EXIT_FAILURE; + + perror_outf: + perror(outf_name); + return EXIT_FAILURE; +} diff --git a/linux-user/gen-vdso-elfn.c.inc b/linux-user/gen-vdso-elfn.c.inc new file mode 100644 index 0000000000..7034c36d5e --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,307 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +static void elfN(bswap_ehdr)(ElfN(Ehdr) *ehdr) +{ + bswaps(&ehdr->e_type); /* Object file type */ + bswaps(&ehdr->e_machine); /* Architecture */ + bswaps(&ehdr->e_version); /* Object file version */ + bswaps(&ehdr->e_entry); /* Entry point virtual address */ + bswaps(&ehdr->e_phoff); /* Program header table file offset = */ + bswaps(&ehdr->e_shoff); /* Section header table file offset = */ + bswaps(&ehdr->e_flags); /* Processor-specific flags */ + bswaps(&ehdr->e_ehsize); /* ELF header size in bytes */ + bswaps(&ehdr->e_phentsize); /* Program header table entry size */ + bswaps(&ehdr->e_phnum); /* Program header table entry count = */ + bswaps(&ehdr->e_shentsize); /* Section header table entry size */ + bswaps(&ehdr->e_shnum); /* Section header table entry count = */ + bswaps(&ehdr->e_shstrndx); /* Section header string table index= */ +} + +static void elfN(bswap_phdr)(ElfN(Phdr) *phdr) +{ + bswaps(&phdr->p_type); /* Segment type */ + bswaps(&phdr->p_flags); /* Segment flags */ + bswaps(&phdr->p_offset); /* Segment file offset */ + bswaps(&phdr->p_vaddr); /* Segment virtual address */ + bswaps(&phdr->p_paddr); /* Segment physical address */ + bswaps(&phdr->p_filesz); /* Segment size in file */ + bswaps(&phdr->p_memsz); /* Segment size in memory */ + bswaps(&phdr->p_align); /* Segment alignment */ +} + +static void elfN(bswap_shdr)(ElfN(Shdr) *shdr) +{ + bswaps(&shdr->sh_name); + bswaps(&shdr->sh_type); + bswaps(&shdr->sh_flags); + bswaps(&shdr->sh_addr); + bswaps(&shdr->sh_offset); + bswaps(&shdr->sh_size); + bswaps(&shdr->sh_link); + bswaps(&shdr->sh_info); + bswaps(&shdr->sh_addralign); + bswaps(&shdr->sh_entsize); +} + +static void elfN(bswap_sym)(ElfN(Sym) *sym) +{ + bswaps(&sym->st_name); + bswaps(&sym->st_value); + bswaps(&sym->st_size); + bswaps(&sym->st_shndx); +} + +static void elfN(bswap_dyn)(ElfN(Dyn) *dyn) +{ + bswaps(&dyn->d_tag); /* Dynamic type tag */ + bswaps(&dyn->d_un.d_ptr); /* Dynamic ptr or val, in union */ +} + +static void elfN(search_symtab)(ElfN(Shdr) *shdr, unsigned sym_idx, + void *buf, bool need_bswap) +{ + unsigned str_idx =3D shdr[sym_idx].sh_link; + ElfN(Sym) *sym =3D buf + shdr[sym_idx].sh_offset; + unsigned sym_n =3D shdr[sym_idx].sh_size / sizeof(*sym); + const char *str =3D buf + shdr[str_idx].sh_offset; + + for (unsigned i =3D 0; i < sym_n; ++i) { + const char *name; + + if (need_bswap) { + elfN(bswap_sym)(sym + i); + } + name =3D str + sym[i].st_name; + + if (sigreturn_sym && strcmp(sigreturn_sym, name) =3D=3D 0) { + sigreturn_addr =3D sym[i].st_value; + } + if (rt_sigreturn_sym && strcmp(rt_sigreturn_sym, name) =3D=3D 0) { + rt_sigreturn_addr =3D sym[i].st_value; + } + } +} + +static void elfN(process)(FILE *outf, void *buf, bool need_bswap) +{ + ElfN(Ehdr) *ehdr =3D buf; + ElfN(Phdr) *phdr; + ElfN(Shdr) *shdr; + unsigned phnum, shnum; + unsigned dynamic_ofs =3D 0; + unsigned dynamic_addr =3D 0; + unsigned symtab_idx =3D 0; + unsigned dynsym_idx =3D 0; + unsigned first_segsz =3D 0; + int errors =3D 0; + + if (need_bswap) { + elfN(bswap_ehdr)(ehdr); + } + + phnum =3D ehdr->e_phnum; + phdr =3D buf + ehdr->e_phoff; + if (need_bswap) { + for (unsigned i =3D 0; i < phnum; ++i) { + elfN(bswap_phdr)(phdr + i); + } + } + + shnum =3D ehdr->e_shnum; + shdr =3D buf + ehdr->e_shoff; + if (need_bswap) { + for (unsigned i =3D 0; i < shnum; ++i) { + elfN(bswap_shdr)(shdr + i); + } + } + for (unsigned i =3D 0; i < shnum; ++i) { + switch (shdr[i].sh_type) { + case SHT_SYMTAB: + symtab_idx =3D i; + break; + case SHT_DYNSYM: + dynsym_idx =3D i; + break; + } + } + + /* + * Validate the VDSO is created as we expect: that PT_PHDR, + * PT_DYNAMIC, and PT_NOTE located in a writable data segment. + * PHDR and DYNAMIC require relocation, and NOTE will get the + * linux version number. + */ + for (unsigned i =3D 0; i < phnum; ++i) { + if (phdr[i].p_type !=3D PT_LOAD) { + continue; + } + if (first_segsz !=3D 0) { + fprintf(stderr, "Multiple LOAD segments\n"); + errors++; + } + if (phdr[i].p_offset !=3D 0) { + fprintf(stderr, "LOAD segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr !=3D 0) { + fprintf(stderr, "LOAD segment not loaded at address 0\n"); + errors++; + } + first_segsz =3D phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "LOAD segment does not cover PHDRs\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) !=3D (PF_R | PF_W)) { + fprintf(stderr, "LOAD segment is not read-write\n"); + errors++; + } + } + for (unsigned i =3D 0; i < phnum; ++i) { + const char *which; + + switch (phdr[i].p_type) { + case PT_PHDR: + which =3D "PT_PHDR"; + break; + case PT_NOTE: + which =3D "PT_NOTE"; + break; + case PT_DYNAMIC: + dynamic_ofs =3D phdr[i].p_offset; + dynamic_addr =3D phdr[i].p_vaddr; + which =3D "PT_DYNAMIC"; + break; + default: + continue; + } + if (first_segsz < phdr[i].p_vaddr + phdr[i].p_filesz) { + fprintf(stderr, "LOAD segment does not cover %s\n", which); + errors++; + } + } + if (errors) { + exit(EXIT_FAILURE); + } + + /* Relocate the program headers. */ + for (unsigned i =3D 0; i < phnum; ++i) { + output_reloc(outf, buf, &phdr[i].p_vaddr); + output_reloc(outf, buf, &phdr[i].p_paddr); + } + + /* Relocate the DYNAMIC entries. */ + if (dynamic_addr) { + ElfN(Dyn) *dyn =3D buf + dynamic_ofs; + __typeof(dyn->d_tag) tag; + + do { + + if (need_bswap) { + elfN(bswap_dyn)(dyn); + } + tag =3D dyn->d_tag; + + switch (tag) { + case DT_HASH: + case DT_SYMTAB: + case DT_STRTAB: + case DT_VERDEF: + case DT_VERSYM: + case DT_PLTGOT: + case DT_ADDRRNGLO ... DT_ADDRRNGHI: + /* These entries store an address in the entry. */ + output_reloc(outf, buf, &dyn->d_un.d_val); + break; + + case DT_NULL: + case DT_STRSZ: + case DT_SONAME: + case DT_DEBUG: + case DT_FLAGS: + case DT_FLAGS_1: + case DT_SYMBOLIC: + case DT_BIND_NOW: + case DT_VERDEFNUM: + case DT_VALRNGLO ... DT_VALRNGHI: + /* These entries store an integer in the entry. */ + break; + + case DT_SYMENT: + if (dyn->d_un.d_val !=3D sizeof(ElfN(Sym))) { + fprintf(stderr, "VDSO has incorrect dynamic symbol siz= e\n"); + errors++; + } + break; + + case DT_REL: + case DT_RELSZ: + case DT_RELA: + case DT_RELASZ: + /* + * These entries indicate that the VDSO was built incorrec= tly. + * It should not have any real relocations. + * ??? The RISC-V toolchain will emit these even when there + * are no relocations. Validate zeros. + */ + if (dyn->d_un.d_val !=3D 0) { + fprintf(stderr, "VDSO has dynamic relocations\n"); + errors++; + } + break; + case DT_RELENT: + case DT_RELAENT: + case DT_TEXTREL: + /* These entries store an integer in the entry. */ + /* Should not be required; see above. */ + break; + + case DT_NEEDED: + case DT_VERNEED: + case DT_PLTREL: + case DT_JMPREL: + case DT_RPATH: + case DT_RUNPATH: + fprintf(stderr, "VDSO has external dependencies\n"); + errors++; + break; + + default: + /* This is probably something target specific. */ + fprintf(stderr, "VDSO has unknown DYNAMIC entry (%lx)\n", + (unsigned long)tag); + errors++; + break; + } + dyn++; + } while (tag !=3D DT_NULL); + if (errors) { + exit(EXIT_FAILURE); + } + } + + /* Relocate the dynamic symbol table. */ + if (dynsym_idx) { + ElfN(Sym) *sym =3D buf + shdr[dynsym_idx].sh_offset; + unsigned sym_n =3D shdr[dynsym_idx].sh_size / sizeof(*sym); + + for (unsigned i =3D 0; i < sym_n; ++i) { + output_reloc(outf, buf, &sym[i].st_value); + } + } + + /* Search both dynsym and symtab for the signal return symbols. */ + if (dynsym_idx) { + elfN(search_symtab)(shdr, dynsym_idx, buf, need_bswap); + } + if (symtab_idx) { + elfN(search_symtab)(shdr, symtab_idx, buf, need_bswap); + } +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 7171dc60be..e4cb70ed2d 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -28,9 +28,13 @@ linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: file= s('flatload.c')) linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c')) linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: file= s('semihost.c')) =20 - syscall_nr_generators =3D {} =20 +gen_vdso_exe =3D executable('gen-vdso', 'gen-vdso.c', + native: true, build_by_default: false) +gen_vdso =3D generator(gen_vdso_exe, output: '@BASENAME@.c.inc', + arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT= @']) + subdir('alpha') subdir('arm') subdir('hppa') --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040241; cv=none; d=zohomail.com; s=zohoarc; b=OOSfiUFXQXiIyBxl3ZIk2NR3B4YyjFQcfsSob6xFhoxJhdgUS0UnrKzHG13Ha0KT627lvMmnrWTRijdzGcBZ/K6+FndSYEm57whuk6PQEEDYoZUDlIX605r5qSBl8WPsG/gdpPEgGEfI7Tj5p45Bh+kXt6HIj1Dvhu0xZkZdAFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040241; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uSW32o6XKf+SAPuywPBg7GQDnFcB1zH8mByaGKpZjrE=; b=apjSiabdi5cGZ7wMoxX4T29raD2/lRu5nQFChDq0moeVEY7K1uVbKO4LNOTrxEsEzDswJgh9dzhAJeTFKcLBkiGNi9vBImGJlXcQkejXznKc55uSi9iSqwsoDwPSsDpG5nnYMsxubLfNxlO6dzqAdRTzrOPIcfWoDHHNErLfB+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040241950899.3044957785891; Fri, 29 Sep 2023 19:17:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWT-0000Jy-1T; Fri, 29 Sep 2023 22:16:01 -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 1qmPWQ-0000I5-SX for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:58 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW9-0001zY-8P for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:57 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-27752a1e184so8968604a91.3 for ; Fri, 29 Sep 2023 19:15:40 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040140; x=1696644940; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uSW32o6XKf+SAPuywPBg7GQDnFcB1zH8mByaGKpZjrE=; b=Uv99SVHSRC7gBusld7IyvIw45LVTNBkivD/XJMsC7RG0nSoyyY9cYb8GDtKAp57SM3 tCS1HAxjxC4rxUqMnNP39DyqtSrkAwn+PT+/umI0xy47LQdHsM+tJInEZaZFqJqfzVos gg74l3IEkUGp6OCkmaY0tI2cMhh0tXa9WXmhMwPukBEeweSOlJLGIyDtofDXzLECI/A/ TDqfk/AQCpgjISpoTSAcrk3X9d118CvtMWpwenFjrLpI4dmaLpfNP9MbZV7INVhChPVw MVifeK7+fGeNO06L+oKECcT/tM/K5fUu4Ul11dgwNiZ6daga9QDBXQkTOUy3GPXkD58q ErPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040140; x=1696644940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uSW32o6XKf+SAPuywPBg7GQDnFcB1zH8mByaGKpZjrE=; b=lb4L7l84yl04woxd7dcvx/JCekZkBcxqMArYRfnzTzrl6YmQhHqBQOPG0CQkQXDNhU ALZZFVufog05gb842Gwm+YZfwWziTKtzpQBMSWFDmfFTWPUXzlhnr3jbFdgQ78GcBLPX /tVVK0f2D7Kc1e+kE1x5nRiV7y4UWmebW4KY86nT6I49MNh6OVYoIAf0BVWnxLckZwxy nVXSQoR7rYKbLztHYBCwUUygTew7wcp1tGtmADq+ptAxflrD8EbCylCPKCa7AE6g8wg7 iStok4VwKlYrs+YVNDKnRvjvxPILpkLCDSWNSBMXMwB73+vfwCCdFtzUES1AfnV+8aZn IJoA== X-Gm-Message-State: AOJu0YyI0CmqjoDZ2AOnQN52XCRATj80dWuOiYNGdr7zq2/VexEUJDUd M3/jOU3fN6cIN64KbHQIYbGzMtI6ob0Ah6LSap4= X-Google-Smtp-Source: AGHT+IGayKFi2J9Alf8pXCN/cTAGDEs3lCge9yGoiFhAUXAtEx8LyN/x7WuBfxLaL6OR4LEk24Iskw== X-Received: by 2002:a17:90a:fb50:b0:267:909f:3719 with SMTP id iq16-20020a17090afb5000b00267909f3719mr5723260pjb.19.1696040139700; Fri, 29 Sep 2023 19:15:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 09/19] linux-user/i386: Add vdso Date: Fri, 29 Sep 2023 19:15:19 -0700 Message-Id: <20230930021529.987950-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040244085100003 Content-Type: text/plain; charset="utf-8" Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1267 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/i386/vdso-asmoffset.h | 6 ++ linux-user/elfload.c | 19 +++- linux-user/i386/signal.c | 11 +++ linux-user/i386/Makefile.vdso | 11 +++ linux-user/i386/meson.build | 7 ++ linux-user/i386/vdso.S | 143 +++++++++++++++++++++++++++++++ linux-user/i386/vdso.ld | 76 ++++++++++++++++ linux-user/i386/vdso.so | Bin 0 -> 2672 bytes 8 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 linux-user/i386/vdso-asmoffset.h create mode 100644 linux-user/i386/Makefile.vdso create mode 100644 linux-user/i386/vdso.S create mode 100644 linux-user/i386/vdso.ld create mode 100755 linux-user/i386/vdso.so diff --git a/linux-user/i386/vdso-asmoffset.h b/linux-user/i386/vdso-asmoff= set.h new file mode 100644 index 0000000000..4e5ee0dd49 --- /dev/null +++ b/linux-user/i386/vdso-asmoffset.h @@ -0,0 +1,6 @@ +/* + * offsetof(struct sigframe, sc.eip) + * offsetof(struct rt_sigframe, uc.tuc_mcontext.eip) + */ +#define SIGFRAME_SIGCONTEXT_eip 64 +#define RT_SIGFRAME_SIGCONTEXT_eip 220 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 9c97d14b7e..314ae7cacf 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -305,12 +305,27 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUX86State *en (*regs)[15] =3D tswapreg(env->regs[R_ESP]); (*regs)[16] =3D tswapreg(env->segs[R_SS].selector & 0xffff); } -#endif + +/* + * i386 is the only target which supplies AT_SYSINFO for the vdso. + * All others only supply AT_SYSINFO_EHDR. + */ +#define DLINFO_ARCH_ITEMS (vdso_info !=3D NULL) +#define ARCH_DLINFO \ + do { \ + if (vdso_info) { \ + NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); \ + } \ + } while (0) + +#define VDSO_HEADER "vdso.c.inc" + +#endif /* TARGET_X86_64 */ =20 #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 -#endif +#endif /* TARGET_I386 */ =20 #ifdef TARGET_ARM =20 diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 60fa07d6f9..bc5d45302e 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -214,6 +214,17 @@ struct rt_sigframe { }; #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET ( = \ offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) + +/* + * Verify that vdso-asmoffset.h constants match. + */ +#include "i386/vdso-asmoffset.h" + +QEMU_BUILD_BUG_ON(offsetof(struct sigframe, sc.eip) + !=3D SIGFRAME_SIGCONTEXT_eip); +QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, uc.tuc_mcontext.eip) + !=3D RT_SIGFRAME_SIGCONTEXT_eip); + #else =20 struct rt_sigframe { diff --git a/linux-user/i386/Makefile.vdso b/linux-user/i386/Makefile.vdso new file mode 100644 index 0000000000..95bc616f6d --- /dev/null +++ b/linux-user/i386/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/i386-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/i386 +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ -m32 -nostdlib -shared -Wl,-h,linux-gate.so.1 \ + -Wl,--build-id=3Dsha1 -Wl,--hash-style=3Dboth \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/i386/meson.build b/linux-user/i386/meson.build index ee523019a5..d42fc6cbc9 100644 --- a/linux-user/i386/meson.build +++ b/linux-user/i386/meson.build @@ -3,3 +3,10 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr.= sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc =3D gen_vdso.process('vdso.so', extra_args: [ + '-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn' + ]) + +linux_user_ss.add(when: 'TARGET_I386', if_true: vdso_inc) diff --git a/linux-user/i386/vdso.S b/linux-user/i386/vdso.S new file mode 100644 index 0000000000..e7a1f333a1 --- /dev/null +++ b/linux-user/i386/vdso.S @@ -0,0 +1,143 @@ +/* + * i386 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 vdso_syscall1 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall2 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall3 name, nr +\name: + .cfi_startproc + push %ebx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset %ebx, 0 + mov 8(%esp), %ebx + mov 12(%esp), %ecx + mov 16(%esp), %edx + mov $\nr, %eax + int $0x80 + pop %ebx + .cfi_adjust_cfa_offset -4 + .cfi_restore %ebx + ret + .cfi_endproc +endf \name +.endm + +__kernel_vsyscall: + .cfi_startproc + int $0x80 + ret + .cfi_endproc +endf __kernel_vsyscall + +vdso_syscall2 __vdso_clock_gettime, __NR_clock_gettime +vdso_syscall2 __vdso_clock_gettime64, __NR_clock_gettime64 +vdso_syscall2 __vdso_clock_getres, __NR_clock_getres +vdso_syscall2 __vdso_gettimeofday, __NR_gettimeofday +vdso_syscall1 __vdso_time, __NR_time +vdso_syscall3 __vdso_getcpu, __NR_gettimeofday + +/* + * Signal return handlers. + */ + + .cfi_startproc simple + .cfi_signal_frame + +/* + * For convenience, put the cfa just above eip in sigcontext, and count + * offsets backward from there. Re-compute the cfa in the two contexts + * we have for signal unwinding. This is far simpler than the + * DW_CFA_expression form that the kernel uses, and is equally correct. + */ + + .cfi_def_cfa %esp, SIGFRAME_SIGCONTEXT_eip + 4 + + .cfi_offset %eip, -4 + /* err, -8 */ + /* trapno, -12 */ + .cfi_offset %eax, -16 + .cfi_offset %ecx, -20 + .cfi_offset %edx, -24 + .cfi_offset %ebx, -28 + .cfi_offset %esp, -32 + .cfi_offset %ebp, -36 + .cfi_offset %esi, -40 + .cfi_offset %edi, -44 + +/* + * While this frame is marked as a signal frame, that only applies to how + * the return address is handled for the outer frame. The return address + * that arrived here, from the inner frame, is not marked as a signal frame + * and so the unwinder still tries to subtract 1 to examine the presumed + * call insn. Thus we must extend the unwind info to a nop before the sta= rt. + */ + nop + +__kernel_sigreturn: + popl %eax /* pop sig */ + .cfi_adjust_cfa_offset -4 + movl $__NR_sigreturn, %eax + int $0x80 +endf __kernel_sigreturn + + .cfi_def_cfa_offset RT_SIGFRAME_SIGCONTEXT_eip + 4 + nop + +__kernel_rt_sigreturn: + movl $__NR_rt_sigreturn, %eax + int $0x80 +endf __kernel_rt_sigreturn + + .cfi_endproc + +/* + * TODO: Add elf notes. E.g. + * + * #include + * 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/i386/vdso.ld b/linux-user/i386/vdso.ld new file mode 100644 index 0000000000..326b7a8f98 --- /dev/null +++ b/linux-user/i386/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux i386 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +ENTRY(__kernel_vsyscall) + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; + __vdso_clock_getres; + __vdso_clock_gettime64; + __vdso_getcpu; + }; + + LINUX_2.5 { + global: + __kernel_vsyscall; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS= =3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D 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 + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =3D0x90909090 +} diff --git a/linux-user/i386/vdso.so b/linux-user/i386/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bdece5dfcf8da036d013262d4e3= 7208350283cfa GIT binary patch literal 2672 zcmbtWU1%It6u#5lG_z^4ZB?X_C>9o5sxCF8QBlyONt?nZ)?|y73e)ZGba%;SR(597 zjTXE8QIiHtY6YPbDhO>6s(mPS(FX(Z2Q`g?1xp_^KInr_=3D|f8&)b;yj=3D5}w=3DeGok1 z%XiMX=3DbrmB_ny0ldSlx(O%qZAA|PnR8-(ZpuhYGj4)L&P5F5p65f&@qVw=3DPV(21ar zS~fT!zaSUUNMnrKqu7p`(Ouv?E|~S#J4vR z?eBj&+ji~rg~eZ!zf~VSJr_pXM}D8DFrl0ORPzVHn5LKmbB!e|qzOC^tO77~@mIB) zzl6kpgPDI3e2U8d6uIY2bq_`x0-wZWxDMLSfe$J6M%crOeHivUY<@1rr@`l7bI!EC z1WQ>fZdBic@iW@_P1t@f_$4LZXEGSfcpH2f?e~Kj&v`Zj+$T!NBlkb|jQhnHeiL+a z&lJblO18$ z-OkRAyW9oSmOj5{et#-4CVgruv?pIJqQxKI&ZY~dQ!H3DSHUrA-dxrymL5+h95ZU? zqfdy~j)7gfjrM5g9c>HN9>C7?j(;zF-_-GQuCsOgock95 z$CvrnLFHO513c5BE36+~5f2BEAVM30`47nj^o(oe;NgZND~~oF)87oe)%5l%caD!C zZUR`#4&CABw}%(BE9KdV>yxiUf|Id`UI}64SIQGVslJnSd`)$H14yd$t+Ysc2OQ(J+srhD+k<&>BHxRjq5)uze70i3T0nE36-;4MD zX|P(C`eCbeVGnF6>~F$Q>&)x0)jBo>TdiYfVXJlMbJ%KKV=3DY$enlO4^9_Z@du@yHB zwchCMGqw$O_4gWmJ%e{HQ)lfOF0TyrZnl4$<)z$G>%HU>FE1lXy;xFj>Xa70cGRgB zZe?YqcLID@7{~XU=3Dz-4s6vh$lz%9JdjN|)G?1a8N?pfc* zIKKY`&zcmDP2m_-KOf(Hg0)2EV}IgBfWHx_^Y;P~hc5SkbEE79n459x?;V(~$T$m@ zjElobxDGGOT`N`AK*n(#-do~0bSZKjGMDr(AZ`H$D-74d^xS8@>$IiJAn|o+fMq_` OKQ- (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040289680345.5326895218825; Fri, 29 Sep 2023 19:18:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWP-0000HY-M6; Fri, 29 Sep 2023 22:15:57 -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 1qmPWF-0000Dk-Js for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:47 -0400 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW9-0001zc-Js for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:47 -0400 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-57b6c7d0cabso7325906eaf.1 for ; Fri, 29 Sep 2023 19:15:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040140; x=1696644940; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OwjKzOGDAStulrjp6riCCAf0zhRQZEL2FYxhEzDlVII=; b=qkD3/cyP+y9U8bmxqTqQ+6EvKkVTA3G7HKj5C9Dk2Ms3jrRjcstxivUnEnnSi0NkDf j8OeRdA3fLWOb/foO2aeb9ODUcYptsYlXXFpLw6foRrvmhZD7r/c54go4dWzGbN9pwGo Wo4QRPhUSKVDLC9zin9bd0or5d9DmLwTeDbK9kD+er1SkdHC//GomDpseog7RJfdSmob vbeuIJJpLIp09t9GF5Ly+tmpLyXhTzZ7LBsTytoQfRTyWaEf9lBZ4iSUqtJM/51CAwx3 krYgZ4Ht7zMtE1+D2Hl/5+Xy1p9KndRJhE7ZNR+Zs7HmsB+XDS+pVe+0RXQA86UEhG4Q 4/Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040140; x=1696644940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OwjKzOGDAStulrjp6riCCAf0zhRQZEL2FYxhEzDlVII=; b=u7iyQnanVd9ueunCmzQU9g9NOLbidQo+e72M7yUa/xFQl1VgFjYD/wRZHasdh60JID sdFaEAEywLXz1CxhK/8Trf5VZpbf4DNuvEivJwEdq1cK9UXK1SQ6qPYcEf2i1nt7nQoF /zTQR+JZA9t400KJtZswxtHvRhMIUK/KQJ8Vhd+mI52Kj52wf/kzPB3ehBiGxaPDVImT BieCBfGxbvEJUZDnORQf5rA6Zo3LvL7+Gf98+E1BLBqBRJwO+0ORaYxZXiux91guwzR8 3sBuocVE5CifVxwAxHuQdUORxNo2p6afCqqUnk7eYLcQdxEg+05buQwJHvO+CjdyasKu czcg== X-Gm-Message-State: AOJu0Yx4skDRqdD1pjBvK7pplKvlIBSnfySQQzioxTRgBK5hykR8TGvp 26mzx5uXpy6cIJKMsZImK65N7OUklsGZ3t861Lk= X-Google-Smtp-Source: AGHT+IHeS7pYWwh2AfNvo5xgV3zS40WM7Xen5Mg+MMnNtlJAa7L4H3pSN6Ptl8G1yMQoQLsTtRDNFA== X-Received: by 2002:a05:6358:1ca:b0:134:e301:2c21 with SMTP id e10-20020a05635801ca00b00134e3012c21mr5947400rwa.15.1696040140421; Fri, 29 Sep 2023 19:15:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 10/19] linux-user/x86_64: Add vdso Date: Fri, 29 Sep 2023 19:15:20 -0700 Message-Id: <20230930021529.987950-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c29; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc29.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040290788100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/elfload.c | 4 +- linux-user/x86_64/Makefile.vdso | 11 +++++ linux-user/x86_64/meson.build | 4 ++ linux-user/x86_64/vdso.S | 78 ++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 73 ++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 2968 bytes 6 files changed, 168 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 314ae7cacf..1e1fdce656 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -318,10 +318,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUX86State *en } \ } while (0) =20 -#define VDSO_HEADER "vdso.c.inc" - #endif /* TARGET_X86_64 */ =20 +#define VDSO_HEADER "vdso.c.inc" + #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.v= dso new file mode 100644 index 0000000000..26552b66db --- /dev/null +++ b/linux-user/x86_64/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/x86_64-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/x86_64 +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld + $(CC) -o $@ -nostdlib -shared -Wl,-h,linux-vdso.so.1 \ + -Wl,--build-id=3Dsha1 -Wl,--hash-style=3Dboth \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..8c60da7a60 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,7 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhd= r.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc =3D gen_vdso.process('vdso.so') + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: vdso_inc) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..47d16c00ab --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,78 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro weakalias name +\name =3D __vdso_\name + .weak \name +.endm + +.macro vdso_syscall name, nr +__vdso_\name: + mov $\nr, %eax + syscall + ret +endf __vdso_\name +weakalias \name +.endm + + .cfi_startproc + +vdso_syscall clock_gettime, __NR_clock_gettime +vdso_syscall clock_getres, __NR_clock_getres +vdso_syscall gettimeofday, __NR_gettimeofday +vdso_syscall time, __NR_time + +__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 =3D 0 */ + + /* if (cpu !=3D NULL) *cpu =3D (ecx & 0xfff); */ + test %rdi, %rdi + jz 1f + mov %ecx, %eax + and $0xfff, %eax + mov %eax, (%rdi) + + /* if (node !=3D NULL) *node =3D (ecx >> 12); */ +1: test %rsi, %rsi + jz 2f + shr $12, %ecx + mov %ecx, (%rsi) + +2: xor %eax, %eax + ret +endf __vdso_getcpu + +weakalias getcpu + + .cfi_endproc + +/* TODO: Add elf note for LINUX_VERSION_CODE */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..ca6001cc3c --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,73 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2023 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; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS= =3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D 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 + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =3D0x90909090 +} diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..c873d6ea580b393825506d2ffbd= dcf9827d89e14 GIT binary patch literal 2968 zcmcgtO=3Dw(I6uvKUOl$t7l}J=3DnY6?Lgol-PVEvcEL6HP)om@-1c>vZO|6VjQnGcRQ# zQlk(xE{v3}x(Eh$E+iYFJ0pdXxDr=3DE=3D&lLvMs(4vwBz~aoiCl-j=3DCuHBzL}hzkANP z=3DiPhmJs%H_3^h28p){If=3DE2CAex2B8q6WA=3D6OrF`(`KF&`Uz?MI&EW@IwS5;Jq_-2rSodh0=3Dh5M8yR&|8~q9xUzjR(|@2weye zz8a;S7@IIXlUIKD#o1b1+rN5odUE>L=3Dz;rh$dv40C`m=3Dye*;62d-p2^;2j+^>^@b* z{zK-lF(OZeV2X;(id~9-RYHGjYX7&6)!h7{=3D_DaLK@yv17h=3D=3DzIwme4kF^2|U3rG4QL%vz2K73uCxOLI|+`aN! z$F-%z;-Tzk@6K$E*Jv}RD{ao_%it)TlnNq<^Unr!fz4Lw$ zOy&HC$f92&rz(YWnba(~S{s>9e=3DuV%Oyy_Fufeq||4}nCJT{T^4!f^Qd<}K~WJ1Kz zzvUl)Z^gZPP8#nNzOg~(w`aa@FjYY9u^!IW^5APGzK1@7^HK>gD4>;p^R}arI;0o1?04=3DjpKWw!W)=3D?0Yt=3D zynUbER^IkMss3a7y}So_=3DMcZ`$9S>#$BvH<4@j=3Db`|AzHy`jYM(LpaBOVlKlW^ujb z)P%J2ye6gV=3D6*G&ja!<{1*x-wK{3QEd-+1(8#gnXPvxf4)sE;I_k4cF&8AA(kO_(* zbIC83rV9C8121D-KkJ<idjF0yGj>9sy zEwzyLtiMFu4~T6avc|lrbF^o@CbB+LUq6S#>RVK)S)cWo$nWI(T!)Byg4)h8>pihg zSHk{7hu^QXIU^m!MEjk0M(-crN9uFmIL=3D%4U1~>sm5Pe?`en6ee(>HC`S#L{y??u6 vr;^|o8ppUAvD!gdKbRPND1BpVH#|fA;?X5$6$T literal 0 HcmV?d00001 --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040231; cv=none; d=zohomail.com; s=zohoarc; b=GFiRGagyYGKzi/YsfTchCCdWzLwLJWgH/AA9d5bfpKLoOoPyvP/YSPoVus4Q6x9kI+J5nBVnOYAiEbaZg1RkGcovs4z4nrXzsk1qgx8T6ECBKwj3RkchB8KcsOaEfXLSzmLl1kQrOOf2bceWqvgccC2DlVWkQyyg4IN8V3BGAe0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040231; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FprjvhcaZDLQvmrvhCxQlltAxaJPZ+WhuMFTfP0lrMA=; b=nLSuSC1R8MU7KQL0uMyITkGnH9gd+4TRzxOqziVPuDgEooh5AcHORxWPa1vR2kzLUggPN4Y/IpBrXm5ooJOo0FjgBiSw+xObedEqcmyUokSKOBP9o4tWsmpLf5QyQt1EClb3kNVmDFg9iuN3dn2tJd3hFObn813l6HOjvjZWOno= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040231775766.2078143242052; Fri, 29 Sep 2023 19:17:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWY-0000P0-5v; Fri, 29 Sep 2023 22:16:06 -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 1qmPWT-0000Jx-0p for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:16:01 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWD-00020A-Uj for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:16:00 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690fa0eea3cso13336925b3a.0 for ; Fri, 29 Sep 2023 19:15:44 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040141; x=1696644941; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FprjvhcaZDLQvmrvhCxQlltAxaJPZ+WhuMFTfP0lrMA=; b=OqwpRc7+RBSARcAnOxKoFONpB5D5ZfIJG7XZTuL9N3w6GV40UZ1c7MCSFIbS9tVlYA m04fvtmR9x0nhaRAUBX3j9R8iafBgBu1GKGBy8q4AakW7MQ5zqcop3MJdQrFRrGKS/n+ WjgRHysyn5975YS3+ORIzTjGmX9kN/2h5Yr+HJo3/W+YZpQOjj8C8dGnSkY5rhJia1zX 78IpJLWP1uGO77NQ8YagspzBvGWAEhQVOGmYyGvKHKlZyWq9pzIguTVR9bJkn+AgNOQ2 AmtI6kWh1QWJWb2Y9PlN3ysHgHC7bNCHDzAnY/x61OhvN26dstGrKrTOc93D2HifrC0a KZmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040141; x=1696644941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FprjvhcaZDLQvmrvhCxQlltAxaJPZ+WhuMFTfP0lrMA=; b=OhJsQzDw9SynRQBs7xjUb1yAS1t3Y0+4EPFCZRjE0Z7FYPrQvnXMl0CQarRn9wiUfv 8RvXmcARzp5rE5YBG+hXYlhedBxEQRhFJ3g6o5ne5RWjGc2oobAQXGmDyFA0RkP1gdB8 O3i34YfqHf0xGLHyBCSJDCN8ovjJHEDAWG1cxVYQmXHooM0v6eWxpF2EI5Ksw2E79tYd e53EuPV9vOVLVewR4HddNqAKTH921+qs5Vv04nVxdLcF6atw4cY9GaDBI6ruVuSiVyCx 1rRjn19ufmVEYTUecGJ1X/TGgkRh6JAX1KCjmzK7+5Bx2YHMj673QvYy6k8baCvsZh6k oCPA== X-Gm-Message-State: AOJu0Yye1kdQbfvMxw3bU3mSwlbuTUDGAA5XX4Ty4nNcS14JDm2Zwwba qW3aCyewOZcaHI2sti3B/3Blsk4pRbcdKk/trog= X-Google-Smtp-Source: AGHT+IEnNpYrAtc4GV33dHO/irR3Jo7ITmklHeb2r6HPvmdOfIxZD1M0oXmO2LSlYSNboslZYIsYBw== X-Received: by 2002:a05:6a21:328b:b0:162:ee29:d3c0 with SMTP id yt11-20020a056a21328b00b00162ee29d3c0mr4992980pzb.42.1696040141383; Fri, 29 Sep 2023 19:15:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 11/19] linux-user/aarch64: Add vdso Date: Fri, 29 Sep 2023 19:15:21 -0700 Message-Id: <20230930021529.987950-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040233779100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/elfload.c | 6 +++ linux-user/aarch64/Makefile.vdso | 15 +++++++ linux-user/aarch64/meson.build | 11 +++++ 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 | 71 ++++++++++++++++++++++++++++++ linux-user/aarch64/vdso.ld | 72 +++++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 8 files changed, 176 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 1e1fdce656..693ebc94bd 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -944,6 +944,12 @@ const char *elf_hwcap2_str(uint32_t bit) =20 #undef GET_FEATURE_ID =20 +#if TARGET_BIG_ENDIAN +# define VDSO_HEADER "vdso-be.c.inc" +#else +# define VDSO_HEADER "vdso-le.c.inc" +#endif + #endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ =20 diff --git a/linux-user/aarch64/Makefile.vdso b/linux-user/aarch64/Makefile= .vdso new file mode 100644 index 0000000000..599958116b --- /dev/null +++ b/linux-user/aarch64/Makefile.vdso @@ -0,0 +1,15 @@ +include $(BUILD_DIR)/tests/tcg/aarch64-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/aarch64 +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso-be.so $(SUBDIR)/vdso-le.so + +LDFLAGS =3D -nostdlib -shared -Wl,-h,linux-vdso.so.1 -Wl,--build-id=3Dsha1= \ + -Wl,--hash-style=3Dboth -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-be.so: vdso.S vdso.ld + $(CC) -o $@ $(LDFLAGS) -mbig-endian $< + +$(SUBDIR)/vdso-le.so: vdso.S vdso.ld + $(CC) -o $@ $(LDFLAGS) -mlittle-endian $< diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..248c578d15 --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,11 @@ +# 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_be_inc =3D gen_vdso.process('vdso-be.so', + extra_args: ['-r', '__kernel_rt_sigreturn']) + +vdso_le_inc =3D gen_vdso.process('vdso-le.so', + extra_args: ['-r', '__kernel_rt_sigreturn']) + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_i= nc]) diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..6084f3d1a701316004894fcdd73= 9c4e1e0463b68 GIT binary patch literal 3216 zcmc&$O>A355T57v+64N8Q&ABq6>X&mRj7RmMS`Gmu!EhX$W24qs-c&yv0q~6$41XD z#X$mc;KBh>)D!9f7jbE&o3KO1&W#3omsDqjgUAn$-Zyr zo0*+`yF2UmUcNA$N_k+#hcB@25ZaP4_Th`HO~N+FKpLJveLJ?m*pV~RgWjm21z{L< z$}wd4LC@ee4`!_DFeDmp#mw&i^z)Y(0;(W3!dXI>qX-{*VL(Jr;fPar2{J(&x^9ec+i^?x(BSN1)Vd z6xX6PwHzf$bv>#tm5ZAlwzO6+t%|J=3D9Y>808z-t!U5=3Dw- z6pqiGSyV^E7sBUX!r9;i8&^=3DH^Slq6Ij8hSDe#8W?GM<704wzH#{6Rl z3kP~-l0hxTsW!QgLi`s#bF@9x%T9lbJQ zY!o|4aN}q$C{o`>LtdYI781M2@Zr_SAbWZB{G@i?^Z?>M}yPa6444u6aN z(@-i+W?!6HJsZ|xybR+_P`TIVvL}weg5`%7zsk?5>4ofxyqe7|fSM_soXQr|$?54+ z`P1rjcB+t9-4$r--d6bFQntST=3D8k}{vALcU-#|=3DagB9u3>PZA)d9zkruaW$*LZfyK0az`B=3D zOP9o-=3DtekTbo-S2gfC;0-yF_wz7ueqd5$=3DY$YX0p;sews@%Q~V_LKN6qx+07iF&_y za+`8&63=3DyF?=3DkuAAb%2B2kO6y`P9?hbjKdryS z$@`Pr5;mESVJiH5fKy;kWM_r}wHqu6`)kkRea&Hpa463^!_;Pn&K^S8m+ zp?wpfSa~nu80C99^(GSZO}Up1l7AF+`VDc{mR$&j&a-ljQ9$NP`UtiG@xy#y!}}7* HXyg9^8}}&g 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..947d534ec1899740edbd6921da6= bc6e70e2ecd09 GIT binary patch literal 3216 zcmcguL2MgU5FKYzk|v=3D|N~=3DZ+qD6{Og~_6L z9VDO!E}RJB#LXZsa7BWO3q5c^;)VcKz2t<11S;tPP82h|}KgVe=3DJ;LxHx3r3FKB<#|V;X^n)Fz2- z%cM-;q^lZWOhj#+*XG^Ds~rB${uGqOuBG$Zd_T*Cz*Q~uCH;#!pUtzO6%jc6iOo2- zUEEGBEQ!`_!5rx^Nnd=3D)Smd95v^A8^_@B?;{q2QA>mys0rC%Ro5$%x&)1`=3DocG5ko z6aD^Iry=3D8;Iu?IIw{$G$Bh;3SV;YGV-B3QNd{X(JooK$aERgAej@6vDbv&c;NbCQ9 zy6kcvjnN%lhwQabmYd)|D~|JcjqwS(-w~ZS$+3$5Eo+{GihpC_aoczwaVXo4J(oVt zLv%HS2r(>}=3Dm;)N?7pOQiiV@`7Cn)F;GMkl%e$@jzP@~EJllTi@Po`JTV%{t&#!wc zrs4%bZPjZmmx~)cw6xMFU4<+G_Pu5g^#jwaReUd4^Xs%ytFN`5T`xBqF8`mS!u-P0 zMRU|W=3D01Od7sIQ^Pev*IefZVAM%JKvfiC4uzP+=3DNPvcQDQRF&JRZp-29I1zrXF6AH(sU{_$LFT%Cwyk#+LZ z;ng6&;~EaXMOzkXk;A9cMqe_Vo>WIFiraPM4aMzx@xJ0a>P4w^{aUtsrS3Lpx=3Dhn8 zGTB!bGNW-|qICZ9i-J8#ZsW(zsfpMl-H?`HVJ zQ@N}AZ)ya&&5hNdc!hc3N4$z&y%BiimN)9f)mka+urBjrP$aifUvsO)W;MbCKSI_$ zzgcV4`v#^=3Du2(h7esR?^)iP^hL~h`<0^Y;_N)i`xuRvNNF2N-Z;)L%5uqU}Abr|7; zxC7_l3JG@?*rRSe%~JWM!awQ*_-14tu2H6fJ-)w38511-QAfZJvn)=3Dq2Y-=3D;^38#N z)EjWrSput!}27rBsaAE89EDuX@lA>g=3DoKwq~LLwcEeotS^rIq;}{ z^!&pQ_yx9?I}66Bhu~O0Vg&Dx1uSz%)&%>9-4mgYeZyE{IBt*n3VsBN%5DE|sy*%y zs59VLKc=3Dz$$9+Rb__iuu(-)I_ + +/* ??? 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_P= AC) + + .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 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. + */ + . =3D 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 =3D0xd503201f +} 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 =3D executable('gen-vdso', 'gen-vdso.c', gen_vdso =3D generator(gen_vdso_exe, output: '@BASENAME@.c.inc', arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT= @']) =20 +subdir('aarch64') subdir('alpha') subdir('arm') subdir('hppa') --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040271; cv=none; d=zohomail.com; s=zohoarc; b=AgESaJ/X9/ja1L2l3cxe0V+LfHOHDsyI9OUPwOvKzppNBaLu8KrQBnGCuI412oqaMlUv1fqYq2GTtsNLtzsi6kRLDcI4JyZf3z1mz72N62lydtvP2drRebfBod38mdb+f+C/HX9NViIUS1Ao4orhXLQfGsBlV0QXC98Gqu9QOIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uoL6GPZP7+uSfW4tMRT2lr0ckkHUQiOnFTUyIyL544U=; b=U+WmuanV1C9vQeGPY0N4OeP4SZqioeD/gnE9vc3Q5WEaCREa37dqud9Kf/nc07tzv+ggilN2CUU1D0OnaqK32aFS/vnYBpSc+buVZYMCw4HSV79AtZnfu7aalmKKNRPn0pDBDADOhA+yxBxeohpoOGr/JwKGIYvSzg0JzYGf6k4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040271551939.3478394527689; Fri, 29 Sep 2023 19:17:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWP-0000H9-GU; Fri, 29 Sep 2023 22:15:57 -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 1qmPWH-0000Ej-P0 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:50 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWD-000206-Sx for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:49 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6910ea9cddbso12847111b3a.0 for ; Fri, 29 Sep 2023 19:15:43 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040142; x=1696644942; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uoL6GPZP7+uSfW4tMRT2lr0ckkHUQiOnFTUyIyL544U=; b=HgvcYKDHMX4YPcZogUHwKoZoI/AWLU+J4jU+FEVTX3jn5SuxDi1i9ejeToEivT5pzM OdSBkTViFnl/1TpKzh1Gc/OWf4PHXJUW5gqvHg02eMPQZDHNTnyd0fZrDQEbDtFMlIEO 31tBt0ZBTn48gPgbmpTEIdkf7+ESkwuGi/T1bzXmGhjjO+7XwYtqUfhJscuI6Uk/hbni 9beHukzf2erDwsK08eUJ1WR8J15V81rWXaKlmF6Ae636DkhllhQueIC1prllrzUxwpr1 h8q8LucJIghf26tmXyFOLvP0YnK8TWuDDt01YtTWSTWOwxDp1ijKcZmV/hnlwOzKRpWJ Wggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040142; x=1696644942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uoL6GPZP7+uSfW4tMRT2lr0ckkHUQiOnFTUyIyL544U=; b=N2FcF1h1XEfGZLm++Z0643E+bW41SQuogAB4+gpN0LDAAGAJPXsA5FkQc9MGN3Bq26 xqSJGxUQH34/JHW2nMN2ucc9TtskZOPP1EQrI6/b6eLWJTZquQQP0SDogPt2g+MmvbzK i+UEhdKCMKW/4fmc4HlO0V8sIWusUPjLL+Liqe1yJINkyR4q5jlR4kltXdWLnRWTLkFV /uYDs+h2ZID+Io6kfP4ODHtkzvD6tTUWNyl9yL+pDrzlQBM2HQLS/QAtWgxhl7HCGC2E d4Qvs+jKPg0m95mHXjVeYSY0gH5d5xt2h3RsdigszuQVXKjvF/K75fIxnEYKIT5Covdh fiKQ== X-Gm-Message-State: AOJu0YyN+9MF5qpDeMJabPNU/bMtZi91NIq1qwN7EayNADvwiRaCrpnC MibBK4f0mPCKnPs9EEHh3//5Tp+M+2fzRnNPxz8= X-Google-Smtp-Source: AGHT+IGiBjU0MwZ/kIpzj7tmgJbGqMrraE7C+Na3jmFaryy9OBqYLCfySwd12p/kuX063/Q15RJZ+A== X-Received: by 2002:a05:6a20:158e:b0:15c:7223:7bb1 with SMTP id h14-20020a056a20158e00b0015c72237bb1mr6469497pzj.20.1696040142352; Fri, 29 Sep 2023 19:15:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 12/19] linux-user/arm: Add vdso Date: Fri, 29 Sep 2023 19:15:22 -0700 Message-Id: <20230930021529.987950-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040272203100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/arm/vdso-asmoffset.h | 3 + linux-user/arm/signal.c | 55 ++++++---- linux-user/elfload.c | 3 +- linux-user/arm/Makefile.vdso | 17 ++++ linux-user/arm/meson.build | 12 +++ linux-user/arm/vdso-be.so | Bin 0 -> 2648 bytes linux-user/arm/vdso-le.so | Bin 0 -> 2648 bytes linux-user/arm/vdso.S | 174 ++++++++++++++++++++++++++++++++ linux-user/arm/vdso.ld | 67 ++++++++++++ 9 files changed, 310 insertions(+), 21 deletions(-) create mode 100644 linux-user/arm/vdso-asmoffset.h create mode 100644 linux-user/arm/Makefile.vdso create mode 100755 linux-user/arm/vdso-be.so create mode 100755 linux-user/arm/vdso-le.so create mode 100644 linux-user/arm/vdso.S create mode 100644 linux-user/arm/vdso.ld diff --git a/linux-user/arm/vdso-asmoffset.h b/linux-user/arm/vdso-asmoffse= t.h new file mode 100644 index 0000000000..252a95c46e --- /dev/null +++ b/linux-user/arm/vdso-asmoffset.h @@ -0,0 +1,3 @@ +/* offsetof(struct sigframe, retcode[3]) */ +#define SIGFRAME_RC3_OFFSET 756 +#define RT_SIGFRAME_RC3_OFFSET 884 diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index cf99fd7b8a..e19b514f17 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "vdso-asmoffset.h" =20 struct target_sigcontext { abi_ulong trap_no; @@ -102,6 +103,11 @@ struct rt_sigframe struct sigframe sig; }; =20 +QEMU_BUILD_BUG_ON(offsetof(struct sigframe, retcode[3]) + !=3D SIGFRAME_RC3_OFFSET); +QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, sig.retcode[3]) + !=3D RT_SIGFRAME_RC3_OFFSET); + static abi_ptr sigreturn_fdpic_tramp; =20 /* @@ -160,6 +166,9 @@ get_sigframe(struct target_sigaction *ka, CPUARMState *= regs, int framesize) return (sp - framesize) & ~7; } =20 +static void write_arm_sigreturn(uint32_t *rc, int syscall); +static void write_arm_fdpic_sigreturn(uint32_t *rc, int ofs); + static int setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, struct sigframe *frame, abi_ulong sp_addr) @@ -167,9 +176,9 @@ setup_return(CPUARMState *env, struct target_sigaction = *ka, int usig, abi_ulong handler =3D 0; abi_ulong handler_fdpic_GOT =3D 0; abi_ulong retcode; - int thumb, retcode_idx; - int is_fdpic =3D info_is_fdpic(((TaskState *)thread_cpu->opaque)->info= ); - bool copy_retcode; + bool is_fdpic =3D info_is_fdpic(((TaskState *)thread_cpu->opaque)->inf= o); + bool is_rt =3D ka->sa_flags & TARGET_SA_SIGINFO; + bool thumb; =20 if (is_fdpic) { /* In FDPIC mode, ka->_sa_handler points to a function @@ -184,9 +193,7 @@ setup_return(CPUARMState *env, struct target_sigaction = *ka, int usig, } else { handler =3D ka->_sa_handler; } - thumb =3D handler & 1; - retcode_idx =3D thumb + (ka->sa_flags & TARGET_SA_SIGINFO ? 2 : 0); =20 uint32_t cpsr =3D cpsr_read(env); =20 @@ -202,24 +209,32 @@ setup_return(CPUARMState *env, struct target_sigactio= n *ka, int usig, cpsr &=3D ~CPSR_E; } =20 - if (ka->sa_flags & TARGET_SA_RESTORER) { - if (is_fdpic) { - __put_user((abi_ulong)ka->sa_restorer, &frame->retcode[3]); - retcode =3D (sigreturn_fdpic_tramp + - retcode_idx * RETCODE_BYTES + thumb); - copy_retcode =3D true; - } else { - retcode =3D ka->sa_restorer; - copy_retcode =3D false; - } + /* Our vdso default_sigreturn label is a table of entry points. */ + retcode =3D default_sigreturn + (is_fdpic * 2 + is_rt) * 8; + + /* + * Put the sigreturn code on the stack no matter which return + * mechanism we use in order to remain ABI compliant. + * Because this is about ABI, always use the A32 instructions, + * despite the fact that our actual vdso trampoline is T16. + */ + if (is_fdpic) { + write_arm_fdpic_sigreturn(frame->retcode, + is_rt ? RT_SIGFRAME_RC3_OFFSET + : SIGFRAME_RC3_OFFSET); } else { - retcode =3D default_sigreturn + retcode_idx * RETCODE_BYTES + thum= b; - copy_retcode =3D true; + write_arm_sigreturn(frame->retcode, + is_rt ? TARGET_NR_rt_sigreturn + : TARGET_NR_sigreturn); } =20 - /* Copy the code to the stack slot for ABI compatibility. */ - if (copy_retcode) { - memcpy(frame->retcode, g2h_untagged(retcode & ~1), RETCODE_BYTES); + if (ka->sa_flags & TARGET_SA_RESTORER) { + if (is_fdpic) { + /* Place the function descriptor in slot 3. */ + __put_user((abi_ulong)ka->sa_restorer, &frame->retcode[3]); + } else { + retcode =3D ka->sa_restorer; + } } =20 env->regs[0] =3D usig; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 693ebc94bd..a65401f8d5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -944,13 +944,14 @@ const char *elf_hwcap2_str(uint32_t bit) =20 #undef GET_FEATURE_ID =20 +#endif /* not TARGET_AARCH64 */ + #if TARGET_BIG_ENDIAN # define VDSO_HEADER "vdso-be.c.inc" #else # define VDSO_HEADER "vdso-le.c.inc" #endif =20 -#endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ =20 #ifdef TARGET_SPARC diff --git a/linux-user/arm/Makefile.vdso b/linux-user/arm/Makefile.vdso new file mode 100644 index 0000000000..2d098a5748 --- /dev/null +++ b/linux-user/arm/Makefile.vdso @@ -0,0 +1,17 @@ +include $(BUILD_DIR)/tests/tcg/arm-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/arm +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso-be.so $(SUBDIR)/vdso-le.so + +# Adding -use-blx disables unneeded interworking without actually using bl= x. +LDFLAGS =3D -nostdlib -shared -Wl,-use-blx \ + -Wl,-h,linux-vdso.so.1 -Wl,--build-id=3Dsha1 \ + -Wl,--hash-style=3Dboth -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mbig-endian $< + +$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mlittle-endian $< diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 5a93c925cf..c4bb9af5b8 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -5,3 +5,15 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr.s= h', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +# 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_be_inc =3D gen_vdso.process('vdso-be.so', + extra_args: ['-s', 'sigreturn_codes']) + +vdso_le_inc =3D gen_vdso.process('vdso-le.so', + extra_args: ['-s', 'sigreturn_codes']) + +linux_user_ss.add(when: 'TARGET_ARM', if_true: [vdso_be_inc, vdso_le_inc]) diff --git a/linux-user/arm/vdso-be.so b/linux-user/arm/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..69cafbb956e283e2975bac59a10= 491c0cbafca57 GIT binary patch literal 2648 zcmbtVO>A355T57%q>ketR9ezQ5D`VCwMu1`A`rrf?W8D4OPYuR5-*PZ5?ds8WWR(2 z@#8{h3oY#>2P%XJf@`Y?wNft?xqwg)z@Y~Y{2jstAq3+00GRLFx0^a47sMproBd{H zci-Ec8NZkr$XY&2*2OP(V{8mbk?=3D~e?h{E$mjvPKkU0Dy0KRoBV@w1z%zRKvVA+F& z^~zXK{%ArSV?xa@xZfTX@xgB(Y4`}`*ZKyuK{v)kv;S6bf8WrkT>1HI=3DJ#C}-v0DM z`Ko86^ZqyN_qyPV0iyusSZkHW-@jr%ep?Va4UKQK=3DAm1G3a|}`R~n5!;a`RR3)~0& zBh+P#|F5L*D%>Y>i%1lDAGibEs`+;CC!09VIPho_XRMMAY5ar%&)0|_1Kt@mh37=3DU zx2hZAeHdX3?~e!ucLq!h=3DLA6obHD6}=3DFU|f2Mju6;lhx^e0ON;&FanQ51J*e74D=3DNAY3MoVW#|{6 zanIHg5CLf03mfxAtY?SC_gu{CjJA<-pB(_tzg1GP$SL1Bo+a)3f$z4k_rvzZ7WOgN zJ^><4>mP{+D1V6mJPr-x*-qNEh%uz;lUsF(DljGBI$8)UPyl zNA8oa>(@A1S|7FO(a>)CR!Yzxm1(PEZ z^0nw!=3DZ+iX1{o6A_<0B9K5Cff`2=3DTGT(rgQ}v7(FCIR|w_~Q7kFj14 zBZ!Vi+wgjT<<0Me=3DLBqBI1J9e$GjiLe7}dxdFc2N*p%pg@)YJb_opg2YsvH{IP`qcBbFX4yOh) zc7J+U?7o2`J*ffvNH%*cGh&aVdImCfQ%ledXhQ?p+?1Lc&4xy`MNd-wOA@t(X*V|x z?N&WqG^29GbtF+(DCee2c{M;Rbk5C5VzNA&DCTNK&+b+|%bZiKl`7>8#4bp}DcTd& z+_YmC3y3sK60S4vN+LBpn8>+qwKP8K;%NSp;J#I!GWS^*L^ohW=3De*nj1M?ecr}Bk4 zTL*NGBb~hb-UH1%!+NYERZC;wjAO1cj{Wd}=3D2(yQrE07>zZplc7FcIoZ_R`31?PKE zOxz*-#gf@z*MNm_mp!O@FzdlipFC!M<3U$F z$RXJIz4Y__C=3D&qJ=3D6X0gRrAv?=3D0AXBj6aWAK literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-le.so b/linux-user/arm/vdso-le.so new file mode 100755 index 0000000000000000000000000000000000000000..ad05a1251875ac0c76685e1f919= 0a7307a8444d1 GIT binary patch literal 2648 zcmbtWU1%It6h5<)-6ZYqW>ciL#)n9wmD&!qgeWwKo1aZ8NgB5ajR>7=3Db|=3D}zWT)&- zVj@~ojcv8s`j8h9Aw_&tf++N*n7)V<5g#h}py-1lh)4@s`cPfJ@6OyfN%J6hHs74{ zoqO(`JNMpmZeH#k$QXtpT1i52o2xxn z_w4-TgA;d}AB-ETNwkdyeSX4(|NOh=3Drtr=3Dvd_Bc$r=3DV{@FGDxb z2kZxU9w^2OS&6)uG+N>b;d^!gTz~GJq>~M2BNq(%4+6geoBjRpeYb^w9KNpro(Vlp zJ8cNwc?>UY;!DRDQ>U9=3DNxqs`iodq~%(kbOjXUR6Z#Cm zvm|}VAL(xez5tehI3THH^rb(du~@3Ho_bGROvU_$rfERUMa9H|n3#%TSIXk2wY?3G z$q$QHXf3Z>je#|^mu+hq{d*pq_J@JK@^1XvJDF79_km8|i$QZvZlWYc0%o**L}HOf zPW>*q9(YW(^Zp*tWds@U ze4~nI{qp10j!S2dfTpS@BEvx)kLlnIvCH7X0G0> z?Euj=3DzyNOnKaKabLPya55w-{O +#include "vdso-asmoffset.h" + +/* + * All supported cpus have T16 instructions: at least arm4t. + * + * We support user-user with m-profile cpus as an extension, because it + * is useful for testing gcc, which requires we avoid A32 instructions. + */ + .thumb + .arch armv4t + .eabi_attribute Tag_FP_arch, 0 + .eabi_attribute Tag_ARM_ISA_use, 0 + + .text + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .elseif \n < 0x1ff + mov r7, #0xff + add r7, #(\n - 0xff) + .else + .err + .endif + swi #0 +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r2, {r2, r3} + mov r9, r3 + bx r2 +.endm + +.macro endf name + .globl \name + .type \name, %function + .size \name, . - \name +.endm + +/* + * We must save/restore r7 for the EABI syscall number. + * While we're doing that, we might as well save LR to get a free return, + * and a branch that is interworking back to ARMv5. + */ + +.macro SYSCALL name, nr +\name: + .cfi_startproc + push {r7, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset r7, -8 + .cfi_offset lr, -4 + raw_syscall \nr + pop {r7, pc} + .cfi_endproc +endf \name +.endm + +SYSCALL __vdso_clock_gettime, __NR_clock_gettime +SYSCALL __vdso_clock_gettime64, __NR_clock_gettime64 +SYSCALL __vdso_clock_getres, __NR_clock_getres +SYSCALL __vdso_gettimeofday, __NR_gettimeofday + + +/* + * We, like the real kernel, use a table of sigreturn trampolines. + * Unlike the real kernel, we do not attempt to pack this into as + * few bytes as possible -- simply use 8 bytes per slot. + * + * Within each slot, use the exact same code sequence as the kernel, + * lest we trip up someone doing code inspection. + */ + +.macro slot n + .balign 8 + .org sigreturn_codes + 8 * \n +.endm + +.macro cfi_fdpic_r9 ofs + /* + * fd =3D *(r13 + ofs) + * r9 =3D *(fd + 4) + * + * DW_CFA_expression r9, length (7), + * DW_OP_breg13, ofs, DW_OP_deref, + * DW_OP_plus_uconst, 4, DW_OP_deref + */ + .cfi_escape 0x10, 9, 7, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0x= 23, 4, 0x06 +.endm + +.macro cfi_fdpic_pc ofs + /* + * fd =3D *(r13 + ofs) + * pc =3D *fd + * + * DW_CFA_expression lr (14), length (5), + * DW_OP_breg13, ofs, DW_OP_deref, DW_OP_deref + */ + .cfi_escape 0x10, 14, 5, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0= x06 +.endm + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + .cfi_startproc simple + .cfi_signal_frame + .cfi_return_column 15 + + .cfi_def_cfa sp, 32 + 64 + .cfi_offset r0, -16 * 4 + .cfi_offset r1, -15 * 4 + .cfi_offset r2, -14 * 4 + .cfi_offset r3, -13 * 4 + .cfi_offset r4, -12 * 4 + .cfi_offset r5, -11 * 4 + .cfi_offset r6, -10 * 4 + .cfi_offset r7, -9 * 4 + .cfi_offset r8, -8 * 4 + .cfi_offset r9, -7 * 4 + .cfi_offset r10, -6 * 4 + .cfi_offset r11, -5 * 4 + .cfi_offset r12, -4 * 4 + .cfi_offset r13, -3 * 4 + .cfi_offset r14, -2 * 4 + .cfi_offset r15, -1 * 4 + + nop + + .balign 16 +sigreturn_codes: + /* [EO]ABI sigreturn */ + slot 0 + raw_syscall __NR_sigreturn + + .cfi_def_cfa_offset 160 + 64 + + /* [EO]ABI rt_sigreturn */ + slot 1 + raw_syscall __NR_rt_sigreturn + + .cfi_endproc + + /* FDPIC sigreturn */ + .cfi_startproc + cfi_fdpic_pc SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 SIGFRAME_RC3_OFFSET + + slot 2 + fdpic_thunk SIGFRAME_RC3_OFFSET + .cfi_endproc + + /* FDPIC rt_sigreturn */ + .cfi_startproc + cfi_fdpic_pc RT_SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 RT_SIGFRAME_RC3_OFFSET + + slot 3 + fdpic_thunk RT_SIGFRAME_RC3_OFFSET + .cfi_endproc + + .balign 16 +endf sigreturn_codes diff --git a/linux-user/arm/vdso.ld b/linux-user/arm/vdso.ld new file mode 100644 index 0000000000..3b00adf27a --- /dev/null +++ b/linux-user/arm/vdso.ld @@ -0,0 +1,67 @@ +/* + * Linker script for linux arm replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_clock_getres; + __vdso_clock_gettime64; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS= =3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D 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 +} --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040244; cv=none; d=zohomail.com; s=zohoarc; b=ljtGm9WN/Mv0Pa9bfpbxkOxLx2bxXsj7WSu/3agpnAtJ8AfBo4SupkYL2I1TySK+VcPMynXj179Alk0IicV9fPGwK3EghtD4c/D64PANdaUBV8ScZt6BoeOyEqm9nD6jbXQBaAi4h+r8qsgDpsNTucKHOJ4pKEhTnhQGKu9vXE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040244; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OsAVxFrViuZh0oU7yn+p7tNp6qZeXDvUiqmxP7VIDOM=; b=LY1syTdoM+6eh3m5usaC97Irpgoh8SGzU4qpVzrL3RslAdYJ6I0yrzj58grfY/F6m4aYujaJAsfGQqdZvFXCPiUk6PAS0/qdgb4viQ+pp2ojHl29l+njR7Svl1Er/1fdKHt3vb70mHCILmFpg+Tns8Bga9IbYlVGr2XHltmSrME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040244573314.9192006333129; Fri, 29 Sep 2023 19:17:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWN-0000Gc-EM; Fri, 29 Sep 2023 22:15: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 1qmPWI-0000Ek-0k for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:50 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWE-00020P-0c for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:49 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-27740ce6c76so7673053a91.0 for ; Fri, 29 Sep 2023 19:15:44 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040143; x=1696644943; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OsAVxFrViuZh0oU7yn+p7tNp6qZeXDvUiqmxP7VIDOM=; b=E1c2dVVAILSOJrPN/VJ3xK1xAE3yTDpImmcoTHjBr9lHX0ZJTe6H5TmxrOmnPJ9AgE qbrRW+zMyAVAH8sZxTJA/RotCenXYp+QMVXpM6A8OMIIOGKUSD3dyTxb/Loa2llBDuXd AeqrybIDwUtiVM6SBbMU+9NOt8b6H4uzfSXeNVTv2dq3HMiWo6HAtWaFW4mfS5IJ1geT 3l8s0eqbHKRensqCpc6R4xS5VeyFJPXjoZ7xWICjnw85VSGLo8cblmhJwgWweC5SoT+C j6ZbNsRodtEYiIoqfsi6nu0PHamQz/I3ljM1ed75qOLesVJN9y6rBnzZ80M3IOZGrWMk MZuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040143; x=1696644943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OsAVxFrViuZh0oU7yn+p7tNp6qZeXDvUiqmxP7VIDOM=; b=aYijjXGf9TVKlwoe6Ue/jXcGH1Uqm6Cb2CGy0Rj0oIl7zwINHELytuQ6BkBNW+yMyY 4qw0de7pgPBI4w08KWYsfB2oc8LZWfPy2INIiiZKyOHeuVuwQbp3kPmdjOxMve+4ZckL GGotxSFmJWBGg3AG3L1W1cdC4EuwxnqS0mO4iSLPHbZrykZJWEbUcSoAOt8YPfauL/+E wRvt41AhfvQMiLVM6NLW1njduvKGmepprI6RrMFJojbxlR34nFAUaVBR0rgfUtafPEsN JBu0Kg32TJ0zbqVCGFD/fYj0pvBYqN70CptSa0h9AKRCH97N4kNLr57iv3yc8vF9x2kL pZGg== X-Gm-Message-State: AOJu0YyaabEVAjxoJPD1/tAMLL/XOZ4x4iHwNFdajdZb+/T8iQfKcB/7 mWgCdf7N0aIlEXa7omWlDRKG7FwS3q6RawOd4ao= X-Google-Smtp-Source: AGHT+IH03mSp9uFtRDL9gY9+0dQmnLzroFTeTZZEcl28eEBM8Jz4DhB8SVppiVJ+F540uZA1bvlpig== X-Received: by 2002:a17:90a:fa97:b0:277:5652:cb00 with SMTP id cu23-20020a17090afa9700b002775652cb00mr5023756pjb.24.1696040143312; Fri, 29 Sep 2023 19:15:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 13/19] linux-user/hppa: Add vdso Date: Fri, 29 Sep 2023 19:15:23 -0700 Message-Id: <20230930021529.987950-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040246097100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/hppa/vdso-asmoffset.h | 12 +++ linux-user/elfload.c | 2 + linux-user/hppa/signal.c | 24 +++-- linux-user/hppa/Makefile.vdso | 11 +++ linux-user/hppa/meson.build | 5 + linux-user/hppa/vdso.S | 165 +++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 77 +++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 2104 bytes 8 files changed, 286 insertions(+), 10 deletions(-) create mode 100644 linux-user/hppa/vdso-asmoffset.h create mode 100644 linux-user/hppa/Makefile.vdso create mode 100644 linux-user/hppa/vdso.S create mode 100644 linux-user/hppa/vdso.ld create mode 100755 linux-user/hppa/vdso.so diff --git a/linux-user/hppa/vdso-asmoffset.h b/linux-user/hppa/vdso-asmoff= set.h new file mode 100644 index 0000000000..c8b40c0332 --- /dev/null +++ b/linux-user/hppa/vdso-asmoffset.h @@ -0,0 +1,12 @@ +#define sizeof_rt_sigframe 584 +#define offsetof_sigcontext 160 +#define offsetof_sigcontext_gr 0x4 +#define offsetof_sigcontext_fr 0x88 +#define offsetof_sigcontext_iaoq 0x190 +#define offsetof_sigcontext_sar 0x198 + +/* arch/parisc/include/asm/rt_sigframe.h */ +#define SIGFRAME 64 +#define FUNCTIONCALLFRAME 48 +#define PARISC_RT_SIGFRAME_SIZE32 \ + (((sizeof_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & -SIGFRAME) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a65401f8d5..ccf8a1dc78 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1921,6 +1921,8 @@ static inline void init_thread(struct target_pt_regs = *regs, #define STACK_GROWS_DOWN 0 #define STACK_ALIGNMENT 64 =20 +#define VDSO_HEADER "vdso.c.inc" + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index bda6e54655..741dac79b6 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "vdso-asmoffset.h" =20 struct target_sigcontext { abi_ulong sc_flags; @@ -47,6 +48,19 @@ struct target_rt_sigframe { /* hidden location of upper halves of pa2.0 64-bit gregs */ }; =20 +QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe) !=3D sizeof_rt_sigfram= e); +QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.tuc_mcontext) + !=3D offsetof_sigcontext); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_gr) + !=3D offsetof_sigcontext_gr); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_fr) + !=3D offsetof_sigcontext_fr); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_iaoq) + !=3D offsetof_sigcontext_iaoq); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_sar) + !=3D offsetof_sigcontext_sar); + + static void setup_sigcontext(struct target_sigcontext *sc, CPUArchState *e= nv) { int i; @@ -91,16 +105,6 @@ static void restore_sigcontext(CPUArchState *env, struc= t target_sigcontext *sc) __get_user(env->cr[CR_SAR], &sc->sc_sar); } =20 -#if TARGET_ABI_BITS =3D=3D 32 -#define SIGFRAME 64 -#define FUNCTIONCALLFRAME 48 -#else -#define SIGFRAME 128 -#define FUNCTIONCALLFRAME 96 -#endif -#define PARISC_RT_SIGFRAME_SIZE32 \ - ((sizeof(struct target_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & = -SIGFRAME) - void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUArchState *env) diff --git a/linux-user/hppa/Makefile.vdso b/linux-user/hppa/Makefile.vdso new file mode 100644 index 0000000000..f4537ae716 --- /dev/null +++ b/linux-user/hppa/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/hppa-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/hppa +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ -nostdlib -shared -Wl,-h,linux-vdso32.so.1 \ + -Wl,--build-id=3Dsha1 -Wl,--hash-style=3Dboth \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/hppa/meson.build b/linux-user/hppa/meson.build index 4709508a09..aa2d9a87a6 100644 --- a/linux-user/hppa/meson.build +++ b/linux-user/hppa/meson.build @@ -3,3 +3,8 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr.= sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc =3D gen_vdso.process('vdso.so', + extra_args: [ '-r', '__kernel_sigtramp_rt' ]) + +linux_user_ss.add(when: 'TARGET_HPPA', if_true: vdso_inc) diff --git a/linux-user/hppa/vdso.S b/linux-user/hppa/vdso.S new file mode 100644 index 0000000000..5be14d2f70 --- /dev/null +++ b/linux-user/hppa/vdso.S @@ -0,0 +1,165 @@ +/* + * hppa linux kernel vdso replacement. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "vdso-asmoffset.h" + + .text + + +/* + * arch/parisc/kernel/vdso32/sigtramp.S: + * Gdb expects the trampoline is on the stack and the pc is offset from + * a 64-byte boundary by 0, 4 or 5 instructions. Since the vdso trampoline + * is not on the stack, we need a new variant with different offsets and + * data to tell gdb where to find the signal context on the stack. + * + * Here we put the offset to the context data at the start of the trampoli= ne + * region and offset the first trampoline by 2 instructions. Please do + * not change the trampoline as the code in gdb depends on the following + * instruction sequence exactly. + */ + +/* arch/parisc/kernel/asm-offsets.c */ +#define SIGFRAME_CONTEXT_REGS32 \ + (offsetof_sigcontext - PARISC_RT_SIGFRAME_SIZE32) + + .align 64 + .word SIGFRAME_CONTEXT_REGS32 + +/* + * All that said, we can provide a proper unwind record, which means that + * GDB should not actually need the offset magic. + * + * The return address that arrived here, from the inner frame, is + * not marked as a signal frame and so the unwinder still tries to + * subtract 1 to examine the presumed call insn. Thus we must + * extend the unwind info to a nop before the start. + */ + + .cfi_startproc simple + .cfi_signal_frame + + /* Compare pa32_fallback_frame_state from libgcc. */ + + /* + * Place the CFA at the start of sigcontext for convenience. + * The previous CFA will be restored from the saved stack pointer. + */ + .cfi_def_cfa 30, -PARISC_RT_SIGFRAME_SIZE32 + offsetof_sigcontext + + /* Record save offset of general registers. */ + .cfi_offset 1, offsetof_sigcontext_gr + 1 * 4 + .cfi_offset 2, offsetof_sigcontext_gr + 2 * 4 + .cfi_offset 3, offsetof_sigcontext_gr + 3 * 4 + .cfi_offset 4, offsetof_sigcontext_gr + 4 * 4 + .cfi_offset 5, offsetof_sigcontext_gr + 5 * 4 + .cfi_offset 6, offsetof_sigcontext_gr + 6 * 4 + .cfi_offset 7, offsetof_sigcontext_gr + 7 * 4 + .cfi_offset 8, offsetof_sigcontext_gr + 8 * 4 + .cfi_offset 9, offsetof_sigcontext_gr + 9 * 4 + .cfi_offset 10, offsetof_sigcontext_gr + 10 * 4 + .cfi_offset 11, offsetof_sigcontext_gr + 11 * 4 + .cfi_offset 12, offsetof_sigcontext_gr + 12 * 4 + .cfi_offset 13, offsetof_sigcontext_gr + 13 * 4 + .cfi_offset 14, offsetof_sigcontext_gr + 14 * 4 + .cfi_offset 15, offsetof_sigcontext_gr + 15 * 4 + .cfi_offset 16, offsetof_sigcontext_gr + 16 * 4 + .cfi_offset 17, offsetof_sigcontext_gr + 17 * 4 + .cfi_offset 18, offsetof_sigcontext_gr + 18 * 4 + .cfi_offset 19, offsetof_sigcontext_gr + 19 * 4 + .cfi_offset 20, offsetof_sigcontext_gr + 20 * 4 + .cfi_offset 21, offsetof_sigcontext_gr + 21 * 4 + .cfi_offset 22, offsetof_sigcontext_gr + 22 * 4 + .cfi_offset 23, offsetof_sigcontext_gr + 23 * 4 + .cfi_offset 24, offsetof_sigcontext_gr + 24 * 4 + .cfi_offset 25, offsetof_sigcontext_gr + 25 * 4 + .cfi_offset 26, offsetof_sigcontext_gr + 26 * 4 + .cfi_offset 27, offsetof_sigcontext_gr + 27 * 4 + .cfi_offset 28, offsetof_sigcontext_gr + 28 * 4 + .cfi_offset 29, offsetof_sigcontext_gr + 29 * 4 + .cfi_offset 30, offsetof_sigcontext_gr + 30 * 4 + .cfi_offset 31, offsetof_sigcontext_gr + 31 * 4 + + /* Record save offset of fp registers, left and right halves. */ + .cfi_offset 32, offsetof_sigcontext_fr + 4 * 8 + .cfi_offset 33, offsetof_sigcontext_fr + 4 * 8 + 4 + .cfi_offset 34, offsetof_sigcontext_fr + 5 * 8 + .cfi_offset 35, offsetof_sigcontext_fr + 5 * 8 + 4 + .cfi_offset 36, offsetof_sigcontext_fr + 6 * 8 + .cfi_offset 37, offsetof_sigcontext_fr + 6 * 8 + 4 + .cfi_offset 38, offsetof_sigcontext_fr + 7 * 8 + .cfi_offset 39, offsetof_sigcontext_fr + 7 * 8 + 4 + .cfi_offset 40, offsetof_sigcontext_fr + 8 * 8 + .cfi_offset 41, offsetof_sigcontext_fr + 8 * 8 + 4 + .cfi_offset 42, offsetof_sigcontext_fr + 9 * 8 + .cfi_offset 43, offsetof_sigcontext_fr + 9 * 8 + 4 + .cfi_offset 44, offsetof_sigcontext_fr + 10 * 8 + .cfi_offset 45, offsetof_sigcontext_fr + 10 * 8 + 4 + .cfi_offset 46, offsetof_sigcontext_fr + 11 * 8 + .cfi_offset 47, offsetof_sigcontext_fr + 11 * 8 + 4 + .cfi_offset 48, offsetof_sigcontext_fr + 12 * 8 + .cfi_offset 49, offsetof_sigcontext_fr + 12 * 8 + 4 + .cfi_offset 50, offsetof_sigcontext_fr + 13 * 8 + .cfi_offset 51, offsetof_sigcontext_fr + 13 * 8 + 4 + .cfi_offset 52, offsetof_sigcontext_fr + 14 * 8 + .cfi_offset 53, offsetof_sigcontext_fr + 14 * 8 + 4 + .cfi_offset 54, offsetof_sigcontext_fr + 15 * 8 + .cfi_offset 55, offsetof_sigcontext_fr + 15 * 8 + 4 + .cfi_offset 56, offsetof_sigcontext_fr + 16 * 8 + .cfi_offset 57, offsetof_sigcontext_fr + 16 * 8 + 4 + .cfi_offset 58, offsetof_sigcontext_fr + 17 * 8 + .cfi_offset 59, offsetof_sigcontext_fr + 17 * 8 + 4 + .cfi_offset 60, offsetof_sigcontext_fr + 18 * 8 + .cfi_offset 61, offsetof_sigcontext_fr + 18 * 8 + 4 + .cfi_offset 62, offsetof_sigcontext_fr + 19 * 8 + .cfi_offset 63, offsetof_sigcontext_fr + 19 * 8 + 4 + .cfi_offset 64, offsetof_sigcontext_fr + 20 * 8 + .cfi_offset 65, offsetof_sigcontext_fr + 20 * 8 + 4 + .cfi_offset 66, offsetof_sigcontext_fr + 21 * 8 + .cfi_offset 67, offsetof_sigcontext_fr + 21 * 8 + 4 + .cfi_offset 68, offsetof_sigcontext_fr + 22 * 8 + .cfi_offset 69, offsetof_sigcontext_fr + 22 * 8 + 4 + .cfi_offset 70, offsetof_sigcontext_fr + 23 * 8 + .cfi_offset 71, offsetof_sigcontext_fr + 23 * 8 + 4 + .cfi_offset 72, offsetof_sigcontext_fr + 24 * 8 + .cfi_offset 73, offsetof_sigcontext_fr + 24 * 8 + 4 + .cfi_offset 74, offsetof_sigcontext_fr + 25 * 8 + .cfi_offset 75, offsetof_sigcontext_fr + 25 * 8 + 4 + .cfi_offset 76, offsetof_sigcontext_fr + 26 * 8 + .cfi_offset 77, offsetof_sigcontext_fr + 26 * 8 + 4 + .cfi_offset 78, offsetof_sigcontext_fr + 27 * 8 + .cfi_offset 79, offsetof_sigcontext_fr + 27 * 8 + 4 + .cfi_offset 80, offsetof_sigcontext_fr + 28 * 8 + .cfi_offset 81, offsetof_sigcontext_fr + 28 * 8 + 4 + .cfi_offset 82, offsetof_sigcontext_fr + 29 * 8 + .cfi_offset 83, offsetof_sigcontext_fr + 29 * 8 + 4 + .cfi_offset 84, offsetof_sigcontext_fr + 30 * 8 + .cfi_offset 85, offsetof_sigcontext_fr + 30 * 8 + 4 + .cfi_offset 86, offsetof_sigcontext_fr + 31 * 8 + .cfi_offset 87, offsetof_sigcontext_fr + 31 * 8 + 4 + + /* Record save offset of %sar */ + .cfi_offset 88, offsetof_sigcontext_sar + + /* Record save offset of return address, iaoq[0]. */ + .cfi_return_column 89 + .cfi_offset 89, offsetof_sigcontext_iaoq + + nop + +__kernel_sigtramp_rt: + ldi 0, %r25 + ldi __NR_rt_sigreturn, %r20 + be,l 0x100(%sr2, %r0), %sr0, %r31 + nop + + .cfi_endproc + .size __kernel_sigtramp_rt, . - __kernel_sigtramp_rt + .type __kernel_sigtramp_rt, @function + .globl __kernel_sigtramp_rt diff --git a/linux-user/hppa/vdso.ld b/linux-user/hppa/vdso.ld new file mode 100644 index 0000000000..b17ad974f3 --- /dev/null +++ b/linux-user/hppa/vdso.ld @@ -0,0 +1,77 @@ +/* + * Linker script for linux hppa vdso. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +VERSION { + /* + * The kernel's vdso32.lds.S attempts to export + * __kernel_sigtramp_rt32 + * __kernel_restart_syscall32 + * except that those symbols don't exist. The actual symbols are + * __kernel_sigtramp_rt + * __kernel_restart_syscall + * which means that nothing is exported at all. + * QEMU handles syscall restart internally, so we don't + * need to implement __kernel_restart_syscall at all. + */ + LINUX_5.18 { + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; + dynamic PT_DYNAMIC FLAGS(4); + note PT_NOTE FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; +} + +SECTIONS { + . =3D 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 + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} diff --git a/linux-user/hppa/vdso.so b/linux-user/hppa/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..e1ddd70c37e9eb6871c21d538dc= ce0a1e736a918 GIT binary patch literal 2104 zcmbtVTXR!Y6kaFkhEgcBP%l`hafWdil!Lv1RY03GNz;<1rD7>6(0JUG~~*U)EYXMdFQ(BmGb?r%x-$mIFC+3xTU<+0?(1N%-~JGte| zwo#0&1h`Mkv8G3g7ybaBfv&)R1jiYzaqu#r23QVo^SCSe7yscgz|X_x1OE;7zacM{ z)|dd5Qv4kHJ82ot+=3DCYbD;A=3D;?E| z+O@bm6U{_s6$j@&=3DK!(p?Mg~X zNxxOSx@O|YQQtBD{UyiM14~XUeXw+5*+XR~mp{DXk@8b3A6<32;<3udS3j}l$*QL=3D zd;0Qcu9&>?*|pDI^?daU>t0;{Qq9X(zY>_*^y+o5UH|&#H|#gJymiCdwbOO))W6&C z-q!cGeQ@K4jUV0g@y(xX|8&P^J3qhW%&lKEeHlC(`l|Ws@Hdf}=3D(jE3#lCMHW; zONHX9xm|@5D$=3D2%ovLNGigl^hq-yI{yLwc7k81B#i9XfQuR8at-M6W(+g0)o)qSVx zanzoDsyC(j22_8Vr_*Qt6`W`0eJzTL#S4K_@ijH9MKe`ddw-H+LR}U|=3DQy2(>V?rY z1fBH)(sj*o{IovBFBJ9<$eQLCI%^7~`+_?Ao;v%3I{KO9);;u6S9h0zzRc5gxj|&Sy_i8rNTu72w>n-mm4>KjyI4HF5rW`17r(z$)~w!;~p-Ow|1nqfFBMc>aU8q_P9)|;yMpZzCl>C4=3D|Coz%^Y;{L;DN4)bKq{t{_fJydxBhI~~zzGScmI z2Sf3Qv!HS8{Ndq3>MpVKg`CR=3Djg%cJWW-J%&ZdTk?$!c)!Bd5l*!#1i_FyVM=3D-LZ8 z*K#P6%MXoY7bs3z?98AufIVfL!8AOLCUzk+R&dYvKfl%RW1g54)&;QvFy!T2u7QF1 zMOrSt&AewX$GSF{-%SAXhIp(aT}uJz^keQAkM9EVqIJY$eh5<^kS@K|J0P>p7;oBz z?knzt#CSv_-q=3D6E=3D{Ms-0?_~K7xHZML!Ihc<@;@jdnC0XUJ;yrc(-*8a~%^8c8*D} zdE;G`CSg6AJLMeG0KnLAF#k;p-Us8y>=3D{4wf$jxe@351M-+hqjhn)DwT}TsjLrtFG t#WH69ET#p-{eR>C0pl?r>_u}nn& (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040271709616.9073419958058; Fri, 29 Sep 2023 19:17:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWT-0000Jw-1o; Fri, 29 Sep 2023 22:16:01 -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 1qmPWN-0000G4-2c for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:55 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWG-00020y-6K for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:54 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-27777b778bfso6157452a91.3 for ; Fri, 29 Sep 2023 19:15:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040144; x=1696644944; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QMALYQ6ZHTn7wyG3+42rapaOzHSgcSBLV1NTBu/gWFs=; b=Qf/zU/jnvYcrH6pz6thu9O3On9aBU2kT1B8UhPFtPZLXDaIQj4rCuDjzcZMGBmPYZv udDBrteKge/C0OSJ+GnUIw56xLfs+8vPpxv6l0YeDGBsMp4K52Zm+E7TlW8GHs4QU1QS y/qoUfmxbUZxnNZiinD/nTcG2FbF/89dU/ZBZe9OE/cickmA5qsavut5ImoT1MON9zrr LVNbDnW1CIL3PDNvJsGGajgTQ2PeGMtrLKeMvO4n8nAkJgnXY5VAilFX55vXOo2TZxPp GC7peW6q+YMpvHcoZ8zMMizOQHLeq/FwXNI8mtzQGXNkSyruCPezsUtzNRHLsWF6MHea S7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040144; x=1696644944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QMALYQ6ZHTn7wyG3+42rapaOzHSgcSBLV1NTBu/gWFs=; b=Wwq8bbcCgCMdYlZvR5YfMeNJ9SerhENmj7D8Jv9d74FSDW5qIffLZGgni82qnQSadW qzmJ3Z18bQFS+Ym5/sGy2bCCqCX9ka0Sphzc1y8sgejd7u6FagNkl0NJBxbQuW2tVWLf Ip5HQzG3wS5yOm7Z4DyVGPrRysrLqvSQkWOzuXwKi7ST5Y/OIY4QPzMutGYqwGHk7MzF pAjWeje1ClyFw7NVn66b6FY+jbG9gng/7cHwJ1XZ4ye7wl5vE28PMPuUUr2qrAJVbp+R pSxgol911G5vj9yag6Lt8VhuULXH7vHfu484RijnMpWjWeFoFqcfz9uWESzM+/ND2xiV XvSA== X-Gm-Message-State: AOJu0YwOOqeB09rxr3lX000i0/9SHghl2LEdki/lLs+ZvXEH+siSJy3a ruLzNe9kWO4FzizcGyoQHVL49TA/ZlqD5y0FA8U= X-Google-Smtp-Source: AGHT+IHIm7SDeUBonhtILUxMNzXUdzFNY/COtyT1nHoNeVLv90d/LQI5zJsIYQ7xPP+J9UDd0pF5Aw== X-Received: by 2002:a17:90a:d38c:b0:269:3771:7342 with SMTP id q12-20020a17090ad38c00b0026937717342mr5105088pju.18.1696040144231; Fri, 29 Sep 2023 19:15:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, Alistair Francis Subject: [PATCH v6 14/19] linux-user/riscv: Add vdso Date: Fri, 29 Sep 2023 19:15:24 -0700 Message-Id: <20230930021529.987950-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040272487100003 Content-Type: text/plain; charset="utf-8" Acked-by: Alistair Francis Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/riscv/vdso-asmoffset.h | 9 ++ linux-user/elfload.c | 2 + linux-user/riscv/signal.c | 8 ++ linux-user/meson.build | 1 + linux-user/riscv/Makefile.vdso | 15 +++ linux-user/riscv/meson.build | 7 ++ linux-user/riscv/vdso-32.so | Bin 0 -> 2888 bytes linux-user/riscv/vdso-64.so | Bin 0 -> 3840 bytes linux-user/riscv/vdso.S | 186 ++++++++++++++++++++++++++++++ linux-user/riscv/vdso.ld | 74 ++++++++++++ 10 files changed, 302 insertions(+) create mode 100644 linux-user/riscv/vdso-asmoffset.h create mode 100644 linux-user/riscv/Makefile.vdso create mode 100644 linux-user/riscv/meson.build create mode 100755 linux-user/riscv/vdso-32.so create mode 100755 linux-user/riscv/vdso-64.so create mode 100644 linux-user/riscv/vdso.S create mode 100644 linux-user/riscv/vdso.ld diff --git a/linux-user/riscv/vdso-asmoffset.h b/linux-user/riscv/vdso-asmo= ffset.h new file mode 100644 index 0000000000..123902ef61 --- /dev/null +++ b/linux-user/riscv/vdso-asmoffset.h @@ -0,0 +1,9 @@ +#ifdef TARGET_ABI32 +# define sizeof_rt_sigframe 0x2b0 +# define offsetof_uc_mcontext 0x120 +# define offsetof_freg0 0x80 +#else +# define sizeof_rt_sigframe 0x340 +# define offsetof_uc_mcontext 0x130 +# define offsetof_freg0 0x100 +#endif diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ccf8a1dc78..ff6951950b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1884,8 +1884,10 @@ static void elf_core_copy_regs(target_elf_gregset_t = *regs, =20 #ifdef TARGET_RISCV32 #define ELF_CLASS ELFCLASS32 +#define VDSO_HEADER "vdso-32.c.inc" #else #define ELF_CLASS ELFCLASS64 +#define VDSO_HEADER "vdso-64.c.inc" #endif =20 #define ELF_HWCAP get_elf_hwcap() diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index f989f7f51f..941eadce87 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "vdso-asmoffset.h" =20 /* Signal handler invocation must be transparent for the code being interrupted. Complete CPU (hart) state is saved on entry and restored @@ -37,6 +38,8 @@ struct target_sigcontext { uint32_t fcsr; }; /* cf. riscv-linux:arch/riscv/include/uapi/asm/ptrace.h */ =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, fpr) !=3D offsetof_fr= eg0); + struct target_ucontext { abi_ulong uc_flags; abi_ptr uc_link; @@ -51,6 +54,11 @@ struct target_rt_sigframe { struct target_ucontext uc; }; =20 +QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe) + !=3D sizeof_rt_sigframe); +QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.uc_mcontext) + !=3D offsetof_uc_mcontext); + static abi_ulong get_sigframe(struct target_sigaction *ka, CPURISCVState *regs, size_t framesize) { diff --git a/linux-user/meson.build b/linux-user/meson.build index dd24389052..3ff3bc5bbc 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -45,6 +45,7 @@ subdir('microblaze') subdir('mips64') subdir('mips') subdir('ppc') +subdir('riscv') subdir('s390x') subdir('sh4') subdir('sparc') diff --git a/linux-user/riscv/Makefile.vdso b/linux-user/riscv/Makefile.vdso new file mode 100644 index 0000000000..2c257dbfda --- /dev/null +++ b/linux-user/riscv/Makefile.vdso @@ -0,0 +1,15 @@ +include $(BUILD_DIR)/tests/tcg/riscv64-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/riscv +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso-32.so $(SUBDIR)/vdso-64.so + +LDFLAGS =3D -nostdlib -shared -fpic -Wl,-h,linux-vdso.so.1 -Wl,--build-id= =3Dsha1 \ + -Wl,--hash-style=3Dboth -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-32.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mabi=3Dilp32d -march=3Drv32g $< + +$(SUBDIR)/vdso-64.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mabi=3Dlp64d -march=3Drv64g $< diff --git a/linux-user/riscv/meson.build b/linux-user/riscv/meson.build new file mode 100644 index 0000000000..beb989a7ca --- /dev/null +++ b/linux-user/riscv/meson.build @@ -0,0 +1,7 @@ +vdso_32_inc =3D gen_vdso.process('vdso-32.so', + extra_args: ['-r', '__vdso_rt_sigreturn']) +vdso_64_inc =3D gen_vdso.process('vdso-64.so', + extra_args: ['-r', '__vdso_rt_sigreturn']) + +linux_user_ss.add(when: 'TARGET_RISCV32', if_true: vdso_32_inc) +linux_user_ss.add(when: 'TARGET_RISCV64', if_true: vdso_64_inc) diff --git a/linux-user/riscv/vdso-32.so b/linux-user/riscv/vdso-32.so new file mode 100755 index 0000000000000000000000000000000000000000..274b92c23dca9b44da32cb0c293= f879c03a5f8ae GIT binary patch literal 2888 zcmb_eU2Icj7=3DBMnu}qj912f!W2AjB$*>rUfg3GdY>-e#3%V3I1JnPzSZDj4zo-VKu z2M!Sx1sxzF>HtMl)Cnk}C?uMg=3D#7b2-fO%u#vk-Tk@-C5oUfeeF1+yFp1$AvbKdiP z=3DX<~BoY6?MUDGsC;+9`US&eW`ctvJGH%hh4mO3dDA2jXjxQsEuJi;w9RPVvSmR4Ic z#@edB?H1+|H_+h|aY0oeN#QVTLe=3Dm3&PW`_O%!SoBUGIFiUTvn7a)!jvbv*3>NlT0 zbjEx2%E52H9Q~v7+%M-BUm7h%%m7%c4HNq9+EjKsG?#S|n$KVob1Z@02iyo?>ed>d z@z_k6gWtKp)v2j$FK+l3G}reNbd(eLAEbo^A#Ti;&-N51y$O0g?z{}zi%D}nw0A)( zDU+Y4dSTQ$;tLsc*io1j4!aq)&tY?qxD2k7ntRA+;}oQu!a4AHQaEMiQxm*KE1T00 z5}%JY^UQwuqH=3DP>zCfz#z}~5o7X}wEI?yqU*znd{!Sw8b*3Bne9)+ zwkcnHOE&(Hiu}u&OXigi7srPR%Ie=3Dz$fxvlJQhzC%jXO|pB~61jY2LXThf`r);oAx zKmHpey0)WdliuiWSdIxpT+{y8>(<|~OFzzI&s72JD+>3@h2O&H_a%%`)c$Cd?z^gC z^BMV&xDq-A-37e|`YQbZ#XZt3+ICH=3DoaYkOsQ|tL*aOm4TAe^MGdBRRRy8!`fTei- z1{7$~D(AW;J)V}t&b~)_#~$3Z`O*7#Z+h&WJsThIexmEij=3Dj;R);+yuU;F;HXTs06 zj5i->I=3DJf4%I8)bZhSs?B=3DCa&X#I=3DJUaEU}=3D|tPH@bQ)t&95}Qy6WW0*H)Zrd_DL^ z;7$MO`nQ(7UH8t?$=3DY|9oT)y0>$$4;Zh61r{LLRMxG?`i-$$hv=3DYCxBiTBcMbFN1* zH$DrV9ZGz+M`|X3;~pv3v}-kW$E4h&$+$PLD3AEq5>4DSAsMULDPy;38gg85pT|}1 z>H0HXoK44a*W5llV18lVf^IM z`S`GC+z(G~_|9NDIMkpI28RNAjHCYGP*6|sXCxiZ=3Djb0v_a`&)Boes+GsqR&=3DQcaS z;yt?D=3DE<;l#))b8T$(4sxhUV&xL0>5zo$VZl_-Lx#mZ^DoqLeXHecLO$I&TCvWb zmD;VMx82tfTEDhc^sesC)<|1VcSHvz+#OmS(Km*|(TEOa!8=3DBetkK)ML+c~@nznAy zS4TU;p{U;3-o7ESQ6)O4#3r_x*k~rQo6cd=3D_{y$Sq(cYu6@4U65r2N$pb_hXHgc9u zsZl0tB*mZDmWd6f{((%vpNi#Emfy%(p5bIJpU!5c8G1te$&}uoiw!3A zR05gG62Fn$YKY%FT>hA0tHggF2ez(67 zc#eq{`2Lv}wtWbj-y=3DNZ{0>pVIZ@UDQ+7R`dtyF(svfT=3D?giAhNiTu~=3Di*#1OyT)r zZC>O2{(@+Z)ZM$vJrQIwLF`8VK-EDVc_mSPZ zO=3D*Z!t#1UhfQYC?6vbzKpx}%CFiK2}{M7#%(HNsK`op00oO{n%?oK!Q!yle@?l*HD zGjq?(e0O$_KhR&MX&~Z)U*U2KKxe~zrCnKqphFid#b+(lAOhGr+pgPChzoLOf^N3E z05TLeMje!pUPUK!BCJqs&ZhJyh*Pwr44*XK8SY3$FY5(mp22U;D8;puTiq$oA9QX@+AmUKPu}OftPgT zXRZ6^jdNS}d*e+9_b!|~n_Ru>L~p8lG^_{z+aa)N zXxnz9)6;$blKjhbjtk?Am^^q5RUa#_+(CPreZNDLjl81xU~!o?7tb-KB5b>*BC>s=3DuHSFB&m z2V{3ad4XSx{V`K=3Ds2m0to*uoV-VLRA&xI#g_|nl0j$2vy?iA~n!Jr&$hr#9GEr%NW zsdhH4I&I%2C3wqT>&yJ-3@qh;B|2!>kD6!N|D?|-gw$bmxcI&N>_1Nj&LOvBy%fKW zpq}_u<;zLdtNgu>^(v1ZW4+4LbF5eS{u9=3D#{0)&vd#JxZ8S4Q?g}@jH4EOi~#&CcC7XMap zbkH1=3DZYicLMa0GYTEwN?Q-P`-tX$9$u>*K=3DyOL&jC!(3PF)p=3DK+KhoGx+@h6PHI;9CWV{O4PzVNDG9ec|7GLGP_Xs5fW zw1s~K<^9$C%LIsjXigHZ{!aL}{X=3D&UXT0#a;Eys8qvT)IcX7PXtMHwm%wPOv-K0H@ z70gXW+Jf@?saF(?YW|&bce>8;gl0K0^nIW^ugt%Jo#oEzjHP;ze^7j_7}W7=3D(JpK2 QbiILp&>VIuv98Ad4S{NxYXATM literal 0 HcmV?d00001 diff --git a/linux-user/riscv/vdso.S b/linux-user/riscv/vdso.S new file mode 100644 index 0000000000..70a4f710db --- /dev/null +++ b/linux-user/riscv/vdso.S @@ -0,0 +1,186 @@ +/* + * RISC-V linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#if __riscv_xlen =3D=3D 32 +# define TARGET_ABI32 +#endif +#include "vdso-asmoffset.h" + + .text + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro raw_syscall nr + li a7, \nr + ecall +.endm + +.macro vdso_syscall name, nr +\name: + raw_syscall \nr +endf \name +.endm + +__vdso_gettimeofday: + .cfi_startproc +#ifdef __NR_gettimeofday + raw_syscall __NR_gettimeofday + ret +#else + /* No gettimeofday, fall back to clock_gettime64. */ + beq a1, zero, 1f + sw zero, 0(a1) /* tz->tz_minuteswest =3D 0 */ + sw zero, 4(a1) /* tz->tz_dsttime =3D 0 */ +1: addi sp, sp, -32 + .cfi_adjust_cfa_offset 32 + sw a0, 16(sp) /* save tv */ + mv a0, sp + raw_syscall __NR_clock_gettime64 + lw t0, 0(sp) /* timespec.tv_sec.low */ + lw t1, 4(sp) /* timespec.tv_sec.high */ + lw t2, 8(sp) /* timespec.tv_nsec.low */ + lw a1, 16(sp) /* restore tv */ + addi sp, sp, 32 + .cfi_adjust_cfa_offset -32 + bne a0, zero, 9f /* syscall error? */ + li a0, -EOVERFLOW + bne t1, zero, 9f /* y2038? */ + li a0, 0 + li t3, 1000 + divu t2, t2, t3 /* nsec -> usec */ + sw t0, 0(a1) /* tz->tv_sec */ + sw t2, 4(a1) /* tz->tv_usec */ +9: ret +#endif + .cfi_endproc +endf __vdso_gettimeofday + + .cfi_startproc + +#ifdef __NR_clock_gettime +vdso_syscall __vdso_clock_gettime, __NR_clock_gettime +#else +vdso_syscall __vdso_clock_gettime, __NR_clock_gettime64 +#endif + +#ifdef __NR_clock_getres +vdso_syscall __vdso_clock_getres, __NR_clock_getres +#else +vdso_syscall __vdso_clock_getres, __NR_clock_getres_time64 +#endif + +vdso_syscall __vdso_getcpu, __NR_getcpu + +__vdso_flush_icache: + /* qemu does not need to flush the icache */ + li a0, 0 + ret +endf __vdso_flush_icache + + .cfi_endproc + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + + .cfi_startproc simple + .cfi_signal_frame + +#define sizeof_reg (__riscv_xlen / 4) +#define sizeof_freg 8 +#define B_GR (offsetof_uc_mcontext - sizeof_rt_sigframe) +#define B_FR (offsetof_uc_mcontext - sizeof_rt_sigframe + offsetof_freg0) + + .cfi_def_cfa 2, sizeof_rt_sigframe + + /* Return address */ + .cfi_return_column 64 + .cfi_offset 64, B_GR + 0 /* pc */ + + /* Integer registers */ + .cfi_offset 1, B_GR + 1 * sizeof_reg /* r1 (ra) */ + .cfi_offset 2, B_GR + 2 * sizeof_reg /* r2 (sp) */ + .cfi_offset 3, B_GR + 3 * sizeof_reg + .cfi_offset 4, B_GR + 4 * sizeof_reg + .cfi_offset 5, B_GR + 5 * sizeof_reg + .cfi_offset 6, B_GR + 6 * sizeof_reg + .cfi_offset 7, B_GR + 7 * sizeof_reg + .cfi_offset 8, B_GR + 8 * sizeof_reg + .cfi_offset 9, B_GR + 9 * sizeof_reg + .cfi_offset 10, B_GR + 10 * sizeof_reg + .cfi_offset 11, B_GR + 11 * sizeof_reg + .cfi_offset 12, B_GR + 12 * sizeof_reg + .cfi_offset 13, B_GR + 13 * sizeof_reg + .cfi_offset 14, B_GR + 14 * sizeof_reg + .cfi_offset 15, B_GR + 15 * sizeof_reg + .cfi_offset 16, B_GR + 16 * sizeof_reg + .cfi_offset 17, B_GR + 17 * sizeof_reg + .cfi_offset 18, B_GR + 18 * sizeof_reg + .cfi_offset 19, B_GR + 19 * sizeof_reg + .cfi_offset 20, B_GR + 20 * sizeof_reg + .cfi_offset 21, B_GR + 21 * sizeof_reg + .cfi_offset 22, B_GR + 22 * sizeof_reg + .cfi_offset 23, B_GR + 23 * sizeof_reg + .cfi_offset 24, B_GR + 24 * sizeof_reg + .cfi_offset 25, B_GR + 25 * sizeof_reg + .cfi_offset 26, B_GR + 26 * sizeof_reg + .cfi_offset 27, B_GR + 27 * sizeof_reg + .cfi_offset 28, B_GR + 28 * sizeof_reg + .cfi_offset 29, B_GR + 29 * sizeof_reg + .cfi_offset 30, B_GR + 30 * sizeof_reg + .cfi_offset 31, B_GR + 31 * sizeof_reg /* r31 */ + + .cfi_offset 32, B_FR + 0 /* f0 */ + .cfi_offset 33, B_FR + 1 * sizeof_freg /* f1 */ + .cfi_offset 34, B_FR + 2 * sizeof_freg + .cfi_offset 35, B_FR + 3 * sizeof_freg + .cfi_offset 36, B_FR + 4 * sizeof_freg + .cfi_offset 37, B_FR + 5 * sizeof_freg + .cfi_offset 38, B_FR + 6 * sizeof_freg + .cfi_offset 39, B_FR + 7 * sizeof_freg + .cfi_offset 40, B_FR + 8 * sizeof_freg + .cfi_offset 41, B_FR + 9 * sizeof_freg + .cfi_offset 42, B_FR + 10 * sizeof_freg + .cfi_offset 43, B_FR + 11 * sizeof_freg + .cfi_offset 44, B_FR + 12 * sizeof_freg + .cfi_offset 45, B_FR + 13 * sizeof_freg + .cfi_offset 46, B_FR + 14 * sizeof_freg + .cfi_offset 47, B_FR + 15 * sizeof_freg + .cfi_offset 48, B_FR + 16 * sizeof_freg + .cfi_offset 49, B_FR + 17 * sizeof_freg + .cfi_offset 50, B_FR + 18 * sizeof_freg + .cfi_offset 51, B_FR + 19 * sizeof_freg + .cfi_offset 52, B_FR + 20 * sizeof_freg + .cfi_offset 53, B_FR + 21 * sizeof_freg + .cfi_offset 54, B_FR + 22 * sizeof_freg + .cfi_offset 55, B_FR + 23 * sizeof_freg + .cfi_offset 56, B_FR + 24 * sizeof_freg + .cfi_offset 57, B_FR + 25 * sizeof_freg + .cfi_offset 58, B_FR + 26 * sizeof_freg + .cfi_offset 59, B_FR + 27 * sizeof_freg + .cfi_offset 60, B_FR + 28 * sizeof_freg + .cfi_offset 61, B_FR + 29 * sizeof_freg + .cfi_offset 62, B_FR + 30 * sizeof_freg + .cfi_offset 63, B_FR + 31 * sizeof_freg /* f31 */ + + nop + +__vdso_rt_sigreturn: + raw_syscall __NR_rt_sigreturn +endf __vdso_rt_sigreturn + + .cfi_endproc diff --git a/linux-user/riscv/vdso.ld b/linux-user/riscv/vdso.ld new file mode 100644 index 0000000000..aabe2b0ab3 --- /dev/null +++ b/linux-user/riscv/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux riscv replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_4.15 { + global: + __vdso_rt_sigreturn; + __vdso_gettimeofday; + __vdso_clock_gettime; + __vdso_clock_getres; + __vdso_getcpu; + __vdso_flush_icache; + + 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. + */ + . =3D 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 =3D0xd503201f +} --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040244; cv=none; d=zohomail.com; s=zohoarc; b=iBnbulPbMnZnkJJdJ3dHNso2mtmLC612RAdz3wXU6aOUiJWfJf7gPxB1pob0zzJIaz2p9pptypkTe4dlzUwxEU1sIN54GubhYiQi2ZkDUF3iprP75GhnLaeV74BIUUT9teeHiNTd7DZYZ+9yNFtEvFPFKDYxImpSoiajOVzR1is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040244; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/3tJ54DC6q41L7JPgs7kOMzUfYZ/2V5aWV+NmklhMRs=; b=ahn3R5QV7fVbid0c1QxDYlVvTcLhmr0ecZY57xBfWJ2MPq6M7XdRPM2Hk4FEsa2a58FVqPGu1vxJ9FzgKBqE8hraVKat4RLciERch8H6fE9lu08VJm8w7HncYTFJWVJpa9z5LHi8sNpv8cKUMAbNXc040bH/OcQzp9hpdNz/wt0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040244497180.5647141997207; Fri, 29 Sep 2023 19:17:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWS-0000Jt-Ft; Fri, 29 Sep 2023 22:16:00 -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 1qmPWL-0000Fb-A8 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:53 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWG-00021W-6B for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:53 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5859b06509cso1230312a12.2 for ; Fri, 29 Sep 2023 19:15:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040145; x=1696644945; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/3tJ54DC6q41L7JPgs7kOMzUfYZ/2V5aWV+NmklhMRs=; b=ObTYXCvQX9b2eUVnFndFnuYpltJDI1zGDc3pvjjaxos93RS92gKdVT8HzJ2rS28lnw UWJN06z4WalPoTr7cnMzhyUMkixmpK6aC7nP9alaBiqKI6d6O0DLchuVCNd6v9rCnmnS lMG3IjMUNmEhBKYJ9mE/h2ilYDluPjBAYxajA2x4d1Q5HDIbipqehqtInCXEEgVzMRIh NIMAKGTK9IeLwElfs3XaQqPq3qR0JxYU1tFIl7BVN9okIC63Vsu9vH6JDLmvh7E3sfYp +ZO7qaMyweQmcBjnCcRp9oHLBOYLZcs17P6uqkTNnNarbScNCdcFebHqGiL0Ciydh4BS +GQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040145; x=1696644945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/3tJ54DC6q41L7JPgs7kOMzUfYZ/2V5aWV+NmklhMRs=; b=Y0Cgnz1X/mFYkhVXMP2Axvm5QG7Osezu4MuFZceFvRk7Ag2znN2yPJep7yrH/QTFlw cp8NTd9ssuAvWMuXXK3PDdXh308TLZqFNStuuYSqmUA+JcTZBTpUK+mCniJVWpsSZxH9 7cCFgP7GOmCEEoin5//9jtcFvZrL18N/WcdfKDJHhEhs8yFjAP5he9jLr0lS5yWi1Vr/ BG+XU9sB5EFHo9DLpp+WJIVkq9uCkPppyTHzP99Sy23xQdZbfssPeptLN2dVYUzlPG6S K6glQjqI0I9U/wy5R2tXQl1loRPuJKT7oiHjuW9FOfc2FcrleDNuE6JAe+0aSv8bA8Pl BcWw== X-Gm-Message-State: AOJu0Yw+A4X7aRyZb2YfDZP6JgpgIlxCDEuLsDzDDqFgXqWMg08+kuSx o4MK9SKwjhQS/EK1Wl7Re6TY8+3maTF9g6a97Gk= X-Google-Smtp-Source: AGHT+IEcEKNEzfVDS1gf7D+F/M9HSIAEfi03cXwzwsmfPnOlFKvRa+nzVdxs03j7xOr3KHjHYHQ9LA== X-Received: by 2002:a17:90a:6a82:b0:273:4bbc:c3d0 with SMTP id u2-20020a17090a6a8200b002734bbcc3d0mr4883259pjj.27.1696040145046; Fri, 29 Sep 2023 19:15:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, Song Gao Subject: [PATCH v6 15/19] linux-user/loongarch64: Add vdso Date: Fri, 29 Sep 2023 19:15:25 -0700 Message-Id: <20230930021529.987950-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040246372100007 Content-Type: text/plain; charset="utf-8" Requires a relatively recent binutils version in order to avoid spurious R_LARCH_NONE relocations. The presence of these relocs are diagnosed by our gen-vdso tool. Tested-by: Song Gao Reviewed-by: Song Gao Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/loongarch64/vdso-asmoffset.h | 8 ++ linux-user/elfload.c | 2 + linux-user/loongarch64/signal.c | 17 +++- linux-user/loongarch64/Makefile.vdso | 11 ++ linux-user/loongarch64/meson.build | 4 + linux-user/loongarch64/vdso.S | 130 ++++++++++++++++++++++++ linux-user/loongarch64/vdso.ld | 73 +++++++++++++ linux-user/loongarch64/vdso.so | Bin 0 -> 3560 bytes linux-user/meson.build | 1 + 9 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 linux-user/loongarch64/vdso-asmoffset.h create mode 100644 linux-user/loongarch64/Makefile.vdso create mode 100644 linux-user/loongarch64/meson.build create mode 100644 linux-user/loongarch64/vdso.S create mode 100644 linux-user/loongarch64/vdso.ld create mode 100755 linux-user/loongarch64/vdso.so diff --git a/linux-user/loongarch64/vdso-asmoffset.h b/linux-user/loongarch= 64/vdso-asmoffset.h new file mode 100644 index 0000000000..60d113822f --- /dev/null +++ b/linux-user/loongarch64/vdso-asmoffset.h @@ -0,0 +1,8 @@ +#define sizeof_rt_sigframe 0x240 +#define sizeof_sigcontext 0x110 +#define sizeof_sctx_info 0x10 + +#define offsetof_sigcontext 0x130 +#define offsetof_sigcontext_pc 0 +#define offsetof_sigcontext_gr 8 +#define offsetof_fpucontext_fr 0 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ff6951950b..f41a57ebd5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1197,6 +1197,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUPPCState *en =20 #define elf_check_arch(x) ((x) =3D=3D EM_LOONGARCH) =20 +#define VDSO_HEADER "vdso.c.inc" + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/loongarch64/signal.c b/linux-user/loongarch64/signa= l.c index 39572c1190..afcee641a6 100644 --- a/linux-user/loongarch64/signal.c +++ b/linux-user/loongarch64/signal.c @@ -10,9 +10,9 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" - #include "target/loongarch/internals.h" #include "target/loongarch/vec.h" +#include "vdso-asmoffset.h" =20 /* FP context was used */ #define SC_USED_FP (1 << 0) @@ -24,6 +24,11 @@ struct target_sigcontext { uint64_t sc_extcontext[0] QEMU_ALIGNED(16); }; =20 +QEMU_BUILD_BUG_ON(sizeof(struct target_sigcontext) !=3D sizeof_sigcontext); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_pc) + !=3D offsetof_sigcontext_pc); +QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_regs) + !=3D offsetof_sigcontext_gr); =20 #define FPU_CTX_MAGIC 0x46505501 #define FPU_CTX_ALIGN 8 @@ -33,6 +38,9 @@ struct target_fpu_context { uint32_t fcsr; } QEMU_ALIGNED(FPU_CTX_ALIGN); =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_fpu_context, regs) + !=3D offsetof_fpucontext_fr); + #define CONTEXT_INFO_ALIGN 16 struct target_sctx_info { uint32_t magic; @@ -40,6 +48,8 @@ struct target_sctx_info { uint64_t padding; } QEMU_ALIGNED(CONTEXT_INFO_ALIGN); =20 +QEMU_BUILD_BUG_ON(sizeof(struct target_sctx_info) !=3D sizeof_sctx_info); + struct target_ucontext { abi_ulong tuc_flags; abi_ptr tuc_link; @@ -54,6 +64,11 @@ struct target_rt_sigframe { struct target_ucontext rs_uc; }; =20 +QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe) + !=3D sizeof_rt_sigframe); +QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, rs_uc.tuc_mcontext) + !=3D offsetof_sigcontext); + /* * These two structures are not present in guest memory, are private * to the signal implementation, but are largely copied from the diff --git a/linux-user/loongarch64/Makefile.vdso b/linux-user/loongarch64/= Makefile.vdso new file mode 100644 index 0000000000..369de13344 --- /dev/null +++ b/linux-user/loongarch64/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/loongarch64-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/loongarch64 +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ -nostdlib -shared -fpic -Wl,-h,linux-vdso.so.1 \ + -Wl,--build-id=3Dsha1 -Wl,--hash-style=3Dboth \ + -Wl,--no-warn-rwx-segments -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/loongarch64/meson.build b/linux-user/loongarch64/me= son.build new file mode 100644 index 0000000000..17896535f0 --- /dev/null +++ b/linux-user/loongarch64/meson.build @@ -0,0 +1,4 @@ +vdso_inc =3D gen_vdso.process('vdso.so', + extra_args: ['-r', '__vdso_rt_sigreturn']) + +linux_user_ss.add(when: 'TARGET_LOONGARCH64', if_true: vdso_inc) diff --git a/linux-user/loongarch64/vdso.S b/linux-user/loongarch64/vdso.S new file mode 100644 index 0000000000..780a5fda12 --- /dev/null +++ b/linux-user/loongarch64/vdso.S @@ -0,0 +1,130 @@ +/* + * Loongarch64 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include "vdso-asmoffset.h" + + + .text + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro vdso_syscall name, nr +\name: + li.w $a7, \nr + syscall 0 + jr $ra +endf \name +.endm + + .cfi_startproc + +vdso_syscall __vdso_gettimeofday, __NR_gettimeofday +vdso_syscall __vdso_clock_gettime, __NR_clock_gettime +vdso_syscall __vdso_clock_getres, __NR_clock_getres +vdso_syscall __vdso_getcpu, __NR_getcpu + + .cfi_endproc + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + + .cfi_startproc simple + .cfi_signal_frame + +#define B_GR offsetof_sigcontext_gr +#define B_FR sizeof_sigcontext + sizeof_sctx_info + offsetof_fpucontext_fr + + .cfi_def_cfa 2, offsetof_sigcontext + + /* Return address */ + .cfi_return_column 64 + .cfi_offset 64, offsetof_sigcontext_pc /* pc */ + + /* Integer registers */ + .cfi_offset 1, B_GR + 1 * 8 + .cfi_offset 2, B_GR + 2 * 8 + .cfi_offset 3, B_GR + 3 * 8 + .cfi_offset 4, B_GR + 4 * 8 + .cfi_offset 5, B_GR + 5 * 8 + .cfi_offset 6, B_GR + 6 * 8 + .cfi_offset 7, B_GR + 7 * 8 + .cfi_offset 8, B_GR + 8 * 8 + .cfi_offset 9, B_GR + 9 * 8 + .cfi_offset 10, B_GR + 10 * 8 + .cfi_offset 11, B_GR + 11 * 8 + .cfi_offset 12, B_GR + 12 * 8 + .cfi_offset 13, B_GR + 13 * 8 + .cfi_offset 14, B_GR + 14 * 8 + .cfi_offset 15, B_GR + 15 * 8 + .cfi_offset 16, B_GR + 16 * 8 + .cfi_offset 17, B_GR + 17 * 8 + .cfi_offset 18, B_GR + 18 * 8 + .cfi_offset 19, B_GR + 19 * 8 + .cfi_offset 20, B_GR + 20 * 8 + .cfi_offset 21, B_GR + 21 * 8 + .cfi_offset 22, B_GR + 22 * 8 + .cfi_offset 23, B_GR + 23 * 8 + .cfi_offset 24, B_GR + 24 * 8 + .cfi_offset 25, B_GR + 25 * 8 + .cfi_offset 26, B_GR + 26 * 8 + .cfi_offset 27, B_GR + 27 * 8 + .cfi_offset 28, B_GR + 28 * 8 + .cfi_offset 29, B_GR + 29 * 8 + .cfi_offset 30, B_GR + 30 * 8 + .cfi_offset 31, B_GR + 31 * 8 + + /* Floating point registers */ + .cfi_offset 32, B_FR + 0 + .cfi_offset 33, B_FR + 1 * 8 + .cfi_offset 34, B_FR + 2 * 8 + .cfi_offset 35, B_FR + 3 * 8 + .cfi_offset 36, B_FR + 4 * 8 + .cfi_offset 37, B_FR + 5 * 8 + .cfi_offset 38, B_FR + 6 * 8 + .cfi_offset 39, B_FR + 7 * 8 + .cfi_offset 40, B_FR + 8 * 8 + .cfi_offset 41, B_FR + 9 * 8 + .cfi_offset 42, B_FR + 10 * 8 + .cfi_offset 43, B_FR + 11 * 8 + .cfi_offset 44, B_FR + 12 * 8 + .cfi_offset 45, B_FR + 13 * 8 + .cfi_offset 46, B_FR + 14 * 8 + .cfi_offset 47, B_FR + 15 * 8 + .cfi_offset 48, B_FR + 16 * 8 + .cfi_offset 49, B_FR + 17 * 8 + .cfi_offset 50, B_FR + 18 * 8 + .cfi_offset 51, B_FR + 19 * 8 + .cfi_offset 52, B_FR + 20 * 8 + .cfi_offset 53, B_FR + 21 * 8 + .cfi_offset 54, B_FR + 22 * 8 + .cfi_offset 55, B_FR + 23 * 8 + .cfi_offset 56, B_FR + 24 * 8 + .cfi_offset 57, B_FR + 25 * 8 + .cfi_offset 58, B_FR + 26 * 8 + .cfi_offset 59, B_FR + 27 * 8 + .cfi_offset 60, B_FR + 28 * 8 + .cfi_offset 61, B_FR + 29 * 8 + .cfi_offset 62, B_FR + 30 * 8 + .cfi_offset 63, B_FR + 31 * 8 + + nop + +__vdso_rt_sigreturn: + li.w $a7, __NR_rt_sigreturn + syscall 0 + .cfi_endproc +endf __vdso_rt_sigreturn diff --git a/linux-user/loongarch64/vdso.ld b/linux-user/loongarch64/vdso.ld new file mode 100644 index 0000000000..682446ed0c --- /dev/null +++ b/linux-user/loongarch64/vdso.ld @@ -0,0 +1,73 @@ +/* + * Linker script for linux loongarch64 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_5.10 { + global: + __vdso_getcpu; + __vdso_clock_getres; + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_rt_sigreturn; + + 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. + */ + . =3D 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 =3D0xd503201f +} diff --git a/linux-user/loongarch64/vdso.so b/linux-user/loongarch64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bfaa26f2bfe1aaa01d9a349b8b0= 30ef6323e1f8e GIT binary patch literal 3560 zcmc&%|4$r66ra5Rj;76P?0 z*pkLHYK<{!)EKHwLri1P7+ZfbCjMajKaBm!V50tDu=3Dw8YyuH2cp)oP>9lM{I&%8Hp zXLj~8gA7MHeVQiNbm6WE5mF5|x7&qwgpg0iJ4G?pw^^Ls9SZ#nWrv<>Jc~e?al4l|Sbrr}2@GURkPzG*L^O6Z1o0 zZQxR4^6J;qwR=3DBlPwiV9O)S*Bz9|f2E}l&r6A9CtoKB?29A1Vu*s!Ds2$jnW)gtYFeN| zw>bJ9NW=3DJ%e$Dv}pkqi2l>63vMIiy&S@4|!eIB;WL6Hf?87P^7(iCi;g0dIDpM>&p zsEEUkQP?>GmCpm5hF#CW9mBBu8Q3!jcShl^eyHk$y%D(k1O&RFx)bi{fP35Ez7W*h zkWl-Tg!{jg@W2-m>eeJY_?d)#*Cagjsf7Kj5+1%P;lLFM^&d-USdnn>BMHF|B|P%J zgvR$IG`%C?(AyFoeM>^~n-UJcA>pytBpkUYq2*Nxk6)1R#Il5=3D=3DOi3klJMlMML52( z2v7a7XwT0Ej{O*3{0;c8oWtc+FKUE{_`iE4SN`5rUdj33Z0r68yRN3OAn5oGS#RAA zxJNnqpU>-#4(9V)=3D|YjCv-$qTj^5_;C64aq^QEGY{^|IovTo-4mpS`TKL77@N<+O^ zQtOucA&szjr7z6aS%us49#Q^Y-RwoakPgNa@6|8bq{!c^gXb0R)y;Pm@72d^$QRN< zVRW48Ywhi67e;^dWP7+{C>l0UD4uTZ3LAs1ZIQ5n+JZZ+5$-lRqpiJRqq`$2jIPMZ zw$_Mova@p_JeYIbQqTTIrj!agisuqHha-K=3D)30E5VcLw1ieT2v*qG!}Ds3i2FustA zO;3(l1@uLXnK2QZNX-V5v24=3Dj&5X^=3DB{JE`bSkf6#6>WXG{!Tr>4cGtqbJuy&`ivm zIHCW61+Wj=3Db9mq9?~>78U%5oIuehxiE7rcFNM5&$d|u;yjrTCtW7>b|EW`Qvyu-Mz z`lWcv&GCGWIfNX2Dkx5t@p@-uf7R^7Gf#R)doSnb^BE(xlX3qX$MevFZNKALiR1Y^ z$GBCz)hXWERNoxW=3DRZb1@3Fr}7Q_i`*mUJ*y<+5jlAoXRFg}a%boS#q>l!1CkBrv{ zkKbm67{>xV6UTec;nnP@kmrqQTE^~pKF=3D{Wdj{;yk6V`&&$7tpK1QB@&gbbaFE{%T t^8Y9M)xhXH4|s8YUVn6E (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040254004113.14105585903542; Fri, 29 Sep 2023 19:17:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWP-0000HB-HN; Fri, 29 Sep 2023 22:15:57 -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 1qmPWK-0000FL-Ov for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:52 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWF-00021d-7X for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:52 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-278f0f565e2so5009644a91.2 for ; Fri, 29 Sep 2023 19:15:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040146; x=1696644946; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YJcyirbvLQVJctyldxC5+6m9ivsSds5BTmEyQkVSipk=; b=Cx42ZvPia5IXuOJxKHEseUi6JIPB2HVRTNg+9gDl+OIVNhTtvd5u+U8kJ+9xw38upM M5heCkKrxsqpg7Y+6RlOyv81CGnEadlGgVhICxodBEzSb3kZG365L+jj88ugJ9u6bBIH yRXbHAnNrlzhgMHMGycz50nIEn7tlQffj0Meqkr9kS8YnGJ7kXn9Zqx3wJUB3aGPtr7v zn0+v9wTih3Si06raOVHt4effFhfjC61sqzeczSDaoI6N7iK+XLyDwZZayRQUz9cGsWt +MfaLqdVLpesT6PZjo9Sgy3+7By3UL0fCvW3b2JxGQNAoE7oVOqDriHlH2PmO6ucRR5r gl9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040146; x=1696644946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YJcyirbvLQVJctyldxC5+6m9ivsSds5BTmEyQkVSipk=; b=YQNn1sHQULD058LixkcSXWXdXGIzYqCQl019lONP9OPiOht9HMkxgFEAEgBSnscb5c NWdQfzFrOvJlMiJ+KiHOs32mNg18tc/UKiaf0JTJFD0zoA9tjY3PI5ZX+0IU4dTDVo3H e51InsDSVNPmaqkeYSO4uuNkLAXWKODeqyvZMBMeEFw6fgocu6D1bXvrPqPyKoZLFGOV akVDVOkB2YPI7WPNDTKJP0uubHAqQ7jqwZgEBV1B1QPANLFsnKzW/SNAZJ5lruEMNgAo pumzXGTwCnbfsVWrTY6y4vTOMUvFNY1JdyFNGyJhShJX+KEPfvOG8MAORbNBPg2yjr/8 mDOA== X-Gm-Message-State: AOJu0YxLgb2cREV64HRAZ3aNAapEuiVdp7pA6bdgw3AaYxzkmM2gchEF rv5ZeHN1n+N629QxXiyl8JXEcJDuCTq+2A6YLQc= X-Google-Smtp-Source: AGHT+IEWMFpZsXRaO+CElrB/lQ+GbnqybPx2LT4W+b4asnrFAhZeAgoLqylon3kSkMtffdK/rWAnLw== X-Received: by 2002:a17:90b:4b07:b0:278:eb1f:5538 with SMTP id lx7-20020a17090b4b0700b00278eb1f5538mr5566339pjb.46.1696040145780; Fri, 29 Sep 2023 19:15:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 16/19] linux-user/ppc: Add vdso Date: Fri, 29 Sep 2023 19:15:26 -0700 Message-Id: <20230930021529.987950-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040256134100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/ppc/vdso-asmoffset.h | 20 +++ linux-user/elfload.c | 8 ++ linux-user/ppc/signal.c | 31 +++-- linux-user/gen-vdso-elfn.c.inc | 7 + linux-user/ppc/Makefile.vdso | 20 +++ linux-user/ppc/meson.build | 12 ++ linux-user/ppc/vdso-32.ld | 70 ++++++++++ linux-user/ppc/vdso-32.so | Bin 0 -> 3020 bytes linux-user/ppc/vdso-64.ld | 68 +++++++++ linux-user/ppc/vdso-64.so | Bin 0 -> 3896 bytes linux-user/ppc/vdso-64le.so | Bin 0 -> 3896 bytes linux-user/ppc/vdso.S | 239 ++++++++++++++++++++++++++++++++ 12 files changed, 467 insertions(+), 8 deletions(-) create mode 100644 linux-user/ppc/vdso-asmoffset.h create mode 100644 linux-user/ppc/Makefile.vdso create mode 100644 linux-user/ppc/vdso-32.ld create mode 100755 linux-user/ppc/vdso-32.so create mode 100644 linux-user/ppc/vdso-64.ld create mode 100755 linux-user/ppc/vdso-64.so create mode 100755 linux-user/ppc/vdso-64le.so create mode 100644 linux-user/ppc/vdso.S diff --git a/linux-user/ppc/vdso-asmoffset.h b/linux-user/ppc/vdso-asmoffse= t.h new file mode 100644 index 0000000000..6844c8c81c --- /dev/null +++ b/linux-user/ppc/vdso-asmoffset.h @@ -0,0 +1,20 @@ +/* + * Size of dummy stack frame allocated when calling signal handler. + * See arch/powerpc/include/asm/ptrace.h. + */ +#ifdef TARGET_ABI32 +# define SIGNAL_FRAMESIZE 64 +#else +# define SIGNAL_FRAMESIZE 128 +#endif + +#ifdef TARGET_ABI32 +# define offsetof_sigframe_mcontext 0x20 +# define offsetof_rt_sigframe_mcontext 0x140 +# define offsetof_mcontext_fregs 0xc0 +# define offsetof_mcontext_vregs 0x1d0 +#else +# define offsetof_rt_sigframe_mcontext 0xe8 +# define offsetof_mcontext_fregs 0x180 +# define offsetof_mcontext_vregs_ptr 0x288 +#endif diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f41a57ebd5..4a2d21a1f9 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1187,6 +1187,14 @@ static void elf_core_copy_regs(target_elf_gregset_t = *regs, const CPUPPCState *en #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 +#ifndef TARGET_PPC64 +# define VDSO_HEADER "vdso-32.c.inc" +#elif TARGET_BIG_ENDIAN +# define VDSO_HEADER "vdso-64.c.inc" +#else +# define VDSO_HEADER "vdso-64le.c.inc" +#endif + #endif =20 #ifdef TARGET_LOONGARCH64 diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index a616f20efb..7e7302823b 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -21,14 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" - -/* Size of dummy stack frame allocated when calling signal handler. - See arch/powerpc/include/asm/ptrace.h. */ -#if defined(TARGET_PPC64) -#define SIGNAL_FRAMESIZE 128 -#else -#define SIGNAL_FRAMESIZE 64 -#endif +#include "vdso-asmoffset.h" =20 /* See arch/powerpc/include/asm/ucontext.h. Only used for 32-bit PPC; on 64-bit PPC, sigcontext and mcontext are one and the same. */ @@ -73,6 +66,16 @@ struct target_mcontext { #endif }; =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, mc_fregs) + !=3D offsetof_mcontext_fregs); +#if defined(TARGET_PPC64) +QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, v_regs) + !=3D offsetof_mcontext_vregs_ptr); +#else +QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, mc_vregs) + !=3D offsetof_mcontext_vregs); +#endif + /* See arch/powerpc/include/asm/sigcontext.h. */ struct target_sigcontext { target_ulong _unused[4]; @@ -161,6 +164,7 @@ struct target_ucontext { #endif }; =20 +#if !defined(TARGET_PPC64) /* See arch/powerpc/kernel/signal_32.c. */ struct target_sigframe { struct target_sigcontext sctx; @@ -168,6 +172,10 @@ struct target_sigframe { int32_t abigap[56]; }; =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_sigframe, mctx) + !=3D offsetof_sigframe_mcontext); +#endif + #if defined(TARGET_PPC64) =20 #define TARGET_TRAMP_SIZE 6 @@ -184,6 +192,10 @@ struct target_rt_sigframe { char abigap[288]; } __attribute__((aligned(16))); =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, + uc.tuc_sigcontext.mcontext) + !=3D offsetof_rt_sigframe_mcontext); + #else =20 struct target_rt_sigframe { @@ -192,6 +204,9 @@ struct target_rt_sigframe { int32_t abigap[56]; }; =20 +QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.tuc_mcontext) + !=3D offsetof_rt_sigframe_mcontext); + #endif =20 #if defined(TARGET_PPC64) diff --git a/linux-user/gen-vdso-elfn.c.inc b/linux-user/gen-vdso-elfn.c.inc index 7034c36d5e..95856eb839 100644 --- a/linux-user/gen-vdso-elfn.c.inc +++ b/linux-user/gen-vdso-elfn.c.inc @@ -273,7 +273,14 @@ static void elfN(process)(FILE *outf, void *buf, bool = need_bswap) errors++; break; =20 + case PT_LOPROC + 3: + if (ehdr->e_machine =3D=3D EM_PPC64) { + break; /* DT_PPC64_OPT: integer bitmask */ + } + goto do_default; + default: + do_default: /* This is probably something target specific. */ fprintf(stderr, "VDSO has unknown DYNAMIC entry (%lx)\n", (unsigned long)tag); diff --git a/linux-user/ppc/Makefile.vdso b/linux-user/ppc/Makefile.vdso new file mode 100644 index 0000000000..3ca3c6b83e --- /dev/null +++ b/linux-user/ppc/Makefile.vdso @@ -0,0 +1,20 @@ +include $(BUILD_DIR)/tests/tcg/ppc64-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/ppc +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso-32.so $(SUBDIR)/vdso-64.so $(SUBDIR)/vdso-64le.so + +LDFLAGS32 =3D -nostdlib -shared -Wl,-T,$(SUBDIR)/vdso-32.ld \ + -Wl,-h,linux-vdso32.so.1 -Wl,--hash-style=3Dboth -Wl,--build-i= d=3Dsha1 +LDFLAGS64 =3D -nostdlib -shared -Wl,-T,$(SUBDIR)/vdso-64.ld \ + -Wl,-h,linux-vdso64.so.1 -Wl,--hash-style=3Dboth -Wl,--build-i= d=3Dsha1 + +$(SUBDIR)/vdso-32.so: vdso.S vdso-32.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS32) -m32 $< + +$(SUBDIR)/vdso-64.so: vdso.S vdso-64.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS64) -mbig-endian $< + +$(SUBDIR)/vdso-64le.so: vdso.S vdso-64.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS64) -mlittle-endian $< diff --git a/linux-user/ppc/meson.build b/linux-user/ppc/meson.build index 19fead7bc8..80cacae396 100644 --- a/linux-user/ppc/meson.build +++ b/linux-user/ppc/meson.build @@ -3,3 +3,15 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr.s= h', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_32_inc =3D gen_vdso.process('vdso-32.so', extra_args: [ + '-s', '__kernel_sigtramp32', + '-r', '__kernel_sigtramp_rt32' + ]) +linux_user_ss.add(when: 'TARGET_PPC', if_true: vdso_32_inc) + +vdso_64_inc =3D gen_vdso.process('vdso-64.so', + extra_args: ['-r', '__kernel_sigtramp_rt64'= ]) +vdso_64le_inc =3D gen_vdso.process('vdso-64le.so', + extra_args: ['-r', '__kernel_sigtramp_rt6= 4']) +linux_user_ss.add(when: 'TARGET_PPC64', if_true: [vdso_64_inc, vdso_64le_i= nc]) diff --git a/linux-user/ppc/vdso-32.ld b/linux-user/ppc/vdso-32.ld new file mode 100644 index 0000000000..6962696540 --- /dev/null +++ b/linux-user/ppc/vdso-32.ld @@ -0,0 +1,70 @@ +/* + * Linker script for linux powerpc64 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6.15 { + global: + __kernel_gettimeofday; + __kernel_clock_gettime; + __kernel_clock_gettime64; + __kernel_clock_getres; + __kernel_time; + __kernel_sync_dicache; + __kernel_sigtramp32; + __kernel_sigtramp_rt32; + __kernel_getcpu; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS= =3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D 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 + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} diff --git a/linux-user/ppc/vdso-32.so b/linux-user/ppc/vdso-32.so new file mode 100755 index 0000000000000000000000000000000000000000..b19baafb0d38e15b4a24def5c44= a6d684714be45 GIT binary patch literal 3020 zcmbtWeQXp}5P#e27f_&s6{-a-h*%I#XbYl%a{b~XN2zU*57F)Q?%F%r-of3qv<2Um z1QRhNq7Vb7G1Z^}LI}~u5YuQA2$G0I6M`g?$RC*a2ZmczErej|%2|`C~)=3DmL~agwClu?S594u8bd8b zfqm~5&l#xt?zrckFwM4LED~%tTZ4&2xFZ;C3HW-_R)2fc-=3D=3D+Im}9|s+KLqZ?VV}N z`O;`qswL%VN4zKEHv?h6&mVGx$HT3On6G2I8B3IvI)ZI8Z0+GlXZM1xKs;Jj>W)X< zi-dPg?S@Tese6fg(PEqipU>a__~g{z#Mf5vdoKWUZ*VQ^Q#EqTFWv`YACsyTqsX-k zI@c7=3D-M9w15NZkZbI`dKgwb0sGIx87qCC~YY(u^l^odTqROT| zL54*cl3XuS=3D5ET`McKWS(?hx4G;Sx2@1hBvl$W51ahepP$vY^2J5iLTMCiT_Drl$s z+i2=3DGnii(Q5IxXJ54KQIkfsM{hMyj4riXpx*-ABAsJM=3D1*3v95J+hW&uck+9XigP9 zRzW2zY3`>M%^R}l@lPz8f5xH(A6w)ewCITsEn0ZmqD7}HDm`gY*$Iovk6E<%1B;d% zwdl$BELu8X(NphO^mM;P%igwV`C*Gzyk*fdhb(&bO^ep;x2X12i`MV8sIJeV=3Dk7|X zzay#P7fFq`ByG4U>G>ZdZM-3A({)LkuSwc+RniNWC2jpm(u)@*y>vm6c}`N(uq5A* zq~Kz-~@oI*$AOB2TZwh3x1TN<*oID>uY6dgrnZbCNufRMzSnF5U)QoWr+L-4Kh<`U! zygidL)hxn#dtRv-$NBOQ#(P%#g~I#An&kSVE@r^2_6tAnw+yVvp1CWrZN8tLsdd2D z9k>OLF&kLV;9g+PqvH=3DE{(=3DJ^ho5^+&*aa53mxmPAfETD*WUo<^G{;4YICh;-I_{F z8~pB>)vL{#de6FQb9Gg{FjslkS9rYU`kI=3DC>PEBCQ{k;PM-Lq5C>=3DEiQAUq{%l6vRUM5 zjdZ$0zIZ5UPsEazu3#)4jz&fSGa%f-klBKn9yCJ%L~115iC}jEZ{gol5kmEEA-_Ln zt`kjMBTO^F+y^Mv)b~;!bh{T+O>%wD19N?&hPmHV&z-j8xW+jj*HtN)G4gR;tJ>y1 z(8O`f%fZ}_$jAMudUPc)?}JIlEyefGZD5YW38>!n0{=3DCx!nSeTaFW$G70ilwPfTl( zZv+x?+~=3Dy-rvmGIu(MBW)Zbrl4JMgKVCqbHe@y5<^}L)9eX4qUy7DA1Iu3i+aXc@W zjo~rkcm(ra@lLpJRqqBIar!w}@;+_i?_Xm8fWJ9af7_C0mVP#)CnmTqg{%ZkNv1|DMDif%Nj)) z+SG@i^||i;3HB)Dr!rAf{TX@o{{yAc6^gQ0?s{t>&Ub_T#VA&??jrT0FQi60`-@Rj zsW^=3D~W-02{u9k!1`mJ|PoV_YnU0i;>+kW%g%Rg34j;I)dMT)~Ja?jwPd!Xu_)|yK|XHUw=3D50tEm>f$<)Bm zhQU}iT~i&%rURQq)1H=3Dt?cvRVn!u(l_(C{3Gyh04_|H7HgXWg@7wuWzH#9P)F#O@G z?mSG5r1i5A@q6@CBgZL2cDzmahJr>#IW^>HSl^5xuOk7=3DO}b&d z{aCS{D&8=3Dmz9TQdu)#bD*2~~K0VOX%>2dH6L)j3_dlBXj!h!)P&%wehEXu&*7eMv{ zq+v-4?&yQ1y|AnY?mPy|ldvKIcXh+vT~HB+l`&Wqg?l>T-UtMbLgNvrY=3DzbP;Jy}E z(+pKjaQ{=3DVb}u}z2iEO|2Y12xMtGaOJo>c_)nD1L zy>6*NdEzCxQ+{bKG$W~@!LO#uGT*x+N6GHB1HYwx*W>Z2QWR^GNGt5Q|d5GDl zA=3D{aa8S*f*aYG(qHetwTnN1q?4)RY~}#!MMuHg3vJW)r52 zGMhAIjM|!=3Dz$!=3Dz&mP{}kvt*LlxFwGB$0-wWIb6u4NZImL8v8y}K}bk2f@gtM>_+P#%fS8+OzvKMvy zr{d-n$3oHP5Md=3D4mF1paoVT#O|a<}b&Ey2}4<9@Dxy6KCcdtgp^Z&QqTDRld{t zoIO}y<-HR1ysl2?Hx~bCM(1we;LJ7-)b?!cubLyjtoNM%=3DT!UD-&T+A&0nn^T|W=3Di z@ABy5svUZd6CVAF(rLWj@aQx0phq83^~*&#bhsthyr&+|Z2Ue6H|!2KwgsCT!n;Fl zGtXgf(wK4LyXm4hFU*o!{!Kn`JDQnF+-@9M1hT_@xkx8sF2k76ES1j1MIbhuiu5I; z4#B#Jkz7Osx>EyzL?oMFJ(po+FrLXK)2SIoI3@z|M7RqxRXm)CVNGp`KrTL%Q$zTl zp#odb-@kg@seS40&#IzcX#RCsjYRD$y-)T2brGlD?StafzH)NgdbIU-q3U1nbB*Gf zidW}`8@~ee&3I`Yw;C0F9%yvyv%AngJ;!#uN|ZzOug?vQbTsOBb8716r*Wvo@6uaE z@#olf&zTU~>e(ERjwfTM$EW*u@;inobibdSV7%$~C3`RSKdl@pUY}PQ#S-*;`&adx zbLLR-cQziYW89ub=3DlyAo=3Ds555ccHGINB4h2#Vd4w$FS_4+m1;KxhP(rlN!yu4pit} ze`(nZa2_*`eAl7sC-m^P9tkJ~8vza;H z{q8yU%)K-BoV!kQYl~?Zg2fU`M7||NqwZ*!&lbcrh*G>uQ7PsiU4mDm?)K_sdN9`I z+K%Wljf<%%-N{<$r!vu);$`%>UM)4xn&Wl+oDP%U6}lDC%M~qHYqM-D!Uy%ZUR|U8 zSiAieW1ofBj`scH*7la@tux=3DQtI3pvuGN0C{_N=3D+7s+)Y-B4avDjSdBAUUGk_;WTv z`n+zJQUm3xZqxdcjM2iN%u`CduQk86Wx9=3DSgBoVlAG2!w3H{)=3Dbz2W7W_0^ao|xPD zf5bkFB}IietG|m19ebbVFM9ZM$b+~(tIcvMpzY6l?7KBTsd=3D6*y>^Ow%40vG`R_E( z-`P^lk9q9HN$fzO*ETncgrGHMKjQh_Qa8n?*z|sBDC(y+b8l4#O8w=3Dco7&Vzc5g(s zT;6-_ht($F6k6Th5$EnF2CUtK+N;pFby{&#*7w%r#=3D#v}c9ZzP?L4MY+>;oxYV z4fQ8NecV@sPDWCB7KaE84&~c4UcQwYjfd=3DTEEEhy-E6EkoeT~P+R1c%o#>Cnhep;7 zhf|6AI$tW`s}-%g+V>x{H~Q**wVQB0rsszg&R_kmZ#!zz{-XWLdxzG-#QwLxx67!H z&s?xV0Y2Fs#wPcPit162`N9)=3DYmxUU=3DT4}$*)v>b-&4p_Md9%zSEZBWw+4?Yd6 zcf&)wV9ic=3Dcn7R)fk&F*(EzM#0^fF6?}rVIQ2Vt58^3bku`eB{`@(@upF2?hnFEi1 z>OjLK2cG!Efz2N~u;n8MwqA5#+XV-n{Lq1?K5%I6xHi9{9!H(sZ?dgy)vKj*R%L{2 zS7=3DPgJqnEr*`d&ckk2SIDP*TYQ$p@lXj;g93e5<)U!ja4pH*ngkOveRH{?NuCJcE< zp-Dp?R%ptQ&nYx*$Ri5P81i|AGNyb%p)ph13XPkxOQ8u<1{In#Ww%08rVJ@GZOX7h zGp39vl(A%wLSvTfRcPFjQH3Tf8B=3DJ|l1CMqvSgn^)0XU4XvUHQ3S~-UT%psn&)bD) zz|SmDEi&ylUHCT__8EDb1umX^aEPw=3DG>7CwEm9v#=3Dbx9*(Le6c!6&vQpT zvIB?O{cXFNFlXcW#BSbcw{-g3n(du|&cZzGE*b?HKUXfib)iUU`8V|-7pSn5N@WGtnj{MU88wclqcM>5*t+Wc^mTn zWzFYbeGJK+Gq~2#cS>hNj?ep?^=3D0fMA%EH%d`_X7NU{+x;yFI&1J-O$wj|tUy%jmy znjD|=3D2I~fLLgDe*kJo|vZ{pdM{W-s|4rIOW^w+f5uE%D7K2Nje^E2DiT-~x88?&zX zoUd3f(#HJ!9EbG*?5DFfw>ht|=3DK1qC!t>{6p!`73#Qxs@HT*w@?Rnj}O<%FwpYtT^ z3=3Dgawy#6P&KYfEFoWEGNDmr)fuAe)0&Ikej-&>>OFGQ{qFP=3DYte{_cCwMCed-}T}8 WQjSr;8y}D^=3D0BklzBu&{{(k}Ee8OG; literal 0 HcmV?d00001 diff --git a/linux-user/ppc/vdso.S b/linux-user/ppc/vdso.S new file mode 100644 index 0000000000..689010db13 --- /dev/null +++ b/linux-user/ppc/vdso.S @@ -0,0 +1,239 @@ +/* + * PowerPC linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#ifndef _ARCH_PPC64 +# define TARGET_ABI32 +#endif +#include "vdso-asmoffset.h" + + + .text + +.macro endf name + .globl \name + .size \name, .-\name + /* For PPC64, functions have special linkage; we export pointers. */ +#ifndef _ARCH_PPC64 + .type \name, @function +#endif +.endm + +.macro raw_syscall nr + addi 0, 0, \nr + sc +.endm + +.macro vdso_syscall name, nr +\name: + raw_syscall \nr + blr +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 +vdso_syscall __kernel_getcpu, __NR_getcpu +vdso_syscall __kernel_time, __NR_time + +#ifdef __NR_clock_gettime64 +vdso_syscall __kernel_clock_gettime64, __NR_clock_gettime64 +#endif + +__kernel_sync_dicache: + /* qemu does not need to flush caches */ + blr +endf __kernel_sync_dicache + + .cfi_endproc + +/* + * TODO: __kernel_get_tbfreq + * This is probably a constant for QEMU. + */ + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + + .cfi_startproc simple + .cfi_signal_frame + +#ifdef _ARCH_PPC64 +# define __kernel_sigtramp_rt __kernel_sigtramp_rt64 +# define sizeof_reg 8 +#else +# define __kernel_sigtramp_rt __kernel_sigtramp_rt32 +# define sizeof_reg 4 +#endif +#define sizeof_freg 8 +#define sizeof_vreg 16 + + .cfi_def_cfa 1, SIGNAL_FRAMESIZE + offsetof_rt_sigframe_mcontext + + /* Return address */ + .cfi_return_column 67 + .cfi_offset 67, 32 * sizeof_reg /* nip */ + + /* Integer registers */ + .cfi_offset 0, 0 * sizeof_reg + .cfi_offset 1, 1 * sizeof_reg + .cfi_offset 2, 2 * sizeof_reg + .cfi_offset 3, 3 * sizeof_reg + .cfi_offset 4, 4 * sizeof_reg + .cfi_offset 5, 5 * sizeof_reg + .cfi_offset 6, 6 * sizeof_reg + .cfi_offset 7, 7 * sizeof_reg + .cfi_offset 8, 8 * sizeof_reg + .cfi_offset 9, 9 * sizeof_reg + .cfi_offset 10, 10 * sizeof_reg + .cfi_offset 11, 11 * sizeof_reg + .cfi_offset 12, 12 * sizeof_reg + .cfi_offset 13, 13 * sizeof_reg + .cfi_offset 14, 14 * sizeof_reg + .cfi_offset 15, 15 * sizeof_reg + .cfi_offset 16, 16 * sizeof_reg + .cfi_offset 17, 17 * sizeof_reg + .cfi_offset 18, 18 * sizeof_reg + .cfi_offset 19, 19 * sizeof_reg + .cfi_offset 20, 20 * sizeof_reg + .cfi_offset 21, 21 * sizeof_reg + .cfi_offset 22, 22 * sizeof_reg + .cfi_offset 23, 23 * sizeof_reg + .cfi_offset 24, 24 * sizeof_reg + .cfi_offset 25, 25 * sizeof_reg + .cfi_offset 26, 26 * sizeof_reg + .cfi_offset 27, 27 * sizeof_reg + .cfi_offset 28, 28 * sizeof_reg + .cfi_offset 29, 29 * sizeof_reg + .cfi_offset 30, 30 * sizeof_reg + .cfi_offset 31, 31 * sizeof_reg + .cfi_offset 65, 36 * sizeof_reg /* lr */ + .cfi_offset 70, 38 * sizeof_reg /* ccr */ + + /* Floating point registers */ + .cfi_offset 32, offsetof_mcontext_fregs + .cfi_offset 33, offsetof_mcontext_fregs + 1 * sizeof_freg + .cfi_offset 34, offsetof_mcontext_fregs + 2 * sizeof_freg + .cfi_offset 35, offsetof_mcontext_fregs + 3 * sizeof_freg + .cfi_offset 36, offsetof_mcontext_fregs + 4 * sizeof_freg + .cfi_offset 37, offsetof_mcontext_fregs + 5 * sizeof_freg + .cfi_offset 38, offsetof_mcontext_fregs + 6 * sizeof_freg + .cfi_offset 39, offsetof_mcontext_fregs + 7 * sizeof_freg + .cfi_offset 40, offsetof_mcontext_fregs + 8 * sizeof_freg + .cfi_offset 41, offsetof_mcontext_fregs + 9 * sizeof_freg + .cfi_offset 42, offsetof_mcontext_fregs + 10 * sizeof_freg + .cfi_offset 43, offsetof_mcontext_fregs + 11 * sizeof_freg + .cfi_offset 44, offsetof_mcontext_fregs + 12 * sizeof_freg + .cfi_offset 45, offsetof_mcontext_fregs + 13 * sizeof_freg + .cfi_offset 46, offsetof_mcontext_fregs + 14 * sizeof_freg + .cfi_offset 47, offsetof_mcontext_fregs + 15 * sizeof_freg + .cfi_offset 48, offsetof_mcontext_fregs + 16 * sizeof_freg + .cfi_offset 49, offsetof_mcontext_fregs + 17 * sizeof_freg + .cfi_offset 50, offsetof_mcontext_fregs + 18 * sizeof_freg + .cfi_offset 51, offsetof_mcontext_fregs + 19 * sizeof_freg + .cfi_offset 52, offsetof_mcontext_fregs + 20 * sizeof_freg + .cfi_offset 53, offsetof_mcontext_fregs + 21 * sizeof_freg + .cfi_offset 54, offsetof_mcontext_fregs + 22 * sizeof_freg + .cfi_offset 55, offsetof_mcontext_fregs + 23 * sizeof_freg + .cfi_offset 56, offsetof_mcontext_fregs + 24 * sizeof_freg + .cfi_offset 57, offsetof_mcontext_fregs + 25 * sizeof_freg + .cfi_offset 58, offsetof_mcontext_fregs + 26 * sizeof_freg + .cfi_offset 59, offsetof_mcontext_fregs + 27 * sizeof_freg + .cfi_offset 60, offsetof_mcontext_fregs + 28 * sizeof_freg + .cfi_offset 61, offsetof_mcontext_fregs + 29 * sizeof_freg + .cfi_offset 62, offsetof_mcontext_fregs + 30 * sizeof_freg + .cfi_offset 63, offsetof_mcontext_fregs + 31 * sizeof_freg + + /* + * Unlike the kernel, unconditionally represent the Altivec/VSX regs. + * The space within the stack frame is always available, and most of + * our supported processors have them enabled. The only complication + * for PPC64 is the misalignment, so that we have to use indirection. + */ +.macro save_vreg_ofs reg, ofs +#ifdef _ARCH_PPC64 + /* + * vreg =3D *(cfa + offsetof(v_regs)) + ofs + * + * The CFA is input to the expression on the stack, so: + * DW_CFA_expression reg, length (7), + * DW_OP_plus_uconst (0x23), vreg_ptr, DW_OP_deref (0x06), + * DW_OP_plus_uconst (0x23), ofs + */ + .cfi_escape 0x10, 77 + \reg, 7, 0x23, (offsetof_mcontext_vregs_ptr & 0x7f= ) + 0x80, offsetof_mcontext_vregs_ptr >> 7, 0x06, 0x23, (\ofs & 0x7f) | 0x8= 0, \ofs >> 7 +#else + .cfi_offset 77 + \reg, offsetof_mcontext_vregs + \ofs +#endif +.endm + +.macro save_vreg reg + save_vreg_ofs \reg, (\reg * sizeof_vreg) +.endm + + save_vreg 0 + save_vreg 1 + save_vreg 2 + save_vreg 3 + save_vreg 4 + save_vreg 5 + save_vreg 6 + save_vreg 7 + save_vreg 8 + save_vreg 9 + save_vreg 10 + save_vreg 11 + save_vreg 12 + save_vreg 13 + save_vreg 14 + save_vreg 15 + save_vreg 16 + save_vreg 17 + save_vreg 18 + save_vreg 19 + save_vreg 20 + save_vreg 21 + save_vreg 22 + save_vreg 23 + save_vreg 24 + save_vreg 25 + save_vreg 26 + save_vreg 27 + save_vreg 28 + save_vreg 29 + save_vreg 30 + save_vreg 31 + save_vreg 32 + save_vreg_ofs 33, (32 * sizeof_vreg + 12) + + nop + +__kernel_sigtramp_rt: + raw_syscall __NR_rt_sigreturn +endf __kernel_sigtramp_rt + +#ifndef _ARCH_PPC64 + /* + * The non-rt sigreturn has the same layout at a different offset. + * Move the CFA and leave all othe other descriptions the same. + */ + .cfi_def_cfa 1, SIGNAL_FRAMESIZE + offsetof_sigframe_mcontext + nop +__kernel_sigtramp32: + raw_syscall __NR_sigreturn +endf __kernel_sigtramp32 +#endif + + .cfi_endproc --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040220; cv=none; d=zohomail.com; s=zohoarc; b=bLgFpo8MhdHYlO0Ydw4o0bt8p+8Nv7lRymNkpdb7XgMvXliZxU7L0s1+JFQLdPE26t+vXbwMnZ+UywK6+j0VTW6t4y2h9FCmhe0VL5uBSmnZIBgFvG6xHrlU6d3YadynKnZM5vZm1Qck2KAW7THgpZhbXXiwhiULrncE4ogpoZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040220; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ri0JhH0bqEd6DenOKDhZabd3UHTdrfzqwpuOkMZwzx4=; b=C10AQNjB1guppzPBu8fMOWRXDfJRx3o+Aa031ivGG7V+dRNWYsnf1/SI2Vp6TNJJXYR5OCETzqB3++OObzDTNr5TYm8R6o8sTExOURsDy/2cv5RlvJ/yQfWyJWw2Mq0fugKs+1EKS7ADdxQdTV8gzooXzaG/VzSg0bPGQN8R1yQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040220469988.072727103962; Fri, 29 Sep 2023 19:17:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWR-0000Ja-Ln; Fri, 29 Sep 2023 22:15:59 -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 1qmPWJ-0000FG-9d for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:52 -0400 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWF-00022L-SX for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:51 -0400 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-57bab8676f9so5497027eaf.3 for ; Fri, 29 Sep 2023 19:15:47 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040146; x=1696644946; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ri0JhH0bqEd6DenOKDhZabd3UHTdrfzqwpuOkMZwzx4=; b=kInwXAHCv5tsaUDiTlfkdACIWJcOWx97RZA/UVcc/Ycs35jln+FRAgwSbNdjoqQIHe EjsoHRxYR3m5grjHrQZPaA47Dc52EKOwGy209tRT/F0BdkRIxrhNAguSz4UY66MOfLnn lCQJJp7xAYmVS7Gx6Oxg2zcLXyDhY2ZoqlrJG1GDLm8QcMNE4iBA/cxhpGyuqaKx4WH+ j07J0bHlMJW6LiF3bX4MrylDTQH52zRv+XuLmVhm52SFtzyXCvoZ/uwq5rf4euSxIzq/ j5Lovp82Db3edm3OyCwyC6dzEa8Zqnw7DjMMBryEZTXbTb8DO0DCPv0ns4BYTEdZ4T+q oYpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040146; x=1696644946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ri0JhH0bqEd6DenOKDhZabd3UHTdrfzqwpuOkMZwzx4=; b=LoqIaon5sJLBFmhfHD3FiN4UuRF41kSCgJTuh9GfFt/6IzyTdfuC6foatT1n8rPQOO mOaL770V+sqTMMMt0kMKFeYc2DJUMEA5X7iebKlYW38CcZ2+7kufXJu22E+MVrIZTi25 1aOKHKE6T0B/kyX9l84a2AFZ35aloPQG4Hkopkf8rQh8wVFrJie2MofTzCelNtu/5aHp 5e3KYhOFJbqWN25qnV1/0rH20/MrpQleDrshhzXoUKuGvm+rFYoBMZIdhXavXqirTgtU zLGoQBy9ox3hYzr2KOSmFnULWb6YCOo763IBX1ToKRXNjFAPd3aqTnXQCWELBBZzhv4M sanw== X-Gm-Message-State: AOJu0YwDgMRi9BAO8E9IyxTaVMHFagvBWmwo3qk0jZ9hFTKSuy4mkPmp Lx1lm/01o0FdERQo+X7JHNuvqimlN2RNDIsC23g= X-Google-Smtp-Source: AGHT+IGBvEbr0LxykD3PM2ItSolQ93F5KLvMYzoE0vhoNsm5vDJQzve8q6EiGztwYreJdo0uvLlNFg== X-Received: by 2002:a05:6358:7e07:b0:142:fba8:dcfc with SMTP id o7-20020a0563587e0700b00142fba8dcfcmr7210418rwm.16.1696040146581; Fri, 29 Sep 2023 19:15:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 17/19] linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD Date: Fri, 29 Sep 2023 19:15:27 -0700 Message-Id: <20230930021529.987950-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c2f; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc2f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040222091100005 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/s390x/signal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index f72165576f..0f8b8e04bf 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -26,7 +26,8 @@ #define __NUM_FPRS 16 #define __NUM_ACRS 16 =20 -#define __SIGNAL_FRAMESIZE 160 /* FIXME: 31-bit mode -> 96 */ +/* Minimum stack frame size */ +#define STACK_FRAME_OVERHEAD 160 =20 #define _SIGCONTEXT_NSIG 64 #define _SIGCONTEXT_NSIG_BPW 64 /* FIXME: 31-bit mode -> 32 */ @@ -63,7 +64,7 @@ typedef struct { } target_sigcontext; =20 typedef struct { - uint8_t callee_used_stack[__SIGNAL_FRAMESIZE]; + uint8_t callee_used_stack[STACK_FRAME_OVERHEAD]; target_sigcontext sc; target_sigregs sregs; int signo; @@ -83,7 +84,7 @@ struct target_ucontext { }; =20 typedef struct { - uint8_t callee_used_stack[__SIGNAL_FRAMESIZE]; + uint8_t callee_used_stack[STACK_FRAME_OVERHEAD]; /* * This field is no longer initialized by the kernel, but it's still a= part * of the ABI. --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040289; cv=none; d=zohomail.com; s=zohoarc; b=J/maLmzvI9XQz5STNyjvqHYULW6UutZFRP2iOuibKvdcnViB7P0hhbelEx0yFcA/YoZRVE5sxk7/9ZWvl+iGWb5Ku3rFwpw6JUag5Q9owNnRuBv6b1FbnjHvtMbAMyeVCg0SdHlADjb3L/FEiHTA1Z0yp8CmR51wgMSsvb72vqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040289; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dbZCNQiigqs1hMt3UuY9ADMbzmShhGqncMaRm2ACjJ8=; b=cOIBpQbgVsmv2OlEW+PfLdhZYzvWZcrMFuRD2VU2X42bUBn/aVXOUyQO8Dog//gK6hP6mgtUoJJPJj1TaWdE1CikMH9BIaC4LGJKacpCssvLIsHgXHF1YwhOycr1PNx2+jjuE+Fs60mZf5X5d0yJUnsM8jKGYTPt99G+fLm5/Y4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040289784376.08707272058905; Fri, 29 Sep 2023 19:18:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWQ-0000If-RH; Fri, 29 Sep 2023 22:15:58 -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 1qmPWN-0000G9-52 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:55 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWH-00022a-66 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:54 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6934202b8bdso3571069b3a.1 for ; Fri, 29 Sep 2023 19:15:48 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040147; x=1696644947; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dbZCNQiigqs1hMt3UuY9ADMbzmShhGqncMaRm2ACjJ8=; b=BGmb7a5XCNMybYfoZVPKtgvwLsDGBHklrqsjJeXh6Ds5/kLPPc1wdTYb1Sjxu0hZHd YKJiUzMKw6z1ZkMgwPNwlnPO6eGpLADIYDEI6ITZTrurUq2Z4iF+ddd+a/pnaQKjiU36 6tMhydBa6eC/J0pm564Dfbnt+4ORyFJB6UpqzMAhhSOVZev7CX6NZXAXAtllqsHlJnQv GlLJm2C+IUSV6azS6vQlcrxBfyrAN1v7v5NW/ZUbg7LKsTA94dTIKVdzausw84AEdpQY fFTDvtxbj85l+qRhQEY5ZP6oxJaIwAJI+MBm2lmToFiMSj0m9n6uFPZORW4LVy41idmw XLDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040147; x=1696644947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dbZCNQiigqs1hMt3UuY9ADMbzmShhGqncMaRm2ACjJ8=; b=bKBLtcKAW2jeqa8zC73TbWydSRMuQLxt4zvX3J8Am0+dgUNdfbQv4byfjxQKY+s/vs GcqxYzf6XaSfRRDGUJsLIncrHFyc/r6ERX4uXfkUuH+NR9r2dIcsLcaJTfgWhvyRCvlC Dyqnb4knH4yCx3RkOxHHsEWlYCF4s8qoDMlZcBGWmQSJoEGEknStqzk53ZUyg5OUda1z nsQDkSNcMcCU9fTIAFRNKgV+iZhfLFggTiiw5StBYFS29PQcmZuNsim7a/FCUUG+mfjt UZvgJekzpS81bZO4Yl+DTuhcCUwlcwF/1KyJBDcw3EoqYXjPSZChKlmU7DiMMsmBlEGb AX5g== X-Gm-Message-State: AOJu0Yxnoj83kIqyfa1ns0lfLD8SjVyMCm8zRLEnrKXihgZ9JKWwDry7 syqBwmuinz85NuvTmjBZ71gXFet5+chwBvda6oY= X-Google-Smtp-Source: AGHT+IEU80+rQAv1vphbVBoRNTGHVryyGajuu/dEOSo0qX1qHJKqEUixc3gxvCjKFgBK9xcvc0IABQ== X-Received: by 2002:a05:6a21:a5a7:b0:162:650c:76b8 with SMTP id gd39-20020a056a21a5a700b00162650c76b8mr7444317pzc.45.1696040147527; Fri, 29 Sep 2023 19:15:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 18/19] linux-user/s390x: Add vdso Date: Fri, 29 Sep 2023 19:15:28 -0700 Message-Id: <20230930021529.987950-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040290837100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Acked-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/s390x/vdso-asmoffset.h | 2 + linux-user/elfload.c | 2 + linux-user/s390x/signal.c | 4 +- linux-user/s390x/Makefile.vdso | 11 +++++ linux-user/s390x/meson.build | 6 +++ linux-user/s390x/vdso.S | 61 ++++++++++++++++++++++++++ linux-user/s390x/vdso.ld | 69 ++++++++++++++++++++++++++++++ linux-user/s390x/vdso.so | Bin 0 -> 3464 bytes 8 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 linux-user/s390x/vdso-asmoffset.h create mode 100644 linux-user/s390x/Makefile.vdso 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/s390x/vdso-asmoffset.h b/linux-user/s390x/vdso-asmo= ffset.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/elfload.c b/linux-user/elfload.c index 4a2d21a1f9..7450f9eab0 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1886,6 +1886,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 +#define VDSO_HEADER "vdso.c.inc" + #endif /* TARGET_S390X */ =20 #ifdef TARGET_RISCV 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" =20 #define __NUM_GPRS 16 #define __NUM_FPRS 16 #define __NUM_ACRS 16 =20 -/* 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/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 =3D $(SRC_PATH)/linux-user/s390x +VPATH +=3D $(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=3Dsha1 -Wl,--hash-style=3Dboth \ + -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 +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr= .sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc =3D 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/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..2a30ff382a --- /dev/null +++ b/linux-user/s390x/vdso.ld @@ -0,0 +1,69 @@ +/* + * Linker script for linux x86-64 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_restart_syscall; + __kernel_rt_sigreturn; + __kernel_sigreturn; + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS= =3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D 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 + .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) } :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..64130f6f335269b03291653d006= 225b365be9cd9 GIT binary patch literal 3464 zcmcguUuaup6hAlrn#R#}B6HHJ6^h8v3s#wtDI{HzWs-HJcB~u1U2JZX*fw`0w>2I9 z>4SqkSsXs>VMq|PDvEm&1Rwf1RK!O?(CHKhzDz`4)-9g%edpXip_vbYU-<6tJHKy{lI$0|t_^w-9%V;CvX_ZVV@~UP z5ysh1P<-w|K6-fSIDGtl`ke<)|Mc0}bJcWb@yj2!fBy7s_8}PJ^{b5Jk0Yw$Io;cT zvAm@bv#$o5>1TjUWL@)+V!Xt77o&O(PPe!{_5F56Dq|HugaG54H=3D!y#f0xtl;=3D^ z{(|Oe9c6~jI}MdzM5-AY|8oAd5niPp<$=3Dq-bPi}udYXw&GFgmg;C+@!7ys^{eeuHj z*T4PgtbX)Xd*k=3D9hda69Q>Wkk@x$ybu&hP9*|3+as_nYLm7yGF<^c5IqMK$gD%EM^dJJ&HRX_=3DUlHe3oHd-=3D zIM1UMJ^v4I(xAP;I6DJId&n5swY$R)f#T6@HFFH}{sl84Bv3LERZ;$NK58 z{sq)6-9i5f>gc{kWqnFM;93k>t zPf{jYi+obAVwW^}{2=3DpE|4KxA?w|60@a(yd##JBHtcojrD!7kfczq<42ikk5{qOhf zLwR_@?>o{q)cHH)^P&ED(&rPwe&_gnsNbFI)9)_$_Mtxep3ldxa1KVn%AK6b9zAjh zOC8^LR=3D#KzX0k`~RxvjN*5T5z$!y6wRwz85pS5PQlcl`n_k`ZI;q{zQa|v~hox4`3 zdw3>(zwsz90(Cq9v$eMDmS044n;L7fYB;V9W@W8WUarrp1=3D=3DE(-7=3DWf#)?@hw`!Vq zo0?g*o2|Oj2nkjNOuJ?+G|S7jRjZ(-NMO2l+m)mAUvLDS<$WUcH>WrB>T|p&K(J6A zLY*8iECCvFZapMYV$hoF3cmya_T!ZA42~~#E(lv_L;l=3D1Jb$XEi2%>>r49tu`x(u=3D zA@PZzo*QQk$Cth#sCp{ztt`c#Fpb|mfA{!rX*tRW8I*VOC$q_bj^j&u1tHXb&|dOD z{?B3jE-i3~KihkKi}DYWds%Kr-5;5sp;iO3^}^sP;K oq#^O?{L#B0m|N2GNEUhVg)ofre@WbfvycCv+~*tYC*b-21AbI{0ssI2 literal 0 HcmV?d00001 --=20 2.34.1 From nobody Tue May 14 16:29:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1696040231; cv=none; d=zohomail.com; s=zohoarc; b=Yc5mK4Na3EW6ZZTDdRajSff0k47QHT07c3cTftsUGvZbVG+QlMLyas+i02FaJsw9MHkHVFy5pFuLQd00w9W6EnsMpTMXkwphDoWPAaRlnkReCEMX/IDW9mBSP3mIk5sSuUFf4Nui1F2r3IgbsajFIO7slSWA2WHNZlW7tUCrQcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696040231; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UahwwM0xSudS8dqnIciSUED/htcAdaM6cKw6bB59fHU=; b=Oj5M8mWDvi9G5ZbO3+OGW4JE8tVdsSBH9MiwBZ2pRShVGSBu/p7TSJkVyDo2SremBfiQlGjp69XsBQp3L9bofrKMhwhiEboX2vuDLPujL9OsqgXgckwbudrQKnPBCJnmr9EyDflL4kbxRmLcCjpuS/gH2qZtbYSKHMM+xzvy9y8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696040231086562.0637432019814; Fri, 29 Sep 2023 19:17:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWS-0000Ju-Ff; Fri, 29 Sep 2023 22:16:00 -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 1qmPWO-0000HE-He for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:57 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPWI-00023e-45 for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:56 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c737d61a00so22244735ad.3 for ; Fri, 29 Sep 2023 19:15:49 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040148; x=1696644948; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UahwwM0xSudS8dqnIciSUED/htcAdaM6cKw6bB59fHU=; b=iA8VgOSdJj8jrFevw+ZS7oA140GrbyxBVO1AlJkW0KYbDJFJ1aLfj2TjedWjyMXa3y a7VBQ6NaH4AvkXWa1XUmgnXEx7vrG9dl5sKgV2Xryz6zBkjldduKTiM5Rmd1rcsXcHJe qk05T8E9FSO/kI4R5GLiRRAw7p0dGtE2s6c5gSfACZuTvZp1+QhKz7qBaRrzIt+BlliF vn2PgeDwP3aLiNuoykJJqb9qWOpWzgAaOcS/1xJe0NnzwRigeSqDpXbRUMQ2lRirssw3 xHhk4fFRSSUC+8Q9gT1Y1NBOw8q/9mU5OCS+nesjoDvcPf00bvdUQtK5IJOB49gR0nIU dD0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040148; x=1696644948; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UahwwM0xSudS8dqnIciSUED/htcAdaM6cKw6bB59fHU=; b=QpuQcBHOeqQoC/SkulkQkSFBh+SbVQ08OWaMxlzyMMq87T91o+DBSraLYhdt3pWgnm /mTOgE/caYOty97MYee2kiqKToZtDrPqSIUYl5HGuKtFEgPgyOiKoaGbtTZM0HeDzS28 0iSWk8IpyjkmmQTszwyXKKc/BmiFtXPoYCN6a0dO76hZ03YXJkBByb3tcUMlFApS31Ic 0nrpnrpcfcDh+EJLlHJ5a/ixbWtzu8/NvMV/KIvO5WNSteWeqyrkMPGffE+Iet1hK1BX h7HREf++uogGY8S4bSEFjbcmDAOgjdNqRxNaQrLl6GU6MgqNkp+GjDwcQTLjPDra3lRt uKKQ== X-Gm-Message-State: AOJu0YwOf6DreWlMN9/5YZK3Tbpu5moBimlXTl7Z0WXtHN2c1FupBltU lwPKrVCEg9iJB4jZqBhpkFGqGI5WbfhCDl6+Y3w= X-Google-Smtp-Source: AGHT+IGpuCZWTFNhRsaXjOBrir8bKCRRNJS3vtkoKkTPq3fGYFRo4WuC7SsL9A6hpFZPbJx1uVmxkg== X-Received: by 2002:a17:90a:fb51:b0:274:a021:9383 with SMTP id iq17-20020a17090afb5100b00274a0219383mr5889963pjb.17.1696040148477; Fri, 29 Sep 2023 19:15:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v6 19/19] build: Add update-linux-vdso makefile rule Date: Fri, 29 Sep 2023 19:15:29 -0700 Message-Id: <20230930021529.987950-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1696040232085100003 Content-Type: text/plain; charset="utf-8" This is not ideal, since it requires all cross-compilers to be present rather than a simple subset. But since it is only run manually, should be good enough for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile b/Makefile index bfc4b2c8e9..676a4a54f4 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,13 @@ include $(SRC_PATH)/tests/vm/Makefile.include print-help-run =3D printf " %-30s - %s\\n" "$1" "$2" print-help =3D @$(call print-help-run,$1,$2) =20 +.PHONY: update-linux-vdso +update-linux-vdso: + @for m in $(SRC_PATH)/linux-user/*/Makefile.vdso; do \ + $(MAKE) $(SUBDIR_MAKEFLAGS) -C $$(dirname $$m) -f Makefile.vdso \ + SRC_PATH=3D$(SRC_PATH) BUILD_DIR=3D$(BUILD_DIR); \ + done + .PHONY: help help: @echo 'Generic targets:' @@ -303,6 +310,9 @@ endif $(call print-help,distclean,Remove all generated files) $(call print-help,dist,Build a distributable tarball) @echo '' + @echo 'Linux-user targets:' + $(call print-help,update-linux-vdso,Build linux-user vdso images) + @echo '' @echo 'Test targets:' $(call print-help,check,Run all tests (check-help for details)) $(call print-help,bench,Run all benchmarks) --=20 2.34.1