From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yNERDwSi+mi+HAUAWB0awg (envelope-from ) for ; Thu, 23 Oct 2025 17:45:40 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=imcan.dev header.i=@imcan.dev header.a=rsa-sha256 header.s=google header.b=E0b0heCM; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 300331E0BC; Thu, 23 Oct 2025 17:45:40 -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,HTML_MESSAGE,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 server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 5E3CA1E057 for ; Thu, 23 Oct 2025 17:45:39 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDADB385829B for ; Thu, 23 Oct 2025 21:45:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDADB385829B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=imcan.dev header.i=@imcan.dev header.a=rsa-sha256 header.s=google header.b=E0b0heCM Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 88794385841D for ; Thu, 23 Oct 2025 21:44:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88794385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=imcan.dev Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=imcan.dev ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 88794385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761255898; cv=none; b=Ne7Ui3n9ZztwxYjH6BQWJG7CX1Jp/EczpkWEoGZjaser95jUfXsAvlkAmSNpzN1IreCgCX9/KxzCdG24m8VwPxQCAqldAQgRFXBwWbtHFmOae8IcJhX6weKc6mQxPnsxWRUTjXXFhQ2hFeS2t3aFrNuyaApwlTydhaSHPNrSZxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761255898; c=relaxed/simple; bh=0qaURsH7e4NkFq80tsPFrOykAwrWUHyWy6PUpa6GszU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=OYEi30CGW5JGOAYJLOGbNZKdOcda8z74sSSi3fp3abn9c2tcLBbwRRokJbBxsptjzULGSNkoQydDnDR599asz239IJmSZGkEhgX3/sWycJzlCHy7n4jB+tpm13n6bg0UUk2Tju/k+u6fRzll70KYHUyHzYfyVHi4nXelJzXJcVM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88794385841D Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-783fa3aa35cso16178687b3.3 for ; Thu, 23 Oct 2025 14:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imcan.dev; s=google; t=1761255898; x=1761860698; darn=sourceware.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=76q2y81O7hvGJj/893gCBtY/c81jpEiGbB9yPBQuaHE=; b=E0b0heCMJTLTxbj8/6p7CydI84OrSDY88Bgsg9v/FHB9KqR1sgHsl0qTPcf2i2855j 1E78r5IMy/VbBBrI7+olq1eA1NZicIlXM81IP8KonN3Yny+RHbJmwn8R3oxN73qeE4kC ee7jeJCsyGfQMuSKjWo5RARhSZonZqVwRzIu70K0Ab/c5Cwc2BeIqejTVvLD29aaHWm/ DzWhYWE5TFrAhFzhWSrRfKpmRiUW3OLQsCDD/kFUYB2yjh9xHziPuyhHYoZLSl9JGMRo Uwz4fUFPaCuyEn7l/wCmKM0LipTrZrflH13gi1gI0qhIjY9hEwclbXKs5aeZw4nreXqH t35g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761255898; x=1761860698; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=76q2y81O7hvGJj/893gCBtY/c81jpEiGbB9yPBQuaHE=; b=X6tUhYbrd/yYHdU4aRwGrAz5yYjD6AdqmH/wWmikf5fwMFAs4aFwGDJtZXnVWRzJ59 WVPyFFQPfsOzSZLAnlR2O2ja/eG9vmPuGtt7ZdpseQbY1KyVHnUILTh8FtwfySjFUJK0 Y629secA7hBthZe5PkwbODt81G/TCLuXSK2QKNyytGX1B+QrVopp/FMmdiocbd7XGLXl wVqsdv7c/3oOnfVVJI3I5IF2yKrQIcCVeDZ0gmZZyT7B5FHzqoVId8sa3TPcDvU8xnuO xgjuM6stP9P5PbavBHdPEFurhVDJNQRNlHNBEP8FaNQkXmiz3hIAJWyGB50+ng1QSR/n aM1A== X-Gm-Message-State: AOJu0YycN0FkxtMsXb8BDqZ9V2GjniUKzZUOFuq1aIjxD3JZcQfSRRQn rZi5ixlLqrEI4PKLuDNg+R9tPVqcv9HcJz/UQd+tra5TEGsM2USP+voAnUctc6f7HtGxf9Fsy/6 d0KYD4b/CBnfJw20vltmqviO+4t3TQ5QXK3Wo1666zvqpF0u0fW10oTw= X-Gm-Gg: ASbGnct9TJ9VKXMeFVMCOUCNeGNC52sx8j58LdOPmBUkdvgQgOkbKMYzCuLE1kFfyfw /QWmnNIqPa2Cy1JdDUSdJpmbJyvZxEEqRstMCs1Z5ENduCUpVei2Rsd4/CFLyFaddFciDY59XeZ D+2vqpJMxyGGmMVndmvS40G7zKRwTxXRINfSd8jQ2L990KZipH1D9OCZSjZF1/Gik0ZnCEEbh7A 4rWwsNWeirMohkfrlaWz1zULSj0/eyY3FqHS7vt+mtR0LLXQ5VaT4CfColfL10UOGz8kl0VgA== X-Google-Smtp-Source: AGHT+IEe1fgIzU6cVbUfBY/v1EukEj/Hp+TdwQj0oI5+YBrF8ehRbcXntfl7WjgLtfcLRZ6m3uR/guRUE4tGOCYugCw= X-Received: by 2002:a05:690c:905:b0:784:883c:a868 with SMTP id 00721157ae682-785cda7e3admr39030607b3.30.1761255897604; Thu, 23 Oct 2025 14:44:57 -0700 (PDT) MIME-Version: 1.0 References: <20251023214230.13646-1-canacar@imcan.dev> In-Reply-To: <20251023214230.13646-1-canacar@imcan.dev> From: Can Acar Date: Thu, 23 Oct 2025 14:44:46 -0700 X-Gm-Features: AS18NWDdx9rfG_oZCwmDiJ6ojuJjB942Ot2LVHjjGD2tLX1RwlGQIStQkQ7llf0 Message-ID: Subject: Re: [PATCH] Fix: Sign extensions for DW_FORM_addrx were never considered To: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="00000000000022b3530641da58f6" 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 --00000000000022b3530641da58f6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To be perfectly responsible here, I need to state that I have not run the testsuite, because I couldn't get it working on my machine. It could be possible for me to set up a virtual environment where I can run the test suites if required. Best regards, Can On Thu, Oct 23, 2025 at 2:42=E2=80=AFPM Can Acar wrote: > DW_FORM_addr is converted (sign-extended) to a signed value when > the dwarf size is less than the size of unrelocated_addr, if the > target architecture "naturally" sign extends an address (bfd.c). > > However, the same handling was not done for DW_FORM_addrx. This > meant that for example, trying to `list` a function with an > address >=3D 0x80000000 on (some?) 32-bit mips targets, when > that address was encoded using DW_FORM_addrx, was broken. > > This patch fixes this issue by plumbing read_addr_index_1 into > unit_head::read_address, which is the function used to extract > information from DW_FORM_addr, and so it handles this case > correctly. > --- > gdb/dwarf2/read.c | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 955893c5f0c..e83d6ca38ae 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -15350,12 +15350,14 @@ dwarf2_per_objfile::read_line_string (const > gdb_byte *buf, > > static unrelocated_addr > read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int > addr_index, > - std::optional addr_base, int addr_size) > + std::optional addr_base, unit_head *cu_heade= r) > { > struct objfile *objfile =3D per_objfile->objfile; > bfd *abfd =3D objfile->obfd.get (); > const gdb_byte *info_ptr; > ULONGEST addr_base_or_zero =3D addr_base.has_value () ? *addr_base : 0= ; > + unsigned int ignore_bytes_read; > + unsigned char addr_size =3D cu_header->addr_size; > > per_objfile->per_bfd->addr.read (objfile); > if (per_objfile->per_bfd->addr.buffer =3D=3D NULL) > @@ -15368,10 +15370,7 @@ read_addr_index_1 (dwarf2_per_objfile > *per_objfile, unsigned int addr_index, > objfile_name (objfile)); > info_ptr =3D (per_objfile->per_bfd->addr.buffer + addr_base_or_zero > + addr_index * addr_size); > - if (addr_size =3D=3D 4) > - return (unrelocated_addr) bfd_get_32 (abfd, info_ptr); > - else > - return (unrelocated_addr) bfd_get_64 (abfd, info_ptr); > + return cu_header->read_address(abfd, info_ptr, &ignore_bytes_read); > } > > /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ > @@ -15380,7 +15379,7 @@ static unrelocated_addr > read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) > { > return read_addr_index_1 (cu->per_objfile, addr_index, > - cu->addr_base, cu->header.addr_size); > + cu->addr_base, &cu->header); > } > > /* Given a pointer to an leb128 value, fetch the value from .debug_addr. > */ > @@ -15403,9 +15402,9 @@ dwarf2_read_addr_index (dwarf2_per_cu *per_cu, > dwarf2_per_objfile *per_objfile, > { > struct dwarf2_cu *cu =3D per_objfile->get_cu (per_cu); > std::optional addr_base; > - int addr_size; > + unit_head *cu_header; > > - /* We need addr_base and addr_size. > + /* We need addr_base and header (only some fields of which are used > later). > If we don't have PER_CU->cu, we have to get it. > Nasty, but the alternative is storing the needed info in PER_CU, > which at this point doesn't seem justified: it's not clear how > frequently > @@ -15424,17 +15423,17 @@ dwarf2_read_addr_index (dwarf2_per_cu *per_cu, > dwarf2_per_objfile *per_objfile, > if (cu !=3D NULL) > { > addr_base =3D cu->addr_base; > - addr_size =3D cu->header.addr_size; > + cu_header =3D &cu->header; > } > else > { > cutu_reader reader (*per_cu, *per_objfile, nullptr, nullptr, false= , > language_minimal); > addr_base =3D reader.cu ()->addr_base; > - addr_size =3D reader.cu ()->header.addr_size; > + cu_header =3D &reader.cu ()->header; > } > > - return read_addr_index_1 (per_objfile, addr_index, addr_base, > addr_size); > + return read_addr_index_1 (per_objfile, addr_index, addr_base, > cu_header); > } > > /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string. > -- > 2.50.1 (Apple Git-155) > > --00000000000022b3530641da58f6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
To be perfectly responsible here, I need to state that I h= ave not run the testsuite, because I couldn't get it working on my mach= ine. It could be possible for me to set up a virtual environment where I ca= n run the test suites=C2=A0if required.

