From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id m6C8J51FUmpjBgMAWB0awg (envelope-from ) for ; Sat, 11 Jul 2026 09:31:09 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=DHusFLXL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 93A491E070; Sat, 11 Jul 2026 09:31:09 -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 [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 08BD61E070 for ; Sat, 11 Jul 2026 09:31:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9E104BA23C3 for ; Sat, 11 Jul 2026 13:31:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9E104BA23C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1783776662; bh=iDpnkSr69tTM+BXhwVO9cQC2yim2LGF4hBfHw34ioeM=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DHusFLXLMV6w4XK4ICh2G1v3P7+USWbSzLiWZoF/16pMZlE2pRBhoA1CqTXkIKn1a lsM75mQHWLSoLHgExWl/1f+22305jjOY4g46JIgWlgBrTFNhRS+yWnBQklgaBc3YuY ql7MeBQejB8CnKQJSqZbrNANNWSN7zTjC68InlZc= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3040C4BA2E22 for ; Sat, 11 Jul 2026 13:30:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3040C4BA2E22 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3040C4BA2E22 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783776627; cv=none; b=AMRIDXN0Ky4Mci/IRxibAzaJ2aWe1J1DaDFsEEdQdojJ7vEVqdp8//pDQrw6x/rbbuo+1umKeRHKJKsngQwRUawFjRUH/ZvgfO7wCIMT4ainmTL5DG/UOlKbQAoAkHbX04wVvTcLCMduWtf24K8zYOrKNMjEVm9J9UfY6U+TvNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783776627; c=relaxed/simple; bh=OkqXZJMGSWUiblqQ2w/dUsPpHFn+1UCaUW1K4f1VnO8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rPLrQPqnb4JdoqpsgYsadFgOsXvJl/J39LTED82uebFmY3PEwjWFkT1CHLgxt86MpsDV/0J7iQxGyXHCLIOJzyE4oEu3zafdJ5C1IM9vwSU1R3oraP0VWlFBcW9wAtI8Cja6Lhl4VTlzSwEE1LxNhPXYDUa0URS4jF7raKvB6r8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MUJkPkyQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3040C4BA2E22 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-YnvK0hllPOibQx0U9iJ6hA-1; Sat, 11 Jul 2026 09:30:22 -0400 X-MC-Unique: YnvK0hllPOibQx0U9iJ6hA-1 X-Mimecast-MFC-AGG-ID: YnvK0hllPOibQx0U9iJ6hA_1783776621 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4926596eebcso15644545e9.3 for ; Sat, 11 Jul 2026 06:30:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783776621; x=1784381421; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iDpnkSr69tTM+BXhwVO9cQC2yim2LGF4hBfHw34ioeM=; b=cM54AaeXzbn+CramrB4KUIeyzaay5gMemObZMpi70wtSoVAkV4Qot6YVd28Zh3gPRa JnKRJN1HWr9U+5XOjbNag0FSTIEK6TfnHV6HaTQ+c9gsArHDRceF0GaE4afjYvONVqGO 3dciO+HLMpscsUNrDJOw4rexDx5o7jp1Csh/3OB5VsLZjpYgEgMaSFjWeEEtq3kiDcsr PIq5ZTeenPUJDs9yA6PJh4yfSM1lIp9YmGzuh+HuGKIxtOSXtvceRKsIFljSpXg6/gEL NF4DfLlvoGyhoGR7oUqXHIp6XjTA6t9NEKQuFvl2E9yM2rOEQBTX255r3/qWseQfwDuP XcRQ== X-Forwarded-Encrypted: i=1; AHgh+RrRtItdwxVfPFb0tOg5ElSVM0mO9jmzcisCxjGfhfnIGn7L0e3l/OVHMgAxfzDnFQvYhdM=@sourceware.org X-Gm-Message-State: AOJu0YyWLk16lOTOmBfyUql8e51a+rKrCRFt8F1NwoFXwak8rioQpWd4 w9XGEnou2v5hiqLw/GxnbgrAIRzoqcHw1/J73VC8FX+Ikg7G8JOlwEBwvdnR43XTn2FIQcIFWHN r7TX6EVQVEI7IvUVTirqY6mB2cTad6GQuNvorz4lW8yE57q9vCgvg X-Gm-Gg: AfdE7cnRhILUFRQF4/0F48sDgUwYqHmgAbaHlfjxq6UDu/+s/gH+70UExDCfbYVVGSr IvE4VxBEi0U3XQtcV1no32BWVcgE6g5norPyiRGTluVqeUykqf94SgIssv6Ec9IgyZv2lfsIpeZ 4JVCHgkWn5IVKlAVYQpdpAM0bGr5unDxBp4sfu2i+2MAfaujvGF6dxaSR80Y6BrrAhNjbydViLX K1amiDVQSJjsnEqohv2JcCHgikxDilDtHGdRb0gwA77nXWShNqRErU7UpWPqRPmFM027463Ash0 VZQBLIzaLI1ZEkRXzq9ts0z0wOqrcvJnEwt6PBwAuif1U6gHhM79oMVgOcygGwQrDzfosDCVQcG 7A/7ckvU= X-Received: by 2002:a05:600c:1d16:b0:493:f318:3bc6 with SMTP id 5b1f17b1804b1-493f87e72b3mr26426555e9.13.1783776621393; Sat, 11 Jul 2026 06:30:21 -0700 (PDT) X-Received: by 2002:a05:600c:1d16:b0:493:f318:3bc6 with SMTP id 5b1f17b1804b1-493f87e72b3mr26426235e9.13.1783776620965; Sat, 11 Jul 2026 06:30:20 -0700 (PDT) Received: from localhost ([109.144.18.126]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493eb6ccdbbsm226572435e9.3.2026.07.11.06.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 06:30:20 -0700 (PDT) To: Zhao Yiming , gdb@sourceware.org Subject: Re: Fwd: RISC-V bare-metal: GDB loses source line info when .text starts at 0x0 In-Reply-To: <87zezxekxj.fsf@redhat.com> References: <87wlv8tacj.fsf@redhat.com> <87zezxekxj.fsf@redhat.com> Date: Sat, 11 Jul 2026 14:30:14 +0100 Message-ID: <87wlv1ejrt.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: oyba8sbJ-NZZIH0Q8Lcy7eckaJd8LIPiL_JI5KB7-AM_1783776621 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb Reply-To: Andrew Burgess Errors-To: gdb-bounces~public-inbox=simark.ca@sourceware.org Sender: "Gdb" Andrew Burgess writes: > Andrew Burgess writes: > >> Zhao Yiming via Gdb writes: >> >>> Hi GDB maintainers, >>> >>> I am seeing a possible GDB source-line lookup issue while remote-debugging a >>> bare-metal RISC-V ELF. >>> >>> Environment: >>> - GDB: 15.2.90.20241210-git, Xuantie-900 elf newlib gcc Toolchain V3.2.0 >>> B-20250627 >>> - GCC: 14.1.1 20240710, same Xuantie toolchain >>> - ld: GNU ld 2.42.50 >>> - QEMU: qemu-system-riscv64 8.2.94 (cskysim V5.2.8 B-20250721) >>> - Host: Windows 10.0.19045.6466 >>> >>> Build flags: >>> >>> -O0 -g -ffunction-sections -fdata-sections -Wl,--gc-sections >>> >>> The failing ELF is linked as a bare-metal image with .text VMA = 0x0. >>> >>> Reproducer outline: >>> >>> target remote :1234 >>> load >>> b main >>> c >>> s >>> s >>> n >>> n >>> n >>> n >>> >>> After stepping out of SPI_ModifyGlobalReg(), GDB prints only: >>> >>> 0x00000000000002dc in I2C_PinMuxSetup () >>> >>> Expected: >>> >>> I2C_PinMuxSetup (...) at ../src/demoI2c.c:36 >>> >>> The line information appears to exist: >>> >>> addr2line -e LRV4201_SPI_I2C_2.elf 0x2dc >>> -> ../src/demoI2c.c:36 >>> >>> Relevant symbols: >>> >>> 0000000000000000 T Reset_Handler >>> 00000000000002ca T I2C_PinMuxSetup >>> 0000000000000920 T SPI_ModifyGlobalReg >>> >>> Additional observations: >>> >>> 1. If the linker script changes .text from 0x0 to a non-zero address, the >>> GDB problem disappears. >>> 2. If .text still starts at 0x0 but Reset_Handler is placed in .text instead >>> of .text.init, the problem also disappears. >>> 3. The failing ELF contains many zero-address decoded line-table rows from >>> demoI2c.c/demoSpi.c. A no-gc build and a reduced working project do not. >>> >>> I attached a small archive with decoded line tables, objdump section >>> headers, >>> addr2line output, build flags, linker script, and relevant sources. The full >>> ELFs are not attached because of the mailing list size limit, but I can >>> provide >>> them or file a Bugzilla issue if preferred. >>> >> >> If you could file a bugzilla, include this description, and attach >> everything including the ELFs, that would make things easier. If you >> post the link I'll try to take a look when I have time. >> >> I'm not surprised that there are issues here, some of the older GDB code >> still makes use of 0 as a "magic" flag indicating no-data, etc. I've >> worked on targets that allow code to be placed at address 0, and fixed >> some of these issues in the past, so it would be nice to fix this one >> too. > > I took a look into this and opened this bug: > > https://sourceware.org/bugzilla/show_bug.cgi?id=34389 > > The problem originates from the linker's function garbage collection > (IMHO). > > Garbage collection deletes the function sections, but doesn't > (unfortunately) try to patch up any of the DWARF. As a result things > like `.debug_rnglists` which point at a deleted function are left with a > start address of 0, the range of the deleted function is effectively > moved to start at address zero. > > The `.debug_rnglists` is then used by GDB when building the address map > for its compunit_symtab objects (effectively a DWARF compilation unit). > > These compunit_symtab are expanded lazily depending on the order in > which you make use of them, so if you first visit a compunit_symtab > which contains a garbage collected function then this compunit_symtab > will always be the first that GDB checks when looking for an address. > The garbage collected function, with its range starting at 0, in effect > "claims" that range of addresses. > > There are some heuristics in GDB to try and spot garbage collection and > try to fix up some of the confusing incoming data, but it's not perfect, > and clearly in this case, it isn't sufficient. > > I don't have a plan for fixing this in GDB right now. OK, actually, I did have one idea. If you feel like compiling GDB, I attached a patch to the bug report which resolves the simple reproducer I create for the bug. It would be great to know if this also resolves your original issue or not. If it does then I will write a proper commit message for the patch and post it to the mailing list. Thanks, Andrew