origin.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. diff -Nur uClibc-0.9.33.2.orig/ldso/ldso/dl-elf.c uClibc-0.9.33.2/ldso/ldso/dl-elf.c
  2. --- uClibc-0.9.33.2.orig/ldso/ldso/dl-elf.c 2012-05-15 09:20:09.000000000 +0200
  3. +++ uClibc-0.9.33.2/ldso/ldso/dl-elf.c 2013-11-15 16:04:24.000000000 +0100
  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, 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. - if ((tpnt = _dl_load_elf_shared_library(rflags, 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(rflags, 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, rflags, pnt, rpnt)) != NULL)
  95. + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, tpnt->libname)) != NULL)
  96. return tpnt1;
  97. }
  98. #endif
  99. @@ -240,7 +246,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, rflags, _dl_library_path, rpnt)) != NULL)
  104. + if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt, NULL)) != NULL)
  105. {
  106. return tpnt1;
  107. }
  108. @@ -254,7 +260,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, rflags, pnt, rpnt)) != NULL)
  113. + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, NULL)) != NULL)
  114. return tpnt1;
  115. }
  116. #endif
  117. @@ -288,7 +294,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, rflags, _dl_ldsopath, rpnt);
  122. + tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt, NULL);
  123. if (tpnt1 != NULL)
  124. return tpnt1;
  125. #endif
  126. @@ -301,7 +307,7 @@
  127. #ifndef __LDSO_CACHE_SUPPORT__
  128. ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
  129. #endif
  130. - , rpnt);
  131. + , rpnt, NULL);
  132. if (tpnt1 != NULL)
  133. return tpnt1;
  134. diff -Nur uClibc-0.9.33.2.orig/ldso/ldso/ldso.c uClibc-0.9.33.2/ldso/ldso/ldso.c
  135. --- uClibc-0.9.33.2.orig/ldso/ldso/ldso.c 2012-05-15 09:20:09.000000000 +0200
  136. +++ uClibc-0.9.33.2/ldso/ldso/ldso.c 2013-11-15 15:49:00.000000000 +0100
  137. @@ -409,6 +409,20 @@
  138. return p - list;
  139. }
  140. +static void _dl_setup_progname(const char *argv0)
  141. +{
  142. + char image[PATH_MAX];
  143. + ssize_t s;
  144. +
  145. + s = _dl_readlink("/proc/self/exe", image, sizeof(image));
  146. + if (s > 0 && image[0] == '/') {
  147. + image[s] = 0;
  148. + _dl_progname = _dl_strdup(image);
  149. + } else if (argv0) {
  150. + _dl_progname = argv0;
  151. + }
  152. +}
  153. +
  154. void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
  155. ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
  156. DL_GET_READY_TO_RUN_EXTRA_PARMS)
  157. @@ -460,9 +474,7 @@
  158. * been fixed up by now. Still no function calls outside of this
  159. * library, since the dynamic resolver is not yet ready.
  160. */
  161. - if (argv[0]) {
  162. - _dl_progname = argv[0];
  163. - }
  164. + _dl_setup_progname(argv[0]);
  165. #ifndef __LDSO_STANDALONE_SUPPORT__
  166. if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {