From 22cc99716957bd7e3f70109deed2d322460ef231 Mon Sep 17 00:00:00 2001 From: David Xu Date: Tue, 8 Mar 2005 12:30:32 +0000 Subject: [PATCH] Merge from FreeBSD: Make sure that AT_PHDR has a useful value even for static programs. This header will be accessed via environ variable in libc, as crt0 stores the address into the variable. We use this header to phase TLS info in libc for static programs. --- sys/kern/imgact_elf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index bb7ade73e0..abff851915 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -27,7 +27,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/kern/imgact_elf.c,v 1.73.2.13 2002/12/28 19:49:41 dillon Exp $ - * $DragonFly: src/sys/kern/imgact_elf.c,v 1.25 2005/02/26 20:32:36 dillon Exp $ + * $DragonFly: src/sys/kern/imgact_elf.c,v 1.26 2005/03/08 12:30:32 davidxu Exp $ */ #include @@ -542,6 +542,17 @@ exec_elf_imgact(struct image_params *imgp) phdr[i].p_filesz, prot)) != 0) goto fail; + /* + * If this segment contains the program headers, + * remember their virtual address for the AT_PHDR + * aux entry. Static binaries don't usually include + * a PT_PHDR entry. + */ + if (phdr[i].p_offset == 0 && + hdr->e_phoff + hdr->e_phnum * hdr->e_phentsize + <= phdr[i].p_filesz) + proghdr = phdr[i].p_vaddr + hdr->e_phoff; + seg_addr = trunc_page(phdr[i].p_vaddr); seg_size = round_page(phdr[i].p_memsz + phdr[i].p_vaddr - seg_addr); -- 2.41.0