* opncls.c (bfd_zalloc): Document this function.
[deliverable/binutils-gdb.git] / ld / ldlang.c
index 4cc5927609f2adc3785a49a10af05c77ca44d96b..636dc7f5c475a92e1bac8b7b1a3dbdb066cb606e 100644 (file)
@@ -1,6 +1,6 @@
 /* Linker command language support.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004
+   2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GLD, the Gnu Linker.
@@ -553,20 +553,6 @@ lang_memory_region_lookup (const char *const name, bfd_boolean create)
        return p;
       }
 
-#if 0
-  /* This code used to always use the first region in the list as the
-     default region.  I changed it to instead use a region
-     encompassing all of memory as the default region.  This permits
-     NOLOAD sections to work reasonably without requiring a region.
-     People should specify what region they mean, if they really want
-     a region.  */
-  if (strcmp (name, DEFAULT_MEMORY_REGION) == 0)
-    {
-      if (lang_memory_region_list != NULL)
-       return lang_memory_region_list;
-    }
-#endif
-
   if (!create && strcmp (name, DEFAULT_MEMORY_REGION))
     einfo (_("%P:%S: warning: memory region %s not declared\n"), name);
 
@@ -1284,11 +1270,12 @@ section_already_linked (bfd *abfd, asection *sec, void *data)
      discard all sections.  */
   if (entry->just_syms_flag)
     {
-      bfd_link_just_syms (sec, &link_info);
+      bfd_link_just_syms (abfd, sec, &link_info);
       return;
     }
 
-  bfd_section_already_linked (abfd, sec);
+  if (!(abfd->flags & DYNAMIC))
+    bfd_section_already_linked (abfd, sec);
 }
 \f
 /* The wild routines.
@@ -1427,9 +1414,10 @@ lang_add_section (lang_statement_list_type *ptr,
       if (output->section_alignment != -1)
        output->bfd_section->alignment_power = output->section_alignment;
 
-      if (section->flags & SEC_BLOCK)
+      if (bfd_get_arch (section->owner) == bfd_arch_tic54x
+         && (section->flags & SEC_TIC54X_BLOCK) != 0)
        {
-         output->bfd_section->flags |= SEC_BLOCK;
+         output->bfd_section->flags |= SEC_TIC54X_BLOCK;
          /* FIXME: This value should really be obtained from the bfd...  */
          output->block_value = 128;
        }
@@ -1809,6 +1797,9 @@ load_symbols (lang_input_statement_type *entry,
 
       ldfile_assumed_script = TRUE;
       parser_input = input_script;
+      /* We want to use the same -Bdynamic/-Bstatic as the one for
+        ENTRY.  */
+      config.dynamic_link = entry->dynamic;
       yyparse ();
       ldfile_assumed_script = FALSE;
 
@@ -2154,10 +2145,6 @@ open_output (const char *name)
 
   delete_output_file_on_failure = TRUE;
 
-#if 0
-  output->flags |= D_PAGED;
-#endif
-
   if (! bfd_set_format (output, bfd_object))
     einfo (_("%P%F:%s: can not make object file: %E\n"), name);
   if (! bfd_set_arch_mach (output,
@@ -2305,31 +2292,6 @@ open_input_bfds (lang_statement_union_type *s, bfd_boolean force)
     }
 }
 
-/* If there are [COMMONS] statements, put a wild one into the bss
-   section.  */
-
-static void
-lang_reasonable_defaults (void)
-{
-#if 0
-  lang_output_section_statement_lookup (".text");
-  lang_output_section_statement_lookup (".data");
-
-  default_common_section = lang_output_section_statement_lookup (".bss");
-
-  if (!placed_commons)
-    {
-      lang_wild_statement_type *new =
-      new_stat (lang_wild_statement,
-               &default_common_section->children);
-
-      new->section_name = "COMMON";
-      new->filename = NULL;
-      lang_list_init (&new->children);
-    }
-#endif
-}
-
 /* Add a symbol to a hash of symbols used in DEFINED (NAME) expressions.  */
 
 void
@@ -2649,16 +2611,27 @@ map_input_to_output_sections
          FAIL ();
          break;
        case lang_address_statement_enum:
-         /* Mark the specified section with the supplied address.  */
-         {
-           lang_output_section_statement_type *aos
-             = (lang_output_section_statement_lookup
-                (s->address_statement.section_name));
-
-           if (aos->bfd_section == NULL)
-             init_os (aos);
-           aos->addr_tree = s->address_statement.address;
-         }
+         /* Mark the specified section with the supplied address.  
+
+            If this section was actually a segment marker, then the
+            directive is ignored if the linker script explicitly
+            processed the segment marker.  Originally, the linker
+            treated segment directives (like -Ttext on the
+            command-line) as section directives.  We honor the
+            section directive semantics for backwards compatibilty;
+            linker scripts that do not specifically check for
+            SEGMENT_START automatically get the old semantics.  */
+         if (!s->address_statement.segment 
+             || !s->address_statement.segment->used)
+           {
+             lang_output_section_statement_type *aos
+               = (lang_output_section_statement_lookup
+                  (s->address_statement.section_name));
+             
+             if (aos->bfd_section == NULL)
+               init_os (aos);
+             aos->addr_tree = s->address_statement.address;
+           }
          break;
        }
     }
