aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2020-05-22 13:14:21 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2020-05-22 13:14:21 +0000
commit8a423062d0595edae32c546f96c0966299685e31 (patch)
treec44d5b7c561235312b115d0f6465af700cd1c6c2
parentc59ad6b708cb492702516986fe5f716453b4ba1d (diff)
downloadsrc-8a423062d0595.tar.gz
src-8a423062d0595.zip
MFC r361073:
Implement RTLD_DEEPBIND. PR: 246462
Notes
Notes: svn path=/stable/12/; revision=361380
-rw-r--r--include/dlfcn.h2
-rw-r--r--lib/libc/gen/dlopen.35
-rw-r--r--libexec/rtld-elf/rtld.c4
-rw-r--r--libexec/rtld-elf/rtld.h1
4 files changed, 11 insertions, 1 deletions
diff --git a/include/dlfcn.h b/include/dlfcn.h
index 76a7fa02ed74..f219879b8fa5 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -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().
diff --git a/lib/libc/gen/dlopen.3 b/lib/libc/gen/dlopen.3
index 169a657b3952..8bafb0897fd9 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -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
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 3d08fb1f9d8c..41185d1e8749 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -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 *refobj, int lo_flags,
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)) {
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index aa38724ec891..d96a072a8cec 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -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