public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Reset alignment for each PT_LOAD segment
@ 2022-08-01 23:11 H.J. Lu
  2022-08-03  8:45 ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2022-08-01 23:11 UTC (permalink / raw)
  To: binutils

Reset alignment for each PT_LOAD segment to avoid using alignment from
the previous PT_LOAD segment.

bfd/

	PR ld/29435
	* elf.c (assign_file_positions_for_load_sections): Reset
	alignment for each PT_LOAD segment.

ld/

	PR ld/29435
	* testsuite/ld-elf/pr29435.d: New file.
	* testsuite/ld-elf/pr29435.s: Likewise.
---
 bfd/elf.c                     |  5 +++--
 ld/testsuite/ld-elf/pr29435.d | 11 +++++++++++
 ld/testsuite/ld-elf/pr29435.s |  6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pr29435.d
 create mode 100644 ld/testsuite/ld-elf/pr29435.s

diff --git a/bfd/elf.c b/bfd/elf.c
index 89484ceb233..647f2923beb 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5439,7 +5439,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
   file_ptr off;  /* Octets.  */
   bfd_size_type maxpagesize;
   bfd_size_type p_align;
-  bool p_align_p = false;
+  bool p_align_p;
   unsigned int alloc, actual;
   unsigned int i, j;
   struct elf_segment_map **sorted_seg_map;
@@ -5524,7 +5524,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
     qsort (sorted_seg_map, alloc, sizeof (*sorted_seg_map),
 	   elf_sort_segments);
 
-  p_align = bed->p_align;
   maxpagesize = 1;
   if ((abfd->flags & D_PAGED) != 0)
     {
@@ -5569,6 +5568,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
       p = phdrs + m->idx;
       p->p_type = m->p_type;
       p->p_flags = m->p_flags;
+      p_align = bed->p_align;
+      p_align_p = false;
 
       if (m->count == 0)
 	p->p_vaddr = 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]+ .* 0x8000
+#...
+ +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ .* 0x8000
+#...
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
-- 
2.37.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] elf: Reset alignment for each PT_LOAD segment
  2022-08-01 23:11 [PATCH] elf: Reset alignment for each PT_LOAD segment H.J. Lu
@ 2022-08-03  8:45 ` Jan Beulich
  2022-08-03 17:06   ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2022-08-03  8:45 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On 02.08.2022 01:11, H.J. Lu via Binutils wrote:
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -5439,7 +5439,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
>    file_ptr off;  /* Octets.  */
>    bfd_size_type maxpagesize;
>    bfd_size_type p_align;
> -  bool p_align_p = false;
> +  bool p_align_p;

Wouldn't it be helpful / good practice to also move the two variables
into the loop's scope (and then using initializers in favor of
assignments)? Okay preferably with that adjustment.

Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] elf: Reset alignment for each PT_LOAD segment
  2022-08-03  8:45 ` Jan Beulich
@ 2022-08-03 17:06   ` H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2022-08-03 17:06 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Binutils

On Wed, Aug 3, 2022 at 1:45 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 02.08.2022 01:11, H.J. Lu via Binutils wrote:
> > --- a/bfd/elf.c
> > +++ b/bfd/elf.c
> > @@ -5439,7 +5439,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
> >    file_ptr off;  /* Octets.  */
> >    bfd_size_type maxpagesize;
> >    bfd_size_type p_align;
> > -  bool p_align_p = false;
> > +  bool p_align_p;
>
> Wouldn't it be helpful / good practice to also move the two variables

Good point.

> into the loop's scope (and then using initializers in favor of
> assignments)? Okay preferably with that adjustment.
>
> Jan

This is the patch I am checking in:

https://sourceware.org/pipermail/binutils/2022-August/122191.html

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-03 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 23:11 [PATCH] elf: Reset alignment for each PT_LOAD segment H.J. Lu
2022-08-03  8:45 ` Jan Beulich
2022-08-03 17:06   ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).