2002-01-29 Chris Demetriou <cgd@broadcom.com>
[deliverable/binutils-gdb.git] / ld / ldlang.c
index 30de02bb2179714a91f67e2f5671d8636e964dd1..a7b53dd1b0f6a0c57eaa2f216ab08e48d59f558c 100644 (file)
@@ -1,6 +1,6 @@
 /* Linker command language support.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001
+   2001, 2002
    Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
@@ -23,6 +23,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "bfd.h"
 #include "sysdep.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 #include "obstack.h"
 #include "bfdlink.h"
 
@@ -39,8 +40,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "fnmatch.h"
 #include "demangle.h"
 
-#include <ctype.h>
-
 /* FORWARDS */
 static lang_statement_union_type *new_statement
   PARAMS ((enum statement_enum, size_t, lang_statement_list_type *));
@@ -252,47 +251,59 @@ walk_wild_section (ptr, file, callback, data)
       struct wildcard_list *sec;
 
       sec = ptr->section_list;
-      do
+      if (sec == NULL)
+       (*callback) (ptr, sec, s, file, data);
+
+      while (sec != NULL)
        {
          boolean skip = false;
+         struct name_list *list_tmp;
 
-         if (sec != NULL)
+         /* Don't process sections from files which were
+            excluded.  */
+         for (list_tmp = sec->spec.exclude_name_list;
+              list_tmp;
+              list_tmp = list_tmp->next)
            {
-             struct name_list *list_tmp;
+             if (wildcardp (list_tmp->name))
+               skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
+             else
+               skip = strcmp (list_tmp->name, file->filename) == 0;
 
-             /* Don't process sections from files which were
-                excluded.  */
-             for (list_tmp = sec->spec.exclude_name_list;
-                  list_tmp;
-                  list_tmp = list_tmp->next)
+             /* If this file is part of an archive, and the archive is
+                excluded, exclude this file.  */
+             if (! skip && file->the_bfd != NULL
+                 && file->the_bfd->my_archive != NULL
+                 && file->the_bfd->my_archive->filename != NULL)
                {
                  if (wildcardp (list_tmp->name))
-                   skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
+                   skip = fnmatch (list_tmp->name,
+                                   file->the_bfd->my_archive->filename,
+                                   0) == 0;
                  else
-                   skip = strcmp (list_tmp->name, file->filename) == 0;
-
-                 if (skip)
-                   break;
+                   skip = strcmp (list_tmp->name,
+                                  file->the_bfd->my_archive->filename) == 0;
                }
 
-             if (!skip && sec->spec.name != NULL)
-               {
-                 const char *sname = bfd_get_section_name (file->the_bfd, s);
+             if (skip)
+               break;
+           }
 
-                 if (wildcardp (sec->spec.name))
-                   skip = fnmatch (sec->spec.name, sname, 0) != 0;
-                 else
-                   skip = strcmp (sec->spec.name, sname) != 0;
-               }
+         if (!skip && sec->spec.name != NULL)
+           {
+             const char *sname = bfd_get_section_name (file->the_bfd, s);
+
+             if (wildcardp (sec->spec.name))
+               skip = fnmatch (sec->spec.name, sname, 0) != 0;
+             else
+               skip = strcmp (sec->spec.name, sname) != 0;
            }
 
          if (!skip)
            (*callback) (ptr, sec, s, file, data);
 
-         if (sec != NULL)
-           sec = sec->next;
+         sec = sec->next;
        }
-      while (sec != NULL);
     }
 }
 
@@ -1014,11 +1025,8 @@ section_already_linked (abfd, sec, data)
 
          /* Set the output_section field so that lang_add_section
             does not create a lang_input_section structure for this
-            section.  Since there might be a symbol in the section
-            being discarded, we must retain a pointer to the section
-            which we are really going to use.  */
+            section.  */
          sec->output_section = bfd_abs_section_ptr;
