From patchwork Mon Aug 7 16:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711136 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2127244ltf; Mon, 7 Aug 2023 09:37:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYwjdgqZzRNSliJBGkLforMUr98rIySoWqJ8o3y/xgUHedqMAPqMbzhw0/4G+CY12nFtt0 X-Received: by 2002:a05:620a:3727:b0:76c:a961:5ea5 with SMTP id de39-20020a05620a372700b0076ca9615ea5mr12852313qkb.70.1691426268967; Mon, 07 Aug 2023 09:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691426268; cv=none; d=google.com; s=arc-20160816; b=H3vwen6qAYqeFSq63yGFrMQNrkqn09rLTqWZDY1aXQ39oXfEwDygpubj7jgvu4yXpc Zd3gGlzCY+YHqP42vKLaU3OVZZDtVbM0PtMq65hK0CahX+1ZPfpbqPJOXML/0UrdeuWX qKjvhB+xdPX3r3T7xJk6tKRVKQVWDiP9/f45FWyHQ/M2kP3dvPrClFCl43DZHDaGLylw ABMY3Xz5DbkcIONPG3L2FNSLfBlH8bvlFC6hz9g0EiNkHF8LbrTM39C+YTkVorBoGUNP CrVd21EzWXyQXf80l9mYhQsvHxNCW6ugHQ9uwOhjpL5/8zsI91p8+mf2dqmsq9PU/6xY 6EzA== 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=Y+mZZ88pcdw893U+hesCVPS8DRB2GmOsmcmXPqFY2jE=; fh=eYV+9QhSqCUYQJvtNbbWH67WkoSCLPz+dOVCBJL5cVY=; b=mnbQAFXxBiHtYxZ+Ew6r1lixmlFWxUPoBmCHv05GYyNcwaOsybBf7m3Hdt3cNU2p+1 bAtQQ3eMoQfjVJ/t98azrJyP3HSJtT8PBTmOD9VQk5T6qiywd+zaUmIXvZLLRYezuzMm wXKfJwTKAmRp0toItmb3Q/ep7eV4UHcWXy5qvnuDNZ4IxdJgJRa93WJackxEUA2F9Fcu 3K2qXYw0neXgA9RShVYJLhnqO+aJsHiZhjTLD2inN7BNl/nNZ75HZWMKTAgnNpw0bKEt Tv2ZGJd5uYSVh+jFw/sSOX26QtUrdACYsI2D7AknI1NXhqOEa7rUCnaw8W1KPDGHZ/FU qx3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LAdWI4Bv; 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 f10-20020a05620a280a00b00767eff18f66si5186605qkp.553.2023.08.07.09.37.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Aug 2023 09:37: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=LAdWI4Bv; 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 1qT3EY-0007VZ-Th; Mon, 07 Aug 2023 12:37: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 1qT3EL-00075k-DQ for qemu-devel@nongnu.org; Mon, 07 Aug 2023 12:37:19 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qT3EJ-0002hc-To for qemu-devel@nongnu.org; Mon, 07 Aug 2023 12:37:17 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bc7b25c699so2821165ad.1 for ; Mon, 07 Aug 2023 09:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691426234; x=1692031034; 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=Y+mZZ88pcdw893U+hesCVPS8DRB2GmOsmcmXPqFY2jE=; b=LAdWI4BvRcfFZcUbI/FkufRUEHGCXJICTh669vZNEvlcp8YaUs+QwEc0FtOHOT2p9i 8qqrGQNRxPMUatTKC4w4JlAH1sLZ1UT8OtyVNrTxud8LV46HnSpTLdeBMrwS7XQKMjsu XUJVakuTSQvXWP29UlV0y1d3fnIhUXDU6sCfclDj+csfjECF751ptunnSF1gfsXm3HOF 2huBl03YBef99FOLItStXg6ggqHuxJhFXuVWlIqP0uYNau6rT9wD6yQeEoc8OPBcq2XE b/K58hsmjfYMpLLU710lw9bA9C0lalcvJKy+h+x0jD1gTXBO/Gp3yljJ+kfMyxsnsWJ9 lHOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691426234; x=1692031034; 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=Y+mZZ88pcdw893U+hesCVPS8DRB2GmOsmcmXPqFY2jE=; b=epK4qxjItBk81ZkZ06ywzfA8tIPbyF34d6frawPL+5mk3mImApJOiHNjlKY0RVHeP4 pYCt0JfcAdFXWTwmQkvU5H7hLsmGTaTbD+xoBWfh4GKyc7RmhrIl5C60lgZUFZUafuwT 6i7cB/FdUypruYqJxatFo/dvoPIyeurOumSkf4ldKeE43vBS9nUFtBhiBsBBobYKgycG Gwp/oLMswUN4+qudy254LIGBpj6vvgRzCHHfosEZvCrgn8TvgQQUMLpyg4FNVsqQXYcL VN+mukBPm+X6CtnG87HmH3shnWoCVhvNcZ3IczQAXbE3weNyINWg4kEVtT8UkeiSXHP5 3NPA== X-Gm-Message-State: AOJu0YzOzRHsL0jegGwV3iYK0mcsQTEP7E3rKkAvZOJRR+BT4yO4Fcc4 407kkEdBgfHGuLB1YMVKCpvw3rr6xpaRXuJAUVw= X-Received: by 2002:a17:902:db0c:b0:1bc:7441:d81a with SMTP id m12-20020a170902db0c00b001bc7441d81amr1924036plx.6.1691426234670; Mon, 07 Aug 2023 09:37:14 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:e306:567a:e0a1:341]) by smtp.gmail.com with ESMTPSA id l6-20020a170902d34600b001b9df8f14d7sm7119837plk.267.2023.08.07.09.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 09:37:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, laurent@vivier.eu, deller@gmx.de, Akihiko Odaki Subject: [PATCH for-8.1 v10 09/14] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Mon, 7 Aug 2023 09:37:00 -0700 Message-Id: <20230807163705.9848-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807163705.9848-1-richard.henderson@linaro.org> References: <20230807163705.9848-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- linux-user/elfload.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 6c28cb70ef..c9e176a9f6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3210,7 +3210,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) { @@ -3235,30 +3235,17 @@ 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); - } - } 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); } /* Find the full program boundaries. */