Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 1 | From de4322ef6d4dc9fc3ee9b69af1c10edbc64a66a3 Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 18 Mar 2015 01:48:24 +0000 |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 4 | Subject: [PATCH 03/29] nativesdk-glibc: Look for host system ld.so.cache as |
| 5 | well |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 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 | 16 ++++++++-------- |
| 31 | 1 file changed, 8 insertions(+), 8 deletions(-) |
| 32 | |
| 33 | diff --git a/elf/dl-load.c b/elf/dl-load.c |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 34 | index e39980fb19..565b039b23 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 35 | --- a/elf/dl-load.c |
| 36 | +++ b/elf/dl-load.c |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 37 | @@ -2160,6 +2160,14 @@ _dl_map_object (struct link_map *loader, const char *name, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | + /* try the default path. */ |
| 42 | + if (fd == -1 |
| 43 | + && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL |
| 44 | + || __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1)) |
| 45 | + && rtld_search_dirs.dirs != (void *) -1) |
| 46 | + fd = open_path (name, namelen, mode & __RTLD_SECURE, &rtld_search_dirs, |
| 47 | + &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); |
| 48 | + /* Finally try ld.so.cache */ |
| 49 | #ifdef USE_LDCONFIG |
| 50 | if (fd == -1 |
| 51 | && (__glibc_likely ((mode & __RTLD_SECURE) == 0) |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 52 | @@ -2218,14 +2226,6 @@ _dl_map_object (struct link_map *loader, const char *name, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 53 | } |
| 54 | #endif |
| 55 | |
| 56 | - /* Finally, try the default path. */ |
| 57 | - if (fd == -1 |
| 58 | - && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL |
| 59 | - || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB))) |
| 60 | - && rtld_search_dirs.dirs != (void *) -1) |
| 61 | - fd = open_path (name, namelen, mode, &rtld_search_dirs, |
| 62 | - &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); |
| 63 | - |
| 64 | /* Add another newline when we are tracing the library loading. */ |
| 65 | if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_LIBS)) |
| 66 | _dl_debug_printf ("\n"); |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame^] | 67 | -- |
| 68 | 2.27.0 |
| 69 | |