From patchwork Tue Aug 29 22:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718242 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp239942wrh; Tue, 29 Aug 2023 16:14:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKg67+W3iIKB+nJzWqeLVa0zE5DRgMhmPDGtuLrXrtTFFWWWGVutLyD4d9zea/bA2eFWZe X-Received: by 2002:a05:620a:4484:b0:76c:e9aa:9e09 with SMTP id x4-20020a05620a448400b0076ce9aa9e09mr617497qkp.30.1693350878467; Tue, 29 Aug 2023 16:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350878; cv=none; d=google.com; s=arc-20160816; b=AMVcTbPJf1gW1fE2lh1WU3ZGBCdcGEmMdyOkn7V4kX6znvVzWdJrgzP2mnUrWPk3u7 aWDVWFBJWg3m2TbKNjN3m4wLpAr+CBbva+eEy+LHDPnIjo+m7tsrRwlC0zXRJbGMB9zq 8Ijva28EiW2Iqn2QMXftpn/HxvlCg0ef9OgGVEyPtH7SaZ/yz2ODAddxCgVyr7/ZISQI uFEy3dcppNw2ga5pYt8tGcdGlnxDxcsZSHonGBXJckjNXZ4ouM0jQQZhKbimJDiex8Z0 8t1tl5tmE0JhuJXUSEib7k44K44bXLGNhUb5NrDbgzx7YPa9gmhp+HVuAGV4h53P+Cwi reZw== 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=z20DSFbmc8dhdliPZzapqE4smuEONTK8kCxcYuZWd00=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=G7gaxj3BOglf98vTLq9nxgQtpnGYaQdOSp1pBwhnI1baoyzA9fdB2dD8VCqMPGE/QS zIHrIJIA8R1dh2Xt0kt2WJPzuScHV3EF5AIP2PbdoteGOONkwsHugpi4TrwDGc9Gfc6u rW0ZNJMKNPfCs7krYmV7tYrqeqvOGVhylXD0/Je0/TsSfBGcvZgzj1qh6lv/5DdQqE86 W0J8IFlwzKEkkHpzNRBv3Rn75AYtlY23WbZ4MmAPg8N7eR/txmUtZIxaNHerR7iCfbp5 Wqy9UtyJNuVy9hrRRnib3+4b+cwnSFR8OzQivRXCNaJ7GMgECE71bPY7/9WWkJ1IKqxM JF8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p7hIiG3R; 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 j25-20020a05620a0a5900b0076db5bf13f7si4435017qka.252.2023.08.29.16.14.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:14: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=p7hIiG3R; 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 1qb7mu-0000im-5k; Tue, 29 Aug 2023 19:06:20 -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 1qb6nD-0002N3-AZ for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:35 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nA-00047p-Rd for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:35 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68bed286169so4216879b3a.1 for ; Tue, 29 Aug 2023 15:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346551; x=1693951351; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z20DSFbmc8dhdliPZzapqE4smuEONTK8kCxcYuZWd00=; b=p7hIiG3RnVruTX5Kht1/OUBzJ3kLWpUfH64ZNLc9glN8yAr1tBmczbqcfrZi81rAqK mGljDMpGFVLi+JF4o7yIlZkVtjCYtjrFIL8/BKgbowN3a+F5oOBvZ43VI2bSLQCD4tlJ ngM/muLP3dsQV3hsN2ZQ6r5Pgg1dpi8XHFPuv1aMXctK/TNHVgfmCr0ehb+Xce751s9b N2q5Vdfk2+3jnMeiIzMYWp7QtMh09am1QEE6pA09f+S1YvEtR0of1PORON8Rz8mRmN8p 7P955U6JijHk/+Ir4xSGGiwZ908tMGAZjeUfmyWeC3PwaBJaiWUXaluRwzK474/QYrNA EjxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346551; x=1693951351; 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=z20DSFbmc8dhdliPZzapqE4smuEONTK8kCxcYuZWd00=; b=Pl75UeaQO9SAbXCcGckylcjQvyNnb9h4YsK/MI8P2BLZPcpgM+3pKHSEw++aPZoIjV 186nH4uvFhoWB4yapSLCRkX0BAUVQZ+SXGuWeBWBufCAfRPrtV20eYjWMI3tSZZ/UO8s 3SMJHW1lHYZ24JJbA8F53M9CusoD5ctE1LyVM+bf9rTXTTso2RzETv1gHcOdTU9kpr/n QdMEu3QWJpNIpGrkfeGwI4oails8J6NB0NdPgj1vudVbcQhPlS6a6AlCOwxIKtAd5ig/ U3WTaRgAbzLYA7qx10J+72kBjlrDRY2hLM0sJRwoxdmz85+39E3B52N4yNzfmm+pxzE0 39Nw== X-Gm-Message-State: AOJu0YznazKaeBr4xQDwr5iK7YKsqNp87r9DaB9c4x9PcQwbh9DwvRIm C/wK754Ysao+zRxKhb4fcfpGID8FBJU2RJrMugg= X-Received: by 2002:a05:6a00:21c7:b0:68a:5cf8:dac5 with SMTP id t7-20020a056a0021c700b0068a5cf8dac5mr516153pfj.22.1693346551065; Tue, 29 Aug 2023 15:02:31 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain Date: Tue, 29 Aug 2023 15:02:09 -0700 Message-Id: <20230829220228.928506-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38. See https://github.com/loongson/build-tools Signed-off-by: Richard Henderson Reviewed-by: Song Gao Reviewed-by: Alex Bennée --- tests/docker/dockerfiles/debian-loongarch-cross.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/dockerfiles/debian-loongarch-cross.docker b/tests/docker/dockerfiles/debian-loongarch-cross.docker index 9d957547b5..b4bf265717 100644 --- a/tests/docker/dockerfiles/debian-loongarch-cross.docker +++ b/tests/docker/dockerfiles/debian-loongarch-cross.docker @@ -20,7 +20,7 @@ RUN apt-get update && \ git \ python3-minimal -RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-glibc.tar.xz \ +RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2023.08.08/CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz \ | tar -xJC /opt ENV PATH $PATH:/opt/cross-tools/bin From patchwork Tue Aug 29 22:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718261 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp244125wrh; Tue, 29 Aug 2023 16:27:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmrDljiXzULS6qAihWh02xZnJS2gJOtsI+jQbW+qFwmicQ3N5lVRz+P5Xx6+Q2e1hWoP8l X-Received: by 2002:a0d:ea01:0:b0:589:f5a0:9d7a with SMTP id t1-20020a0dea01000000b00589f5a09d7amr433849ywe.40.1693351651540; Tue, 29 Aug 2023 16:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351651; cv=none; d=google.com; s=arc-20160816; b=cXyEOFKR2aTeMTP25GuBA3r2BZCtPc81YZTQ3xRsTHS7ms0p6WYiatebWMNCjnk3gs aZ8B21wXq5da6qd+sQ7DDiNNCuSg0whjGgnIkODOzWmfRZc99TpyCRR1f+NdAVMwkot+ i9ux0g3GMbWppgBHvuzXRcMnBeY+vjMe9qu6ouku8ur0tuwp0A3GefXJ5Sj9yZHjpt7W cWvZAxFBby1DUxhL9scovuHu/6DhYQn1BY39kXbYYBV6yRO2j1ijsIOar3Xv9JZXs3xf ameqL3WSMkSanPhkCGnjW6smD0F8Dpx+M99v+u3boU73B/x8jy+mzLtOurl1x4Z76bGX t6yQ== 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=ZTp80hQ0gujXFgw4WQRSMNPp9+tNR6xjDomKssEODI0=; fh=cP0QZFg6MuyBR24J0KjrrDlt4joDhDmvpCU8OseFE7U=; b=sd6Lw7oTb07YG2O3LPfuXgOJOE5YHFpHAsoJcH+cfQLUk3iDk1jMrTfrmyAqYnt9Qn yFgUMyy3krrU4qE1oL+SQDo7hBFqcVyTABs2StVh4FAFvvlyNCq1IKISfJh0sPgcCAc6 UwZlTXa2sIe5y9d+QF4Im5PYr2GSt55d4AIAOLumzFmC0Gq57huAlk5n6TDxQrIgt+LD 8Tdi0ecxh0DkIjH/hfmINldxB0LdfTXWtKnxFhuTjfVBn1xGy7zBfo59VHLD2bxTQ8Vg +in4cFZX5bN09BOM46yylqnyrHj2aI+CH5lr19/48t5HAe7vywv4cjavDC+VSG1Ki1tt zEvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pUc7B7C1; 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 o19-20020a0cf4d3000000b0063d220e985csi6670320qvm.242.2023.08.29.16.27.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:27:31 -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=pUc7B7C1; 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 1qb7o7-0002Qe-62; Tue, 29 Aug 2023 19:07:35 -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 1qb6nF-0002NJ-68 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:37 -0400 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nB-00047t-7Z for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:36 -0400 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5712b68dbc0so3061961eaf.1 for ; Tue, 29 Aug 2023 15:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346552; x=1693951352; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZTp80hQ0gujXFgw4WQRSMNPp9+tNR6xjDomKssEODI0=; b=pUc7B7C1j3/4jhV61IgOQoHK5gez7NHAcrx5KvtCkbwdrL+66ueOh5YS81rPnDLGKs UGI11S8m3oXuI2D2BlOlaFRX4qUNnUQEN2bJg5jNcY4pQv2UVa6pEpa6Zo/4RwKxbJqS JOit+e1xMZPvkyRIlGCKGD0sAnp8nVhuip7hNcBaHyHWoqIxJLHrqetRpnBXjsuA669D xkjPJMaEHAnJRclTE69byVoKDpqh+IGZ1pdHiBTYolr2l5UAZV+sV0B/U/22vcghPaq3 yB0pkLTF3FY7E0bKQXNrgaMjLT23LEVRolalsCyXh0rE38lI3SmlObaLHp1Nf8B6+qIO ILLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346552; x=1693951352; 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=ZTp80hQ0gujXFgw4WQRSMNPp9+tNR6xjDomKssEODI0=; b=bTqaIbNX93OnY6IrJfHoW5SUWB7FPpSe90c/p90oLBUCsLooB9VY6cPFthdkoO47i9 BEowA1ZRrLCmKukAi5nrpwHJ/Bdg6jPDqmpH/6/S34Knku40DIcFsiRhRmyV68ztZFq6 Kh6+HPp7P5TJqZvjqIZ1Q03c0KqW+CHY+aulEHhXngarf1swd8gp3Frt3+RLosSZ/Dag /3StYQ5VJG8W1MOtaeQG9G1k9DgKByXXOYK6vfq9dAdWsm7dxiMC63F6qa8rT5oIkNkt 0Ee/cqeluumMxMfaeSLZ/ohn6Y4NzUgkvb2+RFESzVKOKHPcRIlSczqm7iVKvha5MC/z 35Lw== X-Gm-Message-State: AOJu0YzJ6s20vhKs4Ngos71vOpSLP5k8hNx9KVbLRrIwzH9Z9TqsUfMl NVbaxC601VetDV6yVUlphudeO7j+O+JS2YbbHQE= X-Received: by 2002:a05:6808:1789:b0:3a7:49e5:e0da with SMTP id bg9-20020a056808178900b003a749e5e0damr497069oib.26.1693346551935; Tue, 29 Aug 2023 15:02:31 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 02/20] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Tue, 29 Aug 2023 15:02:10 -0700 Message-Id: <20230829220228.928506-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c36; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc36.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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 Tue Aug 29 22:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718249 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp242344wrh; Tue, 29 Aug 2023 16:21:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKVfog722ssSAr79PSMLYyNKujS1klQ+YeimsZfwkJroH/V9BRxBPuZstdFzSmJnDZdixc X-Received: by 2002:a05:620a:4149:b0:76d:93e1:99f4 with SMTP id k9-20020a05620a414900b0076d93e199f4mr590486qko.8.1693351318700; Tue, 29 Aug 2023 16:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351318; cv=none; d=google.com; s=arc-20160816; b=W0lEiQc7dZtLPwrIQpROmRbrEXlkn+3GH7GblbMvKqJHJxukXXDDSnU6b05jnyIbrP A7pgedrXwNMMSohtg5udvvf742oShDzz2T3mOV4Dq0QPFUPDmQZTYTB36NjiSYG6V1cn 4W6O7QhYy7hcF5QPXZYaTVLRYhyBYAhQo+QbwuWg5FN/Y/+vSXUbMjhFrINJTPFKagZ/ bffTvXyhKZjW5lBA4yYyp+ApVA1+jz0+umK0zS4XtwmASpWfvGgq4zsJmy3jcbr4WOar 2JC+cUklARXW6HLJh+M0sVuXFdYsOWmBA2qvQ2m62ZIfl0goFk8/ZyAwZM8zxqAG9Nkf uwBg== 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=CQVgvEA797/6AHlvAuip4Dfdeigp3YyNGto1GCMbIo4=; b=DKewEWzphn6Bh2pbszHC8+cuXRYjjB0U3Ti2S0+VD+KR9+7/BZToxrC55luqCzdKDZ RNBB17JF7MPygI7GZBrUVkpytUPf1heRo39DA9mFmG5prMCP9cO562ERkRFDLhZmFnRe AOG1vXnEFRrszBmzmWn5fmvcXoniVEYDzpPKZqf/t8j0EwNEmgqTPaHQKLax3vVm0e58 6lnesnt30yvTjakrwmR/HBTEI09/kXTwhl+tNTYviWs/Yb4shpnfV6fnYRKA8FFlUTIO WWHfEGPJR2/8sb45qAmfFgYR593R7x4BAeciJXwhKHhH6UlhZXbd4PX62FQ4zg5oi+b0 oOGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hG3z/rGT"; 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 a7-20020a05620a438700b0076ef0254161si6752492qkp.465.2023.08.29.16.21.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:21:58 -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="hG3z/rGT"; 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 1qb7n5-0000sZ-WB; Tue, 29 Aug 2023 19:06:32 -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 1qb6nE-0002NI-UO for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:37 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nC-000484-3m for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:36 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68bed2c786eso3439161b3a.0 for ; Tue, 29 Aug 2023 15:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346553; x=1693951353; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; b=hG3z/rGTj/ci7t6TQvuaJGHAr6QayQo+7l5XjCD+b/Ie0tKkeJicDt27J/ehvBGh7W hth4a28z7N5omYH14ZH+0HM+V6H/RFUv2mLxdiIfWY0XoTngFXGG3qg2kJvLZNafQ0hb xJDWbq8mBhyLKLtDTZpZrZkTrajVL8TdthXtZZpBCDbuuugRAKsbwCQ0TGIGOjcvh/Bq alRiXFWirF5ghlNgVMcDlL/Ri63i25mIGRWPD74mzWZaBOdFvis+muc1kAey2KK5/Cb/ /0KSUpgtf1eDG0zp21eAPmjij1QPZAVuZCG/Le5bPr0kwQ7OhFMxXaFMM29ovwssXV51 UgzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346553; x=1693951353; 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=LKyMGcdvHTaGIVWu9O4RwWR3nJRCLP1Nb/pni6zU7rhJuH6UmGk3JtChEmbOFhhT+Z C3lbwRGWnfbZ2hoI/0iCqsCS//wdljbR0rgzyJjAqQLz7daZ1MeBG8s976r92ezGLGSB e3az0Tn/5a3MaXoqS1ka1wqkEkFKZ6MT3J5f/fLDiiJr9DWNRN3zb++8FUOYL/SjcO+c oM/4xaNvV8ha9Oc3yQEzZbr9Tq9DCq9q0GRVKE1rCK71o+y6IuTXM6MyudfRhcZ01gfe pSKEVU4zrI8Q25cCNPDCRw5kJkQkAYMR2h09qNFxnoZS4yNHR34N6YjifymNnxjRzPJy uU4g== X-Gm-Message-State: AOJu0YyhhdjJlQQkkijvM/rp+qG8GRhUZJynCTnoXgBAvy1sqm3BYaW/ oEGPyeF0NxA7/0I5CEzKW4ZPZMxzP5IoLx0mhEA= X-Received: by 2002:a05:6a00:170d:b0:68b:e29c:b61 with SMTP id h13-20020a056a00170d00b0068be29c0b61mr447946pfc.19.1693346552720; Tue, 29 Aug 2023 15:02:32 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 03/20] linux-user: Tidy loader_exec Date: Tue, 29 Aug 2023 15:02:11 -0700 Message-Id: <20230829220228.928506-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 Reviewed-by: Alex Bennée --- 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 Tue Aug 29 22:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718251 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp242830wrh; Tue, 29 Aug 2023 16:23:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDGxjMaSkt1+viXqZN8ihNn8hvNn631orPysNU3uKOmsleYbeboTvKYSbeJRB+WZ36RZ5k X-Received: by 2002:a05:620a:669:b0:76c:fc7c:ac5e with SMTP id a9-20020a05620a066900b0076cfc7cac5emr427161qkh.74.1693351409095; Tue, 29 Aug 2023 16:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351409; cv=none; d=google.com; s=arc-20160816; b=rt1DNXRy+VzOJ18P9JDRDLqTbky0jHK8UQvfsbcmsHNZ7coLJN/Cj0u+WeeIwnrMPU DuXqv6GwpS/GvSMDAqp6jlPw0uc6C0BCPEzixSXDU5TVPYEbtAcceD3uYY6vihtFT78D UYoY132r7cZLM3HuYOLWWe+gOeTSKLKJR78V69qTNXB/afT1IiTYaa3gb/AyHm2OPdS0 uDuBD9GDL/W7INy50EGjYa/fMs1u7xz033sBam7jBqKEfN8zoTSfg4q7x0UhNvtVaVLn gc7bmwzZWNfJ8EyO1LfZ3u7r68gfcJRXpWIn7C/uUfOpRDLx5PFVH77BtQMKpfAP2aar egWw== 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=YtpDBOXKHVSEIF4Yn08bUEAK6iy270wE2qCEwjH4NwE=; fh=CQVgvEA797/6AHlvAuip4Dfdeigp3YyNGto1GCMbIo4=; b=LFgbELYKmTtufiOdXK23C+cr5UY58x+dMpfRMUG+jJEKPPhKuHP38NCxMxbtvefjI8 rM6Ck3u+5SdDzotjnlahczFkpTBu5pQ8CXlZdb4ULx/g/ezwRpXkoMDqDNnJfB+HwrX4 PYCuaKlRvna2kF2Bw9hnEwHgg3cwX9XwJDalZ8ezZTupsSF+p2wa2+kMc5jgAxC5mTOm 37+4MJ2/4X+oaHgvnRFII6+PrLE/bu3gTWXEA3U8EOOQyv9cvTEsB3M0ii+5r0wiIaRy eP23LlRPENWVwmIo+XVt79jB4LVHOJNz4psLn7tCNlmYc+DPEABtnNYezRlvOh99i076 +WYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JqA3/s/W"; 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 u10-20020ac858ca000000b004055a1ea5b7si6642894qta.190.2023.08.29.16.23.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:23:29 -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="JqA3/s/W"; 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 1qb7mu-0000jI-Qg; Tue, 29 Aug 2023 19:06:20 -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 1qb6nF-0002NK-Bs for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:37 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nC-000489-So for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:37 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-68a42d06d02so3440244b3a.0 for ; Tue, 29 Aug 2023 15:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346553; x=1693951353; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YtpDBOXKHVSEIF4Yn08bUEAK6iy270wE2qCEwjH4NwE=; b=JqA3/s/W4ZhFfGgUhnqLP3oTJLjjQIsYIod0ZjJxffTbSXAd3QPFivcun7uTzeBXNx B5BOaJWB2M2U9TWK+EHukqZdPpo3gX4RkMjjZuBIiDDNAyxXTdO15q2URRFNiTNI50T7 D5iFcbFd03gRgADNsYABMi0XsSQpVmcj7r9jYNGrTPb2LQBApbZUxKKc7tCE6O0v8PE8 8J9wZqDw5HgjoaLGBhw6ek4HgflGjmmbUxD5qQf9DQutcOy9Lmuh4aZ1lv5wpcBIzaVw pTG1IikIqrMLpCQ1jOACQNyVsYmhbRmQbni/b67sff5Vt2kbq8Z3RrVNUvRfRIOfsMuo qfVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346553; x=1693951353; 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=YtpDBOXKHVSEIF4Yn08bUEAK6iy270wE2qCEwjH4NwE=; b=S/IynLuVMGSrqPIUpMNyl3HduaIGqOyXVycxIBYLK23niV5oxrPnbugzn3dkWdKU9u xIGaSyvR/I8SNbj28HTnD17ITbLrJX8IZOft7uBINSBwR5mJqNfj5Ccuwr+bxmzzbsjx mZisKm7Ev+QgRmk9h4ov38L311OXhEpza+IPm0O68Rra5zJM7AQHkhLfasabUd4y90bg AY7qQemaRKGIc1vqdkmR0LoHFEfIGqa2FYFNJ+9WKjCXDzXp6HOrHPk6LAWIiu8qN5ot uDwxC77qmXasbeLVHUTpvekfE3xktluevqBOP5/CPYVC/3Mt0iZmLrGVrP6Hnu5TKNvn 9LPA== X-Gm-Message-State: AOJu0YwMcMXGrSXdQFjZbQyGWGxj6TGE2sLehoDnimlqv4hQZfgeoP4L g9H3CXSOBgU8WCOoB7lOxOOQEf6LPDRUX9pB0F4= X-Received: by 2002:a05:6a00:3393:b0:68c:42:d3d7 with SMTP id cm19-20020a056a00339300b0068c0042d3d7mr457649pfb.25.1693346553526; Tue, 29 Aug 2023 15:02:33 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 04/20] linux-user: Do not clobber bprm_buf swapping ehdr Date: Tue, 29 Aug 2023 15:02:12 -0700 Message-Id: <20230829220228.928506-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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 Reviewed-by: Alex Bennée --- 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 92b981c445..4d3b25ed14 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3020,16 +3020,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; @@ -3344,6 +3345,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; @@ -3365,7 +3367,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) @@ -3558,8 +3560,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; @@ -3571,12 +3579,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 */ @@ -3663,7 +3666,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 Tue Aug 29 22:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718253 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp243051wrh; Tue, 29 Aug 2023 16:24:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4XJuP2B96LKoQ/z5K85IRVZjdy7c7Lect0b4t3Vka97fI8ibca6Lx0ZpTMWYPXm4CZuDM X-Received: by 2002:a0c:e391:0:b0:64f:41dc:83ef with SMTP id a17-20020a0ce391000000b0064f41dc83efmr1032376qvl.1.1693351446358; Tue, 29 Aug 2023 16:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351446; cv=none; d=google.com; s=arc-20160816; b=zrnZL5MP/rgJjfxfcCJ3+e0pjL9CXFM1X3VN6RTyfwF2bvyVHmE7M4tLjoX/U9wySC yYoI8IjLm25NRPegjh/1Ud7tJUDHsf3v1vNzAa7fCFE4M/PhR08WZFxtcPs6789KidN3 nGT2AAMOPFliZHmm1uB9xk2yPxdHgzUbApKTnwn2BjWx7xv0iqtRY2riBnsg4xgY09Hr Ikj8DOScR9sG4fYX9IJIn5AnHptgxZDOv5HwWM2otkGCbIrFiVaN6UrYBJI1YZdcc8yj +tttoyEz2XWoKWXT955sLS3nQkA4E+vh1dCgxzW8yrjIqjp6oIGyi0ItHIQSesiz9166 ZDvw== 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=1QSy9ZU0qavvxc/B/Z2XKJEh1HZrVJBfcA9oJSYmMj8=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=pH8ljW2UUQfHD2+Wcj6dUPppQ5YVcVK3QTtll0sunBoYlIZWjdhuEXgEup1equXoqv NufGFfRUwxFck5duzZmcHhqliKY2bB25LgcnUT3usYDDtSuForl3tYGJ2oLd8kAlKupA PMyXPCojQKRF9BLu9kcd227GibuDpE67gjsXn0/Oioc1N3CG7hUgK/a9WbN5WKPl4cpQ 5QEh0/gBn+zQCYNtZc053xlMpzM/0DxR7PxrEWWKqiaKWFyN2CwofbNvJuKhngMlvEjr T5aocbYvJKTYG/UPDNGB0RKyeeSBnqBbUxFlvUb8HDqewAHRzFVPvLRuFL57WbNdprpC CpLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ajxDbsK+; 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 n14-20020a0ce54e000000b00643abc8b25csi6496282qvm.171.2023.08.29.16.24.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:24:06 -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=ajxDbsK+; 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 1qb7oX-0002qd-1O; Tue, 29 Aug 2023 19:08: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 1qb6nH-0002Ng-3O for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:41 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nE-00048Q-7U for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:38 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68a3082c771so202648b3a.0 for ; Tue, 29 Aug 2023 15:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346555; x=1693951355; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1QSy9ZU0qavvxc/B/Z2XKJEh1HZrVJBfcA9oJSYmMj8=; b=ajxDbsK+v+9zNITLyGGUVb3KX/B0Q96RRcAcA6qyK0o9V4TmIH6OBplpkHG+96Plrf CGRiwvgUWcp/4SGtH5o3v204i9JshG7JtPYlZwocJFCv6Q9jQ8MJUOB1UZdw/AJSwYnf JDeP5+wgCEUyq+9BXt4Jlmwfb5yYKxMP4YY2ftMf+cOtWEdhcCv7XSzCtr9oB9uIE8rE Z+coLNhUvGdn3sHkGC7cKokfnv1Ahqn4uLWgeRsdPATGKeRLGn6tjYAUz2BDinwoz6UI dtGmqlmEfSR67ZtN/PuudOExYKhAg2WRassDz4l8otHVNrxHM/B5RHKAR3zpceDufW7C aayw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346555; x=1693951355; 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=1QSy9ZU0qavvxc/B/Z2XKJEh1HZrVJBfcA9oJSYmMj8=; b=Buh/M74ajjsRTvvfHJ1BE0LusDyEpTZtmb0PS92ooIiVkXl8DufCF+i3SgGddT5uJ4 EWr0kD+y71E8yzBGNZpXqzK3Mo6hSOS/LHf9k4AVWfeR6tBojyaQ/OsLTRRK5LiJvA5/ 9j/d2X4d9BV4oHv5MKoZ3eejWuwE2PY6RVPt31dC8hVDxQiqMpm65whVj/IsljUcVpus SVZtc3FSvlkj/80IEuRJ6H/pvW3pTwY+cXTp3ME7qYTI2SJKO2+KxIaSxMTjjq95PmUu uu4q6tqAj6Yo4v5E4sU/atnn4yeazI634fn2NVv+omhm5GUfsFGHgtnptu+aXUJn020U X5EA== X-Gm-Message-State: AOJu0Yzyz5xP8YKnHHEvWBOh0DR2Jg6Ud4ktViGbivsaHtP5QJJ/fia2 NGQ8iNydiFn2rrMvXEmWH2lNWOB+nOCSqSF50iE= X-Received: by 2002:a05:6a20:3d1e:b0:125:3445:8af0 with SMTP id y30-20020a056a203d1e00b0012534458af0mr824205pzi.7.1693346554621; Tue, 29 Aug 2023 15:02:34 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 05/20] linux-user: Use ImageSource in load_elf_image Date: Tue, 29 Aug 2023 15:02:13 -0700 Message-Id: <20230829220228.928506-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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 4d3b25ed14..833c22da25 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2923,10 +2923,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 { @@ -2954,14 +2953,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; } /* @@ -3007,30 +3000,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; @@ -3041,15 +3038,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); @@ -3086,17 +3079,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"); @@ -3104,7 +3090,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) { @@ -3257,9 +3243,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; } @@ -3291,20 +3277,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 @@ -3317,23 +3294,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; @@ -3346,6 +3316,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; @@ -3363,11 +3334,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) @@ -3578,8 +3549,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 Tue Aug 29 22:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718260 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp243833wrh; Tue, 29 Aug 2023 16:26:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl+NB8B9y7tT2FHP5AibkHGeXnGe5DAeeNEj6zlQMxLWqRU9Ci6KD/jO3wHoAcv4QdNx9n X-Received: by 2002:a5b:b46:0:b0:c6f:b843:c502 with SMTP id b6-20020a5b0b46000000b00c6fb843c502mr586953ybr.25.1693351591866; Tue, 29 Aug 2023 16:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351591; cv=none; d=google.com; s=arc-20160816; b=Xja3nK/i376+KvOR2aR3Rwo18Y0ICiSApKEHBc6U/ZP0Bvpt6V4e5R9HaX9YO7xH6l QTFZj2BRQVSkqlvHeqo7+w+OPRdybqo5CfKuYs6R/DB2iio9brkSftYeDJUKl6kI4tZ+ 7tPKJ4I4Hy7XPzMpfAULrKuHzTBijVzm1v+DFqkKH/CT7i3/bahju6HBSG07RbXDRMv/ 1Pee5hFad4gmN7GSE+excT/7c5AqYTy7GdiF7sNnd7BzuWMdrF+C96le677DTAGi+qdN PKeNBg3m7UiOOPe1BEJ5CN1z7WnXliLrrmNoxfyV7lpTzLsK8Kz2+U+5OEfcwXtj9NuI WzFA== 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=7xFPEtg96l7SmhuQ+kSd7xl3J9r3mzIhq+0WeXI+CaA=; fh=cP0QZFg6MuyBR24J0KjrrDlt4joDhDmvpCU8OseFE7U=; b=kqPxORmGthZQw4NGDRh20tENMZ49BtQlMVk8KtDCzAiPg3Dfu17TJF41erxZV9QDQS lcT6nqCP1MF0Sa1s3UFuM16geJFdNDAmmByUv51QitiXVlvRG7ORsMj8p+ISnGi0F+ES hPAvd2GrNc7DpzKYbuAWTOSPPImL4dG+odheJT8U49P78N0PL62BzGuE7fx+Kr6nFbgb sDwuF5mjAvGIiUDKL6q4HJ9Tmq88TUCi64ck+hOu3Yy56nfmN6lJbiGZw65aJE3kvGSA W78Vbv9wNsvDMMQFPKncHcBG0dGCymqf71G9fQdQTb5VL5/enIILomxoEiOatGTRct0B qTFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DPFPaNc8; 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 v23-20020a05622a189700b0040fdce653bdsi6638412qtc.318.2023.08.29.16.26.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:26:31 -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=DPFPaNc8; 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 1qb7nE-0000vf-I2; Tue, 29 Aug 2023 19:06:41 -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 1qb6nH-0002Nh-Os for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:41 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nE-00048X-UQ for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:39 -0400 Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-34dea77cbe6so4264715ab.2 for ; Tue, 29 Aug 2023 15:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346556; x=1693951356; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7xFPEtg96l7SmhuQ+kSd7xl3J9r3mzIhq+0WeXI+CaA=; b=DPFPaNc8i5fatVmwo7CpfxKA+RPXO1XKIbQh25WgUFUoPXhK4r4qiuh8ze+JePLBBI vvIuy+ZjxW6uW+Ki4rYGx+CW+FHhGw3n1uny+oXHQ79tkRK3GGImy8Nkf6hiPWlOUU6g dfJa/QKNS+52ZAkYjHrSbb7Px7uyPqqbhRBAx+wkMAZGHz2cuiDWeYs9iwYG2b4mpJpZ u+sQEMOdx/nlUJ+xz9KpTlUUfPvsLP9AWFwl1ZkVSI/5OhJ4KBtMj8nRRT4WLK1RJzAR W5TXRPgm9AvZzswQT8sJD6F+8mlIjjOeVKc13ef4VX852vwxhl/q6XAxPZSkzgysScGx 2Fjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346556; x=1693951356; 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=7xFPEtg96l7SmhuQ+kSd7xl3J9r3mzIhq+0WeXI+CaA=; b=ZVLxhPdKFL4gN0SE3lh1w5Kn4FSpO6bQHQ6r+e0QdW4cazNyambiBm1ROfCUM8QwC0 BHbZe7/oxQwrEtrx+4Py2SPU0HtKor1lpsBcUaeX8naeO7mHwDs0v3id0GsXS268oh3z 98W6enYWMcxFwPFV9OTtT52eCRCFbF9Fc1xrZrXje2XXPh0oXu6cmJRFhNPLcLctOLD2 9OD7r73TqTfSFBJ0GONjVjnJ63dG7sTmvh1HKFgIWFWG1tMqW7c4Jgk0hg+/2PPXcmv3 VwxNnWO2Woja5GdHvOTGgpD9Kf7K1Md4kOOY/Zfp8NOd8Kc1NQ3ATSgf1sFh87cwUNzi bZTw== X-Gm-Message-State: AOJu0Ywmk4HbWLYBT8ayBr1qTa64/RQSIKNHhMcAk5vCsdVJ+br2wHs/ Yc+yHwsoQxqTRBiHHfqqYK9EGjKcW+S00QW7Pq4= X-Received: by 2002:a05:6e02:1a6c:b0:345:af1c:29c4 with SMTP id w12-20020a056e021a6c00b00345af1c29c4mr763380ilv.25.1693346555817; Tue, 29 Aug 2023 15:02:35 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 06/20] linux-user: Use ImageSource in load_symbols Date: Tue, 29 Aug 2023 15:02:14 -0700 Message-Id: <20230829220228.928506-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12c.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. Reviewed-by: Philippe Mathieu-Daudé 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 833c22da25..f34fb64c0c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2049,7 +2049,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. */ @@ -3294,7 +3295,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); @@ -3385,19 +3386,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; } @@ -3415,31 +3417,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. */ @@ -3464,10 +3468,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; @@ -3476,20 +3482,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 Tue Aug 29 22:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718263 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp244281wrh; Tue, 29 Aug 2023 16:27:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVsTdYAZMIWHXal+v0ofCFbYZbr5xFnMGQhw/ks7oem0hcR1mKuNCCHgcz9aBtGgTZFtId X-Received: by 2002:ad4:4204:0:b0:64f:42eb:92f3 with SMTP id k4-20020ad44204000000b0064f42eb92f3mr465790qvp.45.1693351676623; Tue, 29 Aug 2023 16:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351676; cv=none; d=google.com; s=arc-20160816; b=OzB8/gfVX7NQzjHYh/9ejAkSA1APeXiIX9A0YcAgYkzLJ9sQw7U0KEbyLoJ1vx274N /VHo5Ct67KCdEny8tFPxIZTsocg+flXV94jONfOo+l+ijItmQ9cYtzPYUORSDqg1GaKr tEO0l6MxC2fSV/vcX6tgUoYF65v5ywt93x5oS6W5ttfvVPL4T/JNKGKsfHZmWQoizISO rexZdhrS1muN/rkYwVFmnZn/UYuQ/kdzensjRVO6LawrNCLpfNp0AIE2StW9NSi5cbSh 3p5EH20EkFyric++TLrrvS+KEyFjfK2TBKQyxEUDkeu68jZAovzAl8FLLajQ+AICVQaP X8mQ== 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=CQVgvEA797/6AHlvAuip4Dfdeigp3YyNGto1GCMbIo4=; b=dtSXj8HMdNRzpLKpbqY4VIm0/Ou+QbEgHhl9gHZ2PBi7buYqOeE3joRqv41Nl2rW9P 4p2gOByzsPpnn4CswUM8NVbI+3WBeeXfWz4rIurg9fV6ce2LZI4ugCCf8lfpnROghCTc 3rPNvY+vG0W8FC43eLgXs87aI0ybj0YCiZU4rBYH0oedkim73cN2BCUSVhxLoJ9xBOOj jTl7PyOB1fDcTWemXpcWnjcxJFv/7jITPExwq+HaTrkgiMsqy4iKvBXhmp3g7AtPTMWa KpFOG0S2oRbketsXxuy+b5jiRdsdTuAIrT0AJweOOqxOqkahoTh++T4kyDUc0vhhrP8K /x+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zuISEipD; 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 bs39-20020a05620a472700b0076efe86cb67si5025026qkb.446.2023.08.29.16.27.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:27:56 -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=zuISEipD; 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 1qb7ov-0003GG-LZ; Tue, 29 Aug 2023 19:08:25 -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 1qb6nJ-0002Ns-If for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:42 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nG-00048t-RL for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:40 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1cccbd43250so3481872fac.1 for ; Tue, 29 Aug 2023 15:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346557; x=1693951357; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RtG96b3jmli1q7lVtewuvoGgDoJMS7AqHQZel0hsDHw=; b=zuISEipDTVKCziWcRRcRCa/WR24i2orPvxaPumvEN2L7yH17vV/NRNhkqnHSAqxvQt vAluQA5u5db/553lY5BVJNl9BsAHxf3S5ZeNixfQ24FBBDlVBRjHmHGJuc5Lu+mJRQse imy4Sv8Z/eFOIt9siJ6xlkEtX71moX0TI6I5GnuHPK5yZuAW1lZ/9BL/R/OFgxswiDU7 MnCBS9zPlbZ9Ondf6WDg71ttpbGWpRF/43dHzIKaNPp+A6weEjJQCTbmm4SXBTx3sZyq hb7l/3zcMOkMPJipZqpBTCkUAa0EONhlaScw5hZZBl1dIo3Ya6Cz1ENvvClLUtjZYfEd L/tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346557; x=1693951357; 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=eZyvbFuJX7nnyCLvqr6XJ9/af8teVwSD13Z0oZxfvEjvVgx4KK7Dyk7D9jSMoq5l7x UUDGkHGqKhWMGhR3v731VpLqPC+pj8Ooe46+7eTYMIOSeD1nD0z2hKoqbTEBg8YkBYd/ HS1N00IAzxA9ZoMt/EFLZ+EiOSGAXxWeHWnZv1TTFGMce6wJotpciuZH0w/s4+jFkmIa xmXIVO3+G7gwwRdiDj/6+Yi954kqZg0zn5GnWTKWMtNtksY0GyPowjWEFzhGuRny/xd0 k3Yt/cOE/b3RkBDvrHSE0aws+VCgJuSF+6OJHNz6Jml3tsUO0Mn5cqFAPHxRgnv0AxCi 64vw== X-Gm-Message-State: AOJu0YxYrooHJLtA2B79UlDsxBITSzS79b9XMoRR7hjYdDUcAS2ry5Cp tkQ5ytplcHwFQSsHy1FceZtsVa9EJkg88McRqX4= X-Received: by 2002:a05:6871:205:b0:1c8:b715:6c81 with SMTP id t5-20020a056871020500b001c8b7156c81mr548472oad.55.1693346556873; Tue, 29 Aug 2023 15:02:36 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 07/20] linux-user: Replace bprm->fd with bprm->src.fd Date: Tue, 29 Aug 2023 15:02:15 -0700 Message-Id: <20230829220228.928506-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::36; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x36.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 Tue Aug 29 22:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718246 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp240241wrh; Tue, 29 Aug 2023 16:15:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjgk0apxVDgEnp8IEbVAjCeCjc9InYE7hkiVsWlvblHJoOkPTtOPNQpPm6mglVzjTh+nB5 X-Received: by 2002:a05:620a:29d1:b0:76f:1828:4f36 with SMTP id s17-20020a05620a29d100b0076f18284f36mr657834qkp.27.1693350924651; Tue, 29 Aug 2023 16:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350924; cv=none; d=google.com; s=arc-20160816; b=0tOqSHzxCWXg2cHJqBr/+jMdm2wDHBbkXu9srIbL2Uxgvq1c8J8qP3mF+Uy1AtSKmW pyI1ry1H4CokxPkll2yBGsXaCOtyAz2YxXjwV0Y2JiCA4eCPNEbfL8G1OW36FOTGHCuy FEjdD96EbmsucasZUPik5ZZsaRhMz8oQBf1cg9PY96VyF/DpuFK7hh/wLdMHBO7aQogr /m/hZ68aK56JHXnuRkWQulVac4VaUu2RsWH/oroRfckPEZLeoVWbBjQt1b0uSCyjMYxB SjX8euCIqWak7cmITYVemSXdg3y9/jpRgyETJiVe/cspHmHruSZWgnmiLxaRVhGMm6XP tnNA== 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=37NCcnAuJjn+I5L6WJxLaF09JKApB7jM4OXRupDrJSg=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=PCwUODI1nGa9NhSC9UnsfwoeRgokOcIS68SHJw/MLputu5U7pXlaqpjKRUTSlF8k7E cF1rdjB8Wxe3ibjDW7nROc6DdBkySZNG4xV5XUM7iQkYfkT3pnkZJQzgp1fZ/pSvXbg7 13OIH6Pxb1zefiupOQ3WDT6g8S6qlZVk37/Eiua5N1qdERtoidiirkpwTtBTzNBu+k/v yt7sj+pvSuWAa8uwj9qHyNqyHMrhTzOYx/xk5HqItif8Ouk/OI+g9lU1JMZXhfPgOQNf nwp2ug11UHd8cya3fUa5sLSYBbVGIJzOz1MqfVlhYzB4MXYJBHyuI2VmJNjTz9E00CMo 4fUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WNkWNkOo; 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 tp3-20020a05620a3c8300b0076dabaa2929si5109121qkn.188.2023.08.29.16.15.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:15:24 -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=WNkWNkOo; 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 1qb7ox-0003Sm-Mg; Tue, 29 Aug 2023 19:08:27 -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 1qb6nK-0002OL-RP for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:43 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nH-000491-Gb for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:42 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68bedc0c268so4223623b3a.0 for ; Tue, 29 Aug 2023 15:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346558; x=1693951358; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=37NCcnAuJjn+I5L6WJxLaF09JKApB7jM4OXRupDrJSg=; b=WNkWNkOok0jNRZGjMS2Z+5sO5VRuH1vgnkSEoVR/PJG+xzz0bfiy/+4mP6XQmwmQ+v ejnc3cqEfEIdHKeWAd+uZbDvisQ6YngrmmVGWcxpf16ftEb9Amc3ihWM7uTMqTHIcSST SMq4nOsMdJbe3qhGZdyyQQ7T+8dJm1J9Hpe8xz3AJZnI/zCQX+NAu5mIAaFxdBcetrtA cckWk5TDgUFz7+m13haZPTo/KHp5Bcl+yN1TwzWPhAU/oEOYfyrOb/8Me6VuHFvr27p+ pchC3os7Byynw8fp2WhjD+Pb4hO7taIbrzbKh1sEKzhqEZK0Irjg8g7Wdmg1oxfCPONg fgFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346558; x=1693951358; 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=37NCcnAuJjn+I5L6WJxLaF09JKApB7jM4OXRupDrJSg=; b=IZXKqNBiov5c3F7plkx0lZOcNKnHCM53hVTIhjM12MWqCHHmuA6uhk+TN8rcE00nNW 5hiEF0bqCJPdFKSm/Ygwgb5MsxMuoJD3Z3RPoXRb3kzQvmDa9hyR2h3ezZsHvLEuZT64 332ekUarGBQcpWttH2er00s1bgwZb0wm5LQx2PQ+4YxYY0H6TTVjfy+ZpbHeTZA+Chjx 51beZm1De8WxSU6wMXznIGL+HnteYHvqMccCjQLCsuyh/4TkeZydcMATEJTpB6CzxipB 4SyH2XsBsbXdtvQbp17xXQU1at8mvM0KoRpZSA9eHjza6XMCNJ5xxmFAjnWqt5jt7fN4 Gklw== X-Gm-Message-State: AOJu0YzJctXeIsOMMwSXknh/uRvuji5ItWWs9BTuHOND5WBas6Oc8fhD /1G0QNfloPKlz2wDMQ7T/IhEID9MDLmbnsqbkOA= X-Received: by 2002:a05:6a00:1acb:b0:687:7d09:c0f with SMTP id f11-20020a056a001acb00b006877d090c0fmr551564pfv.12.1693346557728; Tue, 29 Aug 2023 15:02:37 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 08/20] linux-user: Load vdso image if available Date: Tue, 29 Aug 2023 15:02:16 -0700 Message-Id: <20230829220228.928506-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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 Reviewed-by: Philippe Mathieu-Daudé --- 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 f34fb64c0c..2a6adebb4a 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 */ @@ -2292,7 +2305,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; @@ -2380,10 +2394,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 @@ -2465,6 +2484,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 @@ -3342,6 +3364,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; + } + + /* Remove write from VDSO segment. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ | PROT_EXEC); +} + static int symfind(const void *s0, const void *s1) { struct elf_sym *sym = (struct elf_sym *)s1; @@ -3547,7 +3612,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; @@ -3630,10 +3695,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); @@ -3645,8 +3713,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 Tue Aug 29 22:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718245 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp240002wrh; Tue, 29 Aug 2023 16:14:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES93pa9BUyIXeanEGlQmzCIZ9jlJB8KxaFmlzYdpmJHSQ/A5upg7bh5gfK+9ExOGxKbpIo X-Received: by 2002:ac8:57c2:0:b0:412:1c47:773b with SMTP id w2-20020ac857c2000000b004121c47773bmr489550qta.63.1693350888060; Tue, 29 Aug 2023 16:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350888; cv=none; d=google.com; s=arc-20160816; b=I1JpWKjZle1QAHqvcXpBNO/hbrhz8dDFqmnLD7vmbbwLsjx6IPbL/m3R5aCXppkkE3 s5PjbsQimyiZOII7U5axHbH+0mjox3GjQLNap+NTdgrIJ/klaIfEh3BzmZcPuAGWjUZ2 rW5F+2ffNFDa2EGmBoGTS635uX5eMi3GBCuRolfeporciFItcdDAsJkhWgV3721DsMbl seCdJZ90k908k8VIX8uNvtVQToZkT2yE4H3Qo0/ry2JPdhACa0IJY7r83ODjRYu9nkBg pvVSVMtJIURbPAdoyQ0pxwJ3GMGn7SK8pazg5EXebCtrXAX94btn4IWb8pE3YhQIhF0l tjDQ== 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=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=ZsUeRgo8rwXRm/CgR3Wd9lNekuwkj+CkU+r9eAAtJX9rho3jbAdI1SBDk6kfAJboeY bzwNYfgAbfyoOjhUZhO+HUiNkP3LgBE6UsPylKnX4hypAM11J7Qjw4V1IAaWjq2eRVl4 Hg4YwdSY1V8rysXWvRdq7gSzEGHL+ItgtpZh6bqhjqsdMhHufO+p+lYivkWpmcPxEGPD AmARJlxoPRVMNklTPyuNSzS6wjsXLex69G+5mDpDsKlc3bwEtceexPKa7uOT3KtcQPaf Q5F7TRQQe6QiJlLR+sj1+r2Wm7N+fewiMAwLv8jaCLJqD4IllYvKxgT4twptYcUIa4Fj OGMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VdbKIgII; 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 u31-20020a05622a199f00b0040fcf7c5e74si6487529qtc.117.2023.08.29.16.14.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:14: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=VdbKIgII; 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 1qb7nA-0000uu-Ne; Tue, 29 Aug 2023 19:06:38 -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 1qb6nM-0002PJ-KL for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:47 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nJ-00049B-B5 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:44 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-68a3b66f350so4227172b3a.3 for ; Tue, 29 Aug 2023 15:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346559; x=1693951359; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; b=VdbKIgII7S5kNd7Ce3cXlNfG/fs9usvyJ2KnsuNdRiA3f+1ZF6FH5Wzg2XKYKMFi1J jlmRtJqOpjugsw+6ZmkKzUre20GxUlnNmcvXPSPJ9s8h456CJX7jsE26P2tmigvjiqla hDcJP35EKrcHhoW+YANBWrD8u3aumOWPmx2sPlibanDYVQp8+HpEd42BMMGZ73UKtWfe lT5h7WMKMv6EcbOEtsmJQpJguCCux/iMhOI1iFeMO91S3BOvGxMhxBSnmUBE1ppElWGj Sw1ziDdTgaHrQECmQwyfC/rPnpc5tqFFHgq6CwIkMhyX+tjdxk7K1H+G4T6EoeTnLZYc giXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346559; x=1693951359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8DdcwZ9eARbtAsO2bsYseMjavqpyn3Vml59R5brpVvQ=; b=Ui1IxlMFqVh9+LmVgpdd/83yaZHVPp+3sUpBgTHqwzY9qbj8KcAJrUqJXojH0kwKT5 XlJYxQWnhlWs9fhw2zqUnCb3mXHVCHFskmRS3Fo9s1f9SRpZDbrX1B2UPpWoNaukHozu M6OnhM59gT9G/LyegZpfwzL5ZZkejZR8OsYZah42lysfHeITarkljblrCWoUl9VZR4zs zUzi+fVWLNq8qXOeOIQw02ayk5FDcF1CjiP0YO/BzDHEw2msU8Xre0e/FuOvGzLLqw0T i8+6B3fqHwXVhPoFm6j0FPlUPQGHazj7A5cSR0/b1XQHbBZQ5FbK5i4H2rvugWYg0HRk 1iuw== X-Gm-Message-State: AOJu0YycxgetRJ9K7swo1jMsXk0Ve/pviaMLv9BTP5RIdMadBuHIDg4J LykhsD7RllimGdyNrJxXGJQ0Vm9zCiOs9Gldhjw= X-Received: by 2002:a05:6a20:13d1:b0:140:ef2a:9b79 with SMTP id ho17-20020a056a2013d100b00140ef2a9b79mr571136pzc.33.1693346558687; Tue, 29 Aug 2023 15:02:38 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 09/20] linux-user: Add gen-vdso tool Date: Tue, 29 Aug 2023 15:02:17 -0700 Message-Id: <20230829220228.928506-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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 | 307 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 linux-user/gen-vdso.c create mode 100644 linux-user/gen-vdso-elfn.c.inc diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c new file mode 100644 index 0000000000..a6c61d2f6e --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,223 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "elf.h" + + +#define bswap_(p) _Generic(*(p), \ + uint16_t: __builtin_bswap16, \ + uint32_t: __builtin_bswap32, \ + uint64_t: __builtin_bswap64, \ + int16_t: __builtin_bswap16, \ + int32_t: __builtin_bswap32, \ + int64_t: __builtin_bswap64) +#define bswaps(p) (*(p) = 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..7034c36d5e --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,307 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +static void elfN(bswap_ehdr)(ElfN(Ehdr) *ehdr) +{ + bswaps(&ehdr->e_type); /* Object file type */ + bswaps(&ehdr->e_machine); /* Architecture */ + bswaps(&ehdr->e_version); /* Object file version */ + bswaps(&ehdr->e_entry); /* Entry point virtual address */ + bswaps(&ehdr->e_phoff); /* Program header table file offset */ + bswaps(&ehdr->e_shoff); /* Section header table file offset */ + bswaps(&ehdr->e_flags); /* Processor-specific flags */ + bswaps(&ehdr->e_ehsize); /* ELF header size in bytes */ + bswaps(&ehdr->e_phentsize); /* Program header table entry size */ + bswaps(&ehdr->e_phnum); /* Program header table entry count */ + bswaps(&ehdr->e_shentsize); /* Section header table entry size */ + bswaps(&ehdr->e_shnum); /* Section header table entry count */ + bswaps(&ehdr->e_shstrndx); /* Section header string table index */ +} + +static void elfN(bswap_phdr)(ElfN(Phdr) *phdr) +{ + bswaps(&phdr->p_type); /* Segment type */ + bswaps(&phdr->p_flags); /* Segment flags */ + bswaps(&phdr->p_offset); /* Segment file offset */ + bswaps(&phdr->p_vaddr); /* Segment virtual address */ + bswaps(&phdr->p_paddr); /* Segment physical address */ + bswaps(&phdr->p_filesz); /* Segment size in file */ + bswaps(&phdr->p_memsz); /* Segment size in memory */ + bswaps(&phdr->p_align); /* Segment alignment */ +} + +static void elfN(bswap_shdr)(ElfN(Shdr) *shdr) +{ + bswaps(&shdr->sh_name); + bswaps(&shdr->sh_type); + bswaps(&shdr->sh_flags); + bswaps(&shdr->sh_addr); + bswaps(&shdr->sh_offset); + bswaps(&shdr->sh_size); + bswaps(&shdr->sh_link); + bswaps(&shdr->sh_info); + bswaps(&shdr->sh_addralign); + bswaps(&shdr->sh_entsize); +} + +static void elfN(bswap_sym)(ElfN(Sym) *sym) +{ + bswaps(&sym->st_name); + bswaps(&sym->st_value); + bswaps(&sym->st_size); + bswaps(&sym->st_shndx); +} + +static void elfN(bswap_dyn)(ElfN(Dyn) *dyn) +{ + bswaps(&dyn->d_tag); /* Dynamic type tag */ + bswaps(&dyn->d_un.d_ptr); /* Dynamic ptr or val, in union */ +} + +static void elfN(search_symtab)(ElfN(Shdr) *shdr, unsigned sym_idx, + void *buf, bool need_bswap) +{ + unsigned str_idx = 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) { + continue; + } + if (first_segsz != 0) { + fprintf(stderr, "Multiple LOAD segments\n"); + errors++; + } + if (phdr[i].p_offset != 0) { + fprintf(stderr, "LOAD segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr != 0) { + fprintf(stderr, "LOAD segment not loaded at address 0\n"); + errors++; + } + first_segsz = phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "LOAD segment does not cover PHDRs\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) != (PF_R | PF_W)) { + fprintf(stderr, "LOAD segment is not read-write\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, "LOAD 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 Tue Aug 29 22:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718237 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp237148wrh; Tue, 29 Aug 2023 16:07:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEO4O3fFIc/7U6r8b19U0g1UklMPpXlvOPZ3jfa5R0+3fbwOnrfLVYl6KjuH7R3taQ+RbrY X-Received: by 2002:a05:622a:313:b0:403:b6d2:8dc4 with SMTP id q19-20020a05622a031300b00403b6d28dc4mr647835qtw.34.1693350443436; Tue, 29 Aug 2023 16:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350443; cv=none; d=google.com; s=arc-20160816; b=BrA6eQAxNUj36EGIH2pQ6C8LNHEbn+xkSQf+YW48JhV3MgcRbNhAwd+2pcQOLDx6n4 mvX2mq3Kqp14+8558qWDpJLSOlmt41EeLPqEa/Y8Kbsll8xVnClGyQ9LYUZPS4Phrgjb 6+79nx3pYLrZVR/i9x0bgoYgZci/7NcUzS0qwQEaW/UMI04i/nKFA3aqTZyoSivcasQo PNeOH9f6Wmf5dNtl67uoJupa+FD2nIfrCLGoVlJE2UsSt5i6Eqm6aEA7w8/0HAKXuo1A sXAfC5DocrPc7bWntr29FqzTXfc6UX3fy638C9xMrXfoB6MHSicZxCLakAACAY96ExGU kVog== 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=80yiBDrasGbCP19yEMmSaaDi0ipiYiAfvI51hXAWE6g=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=YPIO3t5rFGjaKewqwd3I28z4GCVRcaX12kiRN0QUjwfs/HNNdgocpMW7YmlP7UplL0 aDhJhBMQzNPsVqJTCpjmkcFP/72g3efmCZEYokTt6I/rJbzdXh3gxjRJpfc3/S7Jrzdh 4ODziyKwhgp+Shg/CMIEZyd/d4/pL4I5OK/R2VqycUGzNobLvqsCfvEGVkfjuDybZdd4 fqeqJX3zo9XOYDTgv0ZMyK++ABya17ruRmgt/v3ipr5Vs9cLRhRjYh0hmO/3WY+9X7An TlcjVnSG2ck20gf/nMyBD1SxU7fwzIL5M1LHTer8D125g1B137xpvMSHA9sCX/UGRodg ZRtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgJs6X4n; 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 z9-20020a05622a060900b0040ff099d956si6717726qta.670.2023.08.29.16.07.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:07:23 -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=dgJs6X4n; 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 1qb7ml-0000c8-Kn; Tue, 29 Aug 2023 19:06:11 -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 1qb6nN-0002PK-JH for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:48 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nK-00049Z-Je for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:44 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68bec3a9bdbso3174541b3a.3 for ; Tue, 29 Aug 2023 15:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346561; x=1693951361; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=80yiBDrasGbCP19yEMmSaaDi0ipiYiAfvI51hXAWE6g=; b=dgJs6X4nB1fJ6mdNPymBrmOQXNgHyf5e5yomo65NlYcdHUzOIcmgFlhnj81MuPCaay 5zNQ/067rPBKGclMhC/nXkXaMbQZ7Dq/Fg9eSbBbuBp9P4nQVp6K+uoNDEvWAgb5bpYR 6CRiMKxESMMreg5vJFSegn21HXkdRsd9cTkcAGXqiREtX1LTgmt3JC6li/BHLZ2l671W Ew5Y4CghLbbGFbp9xAClIEjOp32VL5F4tsPIGAeUTnIh2LIscovwbYzCxlaboF2hY5BM pHM46GkcADtJJHCRAWYaHMuPR0bAjCc3g5nTdVZpQOPu/nK6nNRjEldrR6DKQsmYPZEA ypUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346561; x=1693951361; 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=80yiBDrasGbCP19yEMmSaaDi0ipiYiAfvI51hXAWE6g=; b=d/TdtwsE068REjxigskaZnwBeLIm9cO8gjBEHhWFm3M1zad83V5U7hzRU2CTudCUMO MEaVfl8XN5uuRM/FMeYXPDrjxTWCEwquxhIL+9x06XAk9G/ExGnLErN7T3EXEracTPJy Ho3Fmm46JCtybygwSMN/9VCuzkZLb5pY4g476/49QUUpoyI61967bztFObuLepJx2TWX queBtzKWwXGOADo+lOMBZ2SOTBeKx4WrZltwVrsVE9RO8pKACetgwCIqEW4tcKZfW5TY 9C8raKY5YVC5bYgUjFE7bc20XOAD10XXv0qBDuIPd7V5kOogT+CGlRtop+WgOGxdXsz4 dXxw== X-Gm-Message-State: AOJu0YzN3CPbzw9GTdy/tK/fW4U99RGY8B7PqqjugVzlnoBLRfLDz3yW UJsPTeOiu+pyUlbNSbX6UGCmlvL86Ok30wMV3ec= X-Received: by 2002:a05:6a00:3982:b0:675:ef91:7922 with SMTP id fi2-20020a056a00398200b00675ef917922mr568966pfb.4.1693346559671; Tue, 29 Aug 2023 15:02:39 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 10/20] linux-user: Add build-vdso.sh tool Date: Tue, 29 Aug 2023 15:02:18 -0700 Message-Id: <20230829220228.928506-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org A shell script to build the vdso using the cross-compiler makefile fragment. If none detected, fall back to copying the pre-build vdso from the source directory. Signed-off-by: Richard Henderson --- linux-user/build-vdso.sh | 31 +++++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 2 files changed, 32 insertions(+) create mode 100755 linux-user/build-vdso.sh diff --git a/linux-user/build-vdso.sh b/linux-user/build-vdso.sh new file mode 100755 index 0000000000..489088737f --- /dev/null +++ b/linux-user/build-vdso.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Build vdso using cross tools + +build_dir=error +source_dir=error +target_dir=error +output=error + +while test $# -gt 0; do + opt="$1" + shift + case "$opt" in + -B) build_dir=$1; shift;; + -C) source_dir=$1; shift;; + -T) target_dir=$1; shift;; + -o) output=$1; shift;; + --) break;; + esac +done + +frag="${build_dir}/tests/tcg/${target_dir}/config-target.mak" +if ! test -f "$frag"; then + # No cross-compiler available + # Copy pre-build image into build tree + cp "${source_dir}/$(basename ${output})" "${output}" + exit $? +fi + +# Extract cross-compiler from the makefile fragment, and build. +CC=$(grep CC= "$frag" | sed s/CC=//) +exec $CC -o "$output" $@ diff --git a/linux-user/meson.build b/linux-user/meson.build index e4cb70ed2d..099e5c4fe0 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -30,6 +30,7 @@ linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('sem syscall_nr_generators = {} +build_vdso_cmd = find_program('build-vdso.sh') 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', From patchwork Tue Aug 29 22:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718239 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp238105wrh; Tue, 29 Aug 2023 16:09:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZvg+r7sXIB3hz/xkzgSvuGElj8zPO6CXWwwTbll4HQVUCLLHeC/9RlXr5GtJ5eWO0WIhT X-Received: by 2002:a0d:d443:0:b0:573:9747:9a0d with SMTP id w64-20020a0dd443000000b0057397479a0dmr445705ywd.41.1693350586781; Tue, 29 Aug 2023 16:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350586; cv=none; d=google.com; s=arc-20160816; b=EN6PQMxiPe38rQgeixXv5KHndi5X+tSM2hf98yI581iZ0E7etxyNAFHrxZbW9yVo2W UfywLvmFUKD43fXpIq6c72boPkdMmAVO9x3OQ9HQgAeh35hbqI+9JflKELAY2Q2lvxxN Sxk/Dk75rTXcCxUUY2vJA4oQQSm2h+AlogA9DKj4UUKyKVImowGsZbKyFmmCfMYABWKO ZPxuH03Gs/b03PvWZPbSGsqQ6ruEoxWVOsSzry6brMGtEjkD0eSzhVVlssQem/hvHqfw 1j+i6CRpzxsvOlEp7WLRRIC1LG98ctgzxjEmvWeByBTE2Ejf7Oaln0ze+CXAOft/zZFE p/0g== 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=Kee2mUckLTu0r5fI4Zox2tGZrq73NQtpZRaUibEwLSc=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=vGRynwJNhp6qF4/2B5uw1PHdr3pEkcyDUxIkJ3YtFPbC1lWRa+CgK5KTN0NX66Yjto fiPZYse02ySx1strzX3bkXSPDkCvkZXkYFNCCK9eaF0wF0GtfgPZwhmiRs/21rjOWWEY Covy2iHb/5GOFmAv/Xc9+O5GyF5//GbgpSnGMlz5Y48NSHiHiXQk7Txea3eeYlJpaaS7 DDHKoFGWEWd2lKOfuPqTrXnrA8iiGT5Pgv7VW5XR7Ej/j480z0YcSHUCuVXJ4aUUyg1x WKOmGktFC21+14jl6WqeLt+g+qm60qfUQ8W+phWdwYt6AFEP/+Ahy5xYPk1ri754VpA5 +LhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NYnRP5kg; 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 b10-20020ac85bca000000b0040e332bba5esi6551467qtb.184.2023.08.29.16.09.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:09:46 -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=NYnRP5kg; 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 1qb7ml-0000dp-F5; Tue, 29 Aug 2023 19:06:11 -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 1qb6nR-0002R1-CV for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:51 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nK-00049W-J9 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:47 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68bed286169so4216993b3a.1 for ; Tue, 29 Aug 2023 15:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346561; x=1693951361; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kee2mUckLTu0r5fI4Zox2tGZrq73NQtpZRaUibEwLSc=; b=NYnRP5kgztaNlnwcyCgcHQG+7Kf9dqNM2RU6nuI8jFAQEc6ZbfWK9l/RuzuvGHbbZ8 fY3UvlySFCPAxQ8owMfc16ZlqYIdkmVDOZs6VTN4/U+SoOQNDRHoCCa9wiNB1b0wy4C8 uxrHh26glr59o4jW0Sup64YkWB7QVeWloKz1btc1tFVeerAS3VcJXdSYFrjxdddPGMuu x37IwV1RuAH3n/I3Gzpw7r1tREW9Ob0FylBukklXjfudHTo0URwIvqE2xNHFqba/84iB hVDMbdwY5RwNzPFBVjfSv3troo1nMYWOPgqKP5+MyX3LMmaY7t8FPfc3APm/QKQn2tgM epEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346561; x=1693951361; 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=Kee2mUckLTu0r5fI4Zox2tGZrq73NQtpZRaUibEwLSc=; b=jsCrgbIgGdyge8xNdBpajcuiuhgEgG5bTAXarKQ0WVvcoFenqhiWH+rn7L1EXpaDme 9+O8U8vDMdUj57KgxzT9SzQQY0G9wRdg8y0XtZmWn1i2wJH5+F9uBenCGVb5yB6NGsae a72zSdYYKFvTYEKhlqIJMYQ6JOrGTQXbspnm/sSLNI1XqkXfz86/K213SjkQot4Bn8V+ 84BZ/DTCayQw84Gv1J/8ehDG9Thlvl836fFaBKRtb4bHj8V4BHZdfAWGaYB3r6TVoqWp DRFHCpYyqNUU/Uob+C/VWbVPB1TC1spjI1wURWaLfvv1QWPpk0If7tYZQCV2sajxpzZ0 j7Kw== X-Gm-Message-State: AOJu0Yykg0o2V75hxdhJwh0uuHOlNg+0aW3u8O/5lCi2zZeVFNZ9hJo3 2BghY47qVC+UrV9Stp5tSsYKAmLuT3aoLy5hfbc= X-Received: by 2002:a05:6a00:3903:b0:68c:3f2:6000 with SMTP id fh3-20020a056a00390300b0068c03f26000mr517468pfb.6.1693346560823; Tue, 29 Aug 2023 15:02:40 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 11/20] linux-user/i386: Add vdso Date: Tue, 29 Aug 2023 15:02:19 -0700 Message-Id: <20230829220228.928506-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1267 Signed-off-by: Richard Henderson --- linux-user/i386/vdso-asmoffset.h | 6 ++ linux-user/elfload.c | 16 +++- linux-user/i386/signal.c | 11 +++ linux-user/i386/meson.build | 24 ++++++ linux-user/i386/vdso.S | 143 +++++++++++++++++++++++++++++++ linux-user/i386/vdso.ld | 76 ++++++++++++++++ linux-user/i386/vdso.so | Bin 0 -> 2672 bytes 7 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 linux-user/i386/vdso-asmoffset.h 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 2672 zcmbtWU1%It6u#5lG_z^4ZB?X_C>9o5sxCF8QBlyONt?nZ)?|y73e)ZGba%;SR(597 zjTXE8QIiHtY6YPbDhO>6s(mPS(FX(Z2Q`g?1xp_^KInr_=|f8&)b;yj=5}w=eGok1 z%XiMX=brmB_ny0ldSlx(O%qZAA|PnR8-(ZpuhYGj4)L&P5F5p65f&@qVw=PV(21ar zS~fT!zaSUUNMnrKqu7p`(Ouv?E|~S#J4vR z?eBj&+ji~rg~eZ!zf~VSJr_pXM}D8DFrl0ORPzVHn5LKmbB!e|qzOC^tO77~@mIB) zzl6kpgPDI3e2U8d6uIY2bq_`x0-wZWxDMLSfe$J6M%crOeHivUY<@1rr@`l7bI!EC z1WQ>fZdBic@iW@_P1t@f_$4LZXEGSfcpH2f?e~Kj&v`Zj+$T!NBlkb|jQhnHeiL+a z&lJblO18$ z-OkRAyW9oSmOj5{et#-4CVgruv?pIJqQxKI&ZY~dQ!H3DSHUrA-dxrymL5+h95ZU? zqfdy~j)7gfjrM5g9c>HN9>C7?j(;zF-_-GQuCsOgock95 z$CvrnLFHO513c5BE36+~5f2BEAVM30`47nj^o(oe;NgZND~~oF)87oe)%5l%caD!C zZUR`#4&CABw}%(BE9KdV>yxiUf|Id`UI}64SIQGVslJnSd`)$H14yd$t+Ysc2OQ(J+srhD+k<&>BHxRjq5)uze70i3T0nE36-;4MD zX|P(C`eCbeVGnF6>~F$Q>&)x0)jBo>TdiYfVXJlMbJ%KKV=Y$enlO4^9_Z@du@yHB zwchCMGqw$O_4gWmJ%e{HQ)lfOF0TyrZnl4$<)z$G>%HU>FE1lXy;xFj>Xa70cGRgB zZe?YqcLID@7{~XU=z-4s6vh$lz%9JdjN|)G?1a8N?pfc* zIKKY`&zcmDP2m_-KOf(Hg0)2EV}IgBfWHx_^Y;P~hc5SkbEE79n459x?;V(~$T$m@ zjElobxDGGOT`N`AK*n(#-do~0bSZKjGMDr(AZ`H$D-74d^xS8@>$IiJAn|o+fMq_` OKQ-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/signal.c b/linux-user/i386/signal.c index 60fa07d6f9..bc5d45302e 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -214,6 +214,17 @@ struct rt_sigframe { }; #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET ( \ offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) + +/* + * Verify that vdso-asmoffset.h constants match. + */ +#include "i386/vdso-asmoffset.h" + +QEMU_BUILD_BUG_ON(offsetof(struct sigframe, sc.eip) + != SIGFRAME_SIGCONTEXT_eip); +QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, uc.tuc_mcontext.eip) + != RT_SIGFRAME_SIGCONTEXT_eip); + #else struct rt_sigframe { diff --git a/linux-user/i386/meson.build b/linux-user/i386/meson.build index ee523019a5..d858bf1d77 100644 --- a/linux-user/i386/meson.build +++ b/linux-user/i386/meson.build @@ -3,3 +3,27 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_so = custom_target(output: 'vdso.so', + input: files('vdso.S', 'vdso.ld'), + depend_files: files('vdso-asmoffset.h'), + command: [ + build_vdso_cmd, + '-B', meson.project_build_root(), + '-C', meson.current_source_dir(), + '-T', 'i386-linux-user', + '-o', '@OUTPUT@', + '--', '-m32', '-nostdlib', '-shared', + '-Wl,-h,linux-gate.so.1', + '-Wl,--build-id=sha1', + '-Wl,--hash-style=both', + '-Wl,-T,@INPUT1@', + '@INPUT0@' + ]) + +vdso_inc = gen_vdso.process(vdso_so, extra_args: [ + '-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn' + ]) + +linux_user_ss.add(when: 'TARGET_I386', if_true: vdso_inc) diff --git a/linux-user/i386/vdso.S b/linux-user/i386/vdso.S new file mode 100644 index 0000000000..e7a1f333a1 --- /dev/null +++ b/linux-user/i386/vdso.S @@ -0,0 +1,143 @@ +/* + * i386 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "vdso-asmoffset.h" + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro vdso_syscall1 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall2 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall3 name, nr +\name: + .cfi_startproc + push %ebx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset %ebx, 0 + mov 8(%esp), %ebx + mov 12(%esp), %ecx + mov 16(%esp), %edx + mov $\nr, %eax + int $0x80 + pop %ebx + .cfi_adjust_cfa_offset -4 + .cfi_restore %ebx + ret + .cfi_endproc +endf \name +.endm + +__kernel_vsyscall: + .cfi_startproc + int $0x80 + ret + .cfi_endproc +endf __kernel_vsyscall + +vdso_syscall2 __vdso_clock_gettime, __NR_clock_gettime +vdso_syscall2 __vdso_clock_gettime64, __NR_clock_gettime64 +vdso_syscall2 __vdso_clock_getres, __NR_clock_getres +vdso_syscall2 __vdso_gettimeofday, __NR_gettimeofday +vdso_syscall1 __vdso_time, __NR_time +vdso_syscall3 __vdso_getcpu, __NR_gettimeofday + +/* + * Signal return handlers. + */ + + .cfi_startproc simple + .cfi_signal_frame + +/* + * For convenience, put the cfa just above eip in sigcontext, and count + * offsets backward from there. Re-compute the cfa in the two contexts + * we have for signal unwinding. This is far simpler than the + * DW_CFA_expression form that the kernel uses, and is equally correct. + */ + + .cfi_def_cfa %esp, SIGFRAME_SIGCONTEXT_eip + 4 + + .cfi_offset %eip, -4 + /* err, -8 */ + /* trapno, -12 */ + .cfi_offset %eax, -16 + .cfi_offset %ecx, -20 + .cfi_offset %edx, -24 + .cfi_offset %ebx, -28 + .cfi_offset %esp, -32 + .cfi_offset %ebp, -36 + .cfi_offset %esi, -40 + .cfi_offset %edi, -44 + +/* + * While this frame is marked as a signal frame, that only applies to how + * the return address is handled for the outer frame. The return address + * that arrived here, from the inner frame, is not marked as a signal frame + * and so the unwinder still tries to subtract 1 to examine the presumed + * call insn. Thus we must extend the unwind info to a nop before the start. + */ + nop + +__kernel_sigreturn: + popl %eax /* pop sig */ + .cfi_adjust_cfa_offset -4 + movl $__NR_sigreturn, %eax + int $0x80 +endf __kernel_sigreturn + + .cfi_def_cfa_offset RT_SIGFRAME_SIGCONTEXT_eip + 4 + nop + +__kernel_rt_sigreturn: + movl $__NR_rt_sigreturn, %eax + int $0x80 +endf __kernel_rt_sigreturn + + .cfi_endproc + +/* + * TODO: Add elf notes. E.g. + * + * #include + * ELFNOTE_START(Linux, 0, "a") + * .long LINUX_VERSION_CODE + * ELFNOTE_END + * + * but what version number would we set for QEMU? + */ diff --git a/linux-user/i386/vdso.ld b/linux-user/i386/vdso.ld new file mode 100644 index 0000000000..326b7a8f98 --- /dev/null +++ b/linux-user/i386/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux i386 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +ENTRY(__kernel_vsyscall) + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; + __vdso_clock_getres; + __vdso_clock_gettime64; + __vdso_getcpu; + }; + + LINUX_2.5 { + global: + __kernel_vsyscall; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + .data : { + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0x90909090 +} diff --git a/linux-user/i386/vdso.so b/linux-user/i386/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bdece5dfcf8da036d013262d4e37208350283cfa From patchwork Tue Aug 29 22:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718271 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp245021wrh; Tue, 29 Aug 2023 16:30:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1Pxtq0TunmQnkzlSUcuT1jYlS/soUwIgHiDiZG/nGipvTsEEquKji+01ICBgicNb3qxog X-Received: by 2002:ac8:59d4:0:b0:410:9c99:da10 with SMTP id f20-20020ac859d4000000b004109c99da10mr583811qtf.40.1693351818241; Tue, 29 Aug 2023 16:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351818; cv=none; d=google.com; s=arc-20160816; b=i9f93dRQCRAXcOc/qyy3z46kapOJRfEOPk+ZdiIWn0+T+f9qKagKdegul2fn51/mpa PkL0EvPDsY1hnFG5JSbsX3zftQ84pb5ZYYaKLBbh/ZA7sAUbMXOqaNXq26nyBh2M8PdS cHG0Pb+T9ZZ1eafZBF3hJsP02F5nl/FDZ4M8qKG8j5JQHZbyQ3vuZOI4Yk/ofOuHtjLU A3m+KIUD6IpFdKwza3fbR/uko9PR+Td0Pvj9GT7nh9B5pkmVfX1uqobpZ+edP434b5ou OyTHiOaDCKQUVVCIZbjEzWTnh8vOjbUoiw2IS7o/kKHoNXeJfpd6eRSNPKWbjaCMU5ZD O04g== 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=eeodzQae6xgscra1MOigH7Kir+wMGq9VLUD6APjis3k=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=XN20IEl6CriqQGproqiZGZUNq9+k9Z3tJQ3eWyrQvf86hYvnwjdCSZ/AgBeOBXqoWS rYM32C0ywk/KOIWgV3ESbf7ba/NcmIL771Sco9DzWzrqXvr8HJpg6lfWvFLgLq1Z2k5z Gekvvza+b0ZCGAM81gYTmz8BPs9vn6tXYjE/vL8aeWglM9pXXTCoFbz/KzndTi+JnRM9 vyqYZu5O3zGYPXOUGkkD3gCuOn1MpSYGZnsSKYE+EkRPK0S8bnlHLRf0DKkBpeKZBvZG ukENOSPEUb5VWtavhH21rINsLOvOuDH0NiiiaZBW2ahcp6BrPt87pxQOVKwfIL3zwhGW R46Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MpM4tcEA; 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 j8-20020ac85f88000000b0041095900432si6711562qta.776.2023.08.29.16.30.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:30:18 -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=MpM4tcEA; 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 1qb7nv-0001uF-Qi; Tue, 29 Aug 2023 19:07:23 -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 1qb6nR-0002R0-CM for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:51 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nL-00049h-C4 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:47 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3a88ef953adso3442793b6e.0 for ; Tue, 29 Aug 2023 15:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346562; x=1693951362; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eeodzQae6xgscra1MOigH7Kir+wMGq9VLUD6APjis3k=; b=MpM4tcEAt6KKfGBWgeH9Kl7o0ROQVVsCLLCWhidU7dTQ4FY5D213QeDphznixmux89 GoJR9d1tt7ns5SAqTI+gwbwdm41l2SkphI97ttvkPTMcvgRIKm6KAcAwE//TiioPg7JZ f9IQJ5yGymV8k1BStUTE9CcDBIsLrz6t9Q1kDGOxVzxajsXLp7NwxGaLthCpRSr73on5 MizGt3LzWwwy4b6dvzWfGjwQ0IJxGctelgwOovQB49P8IUVg56K5Z26oiYLraPzam+/Y vYTlq0R4hzNFgIJGFgzhGfOxa5pWd9ilFuYJ3srHIpy9tW91qhQM78ajPvc2C29EPBE3 kNTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346562; x=1693951362; 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=eeodzQae6xgscra1MOigH7Kir+wMGq9VLUD6APjis3k=; b=F0TmykmYL/Rih+fn0ydsh4HQGiHJSLVQpWoqXSjzfym6tWtJ5WVWakFlIRtu2dE7TV fTLTGzoINVtbHVG/7s6XBNNNdUYoSL6oxbygFRW4+QdcbSVROP6CpySQgtgC457GIda6 iUo6Xh3wj+HOZSVFomyR/1r84JFy/bv54i8ttlR0vxub49ouFXz3r4HTxuvwMLb3iK/p ty/zU8Pcvfuc4hq7AnAPllc6XIChaCKdq0dzuaCbL+J0VI3xhv46znMIjOFDRR+NCoHN 5SDhYr/QqeP1sdppVGDm3t/lVC/eg83RHLG4HOircAjnTrjFntBBTNNt5ffGpiLalI/V 27Xw== X-Gm-Message-State: AOJu0YwmpyylPlJpCcMSiig9SAKyiT2peCJalSOx+IA5pcguLGYPsifv zcqTargLgrTUOzQl8XF8Lh8C5wmnD6ciEtNfsPY= X-Received: by 2002:a54:4413:0:b0:3a7:af4c:2406 with SMTP id k19-20020a544413000000b003a7af4c2406mr304177oiw.44.1693346561762; Tue, 29 Aug 2023 15:02:41 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 12/20] linux-user/x86_64: Add vdso Date: Tue, 29 Aug 2023 15:02:20 -0700 Message-Id: <20230829220228.928506-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 +- linux-user/x86_64/meson.build | 20 +++++++++ linux-user/x86_64/vdso.S | 78 ++++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 73 +++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 2968 bytes 5 files changed, 173 insertions(+), 2 deletions(-) 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 2968 zcmcgtO=w(I6uvKUOl$t7l}J=nY6?Lgol-PVEvcEL6HP)om@-1c>vZO|6VjQnGcRQ# zQlk(xE{v3}x(Eh$E+iYFJ0pdXxDr=E=&lLvMs(4vwBz~aoiCl-j=CuHBzL}hzkANP z=iPhmJs%H_3^h28p){If=E2CAex2B8q6WA=6OrF`(`KF&`Uz?MI&EW@IwS5;Jq_-2rSodh0=h5M8yR&|8~q9xUzjR(|@2weye zz8a;S7@IIXlUIKD#o1b1+rN5odUE>L=z;rh$dv40C`m=ye*;62d-p2^;2j+^>^@b* z{zK-lF(OZeV2X;(id~9-RYHGjYX7&6)!h7{=_DaLK@yv17h==zIwme4kF^2|U3rG4QL%vz2K73uCxOLI|+`aN! z$F-%z;-Tzk@6K$E*Jv}RD{ao_%it)TlnNq<^Unr!fz4Lw$ zOy&HC$f92&rz(YWnba(~S{s>9e=uV%Oyy_Fufeq||4}nCJT{T^4!f^Qd<}K~WJ1Kz zzvUl)Z^gZPP8#nNzOg~(w`aa@FjYY9u^!IW^5APGzK1@7^HK>gD4>;p^R}arI;0o1?04=jpKWw!W)=?0Yt= zynUbER^IkMss3a7y}So_=McZ`$9S>#$BvH<4@j=b`|AzHy`jYM(LpaBOVlKlW^ujb z)P%J2ye6gV=6*G&ja!<{1*x-wK{3QEd-+1(8#gnXPvxf4)sE;I_k4cF&8AA(kO_(* zbIC83rV9C8121D-KkJ<idjF0yGj>9sy zEwzyLtiMFu4~T6avc|lrbF^o@CbB+LUq6S#>RVK)S)cWo$nWI(T!)Byg4)h8>pihg zSHk{7hu^QXIU^m!MEjk0M(-crN9uFmIL=%4U1~>sm5Pe?`en6ee(>HC`S#L{y??u6 vr;^|o8ppUAvD!gdKbRPND1BpVH#|fA;?X5$6$T literal 0 HcmV?d00001 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fb876ae30a..b421f04675 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/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..6744563a11 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,23 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_so = custom_target(output: 'vdso.so', + input: files('vdso.S', 'vdso.ld'), + command: [ + build_vdso_cmd, + '-B', meson.project_build_root(), + '-C', meson.current_source_dir(), + '-T', 'x86_64-linux-user', + '-o', '@OUTPUT@', + '--', '-nostdlib', '-shared', + '-Wl,-h,linux-vdso.so.1', + '-Wl,--build-id=sha1', + '-Wl,--hash-style=both', + '-Wl,-T,@INPUT1@', + '@INPUT0@' + ]) + +vdso_inc = gen_vdso.process(vdso_so) + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: vdso_inc) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..47d16c00ab --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,78 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro weakalias name +\name = __vdso_\name + .weak \name +.endm + +.macro vdso_syscall name, nr +__vdso_\name: + mov $\nr, %eax + syscall + ret +endf __vdso_\name +weakalias \name +.endm + + .cfi_startproc + +vdso_syscall clock_gettime, __NR_clock_gettime +vdso_syscall clock_getres, __NR_clock_getres +vdso_syscall gettimeofday, __NR_gettimeofday +vdso_syscall time, __NR_time + +__vdso_getcpu: + /* + * There is no syscall number for this allocated on x64. + * We can handle this several ways: + * + * (1) Invent a syscall number for use within qemu. + * It should be easy enough to pick a number that + * is well out of the way of the kernel numbers. + * + * (2) Force the emulated cpu to support the rdtscp insn, + * and initialize the TSC_AUX value the appropriate value. + * + * (3) Pretend that we're always running on cpu 0. + * + * This last is the one that's implemented here, with the + * tiny bit of extra code to support rdtscp in place. + */ + xor %ecx, %ecx /* rdtscp w/ tsc_aux = 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 +endf __vdso_getcpu + +weakalias getcpu + + .cfi_endproc + +/* TODO: Add elf note for LINUX_VERSION_CODE */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..ca6001cc3c --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,73 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + clock_gettime; + __vdso_clock_gettime; + gettimeofday; + __vdso_gettimeofday; + getcpu; + __vdso_getcpu; + time; + __vdso_time; + clock_getres; + __vdso_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + .data : { + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0x90909090 +} diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..c873d6ea580b393825506d2ffbddcf9827d89e14 From patchwork Tue Aug 29 22:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718258 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp243594wrh; Tue, 29 Aug 2023 16:25:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZRM5bCe9rfabJ6PRTGkjz1eD/Ad/H+CS7WC9VeLraupD8jzXssTM0JxJn8K5rKNbbaGh9 X-Received: by 2002:a0c:e790:0:b0:63c:f605:48a with SMTP id x16-20020a0ce790000000b0063cf605048amr440305qvn.56.1693351553696; Tue, 29 Aug 2023 16:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351553; cv=none; d=google.com; s=arc-20160816; b=iwy6uOw4dCBABq8e6ssf58++PHvZw37x+QDgZdLq6xoh/ux70+WrWPJsn6bMXIExWW AoOvx83iZEdxRHv+PldupgWoe3Uhj5MhVxTwss6pbW9A8YpggX7R10fV38KYh5R7uveX umwmsMB+tPwy6ijgf21f5T54+ZvR4C0wnD2IXEfsxY67TSMmHwuENvEMuR19H+QTc9/E ZBqHVvnHgaip1bGgx0q303G+gLI5VBZArCHBEwW9jrDEzU6+cqgQEEyh1g5HAQkNfWfz vGlfgQLHAwAPMG+W04tCaOOM0kGcqhbsuNYZpm5djYAFJ2LAJ9fRAWGfhar4JReLJkmX EyPA== 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=pLMtweIj9VXeYhHPPyPr7xGLS4OZL75mnN+1BxZJcQ0=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=oIOwwqOrHsLeKI7aFmM4SeWguu8OclIOnFSz+ShWB6VQ4dIQl3h0+eIP9ZIIehOgr2 mVVnMKB+2mkVL8Q+rsLdHlFBObE5U//fdgW4f3gE88o7bdWX1/mmbEd/TVuCXX3TKk0o pKKTs+/X75PMIzS6o+2oNRAaCMO61M/tl8RPysIrfQxrlmTowhdvVUfJRKS0J5vXNP4t mB5uWVgS1iKrqr7DXBl1SZM8ehJC9jN6Pv30LKmYgIXQfLQFFG2iXOmbU5xrL0HjvQ9o wQl8DWX+JaMIz8GhM4LkfcOEAauntOD/s1g0ZCgw+APlDm9WdWf0TTWW4KoeEq1g4ic+ xwwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CbjjBw9g; 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 q6-20020a05620a0d8600b0076ce7431548si4753390qkl.618.2023.08.29.16.25.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:25:53 -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=CbjjBw9g; 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 1qb7mm-0000e3-Dn; Tue, 29 Aug 2023 19:06:12 -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 1qb6nR-0002Qz-CN for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:51 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nL-0004A0-TB for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:47 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a410316a2so3613913b3a.0 for ; Tue, 29 Aug 2023 15:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346562; x=1693951362; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pLMtweIj9VXeYhHPPyPr7xGLS4OZL75mnN+1BxZJcQ0=; b=CbjjBw9g3IllOGxkZYsxUjtZMrFfuQxgioLEgwjzD1Rbk65uyviyMWkBzx3ndqKcUt gwRXcmMNGECOKDuTAWza/BSITD12KurxQOReExCr6RsQ81ix4xUGCpKvRjjGfGsZLgDp 6ES6Xc2foed6mDDDSJjCVrNghQirJ01AAaP4qAmai4MgU5zgiWXoZ9GpT07yPSUbRlvb ZuopSAdARtBSABfwRHJMDa1Dy4uC+IVlGAx0Xxy2LsNVilxFgDcTMZsAIBy9YENitnP3 YUA4x99xuR9sAVQ1IZnx/6Zk5L01kPk+Lf3WfhDMPihKaQG5D1RFGXIx2+HPYmJGgIiG g7Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346562; x=1693951362; 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=pLMtweIj9VXeYhHPPyPr7xGLS4OZL75mnN+1BxZJcQ0=; b=D7xIXDasXgPJBOWoZYoEyYhH2qeXf7ejf8FVni2Mw9NuCwIi4LpjYpWtz8Fr2I3Dyf TUNFI6OmpPk7Dd3R6ra587EKSnD1ByvVukKpH/+DmEFKAGJot6k3Cg2N0EiApT91eAQe 2xIvAqkidFfGtGtOCQ7xUonfB1COeFlv6T7h2wB7ddHctW9XDmev471sTG918GLovyCJ A94OU24ckI55a3jLXiqOa0HUmpyGVC/CVuY9M6CMZLtRA0NbnUO0eEeIlCHKOuqHHlqq wMm/030+YquV12CPwc/WC7nxGYGwys8cyRAjroUe/pwSPpSiceYLkRFCD3puxAfxSqjN 0bTA== X-Gm-Message-State: AOJu0YymtOb0RczihlY747igprFtuIlJ6RxcJGRBkjVHGq2nOPf8Abyz KIyIrjGAlRs8pMBT7TyOLyaY1PMdWOVjSotSh6o= X-Received: by 2002:a05:6a00:1256:b0:68a:5395:7a9c with SMTP id u22-20020a056a00125600b0068a53957a9cmr564445pfi.9.1693346562589; Tue, 29 Aug 2023 15:02:42 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 13/20] linux-user/aarch64: Add vdso Date: Tue, 29 Aug 2023 15:02:21 -0700 Message-Id: <20230829220228.928506-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/elfload.c | 7 ++++ linux-user/aarch64/meson.build | 33 +++++++++++++++ linux-user/aarch64/vdso-be.so | Bin 0 -> 3216 bytes linux-user/aarch64/vdso-le.so | Bin 0 -> 3216 bytes linux-user/aarch64/vdso.S | 73 +++++++++++++++++++++++++++++++++ linux-user/aarch64/vdso.ld | 72 ++++++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 7 files changed, 186 insertions(+) create mode 100644 linux-user/aarch64/meson.build create mode 100755 linux-user/aarch64/vdso-be.so create mode 100755 linux-user/aarch64/vdso-le.so create mode 100644 linux-user/aarch64/vdso.S create mode 100644 linux-user/aarch64/vdso.ld diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b421f04675..8316868bd2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -768,6 +768,13 @@ static uint32_t get_elf_hwcap2(void) #undef GET_FEATURE_ID +#if TARGET_BIG_ENDIAN +# include "vdso-be.c.inc" +#else +# include "vdso-le.c.inc" +#endif +#define vdso_image_info() &vdso_image_info + #endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..b769c87570 --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,33 @@ +# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it +# is always true as far as source_set.apply() is concerned. Always build +# both header files and include the right one via #if. + +vdso_cmd = [ + build_vdso_cmd, + '-B', meson.project_build_root(), + '-C', meson.current_source_dir(), + '-T', 'aarch64-linux-user', + '-o', '@OUTPUT@', + '--', + '-nostdlib', '-shared', + '-Wl,-h,linux-vdso.so.1', + '-Wl,--build-id=sha1', + '-Wl,--hash-style=both', + '-Wl,-T,@INPUT1@', + '@INPUT0@' +] + +vdso_le_so = custom_target(output: 'vdso-le.so', + input: files('vdso.S', 'vdso.ld'), + command: vdso_cmd + ['-mlittle-endian']) + +vdso_be_so = custom_target(output: 'vdso-be.so', + input: files('vdso.S', 'vdso.ld'), + command: vdso_cmd + ['-mbig-endian']) + +gen = [ + gen_vdso.process(vdso_le_so, extra_args: ['-r', '__kernel_rt_sigreturn']), + gen_vdso.process(vdso_be_so, extra_args: ['-r', '__kernel_rt_sigreturn']), +] + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: gen) diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..b19563b648cc3e33a45b9394695d747f55c11db7 GIT binary patch literal 3216 zcmc&$O>A355T57v+5{-Ysi=q)1g#XIswz)u5h$n}>|m!!<)$HRMcT{OwO?YViH)9L zih~5?z=Z>%s3*h$7jXfJb1N?G0i;U3Re&lXl@n4Wq>3KOr9bY>?#y~^Y=p#tN%nm^ z-^}dn+ud2e5A%iTRLTP@K3u}SLugCJ*oV)vHVIoG18H~$^{v9^IFFKH#BtTHHOQ{@AI9wplKX>5uW8hLCPZyyWXO)_afvt zPLSS@;?mf*9GW`;SFwXaoUePPPkDT@e|7!-C&$uv?_9aC^5d7czWDXKi@WpeN3fmy zrxg`AO2vOhEfH@8NmszJhLP@nW06fX~F5^>-dY|g;_5-5_8A8+_8Xaiu zNtb<@VE+Gra0kFPlQ_7^6QK3ZIs9$rX+Ks*pnaEh7d*#b){Dk@&f%|d0P+7IUJH%1 zzr5bM&wHW6q^_JZtbK^5wzY+&;bq`^*2&Mmc`*9?v*xFNq)(mxVb@Eo+;87xAA(Y6 zqqr8Ws^ut2s%uewsa)LXu%*>{>8#lL&~eo0uyLXq)#W%!*5ewiR%`3cm(P_O^$`E} zLt%FA#G*P7z81dnI?e_Uk^LjhGk;ItxpEOTI?vBzGv}1vC)X5a8Aq>- z7#qb765KeN3yRdY(U8~Y9{HAGERQApnQ&<1ck3^+0AX=wCnN+i%_Ix1rxS#7W+- zv2SI-_&YqCw`={!FtFcyg&lu?#tx46!hrgJ%c*ns9$9wy+dK}f`}+yt+Qg2P{9 z|1^|Jhik7ER%XLGjF(}&2`YDTE_-D5O)NjW_*H&JO)q4RP8yjm$@eE=T8>~pLR!<@b%Nw=gTD7D*=!;lP ziV!Z>*27A%Q89cH8|GXTH>&kom!irLMisRb7uOeseg#`A)!b<~d>?B9E;Zi4Rbl#NYS7*iYg&jqWqTB>r&Ch+0LWOd$gY72BNkeGV(#x;0H@0bFqxB|r zDgixk;Y1K8ZU%9ID-u*(=z#+gH&jr?C8tW2K#(5b)Yi=G&a>A)TY-ec*nj8$H#2|! z{y#JO-^~^B1E~~&9QvAiBciklwuhl1*h$*Q&v80P4>3H*Ev;gkPwHggm`30swMk;T zGAR={>8b`86H!~|wRv~(Du=(NTR~auS~{=IA7z;kxT=M|q<>!Lvw1eOA_9j$u^H#K zkK5_R716pbm?J$V>5DHJi~P$^cZTvA|Eu|5{&?}o=EzQE<+n#zLt18ET-@rRrL{)s5@ZRm?=^d8Bt}f;aF))Xy)9ee+$ z!uj{Um(+z6uXE1Y|19H4`Tr{8Np+;6xLrryR@|-^A1S`4UX)4;OIHe)Yi@(4%QW30 zlYMoP9}MRF_k4YyisRwF#{BV^O_ zo3%#0Z(z#gdR4RP7uP*gEwd&@!A zJ8%xJkZ^Z_J?hqRmdZC3{!t&mw + +/* ??? These are in include/elf.h, which is not ready for inclusion in asm. */ +#define NT_GNU_PROPERTY_TYPE_0 5 +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1) + +#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC) + + .section .note.gnu.property + .align 3 + .long 2f - 1f + .long 6f - 3f + .long NT_GNU_PROPERTY_TYPE_0 +1: .string "GNU" +2: .align 3 +3: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND + .long 5f - 4f +4: .long GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT +5: .align 3 +6: + + .text + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro vdso_syscall name, nr +\name: + bti c + mov x8, #\nr + svc #0 + ret +endf \name +.endm + + .cfi_startproc + +vdso_syscall __kernel_gettimeofday, __NR_gettimeofday +vdso_syscall __kernel_clock_gettime, __NR_clock_gettime +vdso_syscall __kernel_clock_getres, __NR_clock_getres + + .cfi_endproc + + +/* + * TODO: The kernel makes a big deal of turning off the .cfi directives, + * because they cause libgcc to crash, but that's because they're wrong. + * + * For now, elide the unwind info for __kernel_rt_sigreturn and rely on + * the libgcc fallback routine as we have always done. This requires + * that the code sequence used be exact. + */ +__kernel_rt_sigreturn: + /* No BTI C insn here -- we arrive via RET. */ + mov x8, #__NR_rt_sigreturn + svc #0 +endf __kernel_rt_sigreturn + +/* TODO: Add elf note for LINUX_VERSION_CODE */ diff --git a/linux-user/aarch64/vdso.ld b/linux-user/aarch64/vdso.ld new file mode 100644 index 0000000000..4c12f33352 --- /dev/null +++ b/linux-user/aarch64/vdso.ld @@ -0,0 +1,72 @@ +/* + * Linker script for linux aarch64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6.39 { + global: + __kernel_rt_sigreturn; + __kernel_gettimeofday; + __kernel_clock_gettime; + __kernel_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0xd503201f +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 099e5c4fe0..1b265ed365 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -36,6 +36,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) +subdir('aarch64') subdir('alpha') subdir('arm') subdir('hppa') From patchwork Tue Aug 29 22:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718247 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp241190wrh; Tue, 29 Aug 2023 16:18:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWQj3eebpQKav4k9qNWHC/ObNBWQjHZKuG1DOJ5w1SFmZrKOFR4Pq3UhRohTHEXivCM5BF X-Received: by 2002:a05:6358:52c5:b0:13c:dc2e:3548 with SMTP id z5-20020a05635852c500b0013cdc2e3548mr496824rwz.28.1693351090960; Tue, 29 Aug 2023 16:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351090; cv=none; d=google.com; s=arc-20160816; b=Ru81bWOkB50I63SUB6HZOlyMYsZiyumJTRHTeTSapH5uPp0BTmrj1c3YvqKmPd1CWB h8h3uR+nTu7ew+UALfMgetLos5yFUe81s7tp1plkLcnqDLnFDu7Ls7rKeGgV52w7VXUE HEGAWG0RlzmJzdKLUlMxDaZCkoU2EtKbBwMpp5Q9OUjO8fYOvS9F5o5NMuZ3ExWLcIt9 UwNDy5uNGA3QsUyWRjFva502lC1vo6BOm7oqyQb1xvebB0CoTMG2qMUewKwyxZXbkGZT qzv4NA7pnTbL2MrXMGZuVrfX37ybUQCKgb8kVpTnbW33PLUqp5l3lBIJHLjBTDqQ9ck/ cLnA== 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=4P8uKuAKuluc1/WNH9Ak63d99XD9VhlZvaJdI6JNt38=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=BjNZ5/O39qfS0Gz3/PZLUZAE0BqRj3qUHxLiDEXuxsUyWri7HTOIL1x/fv159XWNlu cB1NOhUCGEoJ26DJirzUZ6nptWDmePT3QwY4omT/zNe9OkF2ikvIfCsmh8w4oy3QUyZu ktksnciUGWDeWuW8vtlZV4whY8+wQVK0XhZXzo+Fejeyvpz6zZWPZtcvUDqK+IuywlGX tdkAplSens7QlykAuMX1Kv6AhNfwRE/tk1chXtkHAwwjGu6Xo4kadSO97ElzL9Q3jyPE Ko5+MxIRtaIPFLFTRoPCiTZl1WScSN79a9qkU7NrRD9DvvXu0z7X4iZL4CX+PfCHvLG0 aQyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UC9731eg; 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 g17-20020a0cdf11000000b006418d6e8f32si6870335qvl.602.2023.08.29.16.18.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:18:10 -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=UC9731eg; 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 1qb7mm-0000ds-1z; Tue, 29 Aug 2023 19:06:12 -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 1qb6nT-0002R9-DE for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:53 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nN-0004A9-CT for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:50 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68bedc0c268so4223677b3a.0 for ; Tue, 29 Aug 2023 15:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346563; x=1693951363; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4P8uKuAKuluc1/WNH9Ak63d99XD9VhlZvaJdI6JNt38=; b=UC9731egNHoPB9f/Z9cgRMbC9H5MN/KjbDz6htetQqVfVpwfuSjhC1Zy46wjB6rFc1 TM8abRvqXe5ngOWEVZ1plUjjR7QfU+sH0DLpD/8N37+VDdPh5mxOxPpH/uga1UMx9c6b uIoDK2kaiJnrwpZGtD4nY99iUqHn6rvw13XFSbkABozACUcLFc4PFZfRgrX6JWNUc7US R8g0WRVY0Da3GxEGFHvf6kIDDICQoQTSSv5hGbOh5/eNDDZ7AzJE/TOkAESBp5G6CfqX npC7bAn0oS5PCpnI4UG/y3y2ER9N2O8YJO5EJmp2ldh2Mfof8IRjpMadfjeelbkPtwEP wWqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346563; x=1693951363; 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=4P8uKuAKuluc1/WNH9Ak63d99XD9VhlZvaJdI6JNt38=; b=da7i4uPPAw6kOwR1CJ6AC163UECHtp+vrOa4AkfFUs41ZP/sCLQL7evnX4fKvy2CM0 SJrT/kmhCd30HYxdgIHKV0ZvlAQYkO7iSbMFKmf2QgnwtF3/XfP1PqwmpS9+dnpWWLRc kj/3cdh/tRukGVcHGnoB6pHbi8S7q4/SUxHHT2fJBkDzxTzbdlX6OUXLO7b2c+lEX9iO KwP5oZNaH66o18XqH2gXr89lWYm51eUh9qKUlgEPDrUp52WEUC1NTWQuW7axRzBE8sIJ XkXKV8VGStkNPhPI4CBPrLsKlqs4go082aPq65EuEhZwyBOUCTVAHs/vaxqZqZh2NKpI bgDw== X-Gm-Message-State: AOJu0YwNzEugo2TvLeBoPoT2qyUoPkSmu2KWlj1VwLXx7WlZSQNCSPDU WBrsjECs6wrBgY4idqVFFelgeWfbcjuB73qXOT4= X-Received: by 2002:a05:6a20:8f22:b0:14c:7020:d613 with SMTP id b34-20020a056a208f2200b0014c7020d613mr713963pzk.37.1693346563363; Tue, 29 Aug 2023 15:02:43 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 14/20] linux-user/arm: Add vdso Date: Tue, 29 Aug 2023 15:02:22 -0700 Message-Id: <20230829220228.928506-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/arm/signal.c | 28 +++--- linux-user/elfload.c | 3 +- linux-user/arm/meson.build | 35 ++++++++ linux-user/arm/vdso-be.so | Bin 0 -> 2680 bytes linux-user/arm/vdso-le.so | Bin 0 -> 2680 bytes linux-user/arm/vdso.S | 177 +++++++++++++++++++++++++++++++++++++ linux-user/arm/vdso.ld | 67 ++++++++++++++ 7 files changed, 293 insertions(+), 17 deletions(-) create mode 100755 linux-user/arm/vdso-be.so create mode 100755 linux-user/arm/vdso-le.so create mode 100644 linux-user/arm/vdso.S create mode 100644 linux-user/arm/vdso.ld diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index cf99fd7b8a..c328d31081 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 thumb; int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); - bool copy_retcode; 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 8316868bd2..cd2ab4292c 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -768,6 +768,8 @@ static uint32_t get_elf_hwcap2(void) #undef GET_FEATURE_ID +#endif /* not TARGET_AARCH64 */ + #if TARGET_BIG_ENDIAN # include "vdso-be.c.inc" #else @@ -775,7 +777,6 @@ static uint32_t get_elf_hwcap2(void) #endif #define vdso_image_info() &vdso_image_info -#endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ #ifdef TARGET_SPARC diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 5a93c925cf..6a8ce075c3 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -5,3 +5,38 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it +# is always true as far as source_set.apply() is concerned. Always build +# both header files and include the right one via #if. + +vdso_cmd = [ + build_vdso_cmd, + '-B', meson.project_build_root(), + '-C', meson.current_source_dir(), + '-T', 'arm-linux-user', + '-o', '@OUTPUT@', + '--', + '-nostdlib', '-shared', + '-Wl,-use-blx', + '-Wl,-h,linux-vdso.so.1', + '-Wl,--build-id=sha1', + '-Wl,--hash-style=both', + '-Wl,-T,@INPUT1@', + '@INPUT0@' +] + +vdso_le_so = custom_target(output: 'vdso-le.so', + input: files('vdso.S', 'vdso.ld'), + command: vdso_cmd + ['-mlittle-endian']) + +vdso_be_so = custom_target(output: 'vdso-be.so', + input: files('vdso.S', 'vdso.ld'), + command: vdso_cmd + ['-mbig-endian']) + +gen = [ + gen_vdso.process(vdso_be_so, extra_args: ['-s', 'sigreturn_codes']), + gen_vdso.process(vdso_le_so, extra_args: ['-s', 'sigreturn_codes']) +] + +linux_user_ss.add(when: 'TARGET_ARM', if_true: gen) diff --git a/linux-user/arm/vdso-be.so b/linux-user/arm/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..591db80fe47540707e5c627443ac566d7f2c7c60 GIT binary patch literal 2680 zcmbtWO>9(E6h3eMTiWT=5TvP^8XGYPBfGXI^Vd zPzOb*g0LYZMoBQb)ieeZH^f;P!@{t@#DxYIb)&{;qQ-?de&2of)@kj=c&6Vw_dDm@ zpLg%M=k?|Op|s_*WL5m~0NTco5DDK1R(&D~>5?FP?Gl4O1i-h7D`*n|4bvZ#5~z8Q zupSu$${!7=qD`p&IrqCmB0l&HBn2O#{950HHt0s1X!LIe_YaJW%cD~hJ$pKCTisvo z|KV2P=tGz9zVtqPQDEHbW380xfBlB}_-;Yy6g1w^T7Yf_O28%{R;t(kgue!T8{7x| zGt^bI|F0yme9jZOL!yqDfVYKy=8-2yT_d4$XZ2MWU?fG1#WM^ke+2`zO z$8`&{&W6UliGP{PPQ}=C&(c&bvnVr#;@rYcjvL3{!!mSWWc-M|JH8jIz=p5>EUXj1 z)}KCo7j~ZcT>#J3yqV?yaPD_7`Y39jtWN*qX!ihN1Rj9~tV!r&&@<3W(DTq&pkIQ< zIa}`l5nvhE0b2|Z>-ebnPDHKFmR3^EvlZa}H%l@aIpaIey`+5?@cjn%LD;_Dz&-)n z7eJ(8oCG-MJd8=(IO#++cCzi2=&P-#T3*|9y7^4gQsnjU8=B1#sky;x#_Oo2cP8^Rvc4{5&7}S!*DHLwtg_P#XbfqM3KV;?#Xdj290d6Fc?HNOJf7wv2*r>X^ty4^o$ zr$>{+{q|sLRP2GFgT2Wi`(QeKxPQzZOZE=++YKc{7pOG_W_{6WC`4-t*#)BRc2hUKp6) zNIR7;%-JfSa~$d9<@a`I<{8H0JyLgR0-SNoRmQPi?$#XR@qVd0)|lUnBX}2h&p6(S z2iXD6bx=&)K74~&-x0_AsP1F}e0^N6wlOZ{L4DU@R$}hclNhfK3*)YOQ1`)%2RnW8 zwD}(ZwB|wf!Or)kpX;Mc0UVp-VeizP$NZ~e;#^pC9P0pKt=|`R;Z94B2qP2sqIipsG?Q6`Prl;KQ%uX6*`&hPO^*1PT8Hr zL~2a6w$ax1r7uzo6+xdWMHGA~?vvCaQlt-kQ1qd`h)M-5c~IByyE8XV(mV*B-EYtD zJ@?L?d(PcgyLz*cNJKOl@~~*F4aRHr_=!raO}0u5zGg{F947iSEUV>`5YoBF&xCXbx~69Nt;YS;#C_oNkdrV>5ucTL z!pmn2Z3O+Xx-Buv97A2MwpT_d7}_w}0`FSk`R5;##>WH}|47>3Cjo z+F94Qr|k}N*{Nt-Fw&jK+w(G2EX~aAWL^{BN2Pav|H!Dd+uXxNL{~l$tdyVkKL0hz zcYZIx_e%1gEh4vPJ~HSd>3xc{7*Fnl&NDfRz)|pV@WbF!;7j1M;1|Fbz;A)S3*G=+ z0(JmA52VP;gAzTGinKH)h4X9%xc_{2l1Vk3h@Otnz6>uwVE(tIO{jzV3HA-4_i1 z4N7$-KB3~--~4!WB4lq+poZ!;A_s#)HBkRyG9(#1fp4uty)#0`3*wuo>w*vR=^TvT z1V#6V2=o@{M={?%@F>PVLVvJ6p4g|M>-}K-Fmz4qH;15v`&SuyxPS57h5Ofe=;8h) zx!mmhfHQQ!bfwjk*1TAq&-G{e_IF67I9YbQnR3a>xp~zs(A2H29xFST>Fct3ItRt- z?j2~)^jZVi>`>RRHJoYh?Xp5GBWO^o8qC_J6>3DQ8reEMOZ7J~EA!KyJr3@beO}N~ z$@LsD^YbNpx|mY}V!>_C7IU&RV;1a6!MA&5-!kizD@C`oO0n`{It6Q@Y)?B@A&*F{ ziRn3Wo|u`zKGXKRa&dgd!`A$F;`{cm_J8lv*3j_a=*j)C>AQpHg;)gq6Yk#&>`&VP z-jO^qtRrF!GUHe_%*WobJJ5MFd7g;y>1G_kUd1Y7KGq$v1F}BSI_`1UZU=WU>ycoO zTpQOO*qD#^JHdNh6VfX>fZtk>kM&D%eL5dhwWepm^?!gWj0D%B_mt}+O#sZzapC_n zP!;Jo51Ni+A0Qg_qTthU3qc&;3G1CW3|W)v&rps5NU`FoB5tz|0@tbaoZ58*alGHy mKlq;ms(NqiSb7g2$`TgvF@=D1zGmp*xF@h7XLS&`j{64#seq6G literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso.S b/linux-user/arm/vdso.S new file mode 100644 index 0000000000..ea27cdd9b3 --- /dev/null +++ b/linux-user/arm/vdso.S @@ -0,0 +1,177 @@ +/* + * arm linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +/* + * All supported cpus have T16 instructions: at least arm4t. + * + * We support user-user with m-profile cpus as an extension, because it + * is useful for testing gcc, which requires we avoid A32 instructions. + */ + .thumb + .arch armv4t + .eabi_attribute Tag_FP_arch, 0 + .eabi_attribute Tag_ARM_ISA_use, 0 + + .text + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .elseif \n < 0x1ff + mov r7, #0xff + add r7, #(\n - 0xff) + .else + .err + .endif + swi #0 +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r2, {r2, r3} + mov r9, r3 + bx r2 +.endm + +.macro endf name + .globl \name + .type \name, %function + .size \name, . - \name +.endm + +/* + * We must save/restore r7 for the EABI syscall number. + * While we're doing that, we might as well save LR to get a free return, + * and a branch that is interworking back to ARMv5. + */ + +.macro SYSCALL name, nr +\name: + .cfi_startproc + push {r7, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset r7, -8 + .cfi_offset lr, -4 + raw_syscall \nr + pop {r7, pc} + .cfi_endproc +endf \name +.endm + +SYSCALL __vdso_clock_gettime, __NR_clock_gettime +SYSCALL __vdso_clock_gettime64, __NR_clock_gettime64 +SYSCALL __vdso_clock_getres, __NR_clock_getres +SYSCALL __vdso_gettimeofday, __NR_gettimeofday + + +/* + * We, like the real kernel, use a table of sigreturn trampolines. + * Unlike the real kernel, we do not attempt to pack this into as + * few bytes as possible -- simply use 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 + +.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 + +.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 + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + .cfi_startproc simple + .cfi_signal_frame + .cfi_return_column 15 + + .cfi_def_cfa sp, 32 + 64 + .cfi_offset r0, -16 * 4 + .cfi_offset r1, -15 * 4 + .cfi_offset r2, -14 * 4 + .cfi_offset r3, -13 * 4 + .cfi_offset r4, -12 * 4 + .cfi_offset r5, -11 * 4 + .cfi_offset r6, -10 * 4 + .cfi_offset r7, -9 * 4 + .cfi_offset r8, -8 * 4 + .cfi_offset r9, -7 * 4 + .cfi_offset r10, -6 * 4 + .cfi_offset r11, -5 * 4 + .cfi_offset r12, -4 * 4 + .cfi_offset r13, -3 * 4 + .cfi_offset r14, -2 * 4 + .cfi_offset r15, -1 * 4 + + nop + + .balign 16 +sigreturn_codes: + /* [EO]ABI sigreturn */ + slot 0 + raw_syscall __NR_sigreturn + + .cfi_def_cfa_offset 160 + 64 + + /* [EO]ABI rt_sigreturn */ + slot 1 + raw_syscall __NR_rt_sigreturn + + .cfi_endproc + + /* FDPIC sigreturn */ + .cfi_startproc + cfi_fdpic_pc SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 SIGFRAME_RC3_OFFSET + + slot 2 + fdpic_thunk SIGFRAME_RC3_OFFSET + .cfi_endproc + + /* FDPIC rt_sigreturn */ + .cfi_startproc + cfi_fdpic_pc RT_SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 RT_SIGFRAME_RC3_OFFSET + + slot 3 + fdpic_thunk RT_SIGFRAME_RC3_OFFSET + .cfi_endproc + + .balign 16 +endf sigreturn_codes diff --git a/linux-user/arm/vdso.ld b/linux-user/arm/vdso.ld new file mode 100644 index 0000000000..3b00adf27a --- /dev/null +++ b/linux-user/arm/vdso.ld @@ -0,0 +1,67 @@ +/* + * Linker script for linux arm replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_clock_getres; + __vdso_clock_gettime64; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} From patchwork Tue Aug 29 22:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718243 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp239922wrh; Tue, 29 Aug 2023 16:14:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+v76OII/08K4ImybQHdjZu/JdytX4xtyFBuIWiIZ+kvRbooOUWIoTcGmLYmmnA0V/jt74 X-Received: by 2002:a67:fb51:0:b0:44e:c2d6:cbce with SMTP id e17-20020a67fb51000000b0044ec2d6cbcemr566613vsr.11.1693350875551; Tue, 29 Aug 2023 16:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693350875; cv=none; d=google.com; s=arc-20160816; b=IVLEKjlP0eovqydYZWnyJqauMds19xfwR343/r9GaEiLJoI3+/KrGY3jfskShWjdL/ 7koRwXFIq4IC5umtNyCAd/o/92v1WgmxyFaxBVAX+OLqhIbGktkGIRYWE4b2ij2beEGA X1AwNf9zXJ9wvb2kAXxz7FcFL+GDG0JGg0AEdVdaguYaA2EwBPKhTUxKvXC+IAuQb5IZ i+PYe65KE96Qn6qP38uclRO/fw5Qry2wRwfBN1l2a6/aZN4GF+p5EjdyQLe9ex8mL618 LvemrFt04mlUbsXdwVZKXbyu3N4QTT05cEUPxKe8UUbFKXyaQNSQcfSE9w/kwClsdKFg aWOQ== 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=I7HQy8Pf3V+6dbDojL94FaVgMwfQELi+RTDuhyeAeO4=; fh=yAk+WjNOVgQtt4XdbfUGN19AdnXYnHgxXE90MyVs5ko=; b=GoP+q7XZ1lwoKNqeaClwI6fLdPe/8Lu3uWjpk+FfAhM521bxtt/6VlHkFSP98aMOEg haW3GHYV2YwnmmNeJjHML4SLVksV5pKpDL28nCC31F9EDtdCSXzmIWyeOwXi9DKlVaTI 09dbf9dSIKG80l3LKLgnNJlbWWGfse7lg//V6Cg+6ZdhRIgwrNckeMZItZZzmhEnJTP6 hFkGicGKskatoJr6QZQ5OKpG7N9vCUIq0flyzOrB3aib6sDmJe+mPQvDyNDGJSI+xVya EMdUYcSOjMT+qDB243tsoThTTdGpLtXLr2ZoTT8xZd1cXVK71Cht5PkqNR9Ajrdo3Lnk AhqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tAgT8QrR; 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 h3-20020a0cf443000000b0064facf0cf5dsi4323853qvm.49.2023.08.29.16.14.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:14:35 -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=tAgT8QrR; 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 1qb7p0-0003bU-CY; Tue, 29 Aug 2023 19:08:30 -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 1qb6nW-0002SI-48 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:54 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nQ-0004AP-VB for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:53 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-68a520dba33so3914700b3a.0 for ; Tue, 29 Aug 2023 15:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346564; x=1693951364; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I7HQy8Pf3V+6dbDojL94FaVgMwfQELi+RTDuhyeAeO4=; b=tAgT8QrRbQeD7o8jv5H6gLqrlfov22XPJtNZehW37Cf2+MHUeR+uqRIgTG2rw/Iw4L RYKynx5VmwcCC9fa73T4CObdX/N9nie+wrlIc+Fm8C51KWlrneeKMFDBmCkYuislS1v8 VVrMEb2uwKCY7CaB+sABmBVQCt/ncmZeuvsS7NQfgROHgvJgjMX3lPQt3PPOVDkg8+sx OtHCSK9VbvjIUHSuUDhs/sPekSsKAhAmZFtFVl1f0VOezVLxkbvz/+1xPGUOL7bb4eYM Ci+2t+oYblfATOFwDoN7VOnkLGCpSsDodxs5EiH6oiH1ZOxQSVGa+t0SE6yMSPtFp+dn Yy/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346564; x=1693951364; 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=I7HQy8Pf3V+6dbDojL94FaVgMwfQELi+RTDuhyeAeO4=; b=lKbMnfB/mSaJdkkM3/jj7lyDl0hTieCJ6SHT7c0t3ItVeRmfGeJakARZop776BEQ6W DE7EBE+0XOLNHmISm7RMLNxpmohbkPpqA1oQDNj1J/x27TRRaQafSUMzjWYUDXjc59R+ hR5aJVqcIjFjmnJxvk05xcSiGanj5wZAn9qS2HK1s+G83dKst1Rs71Bvn9VMGv0cicrE UICO7Waa0Knphacx65k7SDzkkP9Y+WAkqp8KjgeAfRbRRCldwkQ0ui02uIUg73CaHWJM jnxJEgaAaa8XGiYql4pDkxMHxWK57gVrZwyAEKg8ZYlmkxRBY7Zb/mtAv4Ovc0lLvRia 205Q== X-Gm-Message-State: AOJu0YxWdplY8wFD3FBzFpUpUpYkS0tXgMuy5sZQxSYdpg7ivdooamQq pJ928Nn+Mwr84uLE9OrS/hjFmvDqq4hu//lt8p0= X-Received: by 2002:a05:6a20:9742:b0:11d:8a8f:655d with SMTP id hs2-20020a056a20974200b0011d8a8f655dmr573756pzc.4.1693346564174; Tue, 29 Aug 2023 15:02:44 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu Subject: [PATCH v5 15/20] linux-user/hppa: Add vdso Date: Tue, 29 Aug 2023 15:02:23 -0700 Message-Id: <20230829220228.928506-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/hppa/vdso-asmoffset.h | 12 +++ linux-user/elfload.c | 4 + linux-user/hppa/signal.c | 24 +++-- linux-user/hppa/meson.build | 23 +++++ linux-user/hppa/vdso.S | 165 +++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 77 +++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 2104 bytes 7 files changed, 295 insertions(+), 10 deletions(-) create mode 100644 linux-user/hppa/vdso-asmoffset.h 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 2104 zcmbtVTXR!Y6kaFkhEgcBP%l`hafWdil!Lv1RY03GNz;<1rD7>6(0JUG~~*U)EYXMdFQ(BmGb?r%x-$mIFC+3xTU<+0?(1N%-~JGte| zwo#0&1h`Mkv8G3g7ybaBfv&)R1jiYzaqu#r23QVo^SCSe7yscgz|X_x1OE;7zacM{ z)|dd5Qv4kHJ82ot+=CYbD;A=;?E| z+O@bm6U{_s6$j@&=K!(p?Mg~X zNxxOSx@O|YQQtBD{UyiM14~XUeXw+5*+XR~mp{DXk@8b3A6<32;<3udS3j}l$*QL= zd;0Qcu9&>?*|pDI^?daU>t0;{Qq9X(zY>_*^y+o5UH|&#H|#gJymiCdwbOO))W6&C z-q!cGeQ@K4jUV0g@y(xX|8&P^J3qhW%&lKEeHlC(`l|Ws@Hdf}=(jE3#lCMHW; zONHX9xm|@5D$=2%ovLNGigl^hq-yI{yLwc7k81B#i9XfQuR8at-M6W(+g0)o)qSVx zanzoDsyC(j22_8Vr_*Qt6`W`0eJzTL#S4K_@ijH9MKe`ddw-H+LR}U|=Qy2(>V?rY z1fBH)(sj*o{IovBFBJ9<$eQLCI%^7~`+_?Ao;v%3I{KO9);;u6S9h0zzRc5gxj|&Sy_i8rNTu72w>n-mm4>KjyI4HF5rW`17r(z$)~w!;~p-Ow|1nqfFBMc>aU8q_P9)|;yMpZzCl>C4=|Coz%^Y;{L;DN4)bKq{t{_fJydxBhI~~zzGScmI z2Sf3Qv!HS8{Ndq3>MpVKg`CR=jg%cJWW-J%&ZdTk?$!c)!Bd5l*!#1i_FyVM=-LZ8 z*K#P6%MXoY7bs3z?98AufIVfL!8AOLCUzk+R&dYvKfl%RW1g54)&;QvFy!T2u7QF1 zMOrSt&AewX$GSF{-%SAXhIp(aT}uJz^keQAkM9EVqIJY$eh5<^kS@K|J0P>p7;oBz z?knzt#CSv_-q=6E={Ms-0?_~K7xHZML!Ihc<@;@jdnC0XUJ;yrc(-*8a~%^8c8*D} zdE;G`CSg6AJLMeG0KnLAF#k;p-Us8y>={4wf$jxe@351M-+hqjhn)DwT}TsjLrtFG t#WH69ET#p-{eR>C0pl?r>_u}nn&