Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/ld/ldcref.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* ldcref.c -- output a cross reference table
    2    Copyright 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
     2   Copyright 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
    33   Written by Ian Lance Taylor <ian@cygnus.com>
    44
     
    7070static struct bfd_hash_entry *cref_hash_newfunc
    7171  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
    72 static boolean cref_fill_array PARAMS ((struct cref_hash_entry *, PTR));
     72static bfd_boolean cref_fill_array PARAMS ((struct cref_hash_entry *, PTR));
    7373static int cref_sort_array PARAMS ((const PTR, const PTR));
    7474static void output_one_cref PARAMS ((FILE *, struct cref_hash_entry *));
    75 static boolean check_nocrossref PARAMS ((struct cref_hash_entry *, PTR));
     75static bfd_boolean check_nocrossref PARAMS ((struct cref_hash_entry *, PTR));
     76static void check_section_sym_xref PARAMS ((lang_input_statement_type *));
    7677static void check_refs
    77   PARAMS ((struct cref_hash_entry *, struct bfd_link_hash_entry *,
    78            struct lang_nocrossrefs *));
     78  PARAMS ((const char *, asection *, bfd *, struct lang_nocrossrefs *));
    7979static void check_reloc_refs PARAMS ((bfd *, asection *, PTR));
    8080
     
    9090  (bfd_hash_traverse                                                    \
    9191   (&(table)->root,                                                     \
    92     (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func),       \
     92    (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func),   \
    9393    (info)))
    9494
     
    9999/* Whether the cref hash table has been initialized.  */
    100100
    101 static boolean cref_initialized;
     101static bfd_boolean cref_initialized;
    102102
    103103/* The number of symbols seen so far.  */
     
    157157      if (! bfd_hash_table_init (&cref_table.root, cref_hash_newfunc))
    158158        einfo (_("%X%P: bfd_hash_table_init of cref table failed: %E\n"));
    159       cref_initialized = true;
    160     }
    161 
    162   h = cref_hash_lookup (&cref_table, name, true, false);
     159      cref_initialized = TRUE;
     160    }
     161
     162  h = cref_hash_lookup (&cref_table, name, TRUE, FALSE);
    163163  if (h == NULL)
    164164    einfo (_("%X%P: cref_hash_lookup failed: %E\n"));
     
    174174      h->refs = r;
    175175      r->abfd = abfd;
    176       r->def = false;
    177       r->common = false;
    178       r->undef = false;
     176      r->def = FALSE;
     177      r->common = FALSE;
     178      r->undef = FALSE;
    179179    }
    180180
    181181  if (bfd_is_und_section (section))
    182     r->undef = true;
     182    r->undef = TRUE;
    183183  else if (bfd_is_com_section (section))
    184     r->common = true;
     184    r->common = TRUE;
    185185  else
    186     r->def = true;
     186    r->def = TRUE;
    187187}
    188188
     
    191191   name.  */
    192192
    193 static boolean
     193static bfd_boolean
    194194cref_fill_array (h, data)
    195195     struct cref_hash_entry *h;
     
    205205  ++*pph;
    206206
    207   return true;
     207  return TRUE;
    208208}
    209209
     
    275275  struct cref_ref *r;
    276276
    277   hl = bfd_link_hash_lookup (link_info.hash, h->root.string, false,
    278                              false, true);
     277  hl = bfd_link_hash_lookup (link_info.hash, h->root.string, FALSE,
     278                             FALSE, TRUE);
    279279  if (hl == NULL)
    280280    einfo ("%P: symbol `%T' missing from main hash table\n",
     
    343343
    344344  cref_hash_traverse (&cref_table, check_nocrossref, (PTR) NULL);
     345
     346  lang_for_each_file (check_section_sym_xref);
     347}
     348
     349/* Checks for prohibited cross references to section symbols.  */
     350
     351static void
     352check_section_sym_xref (statement)
     353     lang_input_statement_type *statement;
     354{
     355  bfd *abfd;
     356  asection *sec;
     357
     358  abfd = statement->the_bfd;
     359  if (abfd == NULL)
     360    return;
     361
     362  for (sec = abfd->sections; sec != NULL; sec = sec->next)
     363    {
     364      asection *outsec;
     365
     366      outsec = sec->output_section;
     367      if (outsec != NULL)
     368        {
     369          const char *outsecname;
     370          struct lang_nocrossrefs *ncrs;
     371          struct lang_nocrossref *ncr;
     372
     373          outsecname = outsec->name;
     374          for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
     375            for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
     376              if (strcmp (ncr->name, outsecname) == 0)
     377                check_refs (NULL, sec, abfd, ncrs);
     378        }
     379    }
    345380}
    346381
    347382/* Check one symbol to see if it is a prohibited cross reference.  */
    348383
    349 static boolean
     384static bfd_boolean
    350385check_nocrossref (h, ignore)
    351386     struct cref_hash_entry *h;
     
    357392  struct lang_nocrossrefs *ncrs;
    358393  struct lang_nocrossref *ncr;
    359 
    360   hl = bfd_link_hash_lookup (link_info.hash, h->root.string, false,
    361                              false, true);
     394  struct cref_ref *ref;
     395
     396  hl = bfd_link_hash_lookup (link_info.hash, h->root.string, FALSE,
     397                             FALSE, TRUE);
    362398  if (hl == NULL)
    363399    {
    364400      einfo (_("%P: symbol `%T' missing from main hash table\n"),
    365401             h->root.string);
    366       return true;
     402      return TRUE;
    367403    }
    368404
    369405  if (hl->type != bfd_link_hash_defined
    370406      && hl->type != bfd_link_hash_defweak)
    371     return true;
     407    return TRUE;
    372408
    373409  defsec = hl->u.def.section->output_section;
    374410  if (defsec == NULL)
    375     return true;
     411    return TRUE;
    376412  defsecname = bfd_get_section_name (defsec->owner, defsec);
    377413
     
    379415    for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
    380416      if (strcmp (ncr->name, defsecname) == 0)
    381         check_refs (h, hl, ncrs);
    382 
    383   return true;
     417        for (ref = h->refs; ref != NULL; ref = ref->next)
     418          check_refs (hl->root.string, hl->u.def.section, ref->abfd, ncrs);
     419
     420  return TRUE;
    384421}
    385422
     
    388425
    389426struct check_refs_info {
    390   struct cref_hash_entry *h;
     427  const char *sym_name;
    391428  asection *defsec;
    392429  struct lang_nocrossrefs *ncrs;
    393430  asymbol **asymbols;
    394   boolean same;
    395431};
    396432
     
    401437
    402438static void
    403 check_refs (h, hl, ncrs)
    404      struct cref_hash_entry *h;
    405      struct bfd_link_hash_entry *hl;
     439check_refs (name, sec, abfd, ncrs)
     440     const char *name;
     441     asection *sec;
     442     bfd *abfd;
    406443     struct lang_nocrossrefs *ncrs;
    407444{
    408   struct cref_ref *ref;
    409 
    410   for (ref = h->refs; ref != NULL; ref = ref->next)
    411     {
    412       lang_input_statement_type *li;
    413       asymbol **asymbols;
    414       struct check_refs_info info;
    415 
    416       /* We need to look through the relocations for this BFD, to see
    417          if any of the relocations which refer to this symbol are from
    418          a prohibited section.  Note that we need to do this even for
    419          the BFD in which the symbol is defined, since even a single
    420          BFD might contain a prohibited cross reference; for this
    421          case, we set the SAME field in INFO, which will cause
    422          CHECK_RELOCS_REFS to check for relocations against the
    423          section as well as against the symbol.  */
    424 
    425       li = (lang_input_statement_type *) ref->abfd->usrdata;
    426       if (li != NULL && li->asymbols != NULL)
    427         asymbols = li->asymbols;
    428       else
     445  lang_input_statement_type *li;
     446  asymbol **asymbols;
     447  struct check_refs_info info;
     448
     449  /* We need to look through the relocations for this BFD, to see
     450     if any of the relocations which refer to this symbol are from
     451     a prohibited section.  Note that we need to do this even for
     452     the BFD in which the symbol is defined, since even a single
     453     BFD might contain a prohibited cross reference.  */
     454
     455  li = (lang_input_statement_type *) abfd->usrdata;
     456  if (li != NULL && li->asymbols != NULL)
     457    asymbols = li->asymbols;
     458  else
     459    {
     460      long symsize;
     461      long symbol_count;
     462
     463      symsize = bfd_get_symtab_upper_bound (abfd);
     464      if (symsize < 0)
     465        einfo (_("%B%F: could not read symbols; %E\n"), abfd);
     466      asymbols = (asymbol **) xmalloc (symsize);
     467      symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
     468      if (symbol_count < 0)
     469        einfo (_("%B%F: could not read symbols: %E\n"), abfd);
     470      if (li != NULL)
    429471        {
    430           long symsize;
    431           long symbol_count;
    432 
    433           symsize = bfd_get_symtab_upper_bound (ref->abfd);
    434           if (symsize < 0)
    435             einfo (_("%B%F: could not read symbols; %E\n"), ref->abfd);
    436           asymbols = (asymbol **) xmalloc (symsize);
    437           symbol_count = bfd_canonicalize_symtab (ref->abfd, asymbols);
    438           if (symbol_count < 0)
    439             einfo (_("%B%F: could not read symbols: %E\n"), ref->abfd);
    440           if (li != NULL)
    441             {
    442               li->asymbols = asymbols;
    443               li->symbol_count = symbol_count;
    444             }
     472          li->asymbols = asymbols;
     473          li->symbol_count = symbol_count;
    445474        }
    446 
    447       info.h = h;
    448       info.defsec = hl->u.def.section;
    449       info.ncrs = ncrs;
    450       info.asymbols = asymbols;
    451       if (ref->abfd == hl->u.def.section->owner)
    452         info.same = true;
    453       else
    454         info.same = false;
    455       bfd_map_over_sections (ref->abfd, check_reloc_refs, (PTR) &info);
    456 
    457       if (li == NULL)
    458         free (asymbols);
    459     }
    460 }
    461 
    462 /* This is called via bfd_map_over_sections.  INFO->H is a symbol
     475    }
     476
     477  info.sym_name = name;
     478  info.defsec = sec;
     479  info.ncrs = ncrs;
     480  info.asymbols = asymbols;
     481  bfd_map_over_sections (abfd, check_reloc_refs, (PTR) &info);
     482
     483  if (li == NULL)
     484    free (asymbols);
     485}
     486
     487/* This is called via bfd_map_over_sections.  INFO->SYM_NAME is a symbol
    463488   defined in INFO->DEFSECNAME.  If this section maps into any of the
    464489   sections listed in INFO->NCRS, other than INFO->DEFSECNAME, then we
    465490   look through the relocations.  If any of the relocations are to
    466    INFO->H, then we report a prohibited cross reference error.  */
     491   INFO->SYM_NAME, then we report a prohibited cross reference error.  */
    467492
    468493static void
     
    503528  /* This section is one for which cross references are prohibited.
    504529     Look through the relocations, and see if any of them are to
    505      INFO->H.  */
    506 
    507   symname = info->h->root.string;
     530     INFO->SYM_NAME.  If INFO->SYMNAME is NULL, check for relocations
     531     against the section symbol.  */
     532
     533  symname = info->sym_name;
    508534
    509535  relsize = bfd_get_reloc_upper_bound (abfd, sec);
     
    526552      if (q->sym_ptr_ptr != NULL
    527553          && *q->sym_ptr_ptr != NULL
    528           && (strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
    529               || (info->same
    530                   && bfd_get_section (*q->sym_ptr_ptr) == info->defsec)))
     554          && (symname != NULL
     555              ? strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
     556              : (((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
     557                 && bfd_get_section (*q->sym_ptr_ptr) == info->defsec)))
    531558        {
    532559          /* We found a reloc for the symbol.  The symbol is defined
Note: See TracChangeset for help on using the changeset viewer.