0002-pr17739-sh-gc-sections-bug.diff 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. From a94d834c9d0108f0bb50ddc311554d1bed320f54 Mon Sep 17 00:00:00 2001
  2. From: Nick Clifton <[email protected]>
  3. Date: Tue, 2 Aug 2016 11:56:55 +0100
  4. Subject: [PATCH] Fix SH GOT allocation in the presence of linker garbage collection.
  5. PR ld/17739
  6. ld * emulparams/shelf.sh (CHECK_RELOCS_AFTER_OPEN_INPUT): Define with
  7. valye 'yes'.
  8. * emulparams/shelf32.sh: Likewise.
  9. * emulparams/shelf32.sh: Likewise.
  10. * emulparams/shelf_nto.sh: Likewise.
  11. * emulparams/shelf_nto.sh: Likewise.
  12. * emulparams/shelf_vxworks.sh: Likewise.
  13. * emulparams/shelf_vxworks.sh: Likewise.
  14. * emulparams/shlelf32_linux.sh: Likewise.
  15. * emulparams/shlelf32_linux.sh: Likewise.
  16. * emulparams/shlelf_linux.sh: Likewise.
  17. * emulparams/shlelf_linux.sh: Likewise.
  18. * emulparams/shlelf_nto.sh: Likewise.
  19. * emulparams/shlelf_nto.sh: Likewise.
  20. bfd * elf32-sh.c (sh_elf_gc_sweep_hook): Delete.
  21. (elf_backend_sweep_hook): Delete.
  22. ---
  23. bfd/elf32-sh.c | 215 ---------------------------------------
  24. ld/emulparams/shelf.sh | 3 +
  25. ld/emulparams/shelf32.sh | 3 +
  26. ld/emulparams/shelf_nto.sh | 3 +
  27. ld/emulparams/shelf_vxworks.sh | 4 +
  28. ld/emulparams/shlelf32_linux.sh | 4 +-
  29. ld/emulparams/shlelf_linux.sh | 3 +
  30. ld/emulparams/shlelf_nto.sh | 3 +
  31. 10 files changed, 46 insertions(+), 216 deletions(-)
  32. diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
  33. index 52a5fd1..84c5b1e 100644
  34. --- a/bfd/elf32-sh.c
  35. +++ b/bfd/elf32-sh.c
  36. @@ -5682,220 +5682,6 @@ sh_elf_gc_mark_hook (asection *sec,
  37. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  38. }
  39. -/* Update the got entry reference counts for the section being removed. */
  40. -
  41. -static bfd_boolean
  42. -sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
  43. - asection *sec, const Elf_Internal_Rela *relocs)
  44. -{
  45. - Elf_Internal_Shdr *symtab_hdr;
  46. - struct elf_link_hash_entry **sym_hashes;
  47. - bfd_signed_vma *local_got_refcounts;
  48. - union gotref *local_funcdesc;
  49. - const Elf_Internal_Rela *rel, *relend;
  50. -
  51. - if (bfd_link_relocatable (info))
  52. - return TRUE;
  53. -
  54. - elf_section_data (sec)->local_dynrel = NULL;
  55. -
  56. - symtab_hdr = &elf_symtab_hdr (abfd);
  57. - sym_hashes = elf_sym_hashes (abfd);
  58. - local_got_refcounts = elf_local_got_refcounts (abfd);
  59. - local_funcdesc = sh_elf_local_funcdesc (abfd);
  60. -
  61. - relend = relocs + sec->reloc_count;
  62. - for (rel = relocs; rel < relend; rel++)
  63. - {
  64. - unsigned long r_symndx;
  65. - unsigned int r_type;
  66. - struct elf_link_hash_entry *h = NULL;
  67. -#ifdef INCLUDE_SHMEDIA
  68. - int seen_stt_datalabel = 0;
  69. -#endif
  70. -
  71. - r_symndx = ELF32_R_SYM (rel->r_info);
  72. - if (r_symndx >= symtab_hdr->sh_info)
  73. - {
  74. - struct elf_sh_link_hash_entry *eh;
  75. - struct elf_sh_dyn_relocs **pp;
  76. - struct elf_sh_dyn_relocs *p;
  77. -
  78. - h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  79. - while (h->root.type == bfd_link_hash_indirect
  80. - || h->root.type == bfd_link_hash_warning)
  81. - {
  82. -#ifdef INCLUDE_SHMEDIA
  83. - seen_stt_datalabel |= h->type == STT_DATALABEL;
  84. -#endif
  85. - h = (struct elf_link_hash_entry *) h->root.u.i.link;
  86. - }
  87. - eh = (struct elf_sh_link_hash_entry *) h;
  88. - for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
  89. - if (p->sec == sec)
  90. - {
  91. - /* Everything must go for SEC. */
  92. - *pp = p->next;
  93. - break;
  94. - }
  95. - }
  96. -
  97. - r_type = ELF32_R_TYPE (rel->r_info);
  98. - switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
  99. - {
  100. - case R_SH_TLS_LD_32:
  101. - if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
  102. - sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
  103. - break;
  104. -
  105. - case R_SH_GOT32:
  106. - case R_SH_GOT20:
  107. - case R_SH_GOTOFF:
  108. - case R_SH_GOTOFF20:
  109. - case R_SH_GOTPC:
  110. -#ifdef INCLUDE_SHMEDIA
  111. - case R_SH_GOT_LOW16:
  112. - case R_SH_GOT_MEDLOW16:
  113. - case R_SH_GOT_MEDHI16:
  114. - case R_SH_GOT_HI16:
  115. - case R_SH_GOT10BY4:
  116. - case R_SH_GOT10BY8:
  117. - case R_SH_GOTOFF_LOW16:
  118. - case R_SH_GOTOFF_MEDLOW16:
  119. - case R_SH_GOTOFF_MEDHI16:
  120. - case R_SH_GOTOFF_HI16:
  121. - case R_SH_GOTPC_LOW16:
  122. - case R_SH_GOTPC_MEDLOW16:
  123. - case R_SH_GOTPC_MEDHI16:
  124. - case R_SH_GOTPC_HI16:
  125. -#endif
  126. - case R_SH_TLS_GD_32:
  127. - case R_SH_TLS_IE_32:
  128. - case R_SH_GOTFUNCDESC:
  129. - case R_SH_GOTFUNCDESC20:
  130. - if (h != NULL)
  131. - {
  132. -#ifdef INCLUDE_SHMEDIA
  133. - if (seen_stt_datalabel)
  134. - {
  135. - struct elf_sh_link_hash_entry *eh;
  136. - eh = (struct elf_sh_link_hash_entry *) h;
  137. - if (eh->datalabel_got.refcount > 0)
  138. - eh->datalabel_got.refcount -= 1;
  139. - }
  140. - else
  141. -#endif
  142. - if (h->got.refcount > 0)
  143. - h->got.refcount -= 1;
  144. - }
  145. - else if (local_got_refcounts != NULL)
  146. - {
  147. -#ifdef INCLUDE_SHMEDIA
  148. - if (rel->r_addend & 1)
  149. - {
  150. - if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
  151. - local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
  152. - }
  153. - else
  154. -#endif
  155. - if (local_got_refcounts[r_symndx] > 0)
  156. - local_got_refcounts[r_symndx] -= 1;
  157. - }
  158. - break;
  159. -
  160. - case R_SH_FUNCDESC:
  161. - if (h != NULL)
  162. - sh_elf_hash_entry (h)->abs_funcdesc_refcount -= 1;
  163. - else if (sh_elf_hash_table (info)->fdpic_p && !bfd_link_pic (info))
  164. - sh_elf_hash_table (info)->srofixup->size -= 4;
  165. -
  166. - /* Fall through. */
  167. -
  168. - case R_SH_GOTOFFFUNCDESC:
  169. - case R_SH_GOTOFFFUNCDESC20:
  170. - if (h != NULL)
  171. - sh_elf_hash_entry (h)->funcdesc.refcount -= 1;
  172. - else
  173. - local_funcdesc[r_symndx].refcount -= 1;
  174. - break;
  175. -
  176. - case R_SH_DIR32:
  177. - if (sh_elf_hash_table (info)->fdpic_p && !bfd_link_pic (info)
  178. - && (sec->flags & SEC_ALLOC) != 0)
  179. - sh_elf_hash_table (info)->srofixup->size -= 4;
  180. - /* Fall thru */
  181. -
  182. - case R_SH_REL32:
  183. - if (bfd_link_pic (info))
  184. - break;
  185. - /* Fall thru */
  186. -
  187. - case R_SH_PLT32:
  188. -#ifdef INCLUDE_SHMEDIA
  189. - case R_SH_PLT_LOW16:
  190. - case R_SH_PLT_MEDLOW16:
  191. - case R_SH_PLT_MEDHI16:
  192. - case R_SH_PLT_HI16:
  193. -#endif
  194. - if (h != NULL)
  195. - {
  196. - if (h->plt.refcount > 0)
  197. - h->plt.refcount -= 1;
  198. - }
  199. - break;
  200. -
  201. - case R_SH_GOTPLT32:
  202. -#ifdef INCLUDE_SHMEDIA
  203. - case R_SH_GOTPLT_LOW16:
  204. - case R_SH_GOTPLT_MEDLOW16:
  205. - case R_SH_GOTPLT_MEDHI16:
  206. - case R_SH_GOTPLT_HI16:
  207. - case R_SH_GOTPLT10BY4:
  208. - case R_SH_GOTPLT10BY8:
  209. -#endif
  210. - if (h != NULL)
  211. - {
  212. - struct elf_sh_link_hash_entry *eh;
  213. - eh = (struct elf_sh_link_hash_entry *) h;
  214. - if (eh->gotplt_refcount > 0)
  215. - {
  216. - eh->gotplt_refcount -= 1;
  217. - if (h->plt.refcount > 0)
  218. - h->plt.refcount -= 1;
  219. - }
  220. -#ifdef INCLUDE_SHMEDIA
  221. - else if (seen_stt_datalabel)
  222. - {
  223. - if (eh->datalabel_got.refcount > 0)
  224. - eh->datalabel_got.refcount -= 1;
  225. - }
  226. -#endif
  227. - else if (h->got.refcount > 0)
  228. - h->got.refcount -= 1;
  229. - }
  230. - else if (local_got_refcounts != NULL)
  231. - {
  232. -#ifdef INCLUDE_SHMEDIA
  233. - if (rel->r_addend & 1)
  234. - {
  235. - if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
  236. - local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
  237. - }
  238. - else
  239. -#endif
  240. - if (local_got_refcounts[r_symndx] > 0)
  241. - local_got_refcounts[r_symndx] -= 1;
  242. - }
  243. - break;
  244. -
  245. - default:
  246. - break;
  247. - }
  248. - }
  249. -
  250. - return TRUE;
  251. -}
  252. -
  253. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  254. static void
  255. @@ -7455,7 +7241,6 @@ sh_elf_encode_eh_address (bfd *abfd,
  256. sh_elf_merge_private_data
  257. #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
  258. -#define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
  259. #define elf_backend_check_relocs sh_elf_check_relocs
  260. #define elf_backend_copy_indirect_symbol \
  261. sh_elf_copy_indirect_symbol
  262. diff --git a/ld/emulparams/shelf.sh b/ld/emulparams/shelf.sh
  263. index 83680a6..d3f4752 100644
  264. --- a/ld/emulparams/shelf.sh
  265. +++ b/ld/emulparams/shelf.sh
  266. @@ -11,6 +11,9 @@ MACHINE=
  267. TEMPLATE_NAME=elf32
  268. GENERATE_SHLIB_SCRIPT=yes
  269. EMBEDDED=yes
  270. +# PR 17739. Delay checking relocs until after all files have
  271. +# been opened and linker garbage collection has taken place.
  272. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  273. # These are for compatibility with the COFF toolchain.
  274. ENTRY=start
  275. diff --git a/ld/emulparams/shelf32.sh b/ld/emulparams/shelf32.sh
  276. index 966bd30..bf362c5 100644
  277. --- a/ld/emulparams/shelf32.sh
  278. +++ b/ld/emulparams/shelf32.sh
  279. @@ -11,6 +11,9 @@ ALIGNMENT=8
  280. TEMPLATE_NAME=elf32
  281. GENERATE_SHLIB_SCRIPT=yes
  282. EMBEDDED=yes
  283. +# PR 17739. Delay checking relocs until after all files have
  284. +# been opened and linker garbage collection has taken place.
  285. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  286. DATA_START_SYMBOLS='PROVIDE (___data = .);'
  287. diff --git a/ld/emulparams/shelf_nto.sh b/ld/emulparams/shelf_nto.sh
  288. index c4d71aa..46efd87 100644
  289. --- a/ld/emulparams/shelf_nto.sh
  290. +++ b/ld/emulparams/shelf_nto.sh
  291. @@ -9,3 +9,6 @@ TEMPLATE_NAME=elf32
  292. GENERATE_SHLIB_SCRIPT=yes
  293. TEXT_START_SYMBOLS='_btext = .;'
  294. ENTRY=_start
  295. +# PR 17739. Delay checking relocs until after all files have
  296. +# been opened and linker garbage collection has taken place.
  297. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  298. diff --git a/ld/emulparams/shelf_vxworks.sh b/ld/emulparams/shelf_vxworks.sh
  299. index 77619cb..759ffac 100644
  300. --- a/ld/emulparams/shelf_vxworks.sh
  301. +++ b/ld/emulparams/shelf_vxworks.sh
  302. @@ -14,6 +14,10 @@ TEMPLATE_NAME=elf32
  303. GENERATE_SHLIB_SCRIPT=yes
  304. ENTRY=__start
  305. SYMPREFIX=_
  306. +# PR 17739. Delay checking relocs until after all files have
  307. +# been opened and linker garbage collection has taken place.
  308. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  309. +
  310. GOT=".got ${RELOCATING-0} : {
  311. PROVIDE(__GLOBAL_OFFSET_TABLE_ = .);
  312. *(.got.plt) *(.got) }"
  313. diff --git a/ld/emulparams/shlelf32_linux.sh b/ld/emulparams/shlelf32_linux.sh
  314. index 81aea39..0327e57 100644
  315. --- a/ld/emulparams/shlelf32_linux.sh
  316. +++ b/ld/emulparams/shlelf32_linux.sh
  317. @@ -13,7 +13,9 @@ ALIGNMENT=8
  318. TEMPLATE_NAME=elf32
  319. GENERATE_SHLIB_SCRIPT=yes
  320. GENERATE_PIE_SCRIPT=yes
  321. -
  322. +# PR 17739. Delay checking relocs until after all files have
  323. +# been opened and linker garbage collection has taken place.
  324. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  325. DATA_START_SYMBOLS='PROVIDE (___data = .);'
  326. diff --git a/ld/emulparams/shlelf_linux.sh b/ld/emulparams/shlelf_linux.sh
  327. index c14aae2..4e2a581 100644
  328. --- a/ld/emulparams/shlelf_linux.sh
  329. +++ b/ld/emulparams/shlelf_linux.sh
  330. @@ -12,6 +12,9 @@ MACHINE=
  331. TEMPLATE_NAME=elf32
  332. GENERATE_SHLIB_SCRIPT=yes
  333. GENERATE_PIE_SCRIPT=yes
  334. +# PR 17739. Delay checking relocs until after all files have
  335. +# been opened and linker garbage collection has taken place.
  336. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  337. DATA_START_SYMBOLS='PROVIDE (__data_start = .);';
  338. diff --git a/ld/emulparams/shlelf_nto.sh b/ld/emulparams/shlelf_nto.sh
  339. index 16f6508..f8ffc13 100644
  340. --- a/ld/emulparams/shlelf_nto.sh
  341. +++ b/ld/emulparams/shlelf_nto.sh
  342. @@ -9,3 +9,6 @@ TEMPLATE_NAME=elf32
  343. GENERATE_SHLIB_SCRIPT=yes
  344. TEXT_START_SYMBOLS='_btext = .;'
  345. ENTRY=_start
  346. +# PR 17739. Delay checking relocs until after all files have
  347. +# been opened and linker garbage collection has taken place.
  348. +CHECK_RELOCS_AFTER_OPEN_INPUT=yes
  349. --
  350. 1.7.1