rpath-origin.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. diff -Nur uClibc-0.9.32.orig//ldso/ldso/dl-elf.c uClibc-0.9.32/ldso/ldso/dl-elf.c
  2. --- uClibc-0.9.32.orig//ldso/ldso/dl-elf.c 2011-06-08 21:35:20.000000000 +0200
  3. +++ uClibc-0.9.32/ldso/ldso/dl-elf.c 2011-08-09 11:19:18.325314589 +0200
  4. @@ -133,53 +133,59 @@
  5. * in uClibc/ldso/util/ldd.c */
  6. static struct elf_resolve *
  7. search_for_named_library(const char *name, int secure, const char *path_list,
  8. - struct dyn_elf **rpnt)
  9. + struct dyn_elf **rpnt, const char *origin)
  10. {
  11. - char *path, *path_n, *mylibname;
  12. + char *mylibname;
  13. + const char *p, *pn;
  14. struct elf_resolve *tpnt;
  15. - int done;
  16. + int plen;
  17. if (path_list==NULL)
  18. return NULL;
  19. - /* We need a writable copy of this string, but we don't
  20. - * need this allocated permanently since we don't want
  21. - * to leak memory, so use alloca to put path on the stack */
  22. - done = _dl_strlen(path_list);
  23. - path = alloca(done + 1);
  24. -
  25. /* another bit of local storage */
  26. mylibname = alloca(2050);
  27. - _dl_memcpy(path, path_list, done+1);
  28. -
  29. /* Unlike ldd.c, don't bother to eliminate double //s */
  30. /* Replace colons with zeros in path_list */
  31. /* : at the beginning or end of path maps to CWD */
  32. /* :: anywhere maps CWD */
  33. /* "" maps to CWD */
  34. - done = 0;
  35. - path_n = path;
  36. - do {
  37. - if (*path == 0) {
  38. - *path = ':';
  39. - done = 1;
  40. + for (p = path_list; p != NULL; p = pn) {
  41. + pn = _dl_strchr(p + 1, ':');
  42. + if (pn != NULL) {
  43. + plen = pn - p;
  44. + pn++;
  45. + } else
  46. + plen = _dl_strlen(p);
  47. +
  48. + if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) {
  49. + int olen;
  50. + if (secure && plen != 7)
  51. + continue;
  52. + if (origin == NULL)
  53. + continue;
  54. + for (olen = _dl_strlen(origin) - 1; olen >= 0 && origin[olen] != '/'; olen--)
  55. + ;
  56. + if (olen <= 0)
  57. + continue;
  58. + _dl_memcpy(&mylibname[0], origin, olen);
  59. + _dl_memcpy(&mylibname[olen], p + 7, plen - 7);
  60. + mylibname[olen + plen - 7] = 0;
  61. + } else if (plen != 0) {
  62. + _dl_memcpy(mylibname, p, plen);
  63. + mylibname[plen] = 0;
  64. + } else {
  65. + _dl_strcpy(mylibname, ".");
  66. }
  67. - if (*path == ':') {
  68. - *path = 0;
  69. - if (*path_n)
  70. - _dl_strcpy(mylibname, path_n);
  71. - else
  72. - _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
  73. - _dl_strcat(mylibname, "/");
  74. - _dl_strcat(mylibname, name);
  75. - if ((tpnt = _dl_load_elf_shared_library(secure, rpnt, mylibname)) != NULL)
  76. - return tpnt;
  77. - path_n = path+1;
  78. - }
  79. - path++;
  80. - } while (!done);
  81. + _dl_strcat(mylibname, "/");
  82. + _dl_strcat(mylibname, name);
  83. +
  84. + tpnt = _dl_load_elf_shared_library(secure, rpnt, mylibname);
  85. + if (tpnt != NULL)
  86. + return tpnt;
  87. + }
  88. return NULL;
  89. }
  90. @@ -231,7 +237,7 @@
  91. if (pnt) {
  92. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  93. _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
  94. - if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL)
  95. + if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt, tpnt->libname)) != NULL)
  96. return tpnt1;
  97. }
  98. #endif
  99. @@ -239,7 +245,7 @@
  100. /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
  101. if (_dl_library_path) {
  102. _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
  103. - if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt)) != NULL)
  104. + if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt, NULL)) != NULL)
  105. {
  106. return tpnt1;
  107. }
  108. @@ -253,7 +259,7 @@
  109. if (pnt) {
  110. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  111. _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
  112. - if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL)
  113. + if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt, NULL)) != NULL)
  114. return tpnt1;
  115. }
  116. #endif
  117. @@ -287,7 +293,7 @@
  118. /* Look for libraries wherever the shared library loader
  119. * was installed */
  120. _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
  121. - tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt);
  122. + tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt, NULL);
  123. if (tpnt1 != NULL)
  124. return tpnt1;
  125. @@ -300,7 +306,7 @@
  126. #ifndef __LDSO_CACHE_SUPPORT__
  127. ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
  128. #endif
  129. - , rpnt);
  130. + , rpnt, NULL);
  131. if (tpnt1 != NULL)
  132. return tpnt1;
  133. diff -Nur uClibc-0.9.32.orig//ldso/ldso/ldso.c uClibc-0.9.32/ldso/ldso/ldso.c
  134. --- uClibc-0.9.32.orig//ldso/ldso/ldso.c 2011-06-08 21:35:20.000000000 +0200
  135. +++ uClibc-0.9.32/ldso/ldso/ldso.c 2011-08-09 11:15:04.135386129 +0200
  136. @@ -272,6 +272,20 @@
  137. }
  138. }
  139. +static void _dl_setup_progname(const char *argv0)
  140. +{
  141. + char image[PATH_MAX];
  142. + ssize_t s;
  143. +
  144. + s = _dl_readlink("/proc/self/exe", image, sizeof(image));
  145. + if (s > 0 && image[0] == '/') {
  146. + image[s] = 0;
  147. + _dl_progname = _dl_strdup(image);
  148. + } else if (argv0) {
  149. + _dl_progname = argv0;
  150. + }
  151. +}
  152. +
  153. void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  154. ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp,
  155. char **argv
  156. @@ -321,9 +335,7 @@
  157. * been fixed up by now. Still no function calls outside of this
  158. * library, since the dynamic resolver is not yet ready.
  159. */
  160. - if (argv[0]) {
  161. - _dl_progname = argv[0];
  162. - }
  163. + _dl_setup_progname(argv[0]);
  164. if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
  165. _dl_dprintf(_dl_debug_file, "Standalone execution is not supported yet\n");