From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uY+zHX8RYmr2WSkAWB0awg (envelope-from ) for ; Thu, 23 Jul 2026 09:05:03 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=pAV6rUh3; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 748AE1E09E; Thu, 23 Jul 2026 09:05:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 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 754B41E099 for ; Thu, 23 Jul 2026 09:05:02 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 17D6B4BA7997 for ; Thu, 23 Jul 2026 13:05:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17D6B4BA7997 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=pAV6rUh3 Received: from bat.pear.relay.mailchannels.net (bat.pear.relay.mailchannels.net [23.83.216.13]) by sourceware.org (Postfix) with ESMTPS id 2AD7D4BA23F7 for ; Thu, 23 Jul 2026 13:04:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AD7D4BA23F7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2AD7D4BA23F7 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.216.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811872; cv=none; b=KXzkp0oBS1HvUFic8tYasHYZqQAZQp9gYA82iwqXPd53f4unI9w/yYUBQbXku+8ZnPONqm39ypihSsY4X2r82dMNjs0zBwiOiInDmYQHQqHIWL8rUf6pHD9359vOWHvnhSt4KEz8a2+CYsK9du8xntMkLRyKdd7rrEFBlQ2H3Wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811872; c=relaxed/simple; bh=xGjQXTAhb7n+ecsBdh5H0Au5HlLb3uUj+53y1pp0pUk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=f157Yd2Frf4x6nAYFRA63IeUAfC7nDAhffXWOJL/ds6oOGZzPCQMPn8C7Dc8ij+s8k4ZCnU2nLqU2S9BEqEUdijhvBAkQajKOORc2ncIwJhmHb3QAqLq4e+zHL2gU9LGy0IKhWZhGuBZsFeuh/zzYr2xYVtyM44ERTT6V0Zdz24= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=pAV6rUh3 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AD7D4BA23F7 X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 234B84C2E8F for ; Thu, 23 Jul 2026 13:04:31 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (trex-green-1.trex.outbound.svc.cluster.local [100.103.88.1]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 67F7F4C2FA1 for ; Thu, 23 Jul 2026 13:04:30 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Occur-Battle: 6999457700d2f8bd_1784811871003_957016696 X-MC-Loop-Signature: 1784811871003:684791911 X-MC-Ingress-Time: 1784811871002 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.88.1 (trex/8.0.2); Thu, 23 Jul 2026 13:04:30 +0000 Received: from localhost (bl20-181-64.dsl.telepac.pt [2.81.181.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4h5WY96B8Jz1049 for ; Thu, 23 Jul 2026 06:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1784811870; bh=BWXe/aJ4WAl2iGQVoqAOuQxVBcuC/31+D/htDvN3NnM=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=pAV6rUh3VsiA1/ghnEM/fSqn/Z2z833jYkjJEQs0YCN9FwVs+5tY6VaYGLdNY2JaK aJIHFECYYyr090jvr38S9qm1ddPPJWRxj7tow8Mh/m8OjY6OdcYkrgKq5FW9jiTceA 8uHhyrAMU+F/twjHBnpdTLSYJcl1ERCPKUQva0Fva5vafKFOnfJr/8OFy1dWZYPw6C Z6MG2FPtcKnn4AqHqbZAMeNZsfOKVfaN+4eG9n1culFfEQApgto9QhLP5WCufywxBw G1/UFvQZyCGe3lvaGqISLPu0lKCJogYfN8itThLE2mhEG7ekK5uzwZ9Z9Stp8qDo2E 66SilpgsipcXw== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 16/27] gdb/coffread: Don't relocate absolute symbols Date: Thu, 23 Jul 2026 14:01:07 +0100 Message-ID: <20260723130118.206735-17-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723130118.206735-1-pedro@palves.net> References: <20260723130118.206735-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 A COFF absolute symbol (i.e., one with COFF section number N_ABS) has a value that is a plain constant, not an offset into any section. Such a symbol must not be adjusted when the objfile it belongs to is relocated, e.g. when a DLL is loaded at an address other than its preferred image base. gdb/coffread.c records absolute symbols as mst_abs, which is correct, but it derives the symbol's section from cs_to_section, which in turn asks cs_to_bfd_section for the BFD section. cs_to_bfd_section matches by section number and finds nothing for an N_ABS symbol, returning NULL, so cs_to_section falls back to the text section. The symbol then inherits the text section's relocation offset (the DLL's load bias) and its value is wrongly shifted by that amount. For a DLL loaded at its preferred base the bias is zero and the bug is invisible, but when two DLLs are loaded overlapping so that one is relocated, its absolute symbols come out shifted. This can be seen in gdb.base/shreloc.exp, which loads two libraries at the same base and checks that absolute symbols keep the same value in both: (gdb) maint print msymbols ... [4] A 0x5bc10000 __minor_os_version__ section .text [4] A 0x5bbe0000 __minor_os_version__ section .text __minor_os_version__ has value 0 in both DLLs, but GDB reports its value as each symbols DLL's load base. Note also the contradictory "A ... section .text" -- an absolute symbol should not be tied to a section at all. Fix this in cs_to_bfd_section, by returning BFD's absolute section for an N_ABS symbol rather than NULL. Its relocation offset is always zero, so the symbol's value is left untouched, matching what elf_symtab_read does for absolute ELF symbols. cs_to_section then naturally returns the absolute section's index. While at it, fold the N_ABS case in symtab_read into the general path. Without this fix, gdb.base/shreloc.exp fails on all Windows-based targets, and it now passes cleanly: -FAIL: gdb.base/shreloc.exp: absolute symbols not relocated +PASS: gdb.base/shreloc.exp: absolute symbols not relocated Tested on: x86_64-pc-linux-gnu x86_64-pc-cygwin x86_64-w64-mingw32 x86_64-pc-windows-msvc Change-Id: I91b9882b6918cbd46dfdf1aa18f72cbbace70535 --- gdb/coffread.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index 0a5da42e563..9f792edcd26 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -116,6 +116,13 @@ struct coff_reader asection * coff_reader::cs_to_bfd_section (struct coff_symbol *cs) { + /* An absolute symbol (N_ABS) is not tied to any of the input file's + sections. Its value is a plain constant, so map it to BFD's + absolute section, so that callers treat it as absolute and, in + particular, do not relocate it. */ + if (cs->c_secnum == N_ABS) + return bfd_abs_section_ptr; + for (asection *sect : gdb_bfd_sections (symfile_bfd)) if (sect->target_index == cs->c_secnum) return sect; @@ -469,14 +476,6 @@ coff_reader::symtab_read (minimal_symbol_reader &reader, symbol lookup which returned no match. */ break; } - else if (cs->c_secnum == N_ABS) - { - /* Use the correct minimal symbol type (and don't - relocate) for absolute values. */ - ms_type = mst_abs; - sec = cs_to_section (cs); - tmpaddr = cs->c_value; - } else { asection *bfd_section = cs_to_bfd_section (cs); @@ -484,7 +483,13 @@ coff_reader::symtab_read (minimal_symbol_reader &reader, sec = cs_to_section (cs); tmpaddr = cs->c_value; - if (bfd_section->flags & SEC_CODE) + if (bfd_is_abs_section (bfd_section)) + { + /* Use the correct minimal symbol type (and don't + relocate) for absolute values. */ + ms_type = mst_abs; + } + else if (bfd_section->flags & SEC_CODE) { ms_type = cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC -- 2.54.0