From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oT9nLNNqt2oGOgYAWB0awg (envelope-from ) for ; Sat, 26 Sep 2026 02:48:51 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PdM6bfcX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B310E1E06B; Sat, 26 Sep 2026 02:48:51 -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,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 349981E033 for ; Sat, 26 Sep 2026 02:48:51 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 346884B92087 for ; Sat, 26 Sep 2026 06:48:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 346884B92087 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PdM6bfcX Received: from mail-wm2-x10.google.com (mail-wm2-x10.google.com [IPv6:2a00:1450:4864:31::10]) by sourceware.org (Postfix) with ESMTPS id 509E14BB5911 for ; Sat, 26 Sep 2026 06:48:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 509E14BB5911 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 509E14BB5911 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:31::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790405286; cv=none; b=wztMPG5zfQ/7K+6gld5Z2jp4uBeOGFLDQuzx4N7AMCemv3qzuOgScEr3tbUFCt5NqHe0j4RAqVLw+PhiJ+m2ozY1QyoSIsVPD6bUdQAz6nnp3geyG/YQnyWln7kMHADY3CuRnenohSL5qEqneaDwViX/cg9clxWLV69c4ouaAFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790405286; c=relaxed/simple; bh=5fTNMuSOPMg3a790RX86zvS8Hug503R9+/tKPLP8mIo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qGPEUVQrtd2luR6tmQYE/JAihDNFHiTINftRW7HcLeRofB88jqlLwCYxkKb7Xqbbr/uLhZOIUiAvS1rHF+p8LZCCHYTX+IZrvr3CNKYfrEyHCrKbuXYGDoTxR6HGemYtPvG3J9nNjbA0FBxJc5KHP805Hm6BH4TMBcnRwDmWzBM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=PdM6bfcX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 509E14BB5911 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ff9621c5dso2433965e9.0 for ; Fri, 25 Sep 2026 23:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790405285; x=1791010085; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KXrH1iGF1FSRtUCXckDnfksdI5gDSo/sBi51xuM/+rs=; b=PdM6bfcXtaqGp5UFmWJ97b3n0KhArBtoLTcL5zrIw9bX7OIxCSsXC9PocqYX8jJThf jk2wikP8TbSaQyGHMk1ybUL793Krp+aesQJ0qJpU9v8X7g0r53HVkcNMpkMdfEtCAKti NKxTRXXTJfHqvM0URBEsoOKis03OelFuNmH3lIDZpVhJgV8l2Z7F+wjMl1dxZUJsJGgE O1lzgU/i44CvrHyRcxkidBrAlhcXS8bZyZc9w98gCeLcyYDtJW6sVwU9NQyMTpmra0e9 a6bHvOCiffYA50EhGfk6aRH7S5Np2JhVHh0qHeP08kHtvEumfszNdtcr/LSVntgsMAML i2Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790405285; x=1791010085; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=KXrH1iGF1FSRtUCXckDnfksdI5gDSo/sBi51xuM/+rs=; b=F/kQEUVW8FUqDw0shv5gqKIorond88cOawNK+HPRcOPgc3PFpxXcYslhW5xBLgPORq UnTIaDgZ0czAxPzBJOfIn8IaW+zB7V8qco+35b0bXYwAAy2ms75xhHyzInAhUEqiwadl t8anEEZxpzPwqVGcU+4ViMDfhE3HMbvniFKCaB9vaU9PG6PbTWhDDdvqAJhHtTK0kyCC WgHIRqNPsREPym3r5ff3tISawIRlcQr07FctCQ1ps6BJONKiw/77BgPHZi7ASTQMo2bY DFzfKs2GcpZ8/H+tERsnxjgmHpX0dnhO8Yp05W/x+HziT3qPZ34E8BHl63KEwOTPJZ+7 RTCg== X-Gm-Message-State: AFuF++kav7iyXEov9yv5Wv9KxJpg/dHdRaO2g8XfrnyRQ22Ij3KRuXS6 qbKUpqDKukOzdZ/jlb3HlcbAGQI/29PonWyztvHgINIktnE7d1TkC6oQX/K9RVY= X-Gm-Gg: AYBFou0v8SgEn8rg69LOWnd0q5ngNXLaO9bipwe9s2BtZhuWoTz01hNAzgjktjExH29 w94vlBJ5mtS/Dj3wUyqrTfBtvCgCKOwXSGAhxaMG/7IOaEx2+LmkXWrQItvm+2GcLWraknZYsrL DtTvdtIMKDmYfOWu8Bab1o7c72KE4QYrpvj7g1qrOjkqQ71LP6zQtlOocD243r4NiZ9R0RdtvyO uw04+0lw8wqcKwT02kVzakV2+m/l1JTm3zVL8tuYtgY80Y1ogn/681WYwJbA3od/nXC5qGEmqdc Y6TA3i9pAo6cRYanlQHbYqy5sYl2dzsqUCn4y2ms9V+4intC52nWCiQGnecAdF5wnF02NyLaqzi VcOUE20jlTHaOYv7Y0usv1xXQnUWRlDfXldGxbzDMJck7uPRSWnOC4BESwurkwmZq111O8+oXdv a6soN+bFzd1JEwhm9OSpsPZcaZXm2j82jlDnwtjhYc81NLOeP47hpBbHqROZXz8glwlOLLZstnw UOZhv7haXITyfxvOUfV9BxVxIKi3Yk7EuA4cltvUE+Un5M7UwlFx3pWEFVk3bY1JFA5ILjn X-Received: by 2002:a05:600c:1989:b0:49d:16df:8521 with SMTP id 5b1f17b1804b1-49fe66ab9d1mr140038835e9.4.1790405285169; Fri, 25 Sep 2026 23:48:05 -0700 (PDT) Received: from dragorn421pc.home (2a01cb0c8b3676002a37402cbc062626.ipv6.abo.wanadoo.fr. [2a01:cb0c:8b36:7600:2a37:402c:bc06:2626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49ff023f12esm110012875e9.0.2026.09.25.23.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2026 23:48:04 -0700 (PDT) From: Dragorn421 To: gdb-patches@sourceware.org Cc: Dragorn421 , Keith Seitz Subject: [PATCH v4 1/2] Fix `add-symbol-file -o ... -s ...` address mapping bug Date: Sat, 26 Sep 2026 08:47:23 +0200 Message-ID: <20260926064742.29327-2-dragorn421@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260926064742.29327-1-dragorn421@gmail.com> References: <20260926064742.29327-1-dragorn421@gmail.com> 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 The 'add-symbol-file' command allows users to map sections explicitly ("-s SECTION ADDR") and apply an offset ("-o OFFSET"). The documentation explains: If an optional @var{offset} is specified, it is added to the start address of each section, except those for which the address was specified explicitly. But those two options currently may not be supplied together in the same command invocation without encountering buggy behavior. For example if mapping the .text section from main.o at 0x1234: ``` (gdb) add-symbol-file main.o -s .text 0x1234 add symbol table from file "main.o" at .text_addr = 0x1234 (y or n) y Reading symbols from main.o... (No debugging symbols found in main.o) (gdb) info files ... 0x0000000000001030 - 0x0000000000001040 is .plt.got 0x0000000000001234 - 0x000000000000132c is .text 0x0000000000001138 - 0x0000000000001145 is .fini ... ``` `info files` does then report the expect address for .text However this breaks when combining with the -o "set offset for other unspecified sections" option: ``` (gdb) add-symbol-file main.o -o 0xFF000000 -s .text 0x1234 add symbol table from file "main.o" at .text_addr = 0x1234 with other sections offset by 0xff000000 (y or n) y Reading symbols from main.o... (No debugging symbols found in main.o) (gdb) info files ... 0x00000000ff001030 - 0x00000000ff001040 is .plt.got 0x0000000000001040 - 0x0000000000001138 is .text 0x00000000ff001138 - 0x00000000ff001145 is .fini ... ``` We notice here the -o option was correctly used per the addresses of e.g. the `.fini` section, but the .text section address is now wrong. This behavior boils down to the `set_objfile_default_section_offset` function assuming it can pass 0 as `objfile_relocate`'s `offsets` entries to not modify the `-s` mappings previously set by the `symbol_file_add` call in `add_symbol_file_command`. When in fact `objfile_relocate` does not check for 0, it only checks for the new offset being the same as the current one. The fix is to change `set_objfile_default_section_offset` to pass the current offset instead of 0 for sections that should be unaltered. Reviewed-By: Keith Seitz --- gdb/symfile.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 017f7a49d8d..a5f4e64fa6b 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2139,8 +2139,8 @@ set_objfile_default_section_offset (struct objfile *objf, = addrs_section_sort (objf_addrs); /* Walk the BFD section list, and if a matching section is found in - ADDRS_SORTED_LIST, set its offset to zero to keep its address - unchanged. + ADDRS_SORTED_LIST, set its offset to its current offset to keep + its address unchanged. Note that both lists may contain multiple sections with the same name, and then the sections from ADDRS are matched in BFD order @@ -2163,7 +2163,8 @@ set_objfile_default_section_offset (struct objfile *objf, } if (cmp == 0) - offsets[objf_sect->sectindex] = 0; + offsets[objf_sect->sectindex] + = objf->section_offsets[objf_sect->sectindex]; } /* Apply the new section offsets. */ -- 2.43.0