From 73b8e6a91526a2c6b6ef77730844aabaaa0886fe Mon Sep 17 00:00:00 2001 From: Peter Schauer Date: Sat, 2 Nov 1996 11:59:19 +0000 Subject: [PATCH] * irix5-nat.c, osfsolib.c, solib.c (symbol_add_stub): Handle missing or zero-sized .text sections properly. * mdebugread.c: Handle scRConst and scSUndefined storage classes. * stabsread.c (scan_file_globals): Try to resolve symbols for shared libraries from the minimal symbol table of the main executable first. --- gdb/ChangeLog | 9 +++ gdb/irix5-nat.c | 21 ++++++- gdb/mdebugread.c | 23 +++++--- gdb/osfsolib.c | 20 ++++++- gdb/stabsread.c | 144 ++++++++++++++++++++++++++--------------------- 5 files changed, 145 insertions(+), 72 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b829c4537d0..78f8b259f77 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +Sat Nov 2 03:54:13 1996 Peter Schauer (pes@regent.e-technik.tu-muenchen.de) + + * irix5-nat.c, osfsolib.c, solib.c (symbol_add_stub): Handle + missing or zero-sized .text sections properly. + * mdebugread.c: Handle scRConst and scSUndefined storage classes. + * stabsread.c (scan_file_globals): Try to resolve symbols + for shared libraries from the minimal symbol table of the main + executable first. + start-sanitize-d10v Fri Nov 1 13:59:28 1996 Martin M. Hunt diff --git a/gdb/irix5-nat.c b/gdb/irix5-nat.c index 8490968ac94..7bba96da8b8 100644 --- a/gdb/irix5-nat.c +++ b/gdb/irix5-nat.c @@ -566,9 +566,28 @@ symbol_add_stub (arg) char *arg; { register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */ + CORE_ADDR text_addr = 0; + + if (so -> textsection) + text_addr = so -> textsection -> addr; + else + { + asection *lowest_sect; + + /* If we didn't find a mapped non zero sized .text section, set up + text_addr so that the relocation in symbol_file_add does no harm. */ + + lowest_sect = bfd_get_section_by_name (so -> abfd, ".text"); + if (lowest_sect == NULL) + bfd_map_over_sections (so -> abfd, find_lowest_section, + (PTR) &lowest_sect); + if (lowest_sect) + text_addr = bfd_section_vma (so -> abfd, lowest_sect) + + (CORE_ADDR) LM_ADDR (so) - so -> lm.o_base_address; + } so -> objfile = symbol_file_add (so -> lm.o_path, so -> from_tty, - (unsigned int) so -> textsection -> addr, + text_addr, 0, 0, 0); return (1); } diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index c86fb6db06c..e0d4625c810 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -721,6 +721,7 @@ parse_symbol (sh, ax, ext_sh, bigend, section_offsets) switch (sh->sc) { case scText: + case scRConst: /* Do not relocate relative values. The value of a stEnd symbol is the displacement from the corresponding start symbol value. @@ -790,7 +791,8 @@ parse_symbol (sh, ax, ext_sh, bigend, section_offsets) add_symbol (s, b); /* Type could be missing if file is compiled without debugging info. */ - if (sh->sc == scUndefined || sh->sc == scNil || sh->index == indexNil) + if (sh->sc == scUndefined || sh->sc == scSUndefined + || sh->sc == scNil || sh->index == indexNil) SYMBOL_TYPE (s) = nodebug_var_symbol_type; else SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name); @@ -849,7 +851,7 @@ parse_symbol (sh, ax, ext_sh, bigend, section_offsets) SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; SYMBOL_CLASS (s) = LOC_BLOCK; /* Type of the return value */ - if (sh->sc == scUndefined || sh->sc == scNil) + if (sh->sc == scUndefined || sh->sc == scSUndefined || sh->sc == scNil) t = mdebug_type_int; else { @@ -898,7 +900,7 @@ parse_symbol (sh, ax, ext_sh, bigend, section_offsets) add_block (b, top_stack->cur_st); /* Not if we only have partial info */ - if (sh->sc == scUndefined || sh->sc == scNil) + if (sh->sc == scUndefined || sh->sc == scSUndefined || sh->sc == scNil) break; push_parse_stack (); @@ -2081,7 +2083,8 @@ parse_external (es, bigend, section_offsets) } /* Reading .o files */ - if (es->asym.sc == scUndefined || es->asym.sc == scNil) + if (es->asym.sc == scUndefined || es->asym.sc == scSUndefined + || es->asym.sc == scNil) { char *what; switch (es->asym.st) @@ -2387,7 +2390,8 @@ parse_partial_symbols (objfile, section_offsets) extern_tab[fdr_to_pst[ext_in->ifd].globals_offset + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in; - if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil) + if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scSUndefined + || ext_in->asym.sc == scNil) continue; name = debug_info->ssext + ext_in->asym.iss; @@ -2612,6 +2616,7 @@ parse_partial_symbols (objfile, section_offsets) switch (sh.sc) { case scUndefined: + case scSUndefined: case scNil: case scAbs: break; @@ -2677,7 +2682,8 @@ parse_partial_symbols (objfile, section_offsets) } /* Non absolute static symbols go into the minimal table. */ - if (sh.sc == scUndefined || sh.sc == scNil + if (sh.sc == scUndefined || sh.sc == scSUndefined + || sh.sc == scNil || (sh.index == indexNil && (sh.st != stStatic || sh.sc == scAbs))) { @@ -2691,6 +2697,7 @@ parse_partial_symbols (objfile, section_offsets) switch (sh.sc) { case scText: + case scRConst: /* The value of a stEnd symbol is the displacement from the corresponding start symbol value, do not relocate it. */ if (sh.st != stEnd) @@ -2895,13 +2902,15 @@ parse_partial_symbols (objfile, section_offsets) psh = &ext_ptr->asym; /* Do not add undefined symbols to the partial symbol table. */ - if (psh->sc == scUndefined || psh->sc == scNil) + if (psh->sc == scUndefined || psh->sc == scSUndefined + || psh->sc == scNil) continue; svalue = psh->value; switch (psh->sc) { case scText: + case scRConst: svalue += ANOFFSET (section_offsets, SECT_OFF_TEXT); break; case scData: diff --git a/gdb/osfsolib.c b/gdb/osfsolib.c index 85afa24211c..ea0720846a3 100644 --- a/gdb/osfsolib.c +++ b/gdb/osfsolib.c @@ -566,9 +566,27 @@ symbol_add_stub (arg) char *arg; { register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */ + CORE_ADDR text_addr = 0; + + if (so -> textsection) + text_addr = so -> textsection -> addr; + else + { + asection *lowest_sect; + + /* If we didn't find a mapped non zero sized .text section, set up + text_addr so that the relocation in symbol_file_add does no harm. */ + + lowest_sect = bfd_get_section_by_name (so -> abfd, ".text"); + if (lowest_sect == NULL) + bfd_map_over_sections (so -> abfd, find_lowest_section, + (PTR) &lowest_sect); + if (lowest_sect) + text_addr = bfd_section_vma (so -> abfd, lowest_sect) + LM_OFFSET (so); + } so -> objfile = symbol_file_add (so -> so_name, so -> from_tty, - so -> textsection -> addr, + text_addr, 0, 0, 0); return (1); } diff --git a/gdb/stabsread.c b/gdb/stabsread.c index be312af7195..175415dbd99 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -4491,87 +4491,105 @@ scan_file_globals (objfile) int hash; struct minimal_symbol *msymbol; struct symbol *sym, *prev; + struct objfile *resolve_objfile; - /* Avoid expensive loop through all minimal symbols if there are - no unresolved symbols. */ - for (hash = 0; hash < HASHSIZE; hash++) - { - if (global_sym_chain[hash]) - break; - } - if (hash >= HASHSIZE) - return; + /* SVR4 based linkers copy referenced global symbols from shared + libraries to the main executable. + If we are scanning the symbols for a shared library, try to resolve + them from the minimal symbols of the main executable first. */ - for (msymbol = objfile -> msymbols; - msymbol && SYMBOL_NAME (msymbol) != NULL; - msymbol++) - { - QUIT; + if (symfile_objfile && objfile != symfile_objfile) + resolve_objfile = symfile_objfile; + else + resolve_objfile = objfile; - /* Skip static symbols. */ - switch (MSYMBOL_TYPE (msymbol)) + while (1) + { + /* Avoid expensive loop through all minimal symbols if there are + no unresolved symbols. */ + for (hash = 0; hash < HASHSIZE; hash++) { - case mst_file_text: - case mst_file_data: - case mst_file_bss: - continue; - default: - break; + if (global_sym_chain[hash]) + break; } + if (hash >= HASHSIZE) + return; - prev = NULL; + for (msymbol = resolve_objfile -> msymbols; + msymbol && SYMBOL_NAME (msymbol) != NULL; + msymbol++) + { + QUIT; - /* Get the hash index and check all the symbols - under that hash index. */ + /* Skip static symbols. */ + switch (MSYMBOL_TYPE (msymbol)) + { + case mst_file_text: + case mst_file_data: + case mst_file_bss: + continue; + default: + break; + } - hash = hashname (SYMBOL_NAME (msymbol)); + prev = NULL; - for (sym = global_sym_chain[hash]; sym;) - { - if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] && - STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1)) + /* Get the hash index and check all the symbols + under that hash index. */ + + hash = hashname (SYMBOL_NAME (msymbol)); + + for (sym = global_sym_chain[hash]; sym;) { - /* Splice this symbol out of the hash chain and - assign the value we have to it. */ - if (prev) - { - SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); - } - else + if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] && + STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1)) { - global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); - } - - /* Check to see whether we need to fix up a common block. */ - /* Note: this code might be executed several times for - the same symbol if there are multiple references. */ + /* Splice this symbol out of the hash chain and + assign the value we have to it. */ + if (prev) + { + SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); + } + else + { + global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); + } + + /* Check to see whether we need to fix up a common block. */ + /* Note: this code might be executed several times for + the same symbol if there are multiple references. */ - if (SYMBOL_CLASS (sym) == LOC_BLOCK) - { - fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol)); - } - else - { - SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol); - } + if (SYMBOL_CLASS (sym) == LOC_BLOCK) + { + fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol)); + } + else + { + SYMBOL_VALUE_ADDRESS (sym) + = SYMBOL_VALUE_ADDRESS (msymbol); + } - SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol); - - if (prev) - { - sym = SYMBOL_VALUE_CHAIN (prev); + SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol); + + if (prev) + { + sym = SYMBOL_VALUE_CHAIN (prev); + } + else + { + sym = global_sym_chain[hash]; + } } else { - sym = global_sym_chain[hash]; + prev = sym; + sym = SYMBOL_VALUE_CHAIN (sym); } } - else - { - prev = sym; - sym = SYMBOL_VALUE_CHAIN (sym); - } } + if (resolve_objfile == objfile) + break; + resolve_objfile = objfile; } /* Change the storage class of any remaining unresolved globals to @@ -4593,7 +4611,7 @@ scan_file_globals (objfile) SYMBOL_CLASS (prev) = LOC_UNRESOLVED; else complain (&unresolved_sym_chain_complaint, - objfile->name, SYMBOL_NAME (prev)); + objfile -> name, SYMBOL_NAME (prev)); } } memset (global_sym_chain, 0, sizeof (global_sym_chain)); -- 2.30.2