From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 5C5FE3858C53; Wed, 8 Feb 2023 16:46:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C5FE3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675874798; bh=DMTtCsIKvye6VV4uPiarSoWIVXtFaZWfIVCcmPjZCVo=; h=From:To:Subject:Date:From; b=CPX5XF//kpdPSglddkp2099rKgCNGzdm1tIJlJaGkSJGMhlFSUZWSc2fSXLd3u9VY /dnjccdF9y7WsojUpk4wmNrX3f8+TUPpgIgvuUttehK9tDOgmKI44AuzBA+y9mvNOn mEKrUUSXWMCR9CTLMzSriqwmiJp5amxhh0Ofpl+k= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Set section indices when symbols are made X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 3f01c12b9006227529823a07aee8a21627da63dd X-Git-Newrev: b8a6e9878141f5f1ac6c790e85257eadd51fff8f Message-Id: <20230208164638.5C5FE3858C53@sourceware.org> Date: Wed, 8 Feb 2023 16:46:38 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db8a6e9878141= f5f1ac6c790e85257eadd51fff8f commit b8a6e9878141f5f1ac6c790e85257eadd51fff8f Author: Tom Tromey Date: Fri Jan 13 08:57:08 2023 -0700 Set section indices when symbols are made =20 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. =20 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. Diff: --- 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 val= u, const char *name, source file. Used to detect the SunPRO solaris compiler. */ static int n_opt_found; =20 + /* The section index for this symbol. */ + int section_index =3D -1; + /* Something is wrong if we see real data before seeing a source file name. */ =20 @@ -2477,6 +2480,7 @@ process_one_symbol (int type, int desc, CORE_ADDR val= u, const char *name, sline_found_in_function =3D 0; =20 /* Relocate for dynamic loading. */ + section_index =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; valu =3D gdbarch_addr_bits_remove (gdbarch, valu); last_function_start =3D valu; @@ -2565,6 +2569,7 @@ process_one_symbol (int type, int desc, CORE_ADDR val= u, const char *name, case N_FN_SEQ: /* This kind of symbol indicates the start of an object file. Relocate for dynamic loading. */ + section_index =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; break; =20 @@ -2573,6 +2578,7 @@ process_one_symbol (int type, int desc, CORE_ADDR val= u, 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 =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; =20 n_opt_found =3D 0; @@ -2609,6 +2615,7 @@ process_one_symbol (int type, int desc, CORE_ADDR val= u, 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 =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; start_subfile (name); break; @@ -2709,6 +2716,7 @@ process_one_symbol (int type, int desc, CORE_ADDR val= u, 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 =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; } @@ -2730,21 +2738,25 @@ process_one_symbol (int type, int desc, CORE_ADDR v= alu, const char *name, =20 case_N_STSYM: /* Static symbol in data segment. */ case N_DSLINE: /* Source line number, data segment. */ + section_index =3D SECT_OFF_DATA (objfile); valu +=3D section_offsets[SECT_OFF_DATA (objfile)]; goto define_a_symbol; =20 case_N_LCSYM: /* Static symbol in BSS segment. */ case N_BSLINE: /* Source line number, BSS segment. */ /* N_BROWS: overlaps with N_BSLINE. */ + section_index =3D SECT_OFF_BSS (objfile); valu +=3D section_offsets[SECT_OFF_BSS (objfile)]; goto define_a_symbol; =20 case_N_ROSYM: /* Static symbol in read-only data segment. */ + section_index =3D SECT_OFF_RODATA (objfile); valu +=3D section_offsets[SECT_OFF_RODATA (objfile)]; goto define_a_symbol; =20 case N_ENTRY: /* Alternate entry point. */ /* Relocate for dynamic loading. */ + section_index =3D SECT_OFF_TEXT (objfile); valu +=3D section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; =20 @@ -2836,10 +2848,17 @@ process_one_symbol (int type, int desc, CORE_ADDR v= alu, const char *name, =20 newobj =3D push_context (0, valu); newobj->name =3D define_symbol (valu, name, desc, type, objfile); + if (newobj->name !=3D nullptr) + newobj->name->set_section_index (section_index); break; =20 default: - define_symbol (valu, name, desc, type, objfile); + { + struct symbol *sym =3D define_symbol (valu, name, desc, type, + objfile); + if (sym !=3D nullptr) + sym->set_section_index (section_index); + } break; } } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bbbf8ad1816..8708f7a4074 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -20885,6 +20885,7 @@ new_symbol (struct die_info *die, struct type *type= , struct dwarf2_cu *cu, =20 addr =3D attr->as_address (); addr =3D 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 =3D debug_info->ss + cur_fdr->issBase + sh->iss; =20 + int section_index =3D -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 !=3D stEnd && sh->st !=3D stBlock) - sh->value +=3D section_offsets[SECT_OFF_TEXT (objfile)]; + section_index =3D SECT_OFF_TEXT (objfile); break; case scData: case scSData: case scRData: case scPData: case scXData: - sh->value +=3D section_offsets[SECT_OFF_DATA (objfile)]; + section_index =3D SECT_OFF_DATA (objfile); break; case scBss: case scSBss: - sh->value +=3D section_offsets[SECT_OFF_BSS (objfile)]; + section_index =3D SECT_OFF_BSS (objfile); break; } =20 + if (section_index !=3D -1) + sh->value +=3D 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 =3D top_stack->cur_st->compunit ()->blockvector ()->global_block (= ); s =3D 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_s= h, int bigend, global_sym_chain[bucket] =3D 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; =20 @@ -704,6 +712,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh= , int bigend, s =3D 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 =3D 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 =3D=3D scNil) t =3D 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 *); =20 -static void fix_common_block (struct symbol *, CORE_ADDR); - static int read_type_number (const char **, int *); =20 static struct type *read_type (const char **, struct objfile *); @@ -4305,7 +4303,7 @@ common_block_end (struct objfile *objfile) the common block name). */ =20 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 =3D (struct pending *) sym->type (); =20 @@ -4314,8 +4312,11 @@ fix_common_block (struct symbol *sym, CORE_ADDR valu) int j; =20 for (j =3D next->nsyms - 1; j >=3D 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); + } } } =0C @@ -4585,7 +4586,8 @@ scan_file_globals (struct objfile *objfile) { if (sym->aclass () =3D=3D 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));