public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] elf: Reset alignment for each PT_LOAD segment
@ 2022-08-03 20:41 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2022-08-03 20:41 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=59f214544c50ec7ebbca285ff2b4949f48671690

commit 59f214544c50ec7ebbca285ff2b4949f48671690
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 1 16:02:39 2022 -0700

    elf: Reset alignment for each PT_LOAD segment
    
    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.

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 25f4bca34f0..3e64cdf6699 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5440,8 +5440,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 = false;
   unsigned int alloc, actual;
   unsigned int i, j;
   struct elf_segment_map **sorted_seg_map;
@@ -5526,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)
     {
@@ -5561,6 +5558,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;
 
       /* An ELF segment (described by Elf_Internal_Phdr) may contain a
 	 number of sections with contents contributing to both p_filesz
@@ -5571,6 +5570,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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-03 20:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 20:41 [binutils-gdb] elf: Reset alignment for each PT_LOAD segment 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).