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