From owner-svn-src-head@freebsd.org Wed Nov 23 20:21:54 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C0E44C50F8E; Wed, 23 Nov 2016 20:21:54 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 773A81EC0; Wed, 23 Nov 2016 20:21:54 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uANKLrZF026017; Wed, 23 Nov 2016 20:21:53 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uANKLrkC026015; Wed, 23 Nov 2016 20:21:53 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201611232021.uANKLrkC026015@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Wed, 23 Nov 2016 20:21:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309068 - in head/libexec/rtld-elf: . mips X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Nov 2016 20:21:54 -0000 Author: jhb Date: Wed Nov 23 20:21:53 2016 New Revision: 309068 URL: https://svnweb.freebsd.org/changeset/base/309068 Log: Fix _mips_rtld_bind() to handle ELF filters. MIPS does not use the common _rtld_bind() to handle runtime binding. Instead, it uses a private _mips_rtld_bind(). Update _mips_rtld_bind() to include the changes made to _rtld_bind() in r216695 and r218476 to support upgrading the read-locked rtld_bind_lock to a write lock when an object with a filter is encountered. While here, add a 'where' variable to track the location of the fixup in the GOT to make the code flow more closely match _rtld_bind(). Reviewed by: kib Obtained from: CheriBSD Sponsored by: DARPA / AFRL Differential Revision: https://reviews.freebsd.org/D8625 Modified: head/libexec/rtld-elf/mips/reloc.c head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/mips/reloc.c ============================================================================== --- head/libexec/rtld-elf/mips/reloc.c Wed Nov 23 19:50:12 2016 (r309067) +++ head/libexec/rtld-elf/mips/reloc.c Wed Nov 23 20:21:53 2016 (r309068) @@ -240,10 +240,17 @@ _mips_rtld_bind(Obj_Entry *obj, Elf_Size Elf_Addr *got = obj->pltgot; const Elf_Sym *def; const Obj_Entry *defobj; + Elf_Addr *where; Elf_Addr target; + RtldLockState lockstate; + rlock_acquire(rtld_bind_lock, &lockstate); + if (sigsetjmp(lockstate.env, 0) != 0) + lock_upgrade(rtld_bind_lock, &lockstate); + + where = &got[obj->local_gotno + reloff - obj->gotsym]; def = find_symdef(reloff, obj, &defobj, SYMLOOK_IN_PLT, NULL, - NULL); + &lockstate); if (def == NULL) rtld_die(); @@ -251,9 +258,9 @@ _mips_rtld_bind(Obj_Entry *obj, Elf_Size dbg("bind now/fixup at %s sym # %jd in %s --> was=%p new=%p", obj->path, (intmax_t)reloff, defobj->strtab + def->st_name, - (void *)got[obj->local_gotno + reloff - obj->gotsym], - (void *)target); - got[obj->local_gotno + reloff - obj->gotsym] = target; + (void *)*where, (void *)target); + *where = target; + lock_release(rtld_bind_lock, &lockstate); return (Elf_Addr)target; } Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Wed Nov 23 19:50:12 2016 (r309067) +++ head/libexec/rtld-elf/rtld.c Wed Nov 23 20:21:53 2016 (r309068) @@ -695,6 +695,10 @@ rtld_resolve_ifunc(const Obj_Entry *obj, return ((void *)target); } +/* + * NB: MIPS uses a private version of this function (_mips_rtld_bind). + * Changes to this function should be applied there as well. + */ Elf_Addr _rtld_bind(Obj_Entry *obj, Elf_Size reloff) {