Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2251817rdb; Sun, 4 Feb 2024 23:54:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9xn8rWft25LJcTemdLXsJYP3wPzvIbHkOGj713B08YbGFNY27xNBzIhdEPdPM/io73wYY X-Received: by 2002:a17:902:c412:b0:1d8:f202:2e26 with SMTP id k18-20020a170902c41200b001d8f2022e26mr20591166plk.48.1707119678448; Sun, 04 Feb 2024 23:54:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707119678; cv=pass; d=google.com; s=arc-20160816; b=ZcNGSqpcQq1nVjp4xyukhMlT+vU8gJ/LqEcb6SJmewB1etGKpsYOY6oipUC/cqE5Km 3H6XmjRd8YmhCyyfxq6YAOXR5dg4N75g20tVejJZCfX4fV7GKT1rH1gvX/ApLb01jogk p8rnS82xW9cVOpkV6tatnObQYLbtYM9c6efpjXcoJjeNzGaK3/jIPlcZ66F4/s2xPCB9 ly974JpdQmF0hk308iRzaH85glRz3/bJQ/99GnK15NwdEXKQCJttWd0PlvdPxEzmBplu Yelzqx+fr8mgnJ/3BM20T8KMG00fYkp4rwV6E/e/Gn4WPWhcFxKiViTBkPDhstzMJxfn PviQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=WZfA7yTW/uZogaGxkCysZlx0azumYg4f0hrpQFRU/mQ=; fh=jtstAO7vIw6slMfcE8OrqoJWqMeF5WwWhR4/CZJQWZE=; b=QTfiqQvgvtmagHZxLmI8zRPWjcxnBo8QembbcglVTPSiv2z81ExxgMCNcwOtEJdu9j zfLFf4F+ywWJDkq96nW1AyStDNxojEGNcnzV0CRD/mNCxlA6KFqWn2M901XDDXQLhj1O ch7C5+/1NPrwLjliFMgQGaq/KccftShoNXxvBZDOX04MhRagxk9PqAukwI/zvdKXlyPu yZED4w+NgSR2DIanYs3mCerV+uAJ+iSyKb01W+H7KSYLqPxy9AgBu9jdRfUKAW9UWjht AW2Xh/Qj2Vn7SojhJGLC9hDmHvq4fx3Nfn+Pv76WAr+VglOdssosw2Y5ebYv7vwEAUbD BFFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T0GhAJkQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-52161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCU/uSosRfW/QWeoZ+dq3ItrLkoX+7eOxPqi6AoASh8H/U7HZmscuN8BUQolD0mqEeFjpPMIOqbdB6VmL4vtcPoKmUIjYssbtgZxcloLBg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id g1-20020a170902740100b001d5d6d4c2b6si5782893pll.566.2024.02.04.23.54.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 23:54:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T0GhAJkQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-52161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9A84EB20C83 for ; Mon, 5 Feb 2024 07:47:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00FE210A11; Mon, 5 Feb 2024 07:47:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T0GhAJkQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 173D610A0F; Mon, 5 Feb 2024 07:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707119237; cv=none; b=kjm3NdFFHs0pik8RtiITA9DGHjkBovB20yfBDVSThftetjeII8IGX7YTttEXaD7c9D6F1gkn8mnZlJFTuPOwerHmnhUIIGdAEwnpr16QP1zmc8OFAqZHCSu5MR5ApUrKxydEe9DI+T7ko6pLgMdTAQgBXmk3Gu6F9OTXc/1o9tI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707119237; c=relaxed/simple; bh=SCWJBXw1oTKDsvcQutBEiqdDOJsJRN2Zly7jD9qJ6ZM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=H2XiC5NUiFzZTfURLMl8SVd7BVL/rbSr9JUp0skfsOQQ7lB3FzeyDtI9z7SjZ45l5zEHaXBoHwCrdUFvmE39VR8bckioQyDYG2T7rE8BQ3UN3lXqdI4fVAfMDtcqDrkCnZyVKgLCD4Ph6WIkliJTZtZ405o4vhgaZGLxwTjmuJU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T0GhAJkQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 879B0C43399; Mon, 5 Feb 2024 07:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707119236; bh=SCWJBXw1oTKDsvcQutBEiqdDOJsJRN2Zly7jD9qJ6ZM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=T0GhAJkQXt4uafhc+pThqoyJO6txYLDKJ5U6542K3xQ1R3An40ocU0z6g/+q0lVVn 4p+xvUPoMLau7jfAtqv385h1z9HZLIwWHUrD7U2UYJ1KCPkpOz9cCb8ffRIlUDz7HG Dftfq12gFITiL0Vy9RwLWOnyfrronswAzXgM5lnppXbhI0JqTVHkNC1Xyws6gGAogK Pk7rBVXS1L+TPrbg4OvnqFkWkko/saSxR65u9sygM8JlGHpzip4Z+Y7H/VNjByMsOe iPnV3NzK2B34s+s+omRUVIOgBVh9I6GGqxL7Qs9GY4pQbNvR+tTrNUmFqi0c/h5yFs DCiqmkL1cVfSw== Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-510faac8c57so1919690e87.1; Sun, 04 Feb 2024 23:47:16 -0800 (PST) X-Gm-Message-State: AOJu0Yyph4vaqD3XEncTpbDn3VOXnypOe7MnwgUvX/uZdJY/A+ExsLIP Ttac+gap9hWuys4oK9gB1mMTupe2Pho0NPzyCCjZshjDdaJ36koHCxkNW9KCLIyzSWGqHT/cjk5 AvY/NFifGHkzkzA8iRJFpwR+J3Yw= X-Received: by 2002:a05:6512:1151:b0:511:5467:4fbc with SMTP id m17-20020a056512115100b0051154674fbcmr231223lfg.23.1707119234700; Sun, 04 Feb 2024 23:47:14 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Ard Biesheuvel Date: Mon, 5 Feb 2024 08:47:03 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Broken section alignment in 6.7 and 6.8rc EFI stub To: Mike Beaton Cc: Bagas Sanjaya , Linux EFI , Linux Kernel Mailing List , Ivan Hu , Jeremy Kerr , Peter Jones Content-Type: text/plain; charset="UTF-8" On Mon, 5 Feb 2024 at 08:37, Mike Beaton wrote: > > On Mon, 5 Feb 2024 at 02:06, Bagas Sanjaya wrote: > > > > So v6.7 onwards misses .reloc section, right? > > > > Confused... > > Reloc info is still present as normal in data directories, e.g. > `llvm-objdump -p` shows NumberOfRvaAndSizes = 6. Reloc info is taken > from index 5 https://github.com/tianocore/edk2/blob/master/MdePkg/Include/IndustryStandard/PeImage.h#L128 > . (I've been told a dummy .reloc section was dumped recently?) > So there are a couple of things going on here: - the .reloc section was indeed dropped because we could not find any evidence anywhere that the reason it was added is still valid; - the .compat section uses a non-1:1 RVA mapping, to avoid padding, but reading the PE/COFF spec again, I suppose this is not compliant. Note that objdump looks broken too, on an image I have locally, I get (llvm-readelf -a) Section { Number: 2 Name: .compat (2E 63 6F 6D 70 61 74 00) VirtualSize: 0x8 VirtualAddress: 0xB82000 RawDataSize: 4096 PointerToRawData: 0x4000 (objdump -h) 1 .compat 00000008 0000000000b82000 0000000000b82000 00004000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA So the .compat section is in the correct spot in the file view but not in the memory view. Given that the .setup section is not relevant to EFI boot anyway, we could try to use the same file mapping as the virtual mapping, and just split the content preceding .text across the .setup and .compat sections arbitrarily. Could you try the below? diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index b2771710ed98..f8b48ff86dd9 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -106,8 +106,7 @@ extra_header_fields: .word 0 # MinorSubsystemVersion .long 0 # Win32VersionValue - .long setup_size + ZO__end + pecompat_vsize - # SizeOfImage + .long setup_size + ZO__end # SizeOfImage .long salign # SizeOfHeaders .long 0 # CheckSum @@ -143,7 +142,7 @@ section_table: .ascii ".setup" .byte 0 .byte 0 - .long setup_size - salign # VirtualSize + .long pecompat_fstart - salign # VirtualSize .long salign # VirtualAddress .long pecompat_fstart - salign # SizeOfRawData .long salign # PointerToRawData @@ -157,7 +156,7 @@ section_table: .asciz ".compat" .long 8 # VirtualSize - .long setup_size + ZO__end # VirtualAddress + .long pecompat_fstart # VirtualAddress .long pecompat_fsize # SizeOfRawData .long pecompat_fstart # PointerToRawData @@ -173,7 +172,6 @@ section_table: */ .pushsection ".pecompat", "a", @progbits .balign falign - .set pecompat_vsize, salign .globl pecompat_fstart pecompat_fstart: .byte 0x1 # Version @@ -182,7 +180,6 @@ pecompat_fstart: .long setup_size + ZO_efi32_pe_entry # Entrypoint .popsection #else - .set pecompat_vsize, 0 .set pecompat_fstart, setup_size #endif .ascii ".text"