]>
Commit | Line | Data |
---|---|---|
36591ba1 | 1 | /* 32-bit ELF support for Nios II. |
fd67aa11 | 2 | Copyright (C) 2012-2024 Free Software Foundation, Inc. |
36591ba1 SL |
3 | Contributed by Nigel Gray (ngray@altera.com). |
4 | Contributed by Mentor Graphics, Inc. | |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | MA 02110-1301, USA. */ | |
22 | ||
23 | /* This file handles Altera Nios II ELF targets. */ | |
24 | ||
25 | #include "sysdep.h" | |
26 | #include "bfd.h" | |
27 | #include "libbfd.h" | |
28 | #include "bfdlink.h" | |
29 | #include "genlink.h" | |
30 | #include "elf-bfd.h" | |
31 | #include "elf/nios2.h" | |
32 | #include "opcode/nios2.h" | |
78058a5e | 33 | #include "elf32-nios2.h" |
f3185997 | 34 | #include "libiberty.h" |
36591ba1 SL |
35 | |
36 | /* Use RELA relocations. */ | |
37 | #ifndef USE_RELA | |
38 | #define USE_RELA | |
39 | #endif | |
40 | ||
41 | #ifdef USE_REL | |
42 | #undef USE_REL | |
43 | #endif | |
44 | ||
45 | /* Forward declarations. */ | |
46 | static bfd_reloc_status_type nios2_elf32_ignore_reloc | |
47 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
48 | static bfd_reloc_status_type nios2_elf32_hi16_relocate | |
49 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
50 | static bfd_reloc_status_type nios2_elf32_lo16_relocate | |
51 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
52 | static bfd_reloc_status_type nios2_elf32_hiadj16_relocate | |
53 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
54 | static bfd_reloc_status_type nios2_elf32_pcrel_lo16_relocate | |
55 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
56 | static bfd_reloc_status_type nios2_elf32_pcrel_hiadj16_relocate | |
57 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
58 | static bfd_reloc_status_type nios2_elf32_pcrel16_relocate | |
59 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
60 | static bfd_reloc_status_type nios2_elf32_call26_relocate | |
61 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
62 | static bfd_reloc_status_type nios2_elf32_gprel_relocate | |
63 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
64 | static bfd_reloc_status_type nios2_elf32_ujmp_relocate | |
65 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
66 | static bfd_reloc_status_type nios2_elf32_cjmp_relocate | |
67 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
68 | static bfd_reloc_status_type nios2_elf32_callr_relocate | |
69 | (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); | |
70 | ||
71 | /* Target vector. */ | |
6d00b590 AM |
72 | extern const bfd_target nios2_elf32_le_vec; |
73 | extern const bfd_target nios2_elf32_be_vec; | |
36591ba1 SL |
74 | |
75 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
76 | #define TP_OFFSET 0x7000 | |
77 | #define DTP_OFFSET 0x8000 | |
78 | ||
8c163c5a SL |
79 | /* The relocation tables used for SHT_REL sections. There are separate |
80 | tables for R1 and R2 encodings. */ | |
81 | static reloc_howto_type elf_nios2_r1_howto_table_rel[] = { | |
36591ba1 SL |
82 | /* No relocation. */ |
83 | HOWTO (R_NIOS2_NONE, /* type */ | |
84 | 0, /* rightshift */ | |
c94cb026 | 85 | 0, /* size */ |
36591ba1 | 86 | 0, /* bitsize */ |
0a1b45a2 | 87 | false, /* pc_relative */ |
36591ba1 SL |
88 | 0, /* bitpos */ |
89 | complain_overflow_dont, /* complain_on_overflow */ | |
90 | bfd_elf_generic_reloc, /* special_function */ | |
91 | "R_NIOS2_NONE", /* name */ | |
0a1b45a2 | 92 | false, /* partial_inplace */ |
36591ba1 SL |
93 | 0, /* src_mask */ |
94 | 0, /* dst_mask */ | |
0a1b45a2 | 95 | false), /* pcrel_offset */ |
36591ba1 SL |
96 | |
97 | /* 16-bit signed immediate relocation. */ | |
98 | HOWTO (R_NIOS2_S16, /* type */ | |
99 | 0, /* rightshift */ | |
c94cb026 | 100 | 4, /* size */ |
36591ba1 | 101 | 16, /* bitsize */ |
0a1b45a2 | 102 | false, /* pc_relative */ |
36591ba1 SL |
103 | 6, /* bitpos */ |
104 | complain_overflow_signed, /* complain on overflow */ | |
105 | bfd_elf_generic_reloc, /* special function */ | |
106 | "R_NIOS2_S16", /* name */ | |
0a1b45a2 | 107 | false, /* partial_inplace */ |
36591ba1 SL |
108 | 0x003fffc0, /* src_mask */ |
109 | 0x003fffc0, /* dest_mask */ | |
0a1b45a2 | 110 | false), /* pcrel_offset */ |
36591ba1 SL |
111 | |
112 | /* 16-bit unsigned immediate relocation. */ | |
113 | HOWTO (R_NIOS2_U16, /* type */ | |
114 | 0, /* rightshift */ | |
c94cb026 | 115 | 4, /* size */ |
36591ba1 | 116 | 16, /* bitsize */ |
0a1b45a2 | 117 | false, /* pc_relative */ |
36591ba1 SL |
118 | 6, /* bitpos */ |
119 | complain_overflow_unsigned, /* complain on overflow */ | |
120 | bfd_elf_generic_reloc, /* special function */ | |
121 | "R_NIOS2_U16", /* name */ | |
0a1b45a2 | 122 | false, /* partial_inplace */ |
36591ba1 SL |
123 | 0x003fffc0, /* src_mask */ |
124 | 0x003fffc0, /* dest_mask */ | |
0a1b45a2 | 125 | false), /* pcrel_offset */ |
36591ba1 SL |
126 | |
127 | HOWTO (R_NIOS2_PCREL16, /* type */ | |
128 | 0, /* rightshift */ | |
c94cb026 | 129 | 4, /* size */ |
36591ba1 | 130 | 16, /* bitsize */ |
0a1b45a2 | 131 | true, /* pc_relative */ |
36591ba1 SL |
132 | 6, /* bitpos */ |
133 | complain_overflow_signed, /* complain on overflow */ | |
134 | nios2_elf32_pcrel16_relocate, /* special function */ | |
135 | "R_NIOS2_PCREL16", /* name */ | |
0a1b45a2 | 136 | false, /* partial_inplace */ |
36591ba1 SL |
137 | 0x003fffc0, /* src_mask */ |
138 | 0x003fffc0, /* dest_mask */ | |
0a1b45a2 | 139 | true), /* pcrel_offset */ |
36591ba1 SL |
140 | |
141 | HOWTO (R_NIOS2_CALL26, /* type */ | |
142 | 2, /* rightshift */ | |
c94cb026 | 143 | 4, /* size */ |
36591ba1 | 144 | 26, /* bitsize */ |
0a1b45a2 | 145 | false, /* pc_relative */ |
36591ba1 SL |
146 | 6, /* bitpos */ |
147 | complain_overflow_dont, /* complain on overflow */ | |
148 | nios2_elf32_call26_relocate, /* special function */ | |
149 | "R_NIOS2_CALL26", /* name */ | |
0a1b45a2 | 150 | false, /* partial_inplace */ |
36591ba1 SL |
151 | 0xffffffc0, /* src_mask */ |
152 | 0xffffffc0, /* dst_mask */ | |
0a1b45a2 | 153 | false), /* pcrel_offset */ |
36591ba1 SL |
154 | |
155 | HOWTO (R_NIOS2_IMM5, | |
156 | 0, | |
c94cb026 | 157 | 4, |
36591ba1 | 158 | 5, |
0a1b45a2 | 159 | false, |
36591ba1 SL |
160 | 6, |
161 | complain_overflow_bitfield, | |
162 | bfd_elf_generic_reloc, | |
163 | "R_NIOS2_IMM5", | |
0a1b45a2 | 164 | false, |
36591ba1 SL |
165 | 0x000007c0, |
166 | 0x000007c0, | |
0a1b45a2 | 167 | false), |
36591ba1 SL |
168 | |
169 | HOWTO (R_NIOS2_CACHE_OPX, | |
170 | 0, | |
c94cb026 | 171 | 4, |
36591ba1 | 172 | 5, |
0a1b45a2 | 173 | false, |
36591ba1 SL |
174 | 22, |
175 | complain_overflow_bitfield, | |
176 | bfd_elf_generic_reloc, | |
177 | "R_NIOS2_CACHE_OPX", | |
0a1b45a2 | 178 | false, |
36591ba1 SL |
179 | 0x07c00000, |
180 | 0x07c00000, | |
0a1b45a2 | 181 | false), |
36591ba1 SL |
182 | |
183 | HOWTO (R_NIOS2_IMM6, | |
184 | 0, | |
c94cb026 | 185 | 4, |
36591ba1 | 186 | 6, |
0a1b45a2 | 187 | false, |
36591ba1 SL |
188 | 6, |
189 | complain_overflow_bitfield, | |
190 | bfd_elf_generic_reloc, | |
191 | "R_NIOS2_IMM6", | |
0a1b45a2 | 192 | false, |
36591ba1 SL |
193 | 0x00000fc0, |
194 | 0x00000fc0, | |
0a1b45a2 | 195 | false), |
36591ba1 SL |
196 | |
197 | HOWTO (R_NIOS2_IMM8, | |
198 | 0, | |
c94cb026 | 199 | 4, |
36591ba1 | 200 | 8, |
0a1b45a2 | 201 | false, |
36591ba1 SL |
202 | 6, |
203 | complain_overflow_bitfield, | |
204 | bfd_elf_generic_reloc, | |
205 | "R_NIOS2_IMM8", | |
0a1b45a2 | 206 | false, |
36591ba1 SL |
207 | 0x00003fc0, |
208 | 0x00003fc0, | |
0a1b45a2 | 209 | false), |
36591ba1 SL |
210 | |
211 | HOWTO (R_NIOS2_HI16, | |
212 | 0, | |
c94cb026 | 213 | 4, |
36591ba1 | 214 | 32, |
0a1b45a2 | 215 | false, |
36591ba1 SL |
216 | 6, |
217 | complain_overflow_dont, | |
218 | nios2_elf32_hi16_relocate, | |
219 | "R_NIOS2_HI16", | |
0a1b45a2 | 220 | false, |
36591ba1 SL |
221 | 0x003fffc0, |
222 | 0x003fffc0, | |
0a1b45a2 | 223 | false), |
36591ba1 SL |
224 | |
225 | HOWTO (R_NIOS2_LO16, | |
226 | 0, | |
c94cb026 | 227 | 4, |
36591ba1 | 228 | 32, |
0a1b45a2 | 229 | false, |
36591ba1 SL |
230 | 6, |
231 | complain_overflow_dont, | |
232 | nios2_elf32_lo16_relocate, | |
233 | "R_NIOS2_LO16", | |
0a1b45a2 | 234 | false, |
36591ba1 SL |
235 | 0x003fffc0, |
236 | 0x003fffc0, | |
0a1b45a2 | 237 | false), |
36591ba1 SL |
238 | |
239 | HOWTO (R_NIOS2_HIADJ16, | |
240 | 0, | |
c94cb026 | 241 | 4, |
36591ba1 | 242 | 32, |
0a1b45a2 | 243 | false, |
36591ba1 SL |
244 | 6, |
245 | complain_overflow_dont, | |
246 | nios2_elf32_hiadj16_relocate, | |
247 | "R_NIOS2_HIADJ16", | |
0a1b45a2 | 248 | false, |
36591ba1 SL |
249 | 0x003fffc0, |
250 | 0x003fffc0, | |
0a1b45a2 | 251 | false), |
36591ba1 SL |
252 | |
253 | HOWTO (R_NIOS2_BFD_RELOC_32, | |
254 | 0, | |
c94cb026 | 255 | 4, /* long */ |
36591ba1 | 256 | 32, |
0a1b45a2 | 257 | false, |
36591ba1 SL |
258 | 0, |
259 | complain_overflow_dont, | |
260 | bfd_elf_generic_reloc, | |
261 | "R_NIOS2_BFD_RELOC32", | |
0a1b45a2 | 262 | false, |
36591ba1 SL |
263 | 0xffffffff, |
264 | 0xffffffff, | |
0a1b45a2 | 265 | false), |
36591ba1 SL |
266 | |
267 | HOWTO (R_NIOS2_BFD_RELOC_16, | |
268 | 0, | |
c94cb026 | 269 | 2, /* short */ |
36591ba1 | 270 | 16, |
0a1b45a2 | 271 | false, |
36591ba1 SL |
272 | 0, |
273 | complain_overflow_bitfield, | |
274 | bfd_elf_generic_reloc, | |
275 | "R_NIOS2_BFD_RELOC16", | |
0a1b45a2 | 276 | false, |
36591ba1 SL |
277 | 0x0000ffff, |
278 | 0x0000ffff, | |
0a1b45a2 | 279 | false), |
36591ba1 SL |
280 | |
281 | HOWTO (R_NIOS2_BFD_RELOC_8, | |
282 | 0, | |
c94cb026 | 283 | 1, /* byte */ |
36591ba1 | 284 | 8, |
0a1b45a2 | 285 | false, |
36591ba1 SL |
286 | 0, |
287 | complain_overflow_bitfield, | |
288 | bfd_elf_generic_reloc, | |
289 | "R_NIOS2_BFD_RELOC8", | |
0a1b45a2 | 290 | false, |
36591ba1 SL |
291 | 0x000000ff, |
292 | 0x000000ff, | |
0a1b45a2 | 293 | false), |
36591ba1 SL |
294 | |
295 | HOWTO (R_NIOS2_GPREL, | |
296 | 0, | |
c94cb026 | 297 | 4, |
36591ba1 | 298 | 32, |
0a1b45a2 | 299 | false, |
36591ba1 SL |
300 | 6, |
301 | complain_overflow_dont, | |
302 | nios2_elf32_gprel_relocate, | |
303 | "R_NIOS2_GPREL", | |
0a1b45a2 | 304 | false, |
36591ba1 SL |
305 | 0x003fffc0, |
306 | 0x003fffc0, | |
0a1b45a2 | 307 | false), |
36591ba1 SL |
308 | |
309 | HOWTO (R_NIOS2_GNU_VTINHERIT, | |
310 | 0, | |
c94cb026 | 311 | 4, |
36591ba1 | 312 | 0, |
0a1b45a2 | 313 | false, |
36591ba1 SL |
314 | 0, |
315 | complain_overflow_dont, | |
316 | NULL, | |
317 | "R_NIOS2_GNU_VTINHERIT", | |
0a1b45a2 | 318 | false, |
36591ba1 SL |
319 | 0, |
320 | 0, | |
0a1b45a2 | 321 | false), |
36591ba1 SL |
322 | |
323 | HOWTO (R_NIOS2_GNU_VTENTRY, | |
324 | 0, | |
c94cb026 | 325 | 4, |
36591ba1 | 326 | 0, |
0a1b45a2 | 327 | false, |
36591ba1 SL |
328 | 0, |
329 | complain_overflow_dont, | |
330 | _bfd_elf_rel_vtable_reloc_fn, | |
331 | "R_NIOS2_GNU_VTENTRY", | |
0a1b45a2 | 332 | false, |
36591ba1 SL |
333 | 0, |
334 | 0, | |
0a1b45a2 | 335 | false), |
36591ba1 SL |
336 | |
337 | HOWTO (R_NIOS2_UJMP, | |
338 | 0, | |
c94cb026 | 339 | 4, |
36591ba1 | 340 | 32, |
0a1b45a2 | 341 | false, |
36591ba1 SL |
342 | 6, |
343 | complain_overflow_dont, | |
344 | nios2_elf32_ujmp_relocate, | |
345 | "R_NIOS2_UJMP", | |
0a1b45a2 | 346 | false, |
36591ba1 SL |
347 | 0x003fffc0, |
348 | 0x003fffc0, | |
0a1b45a2 | 349 | false), |
36591ba1 SL |
350 | |
351 | HOWTO (R_NIOS2_CJMP, | |
352 | 0, | |
c94cb026 | 353 | 4, |
36591ba1 | 354 | 32, |
0a1b45a2 | 355 | false, |
36591ba1 SL |
356 | 6, |
357 | complain_overflow_dont, | |
358 | nios2_elf32_cjmp_relocate, | |
359 | "R_NIOS2_CJMP", | |
0a1b45a2 | 360 | false, |
36591ba1 SL |
361 | 0x003fffc0, |
362 | 0x003fffc0, | |
0a1b45a2 | 363 | false), |
36591ba1 SL |
364 | |
365 | HOWTO (R_NIOS2_CALLR, | |
366 | 0, | |
c94cb026 | 367 | 4, |
36591ba1 | 368 | 32, |
0a1b45a2 | 369 | false, |
36591ba1 SL |
370 | 6, |
371 | complain_overflow_dont, | |
372 | nios2_elf32_callr_relocate, | |
373 | "R_NIOS2_CALLR", | |
0a1b45a2 | 374 | false, |
36591ba1 SL |
375 | 0x003fffc0, |
376 | 0x003fffc0, | |
0a1b45a2 | 377 | false), |
36591ba1 SL |
378 | |
379 | HOWTO (R_NIOS2_ALIGN, | |
380 | 0, | |
c94cb026 | 381 | 4, |
36591ba1 | 382 | 0, |
0a1b45a2 | 383 | false, |
36591ba1 SL |
384 | 0, |
385 | complain_overflow_dont, | |
386 | nios2_elf32_ignore_reloc, | |
387 | "R_NIOS2_ALIGN", | |
0a1b45a2 | 388 | false, |
36591ba1 SL |
389 | 0, |
390 | 0, | |
0a1b45a2 | 391 | true), |
36591ba1 SL |
392 | |
393 | ||
394 | HOWTO (R_NIOS2_GOT16, | |
395 | 0, | |
c94cb026 | 396 | 4, |
36591ba1 | 397 | 16, |
0a1b45a2 | 398 | false, |
36591ba1 SL |
399 | 6, |
400 | complain_overflow_bitfield, | |
401 | bfd_elf_generic_reloc, | |
402 | "R_NIOS2_GOT16", | |
0a1b45a2 | 403 | false, |
36591ba1 SL |
404 | 0x003fffc0, |
405 | 0x003fffc0, | |
0a1b45a2 | 406 | false), |
36591ba1 SL |
407 | |
408 | HOWTO (R_NIOS2_CALL16, | |
409 | 0, | |
c94cb026 | 410 | 4, |
36591ba1 | 411 | 16, |
0a1b45a2 | 412 | false, |
36591ba1 SL |
413 | 6, |
414 | complain_overflow_bitfield, | |
415 | bfd_elf_generic_reloc, | |
416 | "R_NIOS2_CALL16", | |
0a1b45a2 | 417 | false, |
36591ba1 SL |
418 | 0x003fffc0, |
419 | 0x003fffc0, | |
0a1b45a2 | 420 | false), |
36591ba1 SL |
421 | |
422 | HOWTO (R_NIOS2_GOTOFF_LO, | |
423 | 0, | |
c94cb026 | 424 | 4, |
36591ba1 | 425 | 16, |
0a1b45a2 | 426 | false, |
36591ba1 SL |
427 | 6, |
428 | complain_overflow_dont, | |
429 | bfd_elf_generic_reloc, | |
430 | "R_NIOS2_GOTOFF_LO", | |
0a1b45a2 | 431 | false, |
36591ba1 SL |
432 | 0x003fffc0, |
433 | 0x003fffc0, | |
0a1b45a2 | 434 | false), |
36591ba1 SL |
435 | |
436 | HOWTO (R_NIOS2_GOTOFF_HA, | |
437 | 0, | |
c94cb026 | 438 | 4, |
36591ba1 | 439 | 16, |
0a1b45a2 | 440 | false, |
36591ba1 SL |
441 | 6, |
442 | complain_overflow_dont, | |
443 | bfd_elf_generic_reloc, | |
444 | "R_NIOS2_GOTOFF_HA", | |
0a1b45a2 | 445 | false, |
36591ba1 SL |
446 | 0x003fffc0, |
447 | 0x003fffc0, | |
0a1b45a2 | 448 | false), |
36591ba1 SL |
449 | |
450 | HOWTO (R_NIOS2_PCREL_LO, | |
451 | 0, | |
c94cb026 | 452 | 4, |
36591ba1 | 453 | 16, |
0a1b45a2 | 454 | true, |
36591ba1 SL |
455 | 6, |
456 | complain_overflow_dont, | |
457 | nios2_elf32_pcrel_lo16_relocate, | |
458 | "R_NIOS2_PCREL_LO", | |
0a1b45a2 | 459 | false, |
36591ba1 SL |
460 | 0x003fffc0, |
461 | 0x003fffc0, | |
0a1b45a2 | 462 | true), |
36591ba1 SL |
463 | |
464 | HOWTO (R_NIOS2_PCREL_HA, | |
465 | 0, | |
c94cb026 | 466 | 4, |
36591ba1 | 467 | 16, |
0a1b45a2 | 468 | false, /* This is a PC-relative relocation, but we need to subtract |
36591ba1 SL |
469 | PC ourselves before the HIADJ. */ |
470 | 6, | |
471 | complain_overflow_dont, | |
472 | nios2_elf32_pcrel_hiadj16_relocate, | |
473 | "R_NIOS2_PCREL_HA", | |
0a1b45a2 | 474 | false, |
36591ba1 SL |
475 | 0x003fffc0, |
476 | 0x003fffc0, | |
0a1b45a2 | 477 | true), |
36591ba1 SL |
478 | |
479 | HOWTO (R_NIOS2_TLS_GD16, | |
480 | 0, | |
c94cb026 | 481 | 4, |
36591ba1 | 482 | 16, |
0a1b45a2 | 483 | false, |
36591ba1 SL |
484 | 6, |
485 | complain_overflow_bitfield, | |
486 | bfd_elf_generic_reloc, | |
487 | "R_NIOS2_TLS_GD16", | |
0a1b45a2 | 488 | false, |
36591ba1 SL |
489 | 0x003fffc0, |
490 | 0x003fffc0, | |
0a1b45a2 | 491 | false), |
36591ba1 SL |
492 | |
493 | HOWTO (R_NIOS2_TLS_LDM16, | |
494 | 0, | |
c94cb026 | 495 | 4, |
36591ba1 | 496 | 16, |
0a1b45a2 | 497 | false, |
36591ba1 SL |
498 | 6, |
499 | complain_overflow_bitfield, | |
500 | bfd_elf_generic_reloc, | |
501 | "R_NIOS2_TLS_LDM16", | |
0a1b45a2 | 502 | false, |
36591ba1 SL |
503 | 0x003fffc0, |
504 | 0x003fffc0, | |
0a1b45a2 | 505 | false), |
36591ba1 SL |
506 | |
507 | HOWTO (R_NIOS2_TLS_LDO16, | |
508 | 0, | |
c94cb026 | 509 | 4, |
36591ba1 | 510 | 16, |
0a1b45a2 | 511 | false, |
36591ba1 SL |
512 | 6, |
513 | complain_overflow_bitfield, | |
514 | bfd_elf_generic_reloc, | |
515 | "R_NIOS2_TLS_LDO16", | |
0a1b45a2 | 516 | false, |
36591ba1 SL |
517 | 0x003fffc0, |
518 | 0x003fffc0, | |
0a1b45a2 | 519 | false), |
36591ba1 SL |
520 | |
521 | HOWTO (R_NIOS2_TLS_IE16, | |
522 | 0, | |
c94cb026 | 523 | 4, |
36591ba1 | 524 | 16, |
0a1b45a2 | 525 | false, |
36591ba1 SL |
526 | 6, |
527 | complain_overflow_bitfield, | |
528 | bfd_elf_generic_reloc, | |
529 | "R_NIOS2_TLS_IE16", | |
0a1b45a2 | 530 | false, |
36591ba1 SL |
531 | 0x003fffc0, |
532 | 0x003fffc0, | |
0a1b45a2 | 533 | false), |
36591ba1 SL |
534 | |
535 | HOWTO (R_NIOS2_TLS_LE16, | |
536 | 0, | |
c94cb026 | 537 | 4, |
36591ba1 | 538 | 16, |
0a1b45a2 | 539 | false, |
36591ba1 SL |
540 | 6, |
541 | complain_overflow_bitfield, | |
542 | bfd_elf_generic_reloc, | |
543 | "R_NIOS2_TLS_LE16", | |
0a1b45a2 | 544 | false, |
36591ba1 SL |
545 | 0x003fffc0, |
546 | 0x003fffc0, | |
0a1b45a2 | 547 | false), |
36591ba1 SL |
548 | |
549 | HOWTO (R_NIOS2_TLS_DTPMOD, | |
550 | 0, | |
c94cb026 | 551 | 4, |
36591ba1 | 552 | 32, |
0a1b45a2 | 553 | false, |
36591ba1 SL |
554 | 0, |
555 | complain_overflow_dont, | |
556 | bfd_elf_generic_reloc, | |
557 | "R_NIOS2_TLS_DTPMOD", | |
0a1b45a2 | 558 | false, |
36591ba1 SL |
559 | 0xffffffff, |
560 | 0xffffffff, | |
0a1b45a2 | 561 | false), |
36591ba1 SL |
562 | |
563 | HOWTO (R_NIOS2_TLS_DTPREL, | |
564 | 0, | |
c94cb026 | 565 | 4, |
36591ba1 | 566 | 32, |
0a1b45a2 | 567 | false, |
36591ba1 SL |
568 | 0, |
569 | complain_overflow_dont, | |
570 | bfd_elf_generic_reloc, | |
571 | "R_NIOS2_TLS_DTPREL", | |
0a1b45a2 | 572 | false, |
36591ba1 SL |
573 | 0xffffffff, |
574 | 0xffffffff, | |
0a1b45a2 | 575 | false), |
36591ba1 SL |
576 | |
577 | HOWTO (R_NIOS2_TLS_TPREL, | |
578 | 0, | |
c94cb026 | 579 | 4, |
36591ba1 | 580 | 32, |
0a1b45a2 | 581 | false, |
36591ba1 SL |
582 | 0, |
583 | complain_overflow_dont, | |
584 | bfd_elf_generic_reloc, | |
585 | "R_NIOS2_TLS_TPREL", | |
0a1b45a2 | 586 | false, |
36591ba1 SL |
587 | 0xffffffff, |
588 | 0xffffffff, | |
0a1b45a2 | 589 | false), |
36591ba1 SL |
590 | |
591 | HOWTO (R_NIOS2_COPY, | |
592 | 0, | |
c94cb026 | 593 | 4, |
36591ba1 | 594 | 32, |
0a1b45a2 | 595 | false, |
36591ba1 SL |
596 | 0, |
597 | complain_overflow_dont, | |
598 | bfd_elf_generic_reloc, | |
599 | "R_NIOS2_COPY", | |
0a1b45a2 | 600 | false, |
36591ba1 SL |
601 | 0, |
602 | 0, | |
0a1b45a2 | 603 | false), |
36591ba1 SL |
604 | |
605 | HOWTO (R_NIOS2_GLOB_DAT, | |
606 | 0, | |
c94cb026 | 607 | 4, |
36591ba1 | 608 | 32, |
0a1b45a2 | 609 | false, |
36591ba1 SL |
610 | 0, |
611 | complain_overflow_dont, | |
612 | bfd_elf_generic_reloc, | |
613 | "R_NIOS2_GLOB_DAT", | |
0a1b45a2 | 614 | false, |
36591ba1 SL |
615 | 0xffffffff, |
616 | 0xffffffff, | |
0a1b45a2 | 617 | false), |
36591ba1 SL |
618 | |
619 | HOWTO (R_NIOS2_JUMP_SLOT, | |
620 | 0, | |
c94cb026 | 621 | 4, |
36591ba1 | 622 | 32, |
0a1b45a2 | 623 | false, |
36591ba1 SL |
624 | 0, |
625 | complain_overflow_dont, | |
626 | bfd_elf_generic_reloc, | |
627 | "R_NIOS2_JUMP_SLOT", | |
0a1b45a2 | 628 | false, |
36591ba1 SL |
629 | 0xffffffff, |
630 | 0xffffffff, | |
0a1b45a2 | 631 | false), |
36591ba1 SL |
632 | |
633 | HOWTO (R_NIOS2_RELATIVE, | |
634 | 0, | |
c94cb026 | 635 | 4, |
36591ba1 | 636 | 32, |
0a1b45a2 | 637 | false, |
36591ba1 SL |
638 | 0, |
639 | complain_overflow_dont, | |
640 | bfd_elf_generic_reloc, | |
641 | "R_NIOS2_RELATIVE", | |
0a1b45a2 | 642 | false, |
36591ba1 SL |
643 | 0xffffffff, |
644 | 0xffffffff, | |
0a1b45a2 | 645 | false), |
36591ba1 SL |
646 | |
647 | HOWTO (R_NIOS2_GOTOFF, | |
648 | 0, | |
c94cb026 | 649 | 4, |
36591ba1 | 650 | 32, |
0a1b45a2 | 651 | false, |
36591ba1 SL |
652 | 0, |
653 | complain_overflow_dont, | |
654 | bfd_elf_generic_reloc, | |
655 | "R_NIOS2_GOTOFF", | |
0a1b45a2 | 656 | false, |
36591ba1 SL |
657 | 0xffffffff, |
658 | 0xffffffff, | |
0a1b45a2 | 659 | false), |
36591ba1 | 660 | |
78058a5e SL |
661 | HOWTO (R_NIOS2_CALL26_NOAT, /* type */ |
662 | 2, /* rightshift */ | |
c94cb026 | 663 | 4, /* size */ |
78058a5e | 664 | 26, /* bitsize */ |
0a1b45a2 | 665 | false, /* pc_relative */ |
78058a5e SL |
666 | 6, /* bitpos */ |
667 | complain_overflow_dont, /* complain on overflow */ | |
668 | nios2_elf32_call26_relocate, /* special function */ | |
669 | "R_NIOS2_CALL26_NOAT", /* name */ | |
0a1b45a2 | 670 | false, /* partial_inplace */ |
78058a5e SL |
671 | 0xffffffc0, /* src_mask */ |
672 | 0xffffffc0, /* dst_mask */ | |
0a1b45a2 | 673 | false), /* pcrel_offset */ |
78058a5e | 674 | |
1c2de463 SL |
675 | HOWTO (R_NIOS2_GOT_LO, |
676 | 0, | |
c94cb026 | 677 | 4, |
1c2de463 | 678 | 16, |
0a1b45a2 | 679 | false, |
1c2de463 SL |
680 | 6, |
681 | complain_overflow_dont, | |
682 | bfd_elf_generic_reloc, | |
683 | "R_NIOS2_GOT_LO", | |
0a1b45a2 | 684 | false, |
1c2de463 SL |
685 | 0x003fffc0, |
686 | 0x003fffc0, | |
0a1b45a2 | 687 | false), |
1c2de463 SL |
688 | |
689 | HOWTO (R_NIOS2_GOT_HA, | |
690 | 0, | |
c94cb026 | 691 | 4, |
1c2de463 | 692 | 16, |
0a1b45a2 | 693 | false, |
1c2de463 SL |
694 | 6, |
695 | complain_overflow_dont, | |
696 | bfd_elf_generic_reloc, | |
697 | "R_NIOS2_GOT_HA", | |
0a1b45a2 | 698 | false, |
1c2de463 SL |
699 | 0x003fffc0, |
700 | 0x003fffc0, | |
0a1b45a2 | 701 | false), |
1c2de463 SL |
702 | |
703 | HOWTO (R_NIOS2_CALL_LO, | |
704 | 0, | |
c94cb026 | 705 | 4, |
1c2de463 | 706 | 16, |
0a1b45a2 | 707 | false, |
1c2de463 SL |
708 | 6, |
709 | complain_overflow_dont, | |
710 | bfd_elf_generic_reloc, | |
711 | "R_NIOS2_CALL_LO", | |
0a1b45a2 | 712 | false, |
1c2de463 SL |
713 | 0x003fffc0, |
714 | 0x003fffc0, | |
0a1b45a2 | 715 | false), |
1c2de463 SL |
716 | |
717 | HOWTO (R_NIOS2_CALL_HA, | |
718 | 0, | |
c94cb026 | 719 | 4, |
1c2de463 | 720 | 16, |
0a1b45a2 | 721 | false, |
1c2de463 SL |
722 | 6, |
723 | complain_overflow_dont, | |
724 | bfd_elf_generic_reloc, | |
725 | "R_NIOS2_CALL_HA", | |
0a1b45a2 | 726 | false, |
1c2de463 SL |
727 | 0x003fffc0, |
728 | 0x003fffc0, | |
0a1b45a2 | 729 | false), |
1c2de463 | 730 | |
36591ba1 SL |
731 | /* Add other relocations here. */ |
732 | }; | |
733 | ||
8c163c5a SL |
734 | static reloc_howto_type elf_nios2_r2_howto_table_rel[] = { |
735 | /* No relocation. */ | |
736 | HOWTO (R_NIOS2_NONE, /* type */ | |
737 | 0, /* rightshift */ | |
c94cb026 | 738 | 0, /* size */ |
8c163c5a | 739 | 0, /* bitsize */ |
0a1b45a2 | 740 | false, /* pc_relative */ |
8c163c5a SL |
741 | 0, /* bitpos */ |
742 | complain_overflow_dont, /* complain_on_overflow */ | |
743 | bfd_elf_generic_reloc, /* special_function */ | |
744 | "R_NIOS2_NONE", /* name */ | |
0a1b45a2 | 745 | false, /* partial_inplace */ |
8c163c5a SL |
746 | 0, /* src_mask */ |
747 | 0, /* dst_mask */ | |
0a1b45a2 | 748 | false), /* pcrel_offset */ |
8c163c5a SL |
749 | |
750 | /* 16-bit signed immediate relocation. */ | |
751 | HOWTO (R_NIOS2_S16, /* type */ | |
752 | 0, /* rightshift */ | |
c94cb026 | 753 | 4, /* size */ |
8c163c5a | 754 | 16, /* bitsize */ |
0a1b45a2 | 755 | false, /* pc_relative */ |
8c163c5a SL |
756 | 16, /* bitpos */ |
757 | complain_overflow_signed, /* complain on overflow */ | |
758 | bfd_elf_generic_reloc, /* special function */ | |
759 | "R_NIOS2_S16", /* name */ | |
0a1b45a2 | 760 | false, /* partial_inplace */ |
8c163c5a SL |
761 | 0xffff0000, /* src_mask */ |
762 | 0xffff0000, /* dest_mask */ | |
0a1b45a2 | 763 | false), /* pcrel_offset */ |
8c163c5a SL |
764 | |
765 | /* 16-bit unsigned immediate relocation. */ | |
766 | HOWTO (R_NIOS2_U16, /* type */ | |
767 | 0, /* rightshift */ | |
c94cb026 | 768 | 4, /* size */ |
8c163c5a | 769 | 16, /* bitsize */ |
0a1b45a2 | 770 | false, /* pc_relative */ |
8c163c5a SL |
771 | 16, /* bitpos */ |
772 | complain_overflow_unsigned, /* complain on overflow */ | |
773 | bfd_elf_generic_reloc, /* special function */ | |
774 | "R_NIOS2_U16", /* name */ | |
0a1b45a2 | 775 | false, /* partial_inplace */ |
8c163c5a SL |
776 | 0xffff0000, /* src_mask */ |
777 | 0xffff0000, /* dest_mask */ | |
0a1b45a2 | 778 | false), /* pcrel_offset */ |
8c163c5a SL |
779 | |
780 | HOWTO (R_NIOS2_PCREL16, /* type */ | |
781 | 0, /* rightshift */ | |
c94cb026 | 782 | 4, /* size */ |
8c163c5a | 783 | 16, /* bitsize */ |
0a1b45a2 | 784 | true, /* pc_relative */ |
8c163c5a SL |
785 | 16, /* bitpos */ |
786 | complain_overflow_signed, /* complain on overflow */ | |
787 | nios2_elf32_pcrel16_relocate, /* special function */ | |
788 | "R_NIOS2_PCREL16", /* name */ | |
0a1b45a2 | 789 | false, /* partial_inplace */ |
8c163c5a SL |
790 | 0xffff0000, /* src_mask */ |
791 | 0xffff0000, /* dest_mask */ | |
0a1b45a2 | 792 | true), /* pcrel_offset */ |
8c163c5a SL |
793 | |
794 | HOWTO (R_NIOS2_CALL26, /* type */ | |
795 | 2, /* rightshift */ | |
c94cb026 | 796 | 4, /* size */ |
8c163c5a | 797 | 26, /* bitsize */ |
0a1b45a2 | 798 | false, /* pc_relative */ |
8c163c5a SL |
799 | 6, /* bitpos */ |
800 | complain_overflow_dont, /* complain on overflow */ | |
801 | nios2_elf32_call26_relocate, /* special function */ | |
802 | "R_NIOS2_CALL26", /* name */ | |
0a1b45a2 | 803 | false, /* partial_inplace */ |
8c163c5a SL |
804 | 0xffffffc0, /* src_mask */ |
805 | 0xffffffc0, /* dst_mask */ | |
0a1b45a2 | 806 | false), /* pcrel_offset */ |
8c163c5a SL |
807 | |
808 | HOWTO (R_NIOS2_IMM5, | |
809 | 0, | |
c94cb026 | 810 | 4, |
8c163c5a | 811 | 5, |
0a1b45a2 | 812 | false, |
8c163c5a SL |
813 | 21, |
814 | complain_overflow_bitfield, | |
815 | bfd_elf_generic_reloc, | |
816 | "R_NIOS2_IMM5", | |
0a1b45a2 | 817 | false, |
8c163c5a SL |
818 | 0x03e00000, |
819 | 0x03e00000, | |
0a1b45a2 | 820 | false), |
8c163c5a SL |
821 | |
822 | HOWTO (R_NIOS2_CACHE_OPX, | |
823 | 0, | |
c94cb026 | 824 | 4, |
8c163c5a | 825 | 5, |
0a1b45a2 | 826 | false, |
8c163c5a SL |
827 | 11, |
828 | complain_overflow_bitfield, | |
829 | bfd_elf_generic_reloc, | |
830 | "R_NIOS2_CACHE_OPX", | |
0a1b45a2 | 831 | false, |
8c163c5a SL |
832 | 0x0000f800, |
833 | 0x0000f800, | |
0a1b45a2 | 834 | false), |
8c163c5a SL |
835 | |
836 | HOWTO (R_NIOS2_IMM6, | |
837 | 0, | |
c94cb026 | 838 | 4, |
8c163c5a | 839 | 6, |
0a1b45a2 | 840 | false, |
8c163c5a SL |
841 | 26, |
842 | complain_overflow_bitfield, | |
843 | bfd_elf_generic_reloc, | |
844 | "R_NIOS2_IMM6", | |
0a1b45a2 | 845 | false, |
8c163c5a SL |
846 | 0xfc000000, |
847 | 0xfc000000, | |
0a1b45a2 | 848 | false), |
8c163c5a SL |
849 | |
850 | HOWTO (R_NIOS2_IMM8, | |
851 | 0, | |
c94cb026 | 852 | 4, |
8c163c5a | 853 | 8, |
0a1b45a2 | 854 | false, |
8c163c5a SL |
855 | 24, |
856 | complain_overflow_bitfield, | |
857 | bfd_elf_generic_reloc, | |
858 | "R_NIOS2_IMM8", | |
0a1b45a2 | 859 | false, |
8c163c5a SL |
860 | 0xff000000, |
861 | 0xff000000, | |
0a1b45a2 | 862 | false), |
8c163c5a SL |
863 | |
864 | HOWTO (R_NIOS2_HI16, | |
865 | 0, | |
c94cb026 | 866 | 4, |
8c163c5a | 867 | 32, |
0a1b45a2 | 868 | false, |
8c163c5a SL |
869 | 16, |
870 | complain_overflow_dont, | |
871 | nios2_elf32_hi16_relocate, | |
872 | "R_NIOS2_HI16", | |
0a1b45a2 | 873 | false, |
8c163c5a SL |
874 | 0xffff0000, |
875 | 0xffff0000, | |
0a1b45a2 | 876 | false), |
8c163c5a SL |
877 | |
878 | HOWTO (R_NIOS2_LO16, | |
879 | 0, | |
c94cb026 | 880 | 4, |
8c163c5a | 881 | 32, |
0a1b45a2 | 882 | false, |
8c163c5a SL |
883 | 16, |
884 | complain_overflow_dont, | |
885 | nios2_elf32_lo16_relocate, | |
886 | "R_NIOS2_LO16", | |
0a1b45a2 | 887 | false, |
8c163c5a SL |
888 | 0xffff0000, |
889 | 0xffff0000, | |
0a1b45a2 | 890 | false), |
8c163c5a SL |
891 | |
892 | HOWTO (R_NIOS2_HIADJ16, | |
893 | 0, | |
c94cb026 | 894 | 4, |
8c163c5a | 895 | 32, |
0a1b45a2 | 896 | false, |
8c163c5a SL |
897 | 16, |
898 | complain_overflow_dont, | |
899 | nios2_elf32_hiadj16_relocate, | |
900 | "R_NIOS2_HIADJ16", | |
0a1b45a2 | 901 | false, |
8c163c5a SL |
902 | 0xffff0000, |
903 | 0xffff0000, | |
0a1b45a2 | 904 | false), |
8c163c5a SL |
905 | |
906 | HOWTO (R_NIOS2_BFD_RELOC_32, | |
907 | 0, | |
c94cb026 | 908 | 4, /* long */ |
8c163c5a | 909 | 32, |
0a1b45a2 | 910 | false, |
8c163c5a SL |
911 | 0, |
912 | complain_overflow_dont, | |
913 | bfd_elf_generic_reloc, | |
914 | "R_NIOS2_BFD_RELOC32", | |
0a1b45a2 | 915 | false, |
8c163c5a SL |
916 | 0xffffffff, |
917 | 0xffffffff, | |
0a1b45a2 | 918 | false), |
8c163c5a SL |
919 | |
920 | HOWTO (R_NIOS2_BFD_RELOC_16, | |
921 | 0, | |
c94cb026 | 922 | 2, /* short */ |
8c163c5a | 923 | 16, |
0a1b45a2 | 924 | false, |
8c163c5a SL |
925 | 0, |
926 | complain_overflow_bitfield, | |
927 | bfd_elf_generic_reloc, | |
928 | "R_NIOS2_BFD_RELOC16", | |
0a1b45a2 | 929 | false, |
8c163c5a SL |
930 | 0x0000ffff, |
931 | 0x0000ffff, | |
0a1b45a2 | 932 | false), |
8c163c5a SL |
933 | |
934 | HOWTO (R_NIOS2_BFD_RELOC_8, | |
935 | 0, | |
c94cb026 | 936 | 1, /* byte */ |
8c163c5a | 937 | 8, |
0a1b45a2 | 938 | false, |
8c163c5a SL |
939 | 0, |
940 | complain_overflow_bitfield, | |
941 | bfd_elf_generic_reloc, | |
942 | "R_NIOS2_BFD_RELOC8", | |
0a1b45a2 | 943 | false, |
8c163c5a SL |
944 | 0x000000ff, |
945 | 0x000000ff, | |
0a1b45a2 | 946 | false), |
8c163c5a SL |
947 | |
948 | HOWTO (R_NIOS2_GPREL, | |
949 | 0, | |
c94cb026 | 950 | 4, |
8c163c5a | 951 | 32, |
0a1b45a2 | 952 | false, |
8c163c5a SL |
953 | 16, |
954 | complain_overflow_dont, | |
955 | nios2_elf32_gprel_relocate, | |
956 | "R_NIOS2_GPREL", | |
0a1b45a2 | 957 | false, |
8c163c5a SL |
958 | 0xffff0000, |
959 | 0xffff0000, | |
0a1b45a2 | 960 | false), |
8c163c5a SL |
961 | |
962 | HOWTO (R_NIOS2_GNU_VTINHERIT, | |
963 | 0, | |
c94cb026 | 964 | 4, |
8c163c5a | 965 | 0, |
0a1b45a2 | 966 | false, |
8c163c5a SL |
967 | 0, |
968 | complain_overflow_dont, | |
969 | NULL, | |
970 | "R_NIOS2_GNU_VTINHERIT", | |
0a1b45a2 | 971 | false, |
8c163c5a SL |
972 | 0, |
973 | 0, | |
0a1b45a2 | 974 | false), |
8c163c5a SL |
975 | |
976 | HOWTO (R_NIOS2_GNU_VTENTRY, | |
977 | 0, | |
c94cb026 | 978 | 4, |
8c163c5a | 979 | 0, |
0a1b45a2 | 980 | false, |
8c163c5a SL |
981 | 0, |
982 | complain_overflow_dont, | |
983 | _bfd_elf_rel_vtable_reloc_fn, | |
984 | "R_NIOS2_GNU_VTENTRY", | |
0a1b45a2 | 985 | false, |
8c163c5a SL |
986 | 0, |
987 | 0, | |
0a1b45a2 | 988 | false), |
8c163c5a SL |
989 | |
990 | HOWTO (R_NIOS2_UJMP, | |
991 | 0, | |
c94cb026 | 992 | 4, |
8c163c5a | 993 | 32, |
0a1b45a2 | 994 | false, |
8c163c5a SL |
995 | 16, |
996 | complain_overflow_dont, | |
997 | nios2_elf32_ujmp_relocate, | |
998 | "R_NIOS2_UJMP", | |
0a1b45a2 | 999 | false, |
8c163c5a SL |
1000 | 0xffff0000, |
1001 | 0xffff0000, | |
0a1b45a2 | 1002 | false), |
8c163c5a SL |
1003 | |
1004 | HOWTO (R_NIOS2_CJMP, | |
1005 | 0, | |
c94cb026 | 1006 | 4, |
8c163c5a | 1007 | 32, |
0a1b45a2 | 1008 | false, |
8c163c5a SL |
1009 | 16, |
1010 | complain_overflow_dont, | |
1011 | nios2_elf32_cjmp_relocate, | |
1012 | "R_NIOS2_CJMP", | |
0a1b45a2 | 1013 | false, |
8c163c5a SL |
1014 | 0xffff0000, |
1015 | 0xffff0000, | |
0a1b45a2 | 1016 | false), |
8c163c5a SL |
1017 | |
1018 | HOWTO (R_NIOS2_CALLR, | |
1019 | 0, | |
c94cb026 | 1020 | 4, |
8c163c5a | 1021 | 32, |
0a1b45a2 | 1022 | false, |
8c163c5a SL |
1023 | 16, |
1024 | complain_overflow_dont, | |
1025 | nios2_elf32_callr_relocate, | |
1026 | "R_NIOS2_CALLR", | |
0a1b45a2 | 1027 | false, |
8c163c5a SL |
1028 | 0xffff0000, |
1029 | 0xffff0000, | |
0a1b45a2 | 1030 | false), |
8c163c5a SL |
1031 | |
1032 | HOWTO (R_NIOS2_ALIGN, | |
1033 | 0, | |
c94cb026 | 1034 | 4, |
8c163c5a | 1035 | 0, |
0a1b45a2 | 1036 | false, |
8c163c5a SL |
1037 | 0, |
1038 | complain_overflow_dont, | |
1039 | nios2_elf32_ignore_reloc, | |
1040 | "R_NIOS2_ALIGN", | |
0a1b45a2 | 1041 | false, |
8c163c5a SL |
1042 | 0, |
1043 | 0, | |
0a1b45a2 | 1044 | true), |
8c163c5a SL |
1045 | |
1046 | HOWTO (R_NIOS2_GOT16, | |
1047 | 0, | |
c94cb026 | 1048 | 4, |
8c163c5a | 1049 | 16, |
0a1b45a2 | 1050 | false, |
8c163c5a SL |
1051 | 16, |
1052 | complain_overflow_bitfield, | |
1053 | bfd_elf_generic_reloc, | |
1054 | "R_NIOS2_GOT16", | |
0a1b45a2 | 1055 | false, |
8c163c5a SL |
1056 | 0xffff0000, |
1057 | 0xffff0000, | |
0a1b45a2 | 1058 | false), |
8c163c5a SL |
1059 | |
1060 | HOWTO (R_NIOS2_CALL16, | |
1061 | 0, | |
c94cb026 | 1062 | 4, |
8c163c5a | 1063 | 16, |
0a1b45a2 | 1064 | false, |
8c163c5a SL |
1065 | 16, |
1066 | complain_overflow_bitfield, | |
1067 | bfd_elf_generic_reloc, | |
1068 | "R_NIOS2_CALL16", | |
0a1b45a2 | 1069 | false, |
8c163c5a SL |
1070 | 0xffff0000, |
1071 | 0xffff0000, | |
0a1b45a2 | 1072 | false), |
8c163c5a SL |
1073 | |
1074 | HOWTO (R_NIOS2_GOTOFF_LO, | |
1075 | 0, | |
c94cb026 | 1076 | 4, |
8c163c5a | 1077 | 16, |
0a1b45a2 | 1078 | false, |
8c163c5a SL |
1079 | 16, |
1080 | complain_overflow_dont, | |
1081 | bfd_elf_generic_reloc, | |
1082 | "R_NIOS2_GOTOFF_LO", | |
0a1b45a2 | 1083 | false, |
8c163c5a SL |
1084 | 0xffff0000, |
1085 | 0xffff0000, | |
0a1b45a2 | 1086 | false), |
8c163c5a SL |
1087 | |
1088 | HOWTO (R_NIOS2_GOTOFF_HA, | |
1089 | 0, | |
c94cb026 | 1090 | 4, |
8c163c5a | 1091 | 16, |
0a1b45a2 | 1092 | false, |
8c163c5a SL |
1093 | 16, |
1094 | complain_overflow_dont, | |
1095 | bfd_elf_generic_reloc, | |
1096 | "R_NIOS2_GOTOFF_HA", | |
0a1b45a2 | 1097 | false, |
8c163c5a SL |
1098 | 0xffff0000, |
1099 | 0xffff0000, | |
0a1b45a2 | 1100 | false), |
8c163c5a SL |
1101 | |
1102 | HOWTO (R_NIOS2_PCREL_LO, | |
1103 | 0, | |
c94cb026 | 1104 | 4, |
8c163c5a | 1105 | 16, |
0a1b45a2 | 1106 | true, |
8c163c5a SL |
1107 | 16, |
1108 | complain_overflow_dont, | |
1109 | nios2_elf32_pcrel_lo16_relocate, | |
1110 | "R_NIOS2_PCREL_LO", | |
0a1b45a2 | 1111 | false, |
8c163c5a SL |
1112 | 0xffff0000, |
1113 | 0xffff0000, | |
0a1b45a2 | 1114 | true), |
8c163c5a SL |
1115 | |
1116 | HOWTO (R_NIOS2_PCREL_HA, | |
1117 | 0, | |
c94cb026 | 1118 | 4, |
8c163c5a | 1119 | 16, |
0a1b45a2 | 1120 | false, /* This is a PC-relative relocation, but we need to subtract |
8c163c5a SL |
1121 | PC ourselves before the HIADJ. */ |
1122 | 16, | |
1123 | complain_overflow_dont, | |
1124 | nios2_elf32_pcrel_hiadj16_relocate, | |
1125 | "R_NIOS2_PCREL_HA", | |
0a1b45a2 | 1126 | false, |
8c163c5a SL |
1127 | 0xffff0000, |
1128 | 0xffff0000, | |
0a1b45a2 | 1129 | true), |
8c163c5a SL |
1130 | |
1131 | HOWTO (R_NIOS2_TLS_GD16, | |
1132 | 0, | |
c94cb026 | 1133 | 4, |
8c163c5a | 1134 | 16, |
0a1b45a2 | 1135 | false, |
8c163c5a SL |
1136 | 16, |
1137 | complain_overflow_bitfield, | |
1138 | bfd_elf_generic_reloc, | |
1139 | "R_NIOS2_TLS_GD16", | |
0a1b45a2 | 1140 | false, |
8c163c5a SL |
1141 | 0xffff0000, |
1142 | 0xffff0000, | |
0a1b45a2 | 1143 | false), |
8c163c5a SL |
1144 | |
1145 | HOWTO (R_NIOS2_TLS_LDM16, | |
1146 | 0, | |
c94cb026 | 1147 | 4, |
8c163c5a | 1148 | 16, |
0a1b45a2 | 1149 | false, |
8c163c5a SL |
1150 | 16, |
1151 | complain_overflow_bitfield, | |
1152 | bfd_elf_generic_reloc, | |
1153 | "R_NIOS2_TLS_LDM16", | |
0a1b45a2 | 1154 | false, |
8c163c5a SL |
1155 | 0xffff0000, |
1156 | 0xffff0000, | |
0a1b45a2 | 1157 | false), |
8c163c5a SL |
1158 | |
1159 | HOWTO (R_NIOS2_TLS_LDO16, | |
1160 | 0, | |
c94cb026 | 1161 | 4, |
8c163c5a | 1162 | 16, |
0a1b45a2 | 1163 | false, |
8c163c5a SL |
1164 | 16, |
1165 | complain_overflow_bitfield, | |
1166 | bfd_elf_generic_reloc, | |
1167 | "R_NIOS2_TLS_LDO16", | |
0a1b45a2 | 1168 | false, |
8c163c5a SL |
1169 | 0xffff0000, |
1170 | 0xffff0000, | |
0a1b45a2 | 1171 | false), |
8c163c5a SL |
1172 | |
1173 | HOWTO (R_NIOS2_TLS_IE16, | |
1174 | 0, | |
c94cb026 | 1175 | 4, |
8c163c5a | 1176 | 16, |
0a1b45a2 | 1177 | false, |
8c163c5a SL |
1178 | 16, |
1179 | complain_overflow_bitfield, | |
1180 | bfd_elf_generic_reloc, | |
1181 | "R_NIOS2_TLS_IE16", | |
0a1b45a2 | 1182 | false, |
8c163c5a SL |
1183 | 0xffff0000, |
1184 | 0xffff0000, | |
0a1b45a2 | 1185 | false), |
8c163c5a SL |
1186 | |
1187 | HOWTO (R_NIOS2_TLS_LE16, | |
1188 | 0, | |
c94cb026 | 1189 | 4, |
8c163c5a | 1190 | 16, |
0a1b45a2 | 1191 | false, |
8c163c5a SL |
1192 | 16, |
1193 | complain_overflow_bitfield, | |
1194 | bfd_elf_generic_reloc, | |
1195 | "R_NIOS2_TLS_LE16", | |
0a1b45a2 | 1196 | false, |
8c163c5a SL |
1197 | 0xffff0000, |
1198 | 0xffff0000, | |
0a1b45a2 | 1199 | false), |
8c163c5a SL |
1200 | |
1201 | HOWTO (R_NIOS2_TLS_DTPMOD, | |
1202 | 0, | |
c94cb026 | 1203 | 4, |
8c163c5a | 1204 | 32, |
0a1b45a2 | 1205 | false, |
8c163c5a SL |
1206 | 0, |
1207 | complain_overflow_dont, | |
1208 | bfd_elf_generic_reloc, | |
1209 | "R_NIOS2_TLS_DTPMOD", | |
0a1b45a2 | 1210 | false, |
8c163c5a SL |
1211 | 0xffffffff, |
1212 | 0xffffffff, | |
0a1b45a2 | 1213 | false), |
8c163c5a SL |
1214 | |
1215 | HOWTO (R_NIOS2_TLS_DTPREL, | |
1216 | 0, | |
c94cb026 | 1217 | 4, |
8c163c5a | 1218 | 32, |
0a1b45a2 | 1219 | false, |
8c163c5a SL |
1220 | 0, |
1221 | complain_overflow_dont, | |
1222 | bfd_elf_generic_reloc, | |
1223 | "R_NIOS2_TLS_DTPREL", | |
0a1b45a2 | 1224 | false, |
8c163c5a SL |
1225 | 0xffffffff, |
1226 | 0xffffffff, | |
0a1b45a2 | 1227 | false), |
8c163c5a SL |
1228 | |
1229 | HOWTO (R_NIOS2_TLS_TPREL, | |
1230 | 0, | |
c94cb026 | 1231 | 4, |
8c163c5a | 1232 | 32, |
0a1b45a2 | 1233 | false, |
8c163c5a SL |
1234 | 0, |
1235 | complain_overflow_dont, | |
1236 | bfd_elf_generic_reloc, | |
1237 | "R_NIOS2_TLS_TPREL", | |
0a1b45a2 | 1238 | false, |
8c163c5a SL |
1239 | 0xffffffff, |
1240 | 0xffffffff, | |
0a1b45a2 | 1241 | false), |
8c163c5a SL |
1242 | |
1243 | HOWTO (R_NIOS2_COPY, | |
1244 | 0, | |
c94cb026 | 1245 | 4, |
8c163c5a | 1246 | 32, |
0a1b45a2 | 1247 | false, |
8c163c5a SL |
1248 | 0, |
1249 | complain_overflow_dont, | |
1250 | bfd_elf_generic_reloc, | |
1251 | "R_NIOS2_COPY", | |
0a1b45a2 | 1252 | false, |
8c163c5a SL |
1253 | 0, |
1254 | 0, | |
0a1b45a2 | 1255 | false), |
8c163c5a SL |
1256 | |
1257 | HOWTO (R_NIOS2_GLOB_DAT, | |
1258 | 0, | |
c94cb026 | 1259 | 4, |
8c163c5a | 1260 | 32, |
0a1b45a2 | 1261 | false, |
8c163c5a SL |
1262 | 0, |
1263 | complain_overflow_dont, | |
1264 | bfd_elf_generic_reloc, | |
1265 | "R_NIOS2_GLOB_DAT", | |
0a1b45a2 | 1266 | false, |
8c163c5a SL |
1267 | 0xffffffff, |
1268 | 0xffffffff, | |
0a1b45a2 | 1269 | false), |
8c163c5a SL |
1270 | |
1271 | HOWTO (R_NIOS2_JUMP_SLOT, | |
1272 | 0, | |
c94cb026 | 1273 | 4, |
8c163c5a | 1274 | 32, |
0a1b45a2 | 1275 | false, |
8c163c5a SL |
1276 | 0, |
1277 | complain_overflow_dont, | |
1278 | bfd_elf_generic_reloc, | |
1279 | "R_NIOS2_JUMP_SLOT", | |
0a1b45a2 | 1280 | false, |
8c163c5a SL |
1281 | 0xffffffff, |
1282 | 0xffffffff, | |
0a1b45a2 | 1283 | false), |
8c163c5a SL |
1284 | |
1285 | HOWTO (R_NIOS2_RELATIVE, | |
1286 | 0, | |
c94cb026 | 1287 | 4, |
8c163c5a | 1288 | 32, |
0a1b45a2 | 1289 | false, |
8c163c5a SL |
1290 | 0, |
1291 | complain_overflow_dont, | |
1292 | bfd_elf_generic_reloc, | |
1293 | "R_NIOS2_RELATIVE", | |
0a1b45a2 | 1294 | false, |
8c163c5a SL |
1295 | 0xffffffff, |
1296 | 0xffffffff, | |
0a1b45a2 | 1297 | false), |
8c163c5a SL |
1298 | |
1299 | HOWTO (R_NIOS2_GOTOFF, | |
1300 | 0, | |
c94cb026 | 1301 | 4, |
8c163c5a | 1302 | 32, |
0a1b45a2 | 1303 | false, |
8c163c5a SL |
1304 | 0, |
1305 | complain_overflow_dont, | |
1306 | bfd_elf_generic_reloc, | |
1307 | "R_NIOS2_GOTOFF", | |
0a1b45a2 | 1308 | false, |
8c163c5a SL |
1309 | 0xffffffff, |
1310 | 0xffffffff, | |
0a1b45a2 | 1311 | false), |
8c163c5a SL |
1312 | |
1313 | HOWTO (R_NIOS2_CALL26_NOAT, /* type */ | |
1314 | 2, /* rightshift */ | |
c94cb026 | 1315 | 4, /* size */ |
8c163c5a | 1316 | 26, /* bitsize */ |
0a1b45a2 | 1317 | false, /* pc_relative */ |
8c163c5a SL |
1318 | 6, /* bitpos */ |
1319 | complain_overflow_dont, /* complain on overflow */ | |
1320 | nios2_elf32_call26_relocate, /* special function */ | |
1321 | "R_NIOS2_CALL26_NOAT", /* name */ | |
0a1b45a2 | 1322 | false, /* partial_inplace */ |
8c163c5a SL |
1323 | 0xffffffc0, /* src_mask */ |
1324 | 0xffffffc0, /* dst_mask */ | |
0a1b45a2 | 1325 | false), /* pcrel_offset */ |
8c163c5a SL |
1326 | |
1327 | HOWTO (R_NIOS2_GOT_LO, | |
1328 | 0, | |
c94cb026 | 1329 | 4, |
8c163c5a | 1330 | 16, |
0a1b45a2 | 1331 | false, |
8c163c5a SL |
1332 | 16, |
1333 | complain_overflow_dont, | |
1334 | bfd_elf_generic_reloc, | |
1335 | "R_NIOS2_GOT_LO", | |
0a1b45a2 | 1336 | false, |
8c163c5a SL |
1337 | 0xffff0000, |
1338 | 0xffff0000, | |
0a1b45a2 | 1339 | false), |
8c163c5a SL |
1340 | |
1341 | HOWTO (R_NIOS2_GOT_HA, | |
1342 | 0, | |
c94cb026 | 1343 | 4, |
8c163c5a | 1344 | 16, |
0a1b45a2 | 1345 | false, |
8c163c5a SL |
1346 | 16, |
1347 | complain_overflow_dont, | |
1348 | bfd_elf_generic_reloc, | |
1349 | "R_NIOS2_GOT_HA", | |
0a1b45a2 | 1350 | false, |
8c163c5a SL |
1351 | 0xffff0000, |
1352 | 0xffff0000, | |
0a1b45a2 | 1353 | false), |
8c163c5a SL |
1354 | |
1355 | HOWTO (R_NIOS2_CALL_LO, | |
1356 | 0, | |
c94cb026 | 1357 | 4, |
8c163c5a | 1358 | 16, |
0a1b45a2 | 1359 | false, |
8c163c5a SL |
1360 | 16, |
1361 | complain_overflow_dont, | |
1362 | bfd_elf_generic_reloc, | |
1363 | "R_NIOS2_CALL_LO", | |
0a1b45a2 | 1364 | false, |
8c163c5a SL |
1365 | 0xffff0000, |
1366 | 0xffff0000, | |
0a1b45a2 | 1367 | false), |
8c163c5a SL |
1368 | |
1369 | HOWTO (R_NIOS2_CALL_HA, | |
1370 | 0, | |
c94cb026 | 1371 | 4, |
8c163c5a | 1372 | 16, |
0a1b45a2 | 1373 | false, |
8c163c5a SL |
1374 | 16, |
1375 | complain_overflow_dont, | |
1376 | bfd_elf_generic_reloc, | |
1377 | "R_NIOS2_CALL_HA", | |
0a1b45a2 | 1378 | false, |
8c163c5a SL |
1379 | 0xffff0000, |
1380 | 0xffff0000, | |
0a1b45a2 | 1381 | false), |
8c163c5a SL |
1382 | |
1383 | HOWTO (R_NIOS2_R2_S12, | |
1384 | 0, | |
c94cb026 | 1385 | 4, |
8c163c5a | 1386 | 12, |
0a1b45a2 | 1387 | false, |
8c163c5a SL |
1388 | 16, |
1389 | complain_overflow_signed, | |
1390 | bfd_elf_generic_reloc, | |
1391 | "R_NIOS2_R2_S12", | |
0a1b45a2 | 1392 | false, |
8c163c5a SL |
1393 | 0x0fff0000, |
1394 | 0x0fff0000, | |
0a1b45a2 | 1395 | false), |
8c163c5a SL |
1396 | |
1397 | HOWTO (R_NIOS2_R2_I10_1_PCREL, | |
1398 | 1, | |
c94cb026 | 1399 | 2, |
8c163c5a | 1400 | 10, |
0a1b45a2 | 1401 | true, |
8c163c5a SL |
1402 | 6, |
1403 | complain_overflow_signed, | |
07d6d2b8 | 1404 | bfd_elf_generic_reloc, /* FIXME? */ |
8c163c5a | 1405 | "R_NIOS2_R2_I10_1_PCREL", |
0a1b45a2 | 1406 | false, |
8c163c5a SL |
1407 | 0xffc0, |
1408 | 0xffc0, | |
0a1b45a2 | 1409 | true), |
8c163c5a SL |
1410 | |
1411 | HOWTO (R_NIOS2_R2_T1I7_1_PCREL, | |
1412 | 1, | |
c94cb026 | 1413 | 2, |
8c163c5a | 1414 | 7, |
0a1b45a2 | 1415 | true, |
8c163c5a SL |
1416 | 9, |
1417 | complain_overflow_signed, | |
1418 | bfd_elf_generic_reloc, /* FIXME? */ | |
1419 | "R_NIOS2_R2_T1I7_1_PCREL", | |
0a1b45a2 | 1420 | false, |
8c163c5a SL |
1421 | 0xfe00, |
1422 | 0xfe00, | |
0a1b45a2 | 1423 | true), |
1b786873 | 1424 | |
8c163c5a SL |
1425 | HOWTO (R_NIOS2_R2_T1I7_2, |
1426 | 2, | |
c94cb026 | 1427 | 2, |
8c163c5a | 1428 | 7, |
0a1b45a2 | 1429 | false, |
8c163c5a SL |
1430 | 9, |
1431 | complain_overflow_unsigned, | |
1432 | bfd_elf_generic_reloc, | |
1433 | "R_NIOS2_R2_T1I7_2", | |
0a1b45a2 | 1434 | false, |
8c163c5a SL |
1435 | 0xfe00, |
1436 | 0xfe00, | |
0a1b45a2 | 1437 | false), |
1b786873 | 1438 | |
8c163c5a SL |
1439 | HOWTO (R_NIOS2_R2_T2I4, |
1440 | 0, | |
c94cb026 | 1441 | 2, |
8c163c5a | 1442 | 4, |
0a1b45a2 | 1443 | false, |
8c163c5a SL |
1444 | 12, |
1445 | complain_overflow_unsigned, | |
1446 | bfd_elf_generic_reloc, | |
1447 | "R_NIOS2_R2_T2I4", | |
0a1b45a2 | 1448 | false, |
8c163c5a SL |
1449 | 0xf000, |
1450 | 0xf000, | |
0a1b45a2 | 1451 | false), |
8c163c5a SL |
1452 | |
1453 | HOWTO (R_NIOS2_R2_T2I4_1, | |
1454 | 1, | |
c94cb026 | 1455 | 2, |
8c163c5a | 1456 | 4, |
0a1b45a2 | 1457 | false, |
8c163c5a SL |
1458 | 12, |
1459 | complain_overflow_unsigned, | |
1460 | bfd_elf_generic_reloc, | |
1461 | "R_NIOS2_R2_T2I4_1", | |
0a1b45a2 | 1462 | false, |
8c163c5a SL |
1463 | 0xf000, |
1464 | 0xf000, | |
0a1b45a2 | 1465 | false), |
8c163c5a SL |
1466 | |
1467 | HOWTO (R_NIOS2_R2_T2I4_2, | |
1468 | 2, | |
c94cb026 | 1469 | 2, |
8c163c5a | 1470 | 4, |
0a1b45a2 | 1471 | false, |
8c163c5a SL |
1472 | 12, |
1473 | complain_overflow_unsigned, | |
1474 | bfd_elf_generic_reloc, | |
1475 | "R_NIOS2_R2_T2I4_2", | |
0a1b45a2 | 1476 | false, |
8c163c5a SL |
1477 | 0xf000, |
1478 | 0xf000, | |
0a1b45a2 | 1479 | false), |
8c163c5a SL |
1480 | |
1481 | HOWTO (R_NIOS2_R2_X1I7_2, | |
1482 | 2, | |
c94cb026 | 1483 | 2, |
8c163c5a | 1484 | 7, |
0a1b45a2 | 1485 | false, |
8c163c5a SL |
1486 | 6, |
1487 | complain_overflow_unsigned, | |
1488 | bfd_elf_generic_reloc, | |
1489 | "R_NIOS2_R2_X1I7_2", | |
0a1b45a2 | 1490 | false, |
8c163c5a SL |
1491 | 0x1fc0, |
1492 | 0x1fc0, | |
0a1b45a2 | 1493 | false), |
1b786873 | 1494 | |
8c163c5a SL |
1495 | HOWTO (R_NIOS2_R2_X2L5, |
1496 | 0, | |
c94cb026 | 1497 | 2, |
8c163c5a | 1498 | 5, |
0a1b45a2 | 1499 | false, |
8c163c5a SL |
1500 | 6, |
1501 | complain_overflow_unsigned, | |
1502 | bfd_elf_generic_reloc, | |
1503 | "R_NIOS2_R2_X2L5", | |
0a1b45a2 | 1504 | false, |
8c163c5a SL |
1505 | 0x07c0, |
1506 | 0x07c0, | |
0a1b45a2 | 1507 | false), |
1b786873 | 1508 | |
8c163c5a SL |
1509 | HOWTO (R_NIOS2_R2_F1I5_2, |
1510 | 2, | |
c94cb026 | 1511 | 2, |
8c163c5a | 1512 | 5, |
0a1b45a2 | 1513 | false, |
8c163c5a SL |
1514 | 6, |
1515 | complain_overflow_unsigned, | |
1516 | bfd_elf_generic_reloc, | |
1517 | "R_NIOS2_R2_F1L5_2", | |
0a1b45a2 | 1518 | false, |
8c163c5a SL |
1519 | 0x07c0, |
1520 | 0x07c0, | |
0a1b45a2 | 1521 | false), |
8c163c5a SL |
1522 | |
1523 | HOWTO (R_NIOS2_R2_L5I4X1, | |
1524 | 2, | |
c94cb026 | 1525 | 2, |
8c163c5a | 1526 | 4, |
0a1b45a2 | 1527 | false, |
8c163c5a SL |
1528 | 6, |
1529 | complain_overflow_unsigned, | |
1530 | bfd_elf_generic_reloc, | |
1531 | "R_NIOS2_R2_L5I4X1", | |
0a1b45a2 | 1532 | false, |
8c163c5a SL |
1533 | 0x03c0, |
1534 | 0x03c0, | |
0a1b45a2 | 1535 | false), |
8c163c5a SL |
1536 | |
1537 | HOWTO (R_NIOS2_R2_T1X1I6, | |
1538 | 0, | |
c94cb026 | 1539 | 2, |
8c163c5a | 1540 | 6, |
0a1b45a2 | 1541 | false, |
8c163c5a SL |
1542 | 9, |
1543 | complain_overflow_unsigned, | |
1544 | bfd_elf_generic_reloc, | |
1545 | "R_NIOS2_R2_T1X1I6", | |
0a1b45a2 | 1546 | false, |
8c163c5a SL |
1547 | 0x7e00, |
1548 | 0x7e00, | |
0a1b45a2 | 1549 | false), |
1b786873 | 1550 | |
8c163c5a SL |
1551 | HOWTO (R_NIOS2_R2_T1X1I6_2, |
1552 | 2, | |
c94cb026 | 1553 | 4, |
8c163c5a | 1554 | 6, |
0a1b45a2 | 1555 | false, |
8c163c5a SL |
1556 | 9, |
1557 | complain_overflow_unsigned, | |
1558 | bfd_elf_generic_reloc, | |
1559 | "R_NIOS2_R2_T1I1X6_2", | |
0a1b45a2 | 1560 | false, |
8c163c5a SL |
1561 | 0x7e00, |
1562 | 0x7e00, | |
0a1b45a2 | 1563 | false), |
1b786873 | 1564 | |
8c163c5a SL |
1565 | /* Add other relocations here. */ |
1566 | }; | |
1567 | ||
36591ba1 SL |
1568 | static unsigned char elf_code_to_howto_index[R_NIOS2_ILLEGAL + 1]; |
1569 | ||
8c163c5a SL |
1570 | |
1571 | /* Return true if producing output for a R2 BFD. */ | |
1572 | #define BFD_IS_R2(abfd) (bfd_get_mach (abfd) == bfd_mach_nios2r2) | |
1573 | ||
36591ba1 SL |
1574 | /* Return the howto for relocation RTYPE. */ |
1575 | static reloc_howto_type * | |
8c163c5a | 1576 | lookup_howto (unsigned int rtype, bfd *abfd) |
36591ba1 SL |
1577 | { |
1578 | static int initialized = 0; | |
1579 | int i; | |
8c163c5a SL |
1580 | /* R2 relocations are a superset of R1, so use that for the lookup |
1581 | table. */ | |
f3185997 NC |
1582 | int r1_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel); |
1583 | int r2_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel); | |
36591ba1 SL |
1584 | |
1585 | if (!initialized) | |
1586 | { | |
1587 | initialized = 1; | |
1588 | memset (elf_code_to_howto_index, 0xff, | |
1589 | sizeof (elf_code_to_howto_index)); | |
8c163c5a SL |
1590 | for (i = 0; i < r2_howto_tbl_size; i++) |
1591 | { | |
1592 | elf_code_to_howto_index[elf_nios2_r2_howto_table_rel[i].type] = i; | |
1593 | if (i < r1_howto_tbl_size) | |
1594 | BFD_ASSERT (elf_nios2_r2_howto_table_rel[i].type | |
1595 | == elf_nios2_r1_howto_table_rel[i].type); | |
1596 | } | |
36591ba1 SL |
1597 | } |
1598 | ||
f3185997 NC |
1599 | if (rtype > R_NIOS2_ILLEGAL) |
1600 | return NULL; | |
36591ba1 | 1601 | i = elf_code_to_howto_index[rtype]; |
8c163c5a SL |
1602 | if (BFD_IS_R2 (abfd)) |
1603 | { | |
1604 | if (i >= r2_howto_tbl_size) | |
f3185997 | 1605 | return NULL; |
8c163c5a SL |
1606 | return elf_nios2_r2_howto_table_rel + i; |
1607 | } | |
1608 | else | |
1609 | { | |
1610 | if (i >= r1_howto_tbl_size) | |
f3185997 | 1611 | return NULL; |
8c163c5a SL |
1612 | return elf_nios2_r1_howto_table_rel + i; |
1613 | } | |
36591ba1 SL |
1614 | } |
1615 | ||
1616 | /* Map for converting BFD reloc types to Nios II reloc types. */ | |
1617 | struct elf_reloc_map | |
1618 | { | |
1619 | bfd_reloc_code_real_type bfd_val; | |
1620 | enum elf_nios2_reloc_type elf_val; | |
1621 | }; | |
1622 | ||
f3185997 NC |
1623 | static const struct elf_reloc_map nios2_reloc_map[] = |
1624 | { | |
0ba38529 | 1625 | {BFD_RELOC_NONE, R_NIOS2_NONE}, |
36591ba1 SL |
1626 | {BFD_RELOC_NIOS2_S16, R_NIOS2_S16}, |
1627 | {BFD_RELOC_NIOS2_U16, R_NIOS2_U16}, | |
1628 | {BFD_RELOC_16_PCREL, R_NIOS2_PCREL16}, | |
1629 | {BFD_RELOC_NIOS2_CALL26, R_NIOS2_CALL26}, | |
1630 | {BFD_RELOC_NIOS2_IMM5, R_NIOS2_IMM5}, | |
1631 | {BFD_RELOC_NIOS2_CACHE_OPX, R_NIOS2_CACHE_OPX}, | |
1632 | {BFD_RELOC_NIOS2_IMM6, R_NIOS2_IMM6}, | |
1633 | {BFD_RELOC_NIOS2_IMM8, R_NIOS2_IMM8}, | |
1634 | {BFD_RELOC_NIOS2_HI16, R_NIOS2_HI16}, | |
1635 | {BFD_RELOC_NIOS2_LO16, R_NIOS2_LO16}, | |
1636 | {BFD_RELOC_NIOS2_HIADJ16, R_NIOS2_HIADJ16}, | |
1637 | {BFD_RELOC_32, R_NIOS2_BFD_RELOC_32}, | |
1638 | {BFD_RELOC_16, R_NIOS2_BFD_RELOC_16}, | |
1639 | {BFD_RELOC_8, R_NIOS2_BFD_RELOC_8}, | |
1640 | {BFD_RELOC_NIOS2_GPREL, R_NIOS2_GPREL}, | |
1641 | {BFD_RELOC_VTABLE_INHERIT, R_NIOS2_GNU_VTINHERIT}, | |
1642 | {BFD_RELOC_VTABLE_ENTRY, R_NIOS2_GNU_VTENTRY}, | |
1643 | {BFD_RELOC_NIOS2_UJMP, R_NIOS2_UJMP}, | |
1644 | {BFD_RELOC_NIOS2_CJMP, R_NIOS2_CJMP}, | |
1645 | {BFD_RELOC_NIOS2_CALLR, R_NIOS2_CALLR}, | |
1646 | {BFD_RELOC_NIOS2_ALIGN, R_NIOS2_ALIGN}, | |
1647 | {BFD_RELOC_NIOS2_GOT16, R_NIOS2_GOT16}, | |
1648 | {BFD_RELOC_NIOS2_CALL16, R_NIOS2_CALL16}, | |
1649 | {BFD_RELOC_NIOS2_GOTOFF_LO, R_NIOS2_GOTOFF_LO}, | |
1650 | {BFD_RELOC_NIOS2_GOTOFF_HA, R_NIOS2_GOTOFF_HA}, | |
1651 | {BFD_RELOC_NIOS2_PCREL_LO, R_NIOS2_PCREL_LO}, | |
1652 | {BFD_RELOC_NIOS2_PCREL_HA, R_NIOS2_PCREL_HA}, | |
1653 | {BFD_RELOC_NIOS2_TLS_GD16, R_NIOS2_TLS_GD16}, | |
1654 | {BFD_RELOC_NIOS2_TLS_LDM16, R_NIOS2_TLS_LDM16}, | |
1655 | {BFD_RELOC_NIOS2_TLS_LDO16, R_NIOS2_TLS_LDO16}, | |
1656 | {BFD_RELOC_NIOS2_TLS_IE16, R_NIOS2_TLS_IE16}, | |
1657 | {BFD_RELOC_NIOS2_TLS_LE16, R_NIOS2_TLS_LE16}, | |
1658 | {BFD_RELOC_NIOS2_TLS_DTPMOD, R_NIOS2_TLS_DTPMOD}, | |
1659 | {BFD_RELOC_NIOS2_TLS_DTPREL, R_NIOS2_TLS_DTPREL}, | |
1660 | {BFD_RELOC_NIOS2_TLS_TPREL, R_NIOS2_TLS_TPREL}, | |
1661 | {BFD_RELOC_NIOS2_COPY, R_NIOS2_COPY}, | |
1662 | {BFD_RELOC_NIOS2_GLOB_DAT, R_NIOS2_GLOB_DAT}, | |
1663 | {BFD_RELOC_NIOS2_JUMP_SLOT, R_NIOS2_JUMP_SLOT}, | |
1664 | {BFD_RELOC_NIOS2_RELATIVE, R_NIOS2_RELATIVE}, | |
78058a5e SL |
1665 | {BFD_RELOC_NIOS2_GOTOFF, R_NIOS2_GOTOFF}, |
1666 | {BFD_RELOC_NIOS2_CALL26_NOAT, R_NIOS2_CALL26_NOAT}, | |
1c2de463 SL |
1667 | {BFD_RELOC_NIOS2_GOT_LO, R_NIOS2_GOT_LO}, |
1668 | {BFD_RELOC_NIOS2_GOT_HA, R_NIOS2_GOT_HA}, | |
1669 | {BFD_RELOC_NIOS2_CALL_LO, R_NIOS2_CALL_LO}, | |
1670 | {BFD_RELOC_NIOS2_CALL_HA, R_NIOS2_CALL_HA}, | |
8c163c5a SL |
1671 | {BFD_RELOC_NIOS2_R2_S12, R_NIOS2_R2_S12}, |
1672 | {BFD_RELOC_NIOS2_R2_I10_1_PCREL, R_NIOS2_R2_I10_1_PCREL}, | |
1673 | {BFD_RELOC_NIOS2_R2_T1I7_1_PCREL, R_NIOS2_R2_T1I7_1_PCREL}, | |
1674 | {BFD_RELOC_NIOS2_R2_T1I7_2, R_NIOS2_R2_T1I7_2}, | |
1675 | {BFD_RELOC_NIOS2_R2_T2I4, R_NIOS2_R2_T2I4}, | |
1676 | {BFD_RELOC_NIOS2_R2_T2I4_1, R_NIOS2_R2_T2I4_1}, | |
1677 | {BFD_RELOC_NIOS2_R2_T2I4_2, R_NIOS2_R2_T2I4_2}, | |
1678 | {BFD_RELOC_NIOS2_R2_X1I7_2, R_NIOS2_R2_X1I7_2}, | |
1679 | {BFD_RELOC_NIOS2_R2_X2L5, R_NIOS2_R2_X2L5}, | |
1680 | {BFD_RELOC_NIOS2_R2_F1I5_2, R_NIOS2_R2_F1I5_2}, | |
1681 | {BFD_RELOC_NIOS2_R2_L5I4X1, R_NIOS2_R2_L5I4X1}, | |
1682 | {BFD_RELOC_NIOS2_R2_T1X1I6, R_NIOS2_R2_T1X1I6}, | |
1683 | {BFD_RELOC_NIOS2_R2_T1X1I6_2, R_NIOS2_R2_T1X1I6_2}, | |
78058a5e SL |
1684 | }; |
1685 | ||
1686 | enum elf32_nios2_stub_type | |
1687 | { | |
1688 | nios2_stub_call26_before, | |
1689 | nios2_stub_call26_after, | |
1690 | nios2_stub_none | |
1691 | }; | |
1692 | ||
1693 | struct elf32_nios2_stub_hash_entry | |
1694 | { | |
1695 | /* Base hash table entry structure. */ | |
1696 | struct bfd_hash_entry bh_root; | |
1697 | ||
1698 | /* The stub section. */ | |
1699 | asection *stub_sec; | |
1700 | ||
1701 | /* Offset within stub_sec of the beginning of this stub. */ | |
1702 | bfd_vma stub_offset; | |
1703 | ||
1704 | /* Given the symbol's value and its section we can determine its final | |
1705 | value when building the stubs (so the stub knows where to jump. */ | |
1706 | bfd_vma target_value; | |
1707 | asection *target_section; | |
1708 | ||
1709 | enum elf32_nios2_stub_type stub_type; | |
1710 | ||
1711 | /* The symbol table entry, if any, that this was derived from. */ | |
1712 | struct elf32_nios2_link_hash_entry *hh; | |
1713 | ||
1714 | /* And the reloc addend that this was derived from. */ | |
1715 | bfd_vma addend; | |
1716 | ||
1717 | /* Where this stub is being called from, or, in the case of combined | |
1718 | stub sections, the first input section in the group. */ | |
1719 | asection *id_sec; | |
36591ba1 SL |
1720 | }; |
1721 | ||
78058a5e SL |
1722 | #define nios2_stub_hash_entry(ent) \ |
1723 | ((struct elf32_nios2_stub_hash_entry *)(ent)) | |
1724 | ||
1725 | #define nios2_stub_hash_lookup(table, string, create, copy) \ | |
1726 | ((struct elf32_nios2_stub_hash_entry *) \ | |
1727 | bfd_hash_lookup ((table), (string), (create), (copy))) | |
1728 | ||
1729 | ||
36591ba1 SL |
1730 | /* Nios II ELF linker hash entry. */ |
1731 | ||
1732 | struct elf32_nios2_link_hash_entry | |
1733 | { | |
1734 | struct elf_link_hash_entry root; | |
1735 | ||
78058a5e SL |
1736 | /* A pointer to the most recently used stub hash entry against this |
1737 | symbol. */ | |
1738 | struct elf32_nios2_stub_hash_entry *hsh_cache; | |
1739 | ||
36591ba1 SL |
1740 | #define GOT_UNKNOWN 0 |
1741 | #define GOT_NORMAL 1 | |
1742 | #define GOT_TLS_GD 2 | |
1743 | #define GOT_TLS_IE 4 | |
1744 | unsigned char tls_type; | |
1745 | ||
1746 | /* We need to detect and take special action for symbols which are only | |
1747 | referenced with %call() and not with %got(). Such symbols do not need | |
1748 | a dynamic GOT reloc in shared objects, only a dynamic PLT reloc. Lazy | |
1749 | linking will not work if the dynamic GOT reloc exists. | |
1750 | To check for this condition efficiently, we compare got_types_used against | |
1c2de463 SL |
1751 | CALL_USED, meaning |
1752 | (got_types_used & (GOT_USED | CALL_USED)) == CALL_USED. | |
1753 | */ | |
1754 | #define GOT_USED 1 | |
1755 | #define CALL_USED 2 | |
36591ba1 SL |
1756 | unsigned char got_types_used; |
1757 | }; | |
1758 | ||
1759 | #define elf32_nios2_hash_entry(ent) \ | |
1760 | ((struct elf32_nios2_link_hash_entry *) (ent)) | |
1761 | ||
1762 | /* Get the Nios II elf linker hash table from a link_info structure. */ | |
1763 | #define elf32_nios2_hash_table(info) \ | |
1764 | ((struct elf32_nios2_link_hash_table *) ((info)->hash)) | |
1765 | ||
1766 | /* Nios II ELF linker hash table. */ | |
1767 | struct elf32_nios2_link_hash_table | |
1768 | { | |
1769 | /* The main hash table. */ | |
1770 | struct elf_link_hash_table root; | |
1771 | ||
78058a5e SL |
1772 | /* The stub hash table. */ |
1773 | struct bfd_hash_table bstab; | |
1774 | ||
1775 | /* Linker stub bfd. */ | |
1776 | bfd *stub_bfd; | |
1777 | ||
1778 | /* Linker call-backs. */ | |
0a1b45a2 | 1779 | asection * (*add_stub_section) (const char *, asection *, bool); |
78058a5e SL |
1780 | void (*layout_sections_again) (void); |
1781 | ||
1782 | /* Array to keep track of which stub sections have been created, and | |
1783 | information on stub grouping. */ | |
1784 | struct map_stub | |
1785 | { | |
1786 | /* These are the section to which stubs in the group will be | |
1787 | attached. */ | |
1788 | asection *first_sec, *last_sec; | |
1789 | /* The stub sections. There might be stubs inserted either before | |
1790 | or after the real section.*/ | |
1791 | asection *first_stub_sec, *last_stub_sec; | |
1792 | } *stub_group; | |
1793 | ||
1794 | /* Assorted information used by nios2_elf32_size_stubs. */ | |
1795 | unsigned int bfd_count; | |
7292b3ac | 1796 | unsigned int top_index; |
78058a5e SL |
1797 | asection **input_list; |
1798 | Elf_Internal_Sym **all_local_syms; | |
1799 | ||
36591ba1 | 1800 | /* Short-cuts to get to dynamic linker sections. */ |
36591ba1 SL |
1801 | asection *sbss; |
1802 | ||
82e91538 SL |
1803 | /* GOT pointer symbol _gp_got. */ |
1804 | struct elf_link_hash_entry *h_gp_got; | |
1805 | ||
36591ba1 SL |
1806 | union { |
1807 | bfd_signed_vma refcount; | |
1808 | bfd_vma offset; | |
1809 | } tls_ldm_got; | |
1810 | ||
36591ba1 SL |
1811 | bfd_vma res_n_size; |
1812 | }; | |
1813 | ||
1814 | struct nios2_elf32_obj_tdata | |
1815 | { | |
1816 | struct elf_obj_tdata root; | |
1817 | ||
1818 | /* tls_type for each local got entry. */ | |
1819 | char *local_got_tls_type; | |
1820 | ||
1821 | /* TRUE if TLS GD relocs have been seen for this object. */ | |
0a1b45a2 | 1822 | bool has_tlsgd; |
36591ba1 SL |
1823 | }; |
1824 | ||
1825 | #define elf32_nios2_tdata(abfd) \ | |
1826 | ((struct nios2_elf32_obj_tdata *) (abfd)->tdata.any) | |
1827 | ||
1828 | #define elf32_nios2_local_got_tls_type(abfd) \ | |
1829 | (elf32_nios2_tdata (abfd)->local_got_tls_type) | |
1830 | ||
1831 | /* The name of the dynamic interpreter. This is put in the .interp | |
1832 | section. */ | |
1833 | #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" | |
1834 | ||
1835 | /* PLT implementation for position-dependent code. */ | |
1836 | static const bfd_vma nios2_plt_entry[] = { /* .PLTn: */ | |
1837 | 0x03c00034, /* movhi r15, %hiadj(plt_got_slot_address) */ | |
1838 | 0x7bc00017, /* ldw r15, %lo(plt_got_slot_address)(r15) */ | |
1839 | 0x7800683a /* jmp r15 */ | |
1840 | }; | |
1841 | ||
1842 | static const bfd_vma nios2_plt0_entry[] = { /* .PLTresolve */ | |
1843 | 0x03800034, /* movhi r14, %hiadj(res_0) */ | |
1844 | 0x73800004, /* addi r14, r14, %lo(res_0) */ | |
1845 | 0x7b9fc83a, /* sub r15, r15, r14 */ | |
1846 | 0x03400034, /* movhi r13, %hiadj(_GLOBAL_OFFSET_TABLE_) */ | |
1847 | 0x6b800017, /* ldw r14, %lo(_GLOBAL_OFFSET_TABLE_+4)(r13) */ | |
1848 | 0x6b400017, /* ldw r13, %lo(_GLOBAL_OFFSET_TABLE_+8)(r13) */ | |
1849 | 0x6800683a /* jmp r13 */ | |
1850 | }; | |
1851 | ||
1852 | /* PLT implementation for position-independent code. */ | |
1853 | static const bfd_vma nios2_so_plt_entry[] = { /* .PLTn */ | |
1854 | 0x03c00034, /* movhi r15, %hiadj(index * 4) */ | |
1855 | 0x7bc00004, /* addi r15, r15, %lo(index * 4) */ | |
1856 | 0x00000006 /* br .PLTresolve */ | |
1857 | }; | |
1858 | ||
1859 | static const bfd_vma nios2_so_plt0_entry[] = { /* .PLTresolve */ | |
1860 | 0x001ce03a, /* nextpc r14 */ | |
1861 | 0x03400034, /* movhi r13, %hiadj(_GLOBAL_OFFSET_TABLE_) */ | |
1862 | 0x6b9b883a, /* add r13, r13, r14 */ | |
1863 | 0x6b800017, /* ldw r14, %lo(_GLOBAL_OFFSET_TABLE_+4)(r13) */ | |
1864 | 0x6b400017, /* ldw r13, %lo(_GLOBAL_OFFSET_TABLE_+8)(r13) */ | |
1865 | 0x6800683a /* jmp r13 */ | |
1866 | }; | |
1867 | ||
78058a5e SL |
1868 | /* CALL26 stub. */ |
1869 | static const bfd_vma nios2_call26_stub_entry[] = { | |
1870 | 0x00400034, /* orhi at, r0, %hiadj(dest) */ | |
1871 | 0x08400004, /* addi at, at, %lo(dest) */ | |
1872 | 0x0800683a /* jmp at */ | |
1873 | }; | |
1874 | ||
1875 | /* Install 16-bit immediate value VALUE at offset OFFSET into section SEC. */ | |
1876 | static void | |
1877 | nios2_elf32_install_imm16 (asection *sec, bfd_vma offset, bfd_vma value) | |
1878 | { | |
1879 | bfd_vma word = bfd_get_32 (sec->owner, sec->contents + offset); | |
1880 | ||
78058a5e SL |
1881 | bfd_put_32 (sec->owner, word | ((value & 0xffff) << 6), |
1882 | sec->contents + offset); | |
1883 | } | |
1884 | ||
1885 | /* Install COUNT 32-bit values DATA starting at offset OFFSET into | |
1886 | section SEC. */ | |
1887 | static void | |
1888 | nios2_elf32_install_data (asection *sec, const bfd_vma *data, bfd_vma offset, | |
1889 | int count) | |
1890 | { | |
1891 | while (count--) | |
1892 | { | |
1893 | bfd_put_32 (sec->owner, *data, sec->contents + offset); | |
1894 | offset += 4; | |
1895 | ++data; | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | /* The usual way of loading a 32-bit constant into a Nios II register is to | |
1900 | load the high 16 bits in one instruction and then add the low 16 bits with | |
1901 | a signed add. This means that the high halfword needs to be adjusted to | |
1902 | compensate for the sign bit of the low halfword. This function returns the | |
1903 | adjusted high halfword for a given 32-bit constant. */ | |
1904 | static | |
1905 | bfd_vma hiadj (bfd_vma symbol_value) | |
1906 | { | |
1907 | return ((symbol_value + 0x8000) >> 16) & 0xffff; | |
1908 | } | |
1909 | ||
36591ba1 SL |
1910 | /* Implement elf_backend_grok_prstatus: |
1911 | Support for core dump NOTE sections. */ | |
0a1b45a2 | 1912 | static bool |
36591ba1 SL |
1913 | nios2_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
1914 | { | |
1915 | int offset; | |
1916 | size_t size; | |
1917 | ||
1918 | switch (note->descsz) | |
1919 | { | |
1920 | default: | |
0a1b45a2 | 1921 | return false; |
36591ba1 SL |
1922 | |
1923 | case 212: /* Linux/Nios II */ | |
1924 | /* pr_cursig */ | |
228e534f | 1925 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
36591ba1 SL |
1926 | |
1927 | /* pr_pid */ | |
228e534f | 1928 | elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24); |
36591ba1 SL |
1929 | |
1930 | /* pr_reg */ | |
1931 | offset = 72; | |
1932 | size = 136; | |
1933 | ||
1934 | break; | |
1935 | } | |
1936 | ||
1937 | /* Make a ".reg/999" section. */ | |
1938 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1939 | size, note->descpos + offset); | |
1940 | } | |
1941 | ||
1942 | /* Implement elf_backend_grok_psinfo. */ | |
0a1b45a2 | 1943 | static bool |
36591ba1 SL |
1944 | nios2_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
1945 | { | |
1946 | switch (note->descsz) | |
1947 | { | |
1948 | default: | |
0a1b45a2 | 1949 | return false; |
36591ba1 SL |
1950 | |
1951 | case 124: /* Linux/Nios II elf_prpsinfo */ | |
228e534f | 1952 | elf_tdata (abfd)->core->program |
36591ba1 | 1953 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); |
228e534f | 1954 | elf_tdata (abfd)->core->command |
36591ba1 SL |
1955 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); |
1956 | } | |
1957 | ||
1958 | /* Note that for some reason, a spurious space is tacked | |
1959 | onto the end of the args in some (at least one anyway) | |
1960 | implementations, so strip it off if it exists. */ | |
1961 | ||
1962 | { | |
228e534f | 1963 | char *command = elf_tdata (abfd)->core->command; |
36591ba1 SL |
1964 | int n = strlen (command); |
1965 | ||
1966 | if (0 < n && command[n - 1] == ' ') | |
1967 | command[n - 1] = '\0'; | |
1968 | } | |
1969 | ||
0a1b45a2 | 1970 | return true; |
36591ba1 SL |
1971 | } |
1972 | ||
78058a5e SL |
1973 | /* Assorted hash table functions. */ |
1974 | ||
1975 | /* Initialize an entry in the stub hash table. */ | |
1976 | static struct bfd_hash_entry * | |
1977 | stub_hash_newfunc (struct bfd_hash_entry *entry, | |
1978 | struct bfd_hash_table *table, | |
1979 | const char *string) | |
1980 | { | |
1981 | /* Allocate the structure if it has not already been allocated by a | |
1982 | subclass. */ | |
1983 | if (entry == NULL) | |
1984 | { | |
1985 | entry = bfd_hash_allocate (table, | |
1986 | sizeof (struct elf32_nios2_stub_hash_entry)); | |
1987 | if (entry == NULL) | |
1988 | return entry; | |
1989 | } | |
1990 | ||
1991 | /* Call the allocation method of the superclass. */ | |
1992 | entry = bfd_hash_newfunc (entry, table, string); | |
1993 | if (entry != NULL) | |
1994 | { | |
1995 | struct elf32_nios2_stub_hash_entry *hsh; | |
1996 | ||
1997 | /* Initialize the local fields. */ | |
1998 | hsh = (struct elf32_nios2_stub_hash_entry *) entry; | |
1999 | hsh->stub_sec = NULL; | |
2000 | hsh->stub_offset = 0; | |
2001 | hsh->target_value = 0; | |
2002 | hsh->target_section = NULL; | |
2003 | hsh->stub_type = nios2_stub_none; | |
2004 | hsh->hh = NULL; | |
2005 | hsh->id_sec = NULL; | |
2006 | } | |
2007 | ||
2008 | return entry; | |
2009 | } | |
2010 | ||
36591ba1 SL |
2011 | /* Create an entry in a Nios II ELF linker hash table. */ |
2012 | static struct bfd_hash_entry * | |
2013 | link_hash_newfunc (struct bfd_hash_entry *entry, | |
2014 | struct bfd_hash_table *table, const char *string) | |
2015 | { | |
2016 | /* Allocate the structure if it has not already been allocated by a | |
2017 | subclass. */ | |
2018 | if (entry == NULL) | |
2019 | { | |
2020 | entry = bfd_hash_allocate (table, | |
2021 | sizeof (struct elf32_nios2_link_hash_entry)); | |
2022 | if (entry == NULL) | |
2023 | return entry; | |
2024 | } | |
2025 | ||
2026 | /* Call the allocation method of the superclass. */ | |
2027 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
2028 | if (entry) | |
2029 | { | |
2030 | struct elf32_nios2_link_hash_entry *eh; | |
2031 | ||
2032 | eh = (struct elf32_nios2_link_hash_entry *) entry; | |
78058a5e | 2033 | eh->hsh_cache = NULL; |
36591ba1 SL |
2034 | eh->tls_type = GOT_UNKNOWN; |
2035 | eh->got_types_used = 0; | |
2036 | } | |
2037 | ||
2038 | return entry; | |
2039 | } | |
2040 | ||
78058a5e SL |
2041 | /* Section name for stubs is the associated section name plus this |
2042 | string. */ | |
2043 | #define STUB_SUFFIX ".stub" | |
2044 | ||
2045 | /* Build a name for an entry in the stub hash table. */ | |
2046 | static char * | |
2047 | nios2_stub_name (const asection *input_section, | |
2048 | const asection *sym_sec, | |
2049 | const struct elf32_nios2_link_hash_entry *hh, | |
2050 | const Elf_Internal_Rela *rel, | |
2051 | enum elf32_nios2_stub_type stub_type) | |
2052 | { | |
2053 | char *stub_name; | |
2054 | bfd_size_type len; | |
2055 | char stubpos = (stub_type == nios2_stub_call26_before) ? 'b' : 'a'; | |
2056 | ||
2057 | if (hh) | |
2058 | { | |
2059 | len = 8 + 1 + 1 + 1+ strlen (hh->root.root.root.string) + 1 + 8 + 1; | |
2060 | stub_name = bfd_malloc (len); | |
2061 | if (stub_name != NULL) | |
2062 | { | |
2063 | sprintf (stub_name, "%08x_%c_%s+%x", | |
2064 | input_section->id & 0xffffffff, | |
2065 | stubpos, | |
2066 | hh->root.root.root.string, | |
2067 | (int) rel->r_addend & 0xffffffff); | |
2068 | } | |
2069 | } | |
2070 | else | |
2071 | { | |
2072 | len = 8 + 1 + 1 + 1+ 8 + 1 + 8 + 1 + 8 + 1; | |
2073 | stub_name = bfd_malloc (len); | |
2074 | if (stub_name != NULL) | |
2075 | { | |
2076 | sprintf (stub_name, "%08x_%c_%x:%x+%x", | |
2077 | input_section->id & 0xffffffff, | |
2078 | stubpos, | |
2079 | sym_sec->id & 0xffffffff, | |
2080 | (int) ELF32_R_SYM (rel->r_info) & 0xffffffff, | |
2081 | (int) rel->r_addend & 0xffffffff); | |
2082 | } | |
2083 | } | |
2084 | return stub_name; | |
2085 | } | |
2086 | ||
2087 | /* Look up an entry in the stub hash. Stub entries are cached because | |
2088 | creating the stub name takes a bit of time. */ | |
2089 | static struct elf32_nios2_stub_hash_entry * | |
2090 | nios2_get_stub_entry (const asection *input_section, | |
2091 | const asection *sym_sec, | |
2092 | struct elf32_nios2_link_hash_entry *hh, | |
2093 | const Elf_Internal_Rela *rel, | |
2094 | struct elf32_nios2_link_hash_table *htab, | |
2095 | enum elf32_nios2_stub_type stub_type) | |
2096 | { | |
2097 | struct elf32_nios2_stub_hash_entry *hsh; | |
2098 | const asection *id_sec; | |
2099 | ||
2100 | /* If this input section is part of a group of sections sharing one | |
2101 | stub section, then use the id of the first/last section in the group, | |
2102 | depending on the stub section placement relative to the group. | |
2103 | Stub names need to include a section id, as there may well be | |
2104 | more than one stub used to reach say, printf, and we need to | |
2105 | distinguish between them. */ | |
2106 | if (stub_type == nios2_stub_call26_before) | |
2107 | id_sec = htab->stub_group[input_section->id].first_sec; | |
2108 | else | |
2109 | id_sec = htab->stub_group[input_section->id].last_sec; | |
2110 | ||
2111 | if (hh != NULL && hh->hsh_cache != NULL | |
2112 | && hh->hsh_cache->hh == hh | |
2113 | && hh->hsh_cache->id_sec == id_sec | |
2114 | && hh->hsh_cache->stub_type == stub_type) | |
2115 | { | |
2116 | hsh = hh->hsh_cache; | |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | char *stub_name; | |
2121 | ||
2122 | stub_name = nios2_stub_name (id_sec, sym_sec, hh, rel, stub_type); | |
2123 | if (stub_name == NULL) | |
2124 | return NULL; | |
2125 | ||
2126 | hsh = nios2_stub_hash_lookup (&htab->bstab, | |
0a1b45a2 | 2127 | stub_name, false, false); |
78058a5e SL |
2128 | |
2129 | if (hh != NULL) | |
2130 | hh->hsh_cache = hsh; | |
2131 | ||
2132 | free (stub_name); | |
2133 | } | |
2134 | ||
2135 | return hsh; | |
2136 | } | |
2137 | ||
2138 | /* Add a new stub entry to the stub hash. Not all fields of the new | |
2139 | stub entry are initialised. */ | |
2140 | static struct elf32_nios2_stub_hash_entry * | |
2141 | nios2_add_stub (const char *stub_name, | |
2142 | asection *section, | |
2143 | struct elf32_nios2_link_hash_table *htab, | |
2144 | enum elf32_nios2_stub_type stub_type) | |
2145 | { | |
2146 | asection *link_sec; | |
2147 | asection *stub_sec; | |
2148 | asection **secptr, **linkptr; | |
2149 | struct elf32_nios2_stub_hash_entry *hsh; | |
0a1b45a2 | 2150 | bool afterp; |
78058a5e SL |
2151 | |
2152 | if (stub_type == nios2_stub_call26_before) | |
2153 | { | |
2154 | link_sec = htab->stub_group[section->id].first_sec; | |
2155 | secptr = &(htab->stub_group[section->id].first_stub_sec); | |
2156 | linkptr = &(htab->stub_group[link_sec->id].first_stub_sec); | |
0a1b45a2 | 2157 | afterp = false; |
78058a5e SL |
2158 | } |
2159 | else | |
2160 | { | |
2161 | link_sec = htab->stub_group[section->id].last_sec; | |
2162 | secptr = &(htab->stub_group[section->id].last_stub_sec); | |
2163 | linkptr = &(htab->stub_group[link_sec->id].last_stub_sec); | |
0a1b45a2 | 2164 | afterp = true; |
78058a5e SL |
2165 | } |
2166 | stub_sec = *secptr; | |
2167 | if (stub_sec == NULL) | |
2168 | { | |
2169 | stub_sec = *linkptr; | |
2170 | if (stub_sec == NULL) | |
2171 | { | |
2172 | size_t namelen; | |
2173 | bfd_size_type len; | |
2174 | char *s_name; | |
2175 | ||
2176 | namelen = strlen (link_sec->name); | |
2177 | len = namelen + sizeof (STUB_SUFFIX); | |
2178 | s_name = bfd_alloc (htab->stub_bfd, len); | |
2179 | if (s_name == NULL) | |
2180 | return NULL; | |
2181 | ||
2182 | memcpy (s_name, link_sec->name, namelen); | |
2183 | memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX)); | |
2184 | ||
2185 | stub_sec = (*htab->add_stub_section) (s_name, link_sec, afterp); | |
2186 | if (stub_sec == NULL) | |
2187 | return NULL; | |
2188 | *linkptr = stub_sec; | |
2189 | } | |
2190 | *secptr = stub_sec; | |
2191 | } | |
2192 | ||
2193 | /* Enter this entry into the linker stub hash table. */ | |
2194 | hsh = nios2_stub_hash_lookup (&htab->bstab, stub_name, | |
0a1b45a2 | 2195 | true, false); |
78058a5e SL |
2196 | if (hsh == NULL) |
2197 | { | |
695344c0 | 2198 | /* xgettext:c-format */ |
871b3ab2 | 2199 | _bfd_error_handler (_("%pB: cannot create stub entry %s"), |
4eca0228 AM |
2200 | section->owner, |
2201 | stub_name); | |
78058a5e SL |
2202 | return NULL; |
2203 | } | |
2204 | ||
2205 | hsh->stub_sec = stub_sec; | |
2206 | hsh->stub_offset = 0; | |
2207 | hsh->id_sec = link_sec; | |
2208 | return hsh; | |
2209 | } | |
2210 | ||
2211 | /* Set up various things so that we can make a list of input sections | |
2212 | for each output section included in the link. Returns -1 on error, | |
2213 | 0 when no stubs will be needed, and 1 on success. */ | |
2214 | int | |
2215 | nios2_elf32_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) | |
2216 | { | |
2217 | bfd *input_bfd; | |
2218 | unsigned int bfd_count; | |
7292b3ac | 2219 | unsigned int top_id, top_index; |
78058a5e SL |
2220 | asection *section; |
2221 | asection **input_list, **list; | |
986f0783 | 2222 | size_t amt; |
78058a5e SL |
2223 | struct elf32_nios2_link_hash_table *htab = elf32_nios2_hash_table (info); |
2224 | ||
2225 | /* Count the number of input BFDs and find the top input section id. */ | |
2226 | for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; | |
2227 | input_bfd != NULL; | |
c72f2fb2 | 2228 | input_bfd = input_bfd->link.next) |
78058a5e SL |
2229 | { |
2230 | bfd_count += 1; | |
2231 | for (section = input_bfd->sections; | |
2232 | section != NULL; | |
2233 | section = section->next) | |
2234 | { | |
2235 | if (top_id < section->id) | |
2236 | top_id = section->id; | |
2237 | } | |
2238 | } | |
2239 | ||
2240 | htab->bfd_count = bfd_count; | |
2241 | ||
2242 | amt = sizeof (struct map_stub) * (top_id + 1); | |
2243 | htab->stub_group = bfd_zmalloc (amt); | |
2244 | if (htab->stub_group == NULL) | |
2245 | return -1; | |
2246 | ||
2247 | /* We can't use output_bfd->section_count here to find the top output | |
2248 | section index as some sections may have been removed, and | |
2249 | strip_excluded_output_sections doesn't renumber the indices. */ | |
2250 | for (section = output_bfd->sections, top_index = 0; | |
2251 | section != NULL; | |
2252 | section = section->next) | |
2253 | { | |
2254 | if (top_index < section->index) | |
2255 | top_index = section->index; | |
2256 | } | |
2257 | ||
2258 | htab->top_index = top_index; | |
2259 | amt = sizeof (asection *) * (top_index + 1); | |
2260 | input_list = bfd_malloc (amt); | |
2261 | htab->input_list = input_list; | |
2262 | if (input_list == NULL) | |
2263 | return -1; | |
2264 | ||
2265 | /* For sections we aren't interested in, mark their entries with a | |
2266 | value we can check later. */ | |
2267 | list = input_list + top_index; | |
2268 | do | |
2269 | *list = bfd_abs_section_ptr; | |
2270 | while (list-- != input_list); | |
2271 | ||
2272 | for (section = output_bfd->sections; | |
2273 | section != NULL; | |
2274 | section = section->next) | |
2275 | { | |
2276 | /* FIXME: This is a bit of hack. Currently our .ctors and .dtors | |
2277 | * have PC relative relocs in them but no code flag set. */ | |
2278 | if (((section->flags & SEC_CODE) != 0) || | |
2279 | strcmp(".ctors", section->name) || | |
2280 | strcmp(".dtors", section->name)) | |
2281 | input_list[section->index] = NULL; | |
2282 | } | |
2283 | ||
2284 | return 1; | |
2285 | } | |
2286 | ||
2287 | /* The linker repeatedly calls this function for each input section, | |
2288 | in the order that input sections are linked into output sections. | |
2289 | Build lists of input sections to determine groupings between which | |
2290 | we may insert linker stubs. */ | |
2291 | void | |
2292 | nios2_elf32_next_input_section (struct bfd_link_info *info, asection *isec) | |
2293 | { | |
2294 | struct elf32_nios2_link_hash_table *htab = elf32_nios2_hash_table (info); | |
2295 | ||
2296 | if (isec->output_section->index <= htab->top_index) | |
2297 | { | |
2298 | asection **list = htab->input_list + isec->output_section->index; | |
2299 | if (*list != bfd_abs_section_ptr) | |
2300 | { | |
2301 | /* Steal the last_sec pointer for our list. | |
2302 | This happens to make the list in reverse order, | |
2303 | which is what we want. */ | |
2304 | htab->stub_group[isec->id].last_sec = *list; | |
2305 | *list = isec; | |
2306 | } | |
2307 | } | |
2308 | } | |
2309 | ||
2310 | /* Segment mask for CALL26 relocation relaxation. */ | |
2311 | #define CALL26_SEGMENT(x) ((x) & 0xf0000000) | |
2312 | ||
2313 | /* Fudge factor for approximate maximum size of all stubs that might | |
2314 | be inserted by the linker. This does not actually limit the number | |
2315 | of stubs that might be inserted, and only affects strategy for grouping | |
2316 | and placement of stubs. Perhaps this should be computed based on number | |
2317 | of relocations seen, or be specifiable on the command line. */ | |
2318 | #define MAX_STUB_SECTION_SIZE 0xffff | |
2319 | ||
2320 | /* See whether we can group stub sections together. Grouping stub | |
2321 | sections may result in fewer stubs. More importantly, we need to | |
2322 | put all .init* and .fini* stubs at the end of the .init or | |
2323 | .fini output sections respectively, because glibc splits the | |
2324 | _init and _fini functions into multiple parts. Putting a stub in | |
2325 | the middle of a function is not a good idea. | |
2326 | Rather than computing groups of a maximum fixed size, for Nios II | |
2327 | CALL26 relaxation it makes more sense to compute the groups based on | |
2328 | sections that fit within a 256MB address segment. Also do not allow | |
2329 | a group to span more than one output section, since different output | |
2330 | sections might correspond to different memory banks on a bare-metal | |
2331 | target, etc. */ | |
2332 | static void | |
2333 | group_sections (struct elf32_nios2_link_hash_table *htab) | |
2334 | { | |
2335 | asection **list = htab->input_list + htab->top_index; | |
2336 | do | |
2337 | { | |
2338 | /* The list is in reverse order so we'll search backwards looking | |
2339 | for the first section that begins in the same memory segment, | |
2340 | marking sections along the way to point at the tail for this | |
2341 | group. */ | |
2342 | asection *tail = *list; | |
2343 | if (tail == bfd_abs_section_ptr) | |
2344 | continue; | |
2345 | while (tail != NULL) | |
2346 | { | |
2347 | bfd_vma start = tail->output_section->vma + tail->output_offset; | |
2348 | bfd_vma end = start + tail->size; | |
2349 | bfd_vma segment = CALL26_SEGMENT (end); | |
2350 | asection *prev; | |
2351 | ||
2352 | if (segment != CALL26_SEGMENT (start) | |
2353 | || segment != CALL26_SEGMENT (end + MAX_STUB_SECTION_SIZE)) | |
2354 | /* This section spans more than one memory segment, or is | |
2355 | close enough to the end of the segment that adding stub | |
2356 | sections before it might cause it to move so that it | |
2357 | spans memory segments, or that stubs added at the end of | |
2358 | this group might overflow into the next memory segment. | |
2359 | Put it in a group by itself to localize the effects. */ | |
2360 | { | |
2361 | prev = htab->stub_group[tail->id].last_sec; | |
2362 | htab->stub_group[tail->id].last_sec = tail; | |
2363 | htab->stub_group[tail->id].first_sec = tail; | |
2364 | } | |
2365 | else | |
2366 | /* Collect more sections for this group. */ | |
2367 | { | |
2368 | asection *curr, *first; | |
2369 | for (curr = tail; ; curr = prev) | |
2370 | { | |
2371 | prev = htab->stub_group[curr->id].last_sec; | |
2372 | if (!prev | |
2373 | || tail->output_section != prev->output_section | |
2374 | || (CALL26_SEGMENT (prev->output_section->vma | |
2375 | + prev->output_offset) | |
2376 | != segment)) | |
2377 | break; | |
2378 | } | |
2379 | first = curr; | |
2380 | for (curr = tail; ; curr = prev) | |
2381 | { | |
2382 | prev = htab->stub_group[curr->id].last_sec; | |
2383 | htab->stub_group[curr->id].last_sec = tail; | |
2384 | htab->stub_group[curr->id].first_sec = first; | |
2385 | if (curr == first) | |
2386 | break; | |
2387 | } | |
2388 | } | |
2389 | ||
2390 | /* Reset tail for the next group. */ | |
2391 | tail = prev; | |
2392 | } | |
2393 | } | |
2394 | while (list-- != htab->input_list); | |
2395 | free (htab->input_list); | |
2396 | } | |
2397 | ||
2398 | /* Determine the type of stub needed, if any, for a call. */ | |
2399 | static enum elf32_nios2_stub_type | |
2400 | nios2_type_of_stub (asection *input_sec, | |
2401 | const Elf_Internal_Rela *rel, | |
2402 | struct elf32_nios2_link_hash_entry *hh, | |
2403 | struct elf32_nios2_link_hash_table *htab, | |
2404 | bfd_vma destination, | |
2405 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
2406 | { | |
2407 | bfd_vma location, segment, start, end; | |
2408 | asection *s0, *s1, *s; | |
2409 | ||
2410 | if (hh != NULL && | |
2411 | !(hh->root.root.type == bfd_link_hash_defined | |
2412 | || hh->root.root.type == bfd_link_hash_defweak)) | |
2413 | return nios2_stub_none; | |
2414 | ||
2415 | /* Determine where the call point is. */ | |
2416 | location = (input_sec->output_section->vma | |
2417 | + input_sec->output_offset + rel->r_offset); | |
2418 | segment = CALL26_SEGMENT (location); | |
2419 | ||
2420 | /* Nios II CALL and JMPI instructions can transfer control to addresses | |
2421 | within the same 256MB segment as the PC. */ | |
2422 | if (segment == CALL26_SEGMENT (destination)) | |
2423 | return nios2_stub_none; | |
2424 | ||
2425 | /* Find the start and end addresses of the stub group. Also account for | |
2426 | any already-created stub sections for this group. Note that for stubs | |
2427 | in the end section, only the first instruction of the last stub | |
2428 | (12 bytes long) needs to be within range. */ | |
2429 | s0 = htab->stub_group[input_sec->id].first_sec; | |
2430 | s = htab->stub_group[s0->id].first_stub_sec; | |
2431 | if (s != NULL && s->size > 0) | |
2432 | start = s->output_section->vma + s->output_offset; | |
2433 | else | |
2434 | start = s0->output_section->vma + s0->output_offset; | |
2435 | ||
2436 | s1 = htab->stub_group[input_sec->id].last_sec; | |
2437 | s = htab->stub_group[s1->id].last_stub_sec; | |
2438 | if (s != NULL && s->size > 0) | |
2439 | end = s->output_section->vma + s->output_offset + s->size - 8; | |
2440 | else | |
2441 | end = s1->output_section->vma + s1->output_offset + s1->size; | |
2442 | ||
2443 | BFD_ASSERT (start < end); | |
2444 | BFD_ASSERT (start <= location); | |
2445 | BFD_ASSERT (location < end); | |
2446 | ||
2447 | /* Put stubs at the end of the group unless that is not a valid | |
2448 | location and the beginning of the group is. It might be that | |
2449 | neither the beginning nor end works if we have an input section | |
2450 | so large that it spans multiple segment boundaries. In that | |
2451 | case, punt; the end result will be a relocation overflow error no | |
2452 | matter what we do here. | |
2453 | ||
2454 | Note that adding stubs pushes up the addresses of all subsequent | |
2455 | sections, so that stubs allocated on one pass through the | |
2456 | relaxation loop may not be valid on the next pass. (E.g., we may | |
2457 | allocate a stub at the beginning of the section on one pass and | |
2458 | find that the call site has been bumped into the next memory | |
2459 | segment on the next pass.) The important thing to note is that | |
2460 | we never try to reclaim the space allocated to such unused stubs, | |
2461 | so code size and section addresses can only increase with each | |
2462 | iteration. Accounting for the start and end addresses of the | |
2463 | already-created stub sections ensures that when the algorithm | |
2464 | converges, it converges accurately, with the entire appropriate | |
2465 | stub section accessible from the call site and not just the | |
2466 | address at the start or end of the stub group proper. */ | |
2467 | ||
2468 | if (segment == CALL26_SEGMENT (end)) | |
2469 | return nios2_stub_call26_after; | |
2470 | else if (segment == CALL26_SEGMENT (start)) | |
2471 | return nios2_stub_call26_before; | |
2472 | else | |
2473 | /* Perhaps this should be a dedicated error code. */ | |
2474 | return nios2_stub_none; | |
2475 | } | |
2476 | ||
0a1b45a2 | 2477 | static bool |
78058a5e SL |
2478 | nios2_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg ATTRIBUTE_UNUSED) |
2479 | { | |
2480 | struct elf32_nios2_stub_hash_entry *hsh | |
2481 | = (struct elf32_nios2_stub_hash_entry *) gen_entry; | |
2482 | asection *stub_sec = hsh->stub_sec; | |
2483 | bfd_vma sym_value; | |
abf874aa | 2484 | struct bfd_link_info *info; |
78058a5e | 2485 | |
abf874aa CL |
2486 | info = (struct bfd_link_info *) in_arg; |
2487 | ||
2488 | /* Fail if the target section could not be assigned to an output | |
2489 | section. The user should fix his linker script. */ | |
2490 | if (hsh->target_section->output_section == NULL | |
2491 | && info->non_contiguous_regions) | |
c63d4862 | 2492 | info->callbacks->einfo (_("%F%P: Could not assign `%pA' to an output section. " |
53215f21 CL |
2493 | "Retry without --enable-non-contiguous-regions.\n"), |
2494 | hsh->target_section); | |
2495 | ||
78058a5e SL |
2496 | /* Make a note of the offset within the stubs for this entry. */ |
2497 | hsh->stub_offset = stub_sec->size; | |
2498 | ||
2499 | switch (hsh->stub_type) | |
2500 | { | |
2501 | case nios2_stub_call26_before: | |
2502 | case nios2_stub_call26_after: | |
2503 | /* A call26 stub looks like: | |
2504 | orhi at, %hiadj(dest) | |
2505 | addi at, at, %lo(dest) | |
2506 | jmp at | |
2507 | Note that call/jmpi instructions can't be used in PIC code | |
2508 | so there is no reason for the stub to be PIC, either. */ | |
2509 | sym_value = (hsh->target_value | |
2510 | + hsh->target_section->output_offset | |
2511 | + hsh->target_section->output_section->vma | |
2512 | + hsh->addend); | |
2513 | ||
2514 | nios2_elf32_install_data (stub_sec, nios2_call26_stub_entry, | |
2515 | hsh->stub_offset, 3); | |
2516 | nios2_elf32_install_imm16 (stub_sec, hsh->stub_offset, | |
2517 | hiadj (sym_value)); | |
2518 | nios2_elf32_install_imm16 (stub_sec, hsh->stub_offset + 4, | |
900c0f0a | 2519 | sym_value); |
78058a5e SL |
2520 | stub_sec->size += 12; |
2521 | break; | |
2522 | default: | |
2523 | BFD_FAIL (); | |
0a1b45a2 | 2524 | return false; |
78058a5e SL |
2525 | } |
2526 | ||
0a1b45a2 | 2527 | return true; |
78058a5e SL |
2528 | } |
2529 | ||
2530 | /* As above, but don't actually build the stub. Just bump offset so | |
2531 | we know stub section sizes. */ | |
0a1b45a2 | 2532 | static bool |
78058a5e SL |
2533 | nios2_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg ATTRIBUTE_UNUSED) |
2534 | { | |
2535 | struct elf32_nios2_stub_hash_entry *hsh | |
2536 | = (struct elf32_nios2_stub_hash_entry *) gen_entry; | |
2537 | ||
2538 | switch (hsh->stub_type) | |
2539 | { | |
2540 | case nios2_stub_call26_before: | |
2541 | case nios2_stub_call26_after: | |
2542 | hsh->stub_sec->size += 12; | |
2543 | break; | |
2544 | default: | |
2545 | BFD_FAIL (); | |
0a1b45a2 | 2546 | return false; |
78058a5e | 2547 | } |
0a1b45a2 | 2548 | return true; |
78058a5e SL |
2549 | } |
2550 | ||
2551 | /* Read in all local syms for all input bfds. | |
2552 | Returns -1 on error, 0 otherwise. */ | |
2553 | ||
2554 | static int | |
2555 | get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd, | |
2556 | struct bfd_link_info *info) | |
2557 | { | |
2558 | unsigned int bfd_indx; | |
2559 | Elf_Internal_Sym *local_syms, **all_local_syms; | |
2560 | struct elf32_nios2_link_hash_table *htab = elf32_nios2_hash_table (info); | |
2561 | ||
2562 | /* We want to read in symbol extension records only once. To do this | |
2563 | we need to read in the local symbols in parallel and save them for | |
2564 | later use; so hold pointers to the local symbols in an array. */ | |
986f0783 | 2565 | size_t amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count; |
78058a5e SL |
2566 | all_local_syms = bfd_zmalloc (amt); |
2567 | htab->all_local_syms = all_local_syms; | |
2568 | if (all_local_syms == NULL) | |
2569 | return -1; | |
2570 | ||
2571 | /* Walk over all the input BFDs, swapping in local symbols. */ | |
2572 | for (bfd_indx = 0; | |
2573 | input_bfd != NULL; | |
c72f2fb2 | 2574 | input_bfd = input_bfd->link.next, bfd_indx++) |
78058a5e SL |
2575 | { |
2576 | Elf_Internal_Shdr *symtab_hdr; | |
2577 | ||
2578 | /* We'll need the symbol table in a second. */ | |
2579 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2580 | if (symtab_hdr->sh_info == 0) | |
2581 | continue; | |
2582 | ||
2583 | /* We need an array of the local symbols attached to the input bfd. */ | |
2584 | local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
2585 | if (local_syms == NULL) | |
2586 | { | |
2587 | local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, | |
2588 | symtab_hdr->sh_info, 0, | |
2589 | NULL, NULL, NULL); | |
2590 | /* Cache them for elf_link_input_bfd. */ | |
2591 | symtab_hdr->contents = (unsigned char *) local_syms; | |
2592 | } | |
2593 | if (local_syms == NULL) | |
2594 | return -1; | |
2595 | ||
2596 | all_local_syms[bfd_indx] = local_syms; | |
2597 | } | |
2598 | ||
2599 | return 0; | |
2600 | } | |
2601 | ||
2602 | /* Determine and set the size of the stub section for a final link. */ | |
0a1b45a2 | 2603 | bool |
78058a5e SL |
2604 | nios2_elf32_size_stubs (bfd *output_bfd, bfd *stub_bfd, |
2605 | struct bfd_link_info *info, | |
2606 | asection *(*add_stub_section) (const char *, | |
0a1b45a2 | 2607 | asection *, bool), |
78058a5e SL |
2608 | void (*layout_sections_again) (void)) |
2609 | { | |
0a1b45a2 | 2610 | bool stub_changed = false; |
78058a5e SL |
2611 | struct elf32_nios2_link_hash_table *htab = elf32_nios2_hash_table (info); |
2612 | ||
2613 | /* Stash our params away. */ | |
2614 | htab->stub_bfd = stub_bfd; | |
2615 | htab->add_stub_section = add_stub_section; | |
2616 | htab->layout_sections_again = layout_sections_again; | |
2617 | ||
2618 | /* FIXME: We only compute the section groups once. This could cause | |
2619 | problems if adding a large stub section causes following sections, | |
2620 | or parts of them, to move into another segment. However, this seems | |
2621 | to be consistent with the way other back ends handle this.... */ | |
2622 | group_sections (htab); | |
2623 | ||
2624 | if (get_local_syms (output_bfd, info->input_bfds, info)) | |
2625 | { | |
2626 | if (htab->all_local_syms) | |
2627 | goto error_ret_free_local; | |
0a1b45a2 | 2628 | return false; |
78058a5e SL |
2629 | } |
2630 | ||
2631 | while (1) | |
2632 | { | |
2633 | bfd *input_bfd; | |
2634 | unsigned int bfd_indx; | |
2635 | asection *stub_sec; | |
2636 | ||
2637 | for (input_bfd = info->input_bfds, bfd_indx = 0; | |
2638 | input_bfd != NULL; | |
c72f2fb2 | 2639 | input_bfd = input_bfd->link.next, bfd_indx++) |
78058a5e SL |
2640 | { |
2641 | Elf_Internal_Shdr *symtab_hdr; | |
2642 | asection *section; | |
2643 | Elf_Internal_Sym *local_syms; | |
2644 | ||
2645 | /* We'll need the symbol table in a second. */ | |
2646 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2647 | if (symtab_hdr->sh_info == 0) | |
2648 | continue; | |
2649 | ||
2650 | local_syms = htab->all_local_syms[bfd_indx]; | |
2651 | ||
2652 | /* Walk over each section attached to the input bfd. */ | |
2653 | for (section = input_bfd->sections; | |
2654 | section != NULL; | |
2655 | section = section->next) | |
2656 | { | |
2657 | Elf_Internal_Rela *internal_relocs, *irelaend, *irela; | |
2658 | ||
2659 | /* If there aren't any relocs, then there's nothing more | |
2660 | to do. */ | |
2661 | if ((section->flags & SEC_RELOC) == 0 | |
2662 | || section->reloc_count == 0) | |
2663 | continue; | |
2664 | ||
2665 | /* If this section is a link-once section that will be | |
2666 | discarded, then don't create any stubs. */ | |
2667 | if (section->output_section == NULL | |
2668 | || section->output_section->owner != output_bfd) | |
2669 | continue; | |
2670 | ||
2671 | /* Get the relocs. */ | |
2672 | internal_relocs | |
2673 | = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, | |
2674 | info->keep_memory); | |
2675 | if (internal_relocs == NULL) | |
2676 | goto error_ret_free_local; | |
2677 | ||
2678 | /* Now examine each relocation. */ | |
2679 | irela = internal_relocs; | |
2680 | irelaend = irela + section->reloc_count; | |
2681 | for (; irela < irelaend; irela++) | |
2682 | { | |
2683 | unsigned int r_type, r_indx; | |
2684 | enum elf32_nios2_stub_type stub_type; | |
2685 | struct elf32_nios2_stub_hash_entry *hsh; | |
2686 | asection *sym_sec; | |
2687 | bfd_vma sym_value; | |
2688 | bfd_vma destination; | |
2689 | struct elf32_nios2_link_hash_entry *hh; | |
2690 | char *stub_name; | |
2691 | const asection *id_sec; | |
2692 | ||
2693 | r_type = ELF32_R_TYPE (irela->r_info); | |
2694 | r_indx = ELF32_R_SYM (irela->r_info); | |
2695 | ||
2696 | if (r_type >= (unsigned int) R_NIOS2_ILLEGAL) | |
2697 | { | |
2698 | bfd_set_error (bfd_error_bad_value); | |
2699 | error_ret_free_internal: | |
2700 | if (elf_section_data (section)->relocs == NULL) | |
2701 | free (internal_relocs); | |
2702 | goto error_ret_free_local; | |
2703 | } | |
2704 | ||
2705 | /* Only look for stubs on CALL and JMPI instructions. */ | |
2706 | if (r_type != (unsigned int) R_NIOS2_CALL26) | |
2707 | continue; | |
2708 | ||
2709 | /* Now determine the call target, its name, value, | |
2710 | section. */ | |
2711 | sym_sec = NULL; | |
2712 | sym_value = 0; | |
2713 | destination = 0; | |
2714 | hh = NULL; | |
2715 | if (r_indx < symtab_hdr->sh_info) | |
2716 | { | |
2717 | /* It's a local symbol. */ | |
2718 | Elf_Internal_Sym *sym; | |
2719 | Elf_Internal_Shdr *hdr; | |
2720 | unsigned int shndx; | |
2721 | ||
2722 | sym = local_syms + r_indx; | |
2723 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
2724 | sym_value = sym->st_value; | |
2725 | shndx = sym->st_shndx; | |
2726 | if (shndx < elf_numsections (input_bfd)) | |
2727 | { | |
2728 | hdr = elf_elfsections (input_bfd)[shndx]; | |
2729 | sym_sec = hdr->bfd_section; | |
2730 | destination = (sym_value + irela->r_addend | |
2731 | + sym_sec->output_offset | |
2732 | + sym_sec->output_section->vma); | |
2733 | } | |
2734 | } | |
2735 | else | |
2736 | { | |
2737 | /* It's an external symbol. */ | |
2738 | int e_indx; | |
2739 | ||
2740 | e_indx = r_indx - symtab_hdr->sh_info; | |
2741 | hh = ((struct elf32_nios2_link_hash_entry *) | |
2742 | elf_sym_hashes (input_bfd)[e_indx]); | |
2743 | ||
2744 | while (hh->root.root.type == bfd_link_hash_indirect | |
2745 | || hh->root.root.type == bfd_link_hash_warning) | |
2746 | hh = ((struct elf32_nios2_link_hash_entry *) | |
2747 | hh->root.root.u.i.link); | |
2748 | ||
2749 | if (hh->root.root.type == bfd_link_hash_defined | |
2750 | || hh->root.root.type == bfd_link_hash_defweak) | |
2751 | { | |
2752 | sym_sec = hh->root.root.u.def.section; | |
2753 | sym_value = hh->root.root.u.def.value; | |
2754 | ||
2755 | if (sym_sec->output_section != NULL) | |
2756 | destination = (sym_value + irela->r_addend | |
2757 | + sym_sec->output_offset | |
2758 | + sym_sec->output_section->vma); | |
2759 | else | |
2760 | continue; | |
2761 | } | |
2762 | else if (hh->root.root.type == bfd_link_hash_undefweak) | |
2763 | { | |
0e1862bb | 2764 | if (! bfd_link_pic (info)) |
78058a5e SL |
2765 | continue; |
2766 | } | |
2767 | else if (hh->root.root.type == bfd_link_hash_undefined) | |
2768 | { | |
2769 | if (! (info->unresolved_syms_in_objects == RM_IGNORE | |
2770 | && (ELF_ST_VISIBILITY (hh->root.other) | |
2771 | == STV_DEFAULT))) | |
2772 | continue; | |
2773 | } | |
2774 | else | |
2775 | { | |
2776 | bfd_set_error (bfd_error_bad_value); | |
2777 | goto error_ret_free_internal; | |
2778 | } | |
2779 | } | |
2780 | ||
2781 | /* Determine what (if any) linker stub is needed. */ | |
2782 | stub_type = nios2_type_of_stub (section, irela, hh, htab, | |
2783 | destination, info); | |
2784 | if (stub_type == nios2_stub_none) | |
2785 | continue; | |
2786 | ||
2787 | /* Support for grouping stub sections. */ | |
2788 | if (stub_type == nios2_stub_call26_before) | |
2789 | id_sec = htab->stub_group[section->id].first_sec; | |
2790 | else | |
2791 | id_sec = htab->stub_group[section->id].last_sec; | |
2792 | ||
2793 | /* Get the name of this stub. */ | |
2794 | stub_name = nios2_stub_name (id_sec, sym_sec, hh, irela, | |
2795 | stub_type); | |
2796 | if (!stub_name) | |
2797 | goto error_ret_free_internal; | |
2798 | ||
2799 | hsh = nios2_stub_hash_lookup (&htab->bstab, | |
2800 | stub_name, | |
0a1b45a2 | 2801 | false, false); |
78058a5e SL |
2802 | if (hsh != NULL) |
2803 | { | |
2804 | /* The proper stub has already been created. */ | |
2805 | free (stub_name); | |
2806 | continue; | |
2807 | } | |
2808 | ||
2809 | hsh = nios2_add_stub (stub_name, section, htab, stub_type); | |
2810 | if (hsh == NULL) | |
2811 | { | |
2812 | free (stub_name); | |
2813 | goto error_ret_free_internal; | |
2814 | } | |
2815 | hsh->target_value = sym_value; | |
2816 | hsh->target_section = sym_sec; | |
2817 | hsh->stub_type = stub_type; | |
2818 | hsh->hh = hh; | |
2819 | hsh->addend = irela->r_addend; | |
0a1b45a2 | 2820 | stub_changed = true; |
78058a5e SL |
2821 | } |
2822 | ||
2823 | /* We're done with the internal relocs, free them. */ | |
2824 | if (elf_section_data (section)->relocs == NULL) | |
2825 | free (internal_relocs); | |
2826 | } | |
2827 | } | |
2828 | ||
2829 | if (!stub_changed) | |
2830 | break; | |
2831 | ||
2832 | /* OK, we've added some stubs. Find out the new size of the | |
2833 | stub sections. */ | |
2834 | for (stub_sec = htab->stub_bfd->sections; | |
2835 | stub_sec != NULL; | |
2836 | stub_sec = stub_sec->next) | |
2837 | stub_sec->size = 0; | |
2838 | ||
2839 | bfd_hash_traverse (&htab->bstab, nios2_size_one_stub, htab); | |
2840 | ||
2841 | /* Ask the linker to do its stuff. */ | |
2842 | (*htab->layout_sections_again) (); | |
0a1b45a2 | 2843 | stub_changed = false; |
78058a5e SL |
2844 | } |
2845 | ||
2846 | free (htab->all_local_syms); | |
0a1b45a2 | 2847 | return true; |
78058a5e SL |
2848 | |
2849 | error_ret_free_local: | |
2850 | free (htab->all_local_syms); | |
0a1b45a2 | 2851 | return false; |
78058a5e SL |
2852 | } |
2853 | ||
2854 | /* Build all the stubs associated with the current output file. The | |
2855 | stubs are kept in a hash table attached to the main linker hash | |
2856 | table. This function is called via nios2elf_finish in the linker. */ | |
0a1b45a2 | 2857 | bool |
78058a5e SL |
2858 | nios2_elf32_build_stubs (struct bfd_link_info *info) |
2859 | { | |
2860 | asection *stub_sec; | |
2861 | struct bfd_hash_table *table; | |
2862 | struct elf32_nios2_link_hash_table *htab; | |
2863 | ||
2864 | htab = elf32_nios2_hash_table (info); | |
2865 | ||
2866 | for (stub_sec = htab->stub_bfd->sections; | |
2867 | stub_sec != NULL; | |
2868 | stub_sec = stub_sec->next) | |
1511baec SL |
2869 | /* The stub_bfd may contain non-stub sections if it is also the |
2870 | dynobj. Any such non-stub sections are created with the | |
2871 | SEC_LINKER_CREATED flag set, while stub sections do not | |
2872 | have that flag. Ignore any non-stub sections here. */ | |
2873 | if ((stub_sec->flags & SEC_LINKER_CREATED) == 0) | |
1b786873 | 2874 | { |
1511baec SL |
2875 | bfd_size_type size; |
2876 | ||
2877 | /* Allocate memory to hold the linker stubs. */ | |
2878 | size = stub_sec->size; | |
2879 | stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); | |
2880 | if (stub_sec->contents == NULL && size != 0) | |
0a1b45a2 | 2881 | return false; |
1511baec SL |
2882 | stub_sec->size = 0; |
2883 | } | |
78058a5e SL |
2884 | |
2885 | /* Build the stubs as directed by the stub hash table. */ | |
2886 | table = &htab->bstab; | |
2887 | bfd_hash_traverse (table, nios2_build_one_stub, info); | |
2888 | ||
0a1b45a2 | 2889 | return true; |
78058a5e SL |
2890 | } |
2891 | ||
2892 | ||
965b1d80 SL |
2893 | #define is_nios2_elf(bfd) \ |
2894 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
2895 | && elf_object_id (bfd) == NIOS2_ELF_DATA) | |
2896 | ||
2897 | /* Merge backend specific data from an object file to the output | |
2898 | object file when linking. */ | |
2899 | ||
0a1b45a2 | 2900 | static bool |
50e03d47 | 2901 | nios2_elf32_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
965b1d80 | 2902 | { |
50e03d47 | 2903 | bfd *obfd = info->output_bfd; |
965b1d80 SL |
2904 | flagword old_flags; |
2905 | flagword new_flags; | |
2906 | ||
2907 | if (!is_nios2_elf (ibfd) || !is_nios2_elf (obfd)) | |
0a1b45a2 | 2908 | return true; |
965b1d80 SL |
2909 | |
2910 | /* Check if we have the same endianness. */ | |
50e03d47 | 2911 | if (! _bfd_generic_verify_endian_match (ibfd, info)) |
0a1b45a2 | 2912 | return false; |
965b1d80 SL |
2913 | |
2914 | new_flags = elf_elfheader (ibfd)->e_flags; | |
2915 | old_flags = elf_elfheader (obfd)->e_flags; | |
2916 | if (!elf_flags_init (obfd)) | |
2917 | { | |
2918 | /* First call, no flags set. */ | |
0a1b45a2 | 2919 | elf_flags_init (obfd) = true; |
965b1d80 SL |
2920 | elf_elfheader (obfd)->e_flags = new_flags; |
2921 | ||
2922 | switch (new_flags) | |
2923 | { | |
2924 | default: | |
2925 | case EF_NIOS2_ARCH_R1: | |
2926 | bfd_default_set_arch_mach (obfd, bfd_arch_nios2, bfd_mach_nios2r1); | |
2927 | break; | |
2928 | case EF_NIOS2_ARCH_R2: | |
2929 | if (bfd_big_endian (ibfd)) | |
2930 | { | |
4eca0228 | 2931 | _bfd_error_handler |
38f14ab8 | 2932 | (_("error: %pB: big-endian R2 is not supported"), ibfd); |
965b1d80 | 2933 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 2934 | return false; |
965b1d80 SL |
2935 | } |
2936 | bfd_default_set_arch_mach (obfd, bfd_arch_nios2, bfd_mach_nios2r2); | |
2937 | break; | |
2938 | } | |
2939 | } | |
2940 | ||
2941 | /* Incompatible flags. */ | |
2942 | else if (new_flags != old_flags) | |
2943 | { | |
2944 | /* So far, the only incompatible flags denote incompatible | |
2945 | architectures. */ | |
4eca0228 | 2946 | _bfd_error_handler |
695344c0 | 2947 | /* xgettext:c-format */ |
38f14ab8 | 2948 | (_("error: %pB: conflicting CPU architectures %d/%d"), |
965b1d80 SL |
2949 | ibfd, new_flags, old_flags); |
2950 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 2951 | return false; |
965b1d80 SL |
2952 | } |
2953 | ||
2954 | /* Merge Tag_compatibility attributes and any common GNU ones. */ | |
50e03d47 | 2955 | _bfd_elf_merge_object_attributes (ibfd, info); |
965b1d80 | 2956 | |
0a1b45a2 | 2957 | return true; |
965b1d80 SL |
2958 | } |
2959 | ||
36591ba1 SL |
2960 | /* Implement bfd_elf32_bfd_reloc_type_lookup: |
2961 | Given a BFD reloc type, return a howto structure. */ | |
f3185997 | 2962 | |
36591ba1 | 2963 | static reloc_howto_type * |
8c163c5a | 2964 | nios2_elf32_bfd_reloc_type_lookup (bfd *abfd, |
36591ba1 SL |
2965 | bfd_reloc_code_real_type code) |
2966 | { | |
2967 | int i; | |
1b786873 | 2968 | |
f3185997 | 2969 | for (i = 0; i < (int) ARRAY_SIZE (nios2_reloc_map); ++i) |
36591ba1 | 2970 | if (nios2_reloc_map[i].bfd_val == code) |
8c163c5a | 2971 | return lookup_howto (nios2_reloc_map[i].elf_val, abfd); |
36591ba1 SL |
2972 | return NULL; |
2973 | } | |
2974 | ||
2975 | /* Implement bfd_elf32_bfd_reloc_name_lookup: | |
2976 | Given a reloc name, return a howto structure. */ | |
f3185997 | 2977 | |
36591ba1 | 2978 | static reloc_howto_type * |
8c163c5a | 2979 | nios2_elf32_bfd_reloc_name_lookup (bfd *abfd, |
36591ba1 SL |
2980 | const char *r_name) |
2981 | { | |
8c163c5a SL |
2982 | int i; |
2983 | reloc_howto_type *howto_tbl; | |
2984 | int howto_tbl_size; | |
36591ba1 | 2985 | |
8c163c5a SL |
2986 | if (BFD_IS_R2 (abfd)) |
2987 | { | |
2988 | howto_tbl = elf_nios2_r2_howto_table_rel; | |
f3185997 | 2989 | howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel); |
8c163c5a SL |
2990 | } |
2991 | else | |
2992 | { | |
2993 | howto_tbl = elf_nios2_r1_howto_table_rel; | |
f3185997 | 2994 | howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel); |
8c163c5a | 2995 | } |
1b786873 | 2996 | |
8c163c5a SL |
2997 | for (i = 0; i < howto_tbl_size; i++) |
2998 | if (howto_tbl[i].name && strcasecmp (howto_tbl[i].name, r_name) == 0) | |
2999 | return howto_tbl + i; | |
f3185997 | 3000 | |
1b786873 | 3001 | return NULL; |
36591ba1 SL |
3002 | } |
3003 | ||
3004 | /* Implement elf_info_to_howto: | |
3005 | Given a ELF32 relocation, fill in a arelent structure. */ | |
f3185997 | 3006 | |
0a1b45a2 | 3007 | static bool |
8c163c5a | 3008 | nios2_elf32_info_to_howto (bfd *abfd, arelent *cache_ptr, |
36591ba1 SL |
3009 | Elf_Internal_Rela *dst) |
3010 | { | |
3011 | unsigned int r_type; | |
3012 | ||
3013 | r_type = ELF32_R_TYPE (dst->r_info); | |
f3185997 NC |
3014 | if ((cache_ptr->howto = lookup_howto (r_type, abfd)) == NULL) |
3015 | { | |
3016 | /* xgettext:c-format */ | |
3017 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), | |
3018 | abfd, r_type); | |
3019 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 3020 | return false; |
f3185997 | 3021 | } |
0a1b45a2 | 3022 | return true; |
36591ba1 SL |
3023 | } |
3024 | ||
3025 | /* Return the base VMA address which should be subtracted from real addresses | |
3026 | when resolving @dtpoff relocation. | |
3027 | This is PT_TLS segment p_vaddr. */ | |
3028 | static bfd_vma | |
3029 | dtpoff_base (struct bfd_link_info *info) | |
3030 | { | |
3031 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3032 | if (elf_hash_table (info)->tls_sec == NULL) | |
3033 | return 0; | |
3034 | return elf_hash_table (info)->tls_sec->vma; | |
3035 | } | |
3036 | ||
3037 | /* Return the relocation value for @tpoff relocation | |
3038 | if STT_TLS virtual address is ADDRESS. */ | |
3039 | static bfd_vma | |
3040 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
3041 | { | |
3042 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
3043 | ||
3044 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
3045 | if (htab->tls_sec == NULL) | |
3046 | return 0; | |
3047 | return address - htab->tls_sec->vma; | |
3048 | } | |
3049 | ||
3050 | /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a | |
3051 | dangerous relocation. */ | |
0a1b45a2 | 3052 | static bool |
36591ba1 SL |
3053 | nios2_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp, struct bfd_link_info *info) |
3054 | { | |
3055 | ||
0a1b45a2 | 3056 | bool gp_found; |
36591ba1 SL |
3057 | struct bfd_hash_entry *h; |
3058 | struct bfd_link_hash_entry *lh; | |
3059 | ||
3060 | /* If we've already figured out what GP will be, just return it. */ | |
3061 | *pgp = _bfd_get_gp_value (output_bfd); | |
3062 | if (*pgp) | |
0a1b45a2 | 3063 | return true; |
36591ba1 | 3064 | |
0a1b45a2 | 3065 | h = bfd_hash_lookup (&info->hash->table, "_gp", false, false); |
36591ba1 | 3066 | lh = (struct bfd_link_hash_entry *) h; |
dc1e8a47 | 3067 | lookup: |
36591ba1 SL |
3068 | if (lh) |
3069 | { | |
3070 | switch (lh->type) | |
3071 | { | |
3072 | case bfd_link_hash_undefined: | |
3073 | case bfd_link_hash_undefweak: | |
3074 | case bfd_link_hash_common: | |
0a1b45a2 | 3075 | gp_found = false; |
36591ba1 SL |
3076 | break; |
3077 | case bfd_link_hash_defined: | |
3078 | case bfd_link_hash_defweak: | |
0a1b45a2 | 3079 | gp_found = true; |
a7be2893 SL |
3080 | { |
3081 | asection *sym_sec = lh->u.def.section; | |
3082 | bfd_vma sym_value = lh->u.def.value; | |
3083 | ||
3084 | if (sym_sec->output_section) | |
3085 | sym_value = (sym_value + sym_sec->output_offset | |
3086 | + sym_sec->output_section->vma); | |
3087 | *pgp = sym_value; | |
3088 | } | |
36591ba1 SL |
3089 | break; |
3090 | case bfd_link_hash_indirect: | |
3091 | case bfd_link_hash_warning: | |
3092 | lh = lh->u.i.link; | |
3093 | /* @@FIXME ignoring warning for now */ | |
3094 | goto lookup; | |
3095 | case bfd_link_hash_new: | |
3096 | default: | |
3097 | abort (); | |
3098 | } | |
3099 | } | |
3100 | else | |
0a1b45a2 | 3101 | gp_found = false; |
36591ba1 SL |
3102 | |
3103 | if (!gp_found) | |
3104 | { | |
3105 | /* Only get the error once. */ | |
3106 | *pgp = 4; | |
3107 | _bfd_set_gp_value (output_bfd, *pgp); | |
0a1b45a2 | 3108 | return false; |
36591ba1 SL |
3109 | } |
3110 | ||
3111 | _bfd_set_gp_value (output_bfd, *pgp); | |
3112 | ||
0a1b45a2 | 3113 | return true; |
36591ba1 SL |
3114 | } |
3115 | ||
3116 | /* Retrieve the previously cached _gp pointer, returning bfd_reloc_dangerous | |
3117 | if it's not available as we don't have a link_info pointer available here | |
3118 | to look it up in the output symbol table. We don't need to adjust the | |
3119 | symbol value for an external symbol if we are producing relocatable | |
3120 | output. */ | |
3121 | static bfd_reloc_status_type | |
0a1b45a2 | 3122 | nios2_elf_final_gp (bfd *output_bfd, asymbol *symbol, bool relocatable, |
36591ba1 SL |
3123 | char **error_message, bfd_vma *pgp) |
3124 | { | |
3125 | if (bfd_is_und_section (symbol->section) && !relocatable) | |
3126 | { | |
3127 | *pgp = 0; | |
3128 | return bfd_reloc_undefined; | |
3129 | } | |
3130 | ||
3131 | *pgp = _bfd_get_gp_value (output_bfd); | |
3132 | if (*pgp == 0 && (!relocatable || (symbol->flags & BSF_SECTION_SYM) != 0)) | |
3133 | { | |
3134 | if (relocatable) | |
3135 | { | |
3136 | /* Make up a value. */ | |
3137 | *pgp = symbol->section->output_section->vma + 0x4000; | |
3138 | _bfd_set_gp_value (output_bfd, *pgp); | |
3139 | } | |
3140 | else | |
3141 | { | |
3142 | *error_message | |
3143 | = (char *) _("global pointer relative relocation when _gp not defined"); | |
3144 | return bfd_reloc_dangerous; | |
3145 | } | |
3146 | } | |
3147 | ||
3148 | return bfd_reloc_ok; | |
3149 | } | |
3150 | ||
36591ba1 SL |
3151 | /* Do the relocations that require special handling. */ |
3152 | static bfd_reloc_status_type | |
1b786873 | 3153 | nios2_elf32_do_hi16_relocate (bfd *abfd, reloc_howto_type *howto, |
25153ba0 | 3154 | asection *input_section, |
1b786873 | 3155 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3156 | bfd_vma symbol_value, bfd_vma addend) |
3157 | { | |
3158 | symbol_value = symbol_value + addend; | |
3159 | addend = 0; | |
3160 | symbol_value = (symbol_value >> 16) & 0xffff; | |
3161 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3162 | data, offset, symbol_value, addend); | |
3163 | } | |
3164 | ||
3165 | static bfd_reloc_status_type | |
3166 | nios2_elf32_do_lo16_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3167 | asection *input_section, |
1b786873 | 3168 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3169 | bfd_vma symbol_value, bfd_vma addend) |
3170 | { | |
3171 | symbol_value = symbol_value + addend; | |
3172 | addend = 0; | |
3173 | symbol_value = symbol_value & 0xffff; | |
3174 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3175 | data, offset, symbol_value, addend); | |
3176 | } | |
3177 | ||
3178 | static bfd_reloc_status_type | |
3179 | nios2_elf32_do_hiadj16_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3180 | asection *input_section, |
36591ba1 SL |
3181 | bfd_byte *data, bfd_vma offset, |
3182 | bfd_vma symbol_value, bfd_vma addend) | |
3183 | { | |
3184 | symbol_value = symbol_value + addend; | |
3185 | addend = 0; | |
3186 | symbol_value = hiadj(symbol_value); | |
3187 | return _bfd_final_link_relocate (howto, abfd, input_section, data, offset, | |
3188 | symbol_value, addend); | |
3189 | } | |
3190 | ||
3191 | static bfd_reloc_status_type | |
3192 | nios2_elf32_do_pcrel_lo16_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3193 | asection *input_section, |
36591ba1 SL |
3194 | bfd_byte *data, bfd_vma offset, |
3195 | bfd_vma symbol_value, bfd_vma addend) | |
3196 | { | |
3197 | symbol_value = symbol_value + addend; | |
3198 | addend = 0; | |
3199 | symbol_value = symbol_value & 0xffff; | |
3200 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3201 | data, offset, symbol_value, addend); | |
3202 | } | |
3203 | ||
3204 | static bfd_reloc_status_type | |
3205 | nios2_elf32_do_pcrel_hiadj16_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3206 | asection *input_section, |
36591ba1 SL |
3207 | bfd_byte *data, bfd_vma offset, |
3208 | bfd_vma symbol_value, bfd_vma addend) | |
3209 | { | |
3210 | symbol_value = symbol_value + addend; | |
3211 | symbol_value -= (input_section->output_section->vma | |
3212 | + input_section->output_offset); | |
3213 | symbol_value -= offset; | |
3214 | addend = 0; | |
3215 | symbol_value = hiadj(symbol_value); | |
3216 | return _bfd_final_link_relocate (howto, abfd, input_section, data, offset, | |
3217 | symbol_value, addend); | |
3218 | } | |
3219 | ||
3220 | static bfd_reloc_status_type | |
3221 | nios2_elf32_do_pcrel16_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3222 | asection *input_section, |
1b786873 | 3223 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3224 | bfd_vma symbol_value, bfd_vma addend) |
3225 | { | |
1b786873 | 3226 | /* NIOS2 pc relative relocations are relative to the next 32-bit instruction |
36591ba1 SL |
3227 | so we need to subtract 4 before doing a final_link_relocate. */ |
3228 | symbol_value = symbol_value + addend - 4; | |
3229 | addend = 0; | |
3230 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3231 | data, offset, symbol_value, addend); | |
3232 | } | |
3233 | ||
3234 | static bfd_reloc_status_type | |
3235 | nios2_elf32_do_call26_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3236 | asection *input_section, |
1b786873 | 3237 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3238 | bfd_vma symbol_value, bfd_vma addend) |
3239 | { | |
3240 | /* Check that the relocation is in the same page as the current address. */ | |
1b786873 | 3241 | if (CALL26_SEGMENT (symbol_value + addend) |
78058a5e SL |
3242 | != CALL26_SEGMENT (input_section->output_section->vma |
3243 | + input_section->output_offset | |
3244 | + offset)) | |
36591ba1 SL |
3245 | return bfd_reloc_overflow; |
3246 | ||
8c163c5a SL |
3247 | /* Check that the target address is correctly aligned on a 4-byte |
3248 | boundary. */ | |
3249 | if ((symbol_value + addend) & 0x3) | |
3250 | return bfd_reloc_overflow; | |
3251 | ||
36591ba1 SL |
3252 | return _bfd_final_link_relocate (howto, abfd, input_section, |
3253 | data, offset, symbol_value, addend); | |
3254 | } | |
3255 | ||
3256 | static bfd_reloc_status_type | |
3257 | nios2_elf32_do_gprel_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3258 | asection *input_section, |
1b786873 | 3259 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3260 | bfd_vma symbol_value, bfd_vma addend) |
3261 | { | |
3262 | /* Because we need the output_bfd, the special handling is done | |
3263 | in nios2_elf32_relocate_section or in nios2_elf32_gprel_relocate. */ | |
3264 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3265 | data, offset, symbol_value, addend); | |
3266 | } | |
3267 | ||
3268 | static bfd_reloc_status_type | |
3269 | nios2_elf32_do_ujmp_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3270 | asection *input_section, |
1b786873 | 3271 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3272 | bfd_vma symbol_value, bfd_vma addend) |
3273 | { | |
3274 | bfd_vma symbol_lo16, symbol_hi16; | |
3275 | bfd_reloc_status_type r; | |
3276 | symbol_value = symbol_value + addend; | |
3277 | addend = 0; | |
3278 | symbol_hi16 = (symbol_value >> 16) & 0xffff; | |
3279 | symbol_lo16 = symbol_value & 0xffff; | |
3280 | ||
3281 | r = _bfd_final_link_relocate (howto, abfd, input_section, | |
3282 | data, offset, symbol_hi16, addend); | |
3283 | ||
3284 | if (r == bfd_reloc_ok) | |
3285 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3286 | data, offset + 4, symbol_lo16, addend); | |
3287 | ||
3288 | return r; | |
3289 | } | |
3290 | ||
3291 | static bfd_reloc_status_type | |
3292 | nios2_elf32_do_cjmp_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3293 | asection *input_section, |
1b786873 | 3294 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3295 | bfd_vma symbol_value, bfd_vma addend) |
3296 | { | |
3297 | bfd_vma symbol_lo16, symbol_hi16; | |
3298 | bfd_reloc_status_type r; | |
3299 | symbol_value = symbol_value + addend; | |
3300 | addend = 0; | |
3301 | symbol_hi16 = (symbol_value >> 16) & 0xffff; | |
3302 | symbol_lo16 = symbol_value & 0xffff; | |
3303 | ||
3304 | r = _bfd_final_link_relocate (howto, abfd, input_section, | |
3305 | data, offset, symbol_hi16, addend); | |
3306 | ||
3307 | if (r == bfd_reloc_ok) | |
3308 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3309 | data, offset + 4, symbol_lo16, addend); | |
3310 | ||
3311 | return r; | |
3312 | } | |
3313 | ||
3314 | static bfd_reloc_status_type | |
3315 | nios2_elf32_do_callr_relocate (bfd *abfd, reloc_howto_type *howto, | |
25153ba0 | 3316 | asection *input_section, |
1b786873 | 3317 | bfd_byte *data, bfd_vma offset, |
36591ba1 SL |
3318 | bfd_vma symbol_value, bfd_vma addend) |
3319 | { | |
3320 | bfd_vma symbol_lo16, symbol_hi16; | |
3321 | bfd_reloc_status_type r; | |
3322 | symbol_value = symbol_value + addend; | |
3323 | addend = 0; | |
3324 | symbol_hi16 = (symbol_value >> 16) & 0xffff; | |
3325 | symbol_lo16 = symbol_value & 0xffff; | |
3326 | ||
3327 | r = _bfd_final_link_relocate (howto, abfd, input_section, | |
3328 | data, offset, symbol_hi16, addend); | |
3329 | ||
3330 | if (r == bfd_reloc_ok) | |
3331 | return _bfd_final_link_relocate (howto, abfd, input_section, | |
3332 | data, offset + 4, symbol_lo16, addend); | |
3333 | ||
3334 | return r; | |
3335 | } | |
3336 | ||
3337 | /* HOWTO handlers for relocations that require special handling. */ | |
3338 | ||
3339 | /* This is for relocations used only when relaxing to ensure | |
3340 | changes in size of section don't screw up .align. */ | |
3341 | static bfd_reloc_status_type | |
3342 | nios2_elf32_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry, | |
1b786873 L |
3343 | asymbol *symbol ATTRIBUTE_UNUSED, |
3344 | void *data ATTRIBUTE_UNUSED, asection *input_section, | |
3345 | bfd *output_bfd, | |
36591ba1 SL |
3346 | char **error_message ATTRIBUTE_UNUSED) |
3347 | { | |
3348 | if (output_bfd != NULL) | |
3349 | reloc_entry->address += input_section->output_offset; | |
3350 | return bfd_reloc_ok; | |
3351 | } | |
3352 | ||
3353 | static bfd_reloc_status_type | |
1b786873 L |
3354 | nios2_elf32_hi16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, |
3355 | void *data, asection *input_section, | |
3356 | bfd *output_bfd, | |
36591ba1 SL |
3357 | char **error_message ATTRIBUTE_UNUSED) |
3358 | { | |
3359 | /* This part is from bfd_elf_generic_reloc. */ | |
3360 | if (output_bfd != NULL | |
3361 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3362 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3363 | { | |
3364 | reloc_entry->address += input_section->output_offset; | |
3365 | return bfd_reloc_ok; | |
3366 | } | |
3367 | ||
3368 | if (output_bfd != NULL) | |
3369 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3370 | return bfd_reloc_continue; | |
3371 | ||
3372 | return nios2_elf32_do_hi16_relocate (abfd, reloc_entry->howto, | |
3373 | input_section, | |
3374 | data, reloc_entry->address, | |
3375 | (symbol->value | |
3376 | + symbol->section->output_section->vma | |
3377 | + symbol->section->output_offset), | |
3378 | reloc_entry->addend); | |
3379 | } | |
3380 | ||
3381 | static bfd_reloc_status_type | |
3382 | nios2_elf32_lo16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 L |
3383 | void *data, asection *input_section, |
3384 | bfd *output_bfd, | |
36591ba1 SL |
3385 | char **error_message ATTRIBUTE_UNUSED) |
3386 | { | |
3387 | /* This part is from bfd_elf_generic_reloc. */ | |
3388 | if (output_bfd != NULL | |
3389 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3390 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3391 | { | |
3392 | reloc_entry->address += input_section->output_offset; | |
3393 | return bfd_reloc_ok; | |
3394 | } | |
3395 | ||
3396 | if (output_bfd != NULL) | |
3397 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3398 | return bfd_reloc_continue; | |
3399 | ||
3400 | return nios2_elf32_do_lo16_relocate (abfd, reloc_entry->howto, | |
3401 | input_section, | |
3402 | data, reloc_entry->address, | |
3403 | (symbol->value | |
3404 | + symbol->section->output_section->vma | |
3405 | + symbol->section->output_offset), | |
3406 | reloc_entry->addend); | |
3407 | } | |
3408 | ||
3409 | static bfd_reloc_status_type | |
3410 | nios2_elf32_hiadj16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 L |
3411 | void *data, asection *input_section, |
3412 | bfd *output_bfd, | |
36591ba1 SL |
3413 | char **error_message ATTRIBUTE_UNUSED) |
3414 | { | |
3415 | /* This part is from bfd_elf_generic_reloc. */ | |
3416 | if (output_bfd != NULL | |
3417 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3418 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3419 | { | |
3420 | reloc_entry->address += input_section->output_offset; | |
3421 | return bfd_reloc_ok; | |
3422 | } | |
3423 | ||
3424 | if (output_bfd != NULL) | |
3425 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3426 | return bfd_reloc_continue; | |
3427 | ||
3428 | return nios2_elf32_do_hiadj16_relocate (abfd, reloc_entry->howto, | |
3429 | input_section, | |
3430 | data, reloc_entry->address, | |
3431 | (symbol->value | |
3432 | + symbol->section->output_section->vma | |
3433 | + symbol->section->output_offset), | |
3434 | reloc_entry->addend); | |
3435 | } | |
3436 | ||
3437 | static bfd_reloc_status_type | |
3438 | nios2_elf32_pcrel_lo16_relocate (bfd *abfd, arelent *reloc_entry, | |
3439 | asymbol *symbol, void *data, | |
3440 | asection *input_section, bfd *output_bfd, | |
3441 | char **error_message ATTRIBUTE_UNUSED) | |
3442 | { | |
3443 | /* This part is from bfd_elf_generic_reloc. */ | |
3444 | if (output_bfd != NULL | |
3445 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3446 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3447 | { | |
3448 | reloc_entry->address += input_section->output_offset; | |
3449 | return bfd_reloc_ok; | |
3450 | } | |
3451 | ||
3452 | if (output_bfd != NULL) | |
3453 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3454 | return bfd_reloc_continue; | |
3455 | ||
3456 | return nios2_elf32_do_pcrel_lo16_relocate ( | |
3457 | abfd, reloc_entry->howto, input_section, data, reloc_entry->address, | |
3458 | (symbol->value + symbol->section->output_section->vma | |
3459 | + symbol->section->output_offset), | |
3460 | reloc_entry->addend); | |
3461 | } | |
3462 | ||
3463 | static bfd_reloc_status_type | |
3464 | nios2_elf32_pcrel_hiadj16_relocate (bfd *abfd, arelent *reloc_entry, | |
3465 | asymbol *symbol, void *data, | |
3466 | asection *input_section, bfd *output_bfd, | |
3467 | char **error_message ATTRIBUTE_UNUSED) | |
3468 | { | |
3469 | /* This part is from bfd_elf_generic_reloc. */ | |
3470 | if (output_bfd != NULL | |
3471 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3472 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3473 | { | |
3474 | reloc_entry->address += input_section->output_offset; | |
3475 | return bfd_reloc_ok; | |
3476 | } | |
3477 | ||
3478 | if (output_bfd != NULL) | |
3479 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3480 | return bfd_reloc_continue; | |
3481 | ||
3482 | return nios2_elf32_do_pcrel_hiadj16_relocate ( | |
3483 | abfd, reloc_entry->howto, input_section, data, reloc_entry->address, | |
3484 | (symbol->value + symbol->section->output_section->vma | |
3485 | + symbol->section->output_offset), | |
3486 | reloc_entry->addend); | |
3487 | } | |
3488 | ||
3489 | static bfd_reloc_status_type | |
3490 | nios2_elf32_pcrel16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 L |
3491 | void *data, asection *input_section, |
3492 | bfd *output_bfd, | |
36591ba1 SL |
3493 | char **error_message ATTRIBUTE_UNUSED) |
3494 | { | |
3495 | /* This part is from bfd_elf_generic_reloc. */ | |
3496 | if (output_bfd != NULL | |
3497 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3498 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3499 | { | |
3500 | reloc_entry->address += input_section->output_offset; | |
3501 | return bfd_reloc_ok; | |
3502 | } | |
3503 | ||
3504 | if (output_bfd != NULL) | |
3505 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3506 | return bfd_reloc_continue; | |
3507 | ||
3508 | return nios2_elf32_do_pcrel16_relocate (abfd, reloc_entry->howto, | |
3509 | input_section, | |
3510 | data, reloc_entry->address, | |
3511 | (symbol->value | |
3512 | + symbol->section->output_section->vma | |
3513 | + symbol->section->output_offset), | |
3514 | reloc_entry->addend); | |
3515 | } | |
3516 | ||
3517 | static bfd_reloc_status_type | |
3518 | nios2_elf32_call26_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 L |
3519 | void *data, asection *input_section, |
3520 | bfd *output_bfd, | |
36591ba1 SL |
3521 | char **error_message ATTRIBUTE_UNUSED) |
3522 | { | |
3523 | /* This part is from bfd_elf_generic_reloc. */ | |
3524 | if (output_bfd != NULL | |
3525 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3526 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3527 | { | |
3528 | reloc_entry->address += input_section->output_offset; | |
3529 | return bfd_reloc_ok; | |
3530 | } | |
3531 | ||
3532 | if (output_bfd != NULL) | |
3533 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3534 | return bfd_reloc_continue; | |
3535 | ||
3536 | return nios2_elf32_do_call26_relocate (abfd, reloc_entry->howto, | |
3537 | input_section, | |
3538 | data, reloc_entry->address, | |
3539 | (symbol->value | |
3540 | + symbol->section->output_section->vma | |
3541 | + symbol->section->output_offset), | |
3542 | reloc_entry->addend); | |
3543 | } | |
3544 | ||
3545 | static bfd_reloc_status_type | |
3546 | nios2_elf32_gprel_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 | 3547 | void *data, asection *input_section, |
36591ba1 SL |
3548 | bfd *output_bfd, char **msg) |
3549 | { | |
3550 | bfd_vma relocation; | |
3551 | bfd_vma gp; | |
3552 | bfd_reloc_status_type r; | |
3553 | ||
3554 | ||
3555 | /* This part is from bfd_elf_generic_reloc. */ | |
3556 | if (output_bfd != NULL | |
3557 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3558 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3559 | { | |
3560 | reloc_entry->address += input_section->output_offset; | |
3561 | return bfd_reloc_ok; | |
3562 | } | |
3563 | ||
3564 | if (output_bfd != NULL) | |
3565 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3566 | return bfd_reloc_continue; | |
3567 | ||
3568 | relocation = (symbol->value | |
3569 | + symbol->section->output_section->vma | |
3570 | + symbol->section->output_offset); | |
3571 | ||
3572 | /* This assumes we've already cached the _gp symbol. */ | |
0a1b45a2 | 3573 | r = nios2_elf_final_gp (abfd, symbol, false, msg, &gp); |
36591ba1 SL |
3574 | if (r == bfd_reloc_ok) |
3575 | { | |
3576 | relocation = relocation + reloc_entry->addend - gp; | |
3577 | reloc_entry->addend = 0; | |
3578 | if ((signed) relocation < -32768 || (signed) relocation > 32767) | |
3579 | { | |
3580 | *msg = _("global pointer relative address out of range"); | |
3581 | r = bfd_reloc_outofrange; | |
3582 | } | |
3583 | else | |
3584 | r = nios2_elf32_do_gprel_relocate (abfd, reloc_entry->howto, | |
3585 | input_section, | |
3586 | data, reloc_entry->address, | |
3587 | relocation, reloc_entry->addend); | |
3588 | } | |
3589 | ||
3590 | return r; | |
3591 | } | |
3592 | ||
3593 | static bfd_reloc_status_type | |
3594 | nios2_elf32_ujmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 | 3595 | void *data, asection *input_section, |
36591ba1 SL |
3596 | bfd *output_bfd, char **msg ATTRIBUTE_UNUSED) |
3597 | { | |
3598 | /* This part is from bfd_elf_generic_reloc. */ | |
3599 | if (output_bfd != NULL | |
3600 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3601 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3602 | { | |
3603 | reloc_entry->address += input_section->output_offset; | |
3604 | return bfd_reloc_ok; | |
3605 | } | |
3606 | ||
3607 | if (output_bfd != NULL) | |
3608 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3609 | return bfd_reloc_continue; | |
3610 | ||
3611 | return nios2_elf32_do_ujmp_relocate (abfd, reloc_entry->howto, | |
3612 | input_section, | |
3613 | data, reloc_entry->address, | |
3614 | (symbol->value | |
3615 | + symbol->section->output_section->vma | |
3616 | + symbol->section->output_offset), | |
3617 | reloc_entry->addend); | |
3618 | } | |
3619 | ||
3620 | static bfd_reloc_status_type | |
3621 | nios2_elf32_cjmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 | 3622 | void *data, asection *input_section, |
36591ba1 SL |
3623 | bfd *output_bfd, char **msg ATTRIBUTE_UNUSED) |
3624 | { | |
3625 | /* This part is from bfd_elf_generic_reloc. */ | |
3626 | if (output_bfd != NULL | |
3627 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3628 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3629 | { | |
3630 | reloc_entry->address += input_section->output_offset; | |
3631 | return bfd_reloc_ok; | |
3632 | } | |
3633 | ||
3634 | if (output_bfd != NULL) | |
3635 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3636 | return bfd_reloc_continue; | |
3637 | ||
3638 | return nios2_elf32_do_cjmp_relocate (abfd, reloc_entry->howto, | |
3639 | input_section, | |
3640 | data, reloc_entry->address, | |
3641 | (symbol->value | |
3642 | + symbol->section->output_section->vma | |
3643 | + symbol->section->output_offset), | |
3644 | reloc_entry->addend); | |
3645 | } | |
3646 | ||
3647 | static bfd_reloc_status_type | |
3648 | nios2_elf32_callr_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, | |
1b786873 | 3649 | void *data, asection *input_section, |
36591ba1 SL |
3650 | bfd *output_bfd, char **msg ATTRIBUTE_UNUSED) |
3651 | { | |
3652 | /* This part is from bfd_elf_generic_reloc. */ | |
3653 | if (output_bfd != NULL | |
3654 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
3655 | && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0)) | |
3656 | { | |
3657 | reloc_entry->address += input_section->output_offset; | |
3658 | return bfd_reloc_ok; | |
3659 | } | |
3660 | ||
3661 | if (output_bfd != NULL) | |
3662 | /* FIXME: See bfd_perform_relocation. Is this right? */ | |
3663 | return bfd_reloc_continue; | |
3664 | ||
3665 | return nios2_elf32_do_callr_relocate (abfd, reloc_entry->howto, | |
3666 | input_section, | |
3667 | data, reloc_entry->address, | |
3668 | (symbol->value | |
3669 | + symbol->section->output_section->vma | |
3670 | + symbol->section->output_offset), | |
3671 | reloc_entry->addend); | |
3672 | } | |
3673 | ||
1b786873 | 3674 | |
36591ba1 | 3675 | /* Implement elf_backend_relocate_section. */ |
0f684201 | 3676 | static int |
36591ba1 SL |
3677 | nios2_elf32_relocate_section (bfd *output_bfd, |
3678 | struct bfd_link_info *info, | |
3679 | bfd *input_bfd, | |
3680 | asection *input_section, | |
3681 | bfd_byte *contents, | |
3682 | Elf_Internal_Rela *relocs, | |
3683 | Elf_Internal_Sym *local_syms, | |
3684 | asection **local_sections) | |
3685 | { | |
3686 | Elf_Internal_Shdr *symtab_hdr; | |
3687 | struct elf_link_hash_entry **sym_hashes; | |
3688 | Elf_Internal_Rela *rel; | |
3689 | Elf_Internal_Rela *relend; | |
3690 | struct elf32_nios2_link_hash_table *htab; | |
3691 | asection *sgot; | |
3692 | asection *splt; | |
3693 | asection *sreloc = NULL; | |
3694 | bfd_vma *local_got_offsets; | |
82e91538 | 3695 | bfd_vma got_base; |
36591ba1 SL |
3696 | |
3697 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
3698 | sym_hashes = elf_sym_hashes (input_bfd); | |
3699 | relend = relocs + input_section->reloc_count; | |
3700 | ||
3701 | htab = elf32_nios2_hash_table (info); | |
3702 | sgot = htab->root.sgot; | |
3703 | splt = htab->root.splt; | |
3704 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
3705 | ||
4ef97a1b | 3706 | if (htab->h_gp_got == NULL) |
82e91538 SL |
3707 | got_base = 0; |
3708 | else | |
4ef97a1b | 3709 | got_base = htab->h_gp_got->root.u.def.value; |
82e91538 | 3710 | |
36591ba1 SL |
3711 | for (rel = relocs; rel < relend; rel++) |
3712 | { | |
3713 | reloc_howto_type *howto; | |
3714 | unsigned long r_symndx; | |
3715 | Elf_Internal_Sym *sym; | |
3716 | asection *sec; | |
3717 | struct elf_link_hash_entry *h; | |
3718 | struct elf32_nios2_link_hash_entry *eh; | |
3719 | bfd_vma relocation; | |
3720 | bfd_vma gp; | |
36591ba1 SL |
3721 | bfd_reloc_status_type r = bfd_reloc_ok; |
3722 | const char *name = NULL; | |
3723 | int r_type; | |
3724 | const char *format; | |
a31b8bd9 | 3725 | char *msg = NULL; |
0a1b45a2 | 3726 | bool unresolved_reloc; |
36591ba1 SL |
3727 | bfd_vma off; |
3728 | int use_plt; | |
3729 | ||
3730 | r_type = ELF32_R_TYPE (rel->r_info); | |
3731 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3732 | ||
8c163c5a | 3733 | howto = lookup_howto ((unsigned) ELF32_R_TYPE (rel->r_info), output_bfd); |
36591ba1 SL |
3734 | h = NULL; |
3735 | sym = NULL; | |
3736 | sec = NULL; | |
3737 | ||
3738 | if (r_symndx < symtab_hdr->sh_info) | |
3739 | { | |
3740 | sym = local_syms + r_symndx; | |
3741 | sec = local_sections[r_symndx]; | |
3742 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
3743 | } | |
3744 | else | |
3745 | { | |
0a1b45a2 | 3746 | bool warned, ignored; |
36591ba1 SL |
3747 | |
3748 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | |
3749 | r_symndx, symtab_hdr, sym_hashes, | |
3750 | h, sec, relocation, | |
62d887d4 | 3751 | unresolved_reloc, warned, ignored); |
36591ba1 SL |
3752 | } |
3753 | ||
3754 | if (sec && discarded_section (sec)) | |
3755 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, | |
3756 | rel, 1, relend, howto, 0, contents); | |
3757 | ||
3758 | /* Nothing more to do unless this is a final link. */ | |
0e1862bb | 3759 | if (bfd_link_relocatable (info)) |
36591ba1 SL |
3760 | continue; |
3761 | ||
36591ba1 SL |
3762 | if (howto) |
3763 | { | |
0a1b45a2 | 3764 | bool resolved_to_zero; |
31a53da5 L |
3765 | |
3766 | resolved_to_zero = (h != NULL | |
3767 | && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); | |
36591ba1 SL |
3768 | switch (howto->type) |
3769 | { | |
3770 | case R_NIOS2_HI16: | |
3771 | r = nios2_elf32_do_hi16_relocate (input_bfd, howto, | |
3772 | input_section, | |
3773 | contents, rel->r_offset, | |
3774 | relocation, rel->r_addend); | |
3775 | break; | |
3776 | case R_NIOS2_LO16: | |
3777 | r = nios2_elf32_do_lo16_relocate (input_bfd, howto, | |
3778 | input_section, | |
3779 | contents, rel->r_offset, | |
3780 | relocation, rel->r_addend); | |
3781 | break; | |
3782 | case R_NIOS2_PCREL_LO: | |
3783 | r = nios2_elf32_do_pcrel_lo16_relocate (input_bfd, howto, | |
3784 | input_section, | |
3785 | contents, | |
3786 | rel->r_offset, | |
3787 | relocation, | |
3788 | rel->r_addend); | |
3789 | break; | |
3790 | case R_NIOS2_HIADJ16: | |
3791 | r = nios2_elf32_do_hiadj16_relocate (input_bfd, howto, | |
3792 | input_section, contents, | |
3793 | rel->r_offset, relocation, | |
3794 | rel->r_addend); | |
3795 | break; | |
3796 | case R_NIOS2_PCREL_HA: | |
3797 | r = nios2_elf32_do_pcrel_hiadj16_relocate (input_bfd, howto, | |
3798 | input_section, | |
3799 | contents, | |
3800 | rel->r_offset, | |
3801 | relocation, | |
3802 | rel->r_addend); | |
3803 | break; | |
3804 | case R_NIOS2_PCREL16: | |
3805 | r = nios2_elf32_do_pcrel16_relocate (input_bfd, howto, | |
3806 | input_section, contents, | |
3807 | rel->r_offset, relocation, | |
3808 | rel->r_addend); | |
3809 | break; | |
3810 | case R_NIOS2_GPREL: | |
3811 | /* Turns an absolute address into a gp-relative address. */ | |
3812 | if (!nios2_elf_assign_gp (output_bfd, &gp, info)) | |
3813 | { | |
a7be2893 SL |
3814 | bfd_vma reloc_address; |
3815 | ||
3816 | if (sec && sec->output_section) | |
3817 | reloc_address = (sec->output_section->vma | |
3818 | + sec->output_offset | |
3819 | + rel->r_offset); | |
3820 | else | |
3821 | reloc_address = 0; | |
3822 | ||
36591ba1 | 3823 | format = _("global pointer relative relocation at address " |
a31b8bd9 | 3824 | "%#" PRIx64 " when _gp not defined\n"); |
6f860418 | 3825 | msg = bfd_asprintf (format, (uint64_t) reloc_address); |
36591ba1 SL |
3826 | r = bfd_reloc_dangerous; |
3827 | } | |
3828 | else | |
3829 | { | |
3830 | bfd_vma symbol_address = rel->r_addend + relocation; | |
a7be2893 | 3831 | relocation = symbol_address - gp; |
36591ba1 SL |
3832 | rel->r_addend = 0; |
3833 | if (((signed) relocation < -32768 | |
3834 | || (signed) relocation > 32767) | |
3835 | && (!h | |
3836 | || h->root.type == bfd_link_hash_defined | |
3837 | || h->root.type == bfd_link_hash_defweak)) | |
3838 | { | |
a7be2893 SL |
3839 | if (h) |
3840 | name = h->root.root.string; | |
a31b8bd9 AM |
3841 | else |
3842 | { | |
3843 | name = (bfd_elf_string_from_elf_section | |
3844 | (input_bfd, symtab_hdr->sh_link, | |
3845 | sym->st_name)); | |
3846 | if (name == NULL || *name == '\0') | |
fd361982 | 3847 | name = bfd_section_name (sec); |
a31b8bd9 | 3848 | } |
695344c0 | 3849 | /* xgettext:c-format */ |
a31b8bd9 AM |
3850 | format = _("unable to reach %s (at %#" PRIx64 ") from " |
3851 | "the global pointer (at %#" PRIx64 ") " | |
3852 | "because the offset (%" PRId64 ") is out of " | |
3853 | "the allowed range, -32678 to 32767\n" ); | |
6f860418 AM |
3854 | msg = bfd_asprintf (format, name, |
3855 | (uint64_t) symbol_address, | |
3856 | (uint64_t) gp, | |
3857 | (int64_t) relocation); | |
36591ba1 SL |
3858 | r = bfd_reloc_outofrange; |
3859 | } | |
3860 | else | |
3861 | r = _bfd_final_link_relocate (howto, input_bfd, | |
3862 | input_section, contents, | |
3863 | rel->r_offset, relocation, | |
3864 | rel->r_addend); | |
3865 | } | |
36591ba1 SL |
3866 | break; |
3867 | case R_NIOS2_UJMP: | |
3868 | r = nios2_elf32_do_ujmp_relocate (input_bfd, howto, | |
3869 | input_section, | |
3870 | contents, rel->r_offset, | |
3871 | relocation, rel->r_addend); | |
3872 | break; | |
3873 | case R_NIOS2_CJMP: | |
3874 | r = nios2_elf32_do_cjmp_relocate (input_bfd, howto, | |
3875 | input_section, | |
3876 | contents, rel->r_offset, | |
3877 | relocation, rel->r_addend); | |
3878 | break; | |
3879 | case R_NIOS2_CALLR: | |
3880 | r = nios2_elf32_do_callr_relocate (input_bfd, howto, | |
3881 | input_section, contents, | |
3882 | rel->r_offset, relocation, | |
3883 | rel->r_addend); | |
3884 | break; | |
3885 | case R_NIOS2_CALL26: | |
78058a5e | 3886 | case R_NIOS2_CALL26_NOAT: |
36591ba1 SL |
3887 | /* If we have a call to an undefined weak symbol, we just want |
3888 | to stuff a zero in the bits of the call instruction and | |
3889 | bypass the normal call26 relocation handling, because it'll | |
3890 | diagnose an overflow error if address 0 isn't in the same | |
3891 | 256MB segment as the call site. Presumably the call | |
3892 | should be guarded by a null check anyway. */ | |
3893 | if (h != NULL && h->root.type == bfd_link_hash_undefweak) | |
3894 | { | |
3895 | BFD_ASSERT (relocation == 0 && rel->r_addend == 0); | |
3896 | r = _bfd_final_link_relocate (howto, input_bfd, | |
3897 | input_section, contents, | |
3898 | rel->r_offset, relocation, | |
3899 | rel->r_addend); | |
3900 | break; | |
3901 | } | |
3902 | /* Handle relocations which should use the PLT entry. | |
3903 | NIOS2_BFD_RELOC_32 relocations will use the symbol's value, | |
3904 | which may point to a PLT entry, but we don't need to handle | |
3905 | that here. If we created a PLT entry, all branches in this | |
3906 | object should go to it. */ | |
3907 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
3908 | { | |
3909 | /* If we've created a .plt section, and assigned a PLT entry | |
3910 | to this function, it should not be known to bind locally. | |
3911 | If it were, we would have cleared the PLT entry. */ | |
3912 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); | |
3913 | ||
3914 | relocation = (splt->output_section->vma | |
3915 | + splt->output_offset | |
3916 | + h->plt.offset); | |
3917 | ||
0a1b45a2 | 3918 | unresolved_reloc = false; |
36591ba1 | 3919 | } |
78058a5e SL |
3920 | /* Detect R_NIOS2_CALL26 relocations that would overflow the |
3921 | 256MB segment. Replace the target with a reference to a | |
3922 | trampoline instead. | |
3923 | Note that htab->stub_group is null if relaxation has been | |
3924 | disabled by the --no-relax linker command-line option, so | |
3925 | we can use that to skip this processing entirely. */ | |
3926 | if (howto->type == R_NIOS2_CALL26 && htab->stub_group) | |
3927 | { | |
3928 | bfd_vma dest = relocation + rel->r_addend; | |
3929 | enum elf32_nios2_stub_type stub_type; | |
3930 | ||
3931 | eh = (struct elf32_nios2_link_hash_entry *)h; | |
3932 | stub_type = nios2_type_of_stub (input_section, rel, eh, | |
3933 | htab, dest, NULL); | |
3934 | ||
3935 | if (stub_type != nios2_stub_none) | |
3936 | { | |
3937 | struct elf32_nios2_stub_hash_entry *hsh; | |
3938 | ||
3939 | hsh = nios2_get_stub_entry (input_section, sec, | |
3940 | eh, rel, htab, stub_type); | |
3941 | if (hsh == NULL) | |
3942 | { | |
3943 | r = bfd_reloc_undefined; | |
3944 | break; | |
3945 | } | |
3946 | ||
3947 | dest = (hsh->stub_offset | |
3948 | + hsh->stub_sec->output_offset | |
3949 | + hsh->stub_sec->output_section->vma); | |
3950 | r = nios2_elf32_do_call26_relocate (input_bfd, howto, | |
3951 | input_section, | |
3952 | contents, | |
3953 | rel->r_offset, | |
3954 | dest, 0); | |
3955 | break; | |
3956 | } | |
3957 | } | |
3958 | ||
3959 | /* Normal case. */ | |
36591ba1 SL |
3960 | r = nios2_elf32_do_call26_relocate (input_bfd, howto, |
3961 | input_section, contents, | |
3962 | rel->r_offset, relocation, | |
3963 | rel->r_addend); | |
3964 | break; | |
3965 | case R_NIOS2_ALIGN: | |
3966 | r = bfd_reloc_ok; | |
3967 | /* For symmetry this would be | |
3968 | r = nios2_elf32_do_ignore_reloc (input_bfd, howto, | |
3969 | input_section, contents, | |
3970 | rel->r_offset, relocation, | |
3971 | rel->r_addend); | |
3972 | but do_ignore_reloc would do no more than return | |
3973 | bfd_reloc_ok. */ | |
3974 | break; | |
3975 | ||
3976 | case R_NIOS2_GOT16: | |
3977 | case R_NIOS2_CALL16: | |
1c2de463 SL |
3978 | case R_NIOS2_GOT_LO: |
3979 | case R_NIOS2_GOT_HA: | |
3980 | case R_NIOS2_CALL_LO: | |
3981 | case R_NIOS2_CALL_HA: | |
36591ba1 SL |
3982 | /* Relocation is to the entry for this symbol in the |
3983 | global offset table. */ | |
3984 | if (sgot == NULL) | |
3985 | { | |
3986 | r = bfd_reloc_notsupported; | |
3987 | break; | |
3988 | } | |
3989 | ||
3990 | use_plt = 0; | |
3991 | ||
3992 | if (h != NULL) | |
3993 | { | |
0a1b45a2 | 3994 | bool dyn; |
36591ba1 SL |
3995 | |
3996 | eh = (struct elf32_nios2_link_hash_entry *)h; | |
1c2de463 | 3997 | use_plt = (eh->got_types_used == CALL_USED |
36591ba1 SL |
3998 | && h->plt.offset != (bfd_vma) -1); |
3999 | ||
4000 | off = h->got.offset; | |
4001 | BFD_ASSERT (off != (bfd_vma) -1); | |
4ef97a1b | 4002 | dyn = htab->root.dynamic_sections_created; |
0e1862bb L |
4003 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
4004 | bfd_link_pic (info), | |
4005 | h) | |
4006 | || (bfd_link_pic (info) | |
36591ba1 | 4007 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
31a53da5 L |
4008 | || ((ELF_ST_VISIBILITY (h->other) |
4009 | || resolved_to_zero) | |
36591ba1 SL |
4010 | && h->root.type == bfd_link_hash_undefweak)) |
4011 | { | |
4012 | /* This is actually a static link, or it is a -Bsymbolic | |
4013 | link and the symbol is defined locally. We must | |
4014 | initialize this entry in the global offset table. | |
4015 | Since the offset must always be a multiple of 4, we | |
4016 | use the least significant bit to record whether we | |
4017 | have initialized it already. | |
4018 | ||
4019 | When doing a dynamic link, we create a .rela.got | |
4020 | relocation entry to initialize the value. This is | |
4021 | done in the finish_dynamic_symbol routine. */ | |
4022 | if ((off & 1) != 0) | |
4023 | off &= ~1; | |
4024 | else | |
4025 | { | |
4026 | bfd_put_32 (output_bfd, relocation, | |
4027 | sgot->contents + off); | |
4028 | h->got.offset |= 1; | |
4029 | } | |
4030 | } | |
4031 | else | |
0a1b45a2 | 4032 | unresolved_reloc = false; |
36591ba1 SL |
4033 | } |
4034 | else | |
4035 | { | |
4036 | BFD_ASSERT (local_got_offsets != NULL | |
4037 | && local_got_offsets[r_symndx] != (bfd_vma) -1); | |
4038 | ||
4039 | off = local_got_offsets[r_symndx]; | |
4040 | ||
4041 | /* The offset must always be a multiple of 4. We use the | |
4042 | least significant bit to record whether we have already | |
4043 | generated the necessary reloc. */ | |
4044 | if ((off & 1) != 0) | |
4045 | off &= ~1; | |
4046 | else | |
4047 | { | |
4048 | bfd_put_32 (output_bfd, relocation, | |
4049 | sgot->contents + off); | |
4050 | ||
0e1862bb | 4051 | if (bfd_link_pic (info)) |
36591ba1 SL |
4052 | { |
4053 | asection *srelgot; | |
4054 | Elf_Internal_Rela outrel; | |
4055 | bfd_byte *loc; | |
4056 | ||
4057 | srelgot = htab->root.srelgot; | |
4058 | BFD_ASSERT (srelgot != NULL); | |
4059 | ||
4060 | outrel.r_addend = relocation; | |
4061 | outrel.r_offset = (sgot->output_section->vma | |
4062 | + sgot->output_offset | |
4063 | + off); | |
4064 | outrel.r_info = ELF32_R_INFO (0, R_NIOS2_RELATIVE); | |
4065 | loc = srelgot->contents; | |
4066 | loc += (srelgot->reloc_count++ * | |
4067 | sizeof (Elf32_External_Rela)); | |
4068 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4069 | } | |
4070 | ||
4071 | local_got_offsets[r_symndx] |= 1; | |
4072 | } | |
4073 | } | |
4074 | ||
0e1862bb | 4075 | if (use_plt && bfd_link_pic (info)) |
36591ba1 SL |
4076 | { |
4077 | off = ((h->plt.offset - 24) / 12 + 3) * 4; | |
82e91538 SL |
4078 | relocation = (htab->root.sgotplt->output_offset + off |
4079 | - got_base); | |
36591ba1 SL |
4080 | } |
4081 | else | |
82e91538 | 4082 | relocation = sgot->output_offset + off - got_base; |
36591ba1 SL |
4083 | |
4084 | /* This relocation does not use the addend. */ | |
4085 | rel->r_addend = 0; | |
4086 | ||
1c2de463 SL |
4087 | switch (howto->type) |
4088 | { | |
4089 | case R_NIOS2_GOT_LO: | |
4090 | case R_NIOS2_CALL_LO: | |
4091 | r = nios2_elf32_do_lo16_relocate (input_bfd, howto, | |
4092 | input_section, contents, | |
4093 | rel->r_offset, relocation, | |
4094 | rel->r_addend); | |
4095 | break; | |
4096 | case R_NIOS2_GOT_HA: | |
4097 | case R_NIOS2_CALL_HA: | |
4098 | r = nios2_elf32_do_hiadj16_relocate (input_bfd, howto, | |
4099 | input_section, contents, | |
4100 | rel->r_offset, | |
4101 | relocation, | |
4102 | rel->r_addend); | |
4103 | break; | |
4104 | default: | |
4105 | r = _bfd_final_link_relocate (howto, input_bfd, | |
4106 | input_section, contents, | |
4107 | rel->r_offset, relocation, | |
4108 | rel->r_addend); | |
4109 | break; | |
4110 | } | |
36591ba1 SL |
4111 | break; |
4112 | ||
4113 | case R_NIOS2_GOTOFF_LO: | |
4114 | case R_NIOS2_GOTOFF_HA: | |
4115 | case R_NIOS2_GOTOFF: | |
82e91538 | 4116 | /* Relocation is relative to the global offset table pointer. */ |
36591ba1 SL |
4117 | |
4118 | BFD_ASSERT (sgot != NULL); | |
4119 | if (sgot == NULL) | |
4120 | { | |
4121 | r = bfd_reloc_notsupported; | |
4122 | break; | |
4123 | } | |
4124 | ||
d9972968 CLT |
4125 | /* Note that sgot->output_offset is not involved in this |
4126 | calculation. We always want the start of .got. */ | |
4127 | relocation -= sgot->output_section->vma; | |
4128 | ||
4129 | /* Now we adjust the relocation to be relative to the GOT pointer | |
4130 | (the _gp_got symbol), which possibly contains the 0x8000 bias. */ | |
4131 | relocation -= got_base; | |
82e91538 | 4132 | |
36591ba1 SL |
4133 | switch (howto->type) |
4134 | { | |
4135 | case R_NIOS2_GOTOFF_LO: | |
4136 | r = nios2_elf32_do_lo16_relocate (input_bfd, howto, | |
4137 | input_section, contents, | |
4138 | rel->r_offset, relocation, | |
4139 | rel->r_addend); | |
4140 | break; | |
4141 | case R_NIOS2_GOTOFF_HA: | |
4142 | r = nios2_elf32_do_hiadj16_relocate (input_bfd, howto, | |
4143 | input_section, contents, | |
4144 | rel->r_offset, | |
4145 | relocation, | |
4146 | rel->r_addend); | |
4147 | break; | |
4148 | default: | |
4149 | r = _bfd_final_link_relocate (howto, input_bfd, | |
4150 | input_section, contents, | |
4151 | rel->r_offset, relocation, | |
4152 | rel->r_addend); | |
4153 | break; | |
4154 | } | |
4155 | break; | |
4156 | ||
4157 | case R_NIOS2_TLS_LDO16: | |
4158 | relocation -= dtpoff_base (info) + DTP_OFFSET; | |
4159 | ||
4160 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4161 | contents, rel->r_offset, | |
4162 | relocation, rel->r_addend); | |
4163 | break; | |
4164 | case R_NIOS2_TLS_LDM16: | |
4165 | if (htab->root.sgot == NULL) | |
4166 | abort (); | |
4167 | ||
4168 | off = htab->tls_ldm_got.offset; | |
4169 | ||
4170 | if ((off & 1) != 0) | |
4171 | off &= ~1; | |
4172 | else | |
4173 | { | |
4174 | /* If we don't know the module number, create a relocation | |
4175 | for it. */ | |
0e1862bb | 4176 | if (bfd_link_pic (info)) |
36591ba1 SL |
4177 | { |
4178 | Elf_Internal_Rela outrel; | |
4179 | bfd_byte *loc; | |
4180 | ||
4181 | if (htab->root.srelgot == NULL) | |
4182 | abort (); | |
4183 | ||
4184 | outrel.r_addend = 0; | |
4185 | outrel.r_offset = (htab->root.sgot->output_section->vma | |
4186 | + htab->root.sgot->output_offset | |
4187 | + off); | |
4188 | outrel.r_info = ELF32_R_INFO (0, R_NIOS2_TLS_DTPMOD); | |
4189 | ||
4190 | loc = htab->root.srelgot->contents; | |
4191 | loc += (htab->root.srelgot->reloc_count++ | |
4192 | * sizeof (Elf32_External_Rela)); | |
4193 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4194 | } | |
4195 | else | |
4196 | bfd_put_32 (output_bfd, 1, | |
4197 | htab->root.sgot->contents + off); | |
4198 | ||
4199 | htab->tls_ldm_got.offset |= 1; | |
4200 | } | |
4201 | ||
82e91538 | 4202 | relocation = htab->root.sgot->output_offset + off - got_base; |
36591ba1 SL |
4203 | |
4204 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4205 | contents, rel->r_offset, | |
4206 | relocation, rel->r_addend); | |
4207 | ||
4208 | break; | |
4209 | case R_NIOS2_TLS_GD16: | |
4210 | case R_NIOS2_TLS_IE16: | |
4211 | { | |
4212 | int indx; | |
4213 | char tls_type; | |
4214 | ||
4215 | if (htab->root.sgot == NULL) | |
4216 | abort (); | |
4217 | ||
4218 | indx = 0; | |
4219 | if (h != NULL) | |
4220 | { | |
0a1b45a2 | 4221 | bool dyn; |
36591ba1 | 4222 | dyn = htab->root.dynamic_sections_created; |
0e1862bb L |
4223 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, |
4224 | bfd_link_pic (info), | |
4225 | h) | |
4226 | && (!bfd_link_pic (info) | |
36591ba1 SL |
4227 | || !SYMBOL_REFERENCES_LOCAL (info, h))) |
4228 | { | |
0a1b45a2 | 4229 | unresolved_reloc = false; |
36591ba1 SL |
4230 | indx = h->dynindx; |
4231 | } | |
4232 | off = h->got.offset; | |
4233 | tls_type = (((struct elf32_nios2_link_hash_entry *) h) | |
4234 | ->tls_type); | |
4235 | } | |
4236 | else | |
4237 | { | |
4238 | if (local_got_offsets == NULL) | |
4239 | abort (); | |
4240 | off = local_got_offsets[r_symndx]; | |
4241 | tls_type = (elf32_nios2_local_got_tls_type (input_bfd) | |
4242 | [r_symndx]); | |
4243 | } | |
4244 | ||
4245 | if (tls_type == GOT_UNKNOWN) | |
4246 | abort (); | |
4247 | ||
4248 | if ((off & 1) != 0) | |
4249 | off &= ~1; | |
4250 | else | |
4251 | { | |
0a1b45a2 | 4252 | bool need_relocs = false; |
36591ba1 SL |
4253 | Elf_Internal_Rela outrel; |
4254 | bfd_byte *loc = NULL; | |
4255 | int cur_off = off; | |
4256 | ||
4257 | /* The GOT entries have not been initialized yet. Do it | |
4258 | now, and emit any relocations. If both an IE GOT and a | |
4259 | GD GOT are necessary, we emit the GD first. */ | |
4260 | ||
0e1862bb | 4261 | if ((bfd_link_pic (info) || indx != 0) |
36591ba1 | 4262 | && (h == NULL |
31a53da5 L |
4263 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
4264 | && !resolved_to_zero) | |
36591ba1 SL |
4265 | || h->root.type != bfd_link_hash_undefweak)) |
4266 | { | |
0a1b45a2 | 4267 | need_relocs = true; |
36591ba1 SL |
4268 | if (htab->root.srelgot == NULL) |
4269 | abort (); | |
4270 | loc = htab->root.srelgot->contents; | |
4271 | loc += (htab->root.srelgot->reloc_count * | |
4272 | sizeof (Elf32_External_Rela)); | |
4273 | } | |
4274 | ||
4275 | if (tls_type & GOT_TLS_GD) | |
4276 | { | |
4277 | if (need_relocs) | |
4278 | { | |
4279 | outrel.r_addend = 0; | |
4280 | outrel.r_offset = (htab->root.sgot->output_section->vma | |
4281 | + htab->root.sgot->output_offset | |
4282 | + cur_off); | |
4283 | outrel.r_info = ELF32_R_INFO (indx, | |
4284 | R_NIOS2_TLS_DTPMOD); | |
4285 | ||
4286 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
4287 | loc); | |
4288 | htab->root.srelgot->reloc_count++; | |
4289 | loc += sizeof (Elf32_External_Rela); | |
4290 | ||
4291 | if (indx == 0) | |
4292 | bfd_put_32 (output_bfd, | |
4293 | (relocation - dtpoff_base (info) - | |
4294 | DTP_OFFSET), | |
4295 | htab->root.sgot->contents + cur_off + 4); | |
4296 | else | |
4297 | { | |
4298 | outrel.r_addend = 0; | |
4299 | outrel.r_info = ELF32_R_INFO (indx, | |
4300 | R_NIOS2_TLS_DTPREL); | |
4301 | outrel.r_offset += 4; | |
4302 | ||
4303 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
4304 | loc); | |
4305 | htab->root.srelgot->reloc_count++; | |
4306 | loc += sizeof (Elf32_External_Rela); | |
4307 | } | |
4308 | } | |
4309 | else | |
4310 | { | |
4311 | /* If we are not emitting relocations for a | |
4312 | general dynamic reference, then we must be in a | |
4313 | static link or an executable link with the | |
4314 | symbol binding locally. Mark it as belonging | |
4315 | to module 1, the executable. */ | |
4316 | bfd_put_32 (output_bfd, 1, | |
4317 | htab->root.sgot->contents + cur_off); | |
4318 | bfd_put_32 (output_bfd, (relocation - | |
4319 | dtpoff_base (info) - | |
4320 | DTP_OFFSET), | |
4321 | htab->root.sgot->contents + cur_off + 4); | |
4322 | } | |
4323 | ||
4324 | cur_off += 8; | |
4325 | } | |
4326 | ||
4327 | if (tls_type & GOT_TLS_IE) | |
4328 | { | |
4329 | if (need_relocs) | |
4330 | { | |
4331 | if (indx == 0) | |
4332 | outrel.r_addend = (relocation - | |
4333 | dtpoff_base (info)); | |
4334 | else | |
4335 | outrel.r_addend = 0; | |
4336 | outrel.r_offset = (htab->root.sgot->output_section->vma | |
4337 | + htab->root.sgot->output_offset | |
4338 | + cur_off); | |
4339 | outrel.r_info = ELF32_R_INFO (indx, | |
4340 | R_NIOS2_TLS_TPREL); | |
4341 | ||
4342 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
4343 | loc); | |
4344 | htab->root.srelgot->reloc_count++; | |
4345 | loc += sizeof (Elf32_External_Rela); | |
4346 | } | |
4347 | else | |
4348 | bfd_put_32 (output_bfd, (tpoff (info, relocation) | |
4349 | - TP_OFFSET), | |
4350 | htab->root.sgot->contents + cur_off); | |
4351 | cur_off += 4; | |
4352 | } | |
4353 | ||
4354 | if (h != NULL) | |
4355 | h->got.offset |= 1; | |
4356 | else | |
4357 | local_got_offsets[r_symndx] |= 1; | |
4358 | } | |
4359 | ||
4360 | if ((tls_type & GOT_TLS_GD) && r_type != R_NIOS2_TLS_GD16) | |
4361 | off += 8; | |
82e91538 | 4362 | relocation = htab->root.sgot->output_offset + off - got_base; |
36591ba1 SL |
4363 | |
4364 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4365 | contents, rel->r_offset, | |
4366 | relocation, rel->r_addend); | |
4367 | } | |
4368 | ||
4369 | break; | |
4370 | case R_NIOS2_TLS_LE16: | |
3cbc1e5e | 4371 | if (bfd_link_dll (info)) |
36591ba1 | 4372 | { |
4eca0228 | 4373 | _bfd_error_handler |
695344c0 | 4374 | /* xgettext:c-format */ |
2dcf00ce | 4375 | (_("%pB(%pA+%#" PRIx64 "): %s relocation not " |
36591ba1 SL |
4376 | "permitted in shared object"), |
4377 | input_bfd, input_section, | |
2dcf00ce | 4378 | (uint64_t) rel->r_offset, howto->name); |
0a1b45a2 | 4379 | return false; |
36591ba1 SL |
4380 | } |
4381 | else | |
4382 | relocation = tpoff (info, relocation) - TP_OFFSET; | |
4383 | ||
4384 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4385 | contents, rel->r_offset, | |
4386 | relocation, rel->r_addend); | |
4387 | break; | |
4388 | ||
4389 | case R_NIOS2_BFD_RELOC_32: | |
0e1862bb | 4390 | if (bfd_link_pic (info) |
36591ba1 SL |
4391 | && (input_section->flags & SEC_ALLOC) != 0 |
4392 | && (h == NULL | |
31a53da5 L |
4393 | || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
4394 | && !resolved_to_zero) | |
36591ba1 SL |
4395 | || h->root.type != bfd_link_hash_undefweak)) |
4396 | { | |
4397 | Elf_Internal_Rela outrel; | |
4398 | bfd_byte *loc; | |
0a1b45a2 | 4399 | bool skip, relocate; |
36591ba1 SL |
4400 | |
4401 | /* When generating a shared object, these relocations | |
4402 | are copied into the output file to be resolved at run | |
4403 | time. */ | |
4404 | ||
0a1b45a2 AM |
4405 | skip = false; |
4406 | relocate = false; | |
36591ba1 SL |
4407 | |
4408 | outrel.r_offset | |
4409 | = _bfd_elf_section_offset (output_bfd, info, | |
4410 | input_section, rel->r_offset); | |
4411 | if (outrel.r_offset == (bfd_vma) -1) | |
0a1b45a2 | 4412 | skip = true; |
36591ba1 | 4413 | else if (outrel.r_offset == (bfd_vma) -2) |
0a1b45a2 | 4414 | skip = true, relocate = true; |
36591ba1 SL |
4415 | outrel.r_offset += (input_section->output_section->vma |
4416 | + input_section->output_offset); | |
4417 | ||
4418 | if (skip) | |
4419 | memset (&outrel, 0, sizeof outrel); | |
4420 | else if (h != NULL | |
4421 | && h->dynindx != -1 | |
0e1862bb | 4422 | && (!bfd_link_pic (info) |
a496fbc8 | 4423 | || !SYMBOLIC_BIND (info, h) |
36591ba1 SL |
4424 | || !h->def_regular)) |
4425 | { | |
4426 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); | |
4427 | outrel.r_addend = rel->r_addend; | |
4428 | } | |
4429 | else | |
4430 | { | |
4431 | /* This symbol is local, or marked to become local. */ | |
4432 | outrel.r_addend = relocation + rel->r_addend; | |
0a1b45a2 | 4433 | relocate = true; |
36591ba1 SL |
4434 | outrel.r_info = ELF32_R_INFO (0, R_NIOS2_RELATIVE); |
4435 | } | |
4436 | ||
4437 | sreloc = elf_section_data (input_section)->sreloc; | |
4438 | if (sreloc == NULL) | |
4439 | abort (); | |
4440 | ||
4441 | loc = sreloc->contents; | |
4442 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
4443 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
4444 | ||
4445 | /* This reloc will be computed at runtime, so there's no | |
4446 | need to do anything now, except for R_NIOS2_BFD_RELOC_32 | |
4447 | relocations that have been turned into | |
4448 | R_NIOS2_RELATIVE. */ | |
4449 | if (!relocate) | |
4450 | break; | |
4451 | } | |
4452 | ||
4453 | r = _bfd_final_link_relocate (howto, input_bfd, | |
4454 | input_section, contents, | |
4455 | rel->r_offset, relocation, | |
4456 | rel->r_addend); | |
4457 | break; | |
4458 | ||
4459 | case R_NIOS2_TLS_DTPREL: | |
4460 | relocation -= dtpoff_base (info); | |
4461 | /* Fall through. */ | |
4462 | ||
4463 | default: | |
4464 | r = _bfd_final_link_relocate (howto, input_bfd, | |
4465 | input_section, contents, | |
4466 | rel->r_offset, relocation, | |
4467 | rel->r_addend); | |
4468 | break; | |
4469 | } | |
4470 | } | |
4471 | else | |
4472 | r = bfd_reloc_notsupported; | |
4473 | ||
4474 | if (r != bfd_reloc_ok) | |
4475 | { | |
4476 | if (h != NULL) | |
4477 | name = h->root.root.string; | |
4478 | else | |
4479 | { | |
4480 | name = bfd_elf_string_from_elf_section (input_bfd, | |
4481 | symtab_hdr->sh_link, | |
4482 | sym->st_name); | |
4483 | if (name == NULL || *name == '\0') | |
fd361982 | 4484 | name = bfd_section_name (sec); |
36591ba1 SL |
4485 | } |
4486 | ||
4487 | switch (r) | |
4488 | { | |
4489 | case bfd_reloc_overflow: | |
1a72702b AM |
4490 | (*info->callbacks->reloc_overflow) (info, NULL, name, |
4491 | howto->name, (bfd_vma) 0, | |
4492 | input_bfd, input_section, | |
4493 | rel->r_offset); | |
36591ba1 SL |
4494 | break; |
4495 | ||
4496 | case bfd_reloc_undefined: | |
1a72702b AM |
4497 | (*info->callbacks->undefined_symbol) (info, name, input_bfd, |
4498 | input_section, | |
0a1b45a2 | 4499 | rel->r_offset, true); |
36591ba1 SL |
4500 | break; |
4501 | ||
4502 | case bfd_reloc_outofrange: | |
4503 | if (msg == NULL) | |
4504 | msg = _("relocation out of range"); | |
4505 | break; | |
4506 | ||
4507 | case bfd_reloc_notsupported: | |
4508 | if (msg == NULL) | |
4509 | msg = _("unsupported relocation"); | |
4510 | break; | |
4511 | ||
4512 | case bfd_reloc_dangerous: | |
4513 | if (msg == NULL) | |
4514 | msg = _("dangerous relocation"); | |
4515 | break; | |
4516 | ||
4517 | default: | |
4518 | if (msg == NULL) | |
4519 | msg = _("unknown error"); | |
4520 | break; | |
4521 | } | |
4522 | ||
4523 | if (msg) | |
4524 | { | |
1a72702b AM |
4525 | (*info->callbacks->warning) (info, msg, name, input_bfd, |
4526 | input_section, rel->r_offset); | |
0a1b45a2 | 4527 | return false; |
36591ba1 SL |
4528 | } |
4529 | } | |
4530 | } | |
0a1b45a2 | 4531 | return true; |
36591ba1 SL |
4532 | } |
4533 | ||
4534 | /* Implement elf-backend_section_flags: | |
4535 | Convert NIOS2 specific section flags to bfd internal section flags. */ | |
0a1b45a2 | 4536 | static bool |
8c803a2d | 4537 | nios2_elf32_section_flags (const Elf_Internal_Shdr *hdr) |
36591ba1 SL |
4538 | { |
4539 | if (hdr->sh_flags & SHF_NIOS2_GPREL) | |
8c803a2d | 4540 | hdr->bfd_section->flags |= SEC_SMALL_DATA; |
36591ba1 | 4541 | |
0a1b45a2 | 4542 | return true; |
36591ba1 SL |
4543 | } |
4544 | ||
4545 | /* Implement elf_backend_fake_sections: | |
4546 | Set the correct type for an NIOS2 ELF section. We do this by the | |
4547 | section name, which is a hack, but ought to work. */ | |
0a1b45a2 | 4548 | static bool |
36591ba1 SL |
4549 | nios2_elf32_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, |
4550 | Elf_Internal_Shdr *hdr, asection *sec) | |
4551 | { | |
fd361982 | 4552 | const char *name = bfd_section_name (sec); |
36591ba1 SL |
4553 | |
4554 | if ((sec->flags & SEC_SMALL_DATA) | |
4555 | || strcmp (name, ".sdata") == 0 | |
4556 | || strcmp (name, ".sbss") == 0 | |
4557 | || strcmp (name, ".lit4") == 0 || strcmp (name, ".lit8") == 0) | |
4558 | hdr->sh_flags |= SHF_NIOS2_GPREL; | |
4559 | ||
0a1b45a2 | 4560 | return true; |
36591ba1 SL |
4561 | } |
4562 | ||
4563 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up | |
4564 | shortcuts to them in our hash table. */ | |
0a1b45a2 | 4565 | static bool |
36591ba1 SL |
4566 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
4567 | { | |
4568 | struct elf32_nios2_link_hash_table *htab; | |
82e91538 | 4569 | struct elf_link_hash_entry *h; |
36591ba1 SL |
4570 | |
4571 | htab = elf32_nios2_hash_table (info); | |
4572 | ||
4573 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
0a1b45a2 | 4574 | return false; |
36591ba1 SL |
4575 | |
4576 | /* In order for the two loads in .PLTresolve to share the same %hiadj, | |
4577 | _GLOBAL_OFFSET_TABLE_ must be aligned to a 16-byte boundary. */ | |
fd361982 | 4578 | if (!bfd_set_section_alignment (htab->root.sgotplt, 4)) |
0a1b45a2 | 4579 | return false; |
36591ba1 | 4580 | |
82e91538 SL |
4581 | /* The Nios II ABI specifies that GOT-relative relocations are relative |
4582 | to the linker-created symbol _gp_got, rather than using | |
4583 | _GLOBAL_OFFSET_TABLE_ directly. In particular, the latter always | |
4584 | points to the base of the GOT while _gp_got may include a bias. */ | |
4585 | h = _bfd_elf_define_linkage_sym (dynobj, info, htab->root.sgotplt, | |
4586 | "_gp_got"); | |
4ef97a1b | 4587 | htab->h_gp_got = h; |
82e91538 | 4588 | if (h == NULL) |
0a1b45a2 | 4589 | return false; |
82e91538 | 4590 | |
0a1b45a2 | 4591 | return true; |
36591ba1 SL |
4592 | } |
4593 | ||
4594 | /* Implement elf_backend_create_dynamic_sections: | |
4595 | Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and | |
4596 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | |
4597 | hash table. */ | |
0a1b45a2 | 4598 | static bool |
36591ba1 SL |
4599 | nios2_elf32_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
4600 | { | |
4601 | struct elf32_nios2_link_hash_table *htab; | |
4602 | ||
4603 | htab = elf32_nios2_hash_table (info); | |
4604 | if (!htab->root.sgot && !create_got_section (dynobj, info)) | |
0a1b45a2 | 4605 | return false; |
36591ba1 | 4606 | |
9d19e4fd | 4607 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
0a1b45a2 | 4608 | return false; |
36591ba1 SL |
4609 | |
4610 | /* In order for the two loads in a shared object .PLTresolve to share the | |
4611 | same %hiadj, the start of the PLT (as well as the GOT) must be aligned | |
4612 | to a 16-byte boundary. This is because the addresses for these loads | |
4613 | include the -(.plt+4) PIC correction. */ | |
fd361982 | 4614 | return bfd_set_section_alignment (htab->root.splt, 4); |
36591ba1 SL |
4615 | } |
4616 | ||
4617 | /* Implement elf_backend_copy_indirect_symbol: | |
4618 | Copy the extra info we tack onto an elf_link_hash_entry. */ | |
4619 | static void | |
4620 | nios2_elf32_copy_indirect_symbol (struct bfd_link_info *info, | |
4621 | struct elf_link_hash_entry *dir, | |
4622 | struct elf_link_hash_entry *ind) | |
4623 | { | |
4624 | struct elf32_nios2_link_hash_entry *edir, *eind; | |
4625 | ||
4626 | edir = (struct elf32_nios2_link_hash_entry *) dir; | |
4627 | eind = (struct elf32_nios2_link_hash_entry *) ind; | |
4628 | ||
36591ba1 SL |
4629 | if (ind->root.type == bfd_link_hash_indirect |
4630 | && dir->got.refcount <= 0) | |
4631 | { | |
4632 | edir->tls_type = eind->tls_type; | |
4633 | eind->tls_type = GOT_UNKNOWN; | |
4634 | } | |
4635 | ||
4636 | edir->got_types_used |= eind->got_types_used; | |
4637 | ||
4638 | _bfd_elf_link_hash_copy_indirect (info, dir, ind); | |
4639 | } | |
4640 | ||
965b1d80 SL |
4641 | /* Set the right machine number for a NIOS2 ELF file. */ |
4642 | ||
0a1b45a2 | 4643 | static bool |
965b1d80 SL |
4644 | nios2_elf32_object_p (bfd *abfd) |
4645 | { | |
4646 | unsigned long mach; | |
4647 | ||
4648 | mach = elf_elfheader (abfd)->e_flags; | |
4649 | ||
4650 | switch (mach) | |
4651 | { | |
4652 | default: | |
4653 | case EF_NIOS2_ARCH_R1: | |
4654 | bfd_default_set_arch_mach (abfd, bfd_arch_nios2, bfd_mach_nios2r1); | |
4655 | break; | |
4656 | case EF_NIOS2_ARCH_R2: | |
4657 | bfd_default_set_arch_mach (abfd, bfd_arch_nios2, bfd_mach_nios2r2); | |
4658 | break; | |
4659 | } | |
4660 | ||
0a1b45a2 | 4661 | return true; |
965b1d80 SL |
4662 | } |
4663 | ||
36591ba1 SL |
4664 | /* Implement elf_backend_check_relocs: |
4665 | Look through the relocs for a section during the first phase. */ | |
0a1b45a2 | 4666 | static bool |
36591ba1 SL |
4667 | nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, |
4668 | asection *sec, const Elf_Internal_Rela *relocs) | |
4669 | { | |
36591ba1 | 4670 | Elf_Internal_Shdr *symtab_hdr; |
9bc8e54b | 4671 | struct elf_link_hash_entry **sym_hashes; |
36591ba1 SL |
4672 | const Elf_Internal_Rela *rel; |
4673 | const Elf_Internal_Rela *rel_end; | |
4674 | struct elf32_nios2_link_hash_table *htab; | |
36591ba1 SL |
4675 | asection *sreloc = NULL; |
4676 | bfd_signed_vma *local_got_refcounts; | |
4677 | ||
0e1862bb | 4678 | if (bfd_link_relocatable (info)) |
0a1b45a2 | 4679 | return true; |
36591ba1 | 4680 | |
36591ba1 SL |
4681 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4682 | sym_hashes = elf_sym_hashes (abfd); | |
36591ba1 SL |
4683 | local_got_refcounts = elf_local_got_refcounts (abfd); |
4684 | ||
4685 | htab = elf32_nios2_hash_table (info); | |
36591ba1 SL |
4686 | |
4687 | rel_end = relocs + sec->reloc_count; | |
4688 | for (rel = relocs; rel < rel_end; rel++) | |
4689 | { | |
4690 | unsigned int r_type; | |
4691 | struct elf_link_hash_entry *h; | |
4692 | unsigned long r_symndx; | |
4693 | ||
4694 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4695 | if (r_symndx < symtab_hdr->sh_info) | |
4696 | h = NULL; | |
4697 | else | |
4698 | { | |
4699 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4700 | while (h->root.type == bfd_link_hash_indirect | |
4701 | || h->root.type == bfd_link_hash_warning) | |
4702 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4703 | } | |
4704 | ||
4705 | r_type = ELF32_R_TYPE (rel->r_info); | |
4706 | ||
4707 | switch (r_type) | |
4708 | { | |
4709 | case R_NIOS2_GOT16: | |
1c2de463 SL |
4710 | case R_NIOS2_GOT_LO: |
4711 | case R_NIOS2_GOT_HA: | |
36591ba1 | 4712 | case R_NIOS2_CALL16: |
1c2de463 SL |
4713 | case R_NIOS2_CALL_LO: |
4714 | case R_NIOS2_CALL_HA: | |
36591ba1 SL |
4715 | case R_NIOS2_TLS_GD16: |
4716 | case R_NIOS2_TLS_IE16: | |
4717 | /* This symbol requires a global offset table entry. */ | |
4718 | { | |
4719 | int tls_type, old_tls_type; | |
4720 | ||
4721 | switch (r_type) | |
4722 | { | |
4723 | default: | |
4724 | case R_NIOS2_GOT16: | |
1c2de463 SL |
4725 | case R_NIOS2_GOT_LO: |
4726 | case R_NIOS2_GOT_HA: | |
36591ba1 | 4727 | case R_NIOS2_CALL16: |
1c2de463 SL |
4728 | case R_NIOS2_CALL_LO: |
4729 | case R_NIOS2_CALL_HA: | |
36591ba1 SL |
4730 | tls_type = GOT_NORMAL; |
4731 | break; | |
4732 | case R_NIOS2_TLS_GD16: | |
4733 | tls_type = GOT_TLS_GD; | |
4734 | break; | |
4735 | case R_NIOS2_TLS_IE16: | |
4736 | tls_type = GOT_TLS_IE; | |
4737 | break; | |
4738 | } | |
4739 | ||
36591ba1 SL |
4740 | if (h != NULL) |
4741 | { | |
4742 | struct elf32_nios2_link_hash_entry *eh | |
4743 | = (struct elf32_nios2_link_hash_entry *)h; | |
4744 | h->got.refcount++; | |
4745 | old_tls_type = elf32_nios2_hash_entry(h)->tls_type; | |
1c2de463 SL |
4746 | if (r_type == R_NIOS2_CALL16 |
4747 | || r_type == R_NIOS2_CALL_LO | |
4748 | || r_type == R_NIOS2_CALL_HA) | |
36591ba1 SL |
4749 | { |
4750 | /* Make sure a plt entry is created for this symbol if | |
4751 | it turns out to be a function defined by a dynamic | |
4752 | object. */ | |
4753 | h->plt.refcount++; | |
4754 | h->needs_plt = 1; | |
4755 | h->type = STT_FUNC; | |
1c2de463 | 4756 | eh->got_types_used |= CALL_USED; |
36591ba1 SL |
4757 | } |
4758 | else | |
1c2de463 | 4759 | eh->got_types_used |= GOT_USED; |
36591ba1 SL |
4760 | } |
4761 | else | |
4762 | { | |
4763 | /* This is a global offset table entry for a local symbol. */ | |
4764 | if (local_got_refcounts == NULL) | |
4765 | { | |
4766 | bfd_size_type size; | |
4767 | ||
4768 | size = symtab_hdr->sh_info; | |
4769 | size *= (sizeof (bfd_signed_vma) + sizeof (char)); | |
4770 | local_got_refcounts | |
4771 | = ((bfd_signed_vma *) bfd_zalloc (abfd, size)); | |
4772 | if (local_got_refcounts == NULL) | |
0a1b45a2 | 4773 | return false; |
36591ba1 SL |
4774 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
4775 | elf32_nios2_local_got_tls_type (abfd) | |
4776 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
4777 | } | |
4778 | local_got_refcounts[r_symndx]++; | |
4779 | old_tls_type = elf32_nios2_local_got_tls_type (abfd) [r_symndx]; | |
4780 | } | |
4781 | ||
4782 | /* We will already have issued an error message if there is a | |
4783 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
4784 | support any linker relaxations. So just combine any TLS | |
4785 | types needed. */ | |
4786 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
4787 | && tls_type != GOT_NORMAL) | |
4788 | tls_type |= old_tls_type; | |
4789 | ||
4790 | if (old_tls_type != tls_type) | |
4791 | { | |
4792 | if (h != NULL) | |
4793 | elf32_nios2_hash_entry (h)->tls_type = tls_type; | |
4794 | else | |
4795 | elf32_nios2_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
4796 | } | |
4797 | } | |
4ef97a1b | 4798 | make_got: |
36591ba1 SL |
4799 | if (htab->root.sgot == NULL) |
4800 | { | |
4801 | if (htab->root.dynobj == NULL) | |
4802 | htab->root.dynobj = abfd; | |
4803 | if (!create_got_section (htab->root.dynobj, info)) | |
0a1b45a2 | 4804 | return false; |
36591ba1 SL |
4805 | } |
4806 | break; | |
4807 | ||
4ef97a1b AM |
4808 | case R_NIOS2_TLS_LDM16: |
4809 | htab->tls_ldm_got.refcount++; | |
4810 | goto make_got; | |
4811 | ||
36591ba1 SL |
4812 | /* This relocation describes the C++ object vtable hierarchy. |
4813 | Reconstruct it for later use during GC. */ | |
4814 | case R_NIOS2_GNU_VTINHERIT: | |
4815 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
0a1b45a2 | 4816 | return false; |
36591ba1 SL |
4817 | break; |
4818 | ||
4819 | /* This relocation describes which C++ vtable entries are actually | |
4820 | used. Record for later use during GC. */ | |
4821 | case R_NIOS2_GNU_VTENTRY: | |
4822 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
0a1b45a2 | 4823 | return false; |
36591ba1 SL |
4824 | break; |
4825 | ||
4826 | case R_NIOS2_BFD_RELOC_32: | |
4827 | case R_NIOS2_CALL26: | |
78058a5e | 4828 | case R_NIOS2_CALL26_NOAT: |
36591ba1 SL |
4829 | case R_NIOS2_HIADJ16: |
4830 | case R_NIOS2_LO16: | |
4831 | ||
4832 | if (h != NULL) | |
4833 | { | |
4834 | /* If this reloc is in a read-only section, we might | |
4835 | need a copy reloc. We can't check reliably at this | |
4836 | stage whether the section is read-only, as input | |
4837 | sections have not yet been mapped to output sections. | |
4838 | Tentatively set the flag for now, and correct in | |
4839 | adjust_dynamic_symbol. */ | |
0e1862bb | 4840 | if (!bfd_link_pic (info)) |
36591ba1 SL |
4841 | h->non_got_ref = 1; |
4842 | ||
4843 | /* Make sure a plt entry is created for this symbol if it | |
4844 | turns out to be a function defined by a dynamic object. */ | |
4845 | h->plt.refcount++; | |
4846 | ||
78058a5e | 4847 | if (r_type == R_NIOS2_CALL26 || r_type == R_NIOS2_CALL26_NOAT) |
36591ba1 SL |
4848 | h->needs_plt = 1; |
4849 | } | |
4850 | ||
4851 | /* If we are creating a shared library, we need to copy the | |
4852 | reloc into the shared library. */ | |
0e1862bb | 4853 | if (bfd_link_pic (info) |
36591ba1 SL |
4854 | && (sec->flags & SEC_ALLOC) != 0 |
4855 | && (r_type == R_NIOS2_BFD_RELOC_32 | |
4856 | || (h != NULL && ! h->needs_plt | |
a496fbc8 | 4857 | && (! SYMBOLIC_BIND (info, h) || ! h->def_regular)))) |
36591ba1 | 4858 | { |
3bf083ed AM |
4859 | struct elf_dyn_relocs *p; |
4860 | struct elf_dyn_relocs **head; | |
36591ba1 SL |
4861 | |
4862 | /* When creating a shared object, we must copy these | |
4863 | reloc types into the output file. We create a reloc | |
4864 | section in dynobj and make room for this reloc. */ | |
4865 | if (sreloc == NULL) | |
4866 | { | |
4ef97a1b AM |
4867 | if (htab->root.dynobj == NULL) |
4868 | htab->root.dynobj = abfd; | |
4869 | ||
36591ba1 | 4870 | sreloc = _bfd_elf_make_dynamic_reloc_section |
0a1b45a2 | 4871 | (sec, htab->root.dynobj, 2, abfd, true); |
36591ba1 | 4872 | if (sreloc == NULL) |
0a1b45a2 | 4873 | return false; |
36591ba1 SL |
4874 | } |
4875 | ||
4876 | /* If this is a global symbol, we count the number of | |
4877 | relocations we need for this symbol. */ | |
4878 | if (h != NULL) | |
190eb1dd | 4879 | head = &h->dyn_relocs; |
36591ba1 SL |
4880 | else |
4881 | { | |
4882 | /* Track dynamic relocs needed for local syms too. | |
4883 | We really need local syms available to do this | |
4884 | easily. Oh well. */ | |
4885 | ||
4886 | asection *s; | |
4887 | void *vpp; | |
4888 | Elf_Internal_Sym *isym; | |
4889 | ||
f1dfbfdb | 4890 | isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, |
36591ba1 SL |
4891 | abfd, r_symndx); |
4892 | if (isym == NULL) | |
0a1b45a2 | 4893 | return false; |
36591ba1 SL |
4894 | |
4895 | s = bfd_section_from_elf_index (abfd, isym->st_shndx); | |
4896 | if (s == NULL) | |
4897 | s = sec; | |
4898 | ||
4899 | vpp = &elf_section_data (s)->local_dynrel; | |
3bf083ed | 4900 | head = (struct elf_dyn_relocs **) vpp; |
36591ba1 SL |
4901 | } |
4902 | ||
4903 | p = *head; | |
4904 | if (p == NULL || p->sec != sec) | |
4905 | { | |
986f0783 | 4906 | size_t amt = sizeof *p; |
3bf083ed | 4907 | p = ((struct elf_dyn_relocs *) |
36591ba1 SL |
4908 | bfd_alloc (htab->root.dynobj, amt)); |
4909 | if (p == NULL) | |
0a1b45a2 | 4910 | return false; |
36591ba1 SL |
4911 | p->next = *head; |
4912 | *head = p; | |
4913 | p->sec = sec; | |
4914 | p->count = 0; | |
4915 | p->pc_count = 0; | |
4916 | } | |
4917 | ||
4918 | p->count += 1; | |
4919 | ||
4920 | } | |
4921 | break; | |
4922 | } | |
4923 | } | |
4924 | ||
0a1b45a2 | 4925 | return true; |
36591ba1 SL |
4926 | } |
4927 | ||
4928 | ||
4929 | /* Implement elf_backend_gc_mark_hook: | |
4930 | Return the section that should be marked against GC for a given | |
4931 | relocation. */ | |
4932 | static asection * | |
4933 | nios2_elf32_gc_mark_hook (asection *sec, | |
25153ba0 | 4934 | struct bfd_link_info *info, |
36591ba1 SL |
4935 | Elf_Internal_Rela *rel, |
4936 | struct elf_link_hash_entry *h, | |
4937 | Elf_Internal_Sym *sym) | |
4938 | { | |
4939 | if (h != NULL) | |
4940 | switch (ELF32_R_TYPE (rel->r_info)) | |
4941 | { | |
4942 | case R_NIOS2_GNU_VTINHERIT: | |
4943 | case R_NIOS2_GNU_VTENTRY: | |
4944 | return NULL; | |
4945 | } | |
4946 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); | |
4947 | } | |
4948 | ||
36591ba1 SL |
4949 | /* Implement elf_backend_finish_dynamic_symbols: |
4950 | Finish up dynamic symbol handling. We set the contents of various | |
4951 | dynamic sections here. */ | |
0a1b45a2 | 4952 | static bool |
36591ba1 SL |
4953 | nios2_elf32_finish_dynamic_symbol (bfd *output_bfd, |
4954 | struct bfd_link_info *info, | |
4955 | struct elf_link_hash_entry *h, | |
4956 | Elf_Internal_Sym *sym) | |
4957 | { | |
4958 | struct elf32_nios2_link_hash_table *htab; | |
4959 | struct elf32_nios2_link_hash_entry *eh | |
4960 | = (struct elf32_nios2_link_hash_entry *)h; | |
4961 | int use_plt; | |
4962 | ||
4963 | htab = elf32_nios2_hash_table (info); | |
4964 | ||
4965 | if (h->plt.offset != (bfd_vma) -1) | |
4966 | { | |
4967 | asection *splt; | |
4968 | asection *sgotplt; | |
4969 | asection *srela; | |
4970 | bfd_vma plt_index; | |
4971 | bfd_vma got_offset; | |
4972 | Elf_Internal_Rela rela; | |
4973 | bfd_byte *loc; | |
4974 | bfd_vma got_address; | |
4975 | ||
4976 | /* This symbol has an entry in the procedure linkage table. Set | |
4977 | it up. */ | |
4978 | BFD_ASSERT (h->dynindx != -1); | |
4979 | splt = htab->root.splt; | |
4980 | sgotplt = htab->root.sgotplt; | |
4981 | srela = htab->root.srelplt; | |
4982 | BFD_ASSERT (splt != NULL && sgotplt != NULL && srela != NULL); | |
4983 | ||
4984 | /* Emit the PLT entry. */ | |
0e1862bb | 4985 | if (bfd_link_pic (info)) |
36591ba1 | 4986 | { |
900c0f0a AM |
4987 | bfd_vma br_offset; |
4988 | ||
36591ba1 SL |
4989 | nios2_elf32_install_data (splt, nios2_so_plt_entry, h->plt.offset, |
4990 | 3); | |
4991 | plt_index = (h->plt.offset - 24) / 12; | |
4992 | got_offset = (plt_index + 3) * 4; | |
4993 | nios2_elf32_install_imm16 (splt, h->plt.offset, | |
900c0f0a | 4994 | hiadj (plt_index * 4)); |
36591ba1 | 4995 | nios2_elf32_install_imm16 (splt, h->plt.offset + 4, |
900c0f0a AM |
4996 | plt_index * 4); |
4997 | br_offset = -(h->plt.offset + 12); | |
4998 | /* If this plt entry is too far away from the start of .plt | |
4999 | for the "br" to reach .PLTresolve, bounce through one or | |
5000 | more of the previous "br" instructions. */ | |
5001 | if (br_offset < (bfd_vma) -32768) | |
5002 | { | |
5003 | br_offset += 32768 / 12 * 12 - 4; | |
5004 | while (br_offset < (bfd_vma) -32768) | |
5005 | br_offset += 32768 / 12 * 12; | |
5006 | } | |
5007 | nios2_elf32_install_imm16 (splt, h->plt.offset + 8, br_offset); | |
5008 | ||
36591ba1 SL |
5009 | got_address = (sgotplt->output_section->vma + sgotplt->output_offset |
5010 | + got_offset); | |
5011 | ||
5012 | /* Fill in the entry in the global offset table. There are no | |
5013 | res_n slots for a shared object PLT, instead the .got.plt entries | |
5014 | point to the PLT entries. */ | |
5015 | bfd_put_32 (output_bfd, | |
5016 | splt->output_section->vma + splt->output_offset | |
5017 | + h->plt.offset, sgotplt->contents + got_offset); | |
5018 | } | |
5019 | else | |
5020 | { | |
5021 | plt_index = (h->plt.offset - 28 - htab->res_n_size) / 12; | |
5022 | got_offset = (plt_index + 3) * 4; | |
5023 | ||
5024 | nios2_elf32_install_data (splt, nios2_plt_entry, h->plt.offset, 3); | |
5025 | got_address = (sgotplt->output_section->vma + sgotplt->output_offset | |
5026 | + got_offset); | |
900c0f0a AM |
5027 | nios2_elf32_install_imm16 (splt, h->plt.offset, hiadj (got_address)); |
5028 | nios2_elf32_install_imm16 (splt, h->plt.offset + 4, got_address); | |
36591ba1 SL |
5029 | |
5030 | /* Fill in the entry in the global offset table. */ | |
5031 | bfd_put_32 (output_bfd, | |
5032 | splt->output_section->vma + splt->output_offset | |
5033 | + plt_index * 4, sgotplt->contents + got_offset); | |
5034 | } | |
5035 | ||
5036 | /* Fill in the entry in the .rela.plt section. */ | |
5037 | rela.r_offset = got_address; | |
5038 | rela.r_info = ELF32_R_INFO (h->dynindx, R_NIOS2_JUMP_SLOT); | |
5039 | rela.r_addend = 0; | |
5040 | loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); | |
5041 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
5042 | ||
5043 | if (!h->def_regular) | |
5044 | { | |
5045 | /* Mark the symbol as undefined, rather than as defined in | |
5046 | the .plt section. Leave the value alone. */ | |
5047 | sym->st_shndx = SHN_UNDEF; | |
5048 | /* If the symbol is weak, we do need to clear the value. | |
5049 | Otherwise, the PLT entry would provide a definition for | |
5050 | the symbol even if the symbol wasn't defined anywhere, | |
5051 | and so the symbol would never be NULL. */ | |
5052 | if (!h->ref_regular_nonweak) | |
5053 | sym->st_value = 0; | |
5054 | } | |
5055 | } | |
5056 | ||
1c2de463 | 5057 | use_plt = (eh->got_types_used == CALL_USED |
36591ba1 SL |
5058 | && h->plt.offset != (bfd_vma) -1); |
5059 | ||
5060 | if (!use_plt && h->got.offset != (bfd_vma) -1 | |
5061 | && (elf32_nios2_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
5062 | && (elf32_nios2_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
5063 | { | |
5064 | asection *sgot; | |
5065 | asection *srela; | |
5066 | Elf_Internal_Rela rela; | |
5067 | bfd_byte *loc; | |
5068 | bfd_vma offset; | |
5069 | ||
5070 | /* This symbol has an entry in the global offset table. Set it | |
5071 | up. */ | |
5072 | sgot = htab->root.sgot; | |
5073 | srela = htab->root.srelgot; | |
5074 | BFD_ASSERT (sgot != NULL && srela != NULL); | |
5075 | ||
5076 | offset = (h->got.offset & ~(bfd_vma) 1); | |
5077 | rela.r_offset = (sgot->output_section->vma | |
5078 | + sgot->output_offset + offset); | |
5079 | ||
5080 | /* If this is a -Bsymbolic link, and the symbol is defined | |
5081 | locally, we just want to emit a RELATIVE reloc. Likewise if | |
5082 | the symbol was forced to be local because of a version file. | |
5083 | The entry in the global offset table will already have been | |
5084 | initialized in the relocate_section function. */ | |
5085 | ||
0e1862bb | 5086 | if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) |
36591ba1 SL |
5087 | { |
5088 | rela.r_info = ELF32_R_INFO (0, R_NIOS2_RELATIVE); | |
5089 | rela.r_addend = bfd_get_signed_32 (output_bfd, | |
5090 | (sgot->contents + offset)); | |
5091 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset); | |
5092 | } | |
5093 | else | |
5094 | { | |
5095 | bfd_put_32 (output_bfd, (bfd_vma) 0, | |
5096 | sgot->contents + offset); | |
5097 | rela.r_info = ELF32_R_INFO (h->dynindx, R_NIOS2_GLOB_DAT); | |
5098 | rela.r_addend = 0; | |
5099 | } | |
5100 | ||
5101 | loc = srela->contents; | |
5102 | loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); | |
5103 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
5104 | } | |
5105 | ||
5106 | if (use_plt && h->got.offset != (bfd_vma) -1) | |
5107 | { | |
5108 | bfd_vma offset = (h->got.offset & ~(bfd_vma) 1); | |
5109 | asection *sgot = htab->root.sgot; | |
5110 | asection *splt = htab->root.splt; | |
5111 | bfd_put_32 (output_bfd, (splt->output_section->vma + splt->output_offset | |
5112 | + h->plt.offset), | |
5113 | sgot->contents + offset); | |
5114 | } | |
5115 | ||
5116 | if (h->needs_copy) | |
5117 | { | |
5118 | asection *s; | |
5119 | Elf_Internal_Rela rela; | |
5120 | bfd_byte *loc; | |
5121 | ||
5122 | /* This symbol needs a copy reloc. Set it up. */ | |
5123 | BFD_ASSERT (h->dynindx != -1 | |
5124 | && (h->root.type == bfd_link_hash_defined | |
5125 | || h->root.type == bfd_link_hash_defweak)); | |
5126 | ||
36591ba1 SL |
5127 | rela.r_offset = (h->root.u.def.value |
5128 | + h->root.u.def.section->output_section->vma | |
5129 | + h->root.u.def.section->output_offset); | |
5130 | rela.r_info = ELF32_R_INFO (h->dynindx, R_NIOS2_COPY); | |
5131 | rela.r_addend = 0; | |
afbf7e8e | 5132 | if (h->root.u.def.section == htab->root.sdynrelro) |
5474d94f AM |
5133 | s = htab->root.sreldynrelro; |
5134 | else | |
5135 | s = htab->root.srelbss; | |
5136 | BFD_ASSERT (s != NULL); | |
36591ba1 SL |
5137 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
5138 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
5139 | } | |
5140 | ||
82e91538 | 5141 | /* Mark _DYNAMIC, _GLOBAL_OFFSET_TABLE_, and _gp_got as absolute. */ |
36591ba1 | 5142 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
4ef97a1b AM |
5143 | || h == htab->root.hgot |
5144 | || h == htab->h_gp_got) | |
36591ba1 SL |
5145 | sym->st_shndx = SHN_ABS; |
5146 | ||
0a1b45a2 | 5147 | return true; |
36591ba1 SL |
5148 | } |
5149 | ||
5150 | /* Implement elf_backend_finish_dynamic_sections. */ | |
0a1b45a2 | 5151 | static bool |
36591ba1 SL |
5152 | nios2_elf32_finish_dynamic_sections (bfd *output_bfd, |
5153 | struct bfd_link_info *info) | |
5154 | { | |
36591ba1 SL |
5155 | asection *sgotplt; |
5156 | asection *sdyn; | |
5157 | struct elf32_nios2_link_hash_table *htab; | |
5158 | ||
5159 | htab = elf32_nios2_hash_table (info); | |
36591ba1 | 5160 | sgotplt = htab->root.sgotplt; |
4ef97a1b | 5161 | sdyn = NULL; |
36591ba1 | 5162 | |
4ef97a1b | 5163 | if (htab->root.dynamic_sections_created) |
36591ba1 SL |
5164 | { |
5165 | asection *splt; | |
5166 | Elf32_External_Dyn *dyncon, *dynconend; | |
5167 | ||
5168 | splt = htab->root.splt; | |
4ef97a1b AM |
5169 | sdyn = bfd_get_linker_section (htab->root.dynobj, ".dynamic"); |
5170 | BFD_ASSERT (splt != NULL && sdyn != NULL && sgotplt != NULL); | |
36591ba1 SL |
5171 | |
5172 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
5173 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | |
5174 | for (; dyncon < dynconend; dyncon++) | |
5175 | { | |
5176 | Elf_Internal_Dyn dyn; | |
5177 | asection *s; | |
5178 | ||
4ef97a1b | 5179 | bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn); |
36591ba1 SL |
5180 | |
5181 | switch (dyn.d_tag) | |
5182 | { | |
5183 | default: | |
5184 | break; | |
5185 | ||
5186 | case DT_PLTGOT: | |
4ade44b7 AM |
5187 | s = htab->root.sgotplt; |
5188 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
36591ba1 SL |
5189 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5190 | break; | |
5191 | ||
5192 | case DT_JMPREL: | |
5193 | s = htab->root.srelplt; | |
4ade44b7 | 5194 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
36591ba1 SL |
5195 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5196 | break; | |
5197 | ||
5198 | case DT_PLTRELSZ: | |
5199 | s = htab->root.srelplt; | |
36591ba1 SL |
5200 | dyn.d_un.d_val = s->size; |
5201 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5202 | break; | |
5203 | ||
36591ba1 | 5204 | case DT_NIOS2_GP: |
4ade44b7 AM |
5205 | s = htab->root.sgotplt; |
5206 | dyn.d_un.d_ptr | |
5207 | = s->output_section->vma + s->output_offset + 0x7ff0; | |
36591ba1 SL |
5208 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
5209 | break; | |
5210 | } | |
5211 | } | |
5212 | ||
5213 | /* Fill in the first entry in the procedure linkage table. */ | |
5214 | if (splt->size > 0) | |
5215 | { | |
5216 | bfd_vma got_address = (sgotplt->output_section->vma | |
5217 | + sgotplt->output_offset); | |
0e1862bb | 5218 | if (bfd_link_pic (info)) |
36591ba1 | 5219 | { |
33d4099f SL |
5220 | bfd_vma got_pcrel = got_address - (splt->output_section->vma |
5221 | + splt->output_offset); | |
5222 | /* Both GOT and PLT must be aligned to a 16-byte boundary | |
5223 | for the two loads to share the %hiadj part. The 4-byte | |
5224 | offset for nextpc is accounted for in the %lo offsets | |
5225 | on the loads. */ | |
5226 | BFD_ASSERT ((got_pcrel & 0xf) == 0); | |
36591ba1 | 5227 | nios2_elf32_install_data (splt, nios2_so_plt0_entry, 0, 6); |
33d4099f | 5228 | nios2_elf32_install_imm16 (splt, 4, hiadj (got_pcrel)); |
900c0f0a AM |
5229 | nios2_elf32_install_imm16 (splt, 12, got_pcrel); |
5230 | nios2_elf32_install_imm16 (splt, 16, got_pcrel + 4); | |
36591ba1 SL |
5231 | } |
5232 | else | |
5233 | { | |
5234 | /* Divide by 4 here, not 3 because we already corrected for the | |
5235 | res_N branches. */ | |
5236 | bfd_vma res_size = (splt->size - 28) / 4; | |
5237 | bfd_vma res_start = (splt->output_section->vma | |
5238 | + splt->output_offset); | |
5239 | bfd_vma res_offset; | |
5240 | ||
5241 | for (res_offset = 0; res_offset < res_size; res_offset += 4) | |
5242 | bfd_put_32 (output_bfd, | |
5243 | 6 | ((res_size - (res_offset + 4)) << 6), | |
5244 | splt->contents + res_offset); | |
5245 | ||
33d4099f SL |
5246 | /* The GOT must be aligned to a 16-byte boundary for the |
5247 | two loads to share the same %hiadj part. */ | |
5248 | BFD_ASSERT ((got_address & 0xf) == 0); | |
5249 | ||
36591ba1 SL |
5250 | nios2_elf32_install_data (splt, nios2_plt0_entry, res_size, 7); |
5251 | nios2_elf32_install_imm16 (splt, res_size, hiadj (res_start)); | |
900c0f0a | 5252 | nios2_elf32_install_imm16 (splt, res_size + 4, res_start); |
36591ba1 SL |
5253 | nios2_elf32_install_imm16 (splt, res_size + 12, |
5254 | hiadj (got_address)); | |
5255 | nios2_elf32_install_imm16 (splt, res_size + 16, | |
900c0f0a | 5256 | got_address + 4); |
36591ba1 | 5257 | nios2_elf32_install_imm16 (splt, res_size + 20, |
900c0f0a | 5258 | got_address + 8); |
36591ba1 SL |
5259 | } |
5260 | } | |
5261 | } | |
4ef97a1b | 5262 | |
36591ba1 | 5263 | /* Fill in the first three entries in the global offset table. */ |
4ef97a1b | 5264 | if (sgotplt != NULL && sgotplt->size > 0) |
36591ba1 SL |
5265 | { |
5266 | if (sdyn == NULL) | |
5267 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents); | |
5268 | else | |
5269 | bfd_put_32 (output_bfd, | |
5270 | sdyn->output_section->vma + sdyn->output_offset, | |
5271 | sgotplt->contents); | |
5272 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 4); | |
5273 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 8); | |
36591ba1 | 5274 | |
4ef97a1b AM |
5275 | if (sgotplt->output_section != bfd_abs_section_ptr) |
5276 | elf_section_data (sgotplt->output_section)->this_hdr.sh_entsize = 4; | |
5277 | } | |
36591ba1 | 5278 | |
0a1b45a2 | 5279 | return true; |
36591ba1 SL |
5280 | } |
5281 | ||
5282 | /* Implement elf_backend_adjust_dynamic_symbol: | |
5283 | Adjust a symbol defined by a dynamic object and referenced by a | |
5284 | regular object. The current definition is in some section of the | |
5285 | dynamic object, but we're not including those sections. We have to | |
5286 | change the definition to something the rest of the link can | |
5287 | understand. */ | |
0a1b45a2 | 5288 | static bool |
36591ba1 SL |
5289 | nios2_elf32_adjust_dynamic_symbol (struct bfd_link_info *info, |
5290 | struct elf_link_hash_entry *h) | |
5291 | { | |
5292 | struct elf32_nios2_link_hash_table *htab; | |
5293 | bfd *dynobj; | |
5474d94f | 5294 | asection *s, *srel; |
36591ba1 SL |
5295 | unsigned align2; |
5296 | ||
5297 | htab = elf32_nios2_hash_table (info); | |
4ef97a1b | 5298 | dynobj = htab->root.dynobj; |
36591ba1 SL |
5299 | |
5300 | /* Make sure we know what is going on here. */ | |
5301 | BFD_ASSERT (dynobj != NULL | |
5302 | && (h->needs_plt | |
60d67dc8 | 5303 | || h->is_weakalias |
36591ba1 SL |
5304 | || (h->def_dynamic |
5305 | && h->ref_regular | |
5306 | && !h->def_regular))); | |
5307 | ||
5308 | /* If this is a function, put it in the procedure linkage table. We | |
5309 | will fill in the contents of the procedure linkage table later, | |
5310 | when we know the address of the .got section. */ | |
5311 | if (h->type == STT_FUNC || h->needs_plt) | |
5312 | { | |
5313 | if (h->plt.refcount <= 0 | |
5314 | || SYMBOL_CALLS_LOCAL (info, h) | |
5315 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5316 | && h->root.type == bfd_link_hash_undefweak)) | |
5317 | { | |
5318 | /* This case can occur if we saw a PLT reloc in an input | |
5319 | file, but the symbol was never referred to by a dynamic | |
5320 | object, or if all references were garbage collected. In | |
5321 | such a case, we don't actually need to build a procedure | |
5322 | linkage table, and we can just do a PCREL reloc instead. */ | |
5323 | h->plt.offset = (bfd_vma) -1; | |
5324 | h->needs_plt = 0; | |
5325 | } | |
5326 | ||
0a1b45a2 | 5327 | return true; |
36591ba1 SL |
5328 | } |
5329 | ||
5330 | /* Reinitialize the plt offset now that it is not used as a reference | |
5331 | count any more. */ | |
5332 | h->plt.offset = (bfd_vma) -1; | |
5333 | ||
5334 | /* If this is a weak symbol, and there is a real definition, the | |
5335 | processor independent code will have arranged for us to see the | |
5336 | real definition first, and we can just use the same value. */ | |
60d67dc8 | 5337 | if (h->is_weakalias) |
36591ba1 | 5338 | { |
60d67dc8 AM |
5339 | struct elf_link_hash_entry *def = weakdef (h); |
5340 | BFD_ASSERT (def->root.type == bfd_link_hash_defined); | |
5341 | h->root.u.def.section = def->root.u.def.section; | |
5342 | h->root.u.def.value = def->root.u.def.value; | |
0a1b45a2 | 5343 | return true; |
36591ba1 SL |
5344 | } |
5345 | ||
5346 | /* If there are no non-GOT references, we do not need a copy | |
5347 | relocation. */ | |
5348 | if (!h->non_got_ref) | |
0a1b45a2 | 5349 | return true; |
36591ba1 SL |
5350 | |
5351 | /* This is a reference to a symbol defined by a dynamic object which | |
5352 | is not a function. | |
5353 | If we are creating a shared library, we must presume that the | |
5354 | only references to the symbol are via the global offset table. | |
5355 | For such cases we need not do anything here; the relocations will | |
5356 | be handled correctly by relocate_section. */ | |
0e1862bb | 5357 | if (bfd_link_pic (info)) |
0a1b45a2 | 5358 | return true; |
36591ba1 SL |
5359 | |
5360 | if (h->size == 0) | |
5361 | { | |
4eca0228 AM |
5362 | _bfd_error_handler (_("dynamic variable `%s' is zero size"), |
5363 | h->root.root.string); | |
0a1b45a2 | 5364 | return true; |
36591ba1 SL |
5365 | } |
5366 | ||
5367 | /* We must allocate the symbol in our .dynbss section, which will | |
5368 | become part of the .bss section of the executable. There will be | |
5369 | an entry for this symbol in the .dynsym section. The dynamic | |
5370 | object will contain position independent code, so all references | |
5371 | from the dynamic object to this symbol will go through the global | |
5372 | offset table. The dynamic linker will use the .dynsym entry to | |
5373 | determine the address it must put in the global offset table, so | |
5374 | both the dynamic object and the regular object will refer to the | |
5375 | same memory location for the variable. */ | |
36591ba1 SL |
5376 | /* We must generate a R_NIOS2_COPY reloc to tell the dynamic linker to |
5377 | copy the initial value out of the dynamic object and into the | |
5378 | runtime process image. We need to remember the offset into the | |
5379 | .rela.bss section we are going to use. */ | |
5474d94f | 5380 | if ((h->root.u.def.section->flags & SEC_READONLY) != 0) |
36591ba1 | 5381 | { |
5474d94f AM |
5382 | s = htab->root.sdynrelro; |
5383 | srel = htab->root.sreldynrelro; | |
5384 | } | |
5385 | else | |
5386 | { | |
5387 | s = htab->root.sdynbss; | |
9d19e4fd | 5388 | srel = htab->root.srelbss; |
5474d94f AM |
5389 | } |
5390 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
5391 | { | |
36591ba1 SL |
5392 | srel->size += sizeof (Elf32_External_Rela); |
5393 | h->needs_copy = 1; | |
5394 | } | |
5395 | ||
5396 | align2 = bfd_log2 (h->size); | |
5397 | if (align2 > h->root.u.def.section->alignment_power) | |
5398 | align2 = h->root.u.def.section->alignment_power; | |
5399 | ||
5400 | /* Align dynbss. */ | |
5401 | s->size = BFD_ALIGN (s->size, (bfd_size_type)1 << align2); | |
fd361982 AM |
5402 | if (align2 > bfd_section_alignment (s) |
5403 | && !bfd_set_section_alignment (s, align2)) | |
0a1b45a2 | 5404 | return false; |
36591ba1 SL |
5405 | |
5406 | /* Define the symbol as being at this point in the section. */ | |
5407 | h->root.u.def.section = s; | |
5408 | h->root.u.def.value = s->size; | |
5409 | ||
5410 | /* Increment the section size to make room for the symbol. */ | |
5411 | s->size += h->size; | |
5412 | ||
0a1b45a2 | 5413 | return true; |
36591ba1 SL |
5414 | } |
5415 | ||
af969b14 | 5416 | /* Worker function for nios2_elf32_late_size_sections. */ |
0a1b45a2 | 5417 | static bool |
f3b9cfd1 | 5418 | adjust_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
36591ba1 SL |
5419 | { |
5420 | struct bfd_link_info *info; | |
5421 | struct elf32_nios2_link_hash_table *htab; | |
5422 | ||
5423 | if (h->root.type == bfd_link_hash_indirect) | |
0a1b45a2 | 5424 | return true; |
36591ba1 SL |
5425 | |
5426 | if (h->root.type == bfd_link_hash_warning) | |
5427 | /* When warning symbols are created, they **replace** the "real" | |
5428 | entry in the hash table, thus we never get to see the real | |
5429 | symbol in a hash traversal. So look at it now. */ | |
5430 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5431 | ||
5432 | info = (struct bfd_link_info *) inf; | |
5433 | htab = elf32_nios2_hash_table (info); | |
5434 | ||
5435 | if (h->plt.offset != (bfd_vma)-1) | |
5436 | h->plt.offset += htab->res_n_size; | |
5437 | if (htab->root.splt == h->root.u.def.section) | |
5438 | h->root.u.def.value += htab->res_n_size; | |
5439 | ||
0a1b45a2 | 5440 | return true; |
36591ba1 SL |
5441 | } |
5442 | ||
af969b14 | 5443 | /* Another worker function for nios2_elf32_late_size_sections. |
36591ba1 SL |
5444 | Allocate space in .plt, .got and associated reloc sections for |
5445 | dynamic relocs. */ | |
0a1b45a2 | 5446 | static bool |
f3b9cfd1 | 5447 | allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) |
36591ba1 SL |
5448 | { |
5449 | struct bfd_link_info *info; | |
5450 | struct elf32_nios2_link_hash_table *htab; | |
5451 | struct elf32_nios2_link_hash_entry *eh; | |
3bf083ed | 5452 | struct elf_dyn_relocs *p; |
36591ba1 SL |
5453 | int use_plt; |
5454 | ||
5455 | if (h->root.type == bfd_link_hash_indirect) | |
0a1b45a2 | 5456 | return true; |
36591ba1 SL |
5457 | |
5458 | if (h->root.type == bfd_link_hash_warning) | |
5459 | /* When warning symbols are created, they **replace** the "real" | |
5460 | entry in the hash table, thus we never get to see the real | |
5461 | symbol in a hash traversal. So look at it now. */ | |
5462 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5463 | ||
5464 | info = (struct bfd_link_info *) inf; | |
5465 | htab = elf32_nios2_hash_table (info); | |
5466 | ||
5467 | if (htab->root.dynamic_sections_created | |
5468 | && h->plt.refcount > 0) | |
5469 | { | |
5470 | /* Make sure this symbol is output as a dynamic symbol. | |
5471 | Undefined weak syms won't yet be marked as dynamic. */ | |
5472 | if (h->dynindx == -1 | |
5473 | && !h->forced_local | |
5474 | && !bfd_elf_link_record_dynamic_symbol (info, h)) | |
0a1b45a2 | 5475 | return false; |
36591ba1 | 5476 | |
0e1862bb | 5477 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)) |
36591ba1 SL |
5478 | { |
5479 | asection *s = htab->root.splt; | |
5480 | ||
5481 | /* Allocate room for the header. */ | |
5482 | if (s->size == 0) | |
5483 | { | |
0e1862bb | 5484 | if (bfd_link_pic (info)) |
36591ba1 SL |
5485 | s->size = 24; |
5486 | else | |
5487 | s->size = 28; | |
5488 | } | |
5489 | ||
5490 | h->plt.offset = s->size; | |
5491 | ||
5492 | /* If this symbol is not defined in a regular file, and we are | |
5493 | not generating a shared library, then set the symbol to this | |
5494 | location in the .plt. This is required to make function | |
5495 | pointers compare as equal between the normal executable and | |
5496 | the shared library. */ | |
0e1862bb | 5497 | if (! bfd_link_pic (info) |
36591ba1 SL |
5498 | && !h->def_regular) |
5499 | { | |
5500 | h->root.u.def.section = s; | |
5501 | h->root.u.def.value = h->plt.offset; | |
5502 | } | |
5503 | ||
5504 | /* Make room for this entry. */ | |
5505 | s->size += 12; | |
5506 | ||
5507 | /* We also need to make an entry in the .rela.plt section. */ | |
5508 | htab->root.srelplt->size += sizeof (Elf32_External_Rela); | |
5509 | ||
5510 | /* And the .got.plt section. */ | |
5511 | htab->root.sgotplt->size += 4; | |
5512 | } | |
5513 | else | |
5514 | { | |
5515 | h->plt.offset = (bfd_vma) -1; | |
5516 | h->needs_plt = 0; | |
5517 | } | |
5518 | } | |
5519 | else | |
5520 | { | |
5521 | h->plt.offset = (bfd_vma) -1; | |
5522 | h->needs_plt = 0; | |
5523 | } | |
5524 | ||
5525 | eh = (struct elf32_nios2_link_hash_entry *) h; | |
1c2de463 | 5526 | use_plt = (eh->got_types_used == CALL_USED |
36591ba1 SL |
5527 | && h->plt.offset != (bfd_vma) -1); |
5528 | ||
5529 | if (h->got.refcount > 0) | |
5530 | { | |
5531 | asection *s; | |
0a1b45a2 | 5532 | bool dyn; |
36591ba1 SL |
5533 | int tls_type = eh->tls_type; |
5534 | int indx; | |
5535 | ||
5536 | /* Make sure this symbol is output as a dynamic symbol. | |
5537 | Undefined weak syms won't yet be marked as dynamic. */ | |
5538 | if (h->dynindx == -1 | |
5539 | && !h->forced_local | |
5540 | && !bfd_elf_link_record_dynamic_symbol (info, h)) | |
0a1b45a2 | 5541 | return false; |
36591ba1 SL |
5542 | |
5543 | s = htab->root.sgot; | |
5544 | h->got.offset = s->size; | |
5545 | ||
5546 | if (tls_type == GOT_UNKNOWN) | |
5547 | abort (); | |
5548 | ||
5549 | if (tls_type == GOT_NORMAL) | |
5550 | /* Non-TLS symbols need one GOT slot. */ | |
5551 | s->size += 4; | |
5552 | else | |
5553 | { | |
5554 | if (tls_type & GOT_TLS_GD) | |
5555 | /* R_NIOS2_TLS_GD16 needs 2 consecutive GOT slots. */ | |
5556 | s->size += 8; | |
5557 | if (tls_type & GOT_TLS_IE) | |
5558 | /* R_NIOS2_TLS_IE16 needs one GOT slot. */ | |
5559 | s->size += 4; | |
5560 | } | |
5561 | ||
5562 | dyn = htab->root.dynamic_sections_created; | |
5563 | ||
5564 | indx = 0; | |
0e1862bb L |
5565 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) |
5566 | && (!bfd_link_pic (info) | |
36591ba1 SL |
5567 | || !SYMBOL_REFERENCES_LOCAL (info, h))) |
5568 | indx = h->dynindx; | |
5569 | ||
5570 | if (tls_type != GOT_NORMAL | |
0e1862bb | 5571 | && (bfd_link_pic (info) || indx != 0) |
36591ba1 SL |
5572 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
5573 | || h->root.type != bfd_link_hash_undefweak)) | |
5574 | { | |
5575 | if (tls_type & GOT_TLS_IE) | |
5576 | htab->root.srelgot->size += sizeof (Elf32_External_Rela); | |
5577 | ||
5578 | if (tls_type & GOT_TLS_GD) | |
5579 | htab->root.srelgot->size += sizeof (Elf32_External_Rela); | |
5580 | ||
5581 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
5582 | htab->root.srelgot->size += sizeof (Elf32_External_Rela); | |
5583 | } | |
5584 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5585 | || h->root.type != bfd_link_hash_undefweak) | |
5586 | && !use_plt | |
0e1862bb | 5587 | && (bfd_link_pic (info) |
36591ba1 SL |
5588 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
5589 | htab->root.srelgot->size += sizeof (Elf32_External_Rela); | |
5590 | } | |
5591 | else | |
5592 | h->got.offset = (bfd_vma) -1; | |
5593 | ||
190eb1dd | 5594 | if (h->dyn_relocs == NULL) |
0a1b45a2 | 5595 | return true; |
36591ba1 SL |
5596 | |
5597 | /* In the shared -Bsymbolic case, discard space allocated for | |
5598 | dynamic pc-relative relocs against symbols which turn out to be | |
5599 | defined in regular objects. For the normal shared case, discard | |
5600 | space for pc-relative relocs that have become local due to symbol | |
5601 | visibility changes. */ | |
5602 | ||
0e1862bb | 5603 | if (bfd_link_pic (info)) |
36591ba1 SL |
5604 | { |
5605 | if (h->def_regular | |
a496fbc8 | 5606 | && (h->forced_local || SYMBOLIC_BIND (info, h))) |
36591ba1 | 5607 | { |
3bf083ed | 5608 | struct elf_dyn_relocs **pp; |
36591ba1 | 5609 | |
190eb1dd | 5610 | for (pp = &h->dyn_relocs; (p = *pp) != NULL; ) |
36591ba1 SL |
5611 | { |
5612 | p->count -= p->pc_count; | |
5613 | p->pc_count = 0; | |
5614 | if (p->count == 0) | |
5615 | *pp = p->next; | |
5616 | else | |
5617 | pp = &p->next; | |
5618 | } | |
5619 | } | |
5620 | ||
5621 | /* Also discard relocs on undefined weak syms with non-default | |
5622 | visibility. */ | |
190eb1dd | 5623 | if (h->dyn_relocs != NULL |
36591ba1 SL |
5624 | && h->root.type == bfd_link_hash_undefweak) |
5625 | { | |
31a53da5 L |
5626 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
5627 | || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) | |
190eb1dd | 5628 | h->dyn_relocs = NULL; |
36591ba1 SL |
5629 | |
5630 | /* Make sure undefined weak symbols are output as a dynamic | |
5631 | symbol in PIEs. */ | |
5632 | else if (h->dynindx == -1 | |
5633 | && !h->forced_local | |
5634 | && !bfd_elf_link_record_dynamic_symbol (info, h)) | |
0a1b45a2 | 5635 | return false; |
36591ba1 SL |
5636 | } |
5637 | } | |
5638 | else | |
5639 | { | |
5640 | /* For the non-shared case, discard space for relocs against | |
5641 | symbols which turn out to need copy relocs or are not | |
5642 | dynamic. */ | |
5643 | ||
5644 | if (!h->non_got_ref | |
5645 | && ((h->def_dynamic && !h->def_regular) | |
5646 | || (htab->root.dynamic_sections_created | |
5647 | && (h->root.type == bfd_link_hash_undefweak | |
5648 | || h->root.type == bfd_link_hash_undefined)))) | |
5649 | { | |
5650 | /* Make sure this symbol is output as a dynamic symbol. | |
5651 | Undefined weak syms won't yet be marked as dynamic. */ | |
5652 | if (h->dynindx == -1 | |
5653 | && !h->forced_local | |
5654 | && !bfd_elf_link_record_dynamic_symbol (info, h)) | |
0a1b45a2 | 5655 | return false; |
36591ba1 SL |
5656 | |
5657 | /* If that succeeded, we know we'll be keeping all the | |
5658 | relocs. */ | |
5659 | if (h->dynindx != -1) | |
5660 | goto keep; | |
5661 | } | |
5662 | ||
190eb1dd | 5663 | h->dyn_relocs = NULL; |
36591ba1 SL |
5664 | |
5665 | keep: ; | |
5666 | } | |
5667 | ||
5668 | /* Finally, allocate space. */ | |
190eb1dd | 5669 | for (p = h->dyn_relocs; p != NULL; p = p->next) |
36591ba1 SL |
5670 | { |
5671 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
5672 | sreloc->size += p->count * sizeof (Elf32_External_Rela); | |
5673 | } | |
5674 | ||
0a1b45a2 | 5675 | return true; |
36591ba1 SL |
5676 | } |
5677 | ||
af969b14 | 5678 | /* Implement elf_backend_late_size_sections: |
36591ba1 | 5679 | Set the sizes of the dynamic sections. */ |
0a1b45a2 | 5680 | static bool |
af969b14 AM |
5681 | nios2_elf32_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
5682 | struct bfd_link_info *info) | |
36591ba1 SL |
5683 | { |
5684 | bfd *dynobj; | |
5685 | asection *s; | |
0a1b45a2 | 5686 | bool relocs; |
36591ba1 SL |
5687 | bfd *ibfd; |
5688 | struct elf32_nios2_link_hash_table *htab; | |
5689 | ||
5690 | htab = elf32_nios2_hash_table (info); | |
4ef97a1b | 5691 | dynobj = htab->root.dynobj; |
af969b14 AM |
5692 | if (dynobj == NULL) |
5693 | return true; | |
36591ba1 SL |
5694 | |
5695 | htab->res_n_size = 0; | |
4ef97a1b | 5696 | if (htab->root.dynamic_sections_created) |
36591ba1 SL |
5697 | { |
5698 | /* Set the contents of the .interp section to the interpreter. */ | |
9b8b325a | 5699 | if (bfd_link_executable (info) && !info->nointerp) |
36591ba1 SL |
5700 | { |
5701 | s = bfd_get_linker_section (dynobj, ".interp"); | |
5702 | BFD_ASSERT (s != NULL); | |
5703 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; | |
5704 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
5705 | } | |
5706 | } | |
5707 | else | |
5708 | { | |
5709 | /* We may have created entries in the .rela.got section. | |
5710 | However, if we are not creating the dynamic sections, we will | |
5711 | not actually use these entries. Reset the size of .rela.got, | |
5712 | which will cause it to get stripped from the output file | |
5713 | below. */ | |
5714 | s = htab->root.srelgot; | |
5715 | if (s != NULL) | |
5716 | s->size = 0; | |
5717 | } | |
5718 | ||
5719 | /* Set up .got offsets for local syms, and space for local dynamic | |
5720 | relocs. */ | |
c72f2fb2 | 5721 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
36591ba1 SL |
5722 | { |
5723 | bfd_signed_vma *local_got; | |
5724 | bfd_signed_vma *end_local_got; | |
5725 | char *local_tls_type; | |
5726 | bfd_size_type locsymcount; | |
5727 | Elf_Internal_Shdr *symtab_hdr; | |
5728 | asection *srel; | |
5729 | ||
5730 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5731 | continue; | |
5732 | ||
5733 | for (s = ibfd->sections; s != NULL; s = s->next) | |
5734 | { | |
3bf083ed | 5735 | struct elf_dyn_relocs *p; |
36591ba1 SL |
5736 | |
5737 | for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) | |
5738 | { | |
5739 | if (!bfd_is_abs_section (p->sec) | |
5740 | && bfd_is_abs_section (p->sec->output_section)) | |
5741 | { | |
5742 | /* Input section has been discarded, either because | |
5743 | it is a copy of a linkonce section or due to | |
5744 | linker script /DISCARD/, so we'll be discarding | |
5745 | the relocs too. */ | |
5746 | } | |
5747 | else if (p->count != 0) | |
5748 | { | |
5749 | srel = elf_section_data (p->sec)->sreloc; | |
5750 | srel->size += p->count * sizeof (Elf32_External_Rela); | |
36591ba1 SL |
5751 | } |
5752 | } | |
5753 | } | |
5754 | ||
5755 | local_got = elf_local_got_refcounts (ibfd); | |
5756 | if (!local_got) | |
5757 | continue; | |
5758 | ||
5759 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5760 | locsymcount = symtab_hdr->sh_info; | |
5761 | end_local_got = local_got + locsymcount; | |
5762 | local_tls_type = elf32_nios2_local_got_tls_type (ibfd); | |
5763 | s = htab->root.sgot; | |
5764 | srel = htab->root.srelgot; | |
5765 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
5766 | { | |
5767 | if (*local_got > 0) | |
5768 | { | |
5769 | *local_got = s->size; | |
5770 | if (*local_tls_type & GOT_TLS_GD) | |
5771 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
5772 | s->size += 8; | |
5773 | if (*local_tls_type & GOT_TLS_IE) | |
5774 | s->size += 4; | |
5775 | if (*local_tls_type == GOT_NORMAL) | |
5776 | s->size += 4; | |
5777 | ||
0e1862bb | 5778 | if (bfd_link_pic (info) || *local_tls_type == GOT_TLS_GD) |
36591ba1 SL |
5779 | srel->size += sizeof (Elf32_External_Rela); |
5780 | } | |
5781 | else | |
5782 | *local_got = (bfd_vma) -1; | |
5783 | } | |
5784 | } | |
5785 | ||
5786 | if (htab->tls_ldm_got.refcount > 0) | |
5787 | { | |
5788 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
5789 | for R_NIOS2_TLS_LDM16 relocations. */ | |
5790 | htab->tls_ldm_got.offset = htab->root.sgot->size; | |
5791 | htab->root.sgot->size += 8; | |
0e1862bb | 5792 | if (bfd_link_pic (info)) |
36591ba1 SL |
5793 | htab->root.srelgot->size += sizeof (Elf32_External_Rela); |
5794 | } | |
5795 | else | |
5796 | htab->tls_ldm_got.offset = -1; | |
5797 | ||
5798 | /* Allocate global sym .plt and .got entries, and space for global | |
5799 | sym dynamic relocs. */ | |
5800 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); | |
5801 | ||
4ef97a1b | 5802 | if (htab->root.dynamic_sections_created) |
82e91538 SL |
5803 | { |
5804 | /* If the .got section is more than 0x8000 bytes, we add | |
5805 | 0x8000 to the value of _gp_got, so that 16-bit relocations | |
5806 | have a greater chance of working. */ | |
5807 | if (htab->root.sgot->size >= 0x8000 | |
4ef97a1b AM |
5808 | && htab->h_gp_got->root.u.def.value == 0) |
5809 | htab->h_gp_got->root.u.def.value = 0x8000; | |
82e91538 SL |
5810 | } |
5811 | ||
36591ba1 SL |
5812 | /* The check_relocs and adjust_dynamic_symbol entry points have |
5813 | determined the sizes of the various dynamic sections. Allocate | |
5814 | memory for them. */ | |
0a1b45a2 | 5815 | relocs = false; |
36591ba1 SL |
5816 | for (s = dynobj->sections; s != NULL; s = s->next) |
5817 | { | |
5818 | const char *name; | |
5819 | ||
5820 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5821 | continue; | |
5822 | ||
5823 | /* It's OK to base decisions on the section name, because none | |
5824 | of the dynobj section names depend upon the input files. */ | |
fd361982 | 5825 | name = bfd_section_name (s); |
36591ba1 | 5826 | |
08dedd66 | 5827 | if (startswith (name, ".rela")) |
36591ba1 SL |
5828 | { |
5829 | if (s->size != 0) | |
5830 | { | |
4ef97a1b | 5831 | if (s != htab->root.srelplt) |
0a1b45a2 | 5832 | relocs = true; |
36591ba1 SL |
5833 | |
5834 | /* We use the reloc_count field as a counter if we need | |
5835 | to copy relocs into the output file. */ | |
5836 | s->reloc_count = 0; | |
5837 | } | |
5838 | } | |
4ef97a1b | 5839 | else if (s == htab->root.splt) |
5474d94f | 5840 | { |
4ef97a1b AM |
5841 | /* Correct for the number of res_N branches. */ |
5842 | if (s->size != 0 && !bfd_link_pic (info)) | |
5843 | { | |
5844 | htab->res_n_size = (s->size - 28) / 3; | |
5845 | s->size += htab->res_n_size; | |
5846 | } | |
5474d94f | 5847 | } |
4ef97a1b AM |
5848 | else if (s != htab->sbss |
5849 | && s != htab->root.sgot | |
5850 | && s != htab->root.sgotplt | |
5851 | && s != htab->root.sdynbss | |
5474d94f | 5852 | && s != htab->root.sdynrelro) |
36591ba1 SL |
5853 | /* It's not one of our sections, so don't allocate space. */ |
5854 | continue; | |
5855 | ||
5856 | if (s->size == 0) | |
5857 | { | |
36591ba1 SL |
5858 | s->flags |= SEC_EXCLUDE; |
5859 | continue; | |
5860 | } | |
5861 | ||
5862 | if ((s->flags & SEC_HAS_CONTENTS) == 0) | |
5863 | continue; | |
5864 | ||
5865 | /* Allocate memory for the section contents. */ | |
36591ba1 SL |
5866 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
5867 | if (s->contents == NULL) | |
0a1b45a2 | 5868 | return false; |
36591ba1 SL |
5869 | } |
5870 | ||
5871 | /* Adjust dynamic symbols that point to the plt to account for the | |
5872 | now-known number of resN slots. */ | |
5873 | if (htab->res_n_size) | |
5874 | elf_link_hash_traverse (& htab->root, adjust_dynrelocs, info); | |
5875 | ||
3084d7a2 | 5876 | return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs); |
36591ba1 SL |
5877 | } |
5878 | ||
68faa637 AM |
5879 | /* Free the derived linker hash table. */ |
5880 | static void | |
d495ab0d | 5881 | nios2_elf32_link_hash_table_free (bfd *obfd) |
68faa637 AM |
5882 | { |
5883 | struct elf32_nios2_link_hash_table *htab | |
d495ab0d | 5884 | = (struct elf32_nios2_link_hash_table *) obfd->link.hash; |
68faa637 AM |
5885 | |
5886 | bfd_hash_table_free (&htab->bstab); | |
d495ab0d | 5887 | _bfd_elf_link_hash_table_free (obfd); |
68faa637 AM |
5888 | } |
5889 | ||
36591ba1 SL |
5890 | /* Implement bfd_elf32_bfd_link_hash_table_create. */ |
5891 | static struct bfd_link_hash_table * | |
5892 | nios2_elf32_link_hash_table_create (bfd *abfd) | |
5893 | { | |
5894 | struct elf32_nios2_link_hash_table *ret; | |
986f0783 | 5895 | size_t amt = sizeof (struct elf32_nios2_link_hash_table); |
36591ba1 | 5896 | |
7bf52ea2 | 5897 | ret = bfd_zmalloc (amt); |
36591ba1 SL |
5898 | if (ret == NULL) |
5899 | return NULL; | |
5900 | ||
5901 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, | |
5902 | link_hash_newfunc, | |
5903 | sizeof (struct | |
5904 | elf32_nios2_link_hash_entry), | |
5905 | NIOS2_ELF_DATA)) | |
5906 | { | |
5907 | free (ret); | |
5908 | return NULL; | |
5909 | } | |
5910 | ||
78058a5e SL |
5911 | /* Init the stub hash table too. */ |
5912 | if (!bfd_hash_table_init (&ret->bstab, stub_hash_newfunc, | |
5913 | sizeof (struct elf32_nios2_stub_hash_entry))) | |
d495ab0d AM |
5914 | { |
5915 | _bfd_elf_link_hash_table_free (abfd); | |
5916 | return NULL; | |
5917 | } | |
5918 | ret->root.root.hash_table_free = nios2_elf32_link_hash_table_free; | |
78058a5e | 5919 | |
36591ba1 SL |
5920 | return &ret->root.root; |
5921 | } | |
5922 | ||
5923 | /* Implement elf_backend_reloc_type_class. */ | |
5924 | static enum elf_reloc_type_class | |
7e612e98 AM |
5925 | nios2_elf32_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
5926 | const asection *rel_sec ATTRIBUTE_UNUSED, | |
5927 | const Elf_Internal_Rela *rela) | |
36591ba1 SL |
5928 | { |
5929 | switch ((int) ELF32_R_TYPE (rela->r_info)) | |
5930 | { | |
5931 | case R_NIOS2_RELATIVE: | |
5932 | return reloc_class_relative; | |
5933 | case R_NIOS2_JUMP_SLOT: | |
5934 | return reloc_class_plt; | |
5935 | case R_NIOS2_COPY: | |
5936 | return reloc_class_copy; | |
5937 | default: | |
5938 | return reloc_class_normal; | |
5939 | } | |
5940 | } | |
5941 | ||
5942 | /* Return 1 if target is one of ours. */ | |
0a1b45a2 | 5943 | static bool |
36591ba1 SL |
5944 | is_nios2_elf_target (const struct bfd_target *targ) |
5945 | { | |
6d00b590 AM |
5946 | return (targ == &nios2_elf32_le_vec |
5947 | || targ == &nios2_elf32_be_vec); | |
36591ba1 SL |
5948 | } |
5949 | ||
5950 | /* Implement elf_backend_add_symbol_hook. | |
5951 | This hook is called by the linker when adding symbols from an object | |
5952 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
0a1b45a2 | 5953 | static bool |
36591ba1 SL |
5954 | nios2_elf_add_symbol_hook (bfd *abfd, |
5955 | struct bfd_link_info *info, | |
5956 | Elf_Internal_Sym *sym, | |
5957 | const char **namep ATTRIBUTE_UNUSED, | |
5958 | flagword *flagsp ATTRIBUTE_UNUSED, | |
5959 | asection **secp, | |
5960 | bfd_vma *valp) | |
5961 | { | |
36591ba1 | 5962 | if (sym->st_shndx == SHN_COMMON |
0e1862bb | 5963 | && !bfd_link_relocatable (info) |
36591ba1 SL |
5964 | && sym->st_size <= elf_gp_size (abfd) |
5965 | && is_nios2_elf_target (info->output_bfd->xvec)) | |
5966 | { | |
5967 | /* Common symbols less than or equal to -G nn bytes are automatically | |
5968 | put into .sbss. */ | |
5969 | struct elf32_nios2_link_hash_table *htab; | |
5970 | ||
5971 | htab = elf32_nios2_hash_table (info); | |
5972 | if (htab->sbss == NULL) | |
5973 | { | |
10885e24 | 5974 | flagword flags = SEC_IS_COMMON | SEC_SMALL_DATA | SEC_LINKER_CREATED; |
36591ba1 | 5975 | |
4ef97a1b AM |
5976 | if (htab->root.dynobj == NULL) |
5977 | htab->root.dynobj = abfd; | |
36591ba1 | 5978 | |
4ef97a1b AM |
5979 | htab->sbss = bfd_make_section_anyway_with_flags (htab->root.dynobj, |
5980 | ".sbss", flags); | |
36591ba1 | 5981 | if (htab->sbss == NULL) |
0a1b45a2 | 5982 | return false; |
36591ba1 SL |
5983 | } |
5984 | ||
5985 | *secp = htab->sbss; | |
5986 | *valp = sym->st_size; | |
5987 | } | |
5988 | ||
0a1b45a2 | 5989 | return true; |
36591ba1 SL |
5990 | } |
5991 | ||
5992 | /* Implement elf_backend_can_make_relative_eh_frame: | |
5993 | Decide whether to attempt to turn absptr or lsda encodings in | |
5994 | shared libraries into pcrel within the given input section. */ | |
0a1b45a2 | 5995 | static bool |
36591ba1 SL |
5996 | nios2_elf32_can_make_relative_eh_frame (bfd *input_bfd ATTRIBUTE_UNUSED, |
5997 | struct bfd_link_info *info | |
5998 | ATTRIBUTE_UNUSED, | |
5999 | asection *eh_frame_section | |
6000 | ATTRIBUTE_UNUSED) | |
6001 | { | |
6002 | /* We can't use PC-relative encodings in the .eh_frame section. */ | |
0a1b45a2 | 6003 | return false; |
36591ba1 SL |
6004 | } |
6005 | ||
6006 | /* Implement elf_backend_special_sections. */ | |
6007 | const struct bfd_elf_special_section elf32_nios2_special_sections[] = | |
6008 | { | |
6009 | { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, | |
6010 | SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL }, | |
6011 | { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, | |
6012 | SHF_ALLOC + SHF_WRITE + SHF_NIOS2_GPREL }, | |
6013 | { NULL, 0, 0, 0, 0 } | |
6014 | }; | |
6015 | ||
6016 | #define ELF_ARCH bfd_arch_nios2 | |
6017 | #define ELF_TARGET_ID NIOS2_ELF_DATA | |
6018 | #define ELF_MACHINE_CODE EM_ALTERA_NIOS2 | |
6019 | ||
6020 | /* The Nios II MMU uses a 4K page size. */ | |
6021 | ||
6022 | #define ELF_MAXPAGESIZE 0x1000 | |
6023 | ||
6024 | #define bfd_elf32_bfd_link_hash_table_create \ | |
6025 | nios2_elf32_link_hash_table_create | |
6026 | ||
965b1d80 SL |
6027 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
6028 | nios2_elf32_merge_private_bfd_data | |
6029 | ||
36591ba1 SL |
6030 | /* Relocation table lookup macros. */ |
6031 | ||
6032 | #define bfd_elf32_bfd_reloc_type_lookup nios2_elf32_bfd_reloc_type_lookup | |
6033 | #define bfd_elf32_bfd_reloc_name_lookup nios2_elf32_bfd_reloc_name_lookup | |
6034 | ||
6035 | /* JUMP_TABLE_LINK macros. */ | |
6036 | ||
6037 | /* elf_info_to_howto (using RELA relocations). */ | |
6038 | ||
6039 | #define elf_info_to_howto nios2_elf32_info_to_howto | |
6040 | ||
6041 | /* elf backend functions. */ | |
6042 | ||
6043 | #define elf_backend_can_gc_sections 1 | |
6044 | #define elf_backend_can_refcount 1 | |
6045 | #define elf_backend_plt_readonly 1 | |
6046 | #define elf_backend_want_got_plt 1 | |
5474d94f | 6047 | #define elf_backend_want_dynrelro 1 |
36591ba1 | 6048 | #define elf_backend_rela_normal 1 |
64f52338 | 6049 | #define elf_backend_dtrel_excludes_plt 1 |
36591ba1 SL |
6050 | |
6051 | #define elf_backend_relocate_section nios2_elf32_relocate_section | |
6052 | #define elf_backend_section_flags nios2_elf32_section_flags | |
6053 | #define elf_backend_fake_sections nios2_elf32_fake_sections | |
6054 | #define elf_backend_check_relocs nios2_elf32_check_relocs | |
6055 | ||
6056 | #define elf_backend_gc_mark_hook nios2_elf32_gc_mark_hook | |
36591ba1 SL |
6057 | #define elf_backend_create_dynamic_sections \ |
6058 | nios2_elf32_create_dynamic_sections | |
6059 | #define elf_backend_finish_dynamic_symbol nios2_elf32_finish_dynamic_symbol | |
6060 | #define elf_backend_finish_dynamic_sections \ | |
6061 | nios2_elf32_finish_dynamic_sections | |
6062 | #define elf_backend_adjust_dynamic_symbol nios2_elf32_adjust_dynamic_symbol | |
6063 | #define elf_backend_reloc_type_class nios2_elf32_reloc_type_class | |
af969b14 | 6064 | #define elf_backend_late_size_sections nios2_elf32_late_size_sections |
36591ba1 SL |
6065 | #define elf_backend_add_symbol_hook nios2_elf_add_symbol_hook |
6066 | #define elf_backend_copy_indirect_symbol nios2_elf32_copy_indirect_symbol | |
965b1d80 | 6067 | #define elf_backend_object_p nios2_elf32_object_p |
36591ba1 SL |
6068 | |
6069 | #define elf_backend_grok_prstatus nios2_grok_prstatus | |
6070 | #define elf_backend_grok_psinfo nios2_grok_psinfo | |
6071 | ||
6072 | #undef elf_backend_can_make_relative_eh_frame | |
6073 | #define elf_backend_can_make_relative_eh_frame \ | |
6074 | nios2_elf32_can_make_relative_eh_frame | |
6075 | ||
6076 | #define elf_backend_special_sections elf32_nios2_special_sections | |
6077 | ||
6d00b590 | 6078 | #define TARGET_LITTLE_SYM nios2_elf32_le_vec |
36591ba1 | 6079 | #define TARGET_LITTLE_NAME "elf32-littlenios2" |
6d00b590 | 6080 | #define TARGET_BIG_SYM nios2_elf32_be_vec |
36591ba1 SL |
6081 | #define TARGET_BIG_NAME "elf32-bignios2" |
6082 | ||
6083 | #define elf_backend_got_header_size 12 | |
03d5b773 | 6084 | #define elf_backend_default_execstack 0 |
36591ba1 SL |
6085 | |
6086 | #include "elf32-target.h" |