From patchwork Tue Aug 8 21:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711580 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2882111ltf; Tue, 8 Aug 2023 14:10:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIDXNwRDYrFH/UtmCoMfJU3RyZc80Fk2flZs+SnGzZ6ZWxijG8tM6WCtKnpUrVTySRRM9/ X-Received: by 2002:a05:622a:87:b0:403:66f7:ae66 with SMTP id o7-20020a05622a008700b0040366f7ae66mr1273273qtw.13.1691529059207; Tue, 08 Aug 2023 14:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691529059; cv=none; d=google.com; s=arc-20160816; b=MkC1Pa3p3G8oCVUGrsMhdL0ooNl1a40IvpHyUrzlSsgJwZdI4bf6I2p8u66HIEzq1C nWAu0Tw8GVvdqErzNqMCovTlClSvuMfKte2NXOf8tMVjPxgHjt+y7iDXLVZuStn9m9DC zzsQgN+KzYyhtEZgl6e6z875Yac0vRP7DFKb8CdF5bOun7uogDQd5bFrtMsDteAY+dI2 eceP5duiDZJaaZ03+3gb/yptowbNa5FxlLx26uM3qHnSumX3zIfMFNB4qa8eJvksxSMe gZpZF372PPY1ZvRpc2tFQX/dAz5WJafedIi2fkTV6xSs+RD924rFIAdl00JuWysk66pf qgNw== 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=mVgimCTGuUjAfzzKq6Eqz3lfGX5YOiTLny3wMx0dHp4=; fh=9PWVySHAdMbaJwSH2JIu1yvgc2H4HTtBBPJgaJCWFJQ=; b=gYKy9v9tneE6Omjd+GmhlDChH7GjSObxTSCjKWCXLSkg/MUMCZGQRuwxqpyTOWEtb7 CZK7M5vb96Llle9gICz3Cn3oIA93/CT0sGBV46PI9W7Cs0OQAi1TeKVQw+x3VzidZWjQ CjIOtKtX7hHQC1hxtIF0I/Gso/CRxJkhr4IaFpn6xJsFlkdVlJmgHTOjLvbXi2PAZnKF v6P5/keW4VYF2FT6AOAr1Ic3dU75VHS5zMOfhjkfBLCnjx8dQbeRMtWUIhX1kpwY9ETM K667FGSrOPQ5AzzxdKnPMvyRE6K3OZtsiXqp0IoESyPwip+yod+iiAZ4fhGa4UOgivws krlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TnDVQbCc; 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 d20-20020a05622a05d400b00403b0f6661asi7303091qtb.94.2023.08.08.14.10.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Aug 2023 14:10:59 -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=TnDVQbCc; 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 1qTTx0-0007iC-9m; Tue, 08 Aug 2023 17:09:10 -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 1qTTwz-0007hZ-6R for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:09 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTTwx-0005ws-Bp for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:08 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1bc8a2f71eeso6595805ad.0 for ; Tue, 08 Aug 2023 14:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691528946; x=1692133746; 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=mVgimCTGuUjAfzzKq6Eqz3lfGX5YOiTLny3wMx0dHp4=; b=TnDVQbCcwnxs52vKgqoQ3E9lHmxLc+ApFqOoz6XxH+pysU5kSNF2akLXTgw9d6Opxt l7boMNpddTX0+0BkRZ41RdTZsR8aW48Yj2Dqul9fVP2RNLGuZNyrJD4jtxiwdqy/CrSQ XmpQ/iRsYK/xHlv4/1//kHgSn1pA/9PT+kgXlm1f/Pb/YScQZFIKLih4hXupSfMXPiaP fE+g/RnPyk8wqjgHq1isFiIs/tT0ULHwsDONDucNupIZMngqSKRKDPMj5odeIZBWMqnU CFL54H23gH8RqPSb+l3glbGcKel4xAQ5LsDbHYqzs0xBAF7eEw6wISoCQptPWP/D5Wgh Nwyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691528946; x=1692133746; 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=mVgimCTGuUjAfzzKq6Eqz3lfGX5YOiTLny3wMx0dHp4=; b=cdDI+NlicomLTJL2mh2AK5KLwLVebBJLOAQvcqqzZN0Fnqq8nlARhx5JrvtQxklu8d EBY+sueHPKEttnYbCpzdNJX2dQlYoxAHDjweH8RgNjYXHtS/9grQrsE9pioIFN/b1bjh Br71Oofr0I1wxyrpPnd8D/JDBJ/EVFbIOcC/PWyOCPEJf8CYk5gCHBNBoXXYYH4dW4Sa //Za75vqhhCPbl/S9iD9B9OPB0TYK7WVUDmH5G+QPIZ/mM6MqtJc4IjOz9LGADIabhyc BE3iZH5R92SOkV8dew9RfrBydPf6ZZh+WcZVbz5uDQClkbflQqIbe0ilqaoCO9tsyQ79 rXBA== X-Gm-Message-State: AOJu0YwcMASGe7x1kbYm6abwSRKt2WVV82t00VbfiDJH+wFf4cpiLYGy okpGGSDOLoFFtQYWR/KjautolxqhcT0SMYhaY+c= X-Received: by 2002:a17:902:d904:b0:1b8:3dec:48de with SMTP id c4-20020a170902d90400b001b83dec48demr758807plz.47.1691528946122; Tue, 08 Aug 2023 14:09:06 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:63dc:2a47:f4bc:4a95]) by smtp.gmail.com with ESMTPSA id k11-20020a170902694b00b001b3fb2f0296sm9437533plt.120.2023.08.08.14.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 14:09:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 09/14] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Tue, 8 Aug 2023 14:08:51 -0700 Message-Id: <20230808210856.95568-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808210856.95568-1-richard.henderson@linaro.org> References: <20230808210856.95568-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If p_filesz == 0, then vaddr_ef == vaddr. We can reuse the code in zero_bss rather than incompletely duplicating it in load_elf_image. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/elfload.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 881fdeb157..e72497c4b4 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3208,7 +3208,7 @@ static void load_elf_image(const char *image_name, int image_fd, for (i = 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { - abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; + abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em; int elf_prot = 0; if (eppnt->p_flags & PF_R) { @@ -3233,31 +3233,18 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = eppnt->p_filesz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED, + error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); - if (error == -1) { goto exit_mmap; } + } - /* - * If the load segment requests extra zeros (e.g. bss), map it. - */ - if (eppnt->p_filesz < eppnt->p_memsz && - !zero_bss(vaddr_ef, vaddr_em, elf_prot)) { - goto exit_mmap; - } - } else if (eppnt->p_memsz != 0) { - vaddr_len = eppnt->p_memsz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, - -1, 0); - - if (error == -1) { - goto exit_mmap; - } + /* If the load segment requests extra zeros (e.g. bss), map it. */ + if (vaddr_ef < vaddr_em && + !zero_bss(vaddr_ef, vaddr_em, elf_prot)) { + goto exit_mmap; } /* Find the full program boundaries. */