@@ -3453,7 +3426,9 @@ lang_size_sections_1
               address from the input section.  FIXME: This is COFF
               specific; it would be cleaner if there were some other way
               to do this, but nothing simple comes to mind.  */
-           if ((os->bfd_section->flags & SEC_COFF_SHARED_LIBRARY) != 0)
+           if ((bfd_get_flavour (output_bfd) == bfd_target_ecoff_flavour
+                || bfd_get_flavour (output_bfd) == bfd_target_coff_flavour)
+               && (os->bfd_section->flags & SEC_COFF_SHARED_LIBRARY) != 0)
              {
                asection *input;
 
@@ -3844,15 +3819,21 @@ lang_size_sections
     {
       /* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try
         to put exp_data_seg.relro on a (common) page boundary.  */
-      bfd_vma old_base, relro_end;
+      bfd_vma old_min_base, relro_end, maxpage;
 
       exp_data_seg.phase = exp_dataseg_relro_adjust;
-      old_base = exp_data_seg.base;
+      old_min_base = exp_data_seg.min_base;
+      maxpage = exp_data_seg.maxpagesize;
       exp_data_seg.base += (-exp_data_seg.relro_end
                            & (exp_data_seg.pagesize - 1));
       /* Compute the expected PT_GNU_RELRO segment end.  */
       relro_end = (exp_data_seg.relro_end + exp_data_seg.pagesize - 1)
-                 & (exp_data_seg.pagesize - 1);
+                 & ~(exp_data_seg.pagesize - 1);
+      if (old_min_base + maxpage < exp_data_seg.base)
+       {
+         exp_data_seg.base -= maxpage;
+         relro_end -= maxpage;
+       }
       result = lang_size_sections_1 (s, output_section_statement, prev, fill,
                                     dot, relax, check_regions);
       if (exp_data_seg.relro_end > relro_end)
@@ -3874,7 +3855,7 @@ lang_size_sections
          if (((bfd_vma) 1 << max_alignment_power) < exp_data_seg.pagesize)
            {
              if (exp_data_seg.base - (1 << max_alignment_power)
-                 < old_base)
+                 < old_min_base)
                exp_data_seg.base += exp_data_seg.pagesize;
              exp_data_seg.base -= (1 << max_alignment_power);
              result = lang_size_sections_1 (s, output_section_statement,
@@ -3967,9 +3948,6 @@ lang_do_assignments_1
        case lang_object_symbols_statement_enum:
        case lang_output_statement_enum:
        case lang_target_statement_enum:
-#if 0
-       case lang_common_statement_enum:
-#endif
          break;
        case lang_data_statement_enum:
          {
@@ -4422,9 +4400,8 @@ lang_place_orphans (void)
                 around for a sensible place for it to go.  */
 
              if (file->just_syms_flag)
-               abort ();
-
-             if ((s->flags & SEC_EXCLUDE) != 0)
+               bfd_link_just_syms (file->the_bfd, s, &link_info);
+             else if ((s->flags & SEC_EXCLUDE) != 0)
                s->output_section = bfd_abs_section_ptr;
              else if (strcmp (s->name, "COMMON") == 0)
                {
@@ -4436,13 +4413,6 @@ lang_place_orphans (void)
                    {
                      if (default_common_section == NULL)
                        {
-#if 0
-                         /* This message happens when using the
-                            svr3.ifile linker script, so I have
-                            disabled it.  */
-                         info_msg (_("%P: no [COMMON] command,"
-                                     " defaulting to .bss\n"));
-#endif
                          default_common_section =
                            lang_output_section_statement_lookup (".bss");
 
@@ -4611,11 +4581,6 @@ lang_enter_output_section_statement (const char *output_section_statement_name,
     lang_output_section_statement_lookup_1 (output_section_statement_name,
                                            constraint);
 
-  /* Add this statement to tree.  */
-#if 0
-  add_statement (lang_output_section_statement_enum,
-                output_section_statement);
-#endif
   /* Make next things chain into subchain of this.  */
 
   if (os->addr_tree == NULL)
@@ -4760,7 +4725,6 @@ lang_gc_sections (void)
 void
 lang_process (void)
 {
-  lang_reasonable_defaults ();
   current_target = default_target;
 
   /* Open the output file.  */
@@ -4968,13 +4932,15 @@ lang_add_wild (struct wildcard_spec *filespec,
 }
 
 void
-lang_section_start (const char *name, etree_type *address)
+lang_section_start (const char *name, etree_type *address,
+                   const segment_type *segment)
 {
   lang_address_statement_type *ad;
 
   ad = new_stat (lang_address_statement, stat_ptr);
   ad->section_name = name;
   ad->address = address;
+  ad->segment = segment;
 }
 
 /* Set the start symbol to NAME.  CMDLINE is nonzero if this is called
This page took 0.026103 seconds and 4 git commands to generate.