0011-xtensa-move-dynamic-relocations-sections-consistency.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From f82863d797e461b936dff2b659a3aa65088ee87e Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Sun, 22 Jul 2018 18:59:11 -0700
  4. Subject: [PATCH] xtensa: move dynamic relocations sections consistency
  5. check
  6. The function elf_xtensa_finish_dynamic_sections checks that sizes of
  7. sections .rela.dyn and .rela.plt match number of corresponding relocation
  8. records, but the check is only done when .rela.plt is non-empty, so, e.g.
  9. it is never run for the static PIE.
  10. Rearrange the test so that .rela.dyn and .rela.plt are checked always.
  11. bfd/
  12. 2018-07-23 Max Filippov <jcmvbkbc@gmail.com>
  13. * elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Move
  14. relocation sections consistency check to always check both
  15. .rela.dyn and .rela.plt when they exist. Rearrange variable
  16. definition and assignment places.
  17. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  18. Backported from: f82863d797e461b936dff2b659a3aa65088ee87e
  19. ---
  20. bfd/elf32-xtensa.c | 22 +++++++++++-----------
  21. 1 file changed, 11 insertions(+), 11 deletions(-)
  22. diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
  23. index a4b046e445f1..cf085b7b0751 100644
  24. --- a/bfd/elf32-xtensa.c
  25. +++ b/bfd/elf32-xtensa.c
  26. @@ -3156,7 +3156,7 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
  27. {
  28. struct elf_xtensa_link_hash_table *htab;
  29. bfd *dynobj;
  30. - asection *sdyn, *srelplt, *sgot, *sxtlit, *sgotloc;
  31. + asection *sdyn, *srelplt, *srelgot, *sgot, *sxtlit, *sgotloc;
  32. Elf32_External_Dyn *dyncon, *dynconend;
  33. int num_xtlit_entries = 0;
  34. @@ -3186,15 +3186,15 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
  35. }
  36. srelplt = htab->elf.srelplt;
  37. + srelgot = htab->elf.srelgot;
  38. if (srelplt && srelplt->size != 0)
  39. {
  40. - asection *sgotplt, *srelgot, *spltlittbl;
  41. + asection *sgotplt, *spltlittbl;
  42. int chunk, plt_chunks, plt_entries;
  43. Elf_Internal_Rela irela;
  44. bfd_byte *loc;
  45. unsigned rtld_reloc;
  46. - srelgot = htab->elf.srelgot;
  47. spltlittbl = htab->spltlittbl;
  48. BFD_ASSERT (srelgot != NULL && spltlittbl != NULL);
  49. @@ -3260,14 +3260,6 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
  50. spltlittbl->contents + (chunk * 8) + 4);
  51. }
  52. - /* All the dynamic relocations have been emitted at this point.
  53. - Make sure the relocation sections are the correct size. */
  54. - if (srelgot->size != (sizeof (Elf32_External_Rela)
  55. - * srelgot->reloc_count)
  56. - || srelplt->size != (sizeof (Elf32_External_Rela)
  57. - * srelplt->reloc_count))
  58. - abort ();
  59. -
  60. /* The .xt.lit.plt section has just been modified. This must
  61. happen before the code below which combines adjacent literal
  62. table entries, and the .xt.lit.plt contents have to be forced to
  63. @@ -3282,6 +3274,14 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
  64. spltlittbl->flags &= ~SEC_HAS_CONTENTS;
  65. }
  66. + /* All the dynamic relocations have been emitted at this point.
  67. + Make sure the relocation sections are the correct size. */
  68. + if ((srelgot && srelgot->size != (sizeof (Elf32_External_Rela)
  69. + * srelgot->reloc_count))
  70. + || (srelplt && srelplt->size != (sizeof (Elf32_External_Rela)
  71. + * srelplt->reloc_count)))
  72. + abort ();
  73. +
  74. /* Combine adjacent literal table entries. */
  75. BFD_ASSERT (! bfd_link_relocatable (info));
  76. sxtlit = bfd_get_section_by_name (output_bfd, ".xt.lit");
  77. --
  78. 2.11.0