* ld-elfweak/size2a.s: Extend test to check size for two weaks.
[deliverable/binutils-gdb.git] / ld / ldlang.c
index 4f9569f42ac5cb06abbed656881a74368514320a..dc8aa1497e3f2cb3aed8c6e07df3f61e9b51e1c2 100644 (file)
@@ -1960,11 +1960,8 @@ wild_sort (lang_wild_statement_type *wild,
         looking at the sections for this file.  */
 
       if (sec != NULL && sec->spec.sorted != none)
-       {
-         if (compare_section (sec->spec.sorted, section,
-                              ls->section) < 0)
-           break;
-       }
+       if (compare_section (sec->spec.sorted, section, ls->section) < 0)
+         break;
     }
 
   return l;
@@ -3052,7 +3049,6 @@ void
 strip_excluded_output_sections (void)
 {
   lang_output_section_statement_type *os;
-  unsigned int gc_sections;
 
   /* Run lang_size_sections (if not already done) to ensure that all
      symbols defined in the linker script are put in the bfd hash
@@ -3065,13 +3061,6 @@ strip_excluded_output_sections (void)
       lang_reset_memory_regions ();
     }
 
-  /* Now call into bfd_gc_sections to mark all sections defining global
-     symbols with SEC_KEEP.  */
-  gc_sections = link_info.gc_sections;
-  link_info.gc_sections = 0;
-  bfd_gc_sections (output_bfd, &link_info);
-  link_info.gc_sections = gc_sections;
-
   for (os = &lang_output_section_statement.head->output_section_statement;
        os != NULL;
        os = os->next)
@@ -3086,39 +3075,40 @@ strip_excluded_output_sections (void)
       if (output_section == NULL)
        continue;
 
-      exclude = TRUE;
-      if (output_section->map_head.s != NULL)
+      exclude = (output_section->rawsize == 0
+                && (output_section->flags & SEC_KEEP) == 0
+                && !bfd_section_removed_from_list (output_bfd,
+                                                   output_section));
+
+      /* Some sections have not yet been sized, notably .gnu.version,
+        .dynsym, .dynstr and .hash.  These all have SEC_LINKER_CREATED
+        input sections, so don't drop output sections that have such
+        input sections unless they are also marked SEC_EXCLUDE.  */
+      if (exclude && output_section->map_head.s != NULL)
        {
          asection *s;
 
-         for (s = output_section->map_head.s; s != NULL;
-              s = s->map_head.s)
-           if ((s->flags & SEC_EXCLUDE) == 0)
+         for (s = output_section->map_head.s; s != NULL; s = s->map_head.s)
+           if ((s->flags & SEC_LINKER_CREATED) != 0
+               && (s->flags & SEC_EXCLUDE) == 0)
              {
                exclude = FALSE;
                break;
              }
-
-         output_section->map_head.link_order = NULL;
-         output_section->map_tail.link_order = NULL;
        }
 
-      if (exclude
-         && (output_section->flags & SEC_KEEP) == 0
-         && output_section->rawsize == 0
-         && !bfd_is_abs_section (output_section))
+      /* TODO: Don't just junk map_head.s, turn them into link_orders.  */
+      output_section->map_head.link_order = NULL;
+      output_section->map_tail.link_order = NULL;
+
+      if (exclude)
        {
          /* We don't set bfd_section to NULL since bfd_section of the
             removed output section statement may still be used.  */
          os->ignored = TRUE;
          output_section->flags |= SEC_EXCLUDE;
-
-         if (!bfd_section_removed_from_list (output_bfd,
-                                             output_section))
-           {
-             bfd_section_list_remove (output_bfd, output_section);
-             output_bfd->section_count--;
-           }
+         bfd_section_list_remove (output_bfd, output_section);
+         output_bfd->section_count--;
        }
     }
 
@@ -4595,6 +4585,7 @@ lang_do_assignments (void)
 {
   lang_statement_iteration++;
   lang_do_assignments_1 (statement_list.head, abs_output_section, NULL, 0);
+  ldemul_do_assignments ();
 }
 
 /* Fix any .startof. or .sizeof. symbols.  When the assemblers see the
This page took 0.024338 seconds and 4 git commands to generate.