[toolchain] uClibc: fix errno access in pthreads (#8166, #8177)
[openwrt.git] / toolchain / uClibc / patches-0.9.31 / 130-ldso-fix-__dl_parse_dynamic_info-segfault.patch
1 [PATCH] ld.so: ldd crashes when __LDSO_SEARCH_INTERP_PATH__ is not #defined
2 Since b65c7b2c79debcb9017e31913e01eeaa280106fb, the implicit search path
3 can be disabled by not #defining __LDSO_SEARCH_INTERP_PATH__. This
4 causes _dl_ldsopath to never be set, so it remains NULL. _dl_ldsopath is
5 still used when __LDSO_LDD_SUPPORT__ is #defined, to strip the path off
6 of the beginning of the absolute path to the ld.so interpreter in use
7 for printing. The _dl_strlen will crash with a NULL argument.
8
9 Rather than relying on _dl_ldsopath, this change causes ldd to compute
10 the interpreter's basename directly.
11
12 glibc ld.so seems to print the full path to the interpreter without
13 any computed basename or =>. I personally prefer glibc's behavior, but
14 to preserve backwards compatibility with uClibc ld.so, the existing
15 format with the computed basename, =>, and full path is used here. This
16 enables simpler (and unchanged) text processing in a pipeline.
17
18 Signed-off-by: Mark Mentovai <mark at moxienet.com>
19 ---
20 ldso/ldso/ldso.c |   12 +++++++++---
21 1 files changed, 9 insertions(+), 3 deletions(-)
22
23 --- a/ldso/ldso/ldso.c
24 +++ b/ldso/ldso/ldso.c
25 @@ -923,9 +923,15 @@ void _dl_get_ready_to_run(struct elf_res
26  #ifdef __LDSO_LDD_SUPPORT__
27         /* End of the line for ldd.... */
28         if (trace_loaded_objects) {
29 -               _dl_dprintf(1, "\t%s => %s (%x)\n",
30 -                           rpnt->dyn->libname + _dl_strlen(_dl_ldsopath) + 1,
31 -                           rpnt->dyn->libname, DL_LOADADDR_BASE(rpnt->dyn->loadaddr));
32 +               /* glibc ld.so/ldd would just do
33 +                * _dl_dprintf(1, "\t%s (%x)\n", rpnt->dyn->libname,
34 +                *             DL_LOADADDR_BASE(rpnt->dyn->loadaddr));
35 +                * but uClibc has always used the => format. */
36 +               char *ptmp = _dl_strrchr(rpnt->dyn->libname, '/');
37 +               if (ptmp != rpnt->dyn->libname)
38 +                       ++ptmp;
39 +               _dl_dprintf(1, "\t%s => %s (%x)\n", ptmp, rpnt->dyn->libname,
40 +                           DL_LOADADDR_BASE(rpnt->dyn->loadaddr));
41                 _dl_exit(0);
42         }
43  #endif