diff options
Diffstat (limited to 'bfd/stabs.c')
-rw-r--r-- | bfd/stabs.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/bfd/stabs.c b/bfd/stabs.c index 42944a41bf1..04b91f68004 100644 --- a/bfd/stabs.c +++ b/bfd/stabs.c @@ -1,5 +1,5 @@ /* Stabs in sections linking support. - Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. @@ -56,12 +56,19 @@ struct stab_link_includes_table }; /* A linked list of totals that we have found for a particular header - file. */ + file. A total is a unique identifier for a particular BINCL...EINCL + sequence of STABs that can be used to identify duplicate sequences. + It consists of three fields, 'sum_chars' which is the sum of all the + STABS characters; 'num_chars' which is the number of these charactes + and 'symb' which is a buffer of all the symbols in the sequence. This + buffer is only checked as a last resort. */ struct stab_link_includes_totals { struct stab_link_includes_totals *next; - bfd_vma total; + bfd_vma sum_chars; /* Accumulated sum of STABS characters. */ + bfd_vma num_chars; /* Number of STABS characters. */ + const char* symb; /* The STABS characters themselves. */ }; /* An entry in the header file hash table. */ @@ -340,15 +347,21 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of first number after an open parenthesis). */ if (type == (int) N_BINCL) { - bfd_vma val; + bfd_vma sum_chars; + bfd_vma num_chars; + bfd_vma buf_len = 0; + char * symb; + char * symb_rover; int nest; - bfd_byte *incl_sym; - struct stab_link_includes_entry *incl_entry; - struct stab_link_includes_totals *t; - struct stab_excl_list *ne; + bfd_byte * incl_sym; + struct stab_link_includes_entry * incl_entry; + struct stab_link_includes_totals * t; + struct stab_excl_list * ne; - val = 0; + symb = symb_rover = NULL; + sum_chars = num_chars = 0; nest = 0; + for (incl_sym = sym + STABSIZE; incl_sym < symend; incl_sym += STABSIZE) @@ -377,7 +390,17 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of + bfd_get_32 (abfd, incl_sym + STRDXOFF)); for (; *str != '\0'; str++) { - val += *str; + if (num_chars >= buf_len) + { + buf_len += 32 * 1024; + symb = bfd_realloc (symb, buf_len); + if (symb == NULL) + goto error_return; + symb_rover = symb + num_chars; + } + * symb_rover ++ = * str; + sum_chars += *str; + num_chars ++; if (*str == '(') { /* Skip the file number. */ @@ -390,6 +413,8 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of } } + BFD_ASSERT (num_chars == (bfd_vma) (symb_rover - symb)); + /* If we have already included a header file with the same value, then replaced this one with an N_EXCL symbol. */ incl_entry = stab_link_includes_lookup (&sinfo->includes, string, @@ -398,7 +423,9 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of goto error_return; for (t = incl_entry->totals; t != NULL; t = t->next) - if (t->total == val) + if (t->sum_chars == sum_chars + && t->num_chars == num_chars + && memcmp (t->symb, symb, num_chars) == 0) break; /* Record this symbol, so that we can set the value @@ -408,7 +435,7 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of if (ne == NULL) goto error_return; ne->offset = sym - stabbuf; - ne->val = val; + ne->val = sum_chars; ne->type = (int) N_BINCL; ne->next = secinfo->excls; secinfo->excls = ne; @@ -421,7 +448,9 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of bfd_hash_allocate (&sinfo->includes.root, sizeof *t)); if (t == NULL) goto error_return; - t->total = val; + t->sum_chars = sum_chars; + t->num_chars = num_chars; + t->symb = bfd_realloc (symb, num_chars); /* Trim data down. */ t->next = incl_entry->totals; incl_entry->totals = t; } @@ -433,6 +462,9 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of pass to change the type to N_EXCL. */ ne->type = (int) N_EXCL; + /* Free off superfluous symbols. */ + free (symb); + /* Mark the skipped symbols. */ nest = 0; @@ -456,6 +488,9 @@ _bfd_link_section_stabs (abfd, psinfo, stabsec, stabstrsec, psecinfo, pstring_of } else if (incl_type == (int) N_BINCL) ++nest; + else if (incl_type == (int) N_EXCL) + /* Keep existing exclusion marks. */ + continue; else if (nest == 0) { *incl_pstridx = (bfd_size_type) -1; |