From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 4B4DD3858C52; Thu, 22 Sep 2022 00:08:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B4DD3858C52 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_39-branch] elf: Reset alignment for each PT_LOAD segment X-Act-Checkin: binutils-gdb X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/binutils-2_39-branch X-Git-Oldrev: 08e401e41cade78591393e865304f664bb206810 X-Git-Newrev: a98316d5cf970cbc99689797d84c2ea832bcdcbb Message-Id: <20220922000839.4B4DD3858C52@sourceware.org> Date: Thu, 22 Sep 2022 00:08:39 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2022 00:08:39 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da98316d5cf97= 0cbc99689797d84c2ea832bcdcbb commit a98316d5cf970cbc99689797d84c2ea832bcdcbb Author: H.J. Lu Date: Mon Aug 1 16:02:39 2022 -0700 elf: Reset alignment for each PT_LOAD segment =20 Reset alignment for each PT_LOAD segment to avoid using alignment from the previous PT_LOAD segment. =20 bfd/ =20 PR ld/29435 * elf.c (assign_file_positions_for_load_sections): Reset alignment for each PT_LOAD segment. =20 ld/ =20 PR ld/29435 * testsuite/ld-elf/pr29435.d: New file. * testsuite/ld-elf/pr29435.s: Likewise. =20 (cherry picked from commit 59f214544c50ec7ebbca285ff2b4949f48671690) Diff: --- bfd/elf.c | 7 ++++--- ld/testsuite/ld-elf/pr29435.d | 11 +++++++++++ ld/testsuite/ld-elf/pr29435.s | 6 ++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 89484ceb233..8bd572d712e 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5438,8 +5438,6 @@ assign_file_positions_for_load_sections (bfd *abfd, Elf_Internal_Phdr *p; file_ptr off; /* Octets. */ bfd_size_type maxpagesize; - bfd_size_type p_align; - bool p_align_p =3D false; unsigned int alloc, actual; unsigned int i, j; struct elf_segment_map **sorted_seg_map; @@ -5524,7 +5522,6 @@ assign_file_positions_for_load_sections (bfd *abfd, qsort (sorted_seg_map, alloc, sizeof (*sorted_seg_map), elf_sort_segments); =20 - p_align =3D bed->p_align; maxpagesize =3D 1; if ((abfd->flags & D_PAGED) !=3D 0) { @@ -5559,6 +5556,8 @@ assign_file_positions_for_load_sections (bfd *abfd, asection **secpp; bfd_vma off_adjust; /* Octets. */ bool no_contents; + bfd_size_type p_align; + bool p_align_p; =20 /* An ELF segment (described by Elf_Internal_Phdr) may contain a number of sections with contents contributing to both p_filesz @@ -5569,6 +5568,8 @@ assign_file_positions_for_load_sections (bfd *abfd, p =3D phdrs + m->idx; p->p_type =3D m->p_type; p->p_flags =3D m->p_flags; + p_align =3D bed->p_align; + p_align_p =3D false; =20 if (m->count =3D=3D 0) p->p_vaddr =3D m->p_vaddr_offset * opb; diff --git a/ld/testsuite/ld-elf/pr29435.d b/ld/testsuite/ld-elf/pr29435.d new file mode 100644 index 00000000000..4ca4fd086a2 --- /dev/null +++ b/ld/testsuite/ld-elf/pr29435.d @@ -0,0 +1,11 @@ +#ld: -shared -z separate-code -z relro +#xfail: ![check_shared_lib_support] +#xfail: ![check_relro_support] +#readelf: -Wl + +#failif +#... + +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ .* 0x8= 000 +#... + +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ .* 0x8= 000 +#... diff --git a/ld/testsuite/ld-elf/pr29435.s b/ld/testsuite/ld-elf/pr29435.s new file mode 100644 index 00000000000..d2d8f265f5e --- /dev/null +++ b/ld/testsuite/ld-elf/pr29435.s @@ -0,0 +1,6 @@ + .text + .balign 0x8000 + .globl foo + .type foo, %function +foo: + .byte 0