1
0

xxx-origin.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. diff -Nur uClibc-git/ldso/ldso/dl-elf.c uClibc-origin/ldso/ldso/dl-elf.c
  2. --- uClibc-git/ldso/ldso/dl-elf.c 2014-02-03 12:32:56.000000000 +0100
  3. +++ uClibc-origin/ldso/ldso/dl-elf.c 2014-02-17 14:44:13.000000000 +0100
  4. @@ -133,56 +133,59 @@
  5. * in uClibc/ldso/util/ldd.c */
  6. static struct elf_resolve *
  7. search_for_named_library(const char *name, unsigned rflags, 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 (rflags && 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. -#ifdef __LDSO_SAFE_RUNPATH__
  76. - if (*mylibname == '/')
  77. -#endif
  78. - if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
  79. - return tpnt;
  80. - path_n = path+1;
  81. - }
  82. - path++;
  83. - } while (!done);
  84. + _dl_strcat(mylibname, "/");
  85. + _dl_strcat(mylibname, name);
  86. +
  87. + tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname);
  88. + if (tpnt != NULL)
  89. + return tpnt;
  90. + }
  91. return NULL;
  92. }
  93. @@ -234,7 +237,7 @@
  94. if (pnt) {
  95. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  96. _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
  97. - if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
  98. + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, tpnt->libname)) != NULL)
  99. return tpnt1;
  100. }
  101. #endif
  102. @@ -243,7 +246,7 @@
  103. /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
  104. if (_dl_library_path) {
  105. _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
  106. - if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt)) != NULL)
  107. + if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt, NULL)) != NULL)
  108. {
  109. return tpnt1;
  110. }
  111. @@ -257,7 +260,7 @@
  112. if (pnt) {
  113. pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
  114. _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
  115. - if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
  116. + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, NULL)) != NULL)
  117. return tpnt1;
  118. }
  119. #endif
  120. @@ -291,7 +294,7 @@
  121. /* Look for libraries wherever the shared library loader
  122. * was installed */
  123. _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
  124. - tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt);
  125. + tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt, NULL);
  126. if (tpnt1 != NULL)
  127. return tpnt1;
  128. #endif
  129. @@ -304,7 +307,7 @@
  130. #ifndef __LDSO_CACHE_SUPPORT__
  131. ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
  132. #endif
  133. - , rpnt);
  134. + , rpnt, NULL);
  135. if (tpnt1 != NULL)
  136. return tpnt1;
  137. diff -Nur uClibc-git/ldso/ldso/ldso.c uClibc-origin/ldso/ldso/ldso.c
  138. --- uClibc-git/ldso/ldso/ldso.c 2014-02-03 12:32:56.000000000 +0100
  139. +++ uClibc-origin/ldso/ldso/ldso.c 2014-02-17 12:34:00.000000000 +0100
  140. @@ -403,6 +403,20 @@
  141. return p - list;
  142. }
  143. +static void _dl_setup_progname(const char *argv0)
  144. +{
  145. + char image[PATH_MAX];
  146. + ssize_t s;
  147. +
  148. + s = _dl_readlink("/proc/self/exe", image, sizeof(image));
  149. + if (s > 0 && image[0] == '/') {
  150. + image[s] = 0;
  151. + _dl_progname = _dl_strdup(image);
  152. + } else if (argv0) {
  153. + _dl_progname = argv0;
  154. + }
  155. +}
  156. +
  157. void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  158. ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
  159. DL_GET_READY_TO_RUN_EXTRA_PARMS)
  160. @@ -454,9 +468,7 @@
  161. * been fixed up by now. Still no function calls outside of this
  162. * library, since the dynamic resolver is not yet ready.
  163. */
  164. - if (argv[0]) {
  165. - _dl_progname = argv[0];
  166. - }
  167. + _dl_setup_progname(argv[0]);
  168. #ifdef __DSBT__
  169. _dl_ldso_dsbt = (void *)tpnt->dynamic_info[DT_DSBT_BASE_IDX];