From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id C7E2E385842A; Wed, 18 Oct 2023 13:39:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7E2E385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1697636397; bh=xGfo0x4aCwaz1qV7OyyiKc1Q8fdAdTCX6Io5dMbhRHs=; h=From:To:Subject:Date:From; b=RJv0BZ+UDNYVzTGdI4b4CE5L12FQL5G+SgSObiFR30JfHr/yCVJ1AtIINdrDFekJL rGOakthA8Xmn7dqVZufpcQS88AoHJAu37T5TDhfavcRHLXpEfuCoGAVXFNdYwNjiIw wfYCID4IdkkJGSdx9jt/P3y3He5TBtH0QNSHpxWk= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc/release/2.36/master] Revert "elf: Remove unused l_text_end field from struct link_map" X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/release/2.36/master X-Git-Oldrev: 22955ad85186ee05834e47e665056148ca07699c X-Git-Newrev: ad96b5532570a6782f784b4f2c6aa2a52359144d Message-Id: <20231018133957.C7E2E385842A@sourceware.org> Date: Wed, 18 Oct 2023 13:39:57 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ad96b5532570a6782f784b4f2c6aa2a52359144d commit ad96b5532570a6782f784b4f2c6aa2a52359144d Author: Florian Weimer Date: Wed Oct 18 14:30:00 2023 +0200 Revert "elf: Remove unused l_text_end field from struct link_map" This reverts commit 9f0d3bb2e325dc30ae20e347cccbe10fa0b4ce9b. Reason for revert: Preserve ABI after revert of commit 5d83a52a4. Diff: --- elf/dl-load.c | 2 +- elf/dl-load.h | 7 +++++-- elf/rtld.c | 6 ++++++ elf/setup-vdso.h | 4 ++++ include/link.h | 2 ++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index cb59c21ce7..1ad0868dad 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1263,7 +1263,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* Now process the load commands and map segments into memory. 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, maplength, has_holes, loader); diff --git a/elf/dl-load.h b/elf/dl-load.h index ebf7d74cd0..f98d264e90 100644 --- a/elf/dl-load.h +++ b/elf/dl-load.h @@ -83,11 +83,14 @@ struct loadcmd /* 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 - responsible for setting the l_phdr fields */ + responsible for setting up the l_text_end and l_phdr fields. */ static __always_inline void _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header, const struct loadcmd *c) { + if (c->prot & PROT_EXEC) + l->l_text_end = l->l_addr + c->mapend; + if (l->l_phdr == 0 && c->mapoff <= header->e_phoff && ((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 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 final places in the address space, with the correct page permissions, and any bss-like regions already zeroed. It returns a null pointer diff --git a/elf/rtld.c b/elf/rtld.c index dd45930ff7..3e771a93d8 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -479,6 +479,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_map_start = (ElfW(Addr)) &__ehdr_start; 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. */ #ifndef DONT_USE_BOOTSTRAP_MAP # if NO_TLS_OFFSET != 0 @@ -1123,6 +1124,7 @@ rtld_setup_main_map (struct link_map *main_map) bool has_interp = false; main_map->l_map_end = 0; + main_map->l_text_end = 0; /* Perhaps the executable has no PT_LOAD header entries at all. */ main_map->l_map_start = ~0; /* And it was opened directly. */ @@ -1214,6 +1216,8 @@ rtld_setup_main_map (struct link_map *main_map) allocend = main_map->l_addr + ph->p_vaddr + ph->p_memsz; if (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 segment. */ @@ -1273,6 +1277,8 @@ rtld_setup_main_map (struct link_map *main_map) = (char *) main_map->l_tls_initimage + main_map->l_addr; if (! main_map->l_map_end) 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) { /* We were invoked directly, so the program might not have a diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h index 415d5057c3..c0807ea82b 100644 --- a/elf/setup-vdso.h +++ b/elf/setup-vdso.h @@ -51,6 +51,9 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)), l->l_addr = ph->p_vaddr; if (ph->p_vaddr + ph->p_memsz >= l->l_map_end) 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 /* 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_addr = l->l_map_start - 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); elf_get_dynamic_info (l, false, false); _dl_setup_hash (l); diff --git a/include/link.h b/include/link.h index 4eb8fe0d96..8176e23da9 100644 --- a/include/link.h +++ b/include/link.h @@ -253,6 +253,8 @@ struct link_map /* Start and finish of memory map for this object. l_map_start need not be the same as l_addr. */ 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 order. Head of list is stored in _dl_init_called_list. */