toolchain: The glorious return of glibc, ver 2.21
[openwrt.git] / toolchain / glibc / patches / 2.15 / 050-all_glibc-2.14-leak-revert-crash.patch
1 partially revert commit 4bff6e0175ed195871f4e01cc4c4c33274b8f6e3 - caused segmentation faults in dlopen
2
3 References:
4 http://comments.gmane.org/gmane.comp.lib.glibc.user/1227
5 http://sourceware.org/ml/libc-alpha/2011-06/msg00006.html
6
7 diff --git a/libc/elf/dl-close.c b/libc/elf/dl-close.c
8 index 4b17bf8..733cc1b 100644
9 --- a/libc/elf/dl-close.c
10 +++ b/libc/elf/dl-close.c
11 @@ -119,17 +119,8 @@ _dl_close_worker (struct link_map *map)
12    if (map->l_direct_opencount > 0 || map->l_type != lt_loaded
13        || dl_close_state != not_pending)
14      {
15 -      if (map->l_direct_opencount == 0)
16 -       {
17 -         if (map->l_type == lt_loaded)
18 -           dl_close_state = rerun;
19 -         else if (map->l_type == lt_library)
20 -           {
21 -             struct link_map **oldp = map->l_initfini;
22 -             map->l_initfini = map->l_orig_initfini;
23 -             _dl_scope_free (oldp);
24 -           }
25 -       }
26 +      if (map->l_direct_opencount == 0 && map->l_type == lt_loaded)
27 +       dl_close_state = rerun;
28  
29        /* There are still references to this object.  Do nothing more.  */
30        if (__builtin_expect (GLRO_dl_debug_mask & DL_DEBUG_FILES, 0))
31 diff --git a/libc/elf/dl-deps.c b/libc/elf/dl-deps.c
32 index 51cb2fa..eddcbf0 100644
33 --- a/libc/elf/dl-deps.c
34 +++ b/libc/elf/dl-deps.c
35 @@ -489,6 +489,7 @@ _dl_map_object_deps (struct link_map *map,
36                   nneeded * sizeof needed[0]);
37           atomic_write_barrier ();
38           l->l_initfini = l_initfini;
39 +         l->l_free_initfini = 1;
40         }
41  
42        /* If we have no auxiliary objects just go on to the next map.  */
43 @@ -689,6 +690,7 @@ Filters not supported with LD_TRACE_PRELINKING"));
44    l_initfini[nlist] = NULL;
45    atomic_write_barrier ();
46    map->l_initfini = l_initfini;
47 +  map->l_free_initfini = 1;
48    if (l_reldeps != NULL)
49      {
50        atomic_write_barrier ();
51 @@ -697,7 +699,7 @@ Filters not supported with LD_TRACE_PRELINKING"));
52        _dl_scope_free (old_l_reldeps);
53      }
54    if (old_l_initfini != NULL)
55 -      map->l_orig_initfini = old_l_initfini;
56 +    _dl_scope_free (old_l_initfini);
57  
58    if (errno_reason)
59      _dl_signal_error (errno_reason == -1 ? 0 : errno_reason, objname,
60 diff --git a/libc/elf/dl-libc.c b/libc/elf/dl-libc.c
61 index f44fa10..7563093 100644
62 --- a/libc/elf/dl-libc.c
63 +++ b/libc/elf/dl-libc.c
64 @@ -284,6 +284,10 @@ libc_freeres_fn (free_mem)
65               if (! old->dont_free)
66                 free (old);
67             }
68 +
69 +         /* Free the initfini dependency list.  */
70 +         if (l->l_free_initfini)
71 +           free (l->l_initfini);
72         }
73  
74        if (__builtin_expect (GL(dl_ns)[ns]._ns_global_scope_alloc, 0) != 0
75 diff --git a/libc/elf/rtld.c b/libc/elf/rtld.c
76 index b93a01f..2fc83ce 100644
77 --- a/libc/elf/rtld.c
78 +++ b/libc/elf/rtld.c
79 @@ -2277,6 +2277,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
80               lnp->dont_free = 1;
81               lnp = lnp->next;
82             }
83 +         l->l_free_initfini = 0;
84  
85           if (l != &GL(dl_rtld_map))
86             _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0,
87 diff --git a/libc/include/link.h b/libc/include/link.h
88 index e877104..b1b4065 100644
89 --- a/libc/include/link.h
90 +++ b/libc/include/link.h
91 @@ -192,6 +192,9 @@ struct link_map
92                                                  during LD_TRACE_PRELINKING=1
93                                                  contains any DT_SYMBOLIC
94                                                  libraries.  */
95 +    unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be
96 +                                      freed, ie. not allocated with
97 +                                      the dummy malloc in ld.so.  */
98  
99      /* Collected information about own RPATH directories.  */
100      struct r_search_path_struct l_rpath_dirs;
101 @@ -240,9 +243,6 @@ struct link_map
102  
103      /* List of object in order of the init and fini calls.  */
104      struct link_map **l_initfini;
105 -    /* The init and fini list generated at startup, saved when the
106 -       object is also loaded dynamically.  */
107 -    struct link_map **l_orig_initfini;
108  
109      /* List of the dependencies introduced through symbol binding.  */
110      struct link_map_reldeps