From patchwork Fri Aug 4 22:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710264 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp231577rwb; Fri, 4 Aug 2023 15:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPzU+kIMU7QvI8KPPAjwboERuNh8KZ9qaTpjqsGM4pOyO6ziwWhkmcd20HCgqvmwGeBENx X-Received: by 2002:a05:620a:4707:b0:767:e807:e5d0 with SMTP id bs7-20020a05620a470700b00767e807e5d0mr3630238qkb.60.1691186809108; Fri, 04 Aug 2023 15:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186809; cv=none; d=google.com; s=arc-20160816; b=Td/oj1KyFiRdSONSrUbqtIwkLPES1yCVnyukpt2rckq+IyD1p8Mc//l06ggahhKlHk UXqQW+HV5kUITEtYdCP0jbvVNWSkifKHOsO0QpNKkzJuvW0S2UfkGUKePKRW0ja8jsYv 2d28L6SigBgjv0mWutqwMFI2ceQgMjW9cbukDwapMwmd7Rnxj2pp8c1jusFu/gCAldmA pbB8Ht7CXSUiS5P0bZJDLQzeG0pJQ7WvHxcYcctMa8COKpGrsktRRk0Cddo3fCKqaa/h sEdwqaDqzpKyTG1zxqZpIrgb6qNYKcg/u/KaYI2ZlXgQlL653wiSscl/e79jBRZdyuQU 59KQ== 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=huskeRM6ExVZUoYAZp4mC/pVAmNkKT1TgboJ92h4fy6FhgbySug28kPNflEgrSL5be vzopWXDLv2QEdLJVunLcvzb+1tRUwsAXYkl+P+fp4t3VSy2vBGo++RHWEDtuWXNPnPIZ gxUozI0mtjXgkF3vDb48pBmxzrwZCL66wKosAyDvl4h5Py8ryhiZ/3PsMQRudfe8tG0p qg5efq/mjh8bxMUbHMHlAYroITMpl+IB1GFejvXGgLkcC5UwWMoV8uXiRjcUcd2gpIiJ zkLY0YyP3vMURNIRNWb/u5LycC6rVDbYCv7mfRyq/zXAMYoUU1zyJ51Y+0UVxnvRTedp 9ufw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2myYZA0; 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 u7-20020a05620a454700b00767fd0121f1si1985417qkp.252.2023.08.04.15.06.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:06:49 -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=D2myYZA0; 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 1qS2rO-00053u-Ak; Fri, 04 Aug 2023 18:01:26 -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 1qS2qv-0004ma-A4 for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:57 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qs-0001vr-3X for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:55 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-26813cd7a8aso1718601a91.2 for ; Fri, 04 Aug 2023 15:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186452; x=1691791252; 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; b=D2myYZA0FnTgN3xdV/0JJ+PQg4BxOJIOoE/mCOhOFFK9OPnNQMczF2h28Eq6OE/6U4 yCd4TvWIOd+k3GZgDgYAsWzGCbf1tQN2ZnRXp8TeD0IOaRFqc7Om1XN0ZJcvpPvz1w9q Do5XPGuPXwFBtuFQh9+PjOvKu0+8z1jsUYaVzKmKWLz4miOskdxmrjyT5bjRMzyqqWL6 ZVBECEKIXw6yADfdltNVZuhJaWMEs8T2HCUbindSWg+FmoJy5kFs3mf1sKrRorfBq8Jn iLAxsUpaDNtFogoEJTJXPm/Hu4uRGGZwcRMMl8wyCd/brnM4VBMx1Wuw5ziHnrmNT/7/ qj6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186452; x=1691791252; 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=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; b=QqL1QkBoGPp8f3aVizmHdhDLKWzlCYsbAAIUtAsC0TeFEm1yQ5tkN8kBuQ0YnkkGb1 LtkJIHk7vecFyz7nVOwdaOmgMf3nrDx3/V5YgpTtNJHg2BodUB3a2snABD1YzjEtr7KX F/CepLwiFCeqjJdz0eT2c2Dvq/b6foF+J7K4DoCxn/CPY2cC6CK7BDID01z+RvJNFOA1 Qf4+xZr0Zgrbu2MLx5yzEF2FgApEbKUFPrhwNapJ6y6L36yWcLXRTF8bbpndVHechtck pjW5j7JdQ+UfOpVrZ65jgy3QQOG1aNPcxuCcsCdqRfeX+R18E8wqfxUe0YNEHOhzZpbs pV7Q== X-Gm-Message-State: AOJu0YzQCRUpVKKm0CVerskBCmLJomDvtGmC3BTzdG69IEWiQornVIsb Kz3dPKPGhEsPg+fN6ADoB2St75mRfd0qivo6b0s= X-Received: by 2002:a17:90a:c7cd:b0:268:5c3b:6f37 with SMTP id gf13-20020a17090ac7cd00b002685c3b6f37mr2927327pjb.0.1691186452517; Fri, 04 Aug 2023 15:00:52 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 22/24] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Fri, 4 Aug 2023 15:00:30 -0700 Message-Id: <20230804220032.295411-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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 --- 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 66ab617bd1..51591a1d94 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3209,7 +3209,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) { @@ -3234,30 +3234,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. */