From patchwork Tue Mar 21 19:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66717 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E60F3847833 for ; Tue, 21 Mar 2023 19:19:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id 2092F3858C62 for ; Tue, 21 Mar 2023 19:18:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2092F3858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway3.mail.pro1.eigbox.com (Postfix) with ESMTP id 678991003F507 for ; Tue, 21 Mar 2023 19:18:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id ehVAp64q6RSTPehVAp7M0R; Tue, 21 Mar 2023 19:18:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=VeEygHl9 c=1 sm=1 tr=0 ts=641a0308 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=MXjOBQuO8C53K5ZXAgIA:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ra6H7pJJ9pKavqAkx4BiOrc5rvTFqXyveZA1v/MAwT4=; b=aqyRN9/STUHWYPOZ/7AVabRkuH DcEMKlgdBmT3lB/NUWkPXa4mSDO+EToVjJwRLJHN6OyEQDhn1ctOstblcNf2xZUwy/xJPwE4tCrhs grn5YYsG8KNkgEu+bZgMEr7HF; Received: from 71-211-185-113.hlrn.qwest.net ([71.211.185.113]:53618 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pehVA-00150d-4m for gdb-patches@sourceware.org; Tue, 21 Mar 2023 13:18:32 -0600 From: Tom Tromey Date: Tue, 21 Mar 2023 13:18:30 -0600 Subject: [PATCH 5/6] Use unrelocated_addr in minimal symbols MIME-Version: 1.0 Message-Id: <20230321-submit-unrelocated-type-v1-5-2a1fb6117abf@tromey.com> References: <20230321-submit-unrelocated-type-v1-0-2a1fb6117abf@tromey.com> In-Reply-To: <20230321-submit-unrelocated-type-v1-0-2a1fb6117abf@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 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: 71.211.185.113 X-Source-L: No X-Exim-ID: 1pehVA-00150d-4m X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-185-113.hlrn.qwest.net ([192.168.0.21]) [71.211.185.113]:53618 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3024.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes minimal symbols to use unrelocated_addr. I believe this detected a latent bug in add_pe_forwarded_sym. --- gdb/coff-pe-read.c | 13 +++++-------- gdb/coffread.c | 12 +++++++----- gdb/dbxread.c | 28 ++++++++++++++++------------ gdb/elfread.c | 22 +++++++++++++--------- gdb/findvar.c | 4 ++-- gdb/machoread.c | 4 ++-- gdb/mdebugread.c | 17 ++++++++++------- gdb/minsyms.c | 40 ++++++++++++++++++++-------------------- gdb/minsyms.h | 6 +++--- gdb/mips-tdep.c | 6 ++++-- gdb/mipsread.c | 2 +- gdb/parse.c | 2 +- gdb/printcmd.c | 2 +- gdb/solib.c | 2 +- gdb/symmisc.c | 2 +- gdb/symtab.c | 2 +- gdb/symtab.h | 15 +++++++++++++-- gdb/xcoffread.c | 16 ++++++++-------- 18 files changed, 109 insertions(+), 86 deletions(-) diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index 2b89e8a3542..07cd216b4b2 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -127,7 +127,8 @@ add_pe_exported_sym (minimal_symbol_reader &reader, const char *dll_name, struct objfile *objfile) { /* Add the stored offset to get the loaded address of the symbol. */ - CORE_ADDR vma = func_rva + section_data->vma_offset; + unrelocated_addr vma = unrelocated_addr (func_rva + + section_data->vma_offset); /* Generate a (hopefully unique) qualified name using the first part of the dll name, e.g. KERNEL32!AddAtomA. This matches the style @@ -174,7 +175,6 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, const char *forward_func_name, int ordinal, const char *dll_name, struct objfile *objfile) { - CORE_ADDR vma, baseaddr; struct bound_minimal_symbol msymbol; enum minimal_symbol_type msymtype; int forward_dll_name_len = strlen (forward_dll_name); @@ -210,7 +210,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, " \"%s\" in dll \"%s\", pointing to \"%s\"\n"), sym_name, dll_name, forward_qualified_name.c_str ()); - vma = msymbol.value_address (); + unrelocated_addr vma = msymbol.minsym->value_raw_address (); msymtype = msymbol.minsym->type (); section = msymbol.minsym->section_index (); @@ -232,14 +232,11 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, really be relocated properly, but nevertheless we make a stab at it, choosing an approach consistent with the history of this code. */ - baseaddr = objfile->text_section_offset (); - reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype, - section); + reader.record_with_info (qualified_name.c_str (), vma, msymtype, section); /* Enter the plain name as well, which might not be unique. */ - reader.record_with_info (bare_name.c_str(), vma - baseaddr, msymtype, - section); + reader.record_with_info (bare_name.c_str(), vma, msymtype, section); return 1; } diff --git a/gdb/coffread.c b/gdb/coffread.c index e993b17db09..837455a1d71 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -445,7 +445,7 @@ is_import_fixup_symbol (struct coff_symbol *cs, static struct minimal_symbol * record_minimal_symbol (minimal_symbol_reader &reader, - struct coff_symbol *cs, CORE_ADDR address, + struct coff_symbol *cs, unrelocated_addr address, enum minimal_symbol_type type, int section, struct objfile *objfile) { @@ -880,8 +880,9 @@ coff_symtab_read (minimal_symbol_reader &reader, tmpaddr = cs->c_value; /* Don't record unresolved symbols. */ if (!(cs->c_secnum <= 0 && cs->c_value == 0)) - record_minimal_symbol (reader, cs, tmpaddr, mst_text, - section, objfile); + record_minimal_symbol (reader, cs, + unrelocated_addr (tmpaddr), + mst_text, section, objfile); fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr; fcn_start_addr = tmpaddr; @@ -1041,8 +1042,9 @@ coff_symtab_read (minimal_symbol_reader &reader, ms_type = mst_unknown; } - msym = record_minimal_symbol (reader, cs, tmpaddr, ms_type, - sec, objfile); + msym = record_minimal_symbol (reader, cs, + unrelocated_addr (tmpaddr), + ms_type, sec, objfile); if (msym) gdbarch_coff_make_msymbol_special (gdbarch, cs->c_sclass, msym); diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 677e91d7725..9df9320bc7b 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -157,7 +157,7 @@ static unsigned char processing_acc_compilation; need to make guesses based on the symbols (which *are* relocated to reflect the address it will be loaded at). */ -static CORE_ADDR lowest_text_address; +static unrelocated_addr lowest_text_address; /* Non-zero if there is any line number info in the objfile. Prevents dbx_end_psymtab from discarding an otherwise empty psymtab. */ @@ -286,7 +286,7 @@ static void dbx_symfile_read (struct objfile *, symfile_add_flags); static void dbx_symfile_finish (struct objfile *); static void record_minimal_symbol (minimal_symbol_reader &, - const char *, CORE_ADDR, int, + const char *, unrelocated_addr, int, struct objfile *); static void add_new_header_file (const char *, int); @@ -428,7 +428,7 @@ explicit_lookup_type (int real_filenum, int index) static void record_minimal_symbol (minimal_symbol_reader &reader, - const char *name, CORE_ADDR address, int type, + const char *name, unrelocated_addr address, int type, struct objfile *objfile) { enum minimal_symbol_type ms_type; @@ -1009,7 +1009,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, set_last_source_file (NULL); - lowest_text_address = (CORE_ADDR) -1; + lowest_text_address = (unrelocated_addr) -1; symfile_bfd = objfile->obfd.get (); /* For next_text_symbol. */ abfd = objfile->obfd.get (); @@ -1103,7 +1103,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, record_it: namestring = set_namestring (objfile, &nlist); - record_minimal_symbol (reader, namestring, nlist.n_value, + record_minimal_symbol (reader, namestring, + unrelocated_addr (nlist.n_value), nlist.n_type, objfile); /* Always */ continue; @@ -1680,7 +1681,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, pst ? pst->filename : NULL, objfile); if (minsym.minsym != NULL) - nlist.n_value = minsym.minsym->value_raw_address (); + nlist.n_value + = CORE_ADDR (minsym.minsym->value_raw_address ()); } if (pst && textlow_not_set && gdbarch_sofun_address_maybe_missing (gdbarch)) @@ -1738,7 +1740,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, pst ? pst->filename : NULL, objfile); if (minsym.minsym != NULL) - nlist.n_value = minsym.minsym->value_raw_address (); + nlist.n_value + = CORE_ADDR (minsym.minsym->value_raw_address ()); } if (pst && textlow_not_set && gdbarch_sofun_address_maybe_missing (gdbarch)) @@ -1945,10 +1948,11 @@ read_dbx_symtab (minimal_symbol_reader &reader, /* Don't set high text address of PST lower than it already is. */ unrelocated_addr text_end - = unrelocated_addr ((lowest_text_address == (CORE_ADDR) -1 - ? text_addr - : lowest_text_address) - + text_size); + = (unrelocated_addr + (lowest_text_address == (unrelocated_addr) -1 + ? text_addr + : CORE_ADDR (lowest_text_address) + + text_size)); dbx_end_psymtab (objfile, partial_symtabs, pst, psymtab_include_list, includes_used, @@ -2054,7 +2058,7 @@ dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs, if (minsym.minsym) pst->set_text_high - (unrelocated_addr (minsym.minsym->value_raw_address () + (unrelocated_addr (CORE_ADDR (minsym.minsym->value_raw_address ()) + minsym.minsym->size ())); last_function_name = NULL; diff --git a/gdb/elfread.c b/gdb/elfread.c index b414da9ed21..55771492044 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -199,7 +199,7 @@ elf_locate_sections (asection *sectp, struct elfinfo *ei) static struct minimal_symbol * record_minimal_symbol (minimal_symbol_reader &reader, gdb::string_view name, bool copy_name, - CORE_ADDR address, + unrelocated_addr address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile) { @@ -207,7 +207,9 @@ record_minimal_symbol (minimal_symbol_reader &reader, if (ms_type == mst_text || ms_type == mst_file_text || ms_type == mst_text_gnu_ifunc) - address = gdbarch_addr_bits_remove (gdbarch, address); + address + = unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, + CORE_ADDR (address))); /* We only setup section information for allocatable sections. Usually we'd only expect to find msymbols for allocatable sections, but if the @@ -338,7 +340,8 @@ elf_symtab_read (minimal_symbol_reader &reader, msym = record_minimal_symbol (reader, sym->name, copy_names, - symaddr, mst_solib_trampoline, sect, objfile); + unrelocated_addr (symaddr), + mst_solib_trampoline, sect, objfile); if (msym != NULL) { msym->filename = filesymname; @@ -477,7 +480,7 @@ elf_symtab_read (minimal_symbol_reader &reader, continue; /* Skip this symbol. */ } msym = record_minimal_symbol - (reader, sym->name, copy_names, symaddr, + (reader, sym->name, copy_names, unrelocated_addr (symaddr), ms_type, sym->section, objfile); if (msym) @@ -509,8 +512,8 @@ elf_symtab_read (minimal_symbol_reader &reader, && (elf_sym->version & VERSYM_HIDDEN) == 0) record_minimal_symbol (reader, gdb::string_view (sym->name, len), - true, symaddr, ms_type, sym->section, - objfile); + true, unrelocated_addr (symaddr), + ms_type, sym->section, objfile); else if (is_plt) { /* For @plt symbols, also record a trampoline to the @@ -523,7 +526,8 @@ elf_symtab_read (minimal_symbol_reader &reader, mtramp = record_minimal_symbol (reader, gdb::string_view (sym->name, len), true, - symaddr, mst_solib_trampoline, sym->section, objfile); + unrelocated_addr (symaddr), + mst_solib_trampoline, sym->section, objfile); if (mtramp) { mtramp->set_size (msym->size()); @@ -641,8 +645,8 @@ elf_rel_plt_read (minimal_symbol_reader &reader, string_buffer.append (got_suffix, got_suffix + got_suffix_len); msym = record_minimal_symbol (reader, string_buffer, - true, address, mst_slot_got_plt, - msym_section, objfile); + true, unrelocated_addr (address), + mst_slot_got_plt, msym_section, objfile); if (msym) msym->set_size (ptr_size); } diff --git a/gdb/findvar.c b/gdb/findvar.c index 60b5ca3faf3..97cc9ba7660 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -754,9 +754,9 @@ language_defn::read_var_value (struct symbol *var, a TLS variable. */ if (obj_section == NULL || (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) - addr = bmsym.minsym->value_raw_address (); + addr = CORE_ADDR (bmsym.minsym->value_raw_address ()); else - addr = bmsym.value_address (); + addr = bmsym.value_address (); if (overlay_debugging) addr = symbol_overlayed_address (addr, obj_section); /* Determine address of TLS variable. */ diff --git a/gdb/machoread.c b/gdb/machoread.c index e8cae810788..9735de80d57 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -98,11 +98,11 @@ macho_symtab_add_minsym (minimal_symbol_reader &reader, if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK)) { - CORE_ADDR symaddr; + unrelocated_addr symaddr; enum minimal_symbol_type ms_type; /* Bfd symbols are section relative. */ - symaddr = sym->value + sym->section->vma; + symaddr = unrelocated_addr (sym->value + sym->section->vma); if (sym->section == bfd_abs_section_ptr) ms_type = mst_abs; diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index e0415587646..8faf482b09c 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -2235,7 +2235,7 @@ function_outside_compilation_unit_complaint (const char *arg1) static void record_minimal_symbol (minimal_symbol_reader &reader, - const char *name, const CORE_ADDR address, + const char *name, const unrelocated_addr address, enum minimal_symbol_type ms_type, int storage_class, struct objfile *objfile) { @@ -2461,7 +2461,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, for (; ext_in < ext_in_end; ext_in++) { enum minimal_symbol_type ms_type = mst_text; - CORE_ADDR svalue = ext_in->asym.value; + unrelocated_addr svalue = unrelocated_addr (ext_in->asym.value); /* The Irix 5 native tools seem to sometimes generate bogus external symbols. */ @@ -2701,7 +2701,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, if (sh.st == stStaticProc) { namestring = debug_info->ss + fh->issBase + sh.iss; - record_minimal_symbol (reader, namestring, sh.value, + record_minimal_symbol (reader, namestring, + unrelocated_addr (sh.value), mst_file_text, sh.sc, objfile); } @@ -2747,7 +2748,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, case scPData: case scXData: namestring = debug_info->ss + fh->issBase + sh.iss; - record_minimal_symbol (reader, namestring, sh.value, + record_minimal_symbol (reader, namestring, + unrelocated_addr (sh.value), mst_file_data, sh.sc, objfile); break; @@ -2756,7 +2758,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, /* FIXME! Shouldn't this use cases for bss, then have the default be abs? */ namestring = debug_info->ss + fh->issBase + sh.iss; - record_minimal_symbol (reader, namestring, sh.value, + record_minimal_symbol (reader, namestring, + unrelocated_addr (sh.value), mst_file_bss, sh.sc, objfile); break; @@ -3369,7 +3372,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, { char *sym_name; enum address_class theclass; - CORE_ADDR minsym_value; + unrelocated_addr minsym_value; short section = -1; (*swap_sym_in) (cur_bfd, @@ -3396,7 +3399,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, sym_name = debug_info->ss + fh->issBase + sh.iss; - minsym_value = sh.value; + minsym_value = unrelocated_addr (sh.value); switch (sh.sc) { diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 02e36cc6dd2..67bd4903a3e 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -672,19 +672,20 @@ lookup_minimal_symbol_by_pc_name (CORE_ADDR pc, const char *name, /* A helper function that makes *PC section-relative. This searches the sections of OBJFILE and if *PC is in a section, it subtracts - the section offset and returns true. Otherwise it returns - false. */ + the section offset, stores the result into UNREL_ADDR, and returns + true. Otherwise it returns false. */ static int -frob_address (struct objfile *objfile, CORE_ADDR *pc) +frob_address (struct objfile *objfile, CORE_ADDR pc, + unrelocated_addr *unrel_addr) { struct obj_section *iter; ALL_OBJFILE_OSECTIONS (objfile, iter) { - if (*pc >= iter->addr () && *pc < iter->endaddr ()) + if (pc >= iter->addr () && pc < iter->endaddr ()) { - *pc -= iter->offset (); + *unrel_addr = unrelocated_addr (pc - iter->offset ()); return 1; } } @@ -793,15 +794,16 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio Warning: this code is trickier than it would appear at first. */ - if (frob_address (objfile, &pc) - && pc >= msymbol[lo].value_raw_address ()) + unrelocated_addr unrel_pc; + if (frob_address (objfile, pc, &unrel_pc) + && unrel_pc >= msymbol[lo].value_raw_address ()) { - while (msymbol[hi].value_raw_address () > pc) + while (msymbol[hi].value_raw_address () > unrel_pc) { /* pc is still strictly less than highest address. */ /* Note "new" will always be >= lo. */ newobj = (lo + hi) / 2; - if ((msymbol[newobj].value_raw_address () >= pc) + if ((msymbol[newobj].value_raw_address () >= unrel_pc) || (lo == newobj)) { hi = newobj; @@ -894,10 +896,8 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio the cancellable variants, but both have sizes. */ if (hi > 0 && msymbol[hi].size () != 0 - && pc >= (msymbol[hi].value_raw_address () - + msymbol[hi].size ()) - && pc < (msymbol[hi - 1].value_raw_address () - + msymbol[hi - 1].size ())) + && unrel_pc >= msymbol[hi].value_raw_end_address () + && unrel_pc < msymbol[hi - 1].value_raw_end_address ()) { hi--; continue; @@ -926,8 +926,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio if (hi >= 0 && msymbol[hi].size () != 0 - && pc >= (msymbol[hi].value_raw_address () - + msymbol[hi].size ())) + && unrel_pc >= msymbol[hi].value_raw_end_address ()) { if (best_zero_sized != -1) hi = best_zero_sized; @@ -1092,7 +1091,7 @@ minimal_symbol_reader::~minimal_symbol_reader () /* See minsyms.h. */ void -minimal_symbol_reader::record (const char *name, CORE_ADDR address, +minimal_symbol_reader::record (const char *name, unrelocated_addr address, enum minimal_symbol_type ms_type) { int section; @@ -1152,7 +1151,7 @@ mst_str (minimal_symbol_type t) struct minimal_symbol * minimal_symbol_reader::record_full (gdb::string_view name, - bool copy_name, CORE_ADDR address, + bool copy_name, unrelocated_addr address, enum minimal_symbol_type ms_type, int section) { @@ -1178,8 +1177,9 @@ minimal_symbol_reader::record_full (gdb::string_view name, return (NULL); symtab_create_debug_printf_v ("recording minsym: %-21s %18s %4d %.*s", - mst_str (ms_type), hex_string (address), section, - (int) name.size (), name.data ()); + mst_str (ms_type), + hex_string (LONGEST (address)), + section, (int) name.size (), name.data ()); if (m_msym_bunch_index == BUNCH_SIZE) { @@ -1198,7 +1198,7 @@ minimal_symbol_reader::record_full (gdb::string_view name, else msymbol->m_name = name.data (); - msymbol->set_value_address (address); + msymbol->set_unrelocated_address (address); msymbol->set_section_index (section); msymbol->set_type (ms_type); diff --git a/gdb/minsyms.h b/gdb/minsyms.h index e9081495eb1..59c276f01f3 100644 --- a/gdb/minsyms.h +++ b/gdb/minsyms.h @@ -120,7 +120,7 @@ class minimal_symbol_reader struct minimal_symbol *record_full (gdb::string_view name, bool copy_name, - CORE_ADDR address, + unrelocated_addr address, enum minimal_symbol_type ms_type, int section); @@ -131,7 +131,7 @@ class minimal_symbol_reader This variant does not return the new symbol. */ - void record (const char *name, CORE_ADDR address, + void record (const char *name, unrelocated_addr address, enum minimal_symbol_type ms_type); /* Like record_full, but: @@ -140,7 +140,7 @@ class minimal_symbol_reader This variant does not return the new symbol. */ - void record_with_info (const char *name, CORE_ADDR address, + void record_with_info (const char *name, unrelocated_addr address, enum minimal_symbol_type ms_type, int section) { diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 52799b926d3..b86bf61f4d1 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -436,12 +436,14 @@ mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) if (ELF_ST_IS_MICROMIPS (st_other)) { SET_MSYMBOL_TARGET_FLAG_MICROMIPS (msym); - msym->set_value_address (msym->value_raw_address () | 1); + CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1; + msym->set_unrelocated_address (unrelocated_addr (fixed)); } else if (ELF_ST_IS_MIPS16 (st_other)) { SET_MSYMBOL_TARGET_FLAG_MIPS16 (msym); - msym->set_value_address (msym->value_raw_address () | 1); + CORE_ADDR fixed = CORE_ADDR (msym->value_raw_address ()) | 1; + msym->set_unrelocated_address (unrelocated_addr (fixed)); } } diff --git a/gdb/mipsread.c b/gdb/mipsread.c index 5c2c88e81c2..efff2841974 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -358,7 +358,7 @@ read_alphacoff_dynamic_symtab (minimal_symbol_reader &reader, } } - reader.record (name, sym_value, ms_type); + reader.record (name, unrelocated_addr (sym_value), ms_type); } } diff --git a/gdb/parse.c b/gdb/parse.c index 24db3ca57d9..4bce63c58f7 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -115,7 +115,7 @@ find_minsym_type_and_address (minimal_symbol *msymbol, { /* Addresses of TLS symbols are really offsets into a per-objfile/per-thread storage block. */ - addr = bound_msym.minsym->value_raw_address (); + addr = CORE_ADDR (bound_msym.minsym->value_raw_address ()); } else if (msymbol_is_function (objfile, msymbol, &addr)) { diff --git a/gdb/printcmd.c b/gdb/printcmd.c index ae59a14aeb1..d4b3cce696f 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1824,7 +1824,7 @@ info_address_command (const char *exp, int from_tty) if (section && (section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) { - load_addr = msym.minsym->value_raw_address (); + load_addr = CORE_ADDR (msym.minsym->value_raw_address ()); gdb_printf (_("a thread-local variable at offset %s " "in the thread-local storage for `%s'"), paddress (gdbarch, load_addr), diff --git a/gdb/solib.c b/gdb/solib.c index e6bccc85ca7..e839b634e04 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1515,7 +1515,7 @@ gdb_bfd_lookup_symbol_from_symtab msym.set_value_address (symaddr); gdbarch_elf_make_msymbol_special (gdbarch, sym, &msym); - symaddr = msym.value_raw_address (); + symaddr = CORE_ADDR (msym.value_raw_address ()); } /* BFD symbols are section relative. */ diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 54dc570d282..df2bdb0d7c3 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -201,7 +201,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile) /* Use the relocated address as shown in the symbol here -- do not try to respect copy relocations. */ - CORE_ADDR addr = (msymbol->value_raw_address () + CORE_ADDR addr = (CORE_ADDR (msymbol->value_raw_address ()) + objfile->section_offsets[msymbol->section_index ()]); gdb_puts (paddress (gdbarch, addr), outfile); gdb_printf (outfile, " %s", msymbol->linkage_name ()); diff --git a/gdb/symtab.c b/gdb/symtab.c index 8ab1f58affe..ac6535fe983 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -424,7 +424,7 @@ minimal_symbol::value_address (objfile *objfile) const if (this->maybe_copied) return get_msymbol_address (objfile, this); else - return (this->value_raw_address () + return (CORE_ADDR (this->value_raw_address ()) + objfile->section_offsets[this->section_index ()]); } diff --git a/gdb/symtab.h b/gdb/symtab.h index 4d760863081..1f3e0b87b19 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -754,10 +754,21 @@ struct minimal_symbol : public general_symbol_info offsets from OBJFILE. */ CORE_ADDR value_address (objfile *objfile) const; + /* It does not make sense to call this for minimal symbols, as they + are stored unrelocated. */ + CORE_ADDR value_address () const = delete; + /* The unrelocated address of the minimal symbol. */ - CORE_ADDR value_raw_address () const + unrelocated_addr value_raw_address () const { - return m_value.address; + return m_value.unrel_addr; + } + + /* The unrelocated address just after the end of the the minimal + symbol. */ + unrelocated_addr value_raw_end_address () const + { + return unrelocated_addr (CORE_ADDR (value_raw_address ()) + size ()); } /* Return this minimal symbol's type. */ diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 5c20468e9e4..52ed13062f2 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -840,7 +840,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset, static void record_minimal_symbol (minimal_symbol_reader &reader, - const char *name, CORE_ADDR address, + const char *name, unrelocated_addr address, enum minimal_symbol_type ms_type, int n_scnum, struct objfile *objfile) @@ -2055,7 +2055,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, unsigned int ssymnum; const char *last_csect_name = NULL; /* Last seen csect's name and value. */ - CORE_ADDR last_csect_val = 0; + unrelocated_addr last_csect_val = unrelocated_addr (0); int last_csect_sec = 0; int misc_func_recorded = 0; /* true if any misc. function. */ int textlow_not_set = 1; @@ -2168,7 +2168,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, || namestring[0] == '@')) { last_csect_name = namestring; - last_csect_val = symbol.n_value; + last_csect_val = unrelocated_addr (symbol.n_value); last_csect_sec = symbol.n_scnum; } if (pst != NULL) @@ -2193,7 +2193,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, table, except for section symbols. */ if (*namestring != '.') record_minimal_symbol - (reader, namestring, symbol.n_value, + (reader, namestring, unrelocated_addr (symbol.n_value), sclass == C_HIDEXT ? mst_file_data : mst_data, symbol.n_scnum, objfile); break; @@ -2231,7 +2231,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr; record_minimal_symbol - (reader, namestring, symbol.n_value, + (reader, namestring, unrelocated_addr (symbol.n_value), sclass == C_HIDEXT ? mst_file_text : mst_text, symbol.n_scnum, objfile); misc_func_recorded = 1; @@ -2246,7 +2246,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, symbols, we will choose mst_text over mst_solib_trampoline. */ record_minimal_symbol - (reader, namestring, symbol.n_value, + (reader, namestring, unrelocated_addr (symbol.n_value), mst_solib_trampoline, symbol.n_scnum, objfile); misc_func_recorded = 1; break; @@ -2268,7 +2268,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, XMC_BS might be possible too. */ if (*namestring != '.') record_minimal_symbol - (reader, namestring, symbol.n_value, + (reader, namestring, unrelocated_addr (symbol.n_value), sclass == C_HIDEXT ? mst_file_data : mst_data, symbol.n_scnum, objfile); break; @@ -2284,7 +2284,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, table, except for section symbols. */ if (*namestring != '.') record_minimal_symbol - (reader, namestring, symbol.n_value, + (reader, namestring, unrelocated_addr (symbol.n_value), sclass == C_HIDEXT ? mst_file_bss : mst_bss, symbol.n_scnum, objfile); break;