From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id c8gzOPmtuGrGQgsAWB0awg (envelope-from ) for ; Sun, 27 Sep 2026 01:47:37 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=xDHDNn3R; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=E4m1UyLp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=SQoo5Opx; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DYj5gl0t; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CF2691E033; Sun, 27 Sep 2026 01:47:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9081E1E033 for ; Sun, 27 Sep 2026 01:47:36 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A26A4BA9017 for ; Sun, 27 Sep 2026 05:47:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A26A4BA9017 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=xDHDNn3R; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=E4m1UyLp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=SQoo5Opx; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DYj5gl0t Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 9E6B44BA79B1 for ; Sun, 27 Sep 2026 05:47:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E6B44BA79B1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E6B44BA79B1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790488029; cv=none; b=UFQWieCgIWE1rG67AB4PNQctecuE71vOYr042HWJK2FpJ0ItXU3RxSupUQ7LkoBRA3kJxcDd1ayCXK+V9RicLbVMOIxaPpMJtDgRcWQq3uG5SJBNDbEVueazG+v5uHJDG2JghUjfpp/baWm/0sjxZBI2pvuYVdXem46qQSQW95g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790488029; c=relaxed/simple; bh=BXItiZATUGEjR1U9GMErBdoC/6QETWYm4qz6cxd37rU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=RcY7UAnSrJHQcHxTpQY8xkf+0uGnY9+sfmR2v4hQr7y5Z13HwUnhQRqC5jpVfuV0V9Q+7WGXcEAQuwIVftfgh+zwfrcqUDcY4Jm0uxNfwUu6fMi7c43JmGMM1Zo/gQYNbAZP/8cRF6Qxknf+0BKf1/EepN6YCLevhtATcq2CmkI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=xDHDNn3R; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=E4m1UyLp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=SQoo5Opx; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DYj5gl0t DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E6B44BA79B1 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8001A1F787 for ; Sun, 27 Sep 2026 05:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790488024; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AtgZ+4oZ670wMWCihXKHdKzNk67B8Tc8V6v6xsRvbao=; b=xDHDNn3RECXMSEhFawXVyl/zDbS48WGyEo9JBVkO//uWbepdtF51CFeyvxsl64hoZ1LuOt I17FaoOAr+Eb8aZEavtmWpTRVyZO/bM0ZQHaYKj/FbL9Q2NJzWDRq+j3j7m4i1yV4noXCn frSaKzp0SUdi4Q3PVhsfsTbTJOqSt2c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790488024; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AtgZ+4oZ670wMWCihXKHdKzNk67B8Tc8V6v6xsRvbao=; b=E4m1UyLpJlAxxJgpte3XVDhcs9Ru/xJ63hH3SzHubl73z181NUX4vZtpCNvcGscuXz0dpn Tt+qpQCb6eiR/KDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SQoo5Opx; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DYj5gl0t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790488020; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AtgZ+4oZ670wMWCihXKHdKzNk67B8Tc8V6v6xsRvbao=; b=SQoo5Opx0lEiPyE8xu0dwrwfMxXz8M8gRvB8wadxxWT6sz4Ypwny0GnrkH7IBS8Z/3gnck Dr9e8nMH0HKBFz44xPKBFHtWqW0rXH2aVBhpmUwccRxVIIdvqhvALXhq3cLm3FrEgv50oU 3qr0AhaUh8oTHtR0Bd3F4iyw2RwCbL4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790488020; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AtgZ+4oZ670wMWCihXKHdKzNk67B8Tc8V6v6xsRvbao=; b=DYj5gl0t5oA3rwBAdhQwbdrk66LnSyRtKSCRLrTJaZXaEYuOxmCFJqU+dRM8eQUn0VFZSh 2O0phHsgHCZTUZBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C49013274 for ; Sun, 27 Sep 2026 05:47:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /Y/JONOtuGqlLAAAD6G6ig (envelope-from ) for ; Sun, 27 Sep 2026 05:47:00 +0000 Message-ID: Date: Sun, 27 Sep 2026 07:46:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH] [gdb] Refactor svr4_solib_ops::lm_addr_check From: Tom de Vries To: gdb-patches@sourceware.org References: <20260911191940.2892092-1-tdevries@suse.de> Content-Language: en-US In-Reply-To: <20260911191940.2892092-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 8001A1F787 X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; DKIM_TRACE(0.00)[suse.de:+] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 9/11/26 9:19 PM, Tom de Vries wrote: > I came across svr4_solib_ops::lm_addr_check and found it hard to follow. > > In particular, it's indent-happy and minimizes code using a goto, resulting in > the following end-of-function: > ... > } > } > > set_addr: > li.l_addr = l_addr; > li.l_addr_p = 1; > } > > return li.l_addr; > } > ... > > I could just address the indentation, but I'd be adding a goto: > ... > - if (dynaddr + l_addr != l_dynaddr) > + if (dynaddr + l_addr == l_dynaddr) > + goto set_addr; > ... > > Instead, refactor the function into this form: > ... > svr4_solib_ops::lm_addr_check (const solib &so, bfd *abfd) const > { > auto &li = get_lm_info_svr4 (so); > if (li.l_addr_p) > return li.l_addr; > > auto set_addr = [&li] (CORE_ADDR addr) > { > li.l_addr = addr; > li.l_addr_p = true; > return addr; > } > > if (...) > return set_addr (l_addr); > > ... > > return set_addr (l_addr); > } > ... Ping. Thanks, - Tom > --- > gdb/solib-svr4.c | 160 +++++++++++++++++++++++------------------------ > 1 file changed, 80 insertions(+), 80 deletions(-) > > diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c > index c4af1b11a4d..40b0fc55113 100644 > --- a/gdb/solib-svr4.c > +++ b/gdb/solib-svr4.c > @@ -225,106 +225,106 @@ CORE_ADDR > svr4_solib_ops::lm_addr_check (const solib &so, bfd *abfd) const > { > auto &li = get_lm_info_svr4 (so); > + if (li.l_addr_p) > + return li.l_addr; > > - if (!li.l_addr_p) > - { > - struct bfd_section *dyninfo_sect; > - CORE_ADDR l_addr, l_dynaddr, dynaddr; > + auto set_addr = [&li] (CORE_ADDR addr) > + { > + li.l_addr = addr; > + li.l_addr_p = true; > + return addr; > + }; > > - l_addr = li.l_addr_inferior; > + struct bfd_section *dyninfo_sect; > + CORE_ADDR l_addr, l_dynaddr, dynaddr; > > - if (!abfd || !this->has_lm_dynamic_from_link_map ()) > - goto set_addr; > + l_addr = li.l_addr_inferior; > + if (!abfd || !this->has_lm_dynamic_from_link_map ()) > + return set_addr (l_addr); > > - l_dynaddr = li.l_ld; > + l_dynaddr = li.l_ld; > > - dyninfo_sect = bfd_get_section_by_name (abfd, ".dynamic"); > - if (dyninfo_sect == NULL) > - goto set_addr; > + dyninfo_sect = bfd_get_section_by_name (abfd, ".dynamic"); > + if (dyninfo_sect == NULL) > + return set_addr (l_addr); > > - dynaddr = bfd_section_vma (dyninfo_sect); > + dynaddr = bfd_section_vma (dyninfo_sect); > + if (dynaddr + l_addr == l_dynaddr) > + return set_addr (l_addr); > > - if (dynaddr + l_addr != l_dynaddr) > - { > - CORE_ADDR align = 0x1000; > - CORE_ADDR minpagesize = align; > + CORE_ADDR align = 0x1000; > + CORE_ADDR minpagesize = align; > > - if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) > - { > - Elf_Internal_Ehdr *ehdr = elf_tdata (abfd)->elf_header; > - Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr; > - int i; > + if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) > + { > + Elf_Internal_Ehdr *ehdr = elf_tdata (abfd)->elf_header; > + Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr; > + int i; > > - align = 1; > + align = 1; > > - for (i = 0; i < ehdr->e_phnum; i++) > - if (phdr[i].p_type == PT_LOAD && phdr[i].p_align > align) > - align = phdr[i].p_align; > + for (i = 0; i < ehdr->e_phnum; i++) > + if (phdr[i].p_type == PT_LOAD && phdr[i].p_align > align) > + align = phdr[i].p_align; > > - minpagesize = get_elf_backend_data (abfd)->minpagesize; > - } > + minpagesize = get_elf_backend_data (abfd)->minpagesize; > + } > > - /* Turn it into a mask. */ > - align--; > + /* Turn it into a mask. */ > + align--; > > - /* If the changes match the alignment requirements, we > - assume we're using a core file that was generated by the > - same binary, just prelinked with a different base offset. > - If it doesn't match, we may have a different binary, the > - same binary with the dynamic table loaded at an unrelated > - location, or anything, really. To avoid regressions, > - don't adjust the base offset in the latter case, although > - odds are that, if things really changed, debugging won't > - quite work. > + /* If the changes match the alignment requirements, we > + assume we're using a core file that was generated by the > + same binary, just prelinked with a different base offset. > + If it doesn't match, we may have a different binary, the > + same binary with the dynamic table loaded at an unrelated > + location, or anything, really. To avoid regressions, > + don't adjust the base offset in the latter case, although > + odds are that, if things really changed, debugging won't > + quite work. > > - One could expect more the condition > - ((l_addr & align) == 0 && ((l_dynaddr - dynaddr) & align) == 0) > - but the one below is relaxed for PPC. The PPC kernel supports > - either 4k or 64k page sizes. To be prepared for 64k pages, > - PPC ELF files are built using an alignment requirement of 64k. > - However, when running on a kernel supporting 4k pages, the memory > - mapping of the library may not actually happen on a 64k boundary! > + One could expect more the condition > + ((l_addr & align) == 0 && ((l_dynaddr - dynaddr) & align) == 0) > + but the one below is relaxed for PPC. The PPC kernel supports > + either 4k or 64k page sizes. To be prepared for 64k pages, > + PPC ELF files are built using an alignment requirement of 64k. > + However, when running on a kernel supporting 4k pages, the memory > + mapping of the library may not actually happen on a 64k boundary! > > - (In the usual case where (l_addr & align) == 0, this check is > - equivalent to the possibly expected check above.) > + (In the usual case where (l_addr & align) == 0, this check is > + equivalent to the possibly expected check above.) > > - Even on PPC it must be zero-aligned at least for MINPAGESIZE. */ > + Even on PPC it must be zero-aligned at least for MINPAGESIZE. */ > > - l_addr = l_dynaddr - dynaddr; > + l_addr = l_dynaddr - dynaddr; > > - if ((l_addr & (minpagesize - 1)) == 0 > - && (l_addr & align) == ((l_dynaddr - dynaddr) & align)) > - { > - if (info_verbose) > - gdb_printf (_("Using PIC (Position Independent Code) " > - "prelink displacement %s for \"%s\".\n"), > - paddress (current_inferior ()->arch (), l_addr), > - so.name.c_str ()); > - } > - else > - { > - /* There is no way to verify the library file matches. prelink > - can during prelinking of an unprelinked file (or unprelinking > - of a prelinked file) shift the DYNAMIC segment by arbitrary > - offset without any page size alignment. There is no way to > - find out the ELF header and/or Program Headers for a limited > - verification if it they match. One could do a verification > - of the DYNAMIC segment. Still the found address is the best > - one GDB could find. */ > - > - warning (_(".dynamic section for \"%s\" " > - "is not at the expected address " > - "(wrong library or version mismatch?)"), > - so.name.c_str ()); > - } > - } > - > - set_addr: > - li.l_addr = l_addr; > - li.l_addr_p = 1; > + if ((l_addr & (minpagesize - 1)) == 0 > + && (l_addr & align) == ((l_dynaddr - dynaddr) & align)) > + { > + if (info_verbose) > + gdb_printf (_("Using PIC (Position Independent Code) " > + "prelink displacement %s for \"%s\".\n"), > + paddress (current_inferior ()->arch (), l_addr), > + so.name.c_str ()); > + } > + else > + { > + /* There is no way to verify the library file matches. prelink > + can during prelinking of an unprelinked file (or unprelinking > + of a prelinked file) shift the DYNAMIC segment by arbitrary > + offset without any page size alignment. There is no way to > + find out the ELF header and/or Program Headers for a limited > + verification if it they match. One could do a verification > + of the DYNAMIC segment. Still the found address is the best > + one GDB could find. */ > + > + warning (_(".dynamic section for \"%s\" " > + "is not at the expected address " > + "(wrong library or version mismatch?)"), > + so.name.c_str ()); > } > > - return li.l_addr; > + return set_addr (l_addr); > } > > struct svr4_so > > base-commit: 0855b93cfb911a4feab76a31bb1914982b3e6979