From owner-svn-src-all@freebsd.org Tue Oct 30 15:33:00 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F097810EB983; Tue, 30 Oct 2018 15:32:59 +0000 (UTC) (envelope-from arichardson.kde@gmail.com) Received: from mail-yw1-f42.google.com (mail-yw1-f42.google.com [209.85.161.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 946006B46B; Tue, 30 Oct 2018 15:32:59 +0000 (UTC) (envelope-from arichardson.kde@gmail.com) Received: by mail-yw1-f42.google.com with SMTP id j202-v6so5066040ywa.13; Tue, 30 Oct 2018 08:32:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lczByhvdLZBbZ0ECfMsYkRoa9DZDp2Yx2OHT+J+VxMI=; b=slmNSDmptevPnxC6WpSqBpyIDG6daH4MOpxT/Br3sQruWV6uLJDhwxGjtq3nn/NTsd IxlUAXmieu9vj2+Nrh7EfhhKAr969p+8WllEjbbuFhcT/MwFdIA5W1wDBvvRyj/uPFhj JWeQ0FmsHjFbpG7qn5s9vn10CiahAHJ0etUq9z31fipbOM1qYu7Z+yZxabBdwNiXEbOM 7AfUuB5Dn1/0+jaKI+fgzypDzewImrV354wL3PtM+h5A8hyZy34LYhnBma8yFI/vfJp2 /351AAKggihCERfXl2X9BXr8jeMhRmTtqwxQqQ9Y4lrOWW1HZby4W7LCfLfuBRJcbMkQ E41A== X-Gm-Message-State: AGRZ1gLAcBKSGsEM9KDgldgr4npIAeL7pZhfjqP5b4ikCDSytPVlqK3M j2tsO6yYyYaS0e0r5GaiBR3CtT7GXQ8= X-Google-Smtp-Source: AJdET5dRO5DHVacPb/OSbtse6GZqxcViGAJuqB3GrfqHciIbkDHdVkcKGoUxnUmMmONWfFgaEvsKPA== X-Received: by 2002:a81:3a89:: with SMTP id h131-v6mr2938948ywa.210.1540913572470; Tue, 30 Oct 2018 08:32:52 -0700 (PDT) Received: from mail-yw1-f49.google.com (mail-yw1-f49.google.com. [209.85.161.49]) by smtp.gmail.com with ESMTPSA id g5-v6sm7103494ywa.39.2018.10.30.08.32.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 08:32:52 -0700 (PDT) Received: by mail-yw1-f49.google.com with SMTP id c126-v6so5071191ywd.8; Tue, 30 Oct 2018 08:32:52 -0700 (PDT) X-Received: by 2002:a81:417:: with SMTP id 23-v6mr2896422ywe.203.1540913571909; Tue, 30 Oct 2018 08:32:51 -0700 (PDT) MIME-Version: 1.0 References: <201810292108.w9TL83bO041913@repo.freebsd.org> In-Reply-To: From: Alexander Richardson Date: Tue, 30 Oct 2018 15:32:40 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r339876 - head/libexec/rtld-elf To: Michael.Tuexen@macmic.franken.de Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2018 15:33:00 -0000 On Tue, 30 Oct 2018 at 10:17, Michael Tuexen wrote: > > > On 29. Oct 2018, at 22:08, Alex Richardson wrote: > > > > Author: arichardson > > Date: Mon Oct 29 21:08:02 2018 > > New Revision: 339876 > > URL: https://svnweb.freebsd.org/changeset/base/339876 > > > > Log: > > rtld: set obj->textsize correctly > > > > With lld-generated binaries the first PT_LOAD will usually be a read-only > > segment unless you pass --no-rosegment. For those binaries the textsize is > > determined by the next PT_LOAD. To allow both LLD and bfd 2.17 binaries to > > be parsed correctly use the end of the last PT_LOAD that is marked as > > executable instead. > > > > I noticed that the value was wrong while adding some debug prints for some rtld > > changes for CHERI binaries. `obj->textsize` only seems to be used by PPC so the > > effect is untested. However, the value before was definitely wrong and the new > > result matches the phdrs. > I build kernel and world with a revision later than this on a PPC. Buildword > ends up with a world where almost all binaries are segfaulting.... Especially gdb > (but svn, ls or so all segfault). > > Best regards > Michael This is rather surprising since if anything the range of the icache flush should increase rather than decrease after this change. I can only see this causing a behaviour change if we actually need to flush more than just the executable segments. Is it possible that some binary/library contains a non-executable segment as the first PT_LOAD? Or is there some linker script that adds custom PHDRS? Alex > > > > Reviewed By: kib > > Approved By: brooks (mentor) > > Differential Revision: https://reviews.freebsd.org/D17117 > > > > Modified: > > head/libexec/rtld-elf/map_object.c > > head/libexec/rtld-elf/rtld.c > > > > Modified: head/libexec/rtld-elf/map_object.c > > ============================================================================== > > --- head/libexec/rtld-elf/map_object.c Mon Oct 29 21:03:43 2018 (r339875) > > +++ head/libexec/rtld-elf/map_object.c Mon Oct 29 21:08:02 2018 (r339876) > > @@ -93,6 +93,7 @@ map_object(int fd, const char *path, const struct stat > > Elf_Addr note_end; > > char *note_map; > > size_t note_map_len; > > + Elf_Addr text_end; > > > > hdr = get_elf_header(fd, path, sb); > > if (hdr == NULL) > > @@ -116,6 +117,7 @@ map_object(int fd, const char *path, const struct stat > > note_map = NULL; > > segs = alloca(sizeof(segs[0]) * hdr->e_phnum); > > stack_flags = RTLD_DEFAULT_STACK_PF_EXEC | PF_R | PF_W; > > + text_end = 0; > > while (phdr < phlimit) { > > switch (phdr->p_type) { > > > > @@ -130,6 +132,10 @@ map_object(int fd, const char *path, const struct stat > > path, nsegs); > > goto error; > > } > > + if ((segs[nsegs]->p_flags & PF_X) == PF_X) { > > + text_end = MAX(text_end, > > + round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_memsz)); > > + } > > break; > > > > case PT_PHDR: > > @@ -280,8 +286,7 @@ map_object(int fd, const char *path, const struct stat > > } > > obj->mapbase = mapbase; > > obj->mapsize = mapsize; > > - obj->textsize = round_page(segs[0]->p_vaddr + segs[0]->p_memsz) - > > - base_vaddr; > > + obj->textsize = text_end - base_vaddr; > > obj->vaddrbase = base_vaddr; > > obj->relocbase = mapbase - base_vaddr; > > obj->dynamic = (const Elf_Dyn *) (obj->relocbase + phdyn->p_vaddr); > > > > Modified: head/libexec/rtld-elf/rtld.c > > ============================================================================== > > --- head/libexec/rtld-elf/rtld.c Mon Oct 29 21:03:43 2018 (r339875) > > +++ head/libexec/rtld-elf/rtld.c Mon Oct 29 21:08:02 2018 (r339876) > > @@ -1390,13 +1390,15 @@ digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t e > > if (nsegs == 0) { /* First load segment */ > > obj->vaddrbase = trunc_page(ph->p_vaddr); > > obj->mapbase = obj->vaddrbase + obj->relocbase; > > - obj->textsize = round_page(ph->p_vaddr + ph->p_memsz) - > > - obj->vaddrbase; > > } else { /* Last load segment */ > > obj->mapsize = round_page(ph->p_vaddr + ph->p_memsz) - > > obj->vaddrbase; > > } > > nsegs++; > > + if ((ph->p_flags & PF_X) == PF_X) { > > + obj->textsize = MAX(obj->textsize, > > + round_page(ph->p_vaddr + ph->p_memsz) - obj->vaddrbase); > > + } > > break; > > > > case PT_DYNAMIC: > > >