Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From 0876fea1b5b26da84f298714a2e23ba696607dba Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 18 Mar 2015 01:48:24 +0000 |
| 4 | Subject: [PATCH 01/27] nativesdk-glibc: Look for host system ld.so.cache as |
| 5 | well |
| 6 | |
| 7 | Upstream-Status: Inappropriate [embedded specific] |
| 8 | |
| 9 | The default lib search path order is: |
| 10 | |
| 11 | 1) LD_LIBRARY_PATH |
| 12 | 2) RPATH from the binary |
| 13 | 3) ld.so.cache |
| 14 | 4) default search paths embedded in the linker |
| 15 | |
| 16 | For nativesdk binaries which are being used alongside binaries on a host system, we |
| 17 | need the search paths to firstly search the shipped nativesdk libs but then also |
| 18 | cover the host system. For example we want the host system's libGL and this may be |
| 19 | in a non-standard location like /usr/lib/mesa. The only place the location is know |
| 20 | about is in the ld.so.cache of the host system. |
| 21 | |
| 22 | Since nativesdk has a simple structure and doesn't need to use a cache itself, we |
| 23 | repurpose the cache for use as a last resort in finding host system binaries. This |
| 24 | means we need to switch the order of 3 and 4 above to make this work effectively. |
| 25 | |
| 26 | RP 14/10/2010 |
| 27 | |
| 28 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 29 | --- |
| 30 | elf/dl-load.c | 17 ++++++++--------- |
| 31 | 1 file changed, 8 insertions(+), 9 deletions(-) |
| 32 | |
| 33 | diff --git a/elf/dl-load.c b/elf/dl-load.c |
| 34 | index 0c052e4..f45085a 100644 |
| 35 | --- a/elf/dl-load.c |
| 36 | +++ b/elf/dl-load.c |
| 37 | @@ -2040,7 +2040,14 @@ _dl_map_object (struct link_map *loader, const char *name, |
| 38 | fd = open_path (name, namelen, mode, |
| 39 | &loader->l_runpath_dirs, &realname, &fb, loader, |
| 40 | LA_SER_RUNPATH, &found_other_class); |
| 41 | - |
| 42 | + /* try the default path. */ |
| 43 | + if (fd == -1 |
| 44 | + && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL |
| 45 | + || __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1)) |
| 46 | + && rtld_search_dirs.dirs != (void *) -1) |
| 47 | + fd = open_path (name, namelen, mode & __RTLD_SECURE, &rtld_search_dirs, |
| 48 | + &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); |
| 49 | + /* Finally try ld.so.cache */ |
| 50 | #ifdef USE_LDCONFIG |
| 51 | if (fd == -1 |
| 52 | && (__glibc_likely ((mode & __RTLD_SECURE) == 0) |
| 53 | @@ -2099,14 +2106,6 @@ _dl_map_object (struct link_map *loader, const char *name, |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | - /* Finally, try the default path. */ |
| 58 | - if (fd == -1 |
| 59 | - && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL |
| 60 | - || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB))) |
| 61 | - && rtld_search_dirs.dirs != (void *) -1) |
| 62 | - fd = open_path (name, namelen, mode, &rtld_search_dirs, |
| 63 | - &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); |
| 64 | - |
| 65 | /* Add another newline when we are tracing the library loading. */ |
| 66 | if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS)) |
| 67 | _dl_debug_printf ("\n"); |
| 68 | -- |
| 69 | 2.1.4 |
| 70 | |