From patchwork Wed Jan 18 15:30:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63340 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 9A2873854385 for ; Wed, 18 Jan 2023 15:31:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A2873854385 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674055865; bh=it4NLATF+NjxumuMV8pJmW/onsnpzFI6LUC41ri3/RE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VxWO/9Sgibe8ispj3nF527Kp8BlUGdcVN7QYh3Ws+Blhzz1ZwzJv5XEgQWTFPhFwv fhdYCWVPDLmivmSp9GkHqt0IKjuJcVafdTfhCx41UBLIyFiPsHS6TwiTVWKNKjHmgc /W65O/eZvOhDip+EWRWuhmTcJOZl4y0/zzftL384= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 5F5493858C53 for ; Wed, 18 Jan 2023 15:30:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F5493858C53 Received: by mail-il1-x12c.google.com with SMTP id m7so4624383ilh.7 for ; Wed, 18 Jan 2023 07:30:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=it4NLATF+NjxumuMV8pJmW/onsnpzFI6LUC41ri3/RE=; b=bQtlWxSXq5ayBcyhIh8qDedba8V5irLSFSU0MFpi92jBJaAa8L0t3QftegxAbOaGk9 2OyHpkPppf+IWRjThEYNVa+WSvjRvSkGe8efpTKzpMLaJRY+sBwseTVsGfC0Vi7ZkJAu viJNw09xRazklcAZ7JB73MmaOnJ4p2iv7aNyvXiRypUm5GyQ9CMu55/8ZvVkBn+lvIb4 QEQEj7QPd7UFZ6wJ75FA5eubtPbRI/yaCA5Fn7kmlLuwNwVldYv/pULf4ScjH9BB96K5 jEwq0CJu2mcfwnqol6yahuwku7+4ai1EpWH/+pyeCwda0e+/wK1Vvx7GuqJPcG3RBm69 qprA== X-Gm-Message-State: AFqh2krU2muhkvvzeOtfGku9zFm0Hm0qVAHIH2zVfrLZWjJQr+rdmZhA 4FN5TSlWdU8QiGNvfianXyzz29HlyQ5OpOVO X-Google-Smtp-Source: AMrXdXss/NZuBpyTKWJ+Cd0hLDMHbvqn9Ksa9fcYYk0F+0d16LYkzM9mL4B1oUf2f7dVXJ2MazjpzQ== X-Received: by 2002:a92:c011:0:b0:30d:859b:156a with SMTP id q17-20020a92c011000000b0030d859b156amr5867030ild.16.1674055837527; Wed, 18 Jan 2023 07:30:37 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id m4-20020a056e020de400b0030bf2476c5fsm10106502ilj.25.2023.01.18.07.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:30:37 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/6] Set section indices when symbols are made Date: Wed, 18 Jan 2023 08:30:21 -0700 Message-Id: <20230118153025.342512-3-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230118153025.342512-1-tromey@adacore.com> References: <20230118153025.342512-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Most places in gdb that create a new symbol will apply a section offset to the address. It seems to me that the choice of offset here is also an implicit choice of the section. This is particularly true if you examine fixup_section, which notes that it must be called before such offsets are applied -- meaning that if any such call has an effect, it's purely by accident. This patch cleans up this area by tracking the section index and applying it to a symbol when the address is set. This is done for nearly every case -- the remaining cases will be handled in later patches. --- gdb/dbxread.c | 21 ++++++++++++++++++++- gdb/dwarf2/read.c | 1 + gdb/mdebugread.c | 18 ++++++++++++++---- gdb/stabsread.c | 14 ++++++++------ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/gdb/dbxread.c b/gdb/dbxread.c index ab0734f0218..dc11f0bb6a9 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2414,6 +2414,9 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, source file. Used to detect the SunPRO solaris compiler. */ static int n_opt_found; + /* The section index for this symbol. */ + int section_index = -1; + /* Something is wrong if we see real data before seeing a source file name. */ @@ -2477,6 +2480,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, sline_found_in_function = 0; /* Relocate for dynamic loading. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; valu = gdbarch_addr_bits_remove (gdbarch, valu); last_function_start = valu; @@ -2565,6 +2569,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, case N_FN_SEQ: /* This kind of symbol indicates the start of an object file. Relocate for dynamic loading. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; break; @@ -2573,6 +2578,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, source file. Finish the symbol table of the previous source file (if any) and start accumulating a new symbol table. Relocate for dynamic loading. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; n_opt_found = 0; @@ -2609,6 +2615,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, sub-source-file, one whose contents were copied or included in the compilation of the main source file (whose name was given in the N_SO symbol). Relocate for dynamic loading. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; start_subfile (name); break; @@ -2709,6 +2716,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, symbol_file_add as addr (this is known to affect SunOS 4, and I suspect ELF too). Since there is no Ttext.text symbol, we can get addr from the text offset. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; } @@ -2730,21 +2738,25 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, case_N_STSYM: /* Static symbol in data segment. */ case N_DSLINE: /* Source line number, data segment. */ + section_index = SECT_OFF_DATA (objfile); valu += section_offsets[SECT_OFF_DATA (objfile)]; goto define_a_symbol; case_N_LCSYM: /* Static symbol in BSS segment. */ case N_BSLINE: /* Source line number, BSS segment. */ /* N_BROWS: overlaps with N_BSLINE. */ + section_index = SECT_OFF_BSS (objfile); valu += section_offsets[SECT_OFF_BSS (objfile)]; goto define_a_symbol; case_N_ROSYM: /* Static symbol in read-only data segment. */ + section_index = SECT_OFF_RODATA (objfile); valu += section_offsets[SECT_OFF_RODATA (objfile)]; goto define_a_symbol; case N_ENTRY: /* Alternate entry point. */ /* Relocate for dynamic loading. */ + section_index = SECT_OFF_TEXT (objfile); valu += section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; @@ -2836,10 +2848,17 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, newobj = push_context (0, valu); newobj->name = define_symbol (valu, name, desc, type, objfile); + if (newobj->name != nullptr) + newobj->name->set_section_index (section_index); break; default: - define_symbol (valu, name, desc, type, objfile); + { + struct symbol *sym = define_symbol (valu, name, desc, type, + objfile); + if (sym != nullptr) + sym->set_section_index (section_index); + } break; } } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 44b54f77de9..6a7412ce834 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -20871,6 +20871,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, addr = attr->as_address (); addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr); + sym->set_section_index (SECT_OFF_TEXT (objfile)); sym->set_value_address (addr); sym->set_aclass_index (LOC_LABEL); } diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 8dc836a0f6e..4feee39035e 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -597,6 +597,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, else name = debug_info->ss + cur_fdr->issBase + sh->iss; + int section_index = -1; switch (sh->sc) { case scText: @@ -607,21 +608,24 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, The value of a stBlock symbol is the displacement from the procedure address. */ if (sh->st != stEnd && sh->st != stBlock) - sh->value += section_offsets[SECT_OFF_TEXT (objfile)]; + section_index = SECT_OFF_TEXT (objfile); break; case scData: case scSData: case scRData: case scPData: case scXData: - sh->value += section_offsets[SECT_OFF_DATA (objfile)]; + section_index = SECT_OFF_DATA (objfile); break; case scBss: case scSBss: - sh->value += section_offsets[SECT_OFF_BSS (objfile)]; + section_index = SECT_OFF_BSS (objfile); break; } + if (section_index != -1) + sh->value += section_offsets[section_index]; + switch (sh->st) { case stNil: @@ -630,6 +634,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, case stGlobal: /* External symbol, goes into global block. */ b = top_stack->cur_st->compunit ()->blockvector ()->global_block (); s = new_symbol (name); + s->set_section_index (section_index); s->set_value_address (sh->value); add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name); break; @@ -647,7 +652,10 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, global_sym_chain[bucket] = s; } else - s->set_value_address (sh->value); + { + s->set_section_index (section_index); + s->set_value_address (sh->value); + } add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name); break; @@ -704,6 +712,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, s = new_symbol (name); s->set_domain (VAR_DOMAIN); /* So that it can be used */ s->set_aclass_index (LOC_LABEL); /* but not misused. */ + s->set_section_index (section_index); s->set_value_address (sh->value); s->set_type (objfile_type (objfile)->builtin_int); add_symbol (s, top_stack->cur_st, top_stack->cur_block); @@ -745,6 +754,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, s = new_symbol (name); s->set_domain (VAR_DOMAIN); s->set_aclass_index (LOC_BLOCK); + s->set_section_index (section_index); /* Type of the return value. */ if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) t = objfile_type (objfile)->builtin_int; diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 8d1b998354f..ca9132b37d0 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -107,8 +107,6 @@ static void patch_block_stabs (struct pending *, struct pending_stabs *, struct objfile *); -static void fix_common_block (struct symbol *, CORE_ADDR); - static int read_type_number (const char **, int *); static struct type *read_type (const char **, struct objfile *); @@ -4305,7 +4303,7 @@ common_block_end (struct objfile *objfile) the common block name). */ static void -fix_common_block (struct symbol *sym, CORE_ADDR valu) +fix_common_block (struct symbol *sym, CORE_ADDR valu, int section_index) { struct pending *next = (struct pending *) sym->type (); @@ -4314,8 +4312,11 @@ fix_common_block (struct symbol *sym, CORE_ADDR valu) int j; for (j = next->nsyms - 1; j >= 0; j--) - next->symbol[j]->set_value_address - (next->symbol[j]->value_address () + valu); + { + next->symbol[j]->set_value_address + (next->symbol[j]->value_address () + valu); + next->symbol[j]->set_section_index (section_index); + } } } @@ -4585,7 +4586,8 @@ scan_file_globals (struct objfile *objfile) { if (sym->aclass () == LOC_BLOCK) fix_common_block - (sym, msymbol->value_address (resolve_objfile)); + (sym, msymbol->value_address (resolve_objfile), + msymbol->section_index ()); else sym->set_value_address (msymbol->value_address (resolve_objfile));