]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/glibc-2.38/0028-Revert-elf-Remove-unused-l_text_end-field-from-struc.patch
glibc: Import latest patches from upstream
[ipfire-2.x.git] / src / patches / glibc-2.38 / 0028-Revert-elf-Remove-unused-l_text_end-field-from-struc.patch
CommitLineData
a61a21ef
MT
1From e0b6c9706c91a642c781918eea52588ee8dc9f09 Mon Sep 17 00:00:00 2001
2From: Florian Weimer <fweimer@redhat.com>
3Date: Wed, 18 Oct 2023 14:22:59 +0200
4Subject: [PATCH 28/44] Revert "elf: Remove unused l_text_end field from struct
5 link_map"
6
7This reverts commit 750f19526ae71aac801c77a3f7ef5374890c09b7.
8
9Reason for revert: Restore ABI after revert of commit a3189f66a5f.
10---
11 elf/dl-load.c | 2 +-
12 elf/dl-load.h | 7 +++++--
13 elf/rtld.c | 6 ++++++
14 elf/setup-vdso.h | 4 ++++
15 include/link.h | 2 ++
16 5 files changed, 18 insertions(+), 3 deletions(-)
17
18diff --git a/elf/dl-load.c b/elf/dl-load.c
19index 2923b1141d..9a87fda9c9 100644
20--- a/elf/dl-load.c
21+++ b/elf/dl-load.c
22@@ -1253,7 +1253,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
23
24 /* Now process the load commands and map segments into memory.
25 This is responsible for filling in:
26- l_map_start, l_map_end, l_addr, l_contiguous, l_phdr
27+ l_map_start, l_map_end, l_addr, l_contiguous, l_text_end, l_phdr
28 */
29 errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds,
30 maplength, has_holes, loader);
31diff --git a/elf/dl-load.h b/elf/dl-load.h
32index 1d5207694b..ecf6910c68 100644
33--- a/elf/dl-load.h
34+++ b/elf/dl-load.h
35@@ -83,11 +83,14 @@ struct loadcmd
36
37 /* This is a subroutine of _dl_map_segments. It should be called for each
38 load command, some time after L->l_addr has been set correctly. It is
39- responsible for setting the l_phdr fields */
40+ responsible for setting up the l_text_end and l_phdr fields. */
41 static __always_inline void
42 _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header,
43 const struct loadcmd *c)
44 {
45+ if (c->prot & PROT_EXEC)
46+ l->l_text_end = l->l_addr + c->mapend;
47+
48 if (l->l_phdr == 0
49 && c->mapoff <= header->e_phoff
50 && ((size_t) (c->mapend - c->mapstart + c->mapoff)
51@@ -100,7 +103,7 @@ _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header,
52
53 /* This is a subroutine of _dl_map_object_from_fd. It is responsible
54 for filling in several fields in *L: l_map_start, l_map_end, l_addr,
55- l_contiguous, l_phdr. On successful return, all the
56+ l_contiguous, l_text_end, l_phdr. On successful return, all the
57 segments are mapped (or copied, or whatever) from the file into their
58 final places in the address space, with the correct page permissions,
59 and any bss-like regions already zeroed. It returns a null pointer
60diff --git a/elf/rtld.c b/elf/rtld.c
61index 5107d16fe3..a91e2a4471 100644
62--- a/elf/rtld.c
63+++ b/elf/rtld.c
64@@ -477,6 +477,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
65 GL(dl_rtld_map).l_real = &GL(dl_rtld_map);
66 GL(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start;
67 GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
68+ GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext;
69 /* Copy the TLS related data if necessary. */
70 #ifndef DONT_USE_BOOTSTRAP_MAP
71 # if NO_TLS_OFFSET != 0
72@@ -1118,6 +1119,7 @@ rtld_setup_main_map (struct link_map *main_map)
73 bool has_interp = false;
74
75 main_map->l_map_end = 0;
76+ main_map->l_text_end = 0;
77 /* Perhaps the executable has no PT_LOAD header entries at all. */
78 main_map->l_map_start = ~0;
79 /* And it was opened directly. */
80@@ -1209,6 +1211,8 @@ rtld_setup_main_map (struct link_map *main_map)
81 allocend = main_map->l_addr + ph->p_vaddr + ph->p_memsz;
82 if (main_map->l_map_end < allocend)
83 main_map->l_map_end = allocend;
84+ if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
85+ main_map->l_text_end = allocend;
86
87 /* The next expected address is the page following this load
88 segment. */
89@@ -1268,6 +1272,8 @@ rtld_setup_main_map (struct link_map *main_map)
90 = (char *) main_map->l_tls_initimage + main_map->l_addr;
91 if (! main_map->l_map_end)
92 main_map->l_map_end = ~0;
93+ if (! main_map->l_text_end)
94+ main_map->l_text_end = ~0;
95 if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name)
96 {
97 /* We were invoked directly, so the program might not have a
98diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
99index d92b12a7aa..0079842d1f 100644
100--- a/elf/setup-vdso.h
101+++ b/elf/setup-vdso.h
102@@ -51,6 +51,9 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
103 l->l_addr = ph->p_vaddr;
104 if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
105 l->l_map_end = ph->p_vaddr + ph->p_memsz;
106+ if ((ph->p_flags & PF_X)
107+ && ph->p_vaddr + ph->p_memsz >= l->l_text_end)
108+ l->l_text_end = ph->p_vaddr + ph->p_memsz;
109 }
110 else
111 /* There must be no TLS segment. */
112@@ -59,6 +62,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
113 l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);
114 l->l_addr = l->l_map_start - l->l_addr;
115 l->l_map_end += l->l_addr;
116+ l->l_text_end += l->l_addr;
117 l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
118 elf_get_dynamic_info (l, false, false);
119 _dl_setup_hash (l);
120diff --git a/include/link.h b/include/link.h
121index 686813f281..a02d5f2eba 100644
122--- a/include/link.h
123+++ b/include/link.h
124@@ -253,6 +253,8 @@ struct link_map
125 /* Start and finish of memory map for this object. l_map_start
126 need not be the same as l_addr. */
127 ElfW(Addr) l_map_start, l_map_end;
128+ /* End of the executable part of the mapping. */
129+ ElfW(Addr) l_text_end;
130
131 /* Linked list of objects in reverse ELF constructor execution
132 order. Head of list is stored in _dl_init_called_list. */
133--
1342.39.2
135