Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Jul 2017 14:59:21 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320872 - in head: contrib/mdocml lib lib/libc/gen lib/libdl share/mk
Message-ID:  <201707101459.v6AExL7N039212@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Jul 10 14:59:21 2017
New Revision: 320872
URL: https://svnweb.freebsd.org/changeset/base/320872

Log:
  Provide libdl.
  
  Create libdl.so.1 as a filter for libc.so.7 which exports public dl*
  functions. The functions are resolved from the rtld instead, the goal
  of creating library is to avoid errors from the static linker due to
  missed libdl. For static binaries, an empty .o is compiled into
  libdl.a so that static binaries still get dl stubs from libc.a.
  
  Right now lld cannot create filter objects, disable libdl on arm64
  when binutils are not used.
  
  Reviewed by:	bdrewery, dim (previos version); emaste
  Exp run:	PR 220525, done by antoine
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 month
  Differential revision:	https://reviews.freebsd.org/D11504

Added:
  head/lib/libdl/
  head/lib/libdl/Makefile   (contents, props changed)
  head/lib/libdl/Symbol.map   (contents, props changed)
Modified:
  head/contrib/mdocml/lib.in
  head/lib/Makefile
  head/lib/libc/gen/dlfcn.c
  head/lib/libc/gen/dlopen.3
  head/share/mk/bsd.libnames.mk
  head/share/mk/bsd.linker.mk
  head/share/mk/src.libnames.mk

Modified: head/contrib/mdocml/lib.in
==============================================================================
--- head/contrib/mdocml/lib.in	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/contrib/mdocml/lib.in	Mon Jul 10 14:59:21 2017	(r320872)
@@ -46,6 +46,7 @@ LINE("libdevctl",	"Device Control Library (libdevctl, 
 LINE("libdevinfo",	"Device and Resource Information Utility Library (libdevinfo, \\-ldevinfo)")
 LINE("libdevstat",	"Device Statistics Library (libdevstat, \\-ldevstat)")
 LINE("libdisk",		"Interface to Slice and Partition Labels Library (libdisk, \\-ldisk)")
+LINE("libdl",		"Dynamic Linker Services Filter (libdl, \\-ldl)")
 LINE("libdm",		"Device Mapper Library (libdm, \\-ldm)")
 LINE("libdwarf",	"DWARF Access Library (libdwarf, \\-ldwarf)")
 LINE("libedit",		"Command Line Editor Library (libedit, \\-ledit)")

Modified: head/lib/Makefile
==============================================================================
--- head/lib/Makefile	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/lib/Makefile	Mon Jul 10 14:59:21 2017	(r320872)
@@ -40,6 +40,7 @@ SUBDIR=	${SUBDIR_BOOTSTRAP} \
 	libdevctl \
 	libdevinfo \
 	libdevstat \
+	${_libdl} \
 	libdwarf \
 	libedit \
 	libevent \
@@ -181,6 +182,10 @@ SUBDIR.${MK_BHYVE}+=	libvmmapi
 .if ${MACHINE_CPUARCH} != "sparc64"
 _libproc=	libproc
 _librtld_db=	librtld_db
+.endif
+
+.if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mfilter}
+_libdl=		libdl
 .endif
 
 SUBDIR.${MK_OPENSSL}+=	libmp

Modified: head/lib/libc/gen/dlfcn.c
==============================================================================
--- head/lib/libc/gen/dlfcn.c	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/lib/libc/gen/dlfcn.c	Mon Jul 10 14:59:21 2017	(r320872)
@@ -27,6 +27,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#if !defined(IN_LIBDL) || defined(PIC)
+
 /*
  * Linkage to services provided by the dynamic linker.
  */
@@ -157,6 +159,7 @@ _rtld_thread_init(void *li __unused)
 	_rtld_error(sorry);
 }
 
+#ifndef IN_LIBDL
 static pthread_once_t dl_phdr_info_once = PTHREAD_ONCE_INIT;
 static struct dl_phdr_info phdr_info;
 
@@ -192,6 +195,7 @@ dl_init_phdr_info(void)
 	}
 	phdr_info.dlpi_adds = 1;
 }
+#endif
 
 #pragma weak dl_iterate_phdr
 int
@@ -199,11 +203,15 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *,
     void *data __unused)
 {
 
+#ifndef IN_LIBDL
 	__init_elf_aux_vector();
 	if (__elf_aux_vector == NULL)
 		return (1);
 	_once(&dl_phdr_info_once, dl_init_phdr_info);
 	return (callback(&phdr_info, sizeof(phdr_info), data));
+#else
+	return (0);
+#endif
 }
 
 #pragma weak fdlopen
