This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] New --inhibit-ldcache option to ld.so to prevent itform reading ld.so.cache


Hi,

It may sometimes be desirable to make the dynamic linker only pick up
libraries from the library path and rpath and not look at the
ld.so.cache that ldconfig generates. An example of such a use case is
the glibc testsuite where the dynamic linker must not be influenced by
any external paths or caches.

Attached patch adds a new option --inhibit-ldcache that when used,
tells the dynamic linker to not use ld.so.cache even if it is available.

To test the patch:

1) Write two simple programs, one for the binary and another for a
library:

echo "int main () {return libbar();}" > foo.c
echo "int libbar(void) {return 42;}" > bar.c
gcc -o libbar.so -shared -fPIC bar.c
gcc -o foo foo.c -L. -lbar

Now move libbar.so to a non-standard library path, add its reference
to ${prefix}/etc/ld.so.conf and run ldconfig.

Run without --inhibit-ldcache:

${prefix}/lib/ld-2.15.90.so --library-path=${prefix}/lib ./foo

Run with --inhibit-ldcache:

${prefix}/lib/ld-2.15.90.so --library-path=${prefix}/lib \
--inhibit-ldcache ./foo

Notice that the latter case throws up an error saying that libbar.so
was not found.

Regards,
Siddhesh

ChangeLog:

2012-04-06  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* elf/dl-support.c (_dl_inhibit_ldcache): New variable.
	* elf/rtld.c (_rtld_global_ro): New member
	_dl_inhibit_ldcache. (dl_main): Handle --inhibit-ldcache.
	* sysdeps/generic/ldsodefs.h (struct rtld_global_ro): New
	member _dl_inhibit_ldcache.
	* elf/dl-load.c (_dl_map_object): Use it.
---
 elf/dl-load.c              |    3 ++-
 elf/dl-support.c           |    2 ++
 elf/rtld.c                 |    9 +++++++++
 sysdeps/generic/ldsodefs.h |    3 +++
 4 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 41d48ee..7756439 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -2194,7 +2194,8 @@ _dl_map_object (struct link_map *loader, const char *name,
 
       if (fd == -1
 	  && (__builtin_expect (! (mode & __RTLD_SECURE), 1)
-	      || ! INTUSE(__libc_enable_secure)))
+	      || ! INTUSE(__libc_enable_secure))
+	  && __builtin_expect (GLRO(dl_inhibit_ldcache) == 0, 1))
 	{
 	  /* Check the list of libraries in the file /etc/ld.so.cache,
 	     for compatibility with Linux's ldconfig program.  */
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 565f342..c1ec796 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -107,6 +107,8 @@ void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
 
 size_t _dl_pagesize = EXEC_PAGESIZE;
 
+int _dl_inhibit_ldcache;
+
 unsigned int _dl_osversion;
 
 /* All known directories in sorted order.  */
diff --git a/elf/rtld.c b/elf/rtld.c
index 1cc9cf3..97e6899 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -161,6 +161,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_fpu_control = _FPU_DEFAULT,
     ._dl_pointer_guard = 1,
     ._dl_pagesize = EXEC_PAGESIZE,
+    ._dl_inhibit_ldcache = 0,
 
     /* Function pointers.  */
     ._dl_debug_printf = _dl_debug_printf,
@@ -973,6 +974,13 @@ dl_main (const ElfW(Phdr) *phdr,
 	    --_dl_argc;
 	    ++INTUSE(_dl_argv);
 	  }
+	else if (! strcmp (INTUSE(_dl_argv)[1], "--inhibit-ldcache"))
+	  {
+	    GLRO(dl_inhibit_ldcache) = 1;
+	    ++_dl_skip_args;
+	    --_dl_argc;
+	    ++INTUSE(_dl_argv);
+	  }
 	else if (! strcmp (INTUSE(_dl_argv)[1], "--library-path")
 		 && _dl_argc > 2)
 	  {
@@ -1022,6 +1030,7 @@ of this helper program; chances are you did not intend to run this program.\n\
   --list                list all dependencies and how they are resolved\n\
   --verify              verify that given object really is a dynamically linked\n\
 			object we can handle\n\
+  --inhibit-ldcache     Do not use ld.so.cache\n\
   --library-path PATH   use given PATH instead of content of the environment\n\
 			variable LD_LIBRARY_PATH\n\
   --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9955430..35cbd56 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -560,6 +560,9 @@ struct rtld_global_ro
   /* Cached value of `getpagesize ()'.  */
   EXTERN size_t _dl_pagesize;
 
+  /* Do we read from ld.so.cache?  */
+  EXTERN int _dl_inhibit_ldcache;
+
   /* Copy of the content of `_dl_main_searchlist' at startup time.  */
   EXTERN struct r_scope_elem _dl_initial_searchlist;
 
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]