[PATCH 4/4] gas: move had_errors() invocation in finishing of subsegs

Jan Beulich jbeulich@suse.com
Mon Nov 11 08:45:06 GMT 2024


Invoking this repeatedly in an inner loop is not only inefficient, but
may lead to inconsistencies in e.g. the listings that the original
comment author cared about. (Accept potential inconsistencies across
distinct sections though, to cover all invocations of the function.)
---
The reason for padding the last fragment of mergable sections to (not
really) their entry size (commit 381a1ab30c06) isn't clear to me. If
such padding was necessary, shouldn't it be truly to entsize, rather
than its largest power-of-2 divisor?

--- a/gas/write.c
+++ b/gas/write.c
@@ -1849,6 +1849,12 @@ subsegs_finish_section (asection *s)
   if (!seginfo)
     return;
 
+  /* This now gets called even if we had errors.  In that case, any alignment
+     is meaningless, and, moreover, will look weird if we are generating a
+     listing.  */
+  if (had_errors ())
+    do_not_pad_sections_to_alignment = 1;
+
   for (frchainP = seginfo->frchainP;
        frchainP != NULL;
        frchainP = frchainP->frch_next)
@@ -1857,12 +1863,6 @@ subsegs_finish_section (asection *s)
 
       subseg_set (s, frchainP->frch_subseg);
 
-      /* This now gets called even if we had errors.  In that case,
-	 any alignment is meaningless, and, moreover, will look weird
-	 if we are generating a listing.  */
-      if (had_errors ())
-	do_not_pad_sections_to_alignment = 1;
-
       alignment = SUB_SEGMENT_ALIGN (now_seg, frchainP);
       if ((bfd_section_flags (now_seg) & (SEC_MERGE | SEC_STRINGS))
 	  && now_seg->entsize)



More information about the Binutils mailing list