]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Further tidies to bed->p_align code
authorAlan Modra <amodra@gmail.com>
Mon, 10 Mar 2025 12:31:54 +0000 (23:01 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 10 Mar 2025 12:31:54 +0000 (23:01 +1030)
align_pagesize was used for two things, reducing p->p_align from
maxpagesize to the bed->p_align value (section alignment permitting),
and increasing p->p_align above maxpagesize if section alignment
required that.  This patch untangles those two, making align_pagesize
only do the former.  p->p_align is set directly for the latter.  I've
made that change to p->p_align only when D_PAGED to keep things
consistent with other early assignments to p->p_align.  p->p_align is
set later according to section alignment when not D_PAGED.

I've also moved the place where align_pagesize adjusts p->p_align to
be with other code setting p->p_align.  That seemed better to me than
leaving it until the last possible moment.  Note that it isn't
necessary to have this adjustment done inside a test for a PT_LOAD
header, since we never set align_pagesize non-zero outside a PT_LOAD
test.

* elf.c (assign_file_positions_for_load_sections): Clear
align_pagesize whenever we have a section alignment more than
bed->p_align.  Set p->p_align rather than align_pagesize
when section alignment exceeds maxpagesize.  Assign p->p_align
from align_pagesize earlier.

bfd/elf.c

index 1193f4a78ce691a577207d029b7ee9dffe99b887..20f96e689ce49288db0df79d5b90a5f5ea21a8fb 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6002,21 +6002,20 @@ assign_file_positions_for_load_sections (bfd *abfd,
                    align_power = secalign;
                }
              align = (bfd_size_type) 1 << align_power;
+             /* If a section requires alignment higher than the
+                minimum p_align value, don't reduce a maxpagesize
+                p->p_align set earlier in this function.  */
+             if (align > bed->p_align)
+               align_pagesize = 0;
              if (align < maxpagesize)
-               {
-                 /* If a section requires alignment higher than the
-                    minimum p_align value, don't reduce a maxpagesize
-                    p->p_align set earlier in this function.  */
-                 if (align > bed->p_align)
-                   align_pagesize = 0;
-                 align = maxpagesize;
-               }
+               align = maxpagesize;
              else
                {
                  /* If a section requires alignment higher than the
                     maximum page size, set p_align to the section
                     alignment.  */
-                 align_pagesize = align;
+                 if ((abfd->flags & D_PAGED) != 0)
+                   p->p_align = align;
                }
            }
 
@@ -6185,6 +6184,9 @@ assign_file_positions_for_load_sections (bfd *abfd,
            }
        }
 
+      if (align_pagesize)
+       p->p_align = align_pagesize;
+
       /* Set up p_filesz, p_memsz, p_align and p_flags from the section
         maps.  Set filepos for sections in PT_LOAD segments, and in
         core files, for sections in PT_NOTE segments.
@@ -6403,9 +6405,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
                  print_segment_map (m);
                }
            }
-
-         if (align_pagesize)
-           p->p_align = align_pagesize;
        }
     }