From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yRCwMINUpGrUKgEAWB0awg (envelope-from ) for ; Fri, 11 Sep 2026 15:20:35 -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=H8PbijYv; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=mHbozhHk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d3M4nbNY; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RHi0z75Q; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B0B921E09E; Fri, 11 Sep 2026 15:20:35 -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 4E2AF1E033 for ; Fri, 11 Sep 2026 15:20:34 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE1E648FBCB6 for ; Fri, 11 Sep 2026 19:20:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE1E648FBCB6 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=H8PbijYv; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=mHbozhHk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d3M4nbNY; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RHi0z75Q Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 27F8148A0808 for ; Fri, 11 Sep 2026 19:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27F8148A0808 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 27F8148A0808 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789154391; cv=none; b=Z+gztGwTZDZlZuH2jOckm1LhNWx66R6DpIN4Q9d8j8SpP1c318VyoJpUdmVvXsMP9NxMcCpAvLW69QbwTnkqxiascGgKE84tj9MXDSvE9IX/CLvXwKtaOljolGzLe8EuxA3T1/LOoKjBcEiUlcKGR/Ul1WWicKDZezn/JGYSk/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789154391; c=relaxed/simple; bh=yYDbze/rDb86EEDaPhSKO2cRwI6i9JVmPFlGNr+Bg0A=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=OMVokOfPMOclVvh0vAilx4Wxf6Saf1QdgBKoFdLDFjBsxi+X/lNDRtw/jh78xmpkp+SQM8Iv8b0hPLwYWUqhCX5ymnCln7+IQMawCiaZAD5g0COesaUmWtICTcUNWm4djkccR3f8rGMknmDGjGkbwTmwwJP4a3e/ULoAC/lr7E0= 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=H8PbijYv; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=mHbozhHk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d3M4nbNY; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RHi0z75Q DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27F8148A0808 Received: from imap1.dmz-prg2.suse.org (unknown [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 843A81FEF9 for ; Fri, 11 Sep 2026 19:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1789154385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L989Ahy77fn0a7r4EOSrmmaHeoxtTBE7Utgpg6RB4lc=; b=H8PbijYvjs+UqdbyF7QqFNAupZqdx7Oo+G6Htb+KCaEgUcGn+j9RpjTYFVhYRGAzUmsVLZ arqoFzGzmeWBzkXfdevimmmlOkqi4uOLB08DJxAe/7Z/2JPoSbXVc3Q6N7DxMkDRiV0nkS LBNHQYLeiy97qKIw2XjOTW5rda+AKHc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1789154385; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L989Ahy77fn0a7r4EOSrmmaHeoxtTBE7Utgpg6RB4lc=; b=mHbozhHkbYR2puTSHdtq0CuAghnfI6ZbO5Z86h1OOl+qfAGYf8lvTrPnx9Zij8o2f001vf 0cUJRFyb9oLu7+AA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1789154381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L989Ahy77fn0a7r4EOSrmmaHeoxtTBE7Utgpg6RB4lc=; b=d3M4nbNYfj2lZhfl38Dn3DFbsjR+AnurvhTe4CO70rwU4mOAiQKLTMm8ZlJeRYQevyUgRn 6m6xUxydBXmwLe/jsGyUWBEwfUNu1iBZL7FfPfe+Bdn7o76A4mKgxfanYsLgx3wfW95m7n RTk1rb9OPdApUjZSP2cXbE5n6aznmjs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1789154381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L989Ahy77fn0a7r4EOSrmmaHeoxtTBE7Utgpg6RB4lc=; b=RHi0z75Q7Qiy/JememrnlNG8ZCfBQ5gP42K/ZSl9wX8FDdYtFLyamIVnWDtTLdGykeszmS IENOImFbf3cSQ5Cw== 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 51CA2132D3 for ; Fri, 11 Sep 2026 19:19:41 +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 V6jtDk1UpGqjJAAAD6G6ig (envelope-from ) for ; Fri, 11 Sep 2026 19:19:41 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb] Refactor svr4_solib_ops::lm_addr_check Date: Fri, 11 Sep 2026 21:19:40 +0200 Message-ID: <20260911191940.2892092-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] 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 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); } ... --- 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 -- 2.51.0