From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 1699D3858C2C for ; Wed, 22 Dec 2021 08:57:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1699D3858C2C Received: by mail-pg1-x52b.google.com with SMTP id r138so1530511pgr.13 for ; Wed, 22 Dec 2021 00:57:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+gy0iIdKo0S28IBoDwn9sy4PuBXoqLZ/ULjNpVUkA/s=; b=3muDCyXhx/ZFCE/708nw3T+oeShnoVm6dVBInJE6sTvaZufheETiL+KhoivYvQUcJj k9H7yrnI2ynfPFH7cdctC8sUqkgJgtorvV3WCAKbcT4nKyVQ5e0SPbw4uJkObA7oAPnR WIa+qkJSvzr2xYlxqQvqfQs5XyclZXyKvHsqhcR15AAR/6weB8cf8yV10AUGhC9YYQxO ATgGc3ZBY3Fq0PNhuLSZU7/ETWgHFdZ4LU1P9iZhqIZM0et9E7cdvkexzVywaw5uUlij 4nK3rQA2Q5/pj3T/egcDNDsqt7Q9ct9R5Ouq3+gNDO3mxx6cuG1bcc9PqxRUc9X/mktq FPgA== X-Gm-Message-State: AOAM532Hdg8kRS3IlpDzc1VKOB1KCpKYEdVwhOxw7/MQBc5OOSTJXMg1 gPJIHdCt9RMlZFYmHonNvfk= X-Google-Smtp-Source: ABdhPJyNIMNx2YtWAfCdu70UZseAQIYbwjX3LbkTrpY/mUmCnXUoSXdl5XogLb1nGT37uWzQPXkLGQ== X-Received: by 2002:aa7:9904:0:b0:4ba:5abb:aaf9 with SMTP id z4-20020aa79904000000b004ba5abbaaf9mr1961150pff.16.1640163434224; Wed, 22 Dec 2021 00:57:14 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id t12sm4927011pjo.44.2021.12.22.00.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 00:57:13 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 12D601140295; Wed, 22 Dec 2021 19:27:10 +1030 (ACDT) Date: Wed, 22 Dec 2021 19:27:10 +1030 From: Alan Modra To: "H.J. Lu" Cc: Binutils , Nick Clifton , Florian Weimer Subject: Re: [PATCH] elf: Set p_align to the common page size if possible Message-ID: References: <20211215163232.1787673-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3032.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Dec 2021 08:57:17 -0000 On Mon, Dec 20, 2021 at 07:50:30AM -0800, H.J. Lu wrote: > On Wed, Dec 15, 2021 at 8:32 AM H.J. Lu wrote: > > > > Currently, on 32-bit and 64-bit ARM, it seems that ld generates p_align > > values of 0x10000 even if no section alignment is greater than 0x1000. > > The issue is more general and probably affects other targets with > > multiple common page sizes. > > > > While file layout absolutely must take 64K page size into account, that > > does not have to be reflected in the p_align value. If running on a 64K > > kernel, the file will be loaded at a 64K page boundary by necessity. On > > a 4K kernel, 64K alignment is not needed. > > > > The glibc loader has been fixed to honor p_align: > > > > https://sourceware.org/bugzilla/show_bug.cgi?id=28676 > > > > similar to kernel: > > > > commit ce81bb256a224259ab686742a6284930cbe4f1fa > > Author: Chris Kennelly > > Date: Thu Oct 15 20:12:32 2020 -0700 > > > > fs/binfmt_elf: use PT_LOAD p_align values for suitable start address The ELF gABI says of p_align: p_align As ``Program Loading'' describes in this chapter of the processor supplement, loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size. This member gives the value to which the segments are aligned in memory and in the file. Values 0 and 1 mean no alignment is required. Otherwise, p_align should be a positive, integral power of 2, and p_vaddr should equal p_offset, modulo p_align. Notice the parallel between page size and p_align. I believe it was reasonable for ld to set p_align to the maximum page size supported by the segment layout, if you treat p_align as a hint. Now that p_align is treated as required alignment, I agree that we should not set p_align to maxpagesize. However, why choose commonpagesize? Is anything more than the maximum section alignment in any given segment needed? Imagine a binary created with maxpagesize of 64k, commonpagesize of 16k, and running with actual page size of 4k. If section alignment requirement is less than 4k, why should it be aligned to 16k? -- Alan Modra Australia Development Lab, IBM