Best regards,
Can

On Thu, Oct 23, 2025 at 2:42=E2=80= =AFPM Can Acar <canacar@imcan.dev> wrote:
DW_FORM_addr is converted (sign-ext= ended) to a signed value when
the dwarf size is less than the size of unrelocated_addr, if the
target architecture "naturally" sign extends an address (bfd.c).<= br>
However, the same handling was not done for DW_FORM_addrx. This
meant that for example, trying to `list` a function with an
address >=3D 0x80000000 on (some?) 32-bit mips targets, when
that address was encoded using DW_FORM_addrx, was broken.

This patch fixes this issue by plumbing read_addr_index_1 into
unit_head::read_address, which is the function used to extract
information from DW_FORM_addr, and so it handles this case
correctly.
---
=C2=A0gdb/dwarf2/read.c | 21 ++++++++++-----------
=C2=A01 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 955893c5f0c..e83d6ca38ae 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15350,12 +15350,14 @@ dwarf2_per_objfile::read_line_string (const gdb_b= yte *buf,

=C2=A0static unrelocated_addr
=C2=A0read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr= _index,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::option= al<ULONGEST> addr_base, int addr_size)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::option= al<ULONGEST> addr_base, unit_head *cu_header)
=C2=A0{
=C2=A0 =C2=A0struct objfile *objfile =3D per_objfile->objfile;
=C2=A0 =C2=A0bfd *abfd =3D objfile->obfd.get ();
=C2=A0 =C2=A0const gdb_byte *info_ptr;
=C2=A0 =C2=A0ULONGEST addr_base_or_zero =3D addr_base.has_value () ? *addr_= base : 0;
+=C2=A0 unsigned int ignore_bytes_read;
+=C2=A0 unsigned char addr_size =3D cu_header->addr_size;

=C2=A0 =C2=A0per_objfile->per_bfd->addr.read (objfile);
=C2=A0 =C2=A0if (per_objfile->per_bfd->addr.buffer =3D=3D NULL)
@@ -15368,10 +15370,7 @@ read_addr_index_1 (dwarf2_per_objfile *per_objfile= , unsigned int addr_index,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0objfile_name (objfile));
=C2=A0 =C2=A0info_ptr =3D (per_objfile->per_bfd->addr.buffer + addr_b= ase_or_zero
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 + addr_index * addr_size);=
-=C2=A0 if (addr_size =3D=3D 4)
-=C2=A0 =C2=A0 return (unrelocated_addr) bfd_get_32 (abfd, info_ptr);
-=C2=A0 else
-=C2=A0 =C2=A0 return (unrelocated_addr) bfd_get_64 (abfd, info_ptr);
+=C2=A0 return cu_header->read_address(abfd, info_ptr, &ignore_bytes= _read);
=C2=A0}

