From owner-svn-src-all@freebsd.org Fri May 22 13:14:22 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9B80E2C8964; Fri, 22 May 2020 13:14:22 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49T6QQ3gBZz4JMb; Fri, 22 May 2020 13:14:22 +0000 (UTC) (envelope-from kib@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 788F61F0CF; Fri, 22 May 2020 13:14:22 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04MDEMXR077609; Fri, 22 May 2020 13:14:22 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04MDELfK077605; Fri, 22 May 2020 13:14:21 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202005221314.04MDELfK077605@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 22 May 2020 13:14:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361380 - in stable/12: include lib/libc/gen libexec/rtld-elf X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/12: include lib/libc/gen libexec/rtld-elf X-SVN-Commit-Revision: 361380 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 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: Fri, 22 May 2020 13:14:22 -0000 Author: kib Date: Fri May 22 13:14:21 2020 New Revision: 361380 URL: https://svnweb.freebsd.org/changeset/base/361380 Log: MFC r361073: Implement RTLD_DEEPBIND. PR: 246462 Modified: stable/12/include/dlfcn.h stable/12/lib/libc/gen/dlopen.3 stable/12/libexec/rtld-elf/rtld.c stable/12/libexec/rtld-elf/rtld.h Directory Properties: stable/12/ (props changed) Modified: stable/12/include/dlfcn.h ============================================================================== --- stable/12/include/dlfcn.h Fri May 22 13:13:34 2020 (r361379) +++ stable/12/include/dlfcn.h Fri May 22 13:14:21 2020 (r361380) @@ -47,6 +47,8 @@ #define RTLD_TRACE 0x200 /* Trace loaded objects and exit. */ #define RTLD_NODELETE 0x01000 /* Do not remove members. */ #define RTLD_NOLOAD 0x02000 /* Do not load if not already loaded. */ +#define RTLD_DEEPBIND 0x04000 /* Put symbols from the dso ahead of + the global list */ /* * Request arguments for dlinfo(). Modified: stable/12/lib/libc/gen/dlopen.3 ============================================================================== --- stable/12/lib/libc/gen/dlopen.3 Fri May 22 13:13:34 2020 (r361379) +++ stable/12/lib/libc/gen/dlopen.3 Fri May 22 13:14:21 2020 (r361380) @@ -32,7 +32,7 @@ .\" @(#) dlopen.3 1.6 90/01/31 SMI .\" $FreeBSD$ .\" -.Dd January 2, 2019 +.Dd May 14, 2020 .Dt DLOPEN 3 .Os .Sh NAME @@ -162,6 +162,9 @@ the process address space, otherwise is returned. Other mode flags may be specified, which will be applied for promotion for the found object. +.It Dv RTLD_DEEPBIND +Symbols from the loaded library are put before global symbols when +resolving symbolic references originated from the library. .El .Pp If Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Fri May 22 13:13:34 2020 (r361379) +++ stable/12/libexec/rtld-elf/rtld.c Fri May 22 13:14:21 2020 (r361380) @@ -3319,6 +3319,8 @@ rtld_dlopen(const char *name, int fd, int mode) lo_flags |= RTLD_LO_NODELETE; if (mode & RTLD_NOLOAD) lo_flags |= RTLD_LO_NOLOAD; + if (mode & RTLD_DEEPBIND) + lo_flags |= RTLD_LO_DEEPBIND; if (ld_tracing != NULL) lo_flags |= RTLD_LO_TRACE | RTLD_LO_IGNSTLS; @@ -3370,6 +3372,8 @@ dlopen_object(const char *name, int fd, Obj_Entry *ref if (globallist_next(old_obj_tail) != NULL) { /* We loaded something new. */ assert(globallist_next(old_obj_tail) == obj); + if ((lo_flags & RTLD_LO_DEEPBIND) != 0) + obj->symbolic = true; result = 0; if ((lo_flags & (RTLD_LO_EARLY | RTLD_LO_IGNSTLS)) == 0 && obj->static_tls && !allocate_tls_offset(obj)) { Modified: stable/12/libexec/rtld-elf/rtld.h ============================================================================== --- stable/12/libexec/rtld-elf/rtld.h Fri May 22 13:13:34 2020 (r361379) +++ stable/12/libexec/rtld-elf/rtld.h Fri May 22 13:14:21 2020 (r361380) @@ -310,6 +310,7 @@ TAILQ_HEAD(obj_entry_q, Struct_Obj_Entry); #define RTLD_LO_EARLY 0x20 /* Do not call ctors, postpone it to the initialization during the image start. */ #define RTLD_LO_IGNSTLS 0x40 /* Do not allocate static TLS */ +#define RTLD_LO_DEEPBIND 0x80 /* Force symbolic for this object */ /* * Symbol cache entry used during relocation to avoid multiple lookups