87a852b5e2d34746bff0431aa8be072953b4e648
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / uclibc / 0.9.33.2 / 0050-libdl-fix-dlopen-implementation-from-statically-link.patch
1 From 7f82a682a730899d30d8640b6af5178919339837 Mon Sep 17 00:00:00 2001
2 From: Filippo Arcidiacono <filippo.arcidiacono@st.com>
3 Date: Thu, 9 May 2013 09:04:20 +0200
4 Subject: [PATCH] libdl: fix dlopen implementation from statically linked
5  application
6
7 Calling dlopen from statically linked application is actually broken,
8 because _dl_find_hash enters into an infinite loop when trying to
9 resolve symbols. In this case it doesn't need to extend the global
10 scope, it is readyto be used as it is, because _dl_loaded_modules already points
11 to the dlopened library.
12
13 The patch also fixesi a typo in __LDSO_LD_LIBRARY_PATH__ macro, that was
14 preventing to get the actual value of the LD_LIBRARY_PATH.
15
16 Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono@st.com>
17 Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
18 (cherry picked from commit 231e4a9b4b972662a6832f714a05525a3754892d)
19
20 Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
21 ---
22  ldso/libdl/libdl.c |   11 +++++++++--
23  1 file changed, 9 insertions(+), 2 deletions(-)
24
25 diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
26 index 018c720..49711a8 100644
27 --- a/ldso/libdl/libdl.c
28 +++ b/ldso/libdl/libdl.c
29 @@ -374,7 +374,7 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from)
30         if (getenv("LD_BIND_NOW"))
31                 now_flag = RTLD_NOW;
32  
33 -#if !defined SHARED && defined __LDSO_LIBRARY_PATH__
34 +#if !defined SHARED && defined __LDSO_LD_LIBRARY_PATH__
35         /* When statically linked, the _dl_library_path is not yet initialized */
36         _dl_library_path = getenv("LD_LIBRARY_PATH");
37  #endif
38 @@ -541,11 +541,18 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from)
39          * to the GOT tables.  We need to do this in reverse order so that COPY
40          * directives work correctly */
41  
42 -       /* Get the tail of the list */
43 +#ifdef SHARED
44 +       /*
45 +        * Get the tail of the list.
46 +        * In the static case doesn't need to extend the global scope, it is
47 +        * ready to be used as it is, because _dl_loaded_modules already points
48 +        * to the dlopened library.
49 +        */
50         for (ls = &_dl_loaded_modules->symbol_scope; ls && ls->next; ls = ls->next);
51  
52         /* Extend the global scope by adding the local scope of the dlopened DSO. */
53         ls->next = &dyn_chain->dyn->symbol_scope;
54 +#endif
55  #ifdef __mips__
56         /*
57          * Relocation of the GOT entries for MIPS have to be done
58 -- 
59 1.7.10.4
60