* lexsup.c (parse_args): Add support for new options -( -) with
[binutils-gdb.git] / ld / ldlang.c
index b4a38500004f6133aeeb5fcdf3057f3c4cbcfe73..6a4ab5fffb976309b32a744013c4d8b9af1c769a 100644 (file)
@@ -49,11 +49,6 @@ static struct obstack stat_obstack;
 #define obstack_chunk_free free
 static CONST char *startup_file;
 static lang_statement_list_type input_file_chain;
-
-/* Points to the last statement in the .data section, so we can add
-   stuff to the data section without pain */
-static lang_statement_list_type end_of_data_section_statement_list;
-
 static boolean placed_commons = false;
 static lang_output_section_statement_type *default_common_section;
 static boolean map_option_f;
@@ -141,8 +136,7 @@ static void reset_memory_regions PARAMS ((void));
 /* EXPORTS */
 lang_output_section_statement_type *abs_output_section;
 lang_statement_list_type *stat_ptr = &statement_list;
-lang_statement_list_type file_chain =
-{0};
+lang_statement_list_type file_chain = { 0 };
 static const char *entry_symbol = 0;
 boolean lang_has_input_file = false;
 boolean had_output_filename = false;
@@ -372,7 +366,6 @@ new_afile (name, file_type, target, add_to_list)
     }
   p->the_bfd = (bfd *) NULL;
   p->asymbols = (asymbol **) NULL;
-  p->superfile = (lang_input_statement_type *) NULL;
   p->next_real_file = (lang_statement_union_type *) NULL;
   p->next = (lang_statement_union_type *) NULL;
   p->symbol_count = 0;
@@ -390,25 +383,7 @@ lang_add_input_file (name, file_type, target)
      lang_input_file_enum_type file_type;
      CONST char *target;
 {
-  /* Look it up or build a new one */
   lang_has_input_file = true;
-
-#if 0
-  lang_input_statement_type *p;
-
-  for (p = (lang_input_statement_type *) input_file_chain.head;
-       p != (lang_input_statement_type *) NULL;
-       p = (lang_input_statement_type *) (p->next_real_file))
-    {
-      /* Sometimes we have incomplete entries in here */
-      if (p->filename != (char *) NULL)
-       {
-         if (strcmp (name, p->filename) == 0)
-           return p;
-       }
-
-    }
-#endif
   return new_afile (name, file_type, target, true);
 }
 
@@ -430,7 +405,7 @@ lang_init ()
                                    (char *) NULL);
   abs_output_section = lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME);
 
-  abs_output_section->bfd_section = &bfd_abs_section;
+  abs_output_section->bfd_section = bfd_abs_section_ptr;
 
 }
 
@@ -909,6 +884,10 @@ ldlang_open_output (statement)
        output_bfd->flags |= WP_TEXT;
       else
        output_bfd->flags &= ~WP_TEXT;
+      if (config.traditional_format)
+       output_bfd->flags |= BFD_TRADITIONAL_FORMAT;
+      else
+       output_bfd->flags &= ~BFD_TRADITIONAL_FORMAT;
       break;
 
     case lang_target_statement_enum:
@@ -1080,15 +1059,12 @@ map_input_to_output_sections (s, target, output_section_statement)
          /* Mark the specified section with the supplied address */
          {
            lang_output_section_statement_type *os =
-           lang_output_section_statement_lookup
-           (s->address_statement.section_name);
+             lang_output_section_statement_lookup
+               (s->address_statement.section_name);
 
+           if (os->bfd_section == NULL)
+             init_os (os);
            os->addr_tree = s->address_statement.address;
-           if (os->bfd_section == (asection *) NULL)
-             {
-               einfo ("%P%F: cannot set the address of undefined section %s\n",
-                      s->address_statement.section_name);
-             }
          }
          break;
        }
@@ -1636,10 +1612,10 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
           break;
         }
 
-       if (os->bfd_section == &bfd_abs_section)
+       if (bfd_is_abs_section (os->bfd_section))
        {
         /* No matter what happens, an abs section starts at zero */
-        bfd_set_section_vma (0, os->bfd_section, 0);
+        ASSERT (os->bfd_section->vma == 0);
        }
        else
        {
@@ -1683,10 +1659,9 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
           os->bfd_section->lma 
             = exp_get_value_int(os->load_base, 0,"load base", lang_final_phase_enum);
         }
-       }
-
 
-       os->bfd_section->output_offset = 0;
+        os->bfd_section->output_offset = 0;
+       }
 
        (void) lang_size_sections (os->children.head, os, &os->children.head,
                                  os->fill, dot, relax);
@@ -1698,13 +1673,15 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax)
                        /* The coercion here is important, see ld.h.  */
                        (bfd_vma) os->block_value);
 
-       os->bfd_section->_raw_size = after - os->bfd_section->vma;
+       if (bfd_is_abs_section (os->bfd_section))
+        ASSERT (after == os->bfd_section->vma);
+       else
+        os->bfd_section->_raw_size = after - os->bfd_section->vma;
        dot = os->bfd_section->vma + os->bfd_section->_raw_size;
        os->processed = true;
 
        /* Replace into region ? */
-       if (os->addr_tree == (etree_type *) NULL
-          && os->region != (lang_memory_region_type *) NULL)
+       if (os->region != (lang_memory_region_type *) NULL)
        {
         os->region->current = dot;
         /* Make sure this isn't silly */
@@ -2321,7 +2298,24 @@ lang_set_flags (ptr, flags)
     }
 }
 
+/* Call a function on each input file.  This function will be called
+   on an archive, but not on the elements.  */
 
+void
+lang_for_each_input_file (func)
+     void (*func) PARAMS ((lang_input_statement_type *));
+{
+  lang_input_statement_type *f;
+
+  for (f = (lang_input_statement_type *) input_file_chain.head;
+       f != NULL;
+       f = (lang_input_statement_type *) f->next_real_file)
+    func (f);
+}
+
+/* Call a function on each file.  The function will be called on all
+   the elements of an archive which are included in the link, but will
+   not be called on the archive file itself.  */
 
 void
 lang_for_each_file (func)
@@ -2768,14 +2762,6 @@ lang_leave_output_section_statement (fill, memspec)
   current_section->fill = fill;
   current_section->region = lang_memory_region_lookup (memspec);
   stat_ptr = &statement_list;
-
-  /* We remember if we are closing a .data section, since we use it to
-     store constructors in */
-  if (strcmp (current_section->name, ".data") == 0)
-    {
-      end_of_data_section_statement_list = statement_list;
-
-    }
 }
 
 /*
@@ -2808,7 +2794,7 @@ lang_abs_symbol_at_beginning_of (secname, name)
       else
        h->u.def.value = bfd_get_section_vma (output_bfd, sec);
 
-      h->u.def.section = &bfd_abs_section;
+      h->u.def.section = bfd_abs_section_ptr;
     }
 }
 
@@ -2843,7 +2829,7 @@ lang_abs_symbol_at_end_of (secname, name)
        h->u.def.value = (bfd_get_section_vma (output_bfd, sec)
                          + bfd_section_size (output_bfd, sec));
 
-      h->u.def.section = &bfd_abs_section;
+      h->u.def.section = bfd_abs_section_ptr;
     }
 }