From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fd6fCjkXAGk6uQwAWB0awg (envelope-from ) for ; Mon, 27 Oct 2025 21:07:05 -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=Vg/9i3qW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1BA9A1E0BC; Mon, 27 Oct 2025 21:07:05 -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,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 D72301E057 for ; Mon, 27 Oct 2025 21:07:03 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 339563858C66 for ; Tue, 28 Oct 2025 01:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 339563858C66 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=Vg/9i3qW Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 14F173858C2A for ; Tue, 28 Oct 2025 01:04:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14F173858C2A 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 14F173858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761613476; cv=none; b=pnS+9PG2exbFfSkrQWRCnbax4+Bug4oFrGlCe5eRxI4+XQkrWmSyFpfa2JE92SJcFvgykpw9nr8aqb5SJJ717BzOwwWFeCS3xJ99j3SEy7tS64FtYj7qya4aTY/PG2/geDRWdH1V9TyaINY8gyo264MSbRrbhG7EnGjBSBK3Gno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761613476; c=relaxed/simple; bh=nnJPRI0R6v7/GKpHKKA97D0htU3nJWMj1XtFI26RU/k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Yd03ATj8AR8fAP2yJkUMZKzsAjL3f71p6iayay0DjIT+44svHH1oCwHYwz8m40rRNlghcKxBclbGG7E1v9FNBxh4oNUFpIpc94vBHOEUZWUMX32aTJHbBFufvcVWNYTVoN9+cZ2fhym3XLAc3lN4zPzhC3Reeh+4FawyDMtZb0s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14F173858C2A Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7a28c7e3577so2810282b3a.1 for ; Mon, 27 Oct 2025 18:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imcan.dev; s=google; t=1761613475; x=1762218275; 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; bh=BW185MKL4G4+hMNd417nprX7IWpP14fkGtB5pKKItzM=; b=Vg/9i3qWSNyO0MHPCHhY8oFC70PtRPJJ2sMo0FWPJyTxJlg3Ow1qdi9NrAKh8ZXpcN yHU4eCjN/R59GDZ4ROAQfZRprlC7/QamQIWOxsb790N1aFi0FSE8xzL451lQt7URZ388 3pYNOhAbt1RheeI6W6GMkXCEA/zSfN6L0ootj5ofDOEwjXkJlkAIiRQ33S94qVFxd5WH Osz6lfuYVSoHFO+3OdIXa5/pjxi0BFr8MQKBSyctq088x9T28ev+VT0p+WzjXxvpMQHW Hg4TGz77wgABo+YyQ2bHNPqq0bZ71KS61oSyKe8QM2JDzIKhPKzEyAcY4FOjkjN0uT9j ofHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761613475; x=1762218275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BW185MKL4G4+hMNd417nprX7IWpP14fkGtB5pKKItzM=; b=cQFi/boAgTkvq4cyREQev7ZL778ggJSiiK5ZoeSYXoX7C8AcpxehPEFQab/NoM0edn cG17PXePIqz2BtxkIctt8UZt+jt58By3hK+D3gFmGipog3kYNAWCkbYYvXJnpRh59WRf 2wOcH5Inze+TeD5tzhmS4gRTKArGyA0YBkEIWroxf6KBh3QDO2qWJBj1NnCobRbmTKUE 6AgXvKXkwbewQtpzaAac5evxTMRjttRZobUwTJ2+7hHCWzyQFVmocCOxPRIke+qTlK3g 0tn3BjrbLtDvD2O8amsacvllRf3aQJTw0RvYTS0H/fMGuJyGmtKedb+QreG/qbCf+MfH IEIw== X-Gm-Message-State: AOJu0YwNggt4eT+quZQPRiFLsL1b6otRb0mGvjzKgN+y1xnG9JV6IarC 3yPFP+Hm0rWHc1KbwAUN08P3O/3uqu2GGrhnBA17vzMsrnLlCUwKaqclDIq0QZ86EmvX2vF38UU R1YrBrC8= X-Gm-Gg: ASbGncu4yvMMPZPnMGuYYBt0thsGMrzKZ/7bog2/v/T5j19DhNSxJyrIO4PkVo8fJ1D VYKgNRuhReoS1zH+j1PrdsfAdbHbWlSTZD8X4qZR1AYFupNafX1lFXAi64FthWyULsTBmyY3ywa Dk6ySQTEbc+3OwwI2t6RqfEqqCFrsmqCUZimBBSvJlPqU0HkyLyFJO6DdjpFc1YMmVkW/eSPGLV Ab6+kEr6+qq6YXiHKMVZRH4A/UMbTebak+HZldEv6gLbLjsOvvPYmsmRxyI/N0lwaHGPQbEba3p s8jsTIDSvXceBKlPy6Ez4L+2l4zEq0J/i6q5rN/w1rxEkcmKQ4QgemKVmFKuN6Bg5z1Es36I/DK GFd8plcYJm1aXw99TBKQSLYRQXSvp1b4LxFxM9jY7b9WyGAkDdsFCovx4yaRCcFAkuvOrsdAoks ZqRGPFxzvAdcwwlu+L2f+tcx/67PzZnY3uP0L+v640U12TuDu0yaoglemqVZUuXjfFXzNbmNw1C OlVQtnV/1NqZlKBmLNMmQ8vwO3PPSxRh8CZXc19/Fa5v+Y= X-Google-Smtp-Source: AGHT+IGqYLLkWp++GNy07x3DNz+wsUQXAXBkxyKrhcuT7VHhRHhhuClKWBUv3fdakRSJsYxbS916wQ== X-Received: by 2002:a17:903:1666:b0:276:76e1:2e84 with SMTP id d9443c01a7336-294cb37b7dfmr23900835ad.3.1761613474927; Mon, 27 Oct 2025 18:04:34 -0700 (PDT) Received: from dhcp-128-189-202-102.ubcsecure.wireless.ubc.ca (dhcp-128-189-202-102.ubcsecure.wireless.ubc.ca. [128.189.202.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29498d44db4sm97564975ad.86.2025.10.27.18.04.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 27 Oct 2025 18:04:34 -0700 (PDT) From: Can Acar To: tom@tromey.com Cc: gdb-patches@sourceware.org, "canacar@imcan.dev" Subject: [PATCH v2] Fix: Sign extensions for DW_FORM_addrx were never considered Date: Mon, 27 Oct 2025 18:03:47 -0700 Message-ID: <20251028010346.20187-2-canacar@imcan.dev> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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 From: "canacar@imcan.dev" 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 >= 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. --- Changes since v1: * read_addr_index_1 has been removed, merging its functionality into read_addr_index. * dwarf2_read_addr_index has been modified to change the reference to the cu in the newly-created cu case to something that seems safer. * fix a formatting issue in a call to read_address. gdb/dwarf2/read.c | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 431b7c9ea2c..cca42722471 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15352,14 +15352,20 @@ dwarf2_per_objfile::read_line_string (const gdb_byte *buf, ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero. ADDR_SIZE is the size of addresses from the CU header. */ +/* Given index ADDR_INDEX in .debug_addr, fetch the value. */ + static unrelocated_addr -read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr_index, - std::optional addr_base, int addr_size) +read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) { + const gdb_byte *info_ptr; + struct dwarf2_per_objfile *per_objfile = cu->per_objfile; + std::optional addr_base = cu->addr_base; + struct unit_head *cu_header = &cu->header; struct objfile *objfile = per_objfile->objfile; bfd *abfd = objfile->obfd.get (); - const gdb_byte *info_ptr; ULONGEST addr_base_or_zero = addr_base.has_value () ? *addr_base : 0; + unsigned int ignore_bytes_read; + unsigned char addr_size = cu_header->addr_size; per_objfile->per_bfd->addr.read (objfile); if (per_objfile->per_bfd->addr.buffer == NULL) @@ -15372,20 +15378,9 @@ read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr_index, objfile_name (objfile)); info_ptr = (per_objfile->per_bfd->addr.buffer + addr_base_or_zero + addr_index * addr_size); - if (addr_size == 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. */ - -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); -} /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ @@ -15405,11 +15400,10 @@ unrelocated_addr dwarf2_read_addr_index (dwarf2_per_cu *per_cu, dwarf2_per_objfile *per_objfile, unsigned int addr_index) { + std::optional reader; struct dwarf2_cu *cu = per_objfile->get_cu (per_cu); - std::optional addr_base; - int addr_size; - /* We need addr_base and addr_size. + /* read_addr_index requires some fields from cu. 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 @@ -15425,20 +15419,14 @@ dwarf2_read_addr_index (dwarf2_per_cu *per_cu, dwarf2_per_objfile *per_objfile, IWBN to use the aging mechanism to let us lazily later discard the CU. For now we skip this optimization. */ - if (cu != NULL) + if (cu == NULL) { - addr_base = cu->addr_base; - addr_size = cu->header.addr_size; - } - else - { - cutu_reader reader (*per_cu, *per_objfile, nullptr, nullptr, false, + reader.emplace (*per_cu, *per_objfile, nullptr, nullptr, false, language_minimal); - addr_base = reader.cu ()->addr_base; - addr_size = reader.cu ()->header.addr_size; + cu = reader->cu (); } - return read_addr_index_1 (per_objfile, addr_index, addr_base, addr_size); + return read_addr_index (cu, addr_index); } /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string. -- 2.50.1 (Apple Git-155)