toolchain/binutils: backport stable patches
[openwrt/staging/hauke.git] / toolchain / binutils / patches / 2.39 / 058-elf-Reset-alignment-for-each-PT_LOAD-segment.patch
1 From a98316d5cf970cbc99689797d84c2ea832bcdcbb Mon Sep 17 00:00:00 2001
2 From: "H.J. Lu" <hjl.tools@gmail.com>
3 Date: Mon, 1 Aug 2022 16:02:39 -0700
4 Subject: [PATCH 058/160] elf: Reset alignment for each PT_LOAD segment
5
6 Reset alignment for each PT_LOAD segment to avoid using alignment from
7 the previous PT_LOAD segment.
8
9 bfd/
10
11 PR ld/29435
12 * elf.c (assign_file_positions_for_load_sections): Reset
13 alignment for each PT_LOAD segment.
14
15 ld/
16
17 PR ld/29435
18 * testsuite/ld-elf/pr29435.d: New file.
19 * testsuite/ld-elf/pr29435.s: Likewise.
20
21 (cherry picked from commit 59f214544c50ec7ebbca285ff2b4949f48671690)
22 ---
23 bfd/elf.c | 7 ++++---
24 ld/testsuite/ld-elf/pr29435.d | 11 +++++++++++
25 ld/testsuite/ld-elf/pr29435.s | 6 ++++++
26 3 files changed, 21 insertions(+), 3 deletions(-)
27 create mode 100644 ld/testsuite/ld-elf/pr29435.d
28 create mode 100644 ld/testsuite/ld-elf/pr29435.s
29
30 --- a/bfd/elf.c
31 +++ b/bfd/elf.c
32 @@ -5438,8 +5438,6 @@ assign_file_positions_for_load_sections
33 Elf_Internal_Phdr *p;
34 file_ptr off; /* Octets. */
35 bfd_size_type maxpagesize;
36 - bfd_size_type p_align;
37 - bool p_align_p = false;
38 unsigned int alloc, actual;
39 unsigned int i, j;
40 struct elf_segment_map **sorted_seg_map;
41 @@ -5524,7 +5522,6 @@ assign_file_positions_for_load_sections
42 qsort (sorted_seg_map, alloc, sizeof (*sorted_seg_map),
43 elf_sort_segments);
44
45 - p_align = bed->p_align;
46 maxpagesize = 1;
47 if ((abfd->flags & D_PAGED) != 0)
48 {
49 @@ -5559,6 +5556,8 @@ assign_file_positions_for_load_sections
50 asection **secpp;
51 bfd_vma off_adjust; /* Octets. */
52 bool no_contents;
53 + bfd_size_type p_align;
54 + bool p_align_p;
55
56 /* An ELF segment (described by Elf_Internal_Phdr) may contain a
57 number of sections with contents contributing to both p_filesz
58 @@ -5569,6 +5568,8 @@ assign_file_positions_for_load_sections
59 p = phdrs + m->idx;
60 p->p_type = m->p_type;
61 p->p_flags = m->p_flags;
62 + p_align = bed->p_align;
63 + p_align_p = false;
64
65 if (m->count == 0)
66 p->p_vaddr = m->p_vaddr_offset * opb;
67 --- /dev/null
68 +++ b/ld/testsuite/ld-elf/pr29435.d
69 @@ -0,0 +1,11 @@
70 +#ld: -shared -z separate-code -z relro
71 +#xfail: ![check_shared_lib_support]
72 +#xfail: ![check_relro_support]
73 +#readelf: -Wl
74 +
75 +#failif
76 +#...
77 + +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ .* 0x8000
78 +#...
79 + +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ .* 0x8000
80 +#...
81 --- /dev/null
82 +++ b/ld/testsuite/ld-elf/pr29435.s
83 @@ -0,0 +1,6 @@
84 + .text
85 + .balign 0x8000
86 + .globl foo
87 + .type foo, %function
88 +foo:
89 + .byte 0