-         sec->kept_section = l->sec;
 
          return;
        }
@@ -1076,7 +1084,7 @@ already_linked_table_free ()
 /* Return true if the PATTERN argument is a wildcard pattern.
    Although backslashes are treated specially if a pattern contains
    wildcards, we do not consider the mere presence of a backslash to
-   be enough to cause the the pattern to be treated as a wildcard.
+   be enough to cause the pattern to be treated as a wildcard.
    That lets us handle DOS filenames more naturally.  */
 
 static boolean
@@ -1618,12 +1626,7 @@ stricpy (dest, src)
   char c;
 
   while ((c = *src++) != 0)
-    {
-      if (isupper ((unsigned char) c))
-       c = tolower (c);
-
-      *dest++ = c;
-    }
+    *dest++ = TOLOWER (c);
 
   *dest = 0;
 }
@@ -2068,6 +2071,7 @@ map_input_to_output_sections (s, target, output_section_statement)
        {
        case lang_wild_statement_enum:
          wild (&s->wild_statement, target, output_section_statement);
+         break;
        case lang_constructors_statement_enum:
          map_input_to_output_sections (constructor_list.head,
                                        target,
@@ -3165,6 +3169,14 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
             padding to shrink.  If padding is needed on this pass, it
             will be added back in.  */
          s->padding_statement.size = 0;
+
+         /* Make sure output_offset is valid.  If relaxation shrinks
+            the section and this pad isn't needed, it's possible to
+            have output_offset larger than the final size of the
+            section.  bfd_set_section_contents will complain even for
+            a pad size of zero.  */
+         s->padding_statement.output_offset
+           = dot - output_section_statement->bfd_section->vma;
          break;
 
        case lang_group_statement_enum:
@@ -3559,6 +3571,8 @@ lang_check ()
 static void
 lang_common ()
 {
+  if (command_line.inhibit_common_definition)
+    return;
   if (link_info.relocateable
       && ! command_line.force_common_definition)
     return;
@@ -4012,6 +4026,7 @@ lang_gc_sections_1 (s)
        {
        case lang_wild_statement_enum:
          lang_gc_wild (&s->wild_statement);
+         break;
        case lang_constructors_statement_enum:
          lang_gc_sections_1 (constructor_list.head);
          break;
@@ -4786,7 +4801,7 @@ lang_leave_overlay_section (fill, phdrs)
   clean = xmalloc (strlen (name) + 1);
   s2 = clean;
   for (s1 = name; *s1 != '\0'; s1++)
-    if (isalnum ((unsigned char) *s1) || *s1 == '_')
+    if (ISALNUM (*s1) || *s1 == '_')
       *s2++ = *s1;
   *s2 = '\0';
 
@@ -5031,6 +5046,16 @@ lang_register_vers_node (name, version, deps)
   struct bfd_elf_version_tree *t, **pp;
   struct bfd_elf_version_expr *e1;
 
+  if (name == NULL)
+    name = "";
+
+  if ((name[0] == '\0' && lang_elf_version_info != NULL)
+      || (lang_elf_version_info && lang_elf_version_info->name[0] == '\0'))
+    {
+      einfo (_("%X%P: anonymous version tag cannot be combined with other version tags\n"));
+      return;
+    }
+
   /* Make sure this node has a unique name.  */
   for (t = lang_elf_version_info; t != NULL; t = t->next)
     if (strcmp (t->name, name) == 0)
@@ -5067,8 +5092,13 @@ lang_register_vers_node (name, version, deps)
 
   version->deps = deps;
   version->name = name;
-  ++version_index;
-  version->vernum = version_index;
+  if (name[0] != '\0')
+    {
+      ++version_index;
+      version->vernum = version_index;
+    }
+  else
+    version->vernum = 0;
 
   for (pp = &lang_elf_version_info; *pp != NULL; pp = &(*pp)->next)
     ;
This page took 0.02541 seconds and 4 git commands to generate.