Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. --- a/elf/dl-deps.c
  2. +++ b/elf/dl-deps.c
  3. @@ -617,61 +617,64 @@ Filters not supported with LD_TRACE_PRELINKING"));
  4. map->l_searchlist.r_list[i]->l_reserved = 0;
  5. }
  6.  
  7. - /* Now determine the order in which the initialization has to happen. */
  8. + /* Sort the initializer list to take dependencies into account. The binary
  9. + itself will always be initialize last. */
  10. memcpy (l_initfini, map->l_searchlist.r_list,
  11. nlist * sizeof (struct link_map *));
  12. -
  13. - /* We can skip looking for the binary itself which is at the front
  14. - of the search list. */
  15. - assert (nlist > 1);
  16. - i = 1;
  17. - bool seen[nlist];
  18. - memset (seen, false, nlist * sizeof (seen[0]));
  19. - while (1)
  20. + if (__builtin_expect (nlist > 1, 1))
  21. {
  22. - /* Keep track of which object we looked at this round. */
  23. - seen[i] = true;
  24. - struct link_map *thisp = l_initfini[i];
  25. -
  26. - /* Find the last object in the list for which the current one is
  27. - a dependency and move the current object behind the object
  28. - with the dependency. */
  29. - unsigned int k = nlist - 1;
  30. - while (k > i)
  31. + /* We can skip looking for the binary itself which is at the front
  32. + of the search list. */
  33. + i = 1;
  34. + bool seen[nlist];
  35. + memset (seen, false, nlist * sizeof (seen[0]));
  36. + while (1)
  37. {
  38. - struct link_map **runp = l_initfini[k]->l_initfini;
  39. - if (runp != NULL)
  40. - /* Look through the dependencies of the object. */
  41. - while (*runp != NULL)
  42. - if (__builtin_expect (*runp++ == thisp, 0))
  43. - {
  44. - /* Move the current object to the back past the last
  45. - object with it as the dependency. */
  46. - memmove (&l_initfini[i], &l_initfini[i + 1],
  47. - (k - i) * sizeof (l_initfini[0]));
  48. - l_initfini[k] = thisp;
  49. -
  50. - if (seen[i + 1])
  51. + /* Keep track of which object we looked at this round. */
  52. + seen[i] = true;
  53. + struct link_map *thisp = l_initfini[i];
  54. +
  55. + /* Find the last object in the list for which the current one is
  56. + a dependency and move the current object behind the object
  57. + with the dependency. */
  58. + unsigned int k = nlist - 1;
  59. + while (k > i)
  60. + {
  61. + struct link_map **runp = l_initfini[k]->l_initfini;
  62. + if (runp != NULL)
  63. + /* Look through the dependencies of the object. */
  64. + while (*runp != NULL)
  65. + if (__builtin_expect (*runp++ == thisp, 0))
  66. {
  67. - ++i;
  68. - goto next_clear;
  69. + /* Move the current object to the back past the last
  70. + object with it as the dependency. */
  71. + memmove (&l_initfini[i], &l_initfini[i + 1],
  72. + (k - i) * sizeof (l_initfini[0]));
  73. + l_initfini[k] = thisp;
  74. +
  75. + if (seen[i + 1])
  76. + {
  77. + ++i;
  78. + goto next_clear;
  79. + }
  80. +
  81. + memmove (&seen[i], &seen[i + 1],
  82. + (k - i) * sizeof (seen[0]));
  83. + seen[k] = true;
  84. +
  85. + goto next;
  86. }
  87.  
  88. - memmove (&seen[i], &seen[i + 1], (k - i) * sizeof (seen[0]));
  89. - seen[k] = true;
  90. + --k;
  91. + }
  92.  
  93. - goto next;
  94. - }
  95. + if (++i == nlist)
  96. + break;
  97. + next_clear:
  98. + memset (&seen[i], false, (nlist - i) * sizeof (seen[0]));
  99.  
  100. - --k;
  101. + next:;
  102. }
  103. -
  104. - if (++i == nlist)
  105. - break;
  106. - next_clear:
  107. - memset (&seen[i], false, (nlist - i) * sizeof (seen[0]));
  108. -
  109. - next:;
  110. }
  111.  
  112. /* Terminate the list of dependencies. */
  113. --- a/elf/dl-fini.c
  114. +++ b/elf/dl-fini.c
  115. @@ -33,9 +33,12 @@ internal_function
  116. _dl_sort_fini (struct link_map *l, struct link_map **maps, size_t nmaps,
  117. char *used, Lmid_t ns)
  118. {
  119. + /* A list of one element need not be sorted. */
  120. + if (nmaps == 1)
  121. + return;
  122. +
  123. /* We can skip looking for the binary itself which is at the front
  124. of the search list for the main namespace. */
  125. - assert (nmaps > 1);
  126. unsigned int i = ns == LM_ID_BASE;
  127. bool seen[nmaps];
  128. memset (seen, false, nmaps * sizeof (seen[0]));
  129. @@ -195,9 +198,8 @@ _dl_fini (void)
  130. assert (ns == LM_ID_BASE || i == nloaded || i == nloaded - 1);
  131. nmaps = i;
  132.  
  133. - if (nmaps > 1)
  134. - /* Now we have to do the sorting. */
  135. - _dl_sort_fini (GL(dl_ns)[ns]._ns_loaded, maps, nmaps, NULL, ns);
  136. + /* Now we have to do the sorting. */
  137. + _dl_sort_fini (GL(dl_ns)[ns]._ns_loaded, maps, nmaps, NULL, ns);
  138.  
  139. /* We do not rely on the linked list of loaded object anymore from
  140. this point on. We have our own list here (maps). The various
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement