Revert "elf: Remove unused l_text_end field from struct link_map"

This reverts commit 34b07bdbdd.

Reason for revert: Preserve ABI after revert of commit 02a67e102f.
This commit is contained in:
Florian Weimer 2023-10-18 14:32:12 +02:00
parent c84018a05a
commit 6aa8380cf5
5 changed files with 18 additions and 3 deletions

View File

@ -1253,7 +1253,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
/* Now process the load commands and map segments into memory. /* Now process the load commands and map segments into memory.
This is responsible for filling in: This is responsible for filling in:
l_map_start, l_map_end, l_addr, l_contiguous, l_phdr l_map_start, l_map_end, l_addr, l_contiguous, l_text_end, l_phdr
*/ */
errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds, errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds,
maplength, has_holes, loader); maplength, has_holes, loader);

View File

@ -83,11 +83,14 @@ struct loadcmd
/* This is a subroutine of _dl_map_segments. It should be called for each /* This is a subroutine of _dl_map_segments. It should be called for each
load command, some time after L->l_addr has been set correctly. It is load command, some time after L->l_addr has been set correctly. It is
responsible for setting the l_phdr fields */ responsible for setting up the l_text_end and l_phdr fields. */
static __always_inline void static __always_inline void
_dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header, _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header,
const struct loadcmd *c) const struct loadcmd *c)
{ {
if (c->prot & PROT_EXEC)
l->l_text_end = l->l_addr + c->mapend;
if (l->l_phdr == 0 if (l->l_phdr == 0
&& c->mapoff <= header->e_phoff && c->mapoff <= header->e_phoff
&& ((size_t) (c->mapend - c->mapstart + c->mapoff) && ((size_t) (c->mapend - c->mapstart + c->mapoff)
@ -100,7 +103,7 @@ _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header,
/* This is a subroutine of _dl_map_object_from_fd. It is responsible /* This is a subroutine of _dl_map_object_from_fd. It is responsible
for filling in several fields in *L: l_map_start, l_map_end, l_addr, for filling in several fields in *L: l_map_start, l_map_end, l_addr,
l_contiguous, l_phdr. On successful return, all the l_contiguous, l_text_end, l_phdr. On successful return, all the
segments are mapped (or copied, or whatever) from the file into their segments are mapped (or copied, or whatever) from the file into their
final places in the address space, with the correct page permissions, final places in the address space, with the correct page permissions,
and any bss-like regions already zeroed. It returns a null pointer and any bss-like regions already zeroed. It returns a null pointer

View File

@ -489,6 +489,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
GL(dl_rtld_map).l_real = &GL(dl_rtld_map); GL(dl_rtld_map).l_real = &GL(dl_rtld_map);
GL(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start; GL(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start;
GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end; GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext;
/* Copy the TLS related data if necessary. */ /* Copy the TLS related data if necessary. */
#ifndef DONT_USE_BOOTSTRAP_MAP #ifndef DONT_USE_BOOTSTRAP_MAP
# if NO_TLS_OFFSET != 0 # if NO_TLS_OFFSET != 0
@ -1142,6 +1143,7 @@ rtld_setup_main_map (struct link_map *main_map)
bool has_interp = false; bool has_interp = false;
main_map->l_map_end = 0; main_map->l_map_end = 0;
main_map->l_text_end = 0;
/* Perhaps the executable has no PT_LOAD header entries at all. */ /* Perhaps the executable has no PT_LOAD header entries at all. */
main_map->l_map_start = ~0; main_map->l_map_start = ~0;
/* And it was opened directly. */ /* And it was opened directly. */
@ -1233,6 +1235,8 @@ rtld_setup_main_map (struct link_map *main_map)
allocend = main_map->l_addr + ph->p_vaddr + ph->p_memsz; allocend = main_map->l_addr + ph->p_vaddr + ph->p_memsz;
if (main_map->l_map_end < allocend) if (main_map->l_map_end < allocend)
main_map->l_map_end = allocend; main_map->l_map_end = allocend;
if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
main_map->l_text_end = allocend;
/* The next expected address is the page following this load /* The next expected address is the page following this load
segment. */ segment. */
@ -1292,6 +1296,8 @@ rtld_setup_main_map (struct link_map *main_map)
= (char *) main_map->l_tls_initimage + main_map->l_addr; = (char *) main_map->l_tls_initimage + main_map->l_addr;
if (! main_map->l_map_end) if (! main_map->l_map_end)
main_map->l_map_end = ~0; main_map->l_map_end = ~0;
if (! main_map->l_text_end)
main_map->l_text_end = ~0;
if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name) if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name)
{ {
/* We were invoked directly, so the program might not have a /* We were invoked directly, so the program might not have a

View File

@ -51,6 +51,9 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
l->l_addr = ph->p_vaddr; l->l_addr = ph->p_vaddr;
if (ph->p_vaddr + ph->p_memsz >= l->l_map_end) if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
l->l_map_end = ph->p_vaddr + ph->p_memsz; l->l_map_end = ph->p_vaddr + ph->p_memsz;
if ((ph->p_flags & PF_X)
&& ph->p_vaddr + ph->p_memsz >= l->l_text_end)
l->l_text_end = ph->p_vaddr + ph->p_memsz;
} }
else else
/* There must be no TLS segment. */ /* There must be no TLS segment. */
@ -59,6 +62,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso); l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);
l->l_addr = l->l_map_start - l->l_addr; l->l_addr = l->l_map_start - l->l_addr;
l->l_map_end += l->l_addr; l->l_map_end += l->l_addr;
l->l_text_end += l->l_addr;
l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr); l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
elf_get_dynamic_info (l, false, false); elf_get_dynamic_info (l, false, false);
_dl_setup_hash (l); _dl_setup_hash (l);

View File

@ -255,6 +255,8 @@ struct link_map
/* Start and finish of memory map for this object. l_map_start /* Start and finish of memory map for this object. l_map_start
need not be the same as l_addr. */ need not be the same as l_addr. */
ElfW(Addr) l_map_start, l_map_end; ElfW(Addr) l_map_start, l_map_end;
/* End of the executable part of the mapping. */
ElfW(Addr) l_text_end;
/* Linked list of objects in reverse ELF constructor execution /* Linked list of objects in reverse ELF constructor execution
order. Head of list is stored in _dl_init_called_list. */ order. Head of list is stored in _dl_init_called_list. */