@@ -251,3 +259,5 @@ _rtld_is_dlopened(void *arg __unused)
 
 	return (0);
 }
+
+#endif /* !defined(IN_LIBDL) || defined(PIC) */

Modified: head/lib/libc/gen/dlopen.3
==============================================================================
--- head/lib/libc/gen/dlopen.3	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/lib/libc/gen/dlopen.3	Mon Jul 10 14:59:21 2017	(r320872)
@@ -32,7 +32,7 @@
 .\" @(#) dlopen.3 1.6 90/01/31 SMI
 .\" $FreeBSD$
 .\"
-.Dd February 14, 2015
+.Dd July 7, 2017
 .Dt DLOPEN 3
 .Os
 .Sh NAME
@@ -376,6 +376,14 @@ option to
 .Xr ld 1
 for symbols defined in the executable to become visible to
 .Fn dlsym .
+.Pp
+Other ELF platforms require linking with
+.Lb libdl
+to provide
+.Fn dlopen
+and other functions.
+.Fx
+does not require linking with the library, but supports it for compatibility.
 .Pp
 In previous implementations, it was necessary to prepend an underscore
 to all external symbols in order to gain symbol

Added: head/lib/libdl/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libdl/Makefile	Mon Jul 10 14:59:21 2017	(r320872)
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+LIB=dl
+SHLIB_MAJOR=1
+
+.PATH:	${SRCTOP}/lib/libc/gen
+CFLAGS+=-I${SRCTOP}/lib/libc/include
+CFLAGS+=-DIN_LIBDL
+LDFLAGS+=-Wl,-F,libc.so.7
+VERSION_DEF=${SRCTOP}/lib/libc/Versions.def
+SYMBOL_MAPS=${.CURDIR}/Symbol.map
+
+SRCS =	dlfcn.c
+
+.include <bsd.lib.mk>

Added: head/lib/libdl/Symbol.map
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libdl/Symbol.map	Mon Jul 10 14:59:21 2017	(r320872)
@@ -0,0 +1,20 @@
+/*
+ * $FreeBSD$
+ */
+
+FBSD_1.0 {
+	dladdr;
+	dlclose;
+	dlerror;
+	dlfunc;
+	dlopen;
+	dlsym;
+	dlvsym;
+	dlinfo;
+	dl_iterate_phdr;
+};
+
+
+FBSD_1.3 {
+	fdlopen;
+};

Modified: head/share/mk/bsd.libnames.mk
==============================================================================
--- head/share/mk/bsd.libnames.mk	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/share/mk/bsd.libnames.mk	Mon Jul 10 14:59:21 2017	(r320872)
@@ -56,6 +56,7 @@ LIBDEVDCTL?=	${LIBDESTDIR}${LIBDIR_BASE}/libdevdctl.a
 LIBDEVINFO?=	${LIBDESTDIR}${LIBDIR_BASE}/libdevinfo.a
 LIBDEVSTAT?=	${LIBDESTDIR}${LIBDIR_BASE}/libdevstat.a
 LIBDIALOG?=	${LIBDESTDIR}${LIBDIR_BASE}/libdialog.a
+LIBDL?=		${LIBDESTDIR}${LIBDIR_BASE}/libdl.a
 LIBDNS?=	${LIBDESTDIR}${LIBDIR_BASE}/libdns.a
 LIBDPV?=	${LIBDESTDIR}${LIBDIR_BASE}/libdpv.a
 LIBDTRACE?=	${LIBDESTDIR}${LIBDIR_BASE}/libdtrace.a

Modified: head/share/mk/bsd.linker.mk
==============================================================================
--- head/share/mk/bsd.linker.mk	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/share/mk/bsd.linker.mk	Mon Jul 10 14:59:21 2017	(r320872)
@@ -70,6 +70,9 @@ ${X_}LINKER_FEATURES=
 .if ${${X_}LINKER_TYPE} != "bfd" || ${${X_}LINKER_VERSION} > 21750
 ${X_}LINKER_FEATURES+=	build-id
 .endif
+.if ${${X_}LINKER_TYPE} == "bfd"
+${X_}LINKER_FEATURES+=	filter
+.endif
 .endif
 .else
 # Use LD's values

Modified: head/share/mk/src.libnames.mk
==============================================================================
--- head/share/mk/src.libnames.mk	Mon Jul 10 12:52:18 2017	(r320871)
+++ head/share/mk/src.libnames.mk	Mon Jul 10 14:59:21 2017	(r320872)
@@ -88,6 +88,7 @@ _LIBRARIES=	\
 		devinfo \
 		devstat \
 		dialog \
+		dl \
 		dpv \
 		dtrace \
 		dwarf \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707101459.v6AExL7N039212>