*** empty log message ***
[deliverable/binutils-gdb.git] / ld / ldcref.c
index 3094735fa19f87adea338966261c876790fbb733..bcb787bec5658ec2926ff2c44a5d3876fa52f8fa 100644 (file)
@@ -1,5 +1,5 @@
 /* ldcref.c -- output a cross reference table
-   Copyright 1996, 1997, 1998, 2000, 2002, 2003
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>
 
@@ -17,7 +17,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 /* This file holds routines that manage the cross reference table.
    The table is used to generate cross reference reports.  It is also
@@ -69,9 +69,9 @@ struct cref_hash_table {
 /* Forward declarations.  */
 
 static void output_one_cref (FILE *, struct cref_hash_entry *);
-static void check_section_sym_xref (lang_input_statement_type *);
+static void check_local_sym_xref (lang_input_statement_type *);
 static bfd_boolean check_nocrossref (struct cref_hash_entry *, void *);
-static void check_refs (const char *, asection *, bfd *,
+static void check_refs (const char *, bfd_boolean, asection *, bfd *,
                        struct lang_nocrossrefs *);
 static void check_reloc_refs (bfd *, asection *, void *);
 
@@ -136,7 +136,7 @@ cref_hash_newfunc (struct bfd_hash_entry *entry,
 }
 
 /* Add a symbol to the cref hash table.  This is called for every
-   symbol that is seen during the link.  */
+   global symbol that is seen during the link.  */
 
 void
 add_cref (const char *name,
@@ -330,39 +330,69 @@ check_nocrossrefs (void)
 
   cref_hash_traverse (&cref_table, check_nocrossref, NULL);
 
-  lang_for_each_file (check_section_sym_xref);
+  lang_for_each_file (check_local_sym_xref);
 }
 
-/* Checks for prohibited cross references to section symbols.  */
+/* Check for prohibited cross references to local and section symbols.  */
 
 static void
-check_section_sym_xref (lang_input_statement_type *statement)
+check_local_sym_xref (lang_input_statement_type *statement)
 {
   bfd *abfd;
-  asection *sec;
+  lang_input_statement_type *li;
+  asymbol **asymbols, **syms;
 
   abfd = statement->the_bfd;
   if (abfd == NULL)
     return;
 
-  for (sec = abfd->sections; sec != NULL; sec = sec->next)
+  li = abfd->usrdata;
+  if (li != NULL && li->asymbols != NULL)
+    asymbols = li->asymbols;
+  else
     {
-      asection *outsec;
+      long symsize;
+      long symbol_count;
 
-      outsec = sec->output_section;
-      if (outsec != NULL)
+      symsize = bfd_get_symtab_upper_bound (abfd);
+      if (symsize < 0)
+       einfo (_("%B%F: could not read symbols; %E\n"), abfd);
+      asymbols = xmalloc (symsize);
+      symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
+      if (symbol_count < 0)
+       einfo (_("%B%F: could not read symbols: %E\n"), abfd);
+      if (li != NULL)
+       {
+         li->asymbols = asymbols;
+         li->symbol_count = symbol_count;
+       }
+    }
+
+  for (syms = asymbols; *syms; ++syms)
+    {
+      asymbol *sym = *syms;
+      if (sym->flags & (BSF_GLOBAL | BSF_WARNING | BSF_INDIRECT | BSF_FILE))
+       continue;
+      if ((sym->flags & (BSF_LOCAL | BSF_SECTION_SYM)) != 0
+         && sym->section->output_section != NULL)
        {
-         const char *outsecname;
+         const char *outsecname, *symname;
          struct lang_nocrossrefs *ncrs;
          struct lang_nocrossref *ncr;
 
-         outsecname = outsec->name;
+         outsecname = sym->section->output_section->name;
+         symname = NULL;
+         if ((sym->flags & BSF_SECTION_SYM) == 0)
+           symname = sym->name;
          for (ncrs = nocrossref_list; ncrs != NULL; ncrs = ncrs->next)
            for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
              if (strcmp (ncr->name, outsecname) == 0)
-               check_refs (NULL, sec, abfd, ncrs);
+               check_refs (symname, FALSE, sym->section, abfd, ncrs);
        }
     }
+
+  if (li == NULL)
+    free (asymbols);
 }
 
 /* Check one symbol to see if it is a prohibited cross reference.  */
@@ -399,7 +429,8 @@ check_nocrossref (struct cref_hash_entry *h, void *ignore ATTRIBUTE_UNUSED)
     for (ncr = ncrs->list; ncr != NULL; ncr = ncr->next)
       if (strcmp (ncr->name, defsecname) == 0)
        for (ref = h->refs; ref != NULL; ref = ref->next)
-         check_refs (hl->root.string, hl->u.def.section, ref->abfd, ncrs);
+         check_refs (hl->root.string, TRUE, hl->u.def.section,
+                     ref->abfd, ncrs);
 
   return TRUE;
 }
@@ -412,6 +443,7 @@ struct check_refs_info {
   asection *defsec;
   struct lang_nocrossrefs *ncrs;
   asymbol **asymbols;
+  bfd_boolean global;
 };
 
 /* This function is called for each symbol defined in a section which
@@ -421,6 +453,7 @@ struct check_refs_info {
 
 static void
 check_refs (const char *name,
+           bfd_boolean global,
            asection *sec,
            bfd *abfd,
            struct lang_nocrossrefs *ncrs)
@@ -458,6 +491,7 @@ check_refs (const char *name,
     }
 
   info.sym_name = name;
+  info.global = global;
   info.defsec = sec;
   info.ncrs = ncrs;
   info.asymbols = asymbols;
@@ -483,6 +517,7 @@ check_reloc_refs (bfd *abfd, asection *sec, void *iarg)
   const char *outdefsecname;
   struct lang_nocrossref *ncr;
   const char *symname;
+  bfd_boolean global;
   long relsize;
   arelent **relpp;
   long relcount;
@@ -508,9 +543,13 @@ check_reloc_refs (bfd *abfd, asection *sec, void *iarg)
   /* This section is one for which cross references are prohibited.
      Look through the relocations, and see if any of them are to
      INFO->SYM_NAME.  If INFO->SYMNAME is NULL, check for relocations
-     against the section symbol.  */
+     against the section symbol.  If INFO->GLOBAL is TRUE, the
+     definition is global, check for relocations against the global
+     symbols.  Otherwise check for relocations against the local and
+     section symbols.  */
 
   symname = info->sym_name;
+  global = info->global;
 
   relsize = bfd_get_reloc_upper_bound (abfd, sec);
   if (relsize < 0)
@@ -531,6 +570,14 @@ check_reloc_refs (bfd *abfd, asection *sec, void *iarg)
 
       if (q->sym_ptr_ptr != NULL
          && *q->sym_ptr_ptr != NULL
+         && ((global
+              && (bfd_is_und_section (bfd_get_section (*q->sym_ptr_ptr))
+                  || bfd_is_com_section (bfd_get_section (*q->sym_ptr_ptr))
+                  || ((*q->sym_ptr_ptr)->flags & (BSF_GLOBAL
+                                                  | BSF_WEAK)) != 0))
+             || (!global
+                 && ((*q->sym_ptr_ptr)->flags & (BSF_LOCAL
+                                                 | BSF_SECTION_SYM)) != 0))
          && (symname != NULL
              ? strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), symname) == 0
              : (((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
This page took 0.025982 seconds and 4 git commands to generate.