Index: contrib/mdocml/lib.in =================================================================== --- contrib/mdocml/lib.in +++ contrib/mdocml/lib.in @@ -46,6 +46,7 @@ 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)") Index: lib/Makefile =================================================================== --- lib/Makefile +++ lib/Makefile @@ -40,6 +40,7 @@ libdevctl \ libdevinfo \ libdevstat \ + ${_libdl} \ libdwarf \ libedit \ libevent \ @@ -183,6 +184,10 @@ _librtld_db= librtld_db .endif +.if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mfilter} +_libdl= libdl +.endif + SUBDIR.${MK_OPENSSL}+= libmp SUBDIR.${MK_PMC}+= libpmc SUBDIR.${MK_RADIUS_SUPPORT}+= libradius Index: lib/libc/gen/dlfcn.c =================================================================== --- lib/libc/gen/dlfcn.c +++ lib/libc/gen/dlfcn.c @@ -27,6 +27,8 @@ #include __FBSDID("$FreeBSD$"); +#if !defined(IN_LIBDL) || defined(PIC) + /* * Linkage to services provided by the dynamic linker. */ @@ -157,6 +159,7 @@ _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 @@ } phdr_info.dlpi_adds = 1; } +#endif #pragma weak dl_iterate_phdr int @@ -199,11 +203,15 @@ 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 @@ return (0); } + +#endif /* !defined(IN_LIBDL) || defined(PIC) */ Index: lib/libc/gen/dlopen.3 =================================================================== --- lib/libc/gen/dlopen.3 +++ lib/libc/gen/dlopen.3 @@ -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 @@ -377,6 +377,14 @@ 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 compatibility with object code compiled from the C language. Index: lib/libdl/Makefile =================================================================== --- /dev/null +++ lib/libdl/Makefile @@ -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 Index: lib/libdl/Symbol.map =================================================================== --- /dev/null +++ lib/libdl/Symbol.map @@ -0,0 +1,20 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.0 { + dladdr; + dlclose; + dlerror; + dlfunc; + dlopen; + dlsym; + dlvsym; + dlinfo; + dl_iterate_phdr; +}; + + +FBSD_1.3 { + fdlopen; +}; Index: share/mk/bsd.libnames.mk =================================================================== --- share/mk/bsd.libnames.mk +++ share/mk/bsd.libnames.mk @@ -56,6 +56,7 @@ 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 Index: share/mk/bsd.linker.mk =================================================================== --- share/mk/bsd.linker.mk +++ share/mk/bsd.linker.mk @@ -70,6 +70,9 @@ .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 Index: share/mk/src.libnames.mk =================================================================== --- share/mk/src.libnames.mk +++ share/mk/src.libnames.mk @@ -88,6 +88,7 @@ devinfo \ devstat \ dialog \ + dl \ dpv \ dtrace \ dwarf \