--- src/sys/kern/imgact_elf.c 2005/02/26 20:32:36 1.25 +++ src/sys/kern/imgact_elf.c 2005/03/08 12:30:32 1.26 @@ -542,6 +542,17 @@ exec_elf_imgact(struct image_params *img 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);