From patchwork Fri Aug 11 16:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712603 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482146wrb; Fri, 11 Aug 2023 09:52:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExROIlKq1jiU7EMWcCFEv/TOXn+tFE7m7NDUeLyxQ2RJg+IL6ME+eWgFQ9x187g2mWsAE+ X-Received: by 2002:a05:622a:11c1:b0:40f:d4b8:113e with SMTP id n1-20020a05622a11c100b0040fd4b8113emr3381171qtk.31.1691772732032; Fri, 11 Aug 2023 09:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772732; cv=none; d=google.com; s=arc-20160816; b=r2ZbhsDPTjfYAVMLbYfOgzlWhwho2cRoM5VqOew49EXnKQzZjqQ8K9I1N7jJMJdWeS dJDoEpJ5RelBhEcvwpGl7Coo2FbcRrkyOoDs1KWUE72IF9ftyQnmmMndmnw5U5cQ+Q3D DxaEo6W1w0Bks5qYOPvpkAuBWKrtSAbP52JEJ4r/cvk/hxSUzQ2qXp4GMazCvOWhaOIP Mk0vzHQixia0Yjhi4PlCNhnAJZRcHKrmRzQMjubnNXHnOQ9jZTTnRtDeKeIQ9584IhKu xnNj8EC6q1qDf8gFc5/oYmeqOd5MHv/GM6+m3MDiHB5Ee84uKL+d+wzlo7R+n/81gcMl mKYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KVQEaJs3GbLkjPKeCbXH/uHTPUARwUrZn+9U7CYMhDA=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=Q1C/YL+ElIHPkFHNc2jUYu2Cv0qBKvHswdI5zFmxe8lYcsHD5/XRdtnZRm0UWzITEa 1iBTfedm2bKZ26KJjkvBERU0Miol2iI03IalLIJP48bPEB5BXCp9GZcNc4HQxyVFxv7s wVBmbBKWS18ZjdMEclNjmLXDgo1ZbkRpy1Vh15oPAmziu9iULAajenjpsRxYXO+ETaTU 88nIST/b+MzJm3Seo25YoI26fAWHd/QexVbNJrI7VY69V59+2SiOo3QD2LlpkPZRazBC lNI9QdDgm89o3yqq/nyL8gNqBUZxwDtSkAzoZOqmO3gHbF22VlHAkLQyXkMmGMFH87nV S5EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=coulX4Zk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t12-20020a05622a148c00b0040fd2436deesi2477729qtx.283.2023.08.11.09.52.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=coulX4Zk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLp-0005jM-Ht; Fri, 11 Aug 2023 12:51: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 1qUVLm-0005iW-6R for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:58 -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 1qUVLk-0001LT-EK for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:57 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-26b2beae166so336328a91.0 for ; Fri, 11 Aug 2023 09:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772655; x=1692377455; 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=KVQEaJs3GbLkjPKeCbXH/uHTPUARwUrZn+9U7CYMhDA=; b=coulX4Zk/tPnaJCY66nmv6HKKr2oCY8JBGdd5H0Xb2S2Vtyh1MAG+eDNYB49nMzbcM ZUDbTxiuAnzwtCafEyGpG0afBPYRsifCohFCrWR+VV6eOu4Qj93tBRO7bpr+bcMTpmkY EvEAPlDfJpigNVPnzqhTZp3htK1CVVCjhe/jVHsEUIG+h+e7Q7SEBQmb+F9kqD9B0/Li ccS5iHno/QRDfkgQXsRWMfQtoADhf0Z3hU4ihh0EWNq4uNwo2qkS+7zGHxvKzhdy/p5O QQL342L2g9H1zdhgIzciBZIClx07Spd4I/LSNsuHKyUYgGRfhgFPkrmxoGwcElVpyIiU x84A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772655; x=1692377455; 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=KVQEaJs3GbLkjPKeCbXH/uHTPUARwUrZn+9U7CYMhDA=; b=S2fhTrCg7drguPlQCZCXQELdqE+kXOWFiI8Ko00BBC26WTtAtyemGwqkS0XrU2vJTt N/sGVBQQCxQx62k9qdugxoz1kbtA3wxLAR23LOVTIENyg0HhyhvtAz981h/BKxDS7CaN m2j9urme674PHEBfQvObs7H+dqsl2MRo87B2fd0isv80WjTY0YWg/vBW2GlAKX3E0tjl tuoBssu8M8dy9/5kOXGZNBRhbX5HvNcKNXDcKy31CUP37BVwgL/zI2V390GDuo2Pl2Ea axqA60eVhFQrMfNIHrt6PVecvUk9c2tOPU51HKPApclxubCBR/2rheB4u2XWOhTWZXfK xJHw== X-Gm-Message-State: AOJu0Yz8GCBgkR/XrbeTgzat2cIhd0SP9ZiURURaR5U2Z6HgnBaMdU1B o4Rf5Ey0uSP0WYGf6jWmiNiCPw4fv1X2444oP/4= X-Received: by 2002:a17:90b:144:b0:263:9e9b:5586 with SMTP id em4-20020a17090b014400b002639e9b5586mr1637454pjb.44.1691772654995; Fri, 11 Aug 2023 09:50:54 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 01/15] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Fri, 11 Aug 2023 09:50:38 -0700 Message-Id: <20230811165052.161080-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE. 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 59cbeacf24..311d20f5d1 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 +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 */ }; 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" #define NGROUPS 32 @@ -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 = bprm->buf; + bprm->src.cache_size = retval; + return retval; } @@ -139,6 +145,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, int retval; bprm->fd = fdexec; + bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); bprm->argv = argv; @@ -173,3 +180,86 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, return retval; } + +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + ssize_t ret; + + if (offset + len <= 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 = pread(img->fd, dst, len, offset); + if (ret == 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 = g_malloc(len); + bool ok = imgsrc_read(alloc, offset, len, img, errp); + + if (!ok) { + g_free(alloc); + alloc = 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 = PROT_READ | PROT_WRITE; + abi_long ret; + void *haddr; + + assert(flags == (MAP_PRIVATE | MAP_FIXED)); + + if (src->fd >= 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 = target_mmap(start, len, prot_write, flags | MAP_ANON, -1, 0); + if (ret == -1) { + return ret; + } + + haddr = lock_user(VERIFY_WRITE, start, len, 0); + assert(haddr != NULL); + if (offset + len <= src->cache_size) { + memcpy(haddr, src->cache + offset, len); + } else { + size_t rest = src->cache_size - offset; + memcpy(haddr, src->cache + offset, rest); + memset(haddr + rest, 0, len - rest); + } + unlock_user(haddr, start, len); + + if (prot != prot_write) { + target_mprotect(start, len, prot); + } + + return ret; +} From patchwork Fri Aug 11 16:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712604 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482152wrb; Fri, 11 Aug 2023 09:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESsamJUara1e5K5BLiNkUZ4JA48CctKUZB4Z7wVwPXRAy4m9B7gI0wIsHjra0LYuowNrdK X-Received: by 2002:ac8:7f95:0:b0:40f:f435:1af7 with SMTP id z21-20020ac87f95000000b0040ff4351af7mr3323565qtj.19.1691772733222; Fri, 11 Aug 2023 09:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772733; cv=none; d=google.com; s=arc-20160816; b=GS/8NuwpElMM8kaSRkx5Q47bXnoZvsKfp8cpZrWHbJO1pdG7MwYibG5AX7067ml/lA 0g8eh8Giocj1I7Z32XNzloBSS2WYBSVXlgaa93xMegFkp0rwczoTQGC5fJHYBnKg5zVJ EAq6+y02zK2QVwE8AEaWzlMTY7P6Dpmtr1ESA2ZeMVZTFKvtPzArfGbrsnvcZ1ZMn7VI 2pXy8iOsWHPxcyBOFo3gILcI1rX6YcnEA4AS6HGkkg5eeYfYW1/rLkk/jxACdvxgdQCC VKnCqdYNeVhcIVEhsjiHHoNZbkbFZllhrDxswavW8udk38ElbrOSgC1iMUWekE9bMrn5 iiIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; fh=kNJidqFjxQIJ5KuZrzJozBZzMcjrUTD9AQ28ALCLCZM=; b=bAXcn0XPpdr6DW2xFOEgmUl+9dZa8oMDZgvJIojEfqVcrDQH+v1V1kxvk6pppKAqFf b/kPL6Jtv8rGwCv07Ghr09FmwxYYeno6a628ZbyGhkol5sP1DbjV0q8/27uJ85iyPXK/ V9+5bzpEvUdX+HMGV3l6OaEBbRbd4Am0gNh5iTgVGVcmzVttcWyBV+VopXe1gA9+TWRD pTTYtXqEswBWTqc1Eez4YEyHatr6nznpMuOPec3vLNJObNjBoKF4vPdqG8L/TcjDD859 uPRDa9i+RHZZraGVGtBlx4Qyzj7s6jrB14gaJAcnqqE73t3bPNl19HcrzO8YYunenfbU 8F3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QsKlJln/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n4-20020ac85b44000000b00403e8a6a4cfsi2528114qtw.333.2023.08.11.09.52.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QsKlJln/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLs-0005kC-6v; Fri, 11 Aug 2023 12:51:04 -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 1qUVLn-0005ip-Iu for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:59 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLl-0001Le-Ui for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:59 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bc83a96067so16148305ad.0 for ; Fri, 11 Aug 2023 09:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772656; x=1692377456; 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=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; b=QsKlJln/1tTBPB5wpY0CMcxDjuYE3SYt1z6TF7b2RKj8BpD38A8CIPv+RtJjakYznV bCpG18PRps215iekak1X2REf7FuLKdJLp4LbXd64+dj/cd51f7xAX551cUCSwAGQbyvw KbO+tb1cmY7yM1zGNMXibNm2GysVemE4IKD+FX6g3sE3uznHObcIezIHOZ5dXGidVf1e VOogD2B5l0UM6Vt0GYAGjV0LvqsS23KU9qhWBAmhKX+V0ZPtSFsUfVO3d5o40xx44VMl OhfR0wypaVbsWx1kaqncTzOh7B8gUlzGRZTqZkWwMMqcp/rJJU3I7DbDdp+VxmBLqV/6 JReg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772656; x=1692377456; 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=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; b=OeCoKvx4v/GbwNzr+mYjpDX3TsgkxopAerqVsiVJgmlNS+gdLqb8MSnz1F6RUbM6EN DcgMSR1++uruhgO8QftJV2pONpUVGWBHYQSuUQIYtr7to26khKaPOCybMcB4QQ6XqMZi jC4eR14zUN174uqR34yU+7mLk70frJyPy0EXhxahrFkfZOcq1NBs6FsdNZHtg1QOHKX9 wimRSUU3tHM36yMJQtGddSN8K+yAPhcyBDS22buUkVKXu043SUpSxxFuky9JU8pDaj5m W5UMZ/dDEakJRXc1+PdvhrTKMz/F9LOJXkyHBoRCm5QBsBufyBv9gjDYXeNvaqxRJB00 PdQg== X-Gm-Message-State: AOJu0Yznm02zuCgwbphyntK6X2JZbbogqyMnhKN4elUsIhRX/0rWcGp8 uYIg1ATUP3012JHneLONCi0r5o6AP2IPPPxzUf8= X-Received: by 2002:a17:903:11d0:b0:1bc:844:5831 with SMTP id q16-20020a17090311d000b001bc08445831mr2231945plh.57.1691772655802; Fri, 11 Aug 2023 09:50:55 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 02/15] linux-user: Tidy loader_exec Date: Fri, 11 Aug 2023 09:50:39 -0700 Message-Id: <20230811165052.161080-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Reviewed-by: Philippe Mathieu-Daudé 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, char **argv, char **envp, retval = prepare_binprm(bprm); - if (retval >= 0) { - if (bprm->buf[0] == 0x7f - && bprm->buf[1] == 'E' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'F') { - retval = load_elf_binary(bprm, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] == 'b' - && bprm->buf[1] == 'F' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'T') { - retval = load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >= 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] == 'b' + && bprm->buf[1] == 'F' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'T') { + retval = load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } bool imgsrc_read(void *dst, off_t offset, size_t len, From patchwork Fri Aug 11 16:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712601 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482061wrb; Fri, 11 Aug 2023 09:52:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0eirHih+XV08FYb9u67Z4Ix6B5c3ghRFnOs8r2qEDvyoq1ppYsBAYXISoEVoV0bhTlcQp X-Received: by 2002:a05:622a:1650:b0:40f:e2d1:7b7c with SMTP id y16-20020a05622a165000b0040fe2d17b7cmr3483300qtj.9.1691772723634; Fri, 11 Aug 2023 09:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772723; cv=none; d=google.com; s=arc-20160816; b=ULF5rKUaPsVACBd1MMCPnbareVMlR66pbZMBMMpFZEXgYCAnVyi8e8OfdqLWk1EC5M QH4dHGkuWqsL1KDGtboNHKdcCO9hLyAD3jUfMf/zS1k/ed+H75NAgStfiLxIdazlZCgS STzdjeJr88L0GXMdQY1yHCj3IOZNl8QNYn+jKafPPizoJFakd4Jk4TdpvL3y02UngcUA GEuJK8ggSL+9u89cmaUHy3N2aF4ma45maNGW63jWU2oeWIgVkYIsNGNKa14WmOAR7Y4A RFf2CozMUPqKm2SXsa4PU8uVVHsl5mzxFAVhqjuQJW7mEtVnV0dlhc/QDsh3+PUw9j7T Zlow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hnWfSxPGmBDugDNsx/9arIWCUJcfcyXd41yVekLb5Tk=; fh=kNJidqFjxQIJ5KuZrzJozBZzMcjrUTD9AQ28ALCLCZM=; b=rXM71Rmhg9VRVRnp3rxRn82Kt86D6x5Qp9R+KVBny8xhMTFla/9WJ0OFJE+tDRbIkh yhLAvHs2O72koNgd87Wqfah3K06RaUaqRKdDEATI48sffYy9vCP73Tzgf3Su5TnCT8hc ILbpf8yGFX1xN4Acc+nn57H1HijVAyGs07gleUao4W/EOT5KAbrWQwJKo6jEn+28Rxof /6EXyboR33cT3WY3Fi3/d/Pnzyn2gRn4rW8e1+zl6dacUvWu6qOQl1bnlQr7WdebKHEk jlOd52TdlBPyw3LxAQ5THlC0T+Kru7UBG1dgd/Sf5bU1gWPGlbyCQj0+TpdPYQFnwZkV 4M/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yYlUuYX5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n6-20020ac85a06000000b00406a59248adsi2446334qta.790.2023.08.11.09.52.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yYlUuYX5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLs-0005k7-6l; Fri, 11 Aug 2023 12:51:04 -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 1qUVLo-0005j1-LC for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:00 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLl-0001Lg-Uo for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:00 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6bcade59b24so2038217a34.0 for ; Fri, 11 Aug 2023 09:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772657; x=1692377457; 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=hnWfSxPGmBDugDNsx/9arIWCUJcfcyXd41yVekLb5Tk=; b=yYlUuYX5gu3gIL2BRMy7+/gMG9zVkJcO9M8aInowUWTth07HGlKCak3saAXJsJbafH vkx0ZgglRCk6sy9Gmp9t0lkL2PiM3Iz9TvJZsSlBb5qY+nzBueZMV6irCx0KS1OHuUfG mZzYlS2rqV9OtH/sd+U1pNkanBMtIK6W5cCeaz8cl/SvQtpt50a5ooLQKUcF2pkhXf8p B7rPALCJYLy5hEF9hud1R2jkrx1njHrG6A+PYbM5aOK8DSP9xpjpbwIKgtcF7taMOfaD PxR3LUstneohFTeF8owRYA7S3EaaZM0m3yIKPBYuaTmk0PfjSTkUAwJtmKs6kfayTav7 6ZpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772657; x=1692377457; 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=hnWfSxPGmBDugDNsx/9arIWCUJcfcyXd41yVekLb5Tk=; b=WQOy/2nBoB6TVccjtcVBHR6A4ONGBmn7EOFORtnaqqugdmOCQswi4pdcvV5bDRT+lm onUjlhRm6w0j2HAuwbIdXvSnOzrqvPmqedX3yR84hqH2oRKuelCuU2W21SZMVwG912Jz ZwEz8LaUIkESQ8sQsxlzffoNvTeaJ/E1JJOTd0ZBYjtRerMNTodowtXn+zv3PJ4g7csh BhxRx/2BbBncGU+dvGKFHZ1n0KK4k8nHvsPBomMLDTZgdXUvJpNp+5Sm8z3jWqJ1Q4wD 5YszuFeIDJRxHR8a9ecL6WLcydXla67lhDvGbA8Q9Q9nHwGKN6vviHiKGUjvZ06ij4rX BgNw== X-Gm-Message-State: AOJu0YzvCCMqAsb0x4bayQ7hwVPWnJAq2JhUlUuteYNiMG2OU3eXtnFW NOaKujYIObskzGE7TZ6vk7Hz1X+lIRfqsjHeW4k= X-Received: by 2002:a9d:6d93:0:b0:6bc:de9b:a3e6 with SMTP id x19-20020a9d6d93000000b006bcde9ba3e6mr2475520otp.24.1691772656794; Fri, 11 Aug 2023 09:50:56 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 03/15] linux-user: Do not clobber bprm_buf swapping ehdr Date: Fri, 11 Aug 2023 09:50:40 -0700 Message-Id: <20230811165052.161080-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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: Philippe Mathieu-Daudé 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 ac03beb01b..11bbf4e99b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3019,16 +3019,17 @@ static bool parse_elf_properties(int image_fd, On return: INFO values will be filled in, as necessary or available. */ 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 = (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval, prot_exec; Error *err = NULL; /* 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; @@ -3343,6 +3344,7 @@ static void load_elf_image(const char *image_name, int 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 = NULL; @@ -3364,7 +3366,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); } - load_elf_image(filename, fd, info, NULL, bprm_buf); + load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); } static int symfind(const void *s0, const void *s1) @@ -3557,8 +3559,14 @@ uint32_t get_elf_eflags(int fd) 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 = NULL; char *scratch; @@ -3570,12 +3578,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; 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_tables. - If we do nothing, we'll have overwritten this when we re-use bprm->buf - when we load the interpreter. */ - elf_ex = *(struct elfhdr *)bprm->buf; + &ehdr, &elf_interpreter, bprm->buf); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ @@ -3662,7 +3665,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex, + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, (elf_interpreter ? &interp_info : NULL)); info->start_stack = bprm->p; From patchwork Fri Aug 11 16:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712615 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482511wrb; Fri, 11 Aug 2023 09:53:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYxIsKWSCJBJNPdZW4rfS5WJgs2W6sYR6N8J8iP5uPTsOnXr+BFWoEt+xm/cPO/ZwSl5ip X-Received: by 2002:ae9:e11a:0:b0:76c:b311:49c7 with SMTP id g26-20020ae9e11a000000b0076cb31149c7mr2392899qkm.43.1691772781543; Fri, 11 Aug 2023 09:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772781; cv=none; d=google.com; s=arc-20160816; b=fZEqyc9MdcGVKqPbyHs4veaZUrzh1afxmFDCP5o97yNlJen7/hnmWbINR3bJy3uT5a z6oOHKNyWBhpD2Drgth6ssKRFXIwEMwsOIVNigIxdQ2zkUT4WRgxhJbf5HSf7e8Ny65H 0xTsFlH+57EedlxoobwfiN2as1496qBAeLOJpKFXcA6HJbC1THZk2fGphHE+WQiOEzIG 2cfpLdvyHNHRM3YqFTNv1K9H8x8jZdjuldCaqudmBS5YpsU8srqTBZ1aeJziL+hR+WM2 mhA/H574dhpQf4yMo1epRO9ALS3ldpPgha8wMESfoawrBG3DaCtfnf62THEBIQT6w2zH yEsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dcDp54///Kf+CDj6N0TXUWsVxMt18CBlFITqwULqOtE=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=yUzmys3wwhT+7595LOKtoPDOu28IkADbzwhDitGf1+Y1A7rvOSEiREU7IgJwzfHx0H o28l68wkhRivzv1Tz3xSJWhtEJabTnuEQs+2nIMiz4Zh1fYDDiRR7+5cTlUzNqZIuWP9 9+0gWoUh/WUTZkwpFCdVoxfby5HjU4UWEXSJ0JAVzUApdH4Ze9uz1KGKMbmqONGTkaPg 7wD3Wt+MuSeLHzevUj4TGWmlzX5XHsljL4ur8K2jjk3oruX52ZwIfzcIvfCeige2zFmX X8CzD94j9EqSSEn5jFc7bsSqF5llV7tz8q6QGOpYghTILydKwHSw/MSeui8Eh+cx+YKW y5+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rbzlk7ug; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ea20-20020a05620a489400b00767d63de20fsi2461742qkb.193.2023.08.11.09.53.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:53:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rbzlk7ug; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLv-0005lr-9K; Fri, 11 Aug 2023 12:51:07 -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 1qUVLr-0005k1-4O for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:03 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLp-0001M0-3Y for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:02 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5657a28f920so426859a12.3 for ; Fri, 11 Aug 2023 09:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772658; x=1692377458; 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=dcDp54///Kf+CDj6N0TXUWsVxMt18CBlFITqwULqOtE=; b=Rbzlk7ugFLwlDVbPlSfxPMo5jzNk4pXE1Kpe2B0fgCxc85lywyH1nZHlTi8jXWxK82 qqPk1uifQdldSiEdru3Ed8dtIG3QdlH5LRdThPqstqE57qAh4avN6MAoGMSx5gdcWn+w bMl7SwbIk/qSZhcIhYETC0ZINh8esFthASf3Xo2HRdB2HaP165l2YhuH3FL7KrM7yEsO loFY5NaRuMn6K2ioD7XSv0Q1+OupfH+4RJFkBoQRyODDgUVMKPwTfW2sT0NujY+vzNgV wA0KWZ0sDjVaZrNUJ1hz/6XHEEkkps1B7TjRYlbFkQJVsT3/T522MK1/fkUemiwXsfzT hV7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772658; x=1692377458; 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=dcDp54///Kf+CDj6N0TXUWsVxMt18CBlFITqwULqOtE=; b=KSnEP9OU/6fDLG6qDUZV4UkYcD10VWDvLE7+ueli5RJIs2dPXSSvOQy3IiEOh4DlT3 uIcaqhBB+vvkP31tUOjYzFzV70IfV5V2Yf8s9jd5Kxz3nU6XTo0cQbqV6aH8hPPtgqkg D8Cvp5Xx4Qmk1XcWTvcpg0R72kzRJhSEWUU5YvtAES7lzdcQwY7L58znHSh1dV2n4nXz 8zil4m3cu1jSHoZRemfB/nDhGYsUpQsH8Tn3fjSNyy5ZNgVjVqnLYPMH1vOFPYAdTB3B iJ4i0Np1bS6zW7HIrRzQxvpYgrO2sWClv45qx+n0sH/ze1RLEDK/YGx0ppoYCdcIJn1H ZfcA== X-Gm-Message-State: AOJu0YwzRlNZh+DH30/31ici9ijfyNeLkVMO7K+W2fHDre/CYrJfSiWL xhm/B4xrcrwrTBO5q3XQk4zro3ZMva5p3VGzbRc= X-Received: by 2002:a17:90a:cb06:b0:26b:2538:d717 with SMTP id z6-20020a17090acb0600b0026b2538d717mr1727966pjt.25.1691772657684; Fri, 11 Aug 2023 09:50:57 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 04/15] linux-user: Use ImageSource in load_elf_image Date: Fri, 11 Aug 2023 09:50:41 -0700 Message-Id: <20230811165052.161080-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely. Signed-off-by: Richard Henderson --- 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 11bbf4e99b..f3511ae766 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2922,10 +2922,9 @@ static bool parse_elf_property(const uint32_t *data, int *off, int datasz, } /* 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 { @@ -2953,14 +2952,8 @@ static bool parse_elf_properties(int image_fd, return false; } - if (phdr->p_offset + n <= BPRM_BUF_SIZE) { - memcpy(¬e, bprm_buf + phdr->p_offset, n); - } else { - ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); - if (len != n) { - error_setg_errno(errp, errno, "Error reading file header"); - return false; - } + if (!imgsrc_read(¬e, phdr->p_offset, n, src, errp)) { + return false; } /* @@ -3006,30 +2999,34 @@ static bool parse_elf_properties(int image_fd, } } -/* 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. + */ - 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 = NULL; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval, prot_exec; + int i, prot_exec; Error *err = NULL; - /* 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; @@ -3040,15 +3037,11 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - i = ehdr->e_phnum * sizeof(struct elf_phdr); - if (ehdr->e_phoff + i <= BPRM_BUF_SIZE) { - phdr = (struct elf_phdr *)(bprm_buf + ehdr->e_phoff); - } else { - phdr = (struct elf_phdr *) alloca(i); - retval = pread(image_fd, phdr, i, ehdr->e_phoff); - if (retval != i) { - goto exit_read; - } + phdr = imgsrc_read_alloc(ehdr->e_phoff, + ehdr->e_phnum * sizeof(struct elf_phdr), + src, &err); + if (phdr == NULL) { + goto exit_errmsg; } bswap_phdr(phdr, ehdr->e_phnum); @@ -3085,17 +3078,10 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - interp_name = g_malloc(eppnt->p_filesz); - - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval = pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval != eppnt->p_filesz) { - goto exit_read; - } + interp_name = imgsrc_read_alloc(eppnt->p_offset, eppnt->p_filesz, + src, &err); + if (interp_name == NULL) { + goto exit_errmsg; } if (interp_name[eppnt->p_filesz - 1] != 0) { error_setg(&err, "Invalid PT_INTERP entry"); @@ -3103,7 +3089,7 @@ static void load_elf_image(const char *image_name, int image_fd, } *pinterp_name = g_steal_pointer(&interp_name); } else if (eppnt->p_type == PT_GNU_PROPERTY) { - if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { + if (!parse_elf_properties(src, info, eppnt, &err)) { goto exit_errmsg; } } else if (eppnt->p_type == PT_GNU_STACK) { @@ -3256,9 +3242,9 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + error = 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 == -1) { goto exit_mmap; } @@ -3290,20 +3276,11 @@ static void load_elf_image(const char *image_name, int image_fd, #ifdef TARGET_MIPS } else if (eppnt->p_type == 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 <= BPRM_BUF_SIZE) { - memcpy(&abiflags, bprm_buf + eppnt->p_offset, - sizeof(Mips_elf_abiflags_v0)); - } else { - retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), - eppnt->p_offset); - if (retval != sizeof(Mips_elf_abiflags_v0)) { - goto exit_read; - } - } bswap_mips_abiflags(&abiflags); info->fp_abi = abiflags.fp_abi; #endif @@ -3316,23 +3293,16 @@ static void load_elf_image(const char *image_name, int image_fd, } if (qemu_log_enabled()) { - load_symbols(ehdr, image_fd, load_bias); + load_symbols(ehdr, src->fd, load_bias); } - debuginfo_report_elf(image_name, image_fd, load_bias); + debuginfo_report_elf(image_name, src->fd, load_bias); mmap_unlock(); - close(image_fd); + close(src->fd); return; - exit_read: - if (retval >= 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; @@ -3345,6 +3315,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { struct elfhdr ehdr; + ImageSource src; int fd, retval; Error *err = NULL; @@ -3362,11 +3333,11 @@ static void load_elf_interp(const char *filename, struct image_info *info, exit(-1); } - if (retval < BPRM_BUF_SIZE) { - memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); - } + src.fd = fd; + src.cache = bprm_buf; + src.cache_size = retval; - load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); + load_elf_image(filename, &src, info, &ehdr, NULL); } static int symfind(const void *s0, const void *s1) @@ -3577,8 +3548,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; - load_elf_image(bprm->filename, bprm->fd, info, - &ehdr, &elf_interpreter, bprm->buf); + load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpreter); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ From patchwork Fri Aug 11 16:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712608 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482360wrb; Fri, 11 Aug 2023 09:52:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmUTN6hCevM5ZvJalyK+4604zjnE9Ql8qp4rt9KpYAwGrngGoQz+n0EDS71Qsi72GIL8d2 X-Received: by 2002:a0c:b356:0:b0:635:e0dd:db4b with SMTP id a22-20020a0cb356000000b00635e0dddb4bmr2224353qvf.37.1691772761511; Fri, 11 Aug 2023 09:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772761; cv=none; d=google.com; s=arc-20160816; b=BH0ZpqBxoTTXj/ln/LIWeYu0z5NurWYocEkdQRUj9tv6ZOo1x6oPShx785NFypDW6J 7+ELX6VWMnUsfSJGIglu4anROyvsVm2UsSaKCMNAvDvwekWh6lBaaISxgmBNIaxZIIHV dp8hytoHck1cobg9kyBAIfiDW4+37Riuz0k1vHxPFe59b2OAeVNVL+xr3CS6o+l3kiV2 hULOrbtKZbNmQQIbjQfOOJnkzcGR4a93pVI8LV/riQ0DRQZ5bE7bELZOy/uhdtTRhncU w9pVJzAzFjiolxELEr8N3dj+XbWt+UhhD+RX8YNGnNMsvlKLE9gswuEE61Ou1COYt7/9 O3jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ePVxotW82jMDrWJ+ESk2twixLo2Priek8MjmEOc4z70=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=VunAR70VeQtfU2yIbdm5d/ikzKI7gl2yPgBVkC1FV3wV0j4kt1/y8skza5K7VyTb2m +jB3PqviEc0vHbfiadcH1U/Cu0dJ3+eTAhx3aM1IsitZukRveZKAfKtcmCwcuGuOVHeU Cig8UQOSlgCKNMzCByODUBPQTxdUiNwQ7VxmRspBrMVcpXt9xUYN0hLfoCIgjPB4ehu1 kGu1XNJl51sMxuOlr/VxHcOK4bE4bcqTFKcyuUuHYGryWYOg8V7meY94kbLh3vnQWEom hkS7g+wkMnOQRjqL7oh4FrZNMSeO/nOhxoF92leurRHryn3aWJSuU/UqPnFszJrcDnXW EhNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="S/5bRopb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y19-20020a0cd993000000b0063cf4ca0934si2405852qvj.612.2023.08.11.09.52.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="S/5bRopb"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLt-0005lA-JB; Fri, 11 Aug 2023 12:51:05 -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 1qUVLq-0005jc-2z for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:02 -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 1qUVLn-0001M7-SS for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:01 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-26b1adbd655so803821a91.1 for ; Fri, 11 Aug 2023 09:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772658; x=1692377458; 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=ePVxotW82jMDrWJ+ESk2twixLo2Priek8MjmEOc4z70=; b=S/5bRopbca9klFqAItm/gifsMChV/8vThrgzVyOEaRiOqCHzAN0tkEkPghqOb0XKwQ wX+G/GPV3mssho23nIN3UYP4cpIddOiJGiJp3UJd1mdZECWwSzXIv87+CebmSSuIs81O wn2H10JSvqYmHdJmSbUmFY9qMr137O+JLoG/3C+uSTKt6hTYoQI63cxI9coxufO7Up34 MQWoN4INO/gRBeq/AARHxUPDyvMzo5+u9+sIF8Nhvm33Vy62VXXXcu5UMhrUsrTiivDv A42fr6rHNfJKmsVhD3RjZlWCDwCMS2krSlg6clcu3dSiQ1eZURVfaC9rITH9nZ7wq/Cc Zw0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772658; x=1692377458; 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=ePVxotW82jMDrWJ+ESk2twixLo2Priek8MjmEOc4z70=; b=DmZYRbPpnQb8M6ltCqszV8zAHICB1edjmDhRn+IoA+uhTOezRQI/F6RQU1Nm/OAJw/ MAkAdBkkh9w6c41tl537+JY1TJXbX+4z+RL32H1LclmMwJaJxWuJxi+lHns3ANk9xJJq YTprzR5xDqxhzSj7sTjEIRMTUbxaGb9HAotsSsb4Uv5Idbgu9SE6mvo/2mdOVem5Z5YD yMMzoL2gIP27f3zL8W/HJlLV2IhoYkJRUMLMDtAOPX3i2lwE8AVJbqHYPnJlnB7N/O7A YRBFlZkIglCtDjmQyHyDFdgkYfBetpt38V5miISjX5IdPJ6B1upcLFROa0gGa957JB/6 Rm+g== X-Gm-Message-State: AOJu0YyA0pTqvVIrLlpuitj2Iq50+HvUV2bSIyhYwvVRaSHoMMpMmCiv RVkopj/mFXo2ZtQg/DGCLTdqNNSW2Gmn8DbpoZQ= X-Received: by 2002:a17:90b:3503:b0:268:105b:ca1c with SMTP id ls3-20020a17090b350300b00268105bca1cmr1750761pjb.32.1691772658441; Fri, 11 Aug 2023 09:50:58 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 05/15] linux-user: Use ImageSource in load_symbols Date: Fri, 11 Aug 2023 09:50:42 -0700 Message-Id: <20230811165052.161080-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better. 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 f3511ae766..19d3cac039 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2048,7 +2048,8 @@ static inline void bswap_mips_abiflags(Mips_elf_abiflags_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); /* Verify the portions of EHDR within E_IDENT for the target. This can be performed before bswapping the entire header. */ @@ -3293,7 +3294,7 @@ static void load_elf_image(const char *image_name, const ImageSource *src, } if (qemu_log_enabled()) { - load_symbols(ehdr, src->fd, load_bias); + load_symbols(ehdr, src, load_bias); } debuginfo_report_elf(image_name, src->fd, load_bias); @@ -3384,19 +3385,20 @@ static int symcmp(const void *s0, const void *s1) } /* 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 = 0, str_idx = 0; - uint64_t segsz; - struct elf_shdr *shdr; + g_autofree struct elf_shdr *shdr = NULL; char *strings = NULL; - struct syminfo *s = NULL; - struct elf_sym *new_syms, *syms = NULL; + struct elf_sym *syms = NULL; + struct elf_sym *new_syms; + uint64_t segsz; shnum = hdr->e_shnum; - i = shnum * sizeof(struct elf_shdr); - shdr = (struct elf_shdr *)alloca(i); - if (pread(fd, shdr, i, hdr->e_shoff) != i) { + shdr = imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shdr), + src, NULL); + if (shdr == NULL) { return; } @@ -3414,31 +3416,33 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) found: /* Now know where the strtab and symtab are. Snarf them. */ - s = g_try_new(struct syminfo, 1); - if (!s) { - goto give_up; - } segsz = shdr[str_idx].sh_size; - s->disas_strtab = strings = g_try_malloc(segsz); - if (!strings || - pread(fd, strings, segsz, shdr[str_idx].sh_offset) != segsz) { + strings = g_try_malloc(segsz); + if (!strings) { + goto give_up; + } + if (!imgsrc_read(strings, shdr[str_idx].sh_offset, segsz, src, NULL)) { goto give_up; } segsz = shdr[sym_idx].sh_size; - syms = g_try_malloc(segsz); - if (!syms || pread(fd, syms, segsz, shdr[sym_idx].sh_offset) != segsz) { - 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 = segsz / sizeof(struct elf_sym); + syms = 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 = 0; i < nsyms; ) { bswap_sym(syms + i); /* Throw away entries which we do not need. */ @@ -3463,10 +3467,12 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) goto give_up; } - /* 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 = g_try_renew(struct elf_sym, syms, nsyms); if (new_syms == NULL) { goto give_up; @@ -3475,20 +3481,23 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) qsort(syms, nsyms, sizeof(*syms), symcmp); - s->disas_num_syms = nsyms; -#if ELF_CLASS == ELFCLASS32 - s->disas_symtab.elf32 = syms; -#else - s->disas_symtab.elf64 = syms; -#endif - s->lookup_symbol = lookup_symbolxx; - s->next = syminfos; - syminfos = s; + { + struct syminfo *s = g_new(struct syminfo, 1); + s->disas_strtab = strings; + s->disas_num_syms = nsyms; +#if ELF_CLASS == ELFCLASS32 + s->disas_symtab.elf32 = syms; +#else + s->disas_symtab.elf64 = syms; +#endif + s->lookup_symbol = lookup_symbolxx; + s->next = syminfos; + syminfos = s; + } return; -give_up: - g_free(s); + give_up: g_free(strings); g_free(syms); } From patchwork Fri Aug 11 16:50:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712614 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482483wrb; Fri, 11 Aug 2023 09:52:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUINf35zPBNgEGnu89my+afHhFpgq9fATV0Mq4F8j5pF9QrJ5dRdAtRs8OeEsYa0wJcGXW X-Received: by 2002:a0c:da8b:0:b0:63d:203:eb3b with SMTP id z11-20020a0cda8b000000b0063d0203eb3bmr2540201qvj.36.1691772777840; Fri, 11 Aug 2023 09:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772777; cv=none; d=google.com; s=arc-20160816; b=W0VWJF6i1dvj4b+oSkymYvwKxj+ZSe40aX8Q0ZR+7qZA+JGKhN44y0ngEBkKqsMQFU ZQzc1Ro5ERYQhiJmmnlDH+njGaBdxbm9QQW+NByuaeEEFWaAEWcVq4xz9xtCxSwNs0Mv PPUW7geVcU5Gra65O7jKZE9ZRspi8OI/OYCgy41mbn6x2k/PtKhRp6+nwk8dmpRepVcO rdN8va2DBGqIjT3uFph1aBazNgjwmH50qne5pIQPtGJEIxrsf0iNLTgaLQIfb3ObzvTf sIlJVXsAOs75MAkW/A+7puZbKpdQgLNDRtsi1GbYSVKJ1L2/THuUyRAARwHcO/72c9Q/ hetA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RtG96b3jmli1q7lVtewuvoGgDoJMS7AqHQZel0hsDHw=; fh=kNJidqFjxQIJ5KuZrzJozBZzMcjrUTD9AQ28ALCLCZM=; b=Et40wvGviNTDxoaLx+CWkqUsg0Tc3dGDIc7tR9PwE2dCeBOrSraaNtuVDmEIykmufZ nPG/hiieqMZk5P0CMtF6RbrZ/xmboiC/KGoG+0mhCtbCZW2XQaLSlzb24pQGM1dtVYI6 r521TJRPdpw21BpKn6iAX68uw6ZyExgErfM+rtCJpqJfiTBT339GqmIy15Mo9UijhK0c 8pI5aD39LTTyAwR96uJ4MZkkz49Gr8WqMgFmZ4SRYPHRe9thAsMmOSKddNuaG0ug/0lq jVdc6fv92vKNEwP2dBUvdiAyOe7ZGSabpJLnABGnaXoKb537T3iFk48m0Kd4zqVVbzmR M94A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UiXW5TU+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g5-20020a0cdf05000000b00642b9b87526si714290qvl.558.2023.08.11.09.52.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UiXW5TU+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLu-0005ll-PM; Fri, 11 Aug 2023 12:51:07 -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 1qUVLq-0005jd-9C for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:02 -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 1qUVLo-0001MM-Jp for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:02 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-563f8e8a53dso1423477a12.3 for ; Fri, 11 Aug 2023 09:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772659; x=1692377459; 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=RtG96b3jmli1q7lVtewuvoGgDoJMS7AqHQZel0hsDHw=; b=UiXW5TU+wILTYLNL38oY7ZT/faQ7p/gDcFPljcXnk6DSGenvZNoESlruX7ncDUIMce 8Iji+wBNTXPbiOoyBDIXHILZaML2e0D6FXq42ACW5bKdCt1vt9Sbb4CdEVjbNLkYgiWc Oe9gNO8gLRhV+Mtzw7HZiK2FsR++V2LHzCsq/XKL4Zw9kwsnTV6PlJLxQjBZibgCP8qw miT7dxQVtWNRcwJrD6QA5qqkxGgoJ4gmRdV1pQT09XzYVoyX4HowicRLnL4SZdUMczHu QqmEseRP5+P/85btDUAUpWWF3ATHeLecqm1oVnQznzldpS7NdVCqbVqTeM3OSZ3xreO5 zRsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772659; x=1692377459; 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=RtG96b3jmli1q7lVtewuvoGgDoJMS7AqHQZel0hsDHw=; b=E4q48YgXaGVUtrrZFC9DoiEUOSjEaZ5t81YSCvUiGPLoztm//QmCUyQHQ2bt6JijL+ Z5Km7eyZ2U7dPbiTn+X8h6pq6ZHHnwDJTZaGBtebHq4j3m31U35pRT59jNA9LusRIZpc hsnG/qttUtM3iElhS+bEEipF+GvyMPhIHQCPyfFkOtByEGQAhKFUGJV9/2fTKpeX3D+y jriJiJJxBHpcr0RAeeWEpvFuAa1nciQjsCQmgmtOM9iQ6JKIeLyQ1jgjiKbxwnkl/JqF GXPAFdSrvYCeOwQY1RsmKyzJtKwZPmqxVoTvYrnh3t48/cnfGZhKKCbjCGMp6J4I9/1P d4mg== X-Gm-Message-State: AOJu0Yw6c8c/nD5TX2xfqAFZZUpTYKMekzY0GVts0mSxne0PHO0e3T2y Gl/rNXxlzQdMiXSsI/vJIX+j1VFTbAiRikWN60w= X-Received: by 2002:a17:90a:f3c7:b0:267:e011:3e9a with SMTP id ha7-20020a17090af3c700b00267e0113e9amr1597673pjb.3.1691772659260; Fri, 11 Aug 2023 09:50:59 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 06/15] linux-user: Replace bprm->fd with bprm->src.fd Date: Fri, 11 Aug 2023 09:50:43 -0700 Message-Id: <20230811165052.161080-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org There are only a couple of uses of bprm->fd remaining. Migrate to the other field. Reviewed-by: Philippe Mathieu-Daudé 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 311d20f5d1..5b4cdddd50 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 8f5e9f489b..15e3ec5f6b 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"); textpos = target_mmap(0, text_len, PROT_READ|PROT_EXEC, - MAP_PRIVATE, bprm->fd, 0); + MAP_PRIVATE, bprm->src.fd, 0); if (textpos == -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 = target_pread(bprm->fd, datapos, + result = 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 = target_pread(bprm->fd, textpos, + result = target_pread(bprm->src.fd, textpos, text_len, 0); if (result >= 0) { - result = target_pread(bprm->fd, datapos, + result = 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; - if (fstat(bprm->fd, &st) < 0) { + if (fstat(bprm->src.fd, &st) < 0) { return -errno; } @@ -69,7 +69,7 @@ static int prepare_binprm(struct linux_binprm *bprm) bprm->e_gid = st.st_gid; } - retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE); + retval = 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; - bprm->fd = fdexec; bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); From patchwork Fri Aug 11 16:50:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712613 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482421wrb; Fri, 11 Aug 2023 09:52:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3X5BuohANRQxSl7w5NvJWNXA0WrGzdSODekUSWAj2QXh+KOeCgf0SXNVuc/INhljBndDm X-Received: by 2002:a05:620a:28c9:b0:76c:ef70:b7f7 with SMTP id l9-20020a05620a28c900b0076cef70b7f7mr3110098qkp.30.1691772770076; Fri, 11 Aug 2023 09:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772770; cv=none; d=google.com; s=arc-20160816; b=0uUqc9ZE9OrmgMB9A3Lzrnv1zmxdcC0MWnDMBFxY+nVKGiYg7ujwITyjEtX3qAbinc lv4DxJSLMzjz51+9sTimwnQiteEYyH+6nkNHQcobd2iL15TZa0+nzgL5ZXATVC+hQTGq PkWIu2gXRPD0GNjq2IjIP+Ena8MKveDZG3Ox3+SlnWDIcfe4vW+9wQduKmOWqRPam+Np DZ3MDlALMG/0fuQP0YmRfyY2zpHWopRiKJoAPyocbF8bci78/cglCoXJBQWxkm6NN88u rvf0I0ebBeqjGqYF4nij/4573kiT1b0QyUz3sv6JUfZeZaHVn//LQmFDmKh52Jg0JJX+ b3Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lt3tKhxSjXbEIE1KSaUKeQERHy91vOj1K4+DvKn2CTA=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=nfzszkgHVmypMrHhPh08VhnEfzdty64uYOyVyuY9itbVBDcwdrwg9xb1yegetwWXUu vhHuT6v+L+SHn2bwlxfKll+W5CWX3jNXogdwora/9KjR/vc5hJ1S3PZWFeF78b+Nbk+K VsNR2hw74G0hqbyMrnZg3CUQdYrd3/y0cHfERX+bzVPjzz63FFc5/wSbdpAYxvOcPS5U KzO3ljrQ6rSOTG24C5Z/bdKRHJ+YyG3f1jA+LThu7CZNZ1+l1p7PmzU1sm4LV3UN2ca0 UwdW9NxdI/+ZICj/YWlWSQ2vYqCSY3kAaZX/+gWHWtXjEVn7eRfejE7mzni7RTaIEmsu 7O6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gRB/ctro"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d66-20020a37b445000000b00768147a6737si2334343qkf.277.2023.08.11.09.52.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gRB/ctro"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLu-0005lp-Pw; Fri, 11 Aug 2023 12:51:07 -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 1qUVLr-0005kD-OO for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:04 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLp-0001MZ-Un for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:03 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-563dfffea87so1667661a12.2 for ; Fri, 11 Aug 2023 09:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772660; x=1692377460; 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=Lt3tKhxSjXbEIE1KSaUKeQERHy91vOj1K4+DvKn2CTA=; b=gRB/ctrocUMXEDcuQbB+os/j0Rhwp7uajBRR+31qIs3VUfKaQ7kOOhHnaYfh61osN2 UOJnSM3bWxpfbOVwDQWbM7B1Ci2Hn1Vh3Quiauefp9NIddDyVomk35/xv43uzxHaRDsR 7njqtY7WEMBL3xrpiMa9KJ4XDUUlpobWKDfevGKZunajH9zSzRUd+tFyTXy9Vh7ojao5 LB9WGDGbHIbVVpNpQONIH1QECXC1rVBjRV8fbsdcJHbyQJV+ON94qWlrEPdY6pFnBFBU XMSFTPh7yI3EyilMtzSC5UOpNogZ/IQcEoFQoqvmWPM8lseAe1DGAPH6k2hOR7RamzNB jo3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772660; x=1692377460; 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=Lt3tKhxSjXbEIE1KSaUKeQERHy91vOj1K4+DvKn2CTA=; b=gLtTtjex7j8FqGTSQKDRyrkh/lc49IwOA4IeNGfwYcuRVlT2dhq4+N232+rd8Gyeaf gciXLw5Q1OsEZXNmgxTj4TP6de1I2BHy2rjlfB/bSDgwrphY1UQBtfVgT+OUnlTosQY+ gM6ON0CPVuwE4bB8b6GG+6ICk1S4PzrLAFl3NtJ88muBcyT2VVIFb4X5D9RRf6fAOAPn jCTgu24I0vcE+dihaygTlG2bpZ8bVCm5xH5ctD4IaKGG6WrkgGG5V+DACvyiEBqbKd+u Nc0j/XoPcWeS2s2OvxY1k35Vhozv7X/HYqxsA6hQoE0AobFvMiOr3397nBfcKaggxJ5t mxEw== X-Gm-Message-State: AOJu0YyVimbjjZ/MHAdKV7DsRuLThpIieGTwyWNU5aMqB23r1eo//Vuw se83S3cMGR8rLoncaFFwhZXjXjesm8pmWlg8Lnk= X-Received: by 2002:a17:90a:ba84:b0:25f:20f:2f7d with SMTP id t4-20020a17090aba8400b0025f020f2f7dmr2027762pjr.2.1691772660240; Fri, 11 Aug 2023 09:51:00 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 07/15] linux-user: Load vdso image if available Date: Fri, 11 Aug 2023 09:50:44 -0700 Message-Id: <20230811165052.161080-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 19d3cac039..5025611886 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -33,6 +33,19 @@ #undef ELF_ARCH #endif +#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 /* from personality.h */ @@ -2291,7 +2304,8 @@ static abi_ulong loader_build_fdpic_loadmap(struct image_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; @@ -2379,10 +2393,15 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS + 1) * 2; - if (k_base_platform) + if (k_base_platform) { size += 2; - if (k_platform) + } + if (k_platform) { size += 2; + } + if (vdso_info) { + size += 2; + } #ifdef DLINFO_ARCH_ITEMS size += DLINFO_ARCH_ITEMS * 2; #endif @@ -2464,6 +2483,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 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 @@ -3341,6 +3363,49 @@ static void load_elf_interp(const char *filename, struct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } +#ifndef vdso_image_info +#define vdso_image_info() NULL +#endif + +static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso) +{ + ImageSource src; + struct elfhdr ehdr; + abi_ulong load_bias, load_addr; + + src.fd = -1; + src.cache = vdso->image; + src.cache_size = vdso->image_size; + + load_elf_image("", &src, info, &ehdr, NULL); + load_addr = info->load_addr; + load_bias = 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 = 0, n = vdso->reloc_count; i < n; i++) { + abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]); + *addr = tswapal(tswapal(*addr) + load_bias); + } + + /* Install signal trampolines, if present. */ + if (vdso->sigreturn_ofs) { + default_sigreturn = load_addr + vdso->sigreturn_ofs; + } + if (vdso->rt_sigreturn_ofs) { + default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs; + } + + /* Mark the VDSO writable segment read-only. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ); +} + static int symfind(const void *s0, const void *s1) { struct elf_sym *sym = (struct elf_sym *)s1; @@ -3546,7 +3611,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 = NULL; char *scratch; @@ -3629,10 +3694,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) } /* - * 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 the + * signal trampolines. Otherwise, allocate a separate page for them. */ - if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { + const VdsoImageInfo *vdso = vdso_image_info(); + if (vdso) { + load_elf_vdso(&vdso_info, vdso); + } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { abi_long tramp_page = target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -3644,8 +3712,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, - info, (elf_interpreter ? &interp_info : NULL)); + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, + elf_interpreter ? &interp_info : NULL, + vdso ? &vdso_info : NULL); info->start_stack = bprm->p; /* If we have an interpreter, set that as the program's entry point. From patchwork Fri Aug 11 16:50:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712609 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482373wrb; Fri, 11 Aug 2023 09:52:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgOrvaj7qjURHMeo6nQXrfDwZKmNSFeX4D00/qZxNPlCRtbIVufVLJgm0Ig2AvXAshnGh/ X-Received: by 2002:a05:622a:1816:b0:403:ed26:3f5c with SMTP id t22-20020a05622a181600b00403ed263f5cmr2374946qtc.52.1691772764447; Fri, 11 Aug 2023 09:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772764; cv=none; d=google.com; s=arc-20160816; b=kXDM9vmehz+OAEYqYOXiU9aRoX1G7tidVPUWZ0jgfi618MS7XPIrlOBLVgjVNgqHrh oAK18FZ8aSKpYi5NeHKALSf3QhIPEJCItnLda2JgmZZx1EKqIzRNIZWdoua/AN4cfvfc 78NX8BXMAWiG2vkVn+TduBb9Q20r/a3dK3dJxYwCnKtlAHShW9jhRcHL3dPDCs9B0isU byBvqehCql5HtGPNytcZf3mpPxnNC0ssn3TI++SudLYgeaLrg1edXOSg/WSintA+Xl5S 3CGp8t4uxjeRlfN+tWCM6spAH13vYzb2evsfs4M/gQ/DsIbQMcFTBeEUb+54PYaTXIoK rmAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NIq4S/pAACZk8nXXxZkiBpo/lIyWEJzLUxvAfi6YGAE=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=H6Jxg60Uf96EGptZVc6xBh6kaHApxU8ANgUTcI55fyMnLQEwqC0MlgIi8lVQ+aUbUK qjyxuJNLqGVVJSwq67aQJ8CUmG4eEO6rKlHVtEH1j6okkCWGglQdtM+618i9y2bSTm4l ZRWIkU+W5GRPrwhZaV9ajqTK4hOW+1O9q7Yh3py5bCzJMIiHh/RQ/zpFAMBmV2O/9Ame KwdV/XzEGgz3DfqCNkgqr5+Vly6mB+5sP7wCz4TsHGU2ZYmilWbhHLDSLSMZ+97JcXDI u7IMWK2jywlE1fVGFrFsN6HAsA5oQD9+DG4LVoBVfc4K07ENDoz0JKaY9snROHDWYgWs 0FqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jJaSwJFB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f8-20020a05622a1a0800b00403ae25401csi2598892qtb.529.2023.08.11.09.52.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jJaSwJFB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLw-0005mV-M3; Fri, 11 Aug 2023 12:51:09 -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 1qUVLt-0005lB-Iz for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:05 -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 1qUVLr-0001Mo-07 for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:05 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5650ec45a7cso1429812a12.3 for ; Fri, 11 Aug 2023 09:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772661; x=1692377461; 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=NIq4S/pAACZk8nXXxZkiBpo/lIyWEJzLUxvAfi6YGAE=; b=jJaSwJFB6iaJS2wLYD+ees51O76DufeLkmYPQo13azyBEJHfIP26yrxG4oWnRYaE0d 9KRHHnijx6NGnICKVV56T7RhHCKHsWfaUMLUHaSbhTaTk7Rza0X+jaZc9v6g8zLn2hu2 CNEP/l09YzD7V34XRsXStTIsb4IRtQ1M1TpsMFH2JdHQQ2Kx2tkr815W/WQhGjF0WzuW psVXI2K1X74sooLjrSg6SA/70qKioQN1/syKXYeUbnci40WZVnlYIJ+fY3KNVNsMXoxL ha/w6wUdGdR6qYFCu8MT0wXe7l4Ezb44vR5cMMOPf8RydKNaGYT85khhy3FVIglbK2ZH f/8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772661; x=1692377461; 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=NIq4S/pAACZk8nXXxZkiBpo/lIyWEJzLUxvAfi6YGAE=; b=flg4n3Le+43YMefqGBqcKLrhReeFh3p95H/D2z5fUrBsMcJYlm0w3bj3L101izHcRn nAlHOATaUGvshlfrDs+I+rbMGFrLs7412xUylkiDZR5JEl/2tclmt6fISZQx//wsIzpa jk36VuyNmpSuYw6Pzx4l57x5LG3/ORYVuOKEp95qXJqGlhQTw47GPvw1wn4R4KOECE1M p1IIfXucZflAJ3ed+fZq26DQfpG36uNPG8mLYwOKYQaaFgKmPHgz97mCm7yGnCf4y+a7 ouLFsHOfl5ndJclLh0zxxBTQXSP6UeCRkuSPrdjZa/ELc3Mr+4J9WsItMyDaOy+EFvbj E4Ug== X-Gm-Message-State: AOJu0YykU74MhUGRy4xZ5kYh0WX/03Saq3caC5iV+16qxU7qubxDPjXH Tu1tAJFuACDSxkw0CCIVdcnfmwEbcGvdVooXbZU= X-Received: by 2002:a17:90a:fee:b0:268:1489:959e with SMTP id 101-20020a17090a0fee00b002681489959emr1609189pjz.33.1691772661243; Fri, 11 Aug 2023 09:51:01 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 08/15] linux-user: Add gen-vdso tool Date: Fri, 11 Aug 2023 09:50:45 -0700 Message-Id: <20230811165052.161080-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- linux-user/gen-vdso.c | 223 ++++++++++++++++++++++++ linux-user/gen-vdso-elfn.c.inc | 306 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 534 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..0550804ea0 --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,223 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2021 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) = 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 = "vdso"; + const char *inf_name; + const char *outf_name = NULL; + unsigned char *buf; + bool need_bswap; + + while (1) { + int opt = getopt(argc, argv, "o:p:r:s:"); + if (opt < 0) { + break; + } + switch (opt) { + case 'o': + outf_name = optarg; + break; + case 'p': + prefix = optarg; + break; + case 'r': + rt_sigreturn_sym = optarg; + break; + case 's': + sigreturn_sym = 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 >= argc || outf_name == NULL) { + goto usage; + } + inf_name = argv[optind]; + + /* + * Open the input and output files. + */ + inf = fopen(inf_name, "rb"); + if (inf == NULL) { + goto perror_inf; + } + outf = fopen(outf_name, "w"); + if (outf == 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 = ftell(inf); + fseek(inf, 0, SEEK_SET); + + buf = malloc(total_len); + if (buf == NULL) { + goto perror_inf; + } + + errno = 0; + if (fread(buf, 1, total_len, inf) != 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[] = {", + prefix); + for (long i = 0; i < total_len; ++i) { + if (i % 12 == 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] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 || + buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3) { + fprintf(stderr, "%s: not an elf file\n", inf_name); + return EXIT_FAILURE; + } + switch (buf[EI_DATA]) { + case ELFDATA2LSB: + need_bswap = BYTE_ORDER != LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + need_bswap = BYTE_ORDER != 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[] = {\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 = {\n", prefix); + fprintf(outf, " .image = %s_image,\n", prefix); + fprintf(outf, " .relocs = %s_relocs,\n", prefix); + fprintf(outf, " .image_size = sizeof(%s_image),\n", prefix); + fprintf(outf, " .reloc_count = ARRAY_SIZE(%s_relocs),\n", prefix); + fprintf(outf, " .sigreturn_ofs = 0x%x,\n", sigreturn_addr); + fprintf(outf, " .rt_sigreturn_ofs = 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..1a5b0099fd --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,306 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2021 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 = shdr[sym_idx].sh_link; + ElfN(Sym) *sym = buf + shdr[sym_idx].sh_offset; + unsigned sym_n = shdr[sym_idx].sh_size / sizeof(*sym); + const char *str = buf + shdr[str_idx].sh_offset; + + for (unsigned i = 0; i < sym_n; ++i) { + const char *name; + + if (need_bswap) { + elfN(bswap_sym)(sym + i); + } + name = str + sym[i].st_name; + + if (sigreturn_sym && strcmp(sigreturn_sym, name) == 0) { + sigreturn_addr = sym[i].st_value; + } + if (rt_sigreturn_sym && strcmp(rt_sigreturn_sym, name) == 0) { + rt_sigreturn_addr = sym[i].st_value; + } + } +} + +static void elfN(process)(FILE *outf, void *buf, bool need_bswap) +{ + ElfN(Ehdr) *ehdr = buf; + ElfN(Phdr) *phdr; + ElfN(Shdr) *shdr; + unsigned phnum, shnum; + unsigned dynamic_ofs = 0; + unsigned dynamic_addr = 0; + unsigned symtab_idx = 0; + unsigned dynsym_idx = 0; + unsigned first_segsz = 0; + int errors = 0; + + if (need_bswap) { + elfN(bswap_ehdr)(ehdr); + } + + phnum = ehdr->e_phnum; + phdr = buf + ehdr->e_phoff; + if (need_bswap) { + for (unsigned i = 0; i < phnum; ++i) { + elfN(bswap_phdr)(phdr + i); + } + } + + shnum = ehdr->e_shnum; + shdr = buf + ehdr->e_shoff; + if (need_bswap) { + for (unsigned i = 0; i < shnum; ++i) { + elfN(bswap_shdr)(shdr + i); + } + } + for (unsigned i = 0; i < shnum; ++i) { + switch (shdr[i].sh_type) { + case SHT_SYMTAB: + symtab_idx = i; + break; + case SHT_DYNSYM: + dynsym_idx = 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 = 0; i < phnum; ++i) { + if (phdr[i].p_type == PT_LOAD && phdr[i].p_vaddr == 0) { + if (first_segsz != 0) { + fprintf(stderr, "Multiple load segments covering EHDR\n"); + errors++; + } + if (phdr[i].p_offset != 0) { + fprintf(stderr, "First vdso segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr != 0) { + fprintf(stderr, "First vdso segment not loaded at address 0\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) != (PF_R | PF_W)) { + fprintf(stderr, "First vdso segment is not read-write\n"); + errors++; + } + first_segsz = phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "First vdso segment does not cover PHDRs\n"); + errors++; + } + } + } + for (unsigned i = 0; i < phnum; ++i) { + const char *which; + + switch (phdr[i].p_type) { + case PT_PHDR: + which = "PT_PHDR"; + break; + case PT_NOTE: + which = "PT_NOTE"; + break; + case PT_DYNAMIC: + dynamic_ofs = phdr[i].p_offset; + dynamic_addr = phdr[i].p_vaddr; + which = "PT_DYNAMIC"; + break; + default: + continue; + } + if (first_segsz < phdr[i].p_vaddr + phdr[i].p_filesz) { + fprintf(stderr, "First vdso segment does not cover %s\n", which); + errors++; + } + } + if (errors) { + exit(EXIT_FAILURE); + } + + /* Relocate the program headers. */ + for (unsigned i = 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 = buf + dynamic_ofs; + __typeof(dyn->d_tag) tag; + + do { + + if (need_bswap) { + elfN(bswap_dyn)(dyn); + } + tag = 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 != sizeof(ElfN(Sym))) { + fprintf(stderr, "VDSO has incorrect dynamic symbol size\n"); + errors++; + } + break; + + case DT_REL: + case DT_RELSZ: + case DT_RELA: + case DT_RELASZ: + /* + * These entries indicate that the VDSO was built incorrectly. + * 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 != 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 != DT_NULL); + if (errors) { + exit(EXIT_FAILURE); + } + } + + /* Relocate the dynamic symbol table. */ + if (dynsym_idx) { + ElfN(Sym) *sym = buf + shdr[dynsym_idx].sh_offset; + unsigned sym_n = shdr[dynsym_idx].sh_size / sizeof(*sym); + + for (unsigned i = 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: files('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: files('semihost.c')) - syscall_nr_generators = {} +gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', + native: true, build_by_default: false) +gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', + arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) + subdir('alpha') subdir('arm') subdir('hppa') From patchwork Fri Aug 11 16:50:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712611 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482377wrb; Fri, 11 Aug 2023 09:52:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH97vvTDbFyVDhXz87S3llH9ZfpzhyoIUXq3+fnLjVL/bZvhpG/X0G3M3nVFaXRAchd/QVI X-Received: by 2002:a05:6358:990d:b0:139:b911:f3f1 with SMTP id w13-20020a056358990d00b00139b911f3f1mr2593988rwa.0.1691772764982; Fri, 11 Aug 2023 09:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772764; cv=none; d=google.com; s=arc-20160816; b=Yry2o5BqWostvVasPu06vOj14SEV1iQfiQK0Mn6uLr9ALjn7ApKo3sTBIBXYAYXFzC GWQifqZdyjWQvasYTfA5AaAxqHFgC/DraXd3NK7RiEqekZ2TDVzM1W/l89ot7Qbt5S2t NONeiAIltOaxmDhtVi6ozewX1CRV//6vl+HCAa0QIf/85i4DjtWHhsRPXjpRe4VHXO83 gvr/coBS8g5wxx22ddHx8NlvU4WnaqlkIrzr6IlPyDKFTIj9PJiZEZRSkI7SL7ivNF7l FwAnfbsEK5SbkR6ZA5XvPIXQ7r820pLbH7MbbEVXKCNa6SvFyDB0qMsx2QegHHWmggJG ZUAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6xn88yx7G9PaLj+24GCnAvuJlmylOiU/Sm68r/tNKXg=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=R42OXLLuaUMnyJkhKK4IM+ymsCx3vcJUUkSAViPSbG0N6AL/N5lfjSSHZT2r+O6CxK kz3DEEyXnoFgSBETMvKXQH63xXcTqIFGcn+XOR0hh2eUX7nTGXK5i8Gi20DowpxKR455 LCmIGkG+0RkhrbMoGFe+pifCCAnjqguHR7dpnD+LLScQnJar3Av3QztUDtlNV52nqvRH jSFvIlYtYfB8lOZmC08q3RVRlWN94CnaNBl5XLdmH6x5B+nB3Ssh8IoCv9rjkVyhpjWS Rq7NJPerQA9TdvRS2F78WOYImjZp4QBwn8LuDwpGAJsXlIWQ2FTqasxrCc3zUipiCpJL ArSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=olbIF2fu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b11-20020a05622a020b00b00403b84be504si2481571qtx.580.2023.08.11.09.52.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=olbIF2fu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLx-0005mX-Fl; Fri, 11 Aug 2023 12:51:09 -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 1qUVLt-0005lL-VC for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:05 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLr-0001N7-Os for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:05 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-564cd28d48dso1447526a12.0 for ; Fri, 11 Aug 2023 09:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772662; x=1692377462; 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=6xn88yx7G9PaLj+24GCnAvuJlmylOiU/Sm68r/tNKXg=; b=olbIF2fuWnk4Mc0OzTuWk9+TDERX1XSkzHys5an/udMzQoLZJQtyNTp0CGrZ2OyA3J 9pNHcxUmhmyLo8xwYTTB7sNXlulpJRf9jvcI+F9JiyKOsBLrGQ+ERMVrGSB1+aQ0mooi Vch/ee7ObALkqNPrP9icMWq/5Vwg+r3Qv11limxKThCJPV6dIaLOgg8svFA7+DD4G0Wm IBTh8RAHySrT+VpyiO5CD8X080+viL8bmox9Z/OVIqqwr0oBBQdQkWuSPP1f57jnAih9 ewC2OnD/lAO+DiopWrfg1jYe3NEpMQjD9i3XBvFNhGKsUach54tao1qakUwXq1XGaJOx DhFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772662; x=1692377462; 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=6xn88yx7G9PaLj+24GCnAvuJlmylOiU/Sm68r/tNKXg=; b=Cg4k2NQRc3Ku53GiuDhGVCjKvV9HZSMkNbvxyhSxF/zMGGw/ZOJym4p82nHQ+WkwGy mx/huxNM8/ZpUDbsZathQ8ugyCgbQstoNqKj929byi69bZUEM1ETtM58+QwdQZW0Wgve bFyJRvtd45vsDhIa0t+J84YN7ID0DwQGCxIXOUHPG+RFdbV7JuYKClQGqXofMz8+X2fB r3Smchposve3IWH1if0S6IKRWKDEFBKfT69/g69YICmNo84lmAG+GD+OwdJ7vnOx50DK vvVhC0v2hOrbB1om0gXncb2jFU9FNDA4dUX5iJb7SUs4uHzKwgjmwS44XehsoyooVh35 EeUQ== X-Gm-Message-State: AOJu0YzYS0vi+8uI44NULoO1fgRZ9TVAiFUPhuVmLWHyrUfgnUpEZdQJ UsVoZp7grDefdJeJL11VLY6WFhByhFCImGdC6I8= X-Received: by 2002:a17:90b:3687:b0:268:c5c7:f7ed with SMTP id mj7-20020a17090b368700b00268c5c7f7edmr1592753pjb.30.1691772662387; Fri, 11 Aug 2023 09:51:02 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 09/15] linux-user/aarch64: Add vdso and use it for rt_sigreturn Date: Fri, 11 Aug 2023 09:50:46 -0700 Message-Id: <20230811165052.161080-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building of the vdsos are not actually wired up to anything, since we require a cross-compiler. Just check in the files for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++ linux-user/aarch64/Makefile.vdso | 11 +++++ linux-user/aarch64/meson.build | 11 +++++ linux-user/aarch64/vdso-be.so | Bin 0 -> 6000 bytes linux-user/aarch64/vdso-le.so | Bin 0 -> 6000 bytes linux-user/aarch64/vdso.S | 77 +++++++++++++++++++++++++++++++ linux-user/aarch64/vdso.ld | 74 +++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 8 files changed, 178 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 5025611886..aff58cabfd 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -576,10 +576,14 @@ static const char *get_elf_platform(void) #define ELF_CLASS ELFCLASS64 #if TARGET_BIG_ENDIAN # define ELF_PLATFORM "aarch64_be" +# include "vdso-be.c.inc" #else # define ELF_PLATFORM "aarch64" +# include "vdso-le.c.inc" #endif +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/aarch64/Makefile.vdso b/linux-user/aarch64/Makefile.vdso new file mode 100644 index 0000000000..97ede674e5 --- /dev/null +++ b/linux-user/aarch64/Makefile.vdso @@ -0,0 +1,11 @@ +CROSS_CC ?= aarch64-linux-gnu-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=sysv -Wl,--build-id=sha1 + +all: vdso-le.so vdso-be.so + +vdso-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian vdso.S -o $@ + +vdso-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian vdso.S -o $@ diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..0b1b3a5560 --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,11 @@ +# ??? There does not seem to be a way to do +# when: ['TARGET_AARCH64', !'TARGET_WORDS_BIGENDIAN'] +# so we'd need to add TARGET_WORDS_LITTLEENDIAN. +# In the meantime, build both files for aarch64 and aarch64_be. + +gen = [ + gen_vdso.process('vdso-be.so', extra_args: ['-r', '__kernel_rt_sigreturn']), + gen_vdso.process('vdso-le.so', extra_args: ['-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: gen) diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..b0f4a83e32f300dd41110740a78f3172efbe9d1d GIT binary patch literal 6000 zcmeHLJ!~9B6n=ZVBmpPk9D{;nL=NNvA+ip!fbb){pLa8( zym`M|trQ9#*y6)C*k+7dv&h9-2TnG_s*S9+B=h`Fa4$XQ@LV5=ILKznd9Vt z$TG*f@FmNSF}}+~Ck!T4RbK*#w}}Mx1oxwn|df zZ>=YBx|wu`?0TH0txnv#)~Ia_*?PNI-%zX@Lnm<`+O6*9;P}l(zZc@am!P`5a^aFX z8NL$Ey{6|;z+ck*d3YZ2@6ey$e~ud3e@|mI`-)~?0B^tg@nhB@z;*g~)BYO>wC`~( z6F(uoiTFF>D&k$l239IMX5Ote2nNr1(+7_UhkI?}Q_(ZNh}=gRE<%p>vF-;kFL?y= z2;>pSBalZRk3b%QJOX(H@(4U+1e%lEKjVMze>qn2cc`ivf9Lrp4flhue%12fQF+Oc zA2b{$1e7^ok-XPP$m{$OdCtQvPx%lQo1bb4$v`*2KV^_5`wn39U9so9%jUhp?`O}E zd=>lG`7I8^X#0QEv?SlRJm<|p(=e8oeAA`9V0?Z`dHgtg%Dtrj_uP*5=;x?s`yYvC z34O=Se{N{+V~%Fa@*a8gMJN9~!Pb<6wH;nMq4<5^@RF+$e&+Bcb|}JZ+PN`XuMaj} zE_W}7J(wB5Oas*7<(2s}%Wq>|i?1N6yre2?^JmIxX>kqI>FU{q`KmfwshlgHSLf#! zs%15r+S-KLCdrfyTlU|l*%0=(I%(}HVwxCiN~_yTV+b2t-CCzr*A28qtfe&wo3(z^ zaA^YJdUrFt87KW#uR9{B283}_T}x`6ST!4HDH4QfJV-fe{|%RrZ~rem@f%a*}gJ```tv^3KHffSh+hp!twL-yhbW-la}DJdZE; zf*_R8#w{{FA>ASTE+*@j`$G`${XxIYNFU-)ad^wo@%-hU5d?Wp6MtC;$rXGz+hv9L z^L=FB(GH@X*QPDmPS5vT_8o3`Z`u2c)=2RaKbb#ub``74hxI{33hXD+VBT}MslomI zZy=NPZyIBJAFjI2*mlRi<@nPavCy`lA_$QdhaamzipG|84J~x57#X5KcnIqhRw^<+ k?H{@m-Pn?z%aLtvd?gH{td~T(xA*X$nq~WKMgi;p4~13}umAu6 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..975d203e6b999e01221a40fb4d2d1a5dc83d3294 GIT binary patch literal 6000 zcmeHLL1+|L82&etniw@2TTzJA74}f1PTB~v#Uc}%T@%>EC2G+kJl5SYyEVHjvlE+$ zU=R-#6uh|6BZA1GB5mONRvKm`>gUVRZWF6|XyBlZ6IycLWOrpy zHXwzo3hp0?L$A+7M|^BfaF<)SfIe=?kazWZOk9;vHXznn{mX9z&!^Yp7+46?2&mn` zT++U!=Q9!Uzm^$>}&wI~*xieq9dRe9%mK)o5Aq4YD z^OPjA1vO&4ru(S%Z&C=hp%CZ?jhi&?()e<1tt-tzy|90EU#HWm?!VOI>$LwJzULW7 z=$|!n;z=g9($nTb^Hr}k@45b>*P)1=cYVLrcDv^qwdL1reW6=Fue2|P_S_yVv^tAR`!6Ni z)H+mPlxKO!W&N7*8Do`km9fDn7S;dK9Q7}Knj77`C*Wki-FW>v0`7C>el$3Txoa_w zyP0Jb$SROkAge%Dfvf^q1+ofc704>^o)u`0tUTiX-#^}yx1PwQ3f7a)c7)smOFa$x z!^!?stpB#@EY=Lrz417U)dX}>lD7!@G|BfQB+9BSGr=_)uRB(dCr!)5a0qn&a`!dgg=i*RTJ8 zj;|W^oMt{vM}NzFnvP!3JcJ!|^i|E9I{IhL=S>|w=C?15)$6@-w>Um&cd4*Mg$Aj~ z)3XyZ)8DYJzM6#&i zi2ZPxO?Gd&?bpsS`d)}lv^rhiCA+cQskK}6puw?>HNQr7v({^dobQo6-&wRTx?Zo< z?Ib#?LAKje=e%0mRm}!RqDQvxF8N%<|7fF}Kfo8xaq#;Dik6R?xefQSQ_eN8eX#F< zt2!BHAJ`Yr|NGd_yFQv9zjxrRSibyrkdJezapr`_{P->a^X!Wo@_|Km%2^DaAKwq4 zoIQwPeB_}HhqVv+I9~(eJS`Z6Z?e|7mASLVXJ^RA_XxOI2V;K30gtm^&f?I=`5aK5 zPfY4BF<8HFVrTi1H6b70H{iS8{{f w2|7B^(GRwTIXSY%{MbJmnL};48QIGAu=#t$gbnlk$#**~e@vf`ue>Aw6>MP?*#H0l literal 0 HcmV?d00001 diff --git a/linux-user/aarch64/vdso.S b/linux-user/aarch64/vdso.S new file mode 100644 index 0000000000..41cda7eb24 --- /dev/null +++ b/linux-user/aarch64/vdso.S @@ -0,0 +1,77 @@ +/* + * aarch64 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +/* ??? These are in include/elf.h, which is not ready for inclusion in asm. */ +#define NT_GNU_PROPERTY_TYPE_0 5 +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1) + +#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC) + + .text + +/* + * 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. + */ + .align 4 +__kernel_rt_sigreturn: + /* No BTI C insn here -- we arrive via RET. */ + mov x8, #__NR_rt_sigreturn + svc #0 + + .globl __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, %function + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + + .align 4 +__kernel_gettimeofday: + .cfi_startproc + bti c + mov x8, #__NR_gettimeofday + svc #0 + ret + .cfi_endproc + + .globl __kernel_gettimeofday + .type __kernel_gettimeofday, %function + .size __kernel_gettimeofday, . - __kernel_gettimeofday + + .align 4 +__kernel_clock_gettime: + .cfi_startproc + bti c + mov x8, #__NR_clock_gettime + svc #0 + ret + .cfi_endproc + + .globl __kernel_clock_gettime + .type __kernel_clock_gettime, %function + .size __kernel_clock_gettime, . - __kernel_clock_gettime + + .align 4 +__kernel_clock_getres: + .cfi_startproc + bti c + mov x8, #__NR_clock_getres + svc #0 + ret + .cfi_endproc + + .globl __kernel_clock_getres + .type __kernel_clock_getres, %function + .size __kernel_clock_getres, . - __kernel_clock_getres diff --git a/linux-user/aarch64/vdso.ld b/linux-user/aarch64/vdso.ld new file mode 100644 index 0000000000..579d27638f --- /dev/null +++ b/linux-user/aarch64/vdso.ld @@ -0,0 +1,74 @@ +/* + * 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; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * 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) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0xd503201f +} diff --git a/linux-user/meson.build b/linux-user/meson.build index e4cb70ed2d..dd24389052 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -35,6 +35,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) +subdir('aarch64') subdir('alpha') subdir('arm') subdir('hppa') From patchwork Fri Aug 11 16:50:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712606 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482328wrb; Fri, 11 Aug 2023 09:52:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtjxFaCvtqQyfzW1aYCYEJWZyRlYlAzh4Nnpse3zN/hKK2pTP/MMhWjNsRBwoKGRV/Fh4O X-Received: by 2002:a05:6214:2e0d:b0:62f:f6ed:857e with SMTP id mx13-20020a0562142e0d00b0062ff6ed857emr1891106qvb.55.1691772757651; Fri, 11 Aug 2023 09:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772757; cv=none; d=google.com; s=arc-20160816; b=qO33YZ091IahPZpee5bfHiTS25Tafs5QikGFy1PVSiemVuwnP/p1EGfojO3ffN7xJ2 PdnuxOw+8JoqgcHU1pE4g+lVXO4/vmjgqgRz/I01QjuMiO1dL2W/arTpt8i1wxEwRG2p QoOQEinML8XUxOeH1vsp4vw5JrV7YdgJ1H8vdP5QHMH12pyDjhbX2ArgQuSuGozApXq9 NiRKhImFN+Buiwc1dghBtD2Upf0WqT/C9xKsC4HCQVNdrNd6ONOTyNla4m6J38JAAoua XS34KN5czmnu4k8psSaMSJQ0+rr5z3E/TnsxJY9Okx/yrfJxKi3cHrReHW3GppkpNFmR DQlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fSaNKhqzYwOq4diDL6Wp3COIrsXI0IfNJEj6qqfJvRM=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=YNp3a/iw/d2eSWD02tQQHsPq4XP3RWIRogxYm79p4VINblG4ShMcsD3VvYxQIFCjal 9OHxbmHJ9Cr4pkgW87n0H93Uzjhj4QydGuxdx3CVhihOl854PkL9ELJOKw/JHnokENd/ 0xayp1vpeeQXf3PUtkWs9GScqBixOCYdgdk+BlZx9SIkdb3JnEBNRCivwhkjxa/QJRhD CDO24ux2ybA6KK5ZNpxl7ehncU3BEQBlZeudtS9+f2XJN4hmMQILc0r/e2VnmU4xXFYB L7hQyj2ZlAjf9FUndQK/QiccVbI2hiyrguD8aTopcIBYiJfUYl0mDgOWX0V/QGKNrwWI KZ/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IqZrj74A; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o7-20020a0ccb07000000b0063cf5487782si2447887qvk.405.2023.08.11.09.52.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IqZrj74A; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVLw-0005mP-5G; Fri, 11 Aug 2023 12:51:08 -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 1qUVLu-0005le-8g for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:06 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLs-0001Nd-KX for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:06 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bc34b32785so16215825ad.3 for ; Fri, 11 Aug 2023 09:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772663; x=1692377463; 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=fSaNKhqzYwOq4diDL6Wp3COIrsXI0IfNJEj6qqfJvRM=; b=IqZrj74AxZu23ERZGxLIL6yPHH9VFJQ8PDPWwpw7tKcJaAJsdZcP1xftLLsvvE6T6L FXr/X9CmYeTj748v6ONlsE4S3/csr5thqEoI7NbCSmy0UkuilU0NcoXCvsGhCSvfM9Ar pEuSotmHGJFJ99FUxWfsdjZgVOKBeS5C8FyLeFlIxOy5dmyqRt7MqoS6YsHkTuU9YsBG GOTo2thaphku9dqOKG8hG5oRXvkBbZYbweSxXTNAMEoBs5mnuvkFkLh/tl2pHF1q8P74 wY/iY2D3BEK+PdXhD8J+nWi1lA3DlnJJXwg9eDYsXKqRqx1qF14zvgb4w0QP5+oV6ToJ yPBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772663; x=1692377463; 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=fSaNKhqzYwOq4diDL6Wp3COIrsXI0IfNJEj6qqfJvRM=; b=dq3YgQnBvBBx8hJh4SrFsl6//QdcHRPIgHJMXSBHQmQ0Gari4k1hdHaErgO50biBPz 8CEIEJV6IWg7IiWL4eXy8KLvGyu63OIvEBZ6JrGzsgLzhZUHsRjO8z4uwfPXpr3w5Wju N6Q3Ee2qqa/fGq/eZU2ETKxsnOpTL+vcCsstqjUyFUD69wrrAriCCHjH6ixABHrFkDNj QkecGsBNlVxSNx7hwFr3M18ZNViZIjjnaR1/pvJzd/su1h1FmySUvXQ4KmaVKUc3Wy32 sKWTUajOGaWuM/hWvxxhVZP0A0tmJEeUviUIx4rybbvBA414Tu7300xzvWE11sw4nrX6 uJTg== X-Gm-Message-State: AOJu0Yz7muIUuzcsilGjBISVtw0EzdboUom+wxlsqOtndBU6ImwvzfLa Pv8/2c2DNapV7wLzF5i6yRMlXO6w9/ccvmaP3p8= X-Received: by 2002:a17:90b:144:b0:269:3bc6:9cc5 with SMTP id em4-20020a17090b014400b002693bc69cc5mr1530057pjb.40.1691772663206; Fri, 11 Aug 2023 09:51:03 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 10/15] target/arm: Add isar_feature_aa32_a32 Date: Fri, 11 Aug 2023 09:50:47 -0700 Message-Id: <20230811165052.161080-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add a probe for whether A32 mode is supported. Fill in the field for the pre-v5 cpus. Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/tcg/cpu32.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 88e5accda6..41d05839a2 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3462,6 +3462,11 @@ static inline bool isar_feature_aa32_i8mm(const ARMISARegisters *id) return FIELD_EX32(id->id_isar6, ID_ISAR6, I8MM) != 0; } +static inline bool isar_feature_aa32_a32(const ARMISARegisters *id) +{ + return FIELD_EX32(id->id_pfr0, ID_PFR0, STATE0) != 0; +} + static inline bool isar_feature_aa32_ras(const ARMISARegisters *id) { return FIELD_EX32(id->id_pfr0, ID_PFR0, RAS) != 0; diff --git a/target/arm/tcg/cpu32.c b/target/arm/tcg/cpu32.c index 47d2e8e781..ea8ccf59a9 100644 --- a/target/arm/tcg/cpu32.c +++ b/target/arm/tcg/cpu32.c @@ -145,6 +145,8 @@ static void arm926_initfn(Object *obj) cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSP, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); + /* Similarly, we need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); } static void arm946_initfn(Object *obj) @@ -158,6 +160,9 @@ static void arm946_initfn(Object *obj) cpu->midr = 0x41059461; cpu->ctr = 0x0f004006; cpu->reset_sctlr = 0x00000078; + + /* We need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); } static void arm1026_initfn(Object *obj) @@ -187,6 +192,8 @@ static void arm1026_initfn(Object *obj) cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSP, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); + /* Similarly, we need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); { /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */ From patchwork Fri Aug 11 16:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712605 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482238wrb; Fri, 11 Aug 2023 09:52:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGR/w7/LmmtpgcRIFS4AHPzTxZMyPjW+xDl307uIJ/cYcyhDD81SgklWAvaU2EM5Iaf6Y8U X-Received: by 2002:a05:620a:2954:b0:76c:e977:9855 with SMTP id n20-20020a05620a295400b0076ce9779855mr2824319qkp.4.1691772745551; Fri, 11 Aug 2023 09:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772745; cv=none; d=google.com; s=arc-20160816; b=qoXq29bVtTJIFiPzeEUTQra9Ve4UwzTUveXeREt5iWVo54PF7/FK43gi4JRnnTFNj8 XgHVu4WqCq4nObnR2lZLyNxRmaoeooahSJBXK5mBjw6HK3iTL9Y3OwbKAB+3uJVe2u+Q AfUzGYYzRFMvX73arw+gwUYMpkgkJyZBxKB/Ut4bizXT2j4YciQMQXFPbigjfyURc07U +1wgHCC0/TzMFP8+kXMzDM6db60DwfXG0/T9FqE4DelcbVHwu4Lat/kAbWNKbvM5/blH 1bmLAMJVakB/57kL8vtXnmxPNy4s6TeF6koZ56QblzsKUirSEMQF+MZxusiRwIecMo6+ 8BLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fv/nprM4vucV0KWAOdV177LiiABh1cKOQpOoQHFwI70=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=XS7Ft8akDsM0RblQeP/WZ4ns/woiGNqIx+PsOxrbn+k62vH5yfzGFs8MQn9dfZhedD dyqhVbhlpDOJW90xv/cNcPtJA9tbyLHjKz4q5wgpUeBsZiv3xaUTISiWGZImnrhjW6j7 Hocjm2Pg2Wq2u0LB1I+G0ilBplcUbOvv8blrKZzgK0vkuZUqV6QbY+H3eX2L/rdiuoT8 yvjCP+ztlUSnFlIh4A2MJnlBIZD6XK/HQRqaSiDXZLC7rWXmrDi3WfyMx6om4udLgzUy nkjFbgl6rxgOcWCPU0r7SZzBrppPChhPCX5RvahVy7BOrPIHo/1tW8VTJ8FboRE8CFrx 4Z5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jqvulLz6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 12-20020ac8590c000000b004008393b23csi2500784qty.334.2023.08.11.09.52.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jqvulLz6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVMP-00069t-GX; Fri, 11 Aug 2023 12:51:39 -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 1qUVMH-0005xr-G9 for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:30 -0400 Received: from mail-yb1-xb36.google.com ([2607:f8b0:4864:20::b36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVME-0001SN-Dj for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:29 -0400 Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-d650a22abd7so1521628276.3 for ; Fri, 11 Aug 2023 09:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772685; x=1692377485; 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=Fv/nprM4vucV0KWAOdV177LiiABh1cKOQpOoQHFwI70=; b=jqvulLz6Uy5x20h1V53/yrnxHfGw0Lrcg39MriQ9LseiJgMVuWmm/R9QSFvqcUl9sK xJVO4cwLnLfiSNdKKNiVQd3Wqa3khMxV08PmlgbqtfShf1URMqtV928uofHVkn/pfPlO +Hr/hCdAikqkT3Y2G6XMGUkiU/2pt/O0PHXkSVA8UhT+/kJ/qRYRZ8YAhwHxEgZr77ng i5cvCxFJVmkaiynD9bUyQ+5ntDYdHPlDjzBZoJTv3IDVF55elhEE2YBcNZrzGpbl7oro lHoBy5wclmeXFFpxYMe54zlQvMykZrrLweMVDH9/GF/nJgX7Yy2jI8+S0LPttalQYa0l wfGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772685; x=1692377485; 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=Fv/nprM4vucV0KWAOdV177LiiABh1cKOQpOoQHFwI70=; b=cTnkuHn+9SIkOvF+x+Hx78uQSeaM6webR/3XDjhNMU4J2OlPyr4DWyR5J++BWj3+3b mVASz+27oTAGoMieI2+pwHn++K2TRHrSLuMzA+ZCqNTOaSosocK6zMp+3nuWx3mBJtoP OJq+ZLwGT+AYDRcpYyq6Ha4CYakEcdkKpJ0yA49yB0Et9oE9JmyokOQP6EyDTk2Mps2P RtQnfF7xxJeRKVAtnT/iv/fT3kMzS6wxUY4J3u6d0L60f51CgQz1e2CG4LV1eNx3ktUf /+WF8OKbXt5TqRS0s9XKoQcTscpT+1M/eiLobu7IWldKTOqRcBo2wQaM4z4z82TFgJm3 QTQw== X-Gm-Message-State: AOJu0Yz+4dWjVAkCVMfpwMvUr8ZtzVcVPVsl9IOWLJFH7b3wC9Hs2yi9 lygmirWNVuRHMDs2QXn0+qrGxuduwZk/12yX5EM= X-Received: by 2002:a17:90b:358d:b0:268:29cf:3231 with SMTP id mm13-20020a17090b358d00b0026829cf3231mr1881005pjb.3.1691772664111; Fri, 11 Aug 2023 09:51:04 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 11/15] linux-user/arm: Add vdso and use it for rt_sigreturn Date: Fri, 11 Aug 2023 09:50:48 -0700 Message-Id: <20230811165052.161080-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::b36; envelope-from=richard.henderson@linaro.org; helo=mail-yb1-xb36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building of the vdsos are not actually wired up to anything, since we require a cross-compiler. Just check in the files for now. The thumb vdso will only be used for m-profile, as all of our a-profile cpus support arm mode. Signed-off-by: Richard Henderson --- linux-user/arm/signal.c | 30 +++-- linux-user/elfload.c | 24 ++++ linux-user/arm/Makefile.vdso | 17 +++ linux-user/arm/meson.build | 18 +++ linux-user/arm/vdso-arm-be.so | Bin 0 -> 5648 bytes linux-user/arm/vdso-arm-le.so | Bin 0 -> 5648 bytes linux-user/arm/vdso-thm-be.so | Bin 0 -> 5620 bytes linux-user/arm/vdso-thm-le.so | Bin 0 -> 5620 bytes linux-user/arm/vdso.S | 209 ++++++++++++++++++++++++++++++++++ linux-user/arm/vdso.ld | 74 ++++++++++++ 10 files changed, 355 insertions(+), 17 deletions(-) create mode 100644 linux-user/arm/Makefile.vdso create mode 100755 linux-user/arm/vdso-arm-be.so create mode 100755 linux-user/arm/vdso-arm-le.so create mode 100755 linux-user/arm/vdso-thm-be.so create mode 100755 linux-user/arm/vdso-thm-le.so create mode 100644 linux-user/arm/vdso.S create mode 100644 linux-user/arm/vdso.ld diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index cf99fd7b8a..bd160b113b 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -167,9 +167,8 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, abi_ulong handler = 0; abi_ulong handler_fdpic_GOT = 0; abi_ulong retcode; - int thumb, retcode_idx; - int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); - bool copy_retcode; + bool thumb; + bool is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); if (is_fdpic) { /* In FDPIC mode, ka->_sa_handler points to a function @@ -184,9 +183,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, } else { handler = ka->_sa_handler; } - thumb = handler & 1; - retcode_idx = thumb + (ka->sa_flags & TARGET_SA_SIGINFO ? 2 : 0); uint32_t cpsr = cpsr_read(env); @@ -202,24 +199,23 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, cpsr &= ~CPSR_E; } + /* Our vdso default_sigreturn label is a table of entry points. */ + int idx = is_fdpic * 2 + ((ka->sa_flags & TARGET_SA_SIGINFO) != 0); + retcode = default_sigreturn + idx * 16; + + /* + * Put the sigreturn code on the stack no matter which return + * mechanism we use in order to remain ABI compliant. + */ + memcpy(frame->retcode, g2h_untagged(retcode & ~1), 16); + 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]); - retcode = (sigreturn_fdpic_tramp + - retcode_idx * RETCODE_BYTES + thumb); - copy_retcode = true; } else { retcode = ka->sa_restorer; - copy_retcode = false; } - } else { - retcode = default_sigreturn + retcode_idx * RETCODE_BYTES + thumb; - copy_retcode = true; - } - - /* Copy the code to the stack slot for ABI compatibility. */ - if (copy_retcode) { - memcpy(frame->retcode, g2h_untagged(retcode & ~1), RETCODE_BYTES); } env->regs[0] = usig; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index aff58cabfd..8e03bb6d76 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -568,6 +568,30 @@ static const char *get_elf_platform(void) #undef END } +#if TARGET_BIG_ENDIAN +# include "vdso-arm-be.c.inc" +# include "vdso-thm-be.c.inc" +#else +# include "vdso-arm-le.c.inc" +# include "vdso-thm-le.c.inc" +#endif + +static const VdsoImageInfo *vdso_image_info(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + + /* + * The only cpus we support that do *not* have arm mode are m-profile. + * It's not really possible to run Linux on these, but this config is + * useful for testing gcc. In any case, choose the vdso image that + * will work for the target cpu. + */ + return (cpu_isar_feature(aa32_a32, cpu) + ? &vdso_arm_image_info + : &vdso_thm_image_info); +} +#define vdso_image_info vdso_image_info + #else /* 64 bit ARM definitions */ #define ELF_START_MMAP 0x80000000 diff --git a/linux-user/arm/Makefile.vdso b/linux-user/arm/Makefile.vdso new file mode 100644 index 0000000000..89da6f91ae --- /dev/null +++ b/linux-user/arm/Makefile.vdso @@ -0,0 +1,17 @@ +CROSS_CC ?= arm-linux-gnueabihf-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=sysv -Wl,--build-id=sha1 + +all: vdso-arm-le.so vdso-arm-be.so vdso-thm-le.so vdso-thm-be.so + +vdso-arm-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian -marm vdso.S -o $@ + +vdso-arm-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian -marm vdso.S -o $@ + +vdso-thm-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian -mthumb vdso.S -o $@ + +vdso-thm-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian -mthumb vdso.S -o $@ diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 5a93c925cf..66072411d6 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -5,3 +5,21 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +# ??? There does not seem to be a way to do +# when: ['TARGET_ARM', !'TARGET_WORDS_BIGENDIAN'] +# so we'd need to add TARGET_WORDS_LITTLEENDIAN. +# In the meantime, build both files for arm and armeb. + +gen = [ + gen_vdso.process('vdso-arm-be.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_arm']), + gen_vdso.process('vdso-arm-le.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_arm']), + gen_vdso.process('vdso-thm-be.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_thm']), + gen_vdso.process('vdso-thm-le.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_thm']), +] + +linux_user_ss.add(when: 'TARGET_ARM', if_true: gen) diff --git a/linux-user/arm/vdso-arm-be.so b/linux-user/arm/vdso-arm-be.so new file mode 100755 index 0000000000000000000000000000000000000000..197a8cc1b5303c0b5844272f2279eb79f9ddb724 GIT binary patch literal 5648 zcmeHL%}*Ow5T9LRV+a^0p-m+?xGD!!g{37ZiqtB?1PqZ3iTIF`(_(A~y9FEBOMr+d z?k8!Irbrx`OC?fq=q0^2Qd=d59{NZ0kSdClR#iVF)Ke<@`@Mb7n3PM^QzZ`>&-=~H z&g`3gFVf7l;bg+HEvZsKy0L~LN>#te(T!lm<|-y3*rL(~eaN@buJ|D&xj}PHKxm}l zxX*abx9IrHq4I2CK@Ms=5?U|qv8=#GR`E05lk+0>4|^;_u#ruE%AFeS!kS!bZwC&H zj8Ds_r)S*W+>M{_de@q}J0CpydS~P+Y!UFZ|BUqvGKhSv4fbyFU7Nv0@F8%txVsA< zdmHjEU>ovxh&x#SSIU|Ihh_H%8pSuT3zE``(F9LIK2J2cI%(_-7fEB+b z>q5dFtHdvb?;!LMaox+Aa?wrC7t?RMb6L;JFJuo?p6vgJx|A&&oqn=-DU({2`Fvq% zrH64H{Ci!JXUC^6xP8t^mC;6a|Ifmyz+daH5AMRky>){5ZPZDHmlgPO=}#cqNUCO5 zN8k;t2f&RYt^EEMAWuOqLM9=vL(V{MK|&|^X05jnGz&m4Q0vNs*lQ81qooxp zl?Qcf`A)3|BjI)XHtWUwuR;It0R1TR-yEQyf&M=9QQ3>r4=l(ziKJ~zI#Y?h)AnxU zz1H_zJ~;GY^Lo?u@JEd|LN|lA8a@u(wm)HV5cA_~w5&jON+R+|>tn#*L%#;uF40Kv z>P|2eiZ(S;zS6)WATjVS@R^5<`aU7;6EZ$9)u~>AdIjngs8^s~fqDh%6{uIBUV(ZA z{;w6N4D|fexVZJ$T3dhIXl?vfseJpCx=pRytkH$FE?lDy|xD31u%r*HQ z@Vy$m)A!kvu)X>8=x(pFdnfkeI0|_zl}*j&(ea@P3-(V*$PROT5baQj236br-WHgB zD@gU}wEI1*Sm^H*(EYCJ>uJ<|uj=oKRYPR@cVP67Bzv2`z~~Q2oIxnuM2S^Q{ra;3 zETe?<=Zv6Az%2mPJvI1!{bAz|8~xGC1ymo1HD?V~(*DN~0zD`LskuN5&z}bzz~=cp z`cVJjRP=wafe6U#6)~-*c~035O*Yb zZZMv7&m|I*!&B~5d@woe*31O-1Y+L=;rXdV&7@)9q~d^~gc@LoQ(j&0QnQd=$(K2^ zDipn}IGNQ#Y9XIi3;05&yp%Y(R5|DCyplL`g(c^5wp7j+3;TeZ5ht5-FO^aYSvQw~ zr$OR)*%eQm_{5l#^1M=hcF99o{tb1&ndg#co%evu8HXW##^q%wc%E_W%uG$q()1Zu zvmc)4SHV0th{t=Q?#>J_{diUxj~~2GW5&aIQfG?i*%1B6r@*{djQ7lEIS!2H6dAwM zS_ePgKXnH=S2JYpNdhyqT`1{y$7gkqOg!jSEhfzj4shFN^)B28eVCUt3ubJ_!#!4a zWrzk%#%~c=`vqcneX#ZXe)-51F#V8+Wg@GYCM8KJAS(!H-kItR{HS{jNizG@IejJk ozJO^9h;zvozn+a literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-arm-le.so b/linux-user/arm/vdso-arm-le.so new file mode 100755 index 0000000000000000000000000000000000000000..94c757a7e283fecc45847a7942c2943b989a1163 GIT binary patch literal 5648 zcmeHL%}-oa6hChs3_}Y8{ZL78fsqAi;8Bq@O>7Lq$CR3ZHhdWB=JA-B!bF&v%sdJ- z81a*8Yn_CcxKYtGjSFkyN*8VH!bSfGO*EuQO^jkBu4=~L@4k2G!?G}OW%ADOn{&^{ zJ?GxTdy|~=>QE|a7=~yvr9+g|EYb^Qa28-JB0B7OZI*^lhs6ajdUH}dPyvBoSwQwEw zzrcC^ZSW7d_>Ytg>^~&GR}+v=At7@fM)of74hXyt<;TH~24oynIcqy>s)_gKeOMQg zSATC!Hy)opifsF0rd+Vo^M&-w_H5R5a|>D7PkEyE5p^kB);fP@;X=k)k@;MHak-0e zE&M$rsWYRKQ+AJaf*B*bA3ibseERLLjl9Q`0RJ~6@0^DGx%j0?8%fv9Xf>bfgIou+ zH;PPwp9C+0r@$|RPlIoQ7s0o|uY$)AbQ8Q29HmrbTpE+eYTRgTXjHXsf%dxwukO+x zkF7_p8O(nixU-Lb82VfL=%=Co26~mpkJAes2|34+w24Wl*P35zdOiL|b|8*mp`)%ly_wXf{dMx)L3b>vUi zM3v7k@R`?VQ9e=MC#rm44k@faSb?wtVFkhpgcS%Y5LO_pKv;qQaRt`;x_+)JZf+T? z>sxh3<+ru9+xMy4@O2vjUCh_T0=iM?M#bBQuIZ;G$V-s9CT>E$8IX5+KDrl+Y}`Lm z?N)a8*}Zb&2^7=GIx{&j(1Ky`Fd@+hJF-V<$5)xE3-sm%RGF%C_4;&A_PW?@KZ@yh zyzJ{eyVv=$zxQNsQla~IQ+1Fc?C(8$OmWU1Jh@)+HosXm)pP(Vzj-v(lt8(tFH;)) z6MMQE^!10h)XgUR*~|6rHs72!JS6(FOuCmhAh$t2hy8uv5$rz>uFoe@F9VSE{po)m zvL?CrYC+7~*?Jg9%)9Ha1r;4SQtb(*V(w-4}@cd|E z!7kB{I0^8rVm!WQL?_nVN78=JV@)0X`2G=`t7*bEMM->D{n;Ad zOM-cIJcugBIJlm{@qHzD7T$wC%uAX97@NA_91)@-?N@}P{o0U>XwZj(P5WK){Zw69 zD4+tSi7L_>fDlElNfj74OVXr6>zrEuIs7)Ew POVF*CA@cg6s1SiroF+~Rv4fmOY7x?lW5320jUCx9 zO;WYOK%s?}QmH~JDI2DE8Z{Kd}gj^6Oq&Mk! z_BT5_^LBQ((#*>v;~6Vt$vTDQQH-HTQq?bVmltV`+H+>0@} zb^dPP@MvyIzRgXQzqqvP+KcbT2KEf)7k|3-!YRxpz*GJj>o#Nr@t7Oz-MR?b39f;+ zfs?hhHQ0n!ApZgmLH-JH8RP#-u5qwk)_%h{jc^Y_#&-Cz`+)BO?$r2RV1ARq%r&#F zG4r}kVT^c|%nJ#7TqmxkFS=aL_bMBVP{r&$?*WHHE>6Nvk zrNXitt5g@3`smljzr8YkFgJDB*=O%p5krXX|5>;d_>2GYjP?9t5|G#CiUQA#F(9wfK{eXCa3muR=Zxi8G6r;WP$$5)${;zo6EM zyo63Bte&noR4NYg*!300osv$(&V(*7UyQ#8`p>q|k3oNJ3;i_oSD=rz_~{20#GFLX zZU&uhCSU1(HSt>fbl2)RKMj9*$Xzm;_(AJa zz+Xd;{lg}ih@4uDM5D=$cFKp_cm*T{{uws-PV8CPM72%S*kCH4AOk@Lf(!&12r>|4 zAjm+Ffgl4x2L7)ZXns2Qd;3oLzImOaOL{c1dV0~<6By5_NyUEzDF<(V@*T>$!FmJ+(x}YVU2maYb&9o;D*4e}aYn|ROg^0*amI%8;*5?@45i1NiA-j4 zx?mr7>y1jSx&b&PvE8zBv|gBVopK4528r#tOP<*2 zeAX^_UcEB2;2|ylhI(Mkd&#@bcR*$z!;rq?@(>if&$xD`Z>IWX`i`sq4)610V4g4h z@!hDmGYw2To-_UNLhsX<{&1hvo#K5qL_0EjD12A+ciU%S&jjlf8M|k+4t9Kh>J74Y zX2`sg4EknkP}1(Q&*~i+f6%L3OqxC$;EK=cTeuI}FfM5ZOyBf}cdXvZFefw_yLn)3 z7f$(a+}gZfE;*s?5Qk|ZtG*>ANhu(kaA>}nYCz#x8Z!IUF^xKT9-na)h`mR?OMV}H d@@=>H+rb=v4mM=`;s2KncDH~p8Y4($_c!UoWV`?X literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-thm-le.so b/linux-user/arm/vdso-thm-le.so new file mode 100755 index 0000000000000000000000000000000000000000..241fc569a4752fbe5642971f8dff72c3625799d1 GIT binary patch literal 5620 zcmeHL-%lJ>6h6DdE>M)T_@fWiXyS|dq&_wF!I;K>L5)p}i4ToIB|cU0`|h1f2js!TCzCnw&3Dha z=bn4#%*-a|yf8GHi9{k|#FAa2w3J96jNU!CL?zZIT@uG!N;<%Lj`PF~A5CE5ZZs&6 z9vBI(bEZ;s(}lm0wrW&>zBvE#Pg~y%)S4I?qG>K5$z=$5AB`(3w*syno&g z^Fq=2*JHZz`1DcYI428@s*^ua%|GwVx}H}myRw;af8RgMb+=(`{>tj{LT*t`lqz!z zy^L$)f3J)l9-BJq?6dcC$LQK0-x&VA_vJ6`d~Oc_d^Qw)&WQXm_ldvHrB=7IY^4NM^3gJ2m>-lDw=xCtDEoj#IE#?Gw7;_*~# zGx?FGxbnG;sS)_7dsaSi-zTnoxHOb717QZj41^g7GZ1DV%s`ldFau!*{=XSm`mF!A z<{k3G(shpB^he_>XXmwT>@o6<%%{K05-|_mjL9Ew(67In_~z|QYS{REzd=vmk6h*4 z+)PQ8r4oChH!Jb>=4|Wc#qx@uT1!=Wx+g%BrK(e1i)&q1s>>{RAeLX%vUbVts1`HY@nMLjN65O}!q0-UWRx*7t*>Sic9%9*CA!IfQ|^fBGLYQ(*QE^59_a zU>&f%K>|p2*6xMYKHZ~ao z-Gp`Bh)o&~s!1VsW3lYzX24!ubJ2_{RnHZ>uvp2JOL;YbFF5Dr#4hF_+HVj5%m@iSpOzMlJho$>fS5oimn z3H^uz0KY26<99~%V9a$C<985a+UUpck6`c22$m_y;JWJf&-h&u+}Ff|s$xunO`nb5 zE5WnyKIp@JDKh|L(-!O%LRDh?YS4^d7d9gj=1`b3ey4mtl~*PT;94UzQI-INSevS0 zg3r>332pW?_Dk@)1|xfq+X3#&nEd52IlxeQwuyYffiET=e_w)rKf>>daRM8^zX6tP BWsm>> literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso.S b/linux-user/arm/vdso.S new file mode 100644 index 0000000000..1831b29efc --- /dev/null +++ b/linux-user/arm/vdso.S @@ -0,0 +1,209 @@ +/* + * arm linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .text + .eabi_attribute Tag_FP_arch, 0 + +#ifdef __thumb__ + .thumb + .arch armv7-m + .eabi_attribute Tag_ARM_ISA_use, 0 + .eabi_attribute Tag_CPU_arch, 13 /* TAG_CPU_ARCH_V7_M */ + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .else + ldr r7, =\n + .endif + swi #0 +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r2, {r2, r3} + mov r9, r3 + bx r2 +.endm + +#else + .arm + .arch armv4t + .eabi_attribute Tag_THUMB_ISA_use, 0 + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .else + mov r7, #(\n & 0xff) + orr r7, r7, #(\n & 0xff00) + .endif + svc #(\n | __NR_OABI_SYSCALL_BASE) +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r3, {r3, r9} + bx r3 +.endm + +#endif + +.macro FUNC name + .globl \name + .type \name, %function +#ifdef __thumb__ + .thumb_func +#endif +\name: +.endm + +.macro ENDF name + .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 n + .cfi_startproc + push {r7, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset r7, -8 + .cfi_offset lr, -4 + raw_syscall \n + pop {r7, pc} + .cfi_endproc +.endm + +FUNC __vdso_clock_gettime + syscall __NR_clock_gettime +ENDF __vdso_clock_gettime + +FUNC __vdso_clock_gettime64 + syscall __NR_clock_gettime64 +ENDF __vdso_clock_gettime64 + +FUNC __vdso_clock_getres + syscall __NR_clock_getres +ENDF __vdso_clock_getres + +FUNC __vdso_gettimeofday + syscall __NR_gettimeofday +ENDF __vdso_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 16 bytes per slot. + * + * Within each slot, use the exact same code sequence as the kernel, + * lest we trip up someone doing code inspection. + */ + +/* offsetof(struct sigframe, retcode[3]) */ +#define SIGFRAME_RC3_OFFSET 756 +#define RT_SIGFRAME_RC3_OFFSET 884 + +.macro slot n + .balign 16 + .org sigreturn_codes + 16 * \n +.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 +FUNC 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 + + .macro cfi_fdpic_pc ofs + /* + * fd = *(r13 + ofs) + * pc = *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, 0x06 + .endm + + .macro cfi_fdpic_r9 ofs + /* + * fd = *(r13 + ofs) + * r9 = *(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, 0x23, 4, 0x06 + .endm + + /* 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..3bddef97a5 --- /dev/null +++ b/linux-user/arm/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux arm replacement vdso. + * + * Copyright 2021 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; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * 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) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text +} From patchwork Fri Aug 11 16:50:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712610 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482375wrb; Fri, 11 Aug 2023 09:52:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5gKGWWx4kKCAZsIfv8S4TKiIjGqGHSInMCweaaTh/h06MQ0SuNzvkBlXt9uFVz1X09izl X-Received: by 2002:a37:e101:0:b0:767:3fb8:12dd with SMTP id c1-20020a37e101000000b007673fb812ddmr2349739qkm.38.1691772764764; Fri, 11 Aug 2023 09:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772764; cv=none; d=google.com; s=arc-20160816; b=ks1QHaXg+QCdfCRhixzsK61Q/JGtZm17gZI7++xOI8JHDBF+u1zwAv3jQAl0qIWcJf pU4ywFzz0rNCMsy45XbQ+4BzKq35wO1U7E5tCSUQa000QA9ZWmNVxPItEnq7K6Iv3Hnh rE/XyL5HcdD7dkuL3jw6aFIXEs0RCf0BgEAcIh5X43F9G6t0Dm0HwPE0PJAWLx0kQGIU CudWII/fmjqVXGt712wiJVIwkAxwNYWWPEEe62t2b49ElS1XSJIWOUqfCgIDjJt7WUBu ax6z7xeaYNRCgIb093LA2BaVFtqNvV3HIRe2epk2DRmv5eN0Wm6g9gPIv6BK1BBgA7Ue aLiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pis+qqfCW8P86dzUIrowDFT2z37u/MYmMlvty1DjFqk=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=MDesYNY/2leUTfuTp55CG6qbJ8oeYn/lKY73blPYsziyf6WODeO07x1TptgvkbPvNV BsmOluSqCBpJOZcKTShHzfMw9qP9xCZ1/Px4pvNfy+A3TY+XmJtV4uNXo+4NThG6KYCU ZXJr0QYn6HCmkvkYoFJaxpsLzRs7ISjxntq27pxmTkopkLnQb4mQjg4wM+uwAHDUTEOe dbq8imcovaF8GOUmU3ev+zvS4ppK0uEpbYuaihoBL7aHRF4NUFYC2nZQlKroo8srUxMR FfDQOegwws1yGffN+c6c7g6dotlzRzxF+uqOObzEK/IJ3QBKrex4w2K6JsYgc/o/bvky rEOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CjtY0PZW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dv24-20020a05620a1b9800b00767b0c9bcf0si2388699qkb.564.2023.08.11.09.52.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CjtY0PZW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVM1-0005mw-7C; Fri, 11 Aug 2023 12:51:13 -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 1qUVLw-0005mW-Uf for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:09 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLu-0001O3-Dy for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:08 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-564b8ea94c1so1454120a12.1 for ; Fri, 11 Aug 2023 09:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772665; x=1692377465; 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=pis+qqfCW8P86dzUIrowDFT2z37u/MYmMlvty1DjFqk=; b=CjtY0PZW0gujjUuxB0VbtFU2w0IV+0dCDZqYId44L4FpfsE74T38m4SjHM70xMZkKz g2NRbI1iYfrGwNWGaeqQCNrfl2JUgxoENUfO+Rdz3v7HtO6vPBpbsPVQ/YJEjuxkltal OsCFBgvvcK+d+d0YdZezPq4gZF1KRhAWtYDPd3R70gZEs7RXi0bxhVkaEJ93LFlQRD6S LrjuH2QOMKbZnhAi6rE3vRL44LDsnyCRkK1bDmeVnELBSW9BXdXWltpDXu25H0WU/igf NQbRFjs2MohONQofOiAm9Q8Fr/BvEUA5HghOIiYLaY2vbiAFG+eXxsh6qMj4ULIwgr6w xxqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772665; x=1692377465; 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=pis+qqfCW8P86dzUIrowDFT2z37u/MYmMlvty1DjFqk=; b=UYsdUBFT7XbRFbc3/Z2FJn2DcJ6fmxqsgPz0YNHlzJLlBli3jjXCVcpt9t9NqQB+0/ bV/djw5g7E+wCSlv9C7B/Eof3MuiqmHxLTQGpxAy214SdV9tCd+Rqp70z1iEVuH6FIP/ lPCFlPtRCFaGGlHSUtOpATL7wnaTlJYp6d5lBIkZjVIk73CoYCznqLmtBITHVEfE6c9T pj25Vp4wrPpAL+Buq9pua487ZYkD0IogTNsFzE37282HBpTypascB9Y9Hi0lApN3QaGg VeGv/PiRyVTGYGD3gqptWhgp2asaNNBCVgF06ZT0lwb8w9TY6h+QQ2yq4nwMAEgkBx7k AiNg== X-Gm-Message-State: AOJu0YyYkjFGuVJz0wSV22p69Jc7p+EC6Go+5k3kRvrLH0+ji3DWiWNc 7evJ4eRWJ3quR3U5B4FLjszpDrBbovxQLqAFCXE= X-Received: by 2002:a17:90b:400a:b0:268:2311:e8d8 with SMTP id ie10-20020a17090b400a00b002682311e8d8mr1714523pjb.17.1691772665107; Fri, 11 Aug 2023 09:51:05 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 12/15] linux-user/hppa: Add vdso and use it for rt_sigreturn Date: Fri, 11 Aug 2023 09:50:49 -0700 Message-Id: <20230811165052.161080-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Drop the now-unused 9 trampoline words, and describe the frame without the trampoline in __kernel_rt_sigreturn. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 + linux-user/hppa/signal.c | 1 - linux-user/hppa/Makefile.vdso | 6 ++ linux-user/hppa/meson.build | 6 ++ linux-user/hppa/vdso.S | 149 ++++++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 75 +++++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 5196 bytes 7 files changed, 240 insertions(+), 1 deletion(-) 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 GIT binary patch literal 5196 zcmeHLTX2&_6y8m`h?i>1Fr!Y<(V03TLgZ2vMX_m{v|xHmQlRzno08B(+64dnt!Y&# zrJ#tSAYi?V;vMhzD?akzLq~o0rOYtnjH5H?lUl!T|9?q4!-F$E`0}6R%h_|;v%6QP>C*pB(!-jarNeZBIKVIh--%n9~VdDL|l%$<-U@r0?d=`hp5?Q4RN~Mq4!%Rm4%zLDf8@TJBYAN^0$} zx^+aw?o+MztF{MJ`&QMlO?8e+72hsZVoa*!4yn4vrCPUBs`b01+OS8e?%hnkK0EIH zydxN!+)(e6p8-Dueg^yu_!;ms;Ag|OQN+)eJyT*#P!?yV zQ&h9abt&t(0<;koy=|9(# zlb(FGCucpGbvTISruJt&jy<~jlWwgHpMahZ8|PnQ_UGAGK&Q#8tydymxwf{Ny4%97 zYZ_5RqhDY}TC8Y1+#0c3n&QH0j? z-$4&WznP_wIhXHB=Nx>wCo|r07v>$nQtsp6p7eWSyh#^=eGtsk#CXJNfI9k}bfJ4U zP-*hsw1}c#GYt*=_#X9}^vRPP6^7Nd_-O+SnRwMu O%=EJ%j~XX%?e`Db?gR4x literal 0 HcmV?d00001 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8e03bb6d76..e389295b8d 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1778,6 +1778,10 @@ static inline void init_thread(struct target_pt_regs *regs, #define STACK_GROWS_DOWN 0 #define STACK_ALIGNMENT 64 +#include "vdso.c.inc" + +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index f253a15864..881269f1ac 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -41,7 +41,6 @@ struct target_ucontext { }; struct target_rt_sigframe { - abi_uint tramp[2]; /* syscall restart return address */ target_siginfo_t info; struct target_ucontext uc; /* hidden location of upper halves of pa2.0 64-bit gregs */ diff --git a/linux-user/hppa/Makefile.vdso b/linux-user/hppa/Makefile.vdso new file mode 100644 index 0000000000..d4362c4961 --- /dev/null +++ b/linux-user/hppa/Makefile.vdso @@ -0,0 +1,6 @@ +CROSS_CC ?= hppa-linux-gnu-gcc + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 \ + -Wl,--hash-style=sysv vdso.S -o $@ diff --git a/linux-user/hppa/meson.build b/linux-user/hppa/meson.build index 4709508a09..e065a16a96 100644 --- a/linux-user/hppa/meson.build +++ b/linux-user/hppa/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so', extra_args: ['-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_HPPA', if_true: gen) diff --git a/linux-user/hppa/vdso.S b/linux-user/hppa/vdso.S new file mode 100644 index 0000000000..eeae2c999a --- /dev/null +++ b/linux-user/hppa/vdso.S @@ -0,0 +1,149 @@ +/* + * hppa linux kernel vdso replacement. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .text + +#define sizeof_rt_sigframe 696 +#define offsetof_sigcontext 152 +#define offsetof_sigcontext_gr offsetof_sigcontext + 4 +#define offsetof_sigcontext_fr offsetof_sigcontext_gr + 32 * 4 +#define offsetof_sigcontext_iasq offsetof_sigcontext_fr + 32 * 8 +#define offsetof_sigcontext_iaoq offsetof_sigcontext_iasq + 8 +#define offsetof_sigcontext_sar offsetof_sigcontext_iaoq + 8 + + /* + * While this frame is marked as a signal frame, that only applies + * to how this 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 start. + */ + + .cfi_startproc simple + .cfi_signal_frame + + /* Compare pa32_fallback_frame_state from libgcc. */ + + /* Record the size of the stack frame. */ + .cfi_def_cfa 30, -sizeof_rt_sigframe + + /* 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_rt_sigreturn: + + ldi 0, %r25 + ldi __NR_rt_sigreturn, %r20 + be,l 0x100(%sr2, %r0), %sr0, %r31 + nop + + .cfi_endproc + + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, @function + .globl __kernel_rt_sigreturn diff --git a/linux-user/hppa/vdso.ld b/linux-user/hppa/vdso.ld new file mode 100644 index 0000000000..fed994c3eb --- /dev/null +++ b/linux-user/hppa/vdso.ld @@ -0,0 +1,75 @@ +/* + * 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 . + */ + +/* + * Note that the kernel does not implement a vdso for hppa. + * Mirror the symbol that other targets use for this, e.g. i386. + */ + +VERSION { + QEMU { + global: + __kernel_rt_sigreturn; + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + note PT_NOTE FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; +} + +SECTIONS { + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text +} diff --git a/linux-user/hppa/vdso.so b/linux-user/hppa/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bd77b8a5c33d66380a79b2f816237568998c8af3 From patchwork Fri Aug 11 16:50:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712612 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482411wrb; Fri, 11 Aug 2023 09:52:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgiLq4FnfXRSzE15R3/r0Hlo7COgJQtUsirbGIzWFqU99CQLNTGl13f0LKKUAMX8lEvqcV X-Received: by 2002:a05:620a:4086:b0:765:874f:bd78 with SMTP id f6-20020a05620a408600b00765874fbd78mr3530883qko.0.1691772768930; Fri, 11 Aug 2023 09:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772768; cv=none; d=google.com; s=arc-20160816; b=RMJURmFUQb88gldr7wtbbWhdxOeHTw+UwFFWg85o9PeV1R7dKKfQTZ184GqTzVVziT OtFERfkeRhiSbg4+N7aDXS6Wi/PNGOrh9Ucgj26upLYhEmA+ZIoSuzjfTIHFpXbmVKmW vJEbG+4mlqQsMUTThjD0AolvJBp2TmgGUH4THtfexMQyr0YSzMKgZ23Yes98/c+koMZ2 pSImrTTPEcbXUYkMWrBWZwvnR0VG2IyGNc7J9fBzBsN3Cmnl0mnIAU58/ap+5Al2wjrc rptvLjCe50rr8w1D9furkLWs3lkvYYPjY3dISi1+BCd2xFseDuTBIbs1s1mx/b1mFMDt ZgnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LeSYXr+bc8SsOHvJZBnPAwsYjoUmfsivAadtLDdjJ34=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=F07iDZdK10wH3xH1U8uAHzIk3DuTGP+eKQxP591UDSx7soMI193HhjQHaV+d6d6Z9h z5FkeXkqZ9sCwv+euQV4/n6rRH/RmZyN6QOPHl8Bwn/ICC7NTwNZInd9sDFvOYGoPE+N NhJ+emSmWEIvRY0mn6Bs9m6cMhQ81ox+dHA1u2DQccxK82o5rBq8Zg08UvpbZZevluhM gdQ1ZYJdrP0im92r6ruFvw5tHkafvJGu/VfpXDa96V0WRAqGFwUveIsfhc01WYu6R4UV ZgpW3xWwGBa45geala0hFLvf+PuxU1ubT24SljktDMLdUDh/cKK4O5hF+TnefIcUY7o3 jQ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ghqEZQkD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay15-20020a05620a178f00b007683dbaa557si2610319qkb.445.2023.08.11.09.52.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ghqEZQkD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVM5-0005rj-G6; Fri, 11 Aug 2023 12:51:17 -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 1qUVLx-0005mY-Aw for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:09 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLv-0001OM-7D for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:09 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6bb07d274feso2104583a34.0 for ; Fri, 11 Aug 2023 09:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772666; x=1692377466; 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=LeSYXr+bc8SsOHvJZBnPAwsYjoUmfsivAadtLDdjJ34=; b=ghqEZQkDG6Z6eyu/ZzCtqcRHbl7o9+zRqGNUANkfeMdSeaZ3/Y1Q42pBXgh78358vH xfLugqW9gidTqi0wM6cnfxYtDEO1ZR2QWbzHcZovc6DFEywTaWv8qbHD3D2Ky8mqk9oM CehoIZ3o2AJmg0nI0rd//LDsM8wrEU9r3wxyTHdVQCzU3ksYMR2nfgHXQwde4xpOeYm+ YprCzUF3nbx5GsyZZ8ksy1wYt04NBga+lP1sjLzXrn1r6YLMFUYAznjPWSn6iArvSzYh Jn5xvpxiKl/JgD9aud/n5/i2jLV6BpyzanBY+Auujda7Kzab8zbfPJ7YV83QM0bNtICF oxJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772666; x=1692377466; 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=LeSYXr+bc8SsOHvJZBnPAwsYjoUmfsivAadtLDdjJ34=; b=NaE4eh/ew+G0EDjA90Sc1oyCTt7mal9aUT2EmDi7tLjCqCXRdFdMHvF+DaHE2WTNxR imfk4oYX5OeULuVNgZEi0ebu8Z7mq0S6rgnzJlbj29l0jSwN4XslohNez0P1TOG3PCUL Lzg1kXVQ/lKCoGv/yl/WHJlE6UqqWk6C8fwXI2f3lrICAQkhPzFpxLAwS2auFIfjivt3 gtWbekvmqtejRLwCbpusWfGNiD4gVDiZOmguqaL5Cl2vcPGyDvaXIZuR+W39KY20rom/ k6n8AqF6P3zmTnKs2sbAEO45HCUv7KIWULy62MEg1ISbH/CErEobKaWO8BHlQg2ZAUNg AtnA== X-Gm-Message-State: AOJu0YzBZgyHdvYmgQFFeyjEIExhTpDnqo2Eq+aA9rfMV56F0arBDYJc vQLFQ4cWzWXAijozt4e6wUrNPopiamH1Hc2TSZY= X-Received: by 2002:a05:6830:1683:b0:6bc:8cd2:dd9c with SMTP id k3-20020a056830168300b006bc8cd2dd9cmr2446809otr.36.1691772666035; Fri, 11 Aug 2023 09:51:06 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 13/15] linux-user/i386: Add vdso and use it for sigreturn Date: Fri, 11 Aug 2023 09:50:50 -0700 Message-Id: <20230811165052.161080-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 16 ++- linux-user/i386/Makefile.vdso | 5 + linux-user/i386/meson.build | 7 ++ linux-user/i386/vdso.S | 181 ++++++++++++++++++++++++++++++++++ linux-user/i386/vdso.ld | 76 ++++++++++++++ linux-user/i386/vdso.so | Bin 0 -> 5528 bytes 6 files changed, 283 insertions(+), 2 deletions(-) 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 GIT binary patch literal 5528 zcmeHLO=w(I6u!?lZ6;}xHc@OPQ7nWSTODdiBWh`;>7-3D37S}}P=~aQ+3gW3qiq6D_w}pazJn)trQdlacNz+s*rT0#_zlDoyki(g5XMcCpkI4 z_uTu=y%+M`Q={Vt4Z~1ErZSbbHY+sL`>(zkTq`Dxz7~|xI&k;!SYBd<3 zfps2poI+ixPo3;SkddbC2Ozd0Nw^A|EcIWy?WUUsoC(Cp5~o}Wa6fc%F#Zs16MSg$ zh`QbL;c$Y0=5G?4Lj=RXCS9x z<5!RW3R0+B{l0P@MghS#NY>{uFk#DlS0x#e`CJ!!p!XQE9W2BiaZj1UJzx*{J*>_3 zkQk$nd92a)Y;;>Z+EYcydsD9A-{$poqJHFZe+oie7 zk9>NdxBy*Q){I>)+Ig$u%sZ)MJ`YbN?UbxkzLc7=GPdjH3U*89(BOUUvh9e^A6Yt) zPR@(ZFXhkZgyr0W=zT3oo=mYbNlDys->hA0pro?2A7~`#8_G8SK{Wf~d7viwF7iyzY z#~@6|Hz2n_)*yF6egZiRS%;j4yakzp+>GL!k7T?(rHpr@M(@T*qy|5Zi?>D`4DK(9 zxx2s%@ab_Q?IypC`WW~^3;%KW&$jT-!GEfSe-Zw7;OG3xuh08W!WyS#k@1>QjhtS0 zX8qZ=bJ6$O&v#&QuHz~2ix}U{0V7>|4|V;_7KRjdAnZWcfv^K%2f_}79SA!RcHn>C zft%H@FaES}tUt0a-XE>EmiTiY zE%_e*^+98Qx`=&9#M&gHArdh;$<&AvIHhUpR|JjGy|{-+1%sO&(ow|dUff5Z1g0R< zN3MycP2>sEV1n@t8f)=wf@ENQI>XN=@_p0`>A%FrPf){nPDw2N9Apr?PcZHi^IwG? z#NGwiL2Q2-b`aZNfgQx=>~aw6H(&>`zOoXpP41sKd;k~~?;qCan00V!|HP;@mY8b7 z(4kcTdoPM!gMtOX?pe)W19-v5lOHJI076?5hbZt`_Vx9rKRXvLCi zt5|xzm@MQ{T0yRgWs0-0Y|_bk9=GgyDt6h)m5OT&E3IO7);dv67HlhE z`ucCF7m38!Jf=MBWWl6R{Zp*eHt0ODJS)NXFL_ttG2@Bd0R}|X^>{bP*I_dcs;bCVL_6~7+u9{FMT zWL}OZzYOME8Fk)C@+;7#2V5KJIGDAWCyVABLXua6L-Kfs$-hVvq~!7KfO)#FY!o=S zpYk123mKYRP*5h!#cgeRwRZDn0xIx7ysmC{kU|yp~sgsffDS3Yb$_a-e literal 0 HcmV?d00001 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e389295b8d..486f5c4982 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -309,12 +309,24 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en (*regs)[15] = tswapreg(env->regs[R_ESP]); (*regs)[16] = 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 1 +#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); + +#include "vdso.c.inc" + +#define vdso_image_info() &vdso_image_info + +#endif /* TARGET_X86_64 */ #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 -#endif +#endif /* TARGET_I386 */ #ifdef TARGET_ARM diff --git a/linux-user/i386/Makefile.vdso b/linux-user/i386/Makefile.vdso new file mode 100644 index 0000000000..42cfc1974b --- /dev/null +++ b/linux-user/i386/Makefile.vdso @@ -0,0 +1,5 @@ +CROSS_CC ?= $(CC) + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -m32 -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=sha1 \ + -Wl,-h,linux-gate.so.1 -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/i386/meson.build b/linux-user/i386/meson.build index ee523019a5..b729d73686 100644 --- a/linux-user/i386/meson.build +++ b/linux-user/i386/meson.build @@ -3,3 +3,10 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so', extra_args: ['-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_I386', if_true: gen) diff --git a/linux-user/i386/vdso.S b/linux-user/i386/vdso.S new file mode 100644 index 0000000000..009f40696e --- /dev/null +++ b/linux-user/i386/vdso.S @@ -0,0 +1,181 @@ +/* + * i386 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +__kernel_vsyscall: + .cfi_startproc + int $0x80 + ret + .cfi_endproc + + .globl __kernel_vsyscall + .type __kernel_vsyscall, @function + .size __kernel_vsyscall, . - __kernel_vsyscall + +/* + * int __vdso_clock_gettime(clockid_t clock, struct old_timespec32 *ts); + */ + .cfi_startproc +__vdso_clock_gettime: + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $__NR_clock_gettime, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .size __vdso_clock_gettime, . - __vdso_clock_gettime + +/* + * int __vdso_clock_gettime64(clockid_t clock, struct timespec *ts); + */ + .cfi_startproc +__vdso_clock_gettime64: + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $__NR_clock_gettime64, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc + + .globl __vdso_clock_gettime64 + .type __vdso_clock_gettime64, @function + .size __vdso_clock_gettime64, . - __vdso_clock_gettime64 + +/* + * int __vdso_clock_getres(clockid_t clock, struct old_timespec32 *res); + */ + .cfi_startproc +__vdso_clock_getres: + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $__NR_clock_getres, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc + + .globl __vdso_clock_getres + .type __vdso_clock_getres, @function + .size __vdso_clock_getres, . - __vdso_clock_getres + +/* + * int __vdso_gettimeofday(struct old_timeval *tv, struct timezone *tz); + */ + .cfi_startproc +__vdso_gettimeofday: + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $__NR_gettimeofday, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .size __vdso_gettimeofday, . - __vdso_gettimeofday + +/* + * old_time_t __vdso_time(old_time_t *t); + */ + .cfi_startproc +__vdso_time: + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov $__NR_time, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc + + .globl __vdso_time + .type __vdso_time, @function + .size __vdso_time, . - __vdso_time + + /* + * While this frame is marked as a signal frame, that only applies + * to how this 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 start. + */ + + .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 several contexts we have for signal unwinding. + * This is far simpler than the DW_CFA_expression form that + * the kernel uses, and is equally correct. + */ +#define IA32_SIGCONTEXT_cfa 60 +#define IA32_RT_SIGFRAME_sigcontext 164 + + .cfi_def_cfa %esp, IA32_SIGCONTEXT_cfa + 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 + + nop +__kernel_sigreturn: + popl %eax /* pop sig */ + .cfi_adjust_cfa_offset -4 + movl $__NR_sigreturn, %eax + int $0x80 + + .globl __kernel_sigreturn + .type __kernel_sigreturn, @function + .size __kernel_sigreturn, . - __kernel_sigreturn + + .cfi_adjust_cfa_offset IA32_RT_SIGFRAME_sigcontext - 4 + nop +__kernel_rt_sigreturn: + movl $__NR_rt_sigreturn, %eax + int $0x80 + + .globl __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, @function + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + .cfi_endproc + +/* + * ??? Perhaps 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..b16e5c31bd --- /dev/null +++ b/linux-user/i386/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2021 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; + }; + + LINUX_2.5 { + global: + __kernel_vsyscall; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0x90909090 +} diff --git a/linux-user/i386/vdso.so b/linux-user/i386/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..977ac01f5a2f06660560ee05d582b4804d842c59 From patchwork Fri Aug 11 16:50:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712607 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482341wrb; Fri, 11 Aug 2023 09:52:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXa0RKKwzBv6X/9AHbRoVNHqYkji90XPtMKKaSf+cwS8rV6xUuHzKSwZAIaRKE4BhQ9qS8 X-Received: by 2002:ac8:4e89:0:b0:400:aaaf:cf0b with SMTP id 9-20020ac84e89000000b00400aaafcf0bmr3306586qtp.4.1691772758295; Fri, 11 Aug 2023 09:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772758; cv=none; d=google.com; s=arc-20160816; b=X2PZ6+Km7hI7gEHK97uRpr5UAWw14akACTJLo146M8a9LmAKJ2z+YNWwPtWoanU0Pp txTImzWbLHoA2+15saZD3BaTwFyLHNu0N7EV6CREBdALfn7z2oaFaaEFup/1R3IhEF/H GC80JeVRrnEZ+Q2D36pPvlHSVTN/kAcAPpXWvkwWu6WsgbIIKhdBJ92UuQmIh/5UrBtl bK7tojR4iZ/aEcxIxHHQhKrP4r/JR8pmKjrl+xbMQiKFSOVBSnRFwowzGBdte7klMY/U XcIYN8bP4exgHnRZMwFH7dEreY8diqYqVutpaiWdSMhFAYHuF1kGQ2wvcKrv0lzzJwUe BfeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JlqJ6bsGEq567bXJTbbPy7vJ5t+E2zaO0mIk+zrl1mo=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=pibZjwUj3JGFWCV9rIOevX/8bQE7Dgp/FavXNSkfei5Adth2cfw5Un6u6hxHCwTe78 z6bmLoRcEFQkjoaD5O8mg2GyvI04ypBupyecyIpu6IkpJrCyOFVJSeV92KH7l+ubu5Rx NhZlYpsP5kay0LxkNa3ojvmJQixkBYgvwJ8XTVkYyHaszIBPGe3sZCtz5/JqTOWQg/e0 1RKFf15PrdO3NMSNtKDtVjReWmjtBe9kvX5PQruxWDRXPeC2Z0L4lvT2zbcjPr94Ol/X k5uNPgtQqaGxZ1dJ9i9c+RK6DPj9n6jUMV3ErdqdPTojF7dpZgSlcgjNZOUS2KtZzsUA Z0zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xvHyt3xE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d16-20020a05622a15d000b0040fda6604f6si2385644qty.406.2023.08.11.09.52.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xvHyt3xE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVM5-0005rs-KG; Fri, 11 Aug 2023 12:51:17 -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 1qUVLy-0005ml-RA for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:11 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLw-0001OR-Nt for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:10 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bbf8cb694aso18953185ad.3 for ; Fri, 11 Aug 2023 09:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772667; x=1692377467; 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=JlqJ6bsGEq567bXJTbbPy7vJ5t+E2zaO0mIk+zrl1mo=; b=xvHyt3xErAN30xBmFxZAg4EZ+y2flF7UCeOy8ikdy8OOmxlgh2R8g76wwUj2XlKhut QtZ3Q3Cu991jCKmHcqv15fxeP3pkWxaV9K84p/Tk9T1rX65dJzpLHReu4GWyYmf383eE aKX4dhp1tZEPK3elpNTaPbFBYpZLWqkeX0stQFHMXsfTeR53wAf/1LaOHKbw2yzm7n47 VXtoDd4W3SOMD8EVejP7LDiXJ42dW5WL6Xjj17pqomAdlZsNBfjSjKzI5y3gDdY/UzGM 6Bx0UaiLLeQ/a2BGdV+HSGCnCe7QOitkeG9CVUT60PvvjgV8kGkAEqtdE3ckFLV4Ljgw FB6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772667; x=1692377467; 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=JlqJ6bsGEq567bXJTbbPy7vJ5t+E2zaO0mIk+zrl1mo=; b=EJvJRJGBvcs5N5QNsQeigpmWw/T9nhM8WKQcvCGJnwtQFM2v8YCW4itUVGWsURnyUV VAf3pOtVwZd4d6QsSEBhQx/phSS1UMo/0c+Jxk8rg8vupodWaFlT0Ml0h7CXDJiWTOTY nvnJSeee11eeB1POa6pMqT/70kSnWdGzIC3hO00gfqVr1XYUOMsg4e5RwZVLkkFK/wrK m0KftaUIiV/vpTipMo5Ilboh0Y3rJgTkAZnZvhogoui/dfpKyzqpMhzu8QFWQeiPkW42 JsJThVLRW+DOwE6FG8JgPxT3JpsklWevMqD7xHwcKrdn7POoRG7PdavOYmkrAkDoXCgZ BhVQ== X-Gm-Message-State: AOJu0YxN70nOeE8s1Vm1cLw3ECRYHNGddIHLxYwCPxEYKdoqPUPXEljM d+7ezPkMVP99b0fWNg8ZGTBmzYqIiiGgj0EB/nw= X-Received: by 2002:a17:90a:f310:b0:268:300b:ee82 with SMTP id ca16-20020a17090af31000b00268300bee82mr2037056pjb.19.1691772666903; Fri, 11 Aug 2023 09:51:06 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 14/15] linux-user/x86_64: Add vdso Date: Fri, 11 Aug 2023 09:50:51 -0700 Message-Id: <20230811165052.161080-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 +- linux-user/x86_64/Makefile.vdso | 5 ++ linux-user/x86_64/meson.build | 6 ++ linux-user/x86_64/vdso.S | 122 ++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 74 +++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 6008 bytes 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 linux-user/x86_64/Makefile.vdso create mode 100644 linux-user/x86_64/vdso.S create mode 100644 linux-user/x86_64/vdso.ld create mode 100755 linux-user/x86_64/vdso.so GIT binary patch literal 6008 zcmeHL&1+m$6hD*6bW%;4w2CP4BTB81(jh6O1S%zMlQ_{f#6U1z)R$>ynhDL!#F>{e zBc*~EB_e)+D;LFL*V5(etQ1Pyzn}dkbd%SaAn>;?%6^jWaE{CPr8VHzi>!?3K4UusflWqFHUv?;pbZZ&6ZWm{5Xkw4) zfrjm0$=yWILlj#N?3!KHCQm$N0}{!1DUWs5Z9Ogqn^pzu=Q?Na_*vME*?L?&pnVV` zbRj^L_ia2EcSA{q2we#9K`n7D&&|xsOK11)tzA92?}KkI-@3ef_h>r#@}PF9=L1wETG zIh`vkywwoTJD07LyrtFB(phgg=ld&#+&yGDS0QIAr8C(~ja=A9`d0Be+lpDm?-Z+wzbL+=*rN{qSP{Z;Vz16gtU3@I>`nII-GF1o+-qvXvjR7w zW!2#(l*>CD)|_>?Rpl0y<6Y5aM>-zpc%b8fjt4p(=y;&xfsP0M=N_nktq$l9=(~~X!zSVZ#>=T*XSUb-q`XJpMT%GxnuO|HC6pPiR-sDdK)5Tek=0tH z{-5z4^$}ylBKE7F?JD<0=rbYM#WKOnXyvM@~$7>4~{e z@MqCxR1j%_qZ^NgLeIz;wHbR#s!}WXnbV4XIlw$?#gdGT&`SMDHYoqURF}MymzLYDdfC-RyEm@l%K2m>XCmhNFpKLXa0uIA#t}e zMYq#_QrpM}AU^=%^Gei9-4y1TcrWal$guVz@4)%_ToZ>v_NdaH`6$Hoc*JPW=bt#C zeGsmX_T0yQ?c36v744ZPBjWjhxb^`n@~rjIo_RGQ^Jvt!?XW3WUn4X>-#bL^lk;;P zBJw`S!Li+XKiPX{%w~fBp~L+fEsI*gnrP4W7!kRRu+VShidqTV^Lt1YST3aS@cOi*#pZ>Q2x M_6IFb{!jLQ0P{>E*#H0l literal 0 HcmV?d00001 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 486f5c4982..80587c155e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -317,12 +317,12 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en #define DLINFO_ARCH_ITEMS 1 #define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); +#endif /* TARGET_X86_64 */ + #include "vdso.c.inc" #define vdso_image_info() &vdso_image_info -#endif /* TARGET_X86_64 */ - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.vdso new file mode 100644 index 0000000000..532c9d6964 --- /dev/null +++ b/linux-user/x86_64/Makefile.vdso @@ -0,0 +1,5 @@ +CROSS_CC ?= $(CC) + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=sha1 \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..f6a0015953 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so') +] + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: gen) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..bbd75a79aa --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,122 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .balign 16 + .cfi_startproc +__vdso_clock_gettime: + mov $__NR_clock_gettime, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_gettime, . - __vdso_clock_gettime + +clock_gettime = __vdso_clock_gettime + .weak clock_gettime + + .globl __vdso_clock_getres + .type __vdso_clock_getres, @function + .balign 16 + .cfi_startproc +__vdso_clock_getres: + mov $__NR_clock_getres, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_getres, . - __vdso_clock_getres + +clock_getres = __vdso_clock_getres + .weak clock_getres + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .balign 16 + .cfi_startproc +__vdso_gettimeofday: + mov $__NR_gettimeofday, %eax + syscall + ret + .cfi_endproc + .size __vdso_gettimeofday, . - __vdso_gettimeofday + +gettimeofday = __vdso_gettimeofday + .weak gettimeofday + + + .globl __vdso_time + .type __vdso_time, @function + .balign 16 + .cfi_startproc +__vdso_time: + mov $__NR_time, %eax + syscall + ret + .cfi_endproc + .size __vdso_time, . - __vdso_time + +time = __vdso_time + .weak time + + + .globl __vdso_getcpu + .type __vdso_getcpu, @function + .balign 16 + .cfi_startproc +__vdso_getcpu: + /* + * ??? There is no syscall number for this allocated on x64. + * We can handle this several ways: + * + * (1) Invent a syscall number for use within qemu. + * It should be easy enough to pick a number that + * is well out of the way of the kernel numbers. + * + * (2) Force the emulated cpu to support the rdtscp insn, + * and initialize the TSC_AUX value the appropriate value. + * + * (3) Pretend that we're always running on cpu 0. + * + * This last is the one that's implemented here, with the + * tiny bit of extra code to support rdtscp in place. + */ + xor %ecx, %ecx /* rdtscp w/ tsc_aux = 0 */ + + /* if (cpu != NULL) *cpu = (ecx & 0xfff); */ + test %rdi, %rdi + jz 1f + mov %ecx, %eax + and $0xfff, %eax + mov %eax, (%rdi) + + /* if (node != NULL) *node = (ecx >> 12); */ +1: test %rsi, %rsi + jz 2f + shr $12, %ecx + mov %ecx, (%rsi) + +2: xor %eax, %eax + ret + .cfi_endproc + .size __vdso_getcpu, . - __vdso_getcpu + +getcpu = __vdso_getcpu + .weak getcpu + +/* + * ??? Perhaps add elf notes. E.g. + * + * #include + * ELFNOTE_START(Linux, 0, "a") + * .long LINUX_VERSION_CODE + * ELFNOTE_END + * + * but what version number would we set for QEMU? + */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..6630193079 --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + clock_gettime; + __vdso_clock_gettime; + gettimeofday; + __vdso_gettimeofday; + getcpu; + __vdso_getcpu; + time; + __vdso_time; + clock_getres; + __vdso_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0x90909090 +} diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..0397ef0f4f3c1e7006146a1113d49ba93b7f5042 From patchwork Fri Aug 11 16:50:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712602 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482124wrb; Fri, 11 Aug 2023 09:52:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/hqnU/BQEB3sjmx0rs62IzLETeWxzmdHXjQsJxu+brsjS8uvNSeDd5WC6MtlAxx4n/21v X-Received: by 2002:a9d:6a88:0:b0:6bc:e39c:f531 with SMTP id l8-20020a9d6a88000000b006bce39cf531mr2303097otq.22.1691772729496; Fri, 11 Aug 2023 09:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772729; cv=none; d=google.com; s=arc-20160816; b=JCjsLHCzttdg2OtNjkDy0m7ZxMPlmlzZu9AYuIRLvdNZwA/9CY8RKjW9lSQGE5Do5D bcYwQKCVhNKDU46Trip7jPUPSoTY+RHjkVRgCf/amD6R6xZcZfsB5RYiZTTM+QFH6cCQ Mq2wlXduc286PxBjcaM1OgpBbCCx/lA2HzOkQLkGWl4WNpnmNfa3K0PqthKKW2NQTPi0 +LVWfKT00loczwkrhoenQyqZ4olEtkAyYbgLneLSGfBnminzDq9EE8+mmiYzN899q7IC cmcXya2fRsr40Z3fpGcTlXbI71TfT22MdSNVIqrtcMTrty+nbeqwhV/rJS2QtLUAodyD WvRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TxKF4Ur/LhoNt0quHqHpwLbIjtXq12D6XbBnMhCqN/I=; fh=1OYPYObfZgrrVkY6LqJEmJVCCPQmahTALyAweBWp8LI=; b=HutnIQHoNONSeGTLoh5uOAqWGQQf81CSWfqOgo6wFZx0Q67j6kBvaa9OiTCuc3fXBk XepkJXuDeH/Km8ttGPm6RVu+FPquKWP8vLX9WIrn5ThqJ5LWuuH9Sldpn3w1JlOknE3g YBVbFJEwcRFlCKD9lnhf3HgxppuPvEx7MKdMTtisPc/C5s4yiv02ppnGfUF+tJWg82XT bOpS6q704WL7klkuDvBIDKHKh55I79WqvJZLLOCJKXMjGSk15Qhxzz4SMFd+M4nxATPd eUPjZXqmxqnU/rtTy2SHbws/pN5w4qySDhyoxpplz6ob77rDrU+SNWgdbOKxxXw0HjhJ 12yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FerguKhe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d10-20020a05620a204a00b0076ceb5934f9si2373688qka.23.2023.08.11.09.52.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FerguKhe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUVM3-0005rN-Rc; Fri, 11 Aug 2023 12:51:15 -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 1qUVM0-0005n5-Ki for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:13 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLx-0001OZ-IA for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:51:12 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5650ec45a7cso1429880a12.3 for ; Fri, 11 Aug 2023 09:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772668; x=1692377468; 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=TxKF4Ur/LhoNt0quHqHpwLbIjtXq12D6XbBnMhCqN/I=; b=FerguKheEoWEZB1j3bArXG+rx8EZBsZvZFtuMB9Z/UyCQWIrJo5R9TakcQVu5D1vOm zHdJmQ1oazm49zFF8AqIeku7m9w4rWEXij5h9irdZXSJqOYlA9gQdSjhGmbFCJdDb2ar x55o8ONAhGuiudJcT7e3pFU+Ewu/p6ySqGNaerWAa8lGfGQmmdC0N60fDjFNWWoJuke/ Yf/ndgGmQ1nAZQDt+kQmQTKa8vabtijlOywhWa1vbfj9gY6LOEycsHHuiXhqK1KQ30A4 LguCG2FaFnSLVGjXtZP8gZkxyQyWL0eS7HGdhyDAOAXRkjbah/gizAlyu8gevNuEuSv6 eqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772668; x=1692377468; 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=TxKF4Ur/LhoNt0quHqHpwLbIjtXq12D6XbBnMhCqN/I=; b=JeMRqONvK/Sv3vKdug7VM+Jvw7Z+DO0zLagLYYMNPcb8VZcYxpYswmzpw/LwPaTzuE DZSSwJC8gMOrz/6CBoxHkBjubL1jTIlp/RjY2On/aa/guS/gRe6wXnqrGsM0joPE1ExH nRpHUvVSiks9JFVIt6WUpP2n4dhR9+OXsvzHvykTJUvkEiQmZRZ64yvLwPUOR4JMIS8F AJtM6k4ZTly+hVKkpx/G8eYU1B3/T++vSr4TFzgkESUq6u45d/sxMsSURjT+ebP0KFvU 0V5pUS4I0ZrlmibBhXYyfeOcxuzMz5MR4YPNod6p/xnIDEu3pYqTe7hZp8VnJ8q0zDCG HFzg== X-Gm-Message-State: AOJu0YyNpPeuop5rN0P8Wee/fwXDnj2JMGdu8KSXpV8WjZMGKZGIpiie zD5xI8Ld/7j57W86Camk7465GgagFEt/2wcZdbA= X-Received: by 2002:a17:90a:f00a:b0:267:f094:afcf with SMTP id bt10-20020a17090af00a00b00267f094afcfmr1687852pjb.12.1691772667800; Fri, 11 Aug 2023 09:51:07 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:51:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH v3 15/15] linux-user/riscv: Add vdso and use it for sigreturn Date: Fri, 11 Aug 2023 09:50:52 -0700 Message-Id: <20230811165052.161080-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in those files for now. This fixes a bug wrt libgcc fallback unwinding. It expects the stack pointer to point to the siginfo_t, whereas we had inexplicably placed our private signal trampoline at the start of the signal frame instead of the end. Now moot because we have removed it from the stack frame entirely. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 + linux-user/meson.build | 1 + linux-user/riscv/Makefile.vdso | 11 ++ linux-user/riscv/meson.build | 9 ++ linux-user/riscv/vdso-32.so | Bin 0 -> 5624 bytes linux-user/riscv/vdso-64.so | Bin 0 -> 6120 bytes linux-user/riscv/vdso.S | 207 +++++++++++++++++++++++++++++++++ linux-user/riscv/vdso.ld | 76 ++++++++++++ 8 files changed, 308 insertions(+) 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/elfload.c b/linux-user/elfload.c index 80587c155e..6a943a74d8 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1752,8 +1752,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, #ifdef TARGET_RISCV32 #define ELF_CLASS ELFCLASS32 +#include "vdso-32.c.inc" #else #define ELF_CLASS ELFCLASS64 +#include "vdso-64.c.inc" #endif #define ELF_HWCAP get_elf_hwcap() @@ -1770,6 +1772,8 @@ static uint32_t get_elf_hwcap(void) #undef MISA_BIT } +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/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..de55a0b9f9 --- /dev/null +++ b/linux-user/riscv/Makefile.vdso @@ -0,0 +1,11 @@ +CROSS_CC ?= riscv64-linux-gnu-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both -Wl,--build-id=sha1 + +all: vdso-64.so vdso-32.so + +vdso-64.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mabi=lp64d -march=rv64g -fpic -o $@ vdso.S + +vdso-32.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mabi=ilp32d -march=rv32g -fpic -o $@ vdso.S diff --git a/linux-user/riscv/meson.build b/linux-user/riscv/meson.build new file mode 100644 index 0000000000..475b816da1 --- /dev/null +++ b/linux-user/riscv/meson.build @@ -0,0 +1,9 @@ +gen32 = [ + gen_vdso.process('vdso-32.so', extra_args: ['-r', '__vdso_rt_sigreturn']), +] +gen64 = [ + gen_vdso.process('vdso-64.so', extra_args: ['-r', '__vdso_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_RISCV32', if_true: gen32) +linux_user_ss.add(when: 'TARGET_RISCV64', if_true: gen64) diff --git a/linux-user/riscv/vdso-32.so b/linux-user/riscv/vdso-32.so new file mode 100755 index 0000000000000000000000000000000000000000..0925aae9f50145bab6ef5d1da4a58c2dcb2ebec3 GIT binary patch literal 5624 zcmeHLU2KzO6n?*!!WeAqFi>z)fq_hvy5SI%iTmpqP{uMgord_ewB0)0I&3>K$iiEN z5Ml@{LJT3q3?zgYLl!ke4N(&lHR=r!6R(UnMz4$p{7D4n^L$_5(jg{Zc;Q9Q_Uydp z=RNP=`Ielc1Ho3yvXmjOx}qGZOsP63N6M9&241HYsp+a(m8m)4u8nr$qb%r0+>8bR zwB6@|^AI2xpJU=27y&m&_JA!w5QF282@}8L`*ifU7rHF!VIz#4{AwPSVoc=Q=RwAF zwV}ORUAq4JCtn`kJbAhA>*jA0=U=GFT>7pQwsdw*3pVuYjme==aPILUIL|VHJr;u> z0cHU_&J2K5K2Ya3Nr8D;u8clmk6#I_?f@ycU|CeOY%xOm~~&58Q?pPpDgu_LBzdsj3y zWcS6=>HfjkP;WH6+vp+#Ly_l=_+;8n_4g%X z>EUET4fH35M^+a8~4}U6Q&Q$`;D-z$zgTKT2 zhho}D=6$RR@4B^+c`tE1UI+MR;BoM8z(>J<1Rn$c1N;oQDsgiX&*PAHPp7g*Evur$ zqZoeyPzGP-hUzF?6h)HLw+85e9={Gz*8+6iqT{@dTXX}^1)($feibqaYj4Bi4OYc$ z&$!3epv2lMo>B4ck!d61+a=S}G9xKPJ7s1Ni7eb&{B6? z%j#FPJaSCSnpd=}9nTQ%N|IK!$h10CiPCXUe^ zEebhtZ_1fsu481zGvlL06GgQB6Xj|Rr;>8}1@!eg6{TAXxw6*@(ZIqI#5$S8x}M~9 zI}eKWy(_yFEbDw%cB^_*uY0rAPRI?5`K*53euV4Ku7FaPb9QzIKr9kKUQ`II{a8Db zEY#tgF_E=XUJ9B04VQ}58Vt<-Y2RW@;H=|Wo8{N(tjo9_^{neN;2FrQO(-7*&#(JW zL(cCLT!0+P^H+Au)9sC0Ha07}qjPI>pryMrV59im+_)iNcQrNz12$@CbW`j=o88*k zxFuk>wR9?bLvU+TW6<8(+PW>!WgPR0=4=UnySn>!W&PA@eM)7Xjg%|=^J@H@j%@;^ z{Hfi8>F^HlbkgNe7dx z?ze33i{Ba10Nt&AO<5hxPM?k6Ap2{ExF^ykU@{wz-z6~@IunociKhV5a|^*pa4-4i zg{XP~#^#*-z9K}2%-Q*L#*g1OanNiEHsiN9>*xF@;e`U{zzk7EGO=6d8A literal 0 HcmV?d00001 diff --git a/linux-user/riscv/vdso-64.so b/linux-user/riscv/vdso-64.so new file mode 100755 index 0000000000000000000000000000000000000000..75fe1db977ee1de538963a062e4da7c337ec6a54 GIT binary patch literal 6120 zcmeHLU2GIp6u!Gdp|l0|6i~3JMNzQA+9C+b-?Vhgk4xK>5^G{IU3RzK#&%0~r=*zX zP9OT936Um1LW~do5aWZ1O*94*6Y(cX&=_KjA;uUq{xrsrsz{7M>Nzv#EVI)Z6JLCA zPnrGh{mwb}+&OdaFy}h4cuP1GQX+=>Rk^*0$C#{`T6MEm);y$x%|bQ*{w@Id}j5;!L+ih!>RnB z)tk2MzJc^$PbzUlxMcre@^R73Aam)waOj*oG$g&A{-J!v>Pse)nZocn+sgO#=F;|1 zF01) zoF6JkM?%k&BvfN;p}kGHxrCdf6LAVLgQ#$mj37i1#}R80Pb02DJj?r@AD1$o=un}N zP^e}>*nK6@J{iMtWc`rcTD(RBoQd2>fTKAK2RNFKjhw8nIUFD3?#IApsHQ4B5iT_5;4KHL&p5F7bqAJA zII#2;2X1=Vftyb|ucDMJI&k}#1GS?Lth}z_j%yn3 z{6oX4-!Mv<%_)5e2 zFE!l%g@z3mHEjG`!vmjb*z~D}%@;I0_=$#xKGv}1yoRmkG;I4o!}j+z?08pWPAIQc zn2T=Q9Fl9KN>a)|DFdYplrm7tKq&*I4E%31aJ+oHB9C|9JE|0w_{Ym5^NRbmf&OTb z{bDREZum}=lkY!?f#2Fv5BqHm{0f(PrkFRB)Tzb%%({*A2A&W|9b9aWU-44>_!I_K zIp(Zy4E)g#;quv6BP56s#^*$pTh9fmqOELdkE{uU>@+(-sQWcpkRkp zF3ya*iS5r)f#;Kb*q*IU?LwaF)L`A&&%FB~jcxgc9%VjQk3P+Ou-<)v`C6X8jPnNb z!8%x3&5yP=?%T6dS?wKdJ7diUI${mseFY+ytFzUZvz4&Lm1$8G$|DtuTwgs~;HV^4Dw;nsU?&bD z+Bpw1(#j6nX%$T!$tDK+l5PWS5fgSoMSHVD(M%$r@pwDuF^AK+eBWTUsAHv6G@Y?} za*2Vol}Vwc^i#b3^&)}xL>NPO8Bf?`i&kVs#U&H!i&%l*sy zMQ}4Yp~(2+CwU#r&GFWFSe$A@#VcH zSk0CaU*ZTpf_gf`lfJzF1m*sN`IiawV1wo){=xH9%CBD}Z^F?M_WR5GRPaRLh9&>v zPiFySLTk_!Sy+s8rs5Y-3+In59AOt5ntWq)E(>@`d|7{THb*{wImL +#include + +.macro syscall nr + li a7, \nr + ecall +.endm + + .text + .balign 16 +__vdso_gettimeofday: + .cfi_startproc +#ifdef __NR_gettimeofday + syscall __NR_gettimeofday + ret +#else + /* No gettimeofday, fall back to clock_gettime64. */ + beq a1, zero, 1f + sw zero, 0(a1) /* tz->tz_minuteswest = 0 */ + sw zero, 4(a1) /* tz->tz_dsttime = 0 */ +1: addi sp, sp, -32 + .cfi_adjust_cfa_offset 32 + sw a0, 16(sp) /* save tv */ + mv a0, sp + 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 + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, %function + .size __vdso_gettimeofday, . - __vdso_gettimeofday + + .balign 16 +__vdso_clock_gettime: + .cfi_startproc +#ifdef __NR_clock_gettime + syscall __NR_clock_gettime +#else + syscall __NR_clock_gettime64 +#endif + ret + .cfi_endproc + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, %function + .size __vdso_clock_gettime, . - __vdso_clock_gettime + + .balign 16 +__vdso_clock_getres: + .cfi_startproc +#ifdef __NR_clock_getres + syscall __NR_clock_getres +#else + syscall __NR_clock_getres_time64 +#endif + ret + .cfi_endproc + + .globl __vdso_clock_getres + .type __vdso_clock_getres, %function + .size __vdso_clock_getres, . - __vdso_clock_getres + + .balign 16 +__vdso_getcpu: + .cfi_startproc + syscall __NR_getcpu + ret + .cfi_endproc + + .globl __vdso_getcpu + .type __vdso_getcpu, %function + .size __vdso_getcpu, . - __vdso_getcpu + + .balign 16 +__vdso_flush_icache: + .cfi_startproc + /* qemu does not need to flush the icache */ + li a0, 0 + ret + .cfi_endproc + + .globl __vdso_flush_icache + .type __vdso_flush_icache, %function + .size __vdso_flush_icache, . - __vdso_flush_icache + +/* + * 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 + +#if __riscv_xlen == 32 +# define offsetof_uc_mcontext 0x120 +#else +# define offsetof_uc_mcontext 0x130 +#endif +#define sizeof_reg (__riscv_xlen / 4) +#define sizeof_freg 8 +#define offsetof_freg0 (sizeof_reg * 32) + + .cfi_def_cfa 2, offsetof_uc_mcontext + + /* Return address */ + .cfi_return_column 64 + .cfi_offset 64, 0 /* pc */ + + /* Integer registers */ + .cfi_offset 1, 1 * sizeof_reg /* r1 (ra) */ + .cfi_offset 2, 2 * sizeof_reg /* r2 (sp) */ + .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, sizeof_reg * 8 + .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 /* r31 */ + + .cfi_offset 32, offsetof_freg0 /* f0 */ + .cfi_offset 33, offsetof_freg0 + 1 * sizeof_freg /* f1 */ + .cfi_offset 34, offsetof_freg0 + 2 * sizeof_freg + .cfi_offset 35, offsetof_freg0 + 3 * sizeof_freg + .cfi_offset 36, offsetof_freg0 + 4 * sizeof_freg + .cfi_offset 37, offsetof_freg0 + 5 * sizeof_freg + .cfi_offset 38, offsetof_freg0 + 6 * sizeof_freg + .cfi_offset 39, offsetof_freg0 + 7 * sizeof_freg + .cfi_offset 40, offsetof_freg0 + 8 * sizeof_freg + .cfi_offset 41, offsetof_freg0 + 9 * sizeof_freg + .cfi_offset 42, offsetof_freg0 + 10 * sizeof_freg + .cfi_offset 43, offsetof_freg0 + 11 * sizeof_freg + .cfi_offset 44, offsetof_freg0 + 12 * sizeof_freg + .cfi_offset 45, offsetof_freg0 + 13 * sizeof_freg + .cfi_offset 46, offsetof_freg0 + 14 * sizeof_freg + .cfi_offset 47, offsetof_freg0 + 15 * sizeof_freg + .cfi_offset 48, offsetof_freg0 + 16 * sizeof_freg + .cfi_offset 49, offsetof_freg0 + 17 * sizeof_freg + .cfi_offset 50, offsetof_freg0 + 18 * sizeof_freg + .cfi_offset 51, offsetof_freg0 + 19 * sizeof_freg + .cfi_offset 52, offsetof_freg0 + 20 * sizeof_freg + .cfi_offset 53, offsetof_freg0 + 21 * sizeof_freg + .cfi_offset 54, offsetof_freg0 + 22 * sizeof_freg + .cfi_offset 55, offsetof_freg0 + 23 * sizeof_freg + .cfi_offset 56, offsetof_freg0 + 24 * sizeof_freg + .cfi_offset 57, offsetof_freg0 + 25 * sizeof_freg + .cfi_offset 58, offsetof_freg0 + 26 * sizeof_freg + .cfi_offset 59, offsetof_freg0 + 27 * sizeof_freg + .cfi_offset 60, offsetof_freg0 + 28 * sizeof_freg + .cfi_offset 61, offsetof_freg0 + 29 * sizeof_freg + .cfi_offset 62, offsetof_freg0 + 30 * sizeof_freg + .cfi_offset 63, offsetof_freg0 + 31 * sizeof_freg /* f31 */ + + nop + +__vdso_rt_sigreturn: + syscall __NR_rt_sigreturn + .cfi_endproc + + .globl __vdso_rt_sigreturn + .type __vdso_rt_sigreturn, %function + .size __vdso_rt_sigreturn, . - __vdso_rt_sigreturn diff --git a/linux-user/riscv/vdso.ld b/linux-user/riscv/vdso.ld new file mode 100644 index 0000000000..57f3159415 --- /dev/null +++ b/linux-user/riscv/vdso.ld @@ -0,0 +1,76 @@ +/* + * 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; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * 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) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0xd503201f +}