=C2=A0/* Given index ADDR_INDEX in .debug_addr, fetch the value.=C2=A0 */ @@ -15380,7 +15379,7 @@ static unrelocated_addr
=C2=A0read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
=C2=A0{
=C2=A0 =C2=A0return read_addr_index_1 (cu->per_objfile, addr_index,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0cu->addr_base, cu->header.addr_size);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0cu->addr_base, &cu->header);
=C2=A0}

=C2=A0/* Given a pointer to an leb128 value, fetch the value from .debug_ad= dr.=C2=A0 */
@@ -15403,9 +15402,9 @@ dwarf2_read_addr_index (dwarf2_per_cu *per_cu, dwar= f2_per_objfile *per_objfile,
=C2=A0{
=C2=A0 =C2=A0struct dwarf2_cu *cu =3D per_objfile->get_cu (per_cu);
=C2=A0 =C2=A0std::optional<ULONGEST> addr_base;
-=C2=A0 int addr_size;
+=C2=A0 unit_head *cu_header;

-=C2=A0 /* We need addr_base and addr_size.
+=C2=A0 /* We need addr_base and header (only some fields of which are used= later).
=C2=A0 =C2=A0 =C2=A0 If we don't have PER_CU->cu, we have to get it.=
=C2=A0 =C2=A0 =C2=A0 Nasty, but the alternative is storing the needed info = in PER_CU,
=C2=A0 =C2=A0 =C2=A0 which at this point doesn't seem justified: it'= ;s not clear how frequently
@@ -15424,17 +15423,17 @@ dwarf2_read_addr_index (dwarf2_per_cu *per_cu, dw= arf2_per_objfile *per_objfile,
=C2=A0 =C2=A0if (cu !=3D NULL)
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0addr_base =3D cu->addr_base;
-=C2=A0 =C2=A0 =C2=A0 addr_size =3D cu->header.addr_size;
+=C2=A0 =C2=A0 =C2=A0 cu_header =3D &cu->header;
=C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0else
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0cutu_reader reader (*per_cu, *per_objfile, nullp= tr, nullptr, false,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 language_minimal);
=C2=A0 =C2=A0 =C2=A0 =C2=A0addr_base =3D
reader.cu ()->addr_base;
-=C2=A0 =C2=A0 =C2=A0 addr_size =3D reader.cu ()->header.addr_size;
+=C2=A0 =C2=A0 =C2=A0 cu_header =3D &reader.cu ()->header;
=C2=A0 =C2=A0 =C2=A0}

-=C2=A0 return read_addr_index_1 (per_objfile, addr_index, addr_base, addr_= size);
+=C2=A0 return read_addr_index_1 (per_objfile, addr_index, addr_base, cu_he= ader);
=C2=A0}

=C2=A0/* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string. --
2.50.1 (Apple Git-155)

--00000000000022b3530641da58f6--