ld: better handling of lma region for orphan sections
[deliverable/binutils-gdb.git] / ld / ldlang.c
index 7d495c090086514b754f66e9dde11fe5612a11d7..89b896f51dfe81faa37bd9130a577a228bde0edf 100644 (file)
@@ -1,5 +1,5 @@
 /* Linker command language support.
-   Copyright (C) 1991-2016 Free Software Foundation, Inc.
+   Copyright (C) 1991-2017 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -2035,14 +2035,11 @@ static void
 lang_print_asneeded (void)
 {
   struct asneeded_minfo *m;
-  char buf[100];
 
   if (asneeded_list_head == NULL)
     return;
 
-  sprintf (buf, _("\nAs-needed library included "
-                 "to satisfy reference by file (symbol)\n\n"));
-  minfo ("%s", buf);
+  minfo (_("\nAs-needed library included to satisfy reference by file (symbol)\n\n"));
 
   for (m = asneeded_list_head; m != NULL; m = m->next)
     {
@@ -3377,7 +3374,8 @@ open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode)
 #endif
          break;
        case lang_assignment_statement_enum:
-         if (s->assignment_statement.exp->assign.defsym)
+         if (s->assignment_statement.exp->type.node_class != etree_assert
+             && s->assignment_statement.exp->assign.defsym)
            /* This is from a --defsym on the command line.  */
            exp_fold_tree_no_dot (s->assignment_statement.exp);
          break;
@@ -3704,7 +3702,7 @@ map_input_to_output_sections
             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;
+            section directive semantics for backwards compatibility;
             linker scripts that do not specifically check for
             SEGMENT_START automatically get the old semantics.  */
          if (!s->address_statement.segment
@@ -4674,7 +4672,8 @@ size_input_section
 
   if (i->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
     i->output_offset = i->vma - o->vma;
-  else if ((i->flags & SEC_EXCLUDE) != 0)
+  else if (((i->flags & SEC_EXCLUDE) != 0)
+          || output_section_statement->ignored)
     i->output_offset = dot - o->vma;
   else
     {
@@ -6845,6 +6844,27 @@ lang_check_relocs (void)
     }
 }
 
+/* Look through all output sections looking for places where we can
+   propagate forward the lma region.  */
+
+static void
+lang_propagate_lma_regions (void)
+{
+  lang_output_section_statement_type *os;
+
+  for (os = &lang_output_section_statement.head->output_section_statement;
+       os != NULL;
+       os = os->next)
+    {
+      if (os->prev != NULL
+         && os->lma_region == NULL
+         && os->load_base == NULL
+         && os->addr_tree == NULL
+         && os->region == os->prev->region)
+       os->lma_region = os->prev->lma_region;
+    }
+}
+
 void
 lang_process (void)
 {
@@ -6880,7 +6900,7 @@ lang_process (void)
         are any more to be added to the link before we call the
         emulation's after_open hook.  We create a private list of
         input statements for this purpose, which we will eventually
-        insert into the global statment list after the first claimed
+        insert into the global statement list after the first claimed
         file.  */
       added = *stat_ptr;
       /* We need to manipulate all three chains in synchrony.  */
@@ -7023,6 +7043,9 @@ lang_process (void)
        }
     }
 
+  /* Copy forward lma regions for output sections in same lma region.  */
+  lang_propagate_lma_regions ();
+
   /* Do anything special before sizing sections.  This is where ELF
      and other back-ends size dynamic sections.  */
   ldemul_before_allocation ();
@@ -7303,16 +7326,6 @@ lang_leave_output_section_statement (fill_type *fill, const char *memspec,
                    current_section->load_base != NULL,
                    current_section->addr_tree != NULL);
 
-  /* If this section has no load region or base, but uses the same
-     region as the previous section, then propagate the previous
-     section's load region.  */
-
-  if (current_section->lma_region == NULL
-      && current_section->load_base == NULL
-      && current_section->addr_tree == NULL
-      && current_section->region == current_section->prev->region)
-    current_section->lma_region = current_section->prev->lma_region;
-
   current_section->fill = fill;
   current_section->phdrs = phdrs;
   pop_stat_ptr ();
This page took 0.026266 seconds and 4 git commands to generate.