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