From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RnOxLk2QsGrVrigAWB0awg (envelope-from ) for ; Sun, 20 Sep 2026 22:02:53 -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=QDae4OyE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A5F921E051; Sun, 20 Sep 2026 22:02:53 -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 705B11E033 for ; Sun, 20 Sep 2026 22:02:52 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE90E4BA9012 for ; Mon, 21 Sep 2026 02:02:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE90E4BA9012 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=QDae4OyE 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 45DD34BA9012 for ; Mon, 21 Sep 2026 02:02:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45DD34BA9012 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 45DD34BA9012 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=1789956146; cv=none; b=umZg1C4cFpKVSYMBNimVVRALilMEjL3i5oGlRo53nEFq72dSkYJoXu6pujHqntblHPWQlsGG2ykW6DG7koLkNap6XV77NHs0gJu3SV1laxyCllpHe0s1Hl88LHjuh9/TC+y6WbYbOaz1aI2KzKsQBapvHuuab1obVoqKKG3cbpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789956146; c=relaxed/simple; bh=+/MqM5lrFekMBlXMhoIOKMbXSIZ0r3x40Qx9QsACGZA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=tO8adb8QlhAvBJA8iQPAqOAv/NQTerJTIsJ0mzg0L+9WzH431HNAULUlU8RY9lhARnY+m9RKF9sPyuxDaVLi3VZR4VbSCpitOn5zqP4e4r1eAa3uoNcaL4+Sx1Ncnxj/vz76dI3sFbXd4wvSejxmUa5CqdCp8Q1S8SWv98knXMQ= 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=QDae4OyE DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45DD34BA9012 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d391aso16028785e9.2 for ; Sun, 20 Sep 2026 19:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789956144; x=1790560944; darn=sourceware.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=+7sW4vDcyk2meaRQFUnJQz4giV2fiH4+QxgUyX4yyvQ=; b=QDae4OyEdQw6MzHzljzc1g1PDmkCCwS+rnJQPQUYRzUhClO7fAIGfHud+zq+EXanPU vyyvZmSQYNoGf1teC8tlgw2ZO55KOyAPl+DiCiumsFLRYiYRWACiVbm65qaRZyoIIYQt DoTQNIu8MX+z/2d0BSffcZWY8HYZ0dB+2OMRsA/ILLQ2ywbQ+/PdOxFNBb+USkftcezq p9doawwKcnKMwgkNEgQVIewM2FxCFoJyPammU5ivxQWFCiIkno/lUHYtLqtw4sS0Ei3M QlmW6xBw6OOIQ3XaeLXoUGrvlevoOOKJq3PPMTsBRw8rFD7NlS+t/JHRdb6HhfLGR5AG lqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789956144; x=1790560944; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+7sW4vDcyk2meaRQFUnJQz4giV2fiH4+QxgUyX4yyvQ=; b=A6uidxs5UQQ21rTOv/1J2/+TrauxByGsjvkQYAB+pxX7SpVPX7WI0sTeObFkyCAzf8 /hwX8rdpfrr9txCj0DGY6/YXPNwiVOXREJAG1JPq1D++bvs+ESD5gA2kIf08JJy8/aTU setIYll2D/1jz6oM70p94oFnDN6IDG0PpyxJZy9wXotQ7jCXmDWoKQ7KFs0/JmtF8MVs 2t31UCM+Vkvjb0wsq7rCGdD/b10GPKEt/1DyzHDrJOI26e5nyFS3CB74IQp1+5Jm73dV eGn+56TO7WdHQLREdQOuCvy7i0TRfp+Pib4mJOephC1OHWyXiNoVVB0ZZUqFaVIuSn0S LoJw== X-Gm-Message-State: AFuF++mCOHhtVH1OZZLPo28jWStim1bnuMAS7hf8Fws18nTrMAa/83GI xU5f22x0/JtFQ3uiHSI/eyT/crWRASMkvir1Z2e3DTWpiJPhi/plruVBEsLEms0= X-Gm-Gg: AYBFou10WkPwLkw8zRbjEMSLZASQXkSFteSnWskB3WMG0/dZOpkwaxM+ws3Ey1CO38M y0+1Q/3ZzryCFwWlsx4T1m3kuQMDfutPANGBCWgSZlR8Wo5/Wj4Y50Lt0BPYEhAO1kd9oijledw jy4qIL9lKGpaoLLsLEeKwQIWbobum0XAO4FbmWBtAqV56CubLRdP1VVuB9+eh/1yLiEqY0DImrN gpE25hVYcXcykLa8fuXHYNNMLRT6R7oeIh7/R5ImpmWMni5pwOOKkvbI6q01GlhyEi601QDsXR0 hNK4zcRzCZGUkEzfHtg96rUsHZpvFunB8WKu1xx2lmv5aT2Pk+IsIp0XG6dkm5m38GgeyGtlN5l Ehw1PMmbvHFM0hT7pI4saqs2UvRI8+YSe4fPrM33h70Fmk7xWIUifaDYjbpayQgp8MJc1WZdSnN MPcIit8NHunDZP8jFELwBH+zzy0XZup2qItCBYywXRN4aJ3Mf9gSMCtUms4aeNNSmBB9JGj5WU5 prJQeZyB0yrT+BcgqzE6kPJSPw9+jTbztUzn5N6otsrxRaClDNe8w6fCjW43x6jKNb6+j1hlB6+ tM8xNI8CK7FgyWelf11U6k+ZVu1WPzTipTc= X-Received: by 2002:a05:600c:3e06:b0:49e:8238:6feb with SMTP id 5b1f17b1804b1-49fc56daf07mr136835215e9.14.1789956144433; Sun, 20 Sep 2026 19:02:24 -0700 (PDT) Received: from ?IPV6:2a01:cb0c:8b36:7600:316e:a8fc:d3af:15f3? (2a01cb0c8b367600316ea8fcd3af15f3.ipv6.abo.wanadoo.fr. [2a01:cb0c:8b36:7600:316e:a8fc:d3af:15f3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fcd074336sm186577305e9.8.2026.09.20.19.02.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Sep 2026 19:02:23 -0700 (PDT) Message-ID: <91e0ae19-bbde-4235-9cea-335127512ede@gmail.com> Date: Mon, 21 Sep 2026 04:02:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Dragorn421 Subject: [PING] Fix `add-symbol-file -o ... -s ...` address mapping bug To: gdb-patches@sourceware.org References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed 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 Ping :) ---------- Forwarded message --------- De : Dragorn421 Date: sam. 5 sept. 2026 à 12:16 Subject: Fix `add-symbol-file -o ... -s ...` address mapping bug To: Hello, I encountered an issue in GDB and am hereby submitting a patch for fixing it. First, let me explain the problem: it has to do with the `add-symbol-file` command that is used to map elf files to arbitrary addresses. For example if I want to map 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 proposed fix is to change `set_objfile_default_section_offset` to pass the current offset instead of 0 for sections that should be unaltered: ```diff diff --git a/gdb/symfile.c b/gdb/symfile.c index 017f7a49d8d..5691c2a46d9 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,7 @@ 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. */ ``` This is my first time contributing so my apologies if I'm doing anything not properly, please let me know. Sincerely, Dragorn421