915-xtensa-fix-.init-.fini-literals-moving.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. From 7db2accc3fdea0aaa0c3a76a413d8e8030e022c3 Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Tue, 16 Feb 2016 02:23:28 +0300
  4. Subject: [PATCH] xtensa: fix .init/.fini literals moving
  5. Despite the documentation and the comment in xtensa_move_literals, in
  6. the presence of --text-section-literals and --auto-litpools literals are
  7. moved from the separate literal sections into .init and .fini, because
  8. the check in the xtensa_move_literals is incorrect.
  9. This moving was broken with introduction of auto litpools: some literals
  10. now may be lost. This happens because literal frags emitted from .init
  11. and .fini are not closed when new .literal_position marks new literal
  12. pool. Then frag_align(2, 0, 0) changes type of the last literal frag to
  13. rs_align. rs_align frags are skipped in the xtensa_move_literals. As a
  14. result fixups against such literals are not moved out of .init.literal/
  15. .fini.literal sections producing the following assembler error:
  16. test.S: Warning: fixes not all moved from .init.literal
  17. test.S: Internal error!
  18. Fix check for .init.literal/.fini.literal in the xtensa_move_literals
  19. and don't let it move literals from there in the presence of
  20. --text-section-literals or --auto-litpools.
  21. 2016-02-17 Max Filippov <jcmvbkbc@gmail.com>
  22. gas/
  23. * config/tc-xtensa.c (xtensa_move_literals): Fix check for
  24. .init.literal/.fini.literal section name.
  25. * testsuite/gas/xtensa/all.exp: Add init-fini-literals to the
  26. list of xtensa tests.
  27. * testsuite/gas/xtensa/init-fini-literals.d: New file:
  28. init-fini-literals test result patterns.
  29. * testsuite/gas/xtensa/init-fini-literals.s: New file:
  30. init-fini-literals test.
  31. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  32. ---
  33. Backported from: 4111950f363221c4641dc2f33bea61cc94f34906
  34. gas/config/tc-xtensa.c | 12 ++++++++++--
  35. gas/testsuite/gas/xtensa/all.exp | 1 +
  36. gas/testsuite/gas/xtensa/init-fini-literals.d | 24 ++++++++++++++++++++++++
  37. gas/testsuite/gas/xtensa/init-fini-literals.s | 19 +++++++++++++++++++
  38. 4 files changed, 54 insertions(+), 2 deletions(-)
  39. create mode 100644 gas/testsuite/gas/xtensa/init-fini-literals.d
  40. create mode 100644 gas/testsuite/gas/xtensa/init-fini-literals.s
  41. diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
  42. index 36a06cc..5773634 100644
  43. --- a/gas/config/tc-xtensa.c
  44. +++ b/gas/config/tc-xtensa.c
  45. @@ -11061,6 +11061,10 @@ xtensa_move_literals (void)
  46. fixS *fix, *next_fix, **fix_splice;
  47. sym_list *lit;
  48. struct litpool_seg *lps;
  49. + const char *init_name = INIT_SECTION_NAME;
  50. + const char *fini_name = FINI_SECTION_NAME;
  51. + int init_name_len = strlen(init_name);
  52. + int fini_name_len = strlen(fini_name);
  53. mark_literal_frags (literal_head->next);
  54. @@ -11171,9 +11175,13 @@ xtensa_move_literals (void)
  55. for (segment = literal_head->next; segment; segment = segment->next)
  56. {
  57. + const char *seg_name = segment_name (segment->seg);
  58. +
  59. /* Keep the literals for .init and .fini in separate sections. */
  60. - if (!strcmp (segment_name (segment->seg), INIT_SECTION_NAME)
  61. - || !strcmp (segment_name (segment->seg), FINI_SECTION_NAME))
  62. + if ((!memcmp (seg_name, init_name, init_name_len) &&
  63. + !strcmp (seg_name + init_name_len, ".literal")) ||
  64. + (!memcmp (seg_name, fini_name, fini_name_len) &&
  65. + !strcmp (seg_name + fini_name_len, ".literal")))
  66. continue;
  67. frchain_from = seg_info (segment->seg)->frchainP;
  68. diff --git a/gas/testsuite/gas/xtensa/all.exp b/gas/testsuite/gas/xtensa/all.exp
  69. index 7ff7bd7..6b67320 100644
  70. --- a/gas/testsuite/gas/xtensa/all.exp
  71. +++ b/gas/testsuite/gas/xtensa/all.exp
  72. @@ -102,6 +102,7 @@ if [istarget xtensa*-*-*] then {
  73. run_dump_test "first_frag_align"
  74. run_dump_test "auto-litpools"
  75. run_dump_test "loc"
  76. + run_dump_test "init-fini-literals"
  77. }
  78. if [info exists errorInfo] then {
  79. diff --git a/gas/testsuite/gas/xtensa/init-fini-literals.d b/gas/testsuite/gas/xtensa/init-fini-literals.d
  80. new file mode 100644
  81. index 0000000..19ed121
  82. --- /dev/null
  83. +++ b/gas/testsuite/gas/xtensa/init-fini-literals.d
  84. @@ -0,0 +1,24 @@
  85. +#as: --text-section-literals
  86. +#objdump: -r
  87. +#name: check that literals for .init and .fini always go to separate sections
  88. +
  89. +.*: +file format .*xtensa.*
  90. +#...
  91. +RELOCATION RECORDS FOR \[\.init\.literal\]:
  92. +#...
  93. +00000000 R_XTENSA_PLT init
  94. +#...
  95. +RELOCATION RECORDS FOR \[\.fini\.literal\]:
  96. +#...
  97. +00000000 R_XTENSA_PLT fini
  98. +#...
  99. +RELOCATION RECORDS FOR \[\.init\]:
  100. +#...
  101. +.* R_XTENSA_SLOT0_OP \.init\.literal
  102. +.* R_XTENSA_SLOT0_OP \.init\.literal\+0x00000004
  103. +#...
  104. +RELOCATION RECORDS FOR \[\.fini\]:
  105. +#...
  106. +.* R_XTENSA_SLOT0_OP \.fini\.literal
  107. +.* R_XTENSA_SLOT0_OP \.fini\.literal\+0x00000004
  108. +#...
  109. diff --git a/gas/testsuite/gas/xtensa/init-fini-literals.s b/gas/testsuite/gas/xtensa/init-fini-literals.s
  110. new file mode 100644
  111. index 0000000..7c9ec17
  112. --- /dev/null
  113. +++ b/gas/testsuite/gas/xtensa/init-fini-literals.s
  114. @@ -0,0 +1,19 @@
  115. + .section .init,"ax",@progbits
  116. + .literal_position
  117. + .literal .LC0, init@PLT
  118. + .literal_position
  119. + .literal .LC1, 1
  120. + .align 4
  121. +
  122. + l32r a2, .LC0
  123. + l32r a2, .LC1
  124. +
  125. + .section .fini,"ax",@progbits
  126. + .literal_position
  127. + .literal .LC2, fini@PLT
  128. + .literal_position
  129. + .literal .LC3, 1
  130. + .align 4
  131. +
  132. + l32r a2, .LC2
  133. + l32r a2, .LC3
  134. --
  135. 2.1.4