From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C09103858430 for ; Mon, 20 Dec 2021 18:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C09103858430 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-Rwhn3xwYNrq6PGN5FHu6Bw-1; Mon, 20 Dec 2021 13:51:22 -0500 X-MC-Unique: Rwhn3xwYNrq6PGN5FHu6Bw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFE2481CCB6; Mon, 20 Dec 2021 18:51:20 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B14296AB90; Mon, 20 Dec 2021 18:51:19 +0000 (UTC) From: Florian Weimer To: "H.J. Lu" Cc: Fangrui Song , Binutils Subject: Re: [PATCH] elf: Set p_align to the common page size if possible References: <20211215163232.1787673-1-hjl.tools@gmail.com> <20211216085252.3jgtc6an6x5wlfzs@gmail.com> <87zgovfd2u.fsf@oldenburg.str.redhat.com> Date: Mon, 20 Dec 2021 19:51:17 +0100 In-Reply-To: (H. J. Lu's message of "Mon, 20 Dec 2021 10:39:40 -0800") Message-ID: <87bl1bf6u2.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Mon, 20 Dec 2021 18:51:27 -0000 * H. J. Lu: > We need to set larger p_align > sh_addralign for huge page executables. > My current algorithm to decide if p_align should be used as the maximum > page size for objcopy is > > static bool > elf_is_p_align_valid (bfd *abfd) > { > unsigned int i; > Elf_Internal_Phdr *segment; > unsigned int num_segments; > const struct elf_backend_data *bed = get_elf_backend_data (abfd); > bfd_size_type maxpagesize = bed->maxpagesize; > bfd_size_type commonpagesize = bed->commonpagesize; > > if (commonpagesize == maxpagesize) > return true; > > /* When the common page size != the maximum page size, p_align may > be set to the common page size while segments are aligned to > the maximum page size. In this case, the input p_align will be > ignored and the maximum page size will be used to align the output > segments. */ > segment = elf_tdata (abfd)->phdr; > num_segments = elf_elfheader (abfd)->e_phnum; > for (i = 0; i < num_segments; i++, segment++) > if (segment->p_type == PT_LOAD > && (segment->p_align != commonpagesize > || vma_page_aligned_bias (segment->p_vaddr, > segment->p_offset, > maxpagesize) != 0)) > return true; > > return false; > } > > It should cover all cases. Will this switch from 64K to 4K on POWER and AArch64? I think this will then produce binaries which cannot be loaded by current glibc in all cases: PT_LOAD p_align check is too strict Thanks, Florian