aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-03-10 23:01:54 +1030
committerAlan Modra <amodra@gmail.com>2025-03-10 23:01:54 +1030
commitb8c5ada1742586d389cec1b82f69c895976b1849 (patch)
tree3c24672ff7e18bea809221f1759e5b3f519df73a
parentce53bc06f64a17cfe2e6c598e47e772f6a29e2f5 (diff)
downloadbinutils-b8c5ada1742586d389cec1b82f69c895976b1849.zip
binutils-b8c5ada1742586d389cec1b82f69c895976b1849.tar.gz
binutils-b8c5ada1742586d389cec1b82f69c895976b1849.tar.bz2
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.
-rw-r--r--bfd/elf.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 1193f4a..20f96e6 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;
}
}