[binutils-gdb] Further tidies to bed->p_align code
Alan Modra
amodra@sourceware.org
Mon Mar 10 12:55:56 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b8c5ada1742586d389cec1b82f69c895976b1849
commit b8c5ada1742586d389cec1b82f69c895976b1849
Author: Alan Modra <amodra@gmail.com>
Date: Mon Mar 10 23:01:54 2025 +1030
Further tidies to bed->p_align code
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.
Diff:
---
bfd/elf.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/bfd/elf.c b/bfd/elf.c
index 1193f4a78ce..20f96e689ce 100644
--- 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;
}
}
More information about the Binutils-cvs
mailing list