summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch')
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch230
1 files changed, 230 insertions, 0 deletions
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch b/meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch
new file mode 100644
index 0000000000..7479ec35e1
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-ldso-limited-support-for-ORIGIN-in-rpath.patch
@@ -0,0 +1,230 @@
1From 32eaf738faafad2b16e1f3f5beb91736b3c27a3b Mon Sep 17 00:00:00 2001
2From: Junling Zheng <zhengjunling@huawei.com>
3Date: Fri, 3 Apr 2015 05:02:27 +0000
4Subject: [PATCH] ldso: limited support for $ORIGIN in rpath
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Derived from:
10http://lists.busybox.net/pipermail/uclibc/2011-March/045003.html
11
12However, the above patch introduced '_dl_strchr' in ldso/ldso/dl-elf.c,
13and caused the following undefined referencing compiling error:
14
15 | .../libdl.a(libdl.os): In function `search_for_named_library':
16 | .../dl-elf.c:156: undefined reference to `_dl_strchr'
17 | collect2: error: ld returned 1 exit status
18
19This problem would be reproduced through compiling gdb in static mode
20using uclibc.
21
22So, add the definition of '_dl_strchr' to fix it. The '_dl_strstr' is
23added as well.
24
25Upstream-Status: Submitted
26
27Signed-off-by: Timo Teräs <timo.teras at iki.fi>
28Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
29---
30 ldso/include/dl-string.h | 2 ++
31 ldso/ldso/dl-elf.c | 79 +++++++++++++++++++++++++-----------------------
32 ldso/ldso/ldso.c | 18 +++++++++--
33 3 files changed, 59 insertions(+), 40 deletions(-)
34
35diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
36index aacad10..14ae617 100644
37--- a/ldso/include/dl-string.h
38+++ b/ldso/include/dl-string.h
39@@ -204,7 +204,9 @@ static __always_inline char * _dl_get_last_path_component(char *path)
40 # define _dl_strcat strcat
41 # define _dl_strcpy strcpy
42 # define _dl_strcmp strcmp
43+# define _dl_strchr strchr
44 # define _dl_strrchr strrchr
45+# define _dl_strstr strstr
46 # define _dl_memcpy memcpy
47 # define _dl_memcmp memcmp
48 # define _dl_memset memset
49diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
50index 1b06bc1..b323c90 100644
51--- a/ldso/ldso/dl-elf.c
52+++ b/ldso/ldso/dl-elf.c
53@@ -133,56 +133,60 @@ _dl_protect_relro (struct elf_resolve *l)
54 * in uClibc/ldso/util/ldd.c */
55 static struct elf_resolve *
56 search_for_named_library(const char *name, unsigned rflags, const char *path_list,
57- struct dyn_elf **rpnt)
58+ struct dyn_elf **rpnt, const char* origin)
59 {
60- char *path, *path_n, *mylibname;
61+ char *mylibname;
62+ const char *p, *pn;
63 struct elf_resolve *tpnt;
64- int done;
65+ int plen;
66
67 if (path_list==NULL)
68 return NULL;
69
70- /* We need a writable copy of this string, but we don't
71- * need this allocated permanently since we don't want
72- * to leak memory, so use alloca to put path on the stack */
73- done = _dl_strlen(path_list);
74- path = alloca(done + 1);
75-
76 /* another bit of local storage */
77 mylibname = alloca(2050);
78
79- _dl_memcpy(path, path_list, done+1);
80-
81 /* Unlike ldd.c, don't bother to eliminate double //s */
82
83 /* Replace colons with zeros in path_list */
84 /* : at the beginning or end of path maps to CWD */
85 /* :: anywhere maps CWD */
86 /* "" maps to CWD */
87- done = 0;
88- path_n = path;
89- do {
90- if (*path == 0) {
91- *path = ':';
92- done = 1;
93+ for (p = path_list; p != NULL; p = pn) {
94+ pn = _dl_strchr(p + 1, ':');
95+ if (pn != NULL) {
96+ plen = pn - p;
97+ pn++;
98+ } else
99+ plen = _dl_strlen(p);
100+
101+ if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) {
102+ int olen;
103+ if (rflags && plen != 7)
104+ continue;
105+ if (origin == NULL)
106+ continue;
107+ for (olen = _dl_strlen(origin) - 1; olen >= 0 && origin[olen] != '/'; olen--)
108+ ;
109+ if (olen <= 0)
110+ continue;
111+ _dl_memcpy(&mylibname[0], origin, olen);
112+ _dl_memcpy(&mylibname[olen], p + 7, plen - 7);
113+ mylibname[olen + plen - 7] = 0;
114+ } else if (plen != 0) {
115+ _dl_memcpy(mylibname, p, plen);
116+ mylibname[plen] = 0;
117+ } else {
118+ _dl_strcpy(mylibname, ".");
119 }
120- if (*path == ':') {
121- *path = 0;
122- if (*path_n)
123- _dl_strcpy(mylibname, path_n);
124- else
125- _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
126- _dl_strcat(mylibname, "/");
127- _dl_strcat(mylibname, name);
128+ _dl_strcat(mylibname, "/");
129+ _dl_strcat(mylibname, name);
130 #ifdef __LDSO_SAFE_RUNPATH__
131- if (*mylibname == '/')
132+ if (*mylibname == '/')
133 #endif
134- if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
135- return tpnt;
136- path_n = path+1;
137- }
138- path++;
139- } while (!done);
140+ if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
141+ return tpnt;
142+ }
143 return NULL;
144 }
145
146@@ -234,7 +238,8 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp
147 if (pnt) {
148 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
149 _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
150- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
151+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt,
152+ tpnt->libname)) != NULL)
153 return tpnt1;
154 }
155 #endif
156@@ -243,7 +248,7 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp
157 /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
158 if (_dl_library_path) {
159 _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
160- if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt)) != NULL)
161+ if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt, NULL)) != NULL)
162 {
163 return tpnt1;
164 }
165@@ -257,7 +262,7 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp
166 if (pnt) {
167 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
168 _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
169- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
170+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, NULL)) != NULL)
171 return tpnt1;
172 }
173 #endif
174@@ -291,7 +296,7 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp
175 /* Look for libraries wherever the shared library loader
176 * was installed */
177 _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
178- tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt);
179+ tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt, NULL);
180 if (tpnt1 != NULL)
181 return tpnt1;
182 #endif
183@@ -304,7 +309,7 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp
184 #ifndef __LDSO_CACHE_SUPPORT__
185 ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
186 #endif
187- , rpnt);
188+ , rpnt, NULL);
189 if (tpnt1 != NULL)
190 return tpnt1;
191
192diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
193index 5619629..73bcc41 100644
194--- a/ldso/ldso/ldso.c
195+++ b/ldso/ldso/ldso.c
196@@ -402,6 +402,20 @@ static ptrdiff_t _dl_build_local_scope (struct elf_resolve **list,
197 p += _dl_build_local_scope (p, q->tpnt);
198 return p - list;
199 }
200+
201+static void _dl_setup_progname(const char *argv0)
202+{
203+ char image[PATH_MAX];
204+ ssize_t s;
205+
206+ s = _dl_readlink("/proc/self/exe", image, sizeof(image));
207+ if (s > 0 && image[0] == '/') {
208+ image[s] = 0;
209+ _dl_progname = _dl_strdup(image);
210+ } else if (argv0) {
211+ _dl_progname = argv0;
212+ }
213+}
214
215 void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
216 ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
217@@ -454,9 +468,7 @@ void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
218 * been fixed up by now. Still no function calls outside of this
219 * library, since the dynamic resolver is not yet ready.
220 */
221- if (argv[0]) {
222- _dl_progname = argv[0];
223- }
224+ _dl_setup_progname(argv[0]);
225
226 #ifdef __DSBT__
227 _dl_ldso_dsbt = (void *)tpnt->dynamic_info[DT_DSBT_BASE_IDX];
228--
2291.8.3.4
230