050-all_glibc-2.14-leak-revert-crash.patch 3.7 KB

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