From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id bA4TGRY6HWlpwhEAWB0awg (envelope-from ) for ; Tue, 18 Nov 2025 22:31:34 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=cv+82eDm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 521901E08D; Tue, 18 Nov 2025 22:31:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no 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 0F0B31E08D for ; Tue, 18 Nov 2025 22:31:33 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37F733858D32 for ; Wed, 19 Nov 2025 03:31:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37F733858D32 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=cv+82eDm Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 968523858D20 for ; Wed, 19 Nov 2025 03:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 968523858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 968523858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763523045; cv=none; b=xYgGv957N6f/zX+Gg0ILqd0cj6J3jEMfmbhRmQXqkc260TmKrP4QBHxKnd5kzNErJ/ahHXb7cD7DbL0bmKkqcnuwTDvdV/T6sgkGG54uLepOqeiLDqQL8avlQSBDVXi+aTQBfI0PwOTvDIwIIh9FGRce2862j1cAMarPiJhXoaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763523045; c=relaxed/simple; bh=M2PaRd22PYuUmh9T+1cMkXKE/DpUY6+wmzJNlmcMKBo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hFRuTk+XNmCiHUdnkZ40FjANSI2lniK5BWEaz+GLft9VDQSmwULb/atwffzA/QGUpKvdV8Jv0nabNtGFpFOhQ6lbsOu0mXEvGV9sRyzOzw2Mllg2ZoJXoCaF8zYnaqfgsd84Xuk5vwegELF+kZ7SjwzqWHiuX0ikH+7SxE9azsk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 968523858D20 Received: from eig-obgw-6006b.ext.cloudfilter.net ([10.0.30.211]) by cmsmtp with ESMTPS id LX8KvY3uWZx2iLYu4vrtOS; Wed, 19 Nov 2025 03:30:44 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id LYu3v0Q0NCLDbLYu3vVvMt; Wed, 19 Nov 2025 03:30:44 +0000 X-Authority-Analysis: v=2.4 cv=P6E6hjAu c=1 sm=1 tr=0 ts=691d39e4 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=6UeiqGixMTsA:10 a=ItBw4LHWJt0A:10 a=6nLIIzaLngIjnkGbdcAA:9 a=3ZKOabzyN94A:10 a=VS4QxaUSPT0UtbFnIvSC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iuouG70flfJMrviX6ZBmzlJDMQ7sTujkGSOF/+Q6lhs=; b=cv+82eDmBrk8U+g+u+NEJ56rvd 710J7+N4sZvxMpHexG0EKb0vuxdKtttmG4xUsgiiax4F5I0PFlAdt50/wxZ3BUyprd1OsgdoYH5py ZtOjn8T5094GTaq1nmFDMXaeu; Received: from 97-122-120-205.hlrn.qwest.net ([97.122.120.205]:43676 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vLYu3-00000002ZKd-0lO5; Tue, 18 Nov 2025 20:30:43 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Make blockvector a little more self-contained Date: Tue, 18 Nov 2025 20:30:33 -0700 Message-ID: <20251119033033.3538090-1-tom@tromey.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.120.205 X-Source-L: No X-Exim-ID: 1vLYu3-00000002ZKd-0lO5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-120-205.hlrn.qwest.net (localhost.localdomain) [97.122.120.205]:43676 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfBC8d9RlclTAMrbm8EGSRyUAND9Oj+J3ydf3eiZcMBOyQJDsjOgw9o+MEeuEaS3xQ4t+fPRRHefJZC84/4m17U4Xi2EtG+ufiPe/wKcC3uDq0Y734CjT dkVtrwzAl2NcnkKtwKnny2X4FAorgFaDoIafPCweDOOGN/SfQvgKf7B7TQ1AlXpMzPoz9jD6eOSjW+8NCpSB5fuUuXyr56jcppI= 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 This patch changes blockvector to be a little more self-contained. The idea here is that code outside of blockvector shouldn't really know how it operates. After this patch, this still doesn't fully happen -- a couple spots check the result of map() and make decisions based on that -- but this is a step toward making that happen. The longer term idea here is that this is needed to enable lazier CU expansion. Meanwhile, this patch seems like a simple cleanup. Relocation is now handled by the blockvector itself and the non-const map() method can be removed. There wasn't a great spot to move the section_offsets typedef. I chose defs.h. I've also updated the comment there as it has been out of date for a long time. I've also removed an obsolete comment from the symbol-relocation code. Regression tested on x86-64 Fedora 40. --- gdb/block.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/block.h | 14 ++++++++++---- gdb/defs.h | 4 ++++ gdb/objfiles.c | 45 ++------------------------------------------- gdb/symtab.c | 10 ++++++++++ gdb/symtab.h | 12 +++++------- 6 files changed, 68 insertions(+), 54 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 9fb04635975..e959adc968c 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -366,6 +366,28 @@ block::static_link () const return (struct dynamic_prop *) objfile_lookup_static_link (objfile, this); } +/* See block.h. */ + +void +block::relocate (struct objfile *objfile, const section_offsets &offsets) +{ + int block_line_section = SECT_OFF_TEXT (objfile); + + set_start (start () + offsets[block_line_section]); + set_end (end () + offsets[block_line_section]); + + for (blockrange &r : ranges ()) + { + r.set_start (r.start () + offsets[block_line_section]); + r.set_end (r.end () + offsets[block_line_section]); + } + + /* We only want to iterate over the local symbols, not any + symbols in included symtabs. */ + for (struct symbol *sym : multidict_symbols ()) + sym->relocate (objfile, offsets); +} + /* Initialize a block iterator, either to iterate over a single block, or, for static and global blocks, all the included symtabs as well. */ @@ -865,6 +887,21 @@ blockvector::~blockvector () mdict_free (bl->multidict ()); } +/* See block.h. */ + +void +blockvector::relocate (struct objfile *objfile, + const section_offsets &offsets) +{ + int block_line_section = SECT_OFF_TEXT (objfile); + + if (m_map != nullptr) + m_map->relocate (offsets[block_line_section]); + + for (struct block *b : m_blocks) + b->relocate (objfile, offsets); +} + /* Implement 'maint info blocks' command. If passed an argument then print a list of all blocks at the given address. With no arguments then list all blocks at the current address of the current inferior. */ diff --git a/gdb/block.h b/gdb/block.h index df03231ca4c..ceff97d79e3 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -315,6 +315,11 @@ struct block : public allocate_on_obstack bool contains (const struct block *a, bool allow_nested = false) const; + /* Relocate this block and all contained blocks. OBJFILE is the + objfile holding this block, and OFFSETS is the relocation offsets + to use. */ + void relocate (struct objfile *objfile, const section_offsets &offsets); + private: /* Return the default entry-pc of this block. The default is the address @@ -482,10 +487,6 @@ struct blockvector const struct block *static_block () const { return this->block (STATIC_BLOCK); } - /* Return the address -> block map of this blockvector. */ - addrmap_fixed *map () - { return m_map; } - /* Const version of the above. */ const addrmap_fixed *map () const { return m_map; } @@ -513,6 +514,11 @@ struct blockvector for ADDR are considered. */ struct symbol *symbol_at_address (CORE_ADDR addr) const; + /* Relocate this blockvector and all contained blocks. OBJFILE is + the objfile holding this blockvector, and OFFSETS is the + relocation offsets to use. */ + void relocate (struct objfile *objfile, const section_offsets &offsets); + private: /* An address map mapping addresses to blocks in this blockvector. This pointer is zero if the blocks' start and end addresses are diff --git a/gdb/defs.h b/gdb/defs.h index 8bf9d3dcbda..bb047d9cb4c 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -411,4 +411,8 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what); extern void _initialize_ ## NAME (); \ void _initialize_ ## NAME () +/* How to relocate the symbols from each section in a symbol file. + This is indexed by section numbers. */ +typedef std::vector section_offsets; + #endif /* GDB_DEFS_H */ diff --git a/gdb/objfiles.c b/gdb/objfiles.c index f131bab1dd5..5a7bda7821a 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -508,24 +508,6 @@ objfile::~objfile () } -/* A helper function for objfile_relocate1 that relocates a single - symbol. */ - -static void -relocate_one_symbol (struct symbol *sym, struct objfile *objfile, - const section_offsets &delta) -{ - /* The RS6000 code from which this was taken skipped - any symbols in STRUCT_DOMAIN or UNDEF_DOMAIN. - But I'm leaving out that test, on the theory that - they can't possibly pass the tests below. */ - if ((sym->loc_class () == LOC_LABEL - || sym->loc_class () == LOC_STATIC) - && sym->section_index () >= 0) - sym->set_value_address (sym->value_address () - + delta[sym->section_index ()]); -} - /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here. Return non-zero iff any change happened. */ @@ -549,34 +531,11 @@ objfile_relocate1 (struct objfile *objfile, /* OK, get all the symtabs. */ for (compunit_symtab &cust : objfile->compunits ()) - { - struct blockvector *bv = cust.blockvector (); - int block_line_section = SECT_OFF_TEXT (objfile); - - if (bv->map () != nullptr) - bv->map ()->relocate (delta[block_line_section]); - - for (block *b : bv->blocks ()) - { - b->set_start (b->start () + delta[block_line_section]); - b->set_end (b->end () + delta[block_line_section]); - - for (blockrange &r : b->ranges ()) - { - r.set_start (r.start () + delta[block_line_section]); - r.set_end (r.end () + delta[block_line_section]); - } - - /* We only want to iterate over the local symbols, not any - symbols in included symtabs. */ - for (struct symbol *sym : b->multidict_symbols ()) - relocate_one_symbol (sym, objfile, delta); - } - } + cust.blockvector ()->relocate (objfile, delta); /* Relocate isolated symbols. */ for (symbol *iter = objfile->template_symbols; iter; iter = iter->hash_next) - relocate_one_symbol (iter, objfile, delta); + iter->relocate (objfile, delta); for (int i = 0; i < objfile->section_offsets.size (); ++i) objfile->section_offsets[i] = new_offsets[i]; diff --git a/gdb/symtab.c b/gdb/symtab.c index cc6dbcf7aab..93c91c43bf3 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6610,6 +6610,16 @@ symbol::value_block () const /* See symtab.h. */ +void +symbol::relocate (struct objfile *objfile, const section_offsets &delta) +{ + if ((loc_class () == LOC_LABEL || loc_class () == LOC_STATIC) + && section_index () >= 0) + set_value_address (value_address () + delta[section_index ()]); +} + +/* See symtab.h. */ + CORE_ADDR minimal_symbol::get_maybe_copied_address (objfile *objf) const { diff --git a/gdb/symtab.h b/gdb/symtab.h index 845c49e057d..4f2b88859a5 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1458,6 +1458,11 @@ struct symbol : public general_symbol_info, public allocate_on_obstack void set_symtab (struct symtab *symtab); + /* Relocate this symbol. OBJFILE is the objfile holding this + blockvector, and OFFSETS is the relocation offsets to use. */ + + void relocate (struct objfile *objfile, const section_offsets &offsets); + /* Data type of value */ struct type *m_type = nullptr; @@ -1675,13 +1680,6 @@ struct linetable struct linetable_entry item[1]; }; -/* How to relocate the symbols from each section in a symbol file. - The ordering and meaning of the offsets is file-type-dependent; - typically it is indexed by section numbers or symbol types or - something like that. */ - -typedef std::vector section_offsets; - /* Each source file or header is represented by a struct symtab. The name "symtab" is historical, another name for it is "filetab". These objects are chained through the `next' field. */ -- 2.49.0