Module Name:    src
Committed By:   christos
Date:           Thu Dec  1 14:29:15 UTC 2016

Modified Files:
        src/libexec/ld.elf_so: Makefile rtld.c symbol.c
Added Files:
        src/libexec/ld.elf_so: symbols.map

Log Message:
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.180 -r1.181 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.66 -r1.67 src/libexec/ld.elf_so/symbol.c
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/symbols.map

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.135 src/libexec/ld.elf_so/Makefile:1.136
--- src/libexec/ld.elf_so/Makefile:1.135	Fri Oct  7 15:10:03 2016
+++ src/libexec/ld.elf_so/Makefile	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.135 2016/10/07 19:10:03 christos Exp $
+#	$NetBSD: Makefile,v 1.136 2016/12/01 14:29:15 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -124,6 +124,7 @@ CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\
 COPTS.rtld.c+=	-Wno-stack-protector
 COPTS.symbol.c+=-Wno-stack-protector
 
+LDADD+=		-Wl,--version-script=${.CURDIR}/symbols.map
 LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
 .if ${MKPICLIB} != "no"
 LDADD+=		-lc_pic

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.180 src/libexec/ld.elf_so/rtld.c:1.181
--- src/libexec/ld.elf_so/rtld.c:1.180	Wed Nov 30 15:25:23 2016
+++ src/libexec/ld.elf_so/rtld.c	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -1138,14 +1138,12 @@ do_dlsym(void *handle, const char *name,
 			 * Search the dynamic linker itself, and possibly
 			 * resolve the symbol from there if it is not defined
 			 * already or weak. This is how the application links
-			 * to dynamic linker services such as dlopen. Only the
-			 * values listed in the "_rtld_exports" array can be
-			 * resolved from the dynamic linker.
+			 * to dynamic linker services such as dlopen.
 			 */
 			if (!def || ELF_ST_BIND(def->st_info) == STB_WEAK) {
 				const Elf_Sym *symp = _rtld_symlook_obj(name,
 				    hash, &_rtld_objself, flags, ventry);
-				if (symp != NULL && _rtld_is_exported(symp)) {
+				if (symp != NULL) {
 					def = symp;
 					defobj = &_rtld_objself;
 				}

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.66 src/libexec/ld.elf_so/symbol.c:1.67
--- src/libexec/ld.elf_so/symbol.c:1.66	Wed Nov 30 14:43:32 2016
+++ src/libexec/ld.elf_so/symbol.c	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $	 */
+/*	$NetBSD: symbol.c,v 1.67 2016/12/01 14:29:15 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.67 2016/12/01 14:29:15 christos Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -80,43 +80,6 @@ _rtld_donelist_check(DoneList *dlp, cons
 	return false;
 }
 
-bool
-_rtld_is_exported(const Elf_Sym *def)
-{
-	static const fptr_t _rtld_exports[] = {
-		(fptr_t)dlopen,
-		(fptr_t)dlclose,
-		(fptr_t)dlsym,
-		(fptr_t)dlvsym,
-		(fptr_t)dlerror,
-		(fptr_t)dladdr,
-		(fptr_t)dlinfo,
-		(fptr_t)dl_iterate_phdr,
-		(fptr_t)_dlauxinfo,
-#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
-		(fptr_t)_rtld_tls_allocate,
-		(fptr_t)_rtld_tls_free,
-		(fptr_t)__tls_get_addr,
-#ifdef __i386__
-		(fptr_t)___tls_get_addr,
-#endif
-#endif
-#if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
-		(fptr_t)__gnu_Unwind_Find_exidx,	/* for gcc EHABI */
-#endif
-		NULL
-	};
-	int i;
-	fptr_t value;
-
-	value = (fptr_t)(_rtld_objself.relocbase + def->st_value);
-	for (i = 0; _rtld_exports[i] != NULL; i++) {
-		if (value == _rtld_exports[i])
-			return true;
-	}
-	return false;
-}
-
 /*
  * Hash function for symbol table lookup.  Don't even think about changing
  * this.  It is specified by the System V ABI.
@@ -565,15 +528,13 @@ _rtld_symlook_default(const char *name, 
 	/*
 	 * Search the dynamic linker itself, and possibly resolve the
 	 * symbol from there.  This is how the application links to
-	 * dynamic linker services such as dlopen.  Only the values listed
-	 * in the "_rtld_exports" array can be resolved from the dynamic
-	 * linker.
+	 * dynamic linker services such as dlopen.
 	 */
 	if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) {
 		rdbg(("Search the dynamic linker itself."));
 		symp = _rtld_symlook_obj(name, hash, &_rtld_objself, flags,
 		    ventry);
-		if (symp != NULL && _rtld_is_exported(symp)) {
+		if (symp != NULL) {
 			def = symp;
 			defobj = &_rtld_objself;
 		}

Added files:

Index: src/libexec/ld.elf_so/symbols.map
diff -u /dev/null src/libexec/ld.elf_so/symbols.map:1.1
--- /dev/null	Thu Dec  1 09:29:15 2016
+++ src/libexec/ld.elf_so/symbols.map	Thu Dec  1 09:29:15 2016
@@ -0,0 +1,26 @@
+{
+  global:
+    dlopen;
+    __dlopen;
+    dlclose;
+    __dlclose;
+    dlsym;
+    __dlsym;
+    dlvsym;
+    __dlvsym;
+    dlerror;
+    __dlerror;
+    dladdr;
+    __dladdr;
+    dlinfo;
+    __dlinfo;
+    dl_iterate_phdr;
+    ____dl_iterate_phdr;
+    _dlauxinfo;
+    _rtld_tls_allocate;
+    _rtld_tls_free;
+    __tls_get_addr;
+    ___tls_get_addr;
+    __gnu_Unwind_Find_exidx;
+  local: *;
+};

Reply via email to