public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR25570, ld duplicate "warning: changing start of section"
@ 2020-03-04  5:57 Alan Modra
  2020-03-04  6:13 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2020-03-04  5:57 UTC (permalink / raw)
  To: binutils

	PR 25570
	* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
	errors/warnings until final pass.
	* ldexp.c (fold_name): Likewise.

diff --git a/ld/ldexp.c b/ld/ldexp.c
index 6d1457b929..d2b1b43a5a 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -742,7 +742,7 @@ fold_name (etree_type *tree)
 	      output_section = h->u.def.section->output_section;
 	      if (output_section == NULL)
 		{
-		  if (expld.phase <= lang_mark_phase_enum)
+		  if (expld.phase != lang_final_phase_enum)
 		    new_rel (h->u.def.value, h->u.def.section);
 		  else
 		    einfo (_("%X%P:%pS: unresolvable symbol `%s'"
diff --git a/ld/ldlang.c b/ld/ldlang.c
index be9ac36ede..b089ac304b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5554,7 +5554,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)
+			&& expld.phase == lang_final_phase_enum)
 		      {
 			/* By default this is an error rather than just a
 			   warning because if we allocate the section to the
@@ -5592,7 +5592,7 @@ lang_size_sections_1
 		    if (dotdelta != 0
 			&& (config.warn_section_align
 			    || os->addr_tree != NULL)
-			&& expld.phase != lang_mark_phase_enum)
+			&& expld.phase == lang_final_phase_enum)
 		      einfo (ngettext ("%P: warning: changing start of "
 				       "section %s by %lu byte\n",
 				       "%P: warning: changing start of "

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR25570, ld duplicate "warning: changing start of section"
  2020-03-04  5:57 PR25570, ld duplicate "warning: changing start of section" Alan Modra
@ 2020-03-04  6:13 ` Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2020-03-04  6:13 UTC (permalink / raw)
  To: binutils

On Wed, Mar 04, 2020 at 04:27:31PM +1030, Alan Modra wrote:
> 	PR 25570
> 	* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
> 	errors/warnings until final pass.
> 	* ldexp.c (fold_name): Likewise.

Oops, no.  lang_size_sections isn't called on the final pass so this
patch would never emit the warnings.  Reverted.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* PR25570, ld duplicate "warning: changing start of section"
@ 2020-03-04 23:25 Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2020-03-04 23:25 UTC (permalink / raw)
  To: binutils

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.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index be9ac36ede..6ffa7af575 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -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);
 }

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-04 23:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04  5:57 PR25570, ld duplicate "warning: changing start of section" Alan Modra
2020-03-04  6:13 ` Alan Modra
2020-03-04 23:25 Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).