PR25570, ld duplicate "warning: changing start of section"
authorAlan Modra <amodra@gmail.com>
Wed, 4 Mar 2020 10:44:19 +0000 (21:14 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 4 Mar 2020 23:18:04 +0000 (09:48 +1030)
Note that because we should report a signed delta from the previous
VMA it isn't possible to use ngettext.  ngettext only supports
unsigned long values.  So byte/bytes goes from the message.

PR 25570
* ldlang.c (lang_sizing_iteration): New static var.
(lang_size_sections_1): Warn about no memory region only on first
iteration.  Warn about changing start address on first iteration
then any delta from that on subsequent iterations.  Report a signed
delta.
(one_lang_size_sections_pass): Increment lang_sizing_iteration.

ld/ChangeLog
ld/ldlang.c

index 94fe79f6c24cdca13b68bcfe252b4daf36b9dae3..b634dd8732efb1f325c70ad7f988aa6727eb3b30 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-05  Alan Modra  <amodra@gmail.com>
+
+       PR 25570
+       * ldlang.c (lang_sizing_iteration): New static var.
+       (lang_size_sections_1): Warn about no memory region only on first
+       iteration.  Warn about changing start address on first iteration
+       then any delta from that on subsequent iterations.  Report a signed
+       delta.
+       (one_lang_size_sections_pass): Increment lang_sizing_iteration.
+
 2020-03-03  Nick Clifton  <nickc@redhat.com>
 
        PR 25588
index be9ac36ede430456456d14e97afcb0356cfb515c..6ffa7af5754bb66fcb972147e64b87b1aa331fee 100644 (file)
@@ -131,10 +131,13 @@ struct lang_nocrossrefs *nocrossref_list;
 struct asneeded_minfo **asneeded_list_tail;
 static ctf_file_t *ctf_output;
 
- /* Functions that traverse the linker script and might evaluate
-    DEFINED() need to increment this at the start of the traversal.  */
+/* Functions that traverse the linker script and might evaluate
+   DEFINED() need to increment this at the start of the traversal.  */
 int lang_statement_iteration = 0;
 
+/* Count times through one_lang_size_sections_pass after mark phase.  */
+static int lang_sizing_iteration = 0;
+
 /* 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
@@ -5554,7 +5557,7 @@ lang_size_sections_1
                        && (strcmp (lang_memory_region_list->name_list.name,
                                    DEFAULT_MEMORY_REGION) != 0
                            || lang_memory_region_list->next != NULL)
-                       && expld.phase != lang_mark_phase_enum)
+                       && lang_sizing_iteration == 1)
                      {
                        /* By default this is an error rather than just a
                           warning because if we allocate the section to the
@@ -5586,19 +5589,21 @@ lang_size_sections_1
                if (section_alignment > 0)
                  {
                    bfd_vma savedot = newdot;
-                   newdot = align_power (newdot, section_alignment);
+                   bfd_vma diff = 0;
 
+                   newdot = align_power (newdot, section_alignment);
                    dotdelta = newdot - savedot;
-                   if (dotdelta != 0
+
+                   if (lang_sizing_iteration == 1)
+                     diff = dotdelta;
+                   else if (lang_sizing_iteration > 1)
+                     diff = newdot - os->bfd_section->vma;
+                   if (diff != 0
                        && (config.warn_section_align
-                           || os->addr_tree != NULL)
-                       && expld.phase != lang_mark_phase_enum)
-                     einfo (ngettext ("%P: warning: changing start of "
-                                      "section %s by %lu byte\n",
-                                      "%P: warning: changing start of "
-                                      "section %s by %lu bytes\n",
-                                      (unsigned long) dotdelta),
-                            os->name, (unsigned long) dotdelta);
+                           || os->addr_tree != NULL))
+                     einfo (_("%P: warning: "
+                              "start of section %s changed by %ld\n"),
+                            os->name, (long) diff);
                  }
 
                bfd_set_section_vma (os->bfd_section, newdot);
@@ -6036,6 +6041,8 @@ void
 one_lang_size_sections_pass (bfd_boolean *relax, bfd_boolean check_regions)
 {
   lang_statement_iteration++;
+  if (expld.phase != lang_mark_phase_enum)
+    lang_sizing_iteration++;
   lang_size_sections_1 (&statement_list.head, abs_output_section,
                        0, 0, relax, check_regions);
 }