Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jan 2015 09:22:18 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r276908 - in stable/10: lib/libc/gen libexec/rtld-elf sys/sys
Message-ID:  <201501100922.t0A9MI86028561@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Jan 10 09:22:17 2015
New Revision: 276908
URL: https://svnweb.freebsd.org/changeset/base/276908

Log:
  MFC r276627:
  Add rtld private interface for dso to detect dynamic loading
  vs. static linking.

Modified:
  stable/10/lib/libc/gen/Symbol.map
  stable/10/lib/libc/gen/dlfcn.c
  stable/10/libexec/rtld-elf/Symbol.map
  stable/10/libexec/rtld-elf/rtld.c
  stable/10/libexec/rtld-elf/rtld.h
  stable/10/sys/sys/link_elf.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/Symbol.map
==============================================================================
--- stable/10/lib/libc/gen/Symbol.map	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/lib/libc/gen/Symbol.map	Sat Jan 10 09:22:17 2015	(r276908)
@@ -483,6 +483,7 @@ FBSDprivate_1.0 {
 	_rtld_atfork_post;
 	_rtld_error;		/* for private use */
 	_rtld_get_stack_prot;
+	_rtld_is_dlopened;
 	_rtld_thread_init;	/* for private use */
 	__elf_phdr_match_addr;
 	_err;

Modified: stable/10/lib/libc/gen/dlfcn.c
==============================================================================
--- stable/10/lib/libc/gen/dlfcn.c	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/lib/libc/gen/dlfcn.c	Sat Jan 10 09:22:17 2015	(r276908)
@@ -233,3 +233,10 @@ _rtld_get_stack_prot(void)
 	return (PROT_EXEC | PROT_READ | PROT_WRITE);
 }
 
+#pragma weak _rtld_is_dlopened
+int
+_rtld_is_dlopened(void *arg)
+{
+
+	return (0);
+}

Modified: stable/10/libexec/rtld-elf/Symbol.map
==============================================================================
--- stable/10/libexec/rtld-elf/Symbol.map	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/libexec/rtld-elf/Symbol.map	Sat Jan 10 09:22:17 2015	(r276908)
@@ -30,5 +30,6 @@ FBSDprivate_1.0 {
     _rtld_atfork_post;
     _rtld_addr_phdr;
     _rtld_get_stack_prot;
+    _rtld_is_dlopened;
     _r_debug_postinit;
 };

Modified: stable/10/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/10/libexec/rtld-elf/rtld.c	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/libexec/rtld-elf/rtld.c	Sat Jan 10 09:22:17 2015	(r276908)
@@ -2149,6 +2149,7 @@ do_load_object(int fd, const char *name,
 	return (NULL);
     }
 
+    obj->dlopened = (flags & RTLD_LO_DLOPEN) != 0;
     *obj_tail = obj;
     obj_tail = &obj->next;
     obj_count++;
@@ -4752,6 +4753,27 @@ _rtld_get_stack_prot(void)
 	return (stack_prot);
 }
 
+int
+_rtld_is_dlopened(void *arg)
+{
+	Obj_Entry *obj;
+	RtldLockState lockstate;
+	int res;
+
+	rlock_acquire(rtld_bind_lock, &lockstate);
+	obj = dlcheck(arg);
+	if (obj == NULL)
+		obj = obj_from_addr(arg);
+	if (obj == NULL) {
+		_rtld_error("No shared object contains address");
+		lock_release(rtld_bind_lock, &lockstate);
+		return (-1);
+	}
+	res = obj->dlopened ? 1 : 0;
+	lock_release(rtld_bind_lock, &lockstate);
+	return (res);
+}
+
 static void
 map_stacks_exec(RtldLockState *lockstate)
 {

Modified: stable/10/libexec/rtld-elf/rtld.h
==============================================================================
--- stable/10/libexec/rtld-elf/rtld.h	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/libexec/rtld-elf/rtld.h	Sat Jan 10 09:22:17 2015	(r276908)
@@ -272,6 +272,7 @@ typedef struct Struct_Obj_Entry {
     bool crt_no_init : 1;	/* Object' crt does not call _init/_fini */
     bool valid_hash_sysv : 1;	/* A valid System V hash hash tag is available */
     bool valid_hash_gnu : 1;	/* A valid GNU hash tag is available */
+    bool dlopened : 1;		/* dlopen()-ed (vs. load statically) */
 
     struct link_map linkmap;	/* For GDB and dlinfo() */
     Objlist dldags;		/* Object belongs to these dlopened DAGs (%) */

Modified: stable/10/sys/sys/link_elf.h
==============================================================================
--- stable/10/sys/sys/link_elf.h	Sat Jan 10 08:28:50 2015	(r276907)
+++ stable/10/sys/sys/link_elf.h	Sat Jan 10 09:22:17 2015	(r276908)
@@ -94,6 +94,7 @@ typedef int (*__dl_iterate_hdr_callback)
 extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void *);
 int _rtld_addr_phdr(const void *, struct dl_phdr_info *);
 int _rtld_get_stack_prot(void);
+int _rtld_is_dlopened(void *);
 
 #ifdef __ARM_EABI__
 void * dl_unwind_find_exidx(const void *, int *);



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