0003-nativesdk-glibc-Look-for-host-system-ld.so.cache-as-.patch 2.5 KB

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