Tidy code handling bed->p_align a little.

No functional changes here, just preparation for the next patch.

	* elf.c (assign_file_positions_for_load_sections): Replace
	p_align_p and p_align with align_pagesize.  Revise comments
	on code handling bed->p_align.
This commit is contained in:
Alan Modra
2025-03-10 23:00:10 +10:30
parent 28704396ab
commit ce53bc06f6

View File

@@ -5921,8 +5921,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
asection **secpp; asection **secpp;
bfd_vma off_adjust; /* Octets. */ bfd_vma off_adjust; /* Octets. */
bool no_contents; bool no_contents;
bfd_size_type p_align; bfd_size_type align_pagesize;
bool p_align_p;
/* An ELF segment (described by Elf_Internal_Phdr) may contain a /* An ELF segment (described by Elf_Internal_Phdr) may contain a
number of sections with contents contributing to both p_filesz number of sections with contents contributing to both p_filesz
@@ -5933,8 +5932,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
p = phdrs + m->idx; p = phdrs + m->idx;
p->p_type = m->p_type; p->p_type = m->p_type;
p->p_flags = m->p_flags; p->p_flags = m->p_flags;
p_align = bed->p_align;
p_align_p = false;
if (m->count == 0) if (m->count == 0)
p->p_vaddr = m->p_vaddr_offset * opb; p->p_vaddr = m->p_vaddr_offset * opb;
@@ -5948,6 +5945,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
else else
p->p_paddr = (m->sections[0]->lma + m->p_vaddr_offset) * opb; p->p_paddr = (m->sections[0]->lma + m->p_vaddr_offset) * opb;
align_pagesize = 0;
if (p->p_type == PT_LOAD if (p->p_type == PT_LOAD
&& (abfd->flags & D_PAGED) != 0) && (abfd->flags & D_PAGED) != 0)
{ {
@@ -5961,15 +5959,17 @@ assign_file_positions_for_load_sections (bfd *abfd,
segment. */ segment. */
if (m->p_align_valid) if (m->p_align_valid)
maxpagesize = m->p_align; maxpagesize = m->p_align;
else if (p_align != 0 else if (bed->p_align != 0
&& (link_info == NULL && (link_info == NULL
|| !link_info->maxpagesize_is_set)) || !link_info->maxpagesize_is_set))
/* Set p_align to the default p_align value while laying /* We will lay out this binary using maxpagesize but set
out segments aligning to the maximum page size or the p->p_align later to the possibly smaller bed->p_align.
largest section alignment. The run-time loader can The run-time loader will then be able to load this
align segments to the default p_align value or the binary when the system page size is maxpagesize, but if
maximum page size, depending on system page size. */ the system page size is smaller can use p->p_align.
p_align_p = true; In either case p->p_align will be increased if
necessary to match section alignment. */
align_pagesize = bed->p_align;
p->p_align = maxpagesize; p->p_align = maxpagesize;
} }
@@ -6005,10 +6005,10 @@ assign_file_positions_for_load_sections (bfd *abfd,
if (align < maxpagesize) if (align < maxpagesize)
{ {
/* If a section requires alignment higher than the /* If a section requires alignment higher than the
default p_align value, don't set p_align to the minimum p_align value, don't reduce a maxpagesize
default p_align value. */ p->p_align set earlier in this function. */
if (align > p_align) if (align > bed->p_align)
p_align_p = false; align_pagesize = 0;
align = maxpagesize; align = maxpagesize;
} }
else else
@@ -6016,8 +6016,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
/* If a section requires alignment higher than the /* If a section requires alignment higher than the
maximum page size, set p_align to the section maximum page size, set p_align to the section
alignment. */ alignment. */
p_align_p = true; align_pagesize = align;
p_align = align;
} }
} }
@@ -6405,8 +6404,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
} }
} }
if (p_align_p) if (align_pagesize)
p->p_align = p_align; p->p_align = align_pagesize;
} }
} }