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