1 /* NDS32-specific support for 32-bit ELF.
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 #include "bfd_stdint.h"
29 #include "libiberty.h"
30 #include "bfd_stdint.h"
31 #include "elf/nds32.h"
32 #include "opcode/nds32.h"
33 #include "elf32-nds32.h"
34 #include "opcode/cgen.h"
35 #include "../opcodes/nds32-opc.h"
37 /* Relocation HOWTO functions. */
38 static bfd_reloc_status_type nds32_elf_ignore_reloc
39 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
40 static bfd_reloc_status_type nds32_elf_9_pcrel_reloc
41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
42 static bfd_reloc_status_type nds32_elf_hi20_reloc
43 (bfd *, arelent *, asymbol *, void *,
44 asection *, bfd *, char **);
45 static bfd_reloc_status_type nds32_elf_lo12_reloc
46 (bfd *, arelent *, asymbol *, void *,
47 asection *, bfd *, char **);
48 static bfd_reloc_status_type nds32_elf_generic_reloc
49 (bfd *, arelent *, asymbol *, void *,
50 asection *, bfd *, char **);
51 static bfd_reloc_status_type nds32_elf_sda15_reloc
52 (bfd *, arelent *, asymbol *, void *,
53 asection *, bfd *, char **);
55 /* Helper functions for HOWTO. */
56 static bfd_reloc_status_type nds32_elf_do_9_pcrel_reloc
57 (bfd *, reloc_howto_type *, asection *, bfd_byte *, bfd_vma,
58 asection *, bfd_vma, bfd_vma);
60 /* Nds32 helper functions. */
61 static bfd_vma calculate_memory_address
62 (bfd *, Elf_Internal_Rela *, Elf_Internal_Sym *, Elf_Internal_Shdr *);
63 static int nds32_get_section_contents (bfd *, asection *,
64 bfd_byte **, bfd_boolean);
65 static int nds32_get_local_syms (bfd *, asection *ATTRIBUTE_UNUSED,
67 static bfd_boolean nds32_relax_fp_as_gp
68 (struct bfd_link_info *link_info, bfd *abfd, asection *sec,
69 Elf_Internal_Rela *internal_relocs, Elf_Internal_Rela *irelend,
70 Elf_Internal_Sym *isymbuf);
71 static bfd_boolean nds32_fag_remove_unused_fpbase
72 (bfd *abfd, asection *sec, Elf_Internal_Rela *internal_relocs,
73 Elf_Internal_Rela *irelend);
77 MACH_V1 = bfd_mach_n1h,
78 MACH_V2 = bfd_mach_n1h_v2,
79 MACH_V3 = bfd_mach_n1h_v3,
80 MACH_V3M = bfd_mach_n1h_v3m
83 #define MIN(a, b) ((a) > (b) ? (b) : (a))
84 #define MAX(a, b) ((a) > (b) ? (a) : (b))
86 /* The name of the dynamic interpreter. This is put in the .interp
88 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
90 #define NDS32_GUARD_SEC_P(flags) ((flags) & SEC_ALLOC \
91 && (flags) & SEC_LOAD \
92 && (flags) & SEC_READONLY)
94 /* The nop opcode we use. */
95 #define NDS32_NOP32 0x40000009
96 #define NDS32_NOP16 0x9200
98 /* The size in bytes of an entry in the procedure linkage table. */
99 #define PLT_ENTRY_SIZE 24
100 #define PLT_HEADER_SIZE 24
102 /* The first entry in a procedure linkage table are reserved,
103 and the initial contents are unimportant (we zero them out).
104 Subsequent entries look like this. */
105 #define PLT0_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(.got+4) */
106 #define PLT0_ENTRY_WORD1 0x58f78000 /* ori r15, r25, LO12(.got+4) */
107 #define PLT0_ENTRY_WORD2 0x05178000 /* lwi r17, [r15+0] */
108 #define PLT0_ENTRY_WORD3 0x04f78001 /* lwi r15, [r15+4] */
109 #define PLT0_ENTRY_WORD4 0x4a003c00 /* jr r15 */
111 /* $ta is change to $r15 (from $r25). */
112 #define PLT0_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[1]@GOT) */
113 #define PLT0_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[1]@GOT) */
114 #define PLT0_PIC_ENTRY_WORD2 0x40f7f400 /* add r15, gp, r15 */
115 #define PLT0_PIC_ENTRY_WORD3 0x05178000 /* lwi r17, [r15+0] */
116 #define PLT0_PIC_ENTRY_WORD4 0x04f78001 /* lwi r15, [r15+4] */
117 #define PLT0_PIC_ENTRY_WORD5 0x4a003c00 /* jr r15 */
119 #define PLT_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(&got[n+3]) */
120 #define PLT_ENTRY_WORD1 0x04f78000 /* lwi r15, r15, LO12(&got[n+3]) */
121 #define PLT_ENTRY_WORD2 0x4a003c00 /* jr r15 */
122 #define PLT_ENTRY_WORD3 0x45000000 /* movi r16, sizeof(RELA) * n */
123 #define PLT_ENTRY_WORD4 0x48000000 /* j .plt0. */
125 #define PLT_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[n+3]@GOT) */
126 #define PLT_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[n+3]@GOT) */
127 #define PLT_PIC_ENTRY_WORD2 0x38febc02 /* lw r15, [gp+r15] */
128 #define PLT_PIC_ENTRY_WORD3 0x4a003c00 /* jr r15 */
129 #define PLT_PIC_ENTRY_WORD4 0x45000000 /* movi r16, sizeof(RELA) * n */
130 #define PLT_PIC_ENTRY_WORD5 0x48000000 /* j .plt0 */
132 /* These are macros used to get the relocation accurate value. */
133 #define ACCURATE_8BIT_S1 (0x100)
134 #define ACCURATE_U9BIT_S1 (0x400)
135 #define ACCURATE_12BIT_S1 (0x2000)
136 #define ACCURATE_14BIT_S1 (0x4000)
137 #define ACCURATE_19BIT (0x40000)
139 /* These are macros used to get the relocation conservative value. */
140 #define CONSERVATIVE_8BIT_S1 (0x100 - 4)
141 #define CONSERVATIVE_14BIT_S1 (0x4000 - 4)
142 #define CONSERVATIVE_16BIT_S1 (0x10000 - 4)
143 #define CONSERVATIVE_24BIT_S1 (0x1000000 - 4)
144 /* These must be more conservative because the address may be in
145 different segment. */
146 #define CONSERVATIVE_15BIT (0x4000 - 0x1000)
147 #define CONSERVATIVE_15BIT_S1 (0x8000 - 0x1000)
148 #define CONSERVATIVE_15BIT_S2 (0x10000 - 0x1000)
149 #define CONSERVATIVE_19BIT (0x40000 - 0x1000)
150 #define CONSERVATIVE_20BIT (0x80000 - 0x1000)
152 /* Size of small data/bss sections, used to calculate SDA_BASE. */
153 static long got_size = 0;
154 static int is_SDA_BASE_set = 0;
156 /* Convert ELF-VER in eflags to string for debugging purpose. */
157 static const char *const nds32_elfver_strtab[] =
164 /* The nds32 linker needs to keep track of the number of relocs that it
165 decides to copy in check_relocs for each symbol. This is so that
166 it can discard PC relative relocs if it doesn't need them when
167 linking with -Bsymbolic. We store the information in a field
168 extending the regular ELF linker hash table. */
170 /* This structure keeps track of the number of PC relative relocs we
171 have copied for a given symbol. */
173 struct elf_nds32_pcrel_relocs_copied
176 struct elf_nds32_pcrel_relocs_copied *next;
177 /* A section in dynobj. */
179 /* Number of relocs copied in this section. */
183 enum elf_nds32_tls_type
186 GOT_NORMAL = (1 << 0),
187 GOT_TLS_LE = (1 << 1),
188 GOT_TLS_IE = (1 << 2),
189 GOT_TLS_IEGP = (1 << 3),
190 GOT_TLS_LD = (1 << 4),
191 GOT_TLS_GD = (1 << 5),
192 GOT_TLS_DESC = (1 << 6),
195 /* Nds32 ELF linker hash entry. */
197 struct elf_nds32_link_hash_entry
199 struct elf_link_hash_entry root;
201 /* Track dynamic relocs copied for this symbol. */
202 struct elf_dyn_relocs *dyn_relocs;
204 /* For checking relocation type. */
205 enum elf_nds32_tls_type tls_type;
210 /* Get the nds32 ELF linker hash table from a link_info structure. */
212 #define FP_BASE_NAME "_FP_BASE_"
213 static int check_start_export_sym = 0;
215 /* The offset for executable tls relaxation. */
216 #define TP_OFFSET 0x0
225 } elf32_nds32_relax_group_t;
227 struct elf_nds32_obj_tdata
229 struct elf_obj_tdata root;
231 /* tls_type for each local got entry. */
232 char *local_got_tls_type;
234 /* GOTPLT entries for TLS descriptors. */
235 bfd_vma *local_tlsdesc_gotent;
237 /* for R_NDS32_RELAX_GROUP handling. */
238 elf32_nds32_relax_group_t relax_group;
240 unsigned int hdr_size;
244 #define elf_nds32_tdata(bfd) \
245 ((struct elf_nds32_obj_tdata *) (bfd)->tdata.any)
247 #define elf32_nds32_local_got_tls_type(bfd) \
248 (elf_nds32_tdata (bfd)->local_got_tls_type)
250 #define elf32_nds32_local_gp_offset(bfd) \
251 (elf_nds32_tdata (bfd)->offset_to_gp)
253 #define elf32_nds32_hash_entry(ent) ((struct elf_nds32_link_hash_entry *)(ent))
255 #define elf32_nds32_relax_group_ptr(bfd) \
256 &(elf_nds32_tdata (bfd)->relax_group)
259 nds32_elf_mkobject (bfd *abfd)
261 return bfd_elf_allocate_object (abfd, sizeof (struct elf_nds32_obj_tdata),
265 /* Relocations used for relocation. */
266 /* Define HOWTO2 (for relocation) and HOWTO3 (for relaxation) to
267 initialize array nds32_elf_howto_table in any order. The benefit
268 is that we can add any new relocations with any numbers and don't
269 need to fill the gap by lots of EMPTY_HOWTO. */
270 #define HOWTO2(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
271 [C] = HOWTO(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC)
273 static reloc_howto_type nds32_elf_howto_table[] =
275 /* This reloc does nothing. */
276 HOWTO2 (R_NDS32_NONE, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE, /* pc_relative */
282 complain_overflow_bitfield,/* complain_on_overflow */
283 bfd_elf_generic_reloc, /* special_function */
284 "R_NDS32_NONE", /* name */
285 FALSE, /* partial_inplace */
288 FALSE), /* pcrel_offset */
290 /* A 16 bit absolute relocation. */
291 HOWTO2 (R_NDS32_16, /* type */
293 1, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE, /* pc_relative */
297 complain_overflow_bitfield,/* complain_on_overflow */
298 nds32_elf_generic_reloc,/* special_function */
299 "R_NDS32_16", /* name */
300 FALSE, /* partial_inplace */
301 0xffff, /* src_mask */
302 0xffff, /* dst_mask */
303 FALSE), /* pcrel_offset */
305 /* A 32 bit absolute relocation. */
306 HOWTO2 (R_NDS32_32, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE, /* pc_relative */
312 complain_overflow_bitfield,/* complain_on_overflow */
313 nds32_elf_generic_reloc,/* special_function */
314 "R_NDS32_32", /* name */
315 FALSE, /* partial_inplace */
316 0xffffffff, /* src_mask */
317 0xffffffff, /* dst_mask */
318 FALSE), /* pcrel_offset */
320 /* A 20 bit address. */
321 HOWTO2 (R_NDS32_20, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE, /* pc_relative */
327 complain_overflow_unsigned,/* complain_on_overflow */
328 nds32_elf_generic_reloc,/* special_function */
329 "R_NDS32_20", /* name */
330 FALSE, /* partial_inplace */
331 0xfffff, /* src_mask */
332 0xfffff, /* dst_mask */
333 FALSE), /* pcrel_offset */
335 /* An PC Relative 9-bit relocation, shifted by 2.
336 This reloc is complicated because relocations are relative to pc & -4.
337 i.e. branches in the right insn slot use the address of the left insn
339 /* It's not clear whether this should have partial_inplace set or not.
340 Branch relaxing in the assembler can store the addend in the insn,
341 and if bfd_install_relocation gets called the addend may get added
343 HOWTO2 (R_NDS32_9_PCREL, /* type */
345 1, /* size (0 = byte, 1 = short, 2 = long) */
347 TRUE, /* pc_relative */
349 complain_overflow_signed,/* complain_on_overflow */
350 nds32_elf_9_pcrel_reloc,/* special_function */
351 "R_NDS32_9_PCREL", /* name */
352 FALSE, /* partial_inplace */
355 TRUE), /* pcrel_offset */
357 /* A relative 15 bit relocation, right shifted by 1. */
358 HOWTO2 (R_NDS32_15_PCREL, /* type */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
362 TRUE, /* pc_relative */
364 complain_overflow_signed,/* complain_on_overflow */
365 bfd_elf_generic_reloc, /* special_function */
366 "R_NDS32_15_PCREL", /* name */
367 FALSE, /* partial_inplace */
368 0x3fff, /* src_mask */
369 0x3fff, /* dst_mask */
370 TRUE), /* pcrel_offset */
372 /* A relative 17 bit relocation, right shifted by 1. */
373 HOWTO2 (R_NDS32_17_PCREL, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 TRUE, /* pc_relative */
379 complain_overflow_signed,/* complain_on_overflow */
380 bfd_elf_generic_reloc, /* special_function */
381 "R_NDS32_17_PCREL", /* name */
382 FALSE, /* partial_inplace */
383 0xffff, /* src_mask */
384 0xffff, /* dst_mask */
385 TRUE), /* pcrel_offset */
387 /* A relative 25 bit relocation, right shifted by 1. */
388 /* It's not clear whether this should have partial_inplace set or not.
389 Branch relaxing in the assembler can store the addend in the insn,
390 and if bfd_install_relocation gets called the addend may get added
392 HOWTO2 (R_NDS32_25_PCREL, /* type */
394 2, /* size (0 = byte, 1 = short, 2 = long) */
396 TRUE, /* pc_relative */
398 complain_overflow_signed,/* complain_on_overflow */
399 bfd_elf_generic_reloc, /* special_function */
400 "R_NDS32_25_PCREL", /* name */
401 FALSE, /* partial_inplace */
402 0xffffff, /* src_mask */
403 0xffffff, /* dst_mask */
404 TRUE), /* pcrel_offset */
406 /* High 20 bits of address when lower 12 is or'd in. */
407 HOWTO2 (R_NDS32_HI20, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 FALSE, /* pc_relative */
413 complain_overflow_dont,/* complain_on_overflow */
414 nds32_elf_hi20_reloc, /* special_function */
415 "R_NDS32_HI20", /* name */
416 FALSE, /* partial_inplace */
417 0x000fffff, /* src_mask */
418 0x000fffff, /* dst_mask */
419 FALSE), /* pcrel_offset */
421 /* Lower 12 bits of address. */
422 HOWTO2 (R_NDS32_LO12S3, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE, /* pc_relative */
428 complain_overflow_dont,/* complain_on_overflow */
429 nds32_elf_lo12_reloc, /* special_function */
430 "R_NDS32_LO12S3", /* name */
431 FALSE, /* partial_inplace */
432 0x000001ff, /* src_mask */
433 0x000001ff, /* dst_mask */
434 FALSE), /* pcrel_offset */
436 /* Lower 12 bits of address. */
437 HOWTO2 (R_NDS32_LO12S2, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 FALSE, /* pc_relative */
443 complain_overflow_dont,/* complain_on_overflow */
444 nds32_elf_lo12_reloc, /* special_function */
445 "R_NDS32_LO12S2", /* name */
446 FALSE, /* partial_inplace */
447 0x000003ff, /* src_mask */
448 0x000003ff, /* dst_mask */
449 FALSE), /* pcrel_offset */
451 /* Lower 12 bits of address. */
452 HOWTO2 (R_NDS32_LO12S1, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE, /* pc_relative */
458 complain_overflow_dont,/* complain_on_overflow */
459 nds32_elf_lo12_reloc, /* special_function */
460 "R_NDS32_LO12S1", /* name */
461 FALSE, /* partial_inplace */
462 0x000007ff, /* src_mask */
463 0x000007ff, /* dst_mask */
464 FALSE), /* pcrel_offset */
466 /* Lower 12 bits of address. */
467 HOWTO2 (R_NDS32_LO12S0, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE, /* pc_relative */
473 complain_overflow_dont,/* complain_on_overflow */
474 nds32_elf_lo12_reloc, /* special_function */
475 "R_NDS32_LO12S0", /* name */
476 FALSE, /* partial_inplace */
477 0x00000fff, /* src_mask */
478 0x00000fff, /* dst_mask */
479 FALSE), /* pcrel_offset */
481 /* Small data area 15 bits offset. */
482 HOWTO2 (R_NDS32_SDA15S3, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE, /* pc_relative */
488 complain_overflow_signed,/* complain_on_overflow */
489 nds32_elf_sda15_reloc, /* special_function */
490 "R_NDS32_SDA15S3", /* name */
491 FALSE, /* partial_inplace */
492 0x00007fff, /* src_mask */
493 0x00007fff, /* dst_mask */
494 FALSE), /* pcrel_offset */
496 /* Small data area 15 bits offset. */
497 HOWTO2 (R_NDS32_SDA15S2, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE, /* pc_relative */
503 complain_overflow_signed,/* complain_on_overflow */
504 nds32_elf_sda15_reloc, /* special_function */
505 "R_NDS32_SDA15S2", /* name */
506 FALSE, /* partial_inplace */
507 0x00007fff, /* src_mask */
508 0x00007fff, /* dst_mask */
509 FALSE), /* pcrel_offset */
511 /* Small data area 15 bits offset. */
512 HOWTO2 (R_NDS32_SDA15S1, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE, /* pc_relative */
518 complain_overflow_signed,/* complain_on_overflow */
519 nds32_elf_sda15_reloc, /* special_function */
520 "R_NDS32_SDA15S1", /* name */
521 FALSE, /* partial_inplace */
522 0x00007fff, /* src_mask */
523 0x00007fff, /* dst_mask */
524 FALSE), /* pcrel_offset */
526 /* Small data area 15 bits offset. */
527 HOWTO2 (R_NDS32_SDA15S0, /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 FALSE, /* pc_relative */
533 complain_overflow_signed,/* complain_on_overflow */
534 nds32_elf_sda15_reloc, /* special_function */
535 "R_NDS32_SDA15S0", /* name */
536 FALSE, /* partial_inplace */
537 0x00007fff, /* src_mask */
538 0x00007fff, /* dst_mask */
539 FALSE), /* pcrel_offset */
541 /* GNU extension to record C++ vtable hierarchy */
542 HOWTO2 (R_NDS32_GNU_VTINHERIT,/* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE, /* pc_relative */
548 complain_overflow_dont,/* complain_on_overflow */
549 NULL, /* special_function */
550 "R_NDS32_GNU_VTINHERIT",/* name */
551 FALSE, /* partial_inplace */
554 FALSE), /* pcrel_offset */
556 /* GNU extension to record C++ vtable member usage */
557 HOWTO2 (R_NDS32_GNU_VTENTRY, /* type */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
561 FALSE, /* pc_relative */
563 complain_overflow_dont,/* complain_on_overflow */
564 _bfd_elf_rel_vtable_reloc_fn,/* special_function */
565 "R_NDS32_GNU_VTENTRY", /* name */
566 FALSE, /* partial_inplace */
569 FALSE), /* pcrel_offset */
571 /* A 16 bit absolute relocation. */
572 HOWTO2 (R_NDS32_16_RELA, /* type */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
576 FALSE, /* pc_relative */
578 complain_overflow_bitfield,/* complain_on_overflow */
579 bfd_elf_generic_reloc, /* special_function */
580 "R_NDS32_16_RELA", /* name */
581 FALSE, /* partial_inplace */
582 0xffff, /* src_mask */
583 0xffff, /* dst_mask */
584 FALSE), /* pcrel_offset */
586 /* A 32 bit absolute relocation. */
587 HOWTO2 (R_NDS32_32_RELA, /* type */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
591 FALSE, /* pc_relative */
593 complain_overflow_bitfield,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_NDS32_32_RELA", /* name */
596 FALSE, /* partial_inplace */
597 0xffffffff, /* src_mask */
598 0xffffffff, /* dst_mask */
599 FALSE), /* pcrel_offset */
601 /* A 20 bit address. */
602 HOWTO2 (R_NDS32_20_RELA, /* type */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE, /* pc_relative */
608 complain_overflow_signed,/* complain_on_overflow */
609 bfd_elf_generic_reloc, /* special_function */
610 "R_NDS32_20_RELA", /* name */
611 FALSE, /* partial_inplace */
612 0xfffff, /* src_mask */
613 0xfffff, /* dst_mask */
614 FALSE), /* pcrel_offset */
616 HOWTO2 (R_NDS32_9_PCREL_RELA, /* type */
618 1, /* size (0 = byte, 1 = short, 2 = long) */
620 TRUE, /* pc_relative */
622 complain_overflow_signed,/* complain_on_overflow */
623 bfd_elf_generic_reloc, /* special_function */
624 "R_NDS32_9_PCREL_RELA",/* name */
625 FALSE, /* partial_inplace */
628 TRUE), /* pcrel_offset */
630 /* A relative 15 bit relocation, right shifted by 1. */
631 HOWTO2 (R_NDS32_15_PCREL_RELA,/* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 TRUE, /* pc_relative */
637 complain_overflow_signed,/* complain_on_overflow */
638 bfd_elf_generic_reloc, /* special_function */
639 "R_NDS32_15_PCREL_RELA",/* name */
640 FALSE, /* partial_inplace */
641 0x3fff, /* src_mask */
642 0x3fff, /* dst_mask */
643 TRUE), /* pcrel_offset */
645 /* A relative 17 bit relocation, right shifted by 1. */
646 HOWTO2 (R_NDS32_17_PCREL_RELA,/* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE, /* pc_relative */
652 complain_overflow_signed,/* complain_on_overflow */
653 bfd_elf_generic_reloc, /* special_function */
654 "R_NDS32_17_PCREL_RELA",/* name */
655 FALSE, /* partial_inplace */
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
658 TRUE), /* pcrel_offset */
660 /* A relative 25 bit relocation, right shifted by 2. */
661 HOWTO2 (R_NDS32_25_PCREL_RELA,/* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE, /* pc_relative */
667 complain_overflow_signed,/* complain_on_overflow */
668 bfd_elf_generic_reloc, /* special_function */
669 "R_NDS32_25_PCREL_RELA",/* name */
670 FALSE, /* partial_inplace */
671 0xffffff, /* src_mask */
672 0xffffff, /* dst_mask */
673 TRUE), /* pcrel_offset */
675 /* High 20 bits of address when lower 16 is or'd in. */
676 HOWTO2 (R_NDS32_HI20_RELA, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE, /* pc_relative */
682 complain_overflow_dont,/* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_NDS32_HI20_RELA", /* name */
685 FALSE, /* partial_inplace */
686 0x000fffff, /* src_mask */
687 0x000fffff, /* dst_mask */
688 FALSE), /* pcrel_offset */
690 /* Lower 12 bits of address. */
691 HOWTO2 (R_NDS32_LO12S3_RELA, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE, /* pc_relative */
697 complain_overflow_dont,/* complain_on_overflow */
698 bfd_elf_generic_reloc, /* special_function */
699 "R_NDS32_LO12S3_RELA", /* name */
700 FALSE, /* partial_inplace */
701 0x000001ff, /* src_mask */
702 0x000001ff, /* dst_mask */
703 FALSE), /* pcrel_offset */
705 /* Lower 12 bits of address. */
706 HOWTO2 (R_NDS32_LO12S2_RELA, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE, /* pc_relative */
712 complain_overflow_dont,/* complain_on_overflow */
713 bfd_elf_generic_reloc, /* special_function */
714 "R_NDS32_LO12S2_RELA", /* name */
715 FALSE, /* partial_inplace */
716 0x000003ff, /* src_mask */
717 0x000003ff, /* dst_mask */
718 FALSE), /* pcrel_offset */
720 /* Lower 12 bits of address. */
721 HOWTO2 (R_NDS32_LO12S1_RELA, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 FALSE, /* pc_relative */
727 complain_overflow_dont,/* complain_on_overflow */
728 bfd_elf_generic_reloc, /* special_function */
729 "R_NDS32_LO12S1_RELA", /* name */
730 FALSE, /* partial_inplace */
731 0x000007ff, /* src_mask */
732 0x000007ff, /* dst_mask */
733 FALSE), /* pcrel_offset */
735 /* Lower 12 bits of address. */
736 HOWTO2 (R_NDS32_LO12S0_RELA, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE, /* pc_relative */
742 complain_overflow_dont,/* complain_on_overflow */
743 bfd_elf_generic_reloc, /* special_function */
744 "R_NDS32_LO12S0_RELA", /* name */
745 FALSE, /* partial_inplace */
746 0x00000fff, /* src_mask */
747 0x00000fff, /* dst_mask */
748 FALSE), /* pcrel_offset */
750 /* Small data area 15 bits offset. */
751 HOWTO2 (R_NDS32_SDA15S3_RELA, /* type */
753 2, /* size (0 = byte, 1 = short, 2 = long) */
755 FALSE, /* pc_relative */
757 complain_overflow_signed,/* complain_on_overflow */
758 bfd_elf_generic_reloc, /* special_function */
759 "R_NDS32_SDA15S3_RELA",/* name */
760 FALSE, /* partial_inplace */
761 0x00007fff, /* src_mask */
762 0x00007fff, /* dst_mask */
763 FALSE), /* pcrel_offset */
765 /* Small data area 15 bits offset. */
766 HOWTO2 (R_NDS32_SDA15S2_RELA, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 FALSE, /* pc_relative */
772 complain_overflow_signed,/* complain_on_overflow */
773 bfd_elf_generic_reloc, /* special_function */
774 "R_NDS32_SDA15S2_RELA",/* name */
775 FALSE, /* partial_inplace */
776 0x00007fff, /* src_mask */
777 0x00007fff, /* dst_mask */
778 FALSE), /* pcrel_offset */
780 HOWTO2 (R_NDS32_SDA15S1_RELA, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE, /* pc_relative */
786 complain_overflow_signed,/* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_NDS32_SDA15S1_RELA",/* name */
789 FALSE, /* partial_inplace */
790 0x00007fff, /* src_mask */
791 0x00007fff, /* dst_mask */
792 FALSE), /* pcrel_offset */
794 HOWTO2 (R_NDS32_SDA15S0_RELA, /* type */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE, /* pc_relative */
800 complain_overflow_signed,/* complain_on_overflow */
801 bfd_elf_generic_reloc, /* special_function */
802 "R_NDS32_SDA15S0_RELA",/* name */
803 FALSE, /* partial_inplace */
804 0x00007fff, /* src_mask */
805 0x00007fff, /* dst_mask */
806 FALSE), /* pcrel_offset */
808 /* GNU extension to record C++ vtable hierarchy */
809 HOWTO2 (R_NDS32_RELA_GNU_VTINHERIT,/* type */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 FALSE, /* pc_relative */
815 complain_overflow_dont,/* complain_on_overflow */
816 NULL, /* special_function */
817 "R_NDS32_RELA_GNU_VTINHERIT",/* name */
818 FALSE, /* partial_inplace */
821 FALSE), /* pcrel_offset */
823 /* GNU extension to record C++ vtable member usage */
824 HOWTO2 (R_NDS32_RELA_GNU_VTENTRY,/* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE, /* pc_relative */
830 complain_overflow_dont,/* complain_on_overflow */
831 _bfd_elf_rel_vtable_reloc_fn,/* special_function */
832 "R_NDS32_RELA_GNU_VTENTRY",/* name */
833 FALSE, /* partial_inplace */
836 FALSE), /* pcrel_offset */
838 /* Like R_NDS32_20, but referring to the GOT table entry for
840 HOWTO2 (R_NDS32_GOT20, /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 FALSE, /* pc_relative */
846 complain_overflow_signed,/* complain_on_overflow */
847 bfd_elf_generic_reloc, /* special_function */
848 "R_NDS32_GOT20", /* name */
849 FALSE, /* partial_inplace */
850 0xfffff, /* src_mask */
851 0xfffff, /* dst_mask */
852 FALSE), /* pcrel_offset */
854 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
855 entry for the symbol. */
856 HOWTO2 (R_NDS32_25_PLTREL, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 TRUE, /* pc_relative */
862 complain_overflow_signed,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_NDS32_25_PLTREL", /* name */
865 FALSE, /* partial_inplace */
866 0xffffff, /* src_mask */
867 0xffffff, /* dst_mask */
868 TRUE), /* pcrel_offset */
870 /* This is used only by the dynamic linker. The symbol should exist
871 both in the object being run and in some shared library. The
872 dynamic linker copies the data addressed by the symbol from the
873 shared library into the object, because the object being
874 run has to have the data at some particular address. */
875 HOWTO2 (R_NDS32_COPY, /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE, /* pc_relative */
881 complain_overflow_bitfield,/* complain_on_overflow */
882 bfd_elf_generic_reloc, /* special_function */
883 "R_NDS32_COPY", /* name */
884 FALSE, /* partial_inplace */
885 0xffffffff, /* src_mask */
886 0xffffffff, /* dst_mask */
887 FALSE), /* pcrel_offset */
889 /* Like R_NDS32_20, but used when setting global offset table
891 HOWTO2 (R_NDS32_GLOB_DAT, /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE, /* pc_relative */
897 complain_overflow_bitfield,/* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 "R_NDS32_GLOB_DAT", /* name */
900 FALSE, /* partial_inplace */
901 0xffffffff, /* src_mask */
902 0xffffffff, /* dst_mask */
903 FALSE), /* pcrel_offset */
905 /* Marks a procedure linkage table entry for a symbol. */
906 HOWTO2 (R_NDS32_JMP_SLOT, /* type */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE, /* pc_relative */
912 complain_overflow_bitfield,/* complain_on_overflow */
913 bfd_elf_generic_reloc, /* special_function */
914 "R_NDS32_JMP_SLOT", /* name */
915 FALSE, /* partial_inplace */
916 0xffffffff, /* src_mask */
917 0xffffffff, /* dst_mask */
918 FALSE), /* pcrel_offset */
920 /* Used only by the dynamic linker. When the object is run, this
921 longword is set to the load address of the object, plus the
923 HOWTO2 (R_NDS32_RELATIVE, /* type */
925 2, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE, /* pc_relative */
929 complain_overflow_bitfield,/* complain_on_overflow */
930 bfd_elf_generic_reloc, /* special_function */
931 "R_NDS32_RELATIVE", /* name */
932 FALSE, /* partial_inplace */
933 0xffffffff, /* src_mask */
934 0xffffffff, /* dst_mask */
935 FALSE), /* pcrel_offset */
937 HOWTO2 (R_NDS32_GOTOFF, /* type */
939 2, /* size (0 = byte, 1 = short, 2 = long) */
941 FALSE, /* pc_relative */
943 complain_overflow_signed,/* complain_on_overflow */
944 bfd_elf_generic_reloc, /* special_function */
945 "R_NDS32_GOTOFF", /* name */
946 FALSE, /* partial_inplace */
947 0xfffff, /* src_mask */
948 0xfffff, /* dst_mask */
949 FALSE), /* pcrel_offset */
951 /* An PC Relative 20-bit relocation used when setting PIC offset
953 HOWTO2 (R_NDS32_GOTPC20, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 TRUE, /* pc_relative */
959 complain_overflow_signed,/* complain_on_overflow */
960 bfd_elf_generic_reloc, /* special_function */
961 "R_NDS32_GOTPC20", /* name */
962 FALSE, /* partial_inplace */
963 0xfffff, /* src_mask */
964 0xfffff, /* dst_mask */
965 TRUE), /* pcrel_offset */
967 /* Like R_NDS32_HI20, but referring to the GOT table entry for
969 HOWTO2 (R_NDS32_GOT_HI20, /* type */
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 FALSE, /* pc_relative */
975 complain_overflow_dont,/* complain_on_overflow */
976 bfd_elf_generic_reloc, /* special_function */
977 "R_NDS32_GOT_HI20", /* name */
978 FALSE, /* partial_inplace */
979 0x000fffff, /* src_mask */
980 0x000fffff, /* dst_mask */
981 FALSE), /* pcrel_offset */
982 HOWTO2 (R_NDS32_GOT_LO12, /* type */
984 2, /* size (0 = byte, 1 = short, 2 = long) */
986 FALSE, /* pc_relative */
988 complain_overflow_dont,/* complain_on_overflow */
989 bfd_elf_generic_reloc, /* special_function */
990 "R_NDS32_GOT_LO12", /* name */
991 FALSE, /* partial_inplace */
992 0x00000fff, /* src_mask */
993 0x00000fff, /* dst_mask */
994 FALSE), /* pcrel_offset */
996 /* An PC Relative relocation used when setting PIC offset table register.
997 Like R_NDS32_HI20, but referring to the GOT table entry for
999 HOWTO2 (R_NDS32_GOTPC_HI20, /* type */
1000 12, /* rightshift */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE, /* pc_relative */
1005 complain_overflow_dont,/* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
1007 "R_NDS32_GOTPC_HI20", /* name */
1008 FALSE, /* partial_inplace */
1009 0x000fffff, /* src_mask */
1010 0x000fffff, /* dst_mask */
1011 TRUE), /* pcrel_offset */
1012 HOWTO2 (R_NDS32_GOTPC_LO12, /* type */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 FALSE, /* pc_relative */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_NDS32_GOTPC_LO12", /* name */
1021 FALSE, /* partial_inplace */
1022 0x00000fff, /* src_mask */
1023 0x00000fff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1026 HOWTO2 (R_NDS32_GOTOFF_HI20, /* type */
1027 12, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE, /* pc_relative */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_NDS32_GOTOFF_HI20", /* name */
1035 FALSE, /* partial_inplace */
1036 0x000fffff, /* src_mask */
1037 0x000fffff, /* dst_mask */
1038 FALSE), /* pcrel_offset */
1039 HOWTO2 (R_NDS32_GOTOFF_LO12, /* type */
1041 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE, /* pc_relative */
1045 complain_overflow_dont,/* complain_on_overflow */
1046 bfd_elf_generic_reloc, /* special_function */
1047 "R_NDS32_GOTOFF_LO12", /* name */
1048 FALSE, /* partial_inplace */
1049 0x00000fff, /* src_mask */
1050 0x00000fff, /* dst_mask */
1051 FALSE), /* pcrel_offset */
1053 /* Alignment hint for relaxable instruction. This is used with
1054 R_NDS32_LABEL as a pair. Relax this instruction from 4 bytes to 2
1055 in order to make next label aligned on word boundary. */
1056 HOWTO2 (R_NDS32_INSN16, /* type */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE, /* pc_relative */
1062 complain_overflow_dont,/* complain_on_overflow */
1063 nds32_elf_ignore_reloc,/* special_function */
1064 "R_NDS32_INSN16", /* name */
1065 FALSE, /* partial_inplace */
1066 0x00000fff, /* src_mask */
1067 0x00000fff, /* dst_mask */
1068 FALSE), /* pcrel_offset */
1070 /* Alignment hint for label. */
1071 HOWTO2 (R_NDS32_LABEL, /* type */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE, /* pc_relative */
1077 complain_overflow_dont,/* complain_on_overflow */
1078 nds32_elf_ignore_reloc,/* special_function */
1079 "R_NDS32_LABEL", /* name */
1080 FALSE, /* partial_inplace */
1081 0xffffffff, /* src_mask */
1082 0xffffffff, /* dst_mask */
1083 FALSE), /* pcrel_offset */
1085 /* Relax hint for unconditional call sequence */
1086 HOWTO2 (R_NDS32_LONGCALL1, /* type */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1090 FALSE, /* pc_relative */
1092 complain_overflow_dont,/* complain_on_overflow */
1093 nds32_elf_ignore_reloc,/* special_function */
1094 "R_NDS32_LONGCALL1", /* name */
1095 FALSE, /* partial_inplace */
1096 0xffffffff, /* src_mask */
1097 0xffffffff, /* dst_mask */
1098 FALSE), /* pcrel_offset */
1100 /* Relax hint for conditional call sequence. */
1101 HOWTO2 (R_NDS32_LONGCALL2, /* type */
1103 2, /* size (0 = byte, 1 = short, 2 = long) */
1105 FALSE, /* pc_relative */
1107 complain_overflow_dont,/* complain_on_overflow */
1108 nds32_elf_ignore_reloc,/* special_function */
1109 "R_NDS32_LONGCALL2", /* name */
1110 FALSE, /* partial_inplace */
1111 0xffffffff, /* src_mask */
1112 0xffffffff, /* dst_mask */
1113 FALSE), /* pcrel_offset */
1115 /* Relax hint for conditional call sequence. */
1116 HOWTO2 (R_NDS32_LONGCALL3, /* type */
1118 2, /* size (0 = byte, 1 = short, 2 = long) */
1120 FALSE, /* pc_relative */
1122 complain_overflow_dont,/* complain_on_overflow */
1123 nds32_elf_ignore_reloc,/* special_function */
1124 "R_NDS32_LONGCALL3", /* name */
1125 FALSE, /* partial_inplace */
1126 0xffffffff, /* src_mask */
1127 0xffffffff, /* dst_mask */
1128 FALSE), /* pcrel_offset */
1130 /* Relax hint for unconditional branch sequence. */
1131 HOWTO2 (R_NDS32_LONGJUMP1, /* type */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 FALSE, /* pc_relative */
1137 complain_overflow_dont,/* complain_on_overflow */
1138 nds32_elf_ignore_reloc,/* special_function */
1139 "R_NDS32_LONGJUMP1", /* name */
1140 FALSE, /* partial_inplace */
1141 0xffffffff, /* src_mask */
1142 0xffffffff, /* dst_mask */
1143 FALSE), /* pcrel_offset */
1145 /* Relax hint for conditional branch sequence. */
1146 HOWTO2 (R_NDS32_LONGJUMP2, /* type */
1148 2, /* size (0 = byte, 1 = short, 2 = long) */
1150 FALSE, /* pc_relative */
1152 complain_overflow_dont,/* complain_on_overflow */
1153 nds32_elf_ignore_reloc,/* special_function */
1154 "R_NDS32_LONGJUMP2", /* name */
1155 FALSE, /* partial_inplace */
1156 0xffffffff, /* src_mask */
1157 0xffffffff, /* dst_mask */
1158 FALSE), /* pcrel_offset */
1160 /* Relax hint for conditional branch sequence. */
1161 HOWTO2 (R_NDS32_LONGJUMP3, /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE, /* pc_relative */
1167 complain_overflow_dont,/* complain_on_overflow */
1168 nds32_elf_ignore_reloc,/* special_function */
1169 "R_NDS32_LONGJUMP3", /* name */
1170 FALSE, /* partial_inplace */
1171 0xffffffff, /* src_mask */
1172 0xffffffff, /* dst_mask */
1173 FALSE), /* pcrel_offset */
1175 /* Relax hint for load/store sequence. */
1176 HOWTO2 (R_NDS32_LOADSTORE, /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE, /* pc_relative */
1182 complain_overflow_dont,/* complain_on_overflow */
1183 nds32_elf_ignore_reloc,/* special_function */
1184 "R_NDS32_LOADSTORE", /* name */
1185 FALSE, /* partial_inplace */
1186 0xffffffff, /* src_mask */
1187 0xffffffff, /* dst_mask */
1188 FALSE), /* pcrel_offset */
1190 /* Relax hint for load/store sequence. */
1191 HOWTO2 (R_NDS32_9_FIXED_RELA, /* type */
1193 1, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE, /* pc_relative */
1197 complain_overflow_dont,/* complain_on_overflow */
1198 nds32_elf_ignore_reloc,/* special_function */
1199 "R_NDS32_9_FIXED_RELA",/* name */
1200 FALSE, /* partial_inplace */
1201 0x000000ff, /* src_mask */
1202 0x000000ff, /* dst_mask */
1203 FALSE), /* pcrel_offset */
1205 /* Relax hint for load/store sequence. */
1206 HOWTO2 (R_NDS32_15_FIXED_RELA,/* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE, /* pc_relative */
1212 complain_overflow_dont,/* complain_on_overflow */
1213 nds32_elf_ignore_reloc,/* special_function */
1214 "R_NDS32_15_FIXED_RELA",/* name */
1215 FALSE, /* partial_inplace */
1216 0x00003fff, /* src_mask */
1217 0x00003fff, /* dst_mask */
1218 FALSE), /* pcrel_offset */
1220 /* Relax hint for load/store sequence. */
1221 HOWTO2 (R_NDS32_17_FIXED_RELA,/* type */
1223 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 FALSE, /* pc_relative */
1227 complain_overflow_dont,/* complain_on_overflow */
1228 nds32_elf_ignore_reloc,/* special_function */
1229 "R_NDS32_17_FIXED_RELA",/* name */
1230 FALSE, /* partial_inplace */
1231 0x0000ffff, /* src_mask */
1232 0x0000ffff, /* dst_mask */
1233 FALSE), /* pcrel_offset */
1235 /* Relax hint for load/store sequence. */
1236 HOWTO2 (R_NDS32_25_FIXED_RELA,/* type */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1240 FALSE, /* pc_relative */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 nds32_elf_ignore_reloc,/* special_function */
1244 "R_NDS32_25_FIXED_RELA",/* name */
1245 FALSE, /* partial_inplace */
1246 0x00ffffff, /* src_mask */
1247 0x00ffffff, /* dst_mask */
1248 FALSE), /* pcrel_offset */
1250 /* High 20 bits of PLT symbol offset relative to PC. */
1251 HOWTO2 (R_NDS32_PLTREL_HI20, /* type */
1252 12, /* rightshift */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1255 FALSE, /* pc_relative */
1257 complain_overflow_dont,/* complain_on_overflow */
1258 bfd_elf_generic_reloc, /* special_function */
1259 "R_NDS32_PLTREL_HI20", /* name */
1260 FALSE, /* partial_inplace */
1261 0x000fffff, /* src_mask */
1262 0x000fffff, /* dst_mask */
1263 FALSE), /* pcrel_offset */
1265 /* Low 12 bits of PLT symbol offset relative to PC. */
1266 HOWTO2 (R_NDS32_PLTREL_LO12, /* type */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE, /* pc_relative */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_NDS32_PLTREL_LO12", /* name */
1275 FALSE, /* partial_inplace */
1276 0x00000fff, /* src_mask */
1277 0x00000fff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1280 /* High 20 bits of PLT symbol offset relative to GOT (GP). */
1281 HOWTO2 (R_NDS32_PLT_GOTREL_HI20, /* type */
1282 12, /* rightshift */
1283 2, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE, /* pc_relative */
1287 complain_overflow_dont,/* complain_on_overflow */
1288 bfd_elf_generic_reloc, /* special_function */
1289 "R_NDS32_PLT_GOTREL_HI20",/* name */
1290 FALSE, /* partial_inplace */
1291 0x000fffff, /* src_mask */
1292 0x000fffff, /* dst_mask */
1293 FALSE), /* pcrel_offset */
1295 /* Low 12 bits of PLT symbol offset relative to GOT (GP). */
1296 HOWTO2 (R_NDS32_PLT_GOTREL_LO12,/* type */
1298 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 FALSE, /* pc_relative */
1302 complain_overflow_dont,/* complain_on_overflow */
1303 bfd_elf_generic_reloc, /* special_function */
1304 "R_NDS32_PLT_GOTREL_LO12",/* name */
1305 FALSE, /* partial_inplace */
1306 0x00000fff, /* src_mask */
1307 0x00000fff, /* dst_mask */
1308 FALSE), /* pcrel_offset */
1310 /* Small data area 12 bits offset. */
1311 HOWTO2 (R_NDS32_SDA12S2_DP_RELA,/* type */
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE, /* pc_relative */
1317 complain_overflow_signed,/* complain_on_overflow */
1318 bfd_elf_generic_reloc, /* special_function */
1319 "R_NDS32_SDA12S2_DP_RELA",/* name */
1320 FALSE, /* partial_inplace */
1321 0x00000fff, /* src_mask */
1322 0x00000fff, /* dst_mask */
1323 FALSE), /* pcrel_offset */
1325 /* Small data area 12 bits offset. */
1326 HOWTO2 (R_NDS32_SDA12S2_SP_RELA,/* type */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE, /* pc_relative */
1332 complain_overflow_signed,/* complain_on_overflow */
1333 bfd_elf_generic_reloc, /* special_function */
1334 "R_NDS32_SDA12S2_SP_RELA",/* name */
1335 FALSE, /* partial_inplace */
1336 0x00000fff, /* src_mask */
1337 0x00000fff, /* dst_mask */
1338 FALSE), /* pcrel_offset */
1339 /* Lower 12 bits of address. */
1341 HOWTO2 (R_NDS32_LO12S2_DP_RELA, /* type */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE, /* pc_relative */
1347 complain_overflow_dont,/* complain_on_overflow */
1348 bfd_elf_generic_reloc, /* special_function */
1349 "R_NDS32_LO12S2_DP_RELA",/* name */
1350 FALSE, /* partial_inplace */
1351 0x000003ff, /* src_mask */
1352 0x000003ff, /* dst_mask */
1353 FALSE), /* pcrel_offset */
1355 /* Lower 12 bits of address. */
1356 HOWTO2 (R_NDS32_LO12S2_SP_RELA,/* type */
1358 2, /* size (0 = byte, 1 = short, 2 = long) */
1360 FALSE, /* pc_relative */
1362 complain_overflow_dont,/* complain_on_overflow */
1363 bfd_elf_generic_reloc, /* special_function */
1364 "R_NDS32_LO12S2_SP_RELA",/* name */
1365 FALSE, /* partial_inplace */
1366 0x000003ff, /* src_mask */
1367 0x000003ff, /* dst_mask */
1368 FALSE), /* pcrel_offset */
1369 /* Lower 12 bits of address. Special identity for or case. */
1370 HOWTO2 (R_NDS32_LO12S0_ORI_RELA,/* type */
1372 2, /* size (0 = byte, 1 = short, 2 = long) */
1374 FALSE, /* pc_relative */
1376 complain_overflow_dont,/* complain_on_overflow */
1377 bfd_elf_generic_reloc, /* special_function */
1378 "R_NDS32_LO12S0_ORI_RELA",/* name */
1379 FALSE, /* partial_inplace */
1380 0x00000fff, /* src_mask */
1381 0x00000fff, /* dst_mask */
1382 FALSE), /* pcrel_offset */
1383 /* Small data area 19 bits offset. */
1384 HOWTO2 (R_NDS32_SDA16S3_RELA, /* type */
1386 2, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE, /* pc_relative */
1390 complain_overflow_signed,/* complain_on_overflow */
1391 bfd_elf_generic_reloc, /* special_function */
1392 "R_NDS32_SDA16S3_RELA",/* name */
1393 FALSE, /* partial_inplace */
1394 0x0000ffff, /* src_mask */
1395 0x0000ffff, /* dst_mask */
1396 FALSE), /* pcrel_offset */
1398 /* Small data area 15 bits offset. */
1399 HOWTO2 (R_NDS32_SDA17S2_RELA, /* type */
1401 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 FALSE, /* pc_relative */
1405 complain_overflow_signed,/* complain_on_overflow */
1406 bfd_elf_generic_reloc, /* special_function */
1407 "R_NDS32_SDA17S2_RELA",/* name */
1408 FALSE, /* partial_inplace */
1409 0x0001ffff, /* src_mask */
1410 0x0001ffff, /* dst_mask */
1411 FALSE), /* pcrel_offset */
1413 HOWTO2 (R_NDS32_SDA18S1_RELA, /* type */
1415 2, /* size (0 = byte, 1 = short, 2 = long) */
1417 FALSE, /* pc_relative */
1419 complain_overflow_signed,/* complain_on_overflow */
1420 bfd_elf_generic_reloc, /* special_function */
1421 "R_NDS32_SDA18S1_RELA",/* name */
1422 FALSE, /* partial_inplace */
1423 0x0003ffff, /* src_mask */
1424 0x0003ffff, /* dst_mask */
1425 FALSE), /* pcrel_offset */
1427 HOWTO2 (R_NDS32_SDA19S0_RELA, /* type */
1429 2, /* size (0 = byte, 1 = short, 2 = long) */
1431 FALSE, /* pc_relative */
1433 complain_overflow_signed,/* complain_on_overflow */
1434 bfd_elf_generic_reloc, /* special_function */
1435 "R_NDS32_SDA19S0_RELA",/* name */
1436 FALSE, /* partial_inplace */
1437 0x0007ffff, /* src_mask */
1438 0x0007ffff, /* dst_mask */
1439 FALSE), /* pcrel_offset */
1440 HOWTO2 (R_NDS32_DWARF2_OP1_RELA,/* type */
1442 0, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE, /* pc_relative */
1446 complain_overflow_dont,/* complain_on_overflow */
1447 nds32_elf_ignore_reloc,/* special_function */
1448 "R_NDS32_DWARF2_OP1_RELA",/* name */
1449 FALSE, /* partial_inplace */
1450 0xff, /* src_mask */
1451 0xff, /* dst_mask */
1452 FALSE), /* pcrel_offset */
1453 HOWTO2 (R_NDS32_DWARF2_OP2_RELA,/* type */
1455 1, /* size (0 = byte, 1 = short, 2 = long) */
1457 FALSE, /* pc_relative */
1459 complain_overflow_dont,/* complain_on_overflow */
1460 nds32_elf_ignore_reloc,/* special_function */
1461 "R_NDS32_DWARF2_OP2_RELA",/* name */
1462 FALSE, /* partial_inplace */
1463 0xffff, /* src_mask */
1464 0xffff, /* dst_mask */
1465 FALSE), /* pcrel_offset */
1466 HOWTO2 (R_NDS32_DWARF2_LEB_RELA,/* type */
1468 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 FALSE, /* pc_relative */
1472 complain_overflow_dont,/* complain_on_overflow */
1473 nds32_elf_ignore_reloc,/* special_function */
1474 "R_NDS32_DWARF2_LEB_RELA",/* name */
1475 FALSE, /* partial_inplace */
1476 0xffffffff, /* src_mask */
1477 0xffffffff, /* dst_mask */
1478 FALSE), /* pcrel_offset */
1479 HOWTO2 (R_NDS32_UPDATE_TA_RELA,/* type */
1481 1, /* size (0 = byte, 1 = short, 2 = long) */
1483 FALSE, /* pc_relative */
1485 complain_overflow_dont,/* complain_on_overflow */
1486 nds32_elf_ignore_reloc,/* special_function */
1487 "R_NDS32_UPDATE_TA_RELA",/* name */
1488 FALSE, /* partial_inplace */
1489 0xffff, /* src_mask */
1490 0xffff, /* dst_mask */
1491 FALSE), /* pcrel_offset */
1492 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
1493 entry for the symbol. */
1494 HOWTO2 (R_NDS32_9_PLTREL, /* type */
1496 1, /* size (0 = byte, 1 = short, 2 = long) */
1498 TRUE, /* pc_relative */
1500 complain_overflow_signed,/* complain_on_overflow */
1501 bfd_elf_generic_reloc, /* special_function */
1502 "R_NDS32_9_PLTREL", /* name */
1503 FALSE, /* partial_inplace */
1504 0xff, /* src_mask */
1505 0xff, /* dst_mask */
1506 TRUE), /* pcrel_offset */
1507 /* Low 20 bits of PLT symbol offset relative to GOT (GP). */
1508 HOWTO2 (R_NDS32_PLT_GOTREL_LO20,/* type */
1510 2, /* size (0 = byte, 1 = short, 2 = long) */
1512 FALSE, /* pc_relative */
1514 complain_overflow_dont,/* complain_on_overflow */
1515 bfd_elf_generic_reloc, /* special_function */
1516 "R_NDS32_PLT_GOTREL_LO20",/* name */
1517 FALSE, /* partial_inplace */
1518 0x000fffff, /* src_mask */
1519 0x000fffff, /* dst_mask */
1520 FALSE), /* pcrel_offset */
1521 /* low 15 bits of PLT symbol offset relative to GOT (GP) */
1522 HOWTO2 (R_NDS32_PLT_GOTREL_LO15,/* type */
1524 2, /* size (0 = byte, 1 = short, 2 = long) */
1526 FALSE, /* pc_relative */
1528 complain_overflow_dont,/* complain_on_overflow */
1529 bfd_elf_generic_reloc, /* special_function */
1530 "R_NDS32_PLT_GOTREL_LO15",/* name */
1531 FALSE, /* partial_inplace */
1532 0x00007fff, /* src_mask */
1533 0x00007fff, /* dst_mask */
1534 FALSE), /* pcrel_offset */
1535 /* Low 19 bits of PLT symbol offset relative to GOT (GP). */
1536 HOWTO2 (R_NDS32_PLT_GOTREL_LO19,/* type */
1538 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 FALSE, /* pc_relative */
1542 complain_overflow_dont,/* complain_on_overflow */
1543 bfd_elf_generic_reloc, /* special_function */
1544 "R_NDS32_PLT_GOTREL_LO19",/* name */
1545 FALSE, /* partial_inplace */
1546 0x0007ffff, /* src_mask */
1547 0x0007ffff, /* dst_mask */
1548 FALSE), /* pcrel_offset */
1549 HOWTO2 (R_NDS32_GOT_LO15, /* type */
1551 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 FALSE, /* pc_relative */
1555 complain_overflow_dont,/* complain_on_overflow */
1556 bfd_elf_generic_reloc, /* special_function */
1557 "R_NDS32_GOT_LO15", /* name */
1558 FALSE, /* partial_inplace */
1559 0x00007fff, /* src_mask */
1560 0x00007fff, /* dst_mask */
1561 FALSE), /* pcrel_offset */
1562 HOWTO2 (R_NDS32_GOT_LO19, /* type */
1564 2, /* size (0 = byte, 1 = short, 2 = long) */
1566 FALSE, /* pc_relative */
1568 complain_overflow_dont,/* complain_on_overflow */
1569 bfd_elf_generic_reloc, /* special_function */
1570 "R_NDS32_GOT_LO19", /* name */
1571 FALSE, /* partial_inplace */
1572 0x0007ffff, /* src_mask */
1573 0x0007ffff, /* dst_mask */
1574 FALSE), /* pcrel_offset */
1575 HOWTO2 (R_NDS32_GOTOFF_LO15, /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE, /* pc_relative */
1581 complain_overflow_dont,/* complain_on_overflow */
1582 bfd_elf_generic_reloc, /* special_function */
1583 "R_NDS32_GOTOFF_LO15", /* name */
1584 FALSE, /* partial_inplace */
1585 0x00007fff, /* src_mask */
1586 0x00007fff, /* dst_mask */
1587 FALSE), /* pcrel_offset */
1588 HOWTO2 (R_NDS32_GOTOFF_LO19, /* type */
1590 2, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE, /* pc_relative */
1594 complain_overflow_dont,/* complain_on_overflow */
1595 bfd_elf_generic_reloc, /* special_function */
1596 "R_NDS32_GOTOFF_LO19", /* name */
1597 FALSE, /* partial_inplace */
1598 0x0007ffff, /* src_mask */
1599 0x0007ffff, /* dst_mask */
1600 FALSE), /* pcrel_offset */
1601 /* GOT 15 bits offset. */
1602 HOWTO2 (R_NDS32_GOT15S2_RELA, /* type */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE, /* pc_relative */
1608 complain_overflow_signed,/* complain_on_overflow */
1609 bfd_elf_generic_reloc, /* special_function */
1610 "R_NDS32_GOT15S2_RELA",/* name */
1611 FALSE, /* partial_inplace */
1612 0x00007fff, /* src_mask */
1613 0x00007fff, /* dst_mask */
1614 FALSE), /* pcrel_offset */
1615 /* GOT 17 bits offset. */
1616 HOWTO2 (R_NDS32_GOT17S2_RELA, /* type */
1618 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE, /* pc_relative */
1622 complain_overflow_signed,/* complain_on_overflow */
1623 bfd_elf_generic_reloc, /* special_function */
1624 "R_NDS32_GOT17S2_RELA",/* name */
1625 FALSE, /* partial_inplace */
1626 0x0001ffff, /* src_mask */
1627 0x0001ffff, /* dst_mask */
1628 FALSE), /* pcrel_offset */
1629 /* A 5 bit address. */
1630 HOWTO2 (R_NDS32_5_RELA, /* type */
1632 1, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE, /* pc_relative */
1636 complain_overflow_signed,/* complain_on_overflow */
1637 bfd_elf_generic_reloc, /* special_function */
1638 "R_NDS32_5_RELA", /* name */
1639 FALSE, /* partial_inplace */
1640 0x1f, /* src_mask */
1641 0x1f, /* dst_mask */
1642 FALSE), /* pcrel_offset */
1643 HOWTO2 (R_NDS32_10_UPCREL_RELA,/* type */
1645 1, /* size (0 = byte, 1 = short, 2 = long) */
1647 TRUE, /* pc_relative */
1649 complain_overflow_unsigned,/* complain_on_overflow */
1650 bfd_elf_generic_reloc, /* special_function */
1651 "R_NDS32_10_UPCREL_RELA",/* name */
1652 FALSE, /* partial_inplace */
1653 0x1ff, /* src_mask */
1654 0x1ff, /* dst_mask */
1655 TRUE), /* pcrel_offset */
1656 HOWTO2 (R_NDS32_SDA_FP7U2_RELA,/* type */
1658 1, /* size (0 = byte, 1 = short, 2 = long) */
1660 FALSE, /* pc_relative */
1662 complain_overflow_unsigned,/* complain_on_overflow */
1663 bfd_elf_generic_reloc, /* special_function */
1664 "R_NDS32_SDA_FP7U2_RELA",/* name */
1665 FALSE, /* partial_inplace */
1666 0x0000007f, /* src_mask */
1667 0x0000007f, /* dst_mask */
1668 FALSE), /* pcrel_offset */
1669 HOWTO2 (R_NDS32_WORD_9_PCREL_RELA,/* type */
1671 2, /* size (0 = byte, 1 = short, 2 = long) */
1673 TRUE, /* pc_relative */
1675 complain_overflow_signed,/* complain_on_overflow */
1676 bfd_elf_generic_reloc, /* special_function */
1677 "R_NDS32_WORD_9_PCREL_RELA",/* name */
1678 FALSE, /* partial_inplace */
1679 0xff, /* src_mask */
1680 0xff, /* dst_mask */
1681 TRUE), /* pcrel_offset */
1682 HOWTO2 (R_NDS32_25_ABS_RELA, /* type */
1684 2, /* size (0 = byte, 1 = short, 2 = long) */
1686 FALSE, /* pc_relative */
1688 complain_overflow_dont,/* complain_on_overflow */
1689 bfd_elf_generic_reloc, /* special_function */
1690 "R_NDS32_25_ABS_RELA", /* name */
1691 FALSE, /* partial_inplace */
1692 0xffffff, /* src_mask */
1693 0xffffff, /* dst_mask */
1694 FALSE), /* pcrel_offset */
1696 /* A relative 17 bit relocation for ifc, right shifted by 1. */
1697 HOWTO2 (R_NDS32_17IFC_PCREL_RELA,/* type */
1699 2, /* size (0 = byte, 1 = short, 2 = long) */
1701 TRUE, /* pc_relative */
1703 complain_overflow_signed,/* complain_on_overflow */
1704 bfd_elf_generic_reloc, /* special_function */
1705 "R_NDS32_17IFC_PCREL_RELA",/* name */
1706 FALSE, /* partial_inplace */
1707 0xffff, /* src_mask */
1708 0xffff, /* dst_mask */
1709 TRUE), /* pcrel_offset */
1711 /* A relative unsigned 10 bit relocation for ifc, right shifted by 1. */
1712 HOWTO2 (R_NDS32_10IFCU_PCREL_RELA,/* type */
1714 1, /* size (0 = byte, 1 = short, 2 = long) */
1716 TRUE, /* pc_relative */
1718 complain_overflow_unsigned,/* complain_on_overflow */
1719 bfd_elf_generic_reloc, /* special_function */
1720 "R_NDS32_10IFCU_PCREL_RELA",/* name */
1721 FALSE, /* partial_inplace */
1722 0x1ff, /* src_mask */
1723 0x1ff, /* dst_mask */
1724 TRUE), /* pcrel_offset */
1726 /* Like R_NDS32_HI20, but referring to the TLS LE entry for the symbol. */
1727 HOWTO2 (R_NDS32_TLS_LE_HI20, /* type */
1728 12, /* rightshift */
1729 2, /* size (0 = byte, 1 = short, 2 = long) */
1731 FALSE, /* pc_relative */
1733 complain_overflow_dont,/* complain_on_overflow */
1734 bfd_elf_generic_reloc, /* special_function */
1735 "R_NDS32_TLS_LE_HI20", /* name */
1736 FALSE, /* partial_inplace */
1737 0x000fffff, /* src_mask */
1738 0x000fffff, /* dst_mask */
1739 FALSE), /* pcrel_offset */
1741 HOWTO2 (R_NDS32_TLS_LE_LO12, /* type */
1743 2, /* size (0 = byte, 1 = short, 2 = long) */
1745 FALSE, /* pc_relative */
1747 complain_overflow_dont,/* complain_on_overflow */
1748 bfd_elf_generic_reloc, /* special_function */
1749 "R_NDS32_TLS_LE_LO12", /* name */
1750 FALSE, /* partial_inplace */
1751 0x00000fff, /* src_mask */
1752 0x00000fff, /* dst_mask */
1753 FALSE), /* pcrel_offset */
1755 /* Like R_NDS32_HI20, but referring to the TLS IE entry for the symbol. */
1756 HOWTO2 (R_NDS32_TLS_IE_HI20, /* type */
1757 12, /* rightshift */
1758 2, /* size (0 = byte, 1 = short, 2 = long) */
1760 FALSE, /* pc_relative */
1762 complain_overflow_dont,/* complain_on_overflow */
1763 bfd_elf_generic_reloc, /* special_function */
1764 "R_NDS32_TLS_IE_HI20", /* name */
1765 FALSE, /* partial_inplace */
1766 0x000fffff, /* src_mask */
1767 0x000fffff, /* dst_mask */
1768 FALSE), /* pcrel_offset */
1770 HOWTO2 (R_NDS32_TLS_IE_LO12S2,/* type */
1772 2, /* size (0 = byte, 1 = short, 2 = long) */
1774 FALSE, /* pc_relative */
1776 complain_overflow_dont,/* complain_on_overflow */
1777 bfd_elf_generic_reloc, /* special_function */
1778 "R_NDS32_TLS_IE_LO12S2",/* name */
1779 FALSE, /* partial_inplace */
1780 0x000003ff, /* src_mask */
1781 0x000003ff, /* dst_mask */
1782 FALSE), /* pcrel_offset */
1784 /* TLS LE TP offset relocation */
1785 HOWTO2 (R_NDS32_TLS_TPOFF, /* type */
1787 2, /* size (0 = byte, 1 = short, 2 = long) */
1789 FALSE, /* pc_relative */
1791 complain_overflow_bitfield,/* complain_on_overflow */
1792 bfd_elf_generic_reloc, /* special_function */
1793 "R_NDS32_TLS_TPOFF", /* name */
1794 FALSE, /* partial_inplace */
1795 0xffffffff, /* src_mask */
1796 0xffffffff, /* dst_mask */
1797 FALSE), /* pcrel_offset */
1799 /* A 20 bit address. */
1800 HOWTO2 (R_NDS32_TLS_LE_20, /* type */
1802 2, /* size (0 = byte, 1 = short, 2 = long) */
1804 FALSE, /* pc_relative */
1806 complain_overflow_signed,/* complain_on_overflow */
1807 bfd_elf_generic_reloc, /* special_function */
1808 "R_NDS32_TLS_LE_20", /* name */
1809 FALSE, /* partial_inplace */
1810 0xfffff, /* src_mask */
1811 0xfffff, /* dst_mask */
1812 FALSE), /* pcrel_offset */
1814 HOWTO2 (R_NDS32_TLS_LE_15S0, /* type */
1816 2, /* size (0 = byte, 1 = short, 2 = long) */
1818 FALSE, /* pc_relative */
1820 complain_overflow_signed,/* complain_on_overflow */
1821 bfd_elf_generic_reloc, /* special_function */
1822 "R_NDS32_TLS_LE_15S0", /* name */
1823 FALSE, /* partial_inplace */
1824 0x7fff, /* src_mask */
1825 0x7fff, /* dst_mask */
1826 FALSE), /* pcrel_offset */
1827 HOWTO2 (R_NDS32_TLS_LE_15S1, /* type */
1829 2, /* size (0 = byte, 1 = short, 2 = long) */
1831 FALSE, /* pc_relative */
1833 complain_overflow_signed,/* complain_on_overflow */
1834 bfd_elf_generic_reloc, /* special_function */
1835 "R_NDS32_TLS_LE_15S1", /* name */
1836 FALSE, /* partial_inplace */
1837 0x7fff, /* src_mask */
1838 0x7fff, /* dst_mask */
1839 FALSE), /* pcrel_offset */
1840 HOWTO2 (R_NDS32_TLS_LE_15S2, /* type */
1842 2, /* size (0 = byte, 1 = short, 2 = long) */
1844 FALSE, /* pc_relative */
1846 complain_overflow_signed,/* complain_on_overflow */
1847 bfd_elf_generic_reloc, /* special_function */
1848 "R_NDS32_TLS_LE_15S2", /* name */
1849 FALSE, /* partial_inplace */
1850 0x7fff, /* src_mask */
1851 0x7fff, /* dst_mask */
1852 FALSE), /* pcrel_offset */
1854 /* Relax hint for unconditional call sequence */
1855 HOWTO2 (R_NDS32_LONGCALL4, /* type */
1857 2, /* size (0 = byte, 1 = short, 2 = long) */
1859 FALSE, /* pc_relative */
1861 complain_overflow_dont,/* complain_on_overflow */
1862 nds32_elf_ignore_reloc,/* special_function */
1863 "R_NDS32_LONGCALL4", /* name */
1864 FALSE, /* partial_inplace */
1865 0xffffffff, /* src_mask */
1866 0xffffffff, /* dst_mask */
1867 FALSE), /* pcrel_offset */
1869 /* Relax hint for conditional call sequence. */
1870 HOWTO2 (R_NDS32_LONGCALL5, /* type */
1872 2, /* size (0 = byte, 1 = short, 2 = long) */
1874 FALSE, /* pc_relative */
1876 complain_overflow_dont,/* complain_on_overflow */
1877 nds32_elf_ignore_reloc,/* special_function */
1878 "R_NDS32_LONGCALL5", /* name */
1879 FALSE, /* partial_inplace */
1880 0xffffffff, /* src_mask */
1881 0xffffffff, /* dst_mask */
1882 FALSE), /* pcrel_offset */
1884 /* Relax hint for conditional call sequence. */
1885 HOWTO2 (R_NDS32_LONGCALL6, /* type */
1887 2, /* size (0 = byte, 1 = short, 2 = long) */
1889 FALSE, /* pc_relative */
1891 complain_overflow_dont,/* complain_on_overflow */
1892 nds32_elf_ignore_reloc,/* special_function */
1893 "R_NDS32_LONGCALL6", /* name */
1894 FALSE, /* partial_inplace */
1895 0xffffffff, /* src_mask */
1896 0xffffffff, /* dst_mask */
1897 FALSE), /* pcrel_offset */
1899 /* Relax hint for unconditional branch sequence. */
1900 HOWTO2 (R_NDS32_LONGJUMP4, /* type */
1902 2, /* size (0 = byte, 1 = short, 2 = long) */
1904 FALSE, /* pc_relative */
1906 complain_overflow_dont,/* complain_on_overflow */
1907 nds32_elf_ignore_reloc,/* special_function */
1908 "R_NDS32_LONGJUMP4", /* name */
1909 FALSE, /* partial_inplace */
1910 0xffffffff, /* src_mask */
1911 0xffffffff, /* dst_mask */
1912 FALSE), /* pcrel_offset */
1914 /* Relax hint for conditional branch sequence. */
1915 HOWTO2 (R_NDS32_LONGJUMP5, /* type */
1917 2, /* size (0 = byte, 1 = short, 2 = long) */
1919 FALSE, /* pc_relative */
1921 complain_overflow_dont,/* complain_on_overflow */
1922 nds32_elf_ignore_reloc,/* special_function */
1923 "R_NDS32_LONGJUMP5", /* name */
1924 FALSE, /* partial_inplace */
1925 0xffffffff, /* src_mask */
1926 0xffffffff, /* dst_mask */
1927 FALSE), /* pcrel_offset */
1929 /* Relax hint for conditional branch sequence. */
1930 HOWTO2 (R_NDS32_LONGJUMP6, /* type */
1932 2, /* size (0 = byte, 1 = short, 2 = long) */
1934 FALSE, /* pc_relative */
1936 complain_overflow_dont,/* complain_on_overflow */
1937 nds32_elf_ignore_reloc,/* special_function */
1938 "R_NDS32_LONGJUMP6", /* name */
1939 FALSE, /* partial_inplace */
1940 0xffffffff, /* src_mask */
1941 0xffffffff, /* dst_mask */
1942 FALSE), /* pcrel_offset */
1944 /* Relax hint for conditional branch sequence. */
1945 HOWTO2 (R_NDS32_LONGJUMP7, /* type */
1947 2, /* size (0 = byte, 1 = short, 2 = long) */
1949 FALSE, /* pc_relative */
1951 complain_overflow_dont,/* complain_on_overflow */
1952 nds32_elf_ignore_reloc,/* special_function */
1953 "R_NDS32_LONGJUMP7", /* name */
1954 FALSE, /* partial_inplace */
1955 0xffffffff, /* src_mask */
1956 0xffffffff, /* dst_mask */
1957 FALSE), /* pcrel_offset */
1959 HOWTO2 (R_NDS32_TLS_IE_LO12, /* type */
1961 2, /* size (0 = byte, 1 = short, 2 = long) */
1963 FALSE, /* pc_relative */
1965 complain_overflow_dont,/* complain_on_overflow */
1966 bfd_elf_generic_reloc, /* special_function */
1967 "R_NDS32_TLS_IE_LO12", /* name */
1968 FALSE, /* partial_inplace */
1969 0x00000fff, /* src_mask */
1970 0x00000fff, /* dst_mask */
1971 FALSE), /* pcrel_offset */
1973 /* Like R_NDS32_HI20, but referring to the TLS IE (PIE)
1974 entry for the symbol. */
1975 HOWTO2 (R_NDS32_TLS_IEGP_HI20,/* type */
1976 12, /* rightshift */
1977 2, /* size (0 = byte, 1 = short, 2 = long) */
1979 FALSE, /* pc_relative */
1981 complain_overflow_dont,/* complain_on_overflow */
1982 bfd_elf_generic_reloc, /* special_function */
1983 "R_NDS32_TLS_IEGP_HI20",/* name */
1984 FALSE, /* partial_inplace */
1985 0x000fffff, /* src_mask */
1986 0x000fffff, /* dst_mask */
1987 FALSE), /* pcrel_offset */
1989 HOWTO2 (R_NDS32_TLS_IEGP_LO12,/* type */
1991 2, /* size (0 = byte, 1 = short, 2 = long) */
1993 FALSE, /* pc_relative */
1995 complain_overflow_dont,/* complain_on_overflow */
1996 bfd_elf_generic_reloc, /* special_function */
1997 "R_NDS32_TLS_IEGP_LO12",/* name */
1998 FALSE, /* partial_inplace */
1999 0x00000fff, /* src_mask */
2000 0x00000fff, /* dst_mask */
2001 FALSE), /* pcrel_offset */
2003 HOWTO2 (R_NDS32_TLS_IEGP_LO12S2,/* type */
2005 2, /* size (0 = byte, 1 = short, 2 = long) */
2007 FALSE, /* pc_relative */
2009 complain_overflow_dont,/* complain_on_overflow */
2010 bfd_elf_generic_reloc, /* special_function */
2011 "R_NDS32_TLS_IEGP_LO12S2",/* name */
2012 FALSE, /* partial_inplace */
2013 0x000003ff, /* src_mask */
2014 0x000003ff, /* dst_mask */
2015 FALSE), /* pcrel_offset */
2017 /* TLS description relocation */
2018 HOWTO2 (R_NDS32_TLS_DESC, /* type */
2019 12, /* rightshift */
2020 2, /* size (0 = byte, 1 = short, 2 = long) */
2022 FALSE, /* pc_relative */
2024 complain_overflow_dont,/* complain_on_overflow */
2025 nds32_elf_hi20_reloc, /* special_function */
2026 "R_NDS32_TLS_DESC_HI20",/* name */
2027 FALSE, /* partial_inplace */
2028 0x000fffff, /* src_mask */
2029 0x000fffff, /* dst_mask */
2030 FALSE), /* pcrel_offset */
2032 /* TLS GD/LD description offset high part. */
2033 HOWTO2 (R_NDS32_TLS_DESC_HI20,/* type */
2034 12, /* rightshift */
2035 2, /* size (0 = byte, 1 = short, 2 = long) */
2037 FALSE, /* pc_relative */
2039 complain_overflow_dont,/* complain_on_overflow */
2040 nds32_elf_hi20_reloc, /* special_function */
2041 "R_NDS32_TLS_DESC_HI20",/* name */
2042 FALSE, /* partial_inplace */
2043 0x000fffff, /* src_mask */
2044 0x000fffff, /* dst_mask */
2045 FALSE), /* pcrel_offset */
2047 /* TLS GD/LD description offset low part. */
2048 HOWTO2 (R_NDS32_TLS_DESC_LO12,/* type */
2050 2, /* size (0 = byte, 1 = short, 2 = long) */
2052 FALSE, /* pc_relative */
2054 complain_overflow_dont,/* complain_on_overflow */
2055 nds32_elf_lo12_reloc, /* special_function */
2056 "R_NDS32_TLS_DESC_LO12",/* name */
2057 FALSE, /* partial_inplace */
2058 0x00000fff, /* src_mask */
2059 0x00000fff, /* dst_mask */
2060 FALSE), /* pcrel_offset */
2062 /* TLS GD/LD description offset set (movi). */
2063 HOWTO2 (R_NDS32_TLS_DESC_20, /* type */
2065 2, /* size (0 = byte, 1 = short, 2 = long) */
2067 FALSE, /* pc_relative */
2069 complain_overflow_signed,/* complain_on_overflow */
2070 bfd_elf_generic_reloc, /* special_function */
2071 "R_NDS32_TLS_DESC_20", /* name */
2072 FALSE, /* partial_inplace */
2073 0x000fffff, /* src_mask */
2074 0x000fffff, /* dst_mask */
2075 FALSE), /* pcrel_offset */
2077 /* TLS GD/LD description offset set (lwi.gp). */
2078 HOWTO2 (R_NDS32_TLS_DESC_SDA17S2,/* type */
2080 2, /* size (0 = byte, 1 = short, 2 = long) */
2082 FALSE, /* pc_relative */
2084 complain_overflow_signed,/* complain_on_overflow */
2085 bfd_elf_generic_reloc, /* special_function */
2086 "R_NDS32_TLS_DESC_SDA17S2",/* name */
2087 FALSE, /* partial_inplace */
2088 0x0001ffff, /* src_mask */
2089 0x0001ffff, /* dst_mask */
2090 FALSE), /* pcrel_offset */
2093 /* Relocations used for relaxation. */
2094 #define HOWTO3(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
2095 [C-R_NDS32_RELAX_ENTRY] = HOWTO(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC)
2097 static reloc_howto_type nds32_elf_relax_howto_table[] = {
2098 HOWTO3 (R_NDS32_RELAX_ENTRY, /* type */
2100 2, /* size (0 = byte, 1 = short, 2 = long) */
2102 FALSE, /* pc_relative */
2104 complain_overflow_dont,/* complain_on_overflow */
2105 nds32_elf_ignore_reloc,/* special_function */
2106 "R_NDS32_RELAX_ENTRY", /* name */
2107 FALSE, /* partial_inplace */
2108 0xffffffff, /* src_mask */
2109 0xffffffff, /* dst_mask */
2110 FALSE), /* pcrel_offset */
2111 HOWTO3 (R_NDS32_GOT_SUFF, /* type */
2113 2, /* size (0 = byte, 1 = short, 2 = long) */
2115 FALSE, /* pc_relative */
2117 complain_overflow_dont,/* complain_on_overflow */
2118 nds32_elf_ignore_reloc,/* special_function */
2119 "R_NDS32_GOT_SUFF", /* name */
2120 FALSE, /* partial_inplace */
2121 0xffffffff, /* src_mask */
2122 0xffffffff, /* dst_mask */
2123 FALSE), /* pcrel_offset */
2124 HOWTO3 (R_NDS32_GOTOFF_SUFF, /* type */
2126 2, /* size (0 = byte, 1 = short, 2 = long) */
2128 FALSE, /* pc_relative */
2130 complain_overflow_bitfield,/* complain_on_overflow */
2131 nds32_elf_ignore_reloc,/* special_function */
2132 "R_NDS32_GOTOFF_SUFF", /* name */
2133 FALSE, /* partial_inplace */
2134 0xffffffff, /* src_mask */
2135 0xffffffff, /* dst_mask */
2136 FALSE), /* pcrel_offset */
2137 HOWTO3 (R_NDS32_PLT_GOT_SUFF, /* type */
2139 2, /* size (0 = byte, 1 = short, 2 = long) */
2141 FALSE, /* pc_relative */
2143 complain_overflow_dont,/* complain_on_overflow */
2144 nds32_elf_ignore_reloc,/* special_function */
2145 "R_NDS32_PLT_GOT_SUFF",/* name */
2146 FALSE, /* partial_inplace */
2147 0xffffffff, /* src_mask */
2148 0xffffffff, /* dst_mask */
2149 FALSE), /* pcrel_offset */
2150 HOWTO3 (R_NDS32_MULCALL_SUFF, /* type */
2152 2, /* size (0 = byte, 1 = short, 2 = long) */
2154 FALSE, /* pc_relative */
2156 complain_overflow_dont,/* complain_on_overflow */
2157 nds32_elf_ignore_reloc,/* special_function */
2158 "R_NDS32_MULCALL_SUFF",/* name */
2159 FALSE, /* partial_inplace */
2160 0xffffffff, /* src_mask */
2161 0xffffffff, /* dst_mask */
2162 FALSE), /* pcrel_offset */
2163 HOWTO3 (R_NDS32_PTR, /* type */
2165 2, /* size (0 = byte, 1 = short, 2 = long) */
2167 FALSE, /* pc_relative */
2169 complain_overflow_dont,/* complain_on_overflow */
2170 nds32_elf_ignore_reloc,/* special_function */
2171 "R_NDS32_PTR", /* name */
2172 FALSE, /* partial_inplace */
2173 0xffffffff, /* src_mask */
2174 0xffffffff, /* dst_mask */
2175 FALSE), /* pcrel_offset */
2176 HOWTO3 (R_NDS32_PTR_COUNT, /* type */
2178 2, /* size (0 = byte, 1 = short, 2 = long) */
2180 FALSE, /* pc_relative */
2182 complain_overflow_dont,/* complain_on_overflow */
2183 nds32_elf_ignore_reloc,/* special_function */
2184 "R_NDS32_PTR_COUNT", /* name */
2185 FALSE, /* partial_inplace */
2186 0xffffffff, /* src_mask */
2187 0xffffffff, /* dst_mask */
2188 FALSE), /* pcrel_offset */
2189 HOWTO3 (R_NDS32_PTR_RESOLVED, /* type */
2191 2, /* size (0 = byte, 1 = short, 2 = long) */
2193 FALSE, /* pc_relative */
2195 complain_overflow_dont,/* complain_on_overflow */
2196 nds32_elf_ignore_reloc,/* special_function */
2197 "R_NDS32_PTR_RESOLVED",/* name */
2198 FALSE, /* partial_inplace */
2199 0xffffffff, /* src_mask */
2200 0xffffffff, /* dst_mask */
2201 FALSE), /* pcrel_offset */
2202 HOWTO3 (R_NDS32_PLTBLOCK, /* type */
2204 2, /* size (0 = byte, 1 = short, 2 = long) */
2206 FALSE, /* pc_relative */
2208 complain_overflow_dont,/* complain_on_overflow */
2209 nds32_elf_ignore_reloc,/* special_function */
2210 "R_NDS32_PLTBLOCK", /* name */
2211 FALSE, /* partial_inplace */
2212 0xffffffff, /* src_mask */
2213 0xffffffff, /* dst_mask */
2214 FALSE), /* pcrel_offset */
2215 HOWTO3 (R_NDS32_RELAX_REGION_BEGIN,/* type */
2217 2, /* size (0 = byte, 1 = short, 2 = long) */
2219 FALSE, /* pc_relative */
2221 complain_overflow_dont,/* complain_on_overflow */
2222 nds32_elf_ignore_reloc,/* special_function */
2223 "R_NDS32_RELAX_REGION_BEGIN",/* name */
2224 FALSE, /* partial_inplace */
2225 0xffffffff, /* src_mask */
2226 0xffffffff, /* dst_mask */
2227 FALSE), /* pcrel_offset */
2228 HOWTO3 (R_NDS32_RELAX_REGION_END,/* type */
2230 2, /* size (0 = byte, 1 = short, 2 = long) */
2232 FALSE, /* pc_relative */
2234 complain_overflow_dont,/* complain_on_overflow */
2235 nds32_elf_ignore_reloc,/* special_function */
2236 "R_NDS32_RELAX_REGION_END",/* name */
2237 FALSE, /* partial_inplace */
2238 0xffffffff, /* src_mask */
2239 0xffffffff, /* dst_mask */
2240 FALSE), /* pcrel_offset */
2241 HOWTO3 (R_NDS32_MINUEND, /* type */
2243 2, /* size (0 = byte, 1 = short, 2 = long) */
2245 FALSE, /* pc_relative */
2247 complain_overflow_dont,/* complain_on_overflow */
2248 nds32_elf_ignore_reloc,/* special_function */
2249 "R_NDS32_MINUEND", /* name */
2250 FALSE, /* partial_inplace */
2251 0xffffffff, /* src_mask */
2252 0xffffffff, /* dst_mask */
2253 FALSE), /* pcrel_offset */
2254 HOWTO3 (R_NDS32_SUBTRAHEND, /* type */
2256 2, /* size (0 = byte, 1 = short, 2 = long) */
2258 FALSE, /* pc_relative */
2260 complain_overflow_dont,/* complain_on_overflow */
2261 nds32_elf_ignore_reloc,/* special_function */
2262 "R_NDS32_SUBTRAHEND", /* name */
2263 FALSE, /* partial_inplace */
2264 0xffffffff, /* src_mask */
2265 0xffffffff, /* dst_mask */
2266 FALSE), /* pcrel_offset */
2267 HOWTO3 (R_NDS32_DIFF8, /* type */
2269 0, /* size (0 = byte, 1 = short, 2 = long) */
2271 FALSE, /* pc_relative */
2273 complain_overflow_dont,/* complain_on_overflow */
2274 nds32_elf_ignore_reloc,/* special_function */
2275 "R_NDS32_DIFF8", /* name */
2276 FALSE, /* partial_inplace */
2277 0x000000ff, /* src_mask */
2278 0x000000ff, /* dst_mask */
2279 FALSE), /* pcrel_offset */
2280 HOWTO3 (R_NDS32_DIFF16, /* type */
2282 1, /* size (0 = byte, 1 = short, 2 = long) */
2284 FALSE, /* pc_relative */
2286 complain_overflow_dont,/* complain_on_overflow */
2287 nds32_elf_ignore_reloc,/* special_function */
2288 "R_NDS32_DIFF16", /* name */
2289 FALSE, /* partial_inplace */
2290 0x0000ffff, /* src_mask */
2291 0x0000ffff, /* dst_mask */
2292 FALSE), /* pcrel_offset */
2293 HOWTO3 (R_NDS32_DIFF32, /* type */
2295 2, /* size (0 = byte, 1 = short, 2 = long) */
2297 FALSE, /* pc_relative */
2299 complain_overflow_dont,/* complain_on_overflow */
2300 nds32_elf_ignore_reloc,/* special_function */
2301 "R_NDS32_DIFF32", /* name */
2302 FALSE, /* partial_inplace */
2303 0xffffffff, /* src_mask */
2304 0xffffffff, /* dst_mask */
2305 FALSE), /* pcrel_offset */
2306 HOWTO3 (R_NDS32_DIFF_ULEB128, /* type */
2308 0, /* size (0 = byte, 1 = short, 2 = long) */
2310 FALSE, /* pc_relative */
2312 complain_overflow_dont,/* complain_on_overflow */
2313 nds32_elf_ignore_reloc,/* special_function */
2314 "R_NDS32_DIFF_ULEB128",/* name */
2315 FALSE, /* partial_inplace */
2316 0xffffffff, /* src_mask */
2317 0xffffffff, /* dst_mask */
2318 FALSE), /* pcrel_offset */
2319 HOWTO3 (R_NDS32_DATA, /* type */
2321 2, /* size (0 = byte, 1 = short, 2 = long) */
2323 FALSE, /* pc_relative */
2325 complain_overflow_dont,/* complain_on_overflow */
2326 nds32_elf_ignore_reloc,/* special_function */
2327 "R_NDS32_DATA", /* name */
2328 FALSE, /* partial_inplace */
2329 0xffffffff, /* src_mask */
2330 0xffffffff, /* dst_mask */
2331 FALSE), /* pcrel_offset */
2332 HOWTO3 (R_NDS32_TRAN, /* type */
2334 2, /* size (0 = byte, 1 = short, 2 = long) */
2336 FALSE, /* pc_relative */
2338 complain_overflow_dont,/* complain_on_overflow */
2339 nds32_elf_ignore_reloc,/* special_function */
2340 "R_NDS32_TRAN", /* name */
2341 FALSE, /* partial_inplace */
2342 0xffffffff, /* src_mask */
2343 0xffffffff, /* dst_mask */
2344 FALSE), /* pcrel_offset */
2345 HOWTO3 (R_NDS32_TLS_LE_ADD, /* type */
2347 2, /* size (0 = byte, 1 = short, 2 = long) */
2349 FALSE, /* pc_relative */
2351 complain_overflow_dont,/* complain_on_overflow */
2352 nds32_elf_ignore_reloc,/* special_function */
2353 "R_NDS32_TLS_LE_ADD", /* name */
2354 FALSE, /* partial_inplace */
2355 0xffffffff, /* src_mask */
2356 0xffffffff, /* dst_mask */
2357 FALSE), /* pcrel_offset */
2358 HOWTO3 (R_NDS32_TLS_LE_LS, /* type */
2360 2, /* size (0 = byte, 1 = short, 2 = long) */
2362 FALSE, /* pc_relative */
2364 complain_overflow_dont,/* complain_on_overflow */
2365 nds32_elf_ignore_reloc,/* special_function */
2366 "R_NDS32_TLS_LE_LS", /* name */
2367 FALSE, /* partial_inplace */
2368 0xffffffff, /* src_mask */
2369 0xffffffff, /* dst_mask */
2370 FALSE), /* pcrel_offset */
2371 HOWTO3 (R_NDS32_EMPTY, /* type */
2373 2, /* size (0 = byte, 1 = short, 2 = long) */
2375 FALSE, /* pc_relative */
2377 complain_overflow_dont,/* complain_on_overflow */
2378 nds32_elf_ignore_reloc,/* special_function */
2379 "R_NDS32_EMPTY", /* name */
2380 FALSE, /* partial_inplace */
2381 0xffffffff, /* src_mask */
2382 0xffffffff, /* dst_mask */
2383 FALSE), /* pcrel_offset */
2384 /* TLS GD/LD description address base addition. */
2385 HOWTO3 (R_NDS32_TLS_DESC_ADD, /* type */
2387 2, /* size (0 = byte, 1 = short, 2 = long) */
2389 FALSE, /* pc_relative */
2391 complain_overflow_dont,/* complain_on_overflow */
2392 nds32_elf_ignore_reloc,/* special_function */
2393 "R_NDS32_TLS_DESC_ADD",/* name */
2394 FALSE, /* partial_inplace */
2395 0xffffffff, /* src_mask */
2396 0xffffffff, /* dst_mask */
2397 FALSE), /* pcrel_offset */
2398 /* TLS GD/LD description function load. */
2399 HOWTO3 (R_NDS32_TLS_DESC_FUNC,/* type */
2401 2, /* size (0 = byte, 1 = short, 2 = long) */
2403 FALSE, /* pc_relative */
2405 complain_overflow_dont,/* complain_on_overflow */
2406 nds32_elf_ignore_reloc,/* special_function */
2407 "R_NDS32_TLS_DESC_FUNC",/* name */
2408 FALSE, /* partial_inplace */
2409 0xffffffff, /* src_mask */
2410 0xffffffff, /* dst_mask */
2411 FALSE), /* pcrel_offset */
2412 /* TLS DESC resolve function call. */
2413 HOWTO3 (R_NDS32_TLS_DESC_CALL,/* type */
2415 2, /* size (0 = byte, 1 = short, 2 = long) */
2417 FALSE, /* pc_relative */
2419 complain_overflow_dont,/* complain_on_overflow */
2420 nds32_elf_ignore_reloc,/* special_function */
2421 "R_NDS32_TLS_DESC_CALL",/* name */
2422 FALSE, /* partial_inplace */
2423 0xffffffff, /* src_mask */
2424 0xffffffff, /* dst_mask */
2425 FALSE), /* pcrel_offset */
2426 /* TLS DESC variable access. */
2427 HOWTO3 (R_NDS32_TLS_DESC_MEM, /* type */
2429 2, /* size (0 = byte, 1 = short, 2 = long) */
2431 FALSE, /* pc_relative */
2433 complain_overflow_dont,/* complain_on_overflow */
2434 nds32_elf_ignore_reloc,/* special_function */
2435 "R_NDS32_TLS_DESC_MEM",/* name */
2436 FALSE, /* partial_inplace */
2437 0xffffffff, /* src_mask */
2438 0xffffffff, /* dst_mask */
2439 FALSE), /* pcrel_offset */
2440 /* TLS GD/LD description mark (@tlsdec). */
2441 HOWTO3 (R_NDS32_RELAX_REMOVE, /* type */
2443 2, /* size (0 = byte, 1 = short, 2 = long) */
2445 FALSE, /* pc_relative */
2447 complain_overflow_dont,/* complain_on_overflow */
2448 nds32_elf_ignore_reloc,/* special_function */
2449 "R_NDS32_REMOVE", /* name */
2450 FALSE, /* partial_inplace */
2451 0xffffffff, /* src_mask */
2452 0xffffffff, /* dst_mask */
2453 FALSE), /* pcrel_offset */
2454 /* TLS GD/LD description mark (@tlsdec). */
2455 HOWTO3 (R_NDS32_RELAX_GROUP, /* type */
2457 2, /* size (0 = byte, 1 = short, 2 = long) */
2459 FALSE, /* pc_relative */
2461 complain_overflow_dont,/* complain_on_overflow */
2462 nds32_elf_ignore_reloc,/* special_function */
2463 "R_NDS32_GROUP", /* name */
2464 FALSE, /* partial_inplace */
2465 0xffffffff, /* src_mask */
2466 0xffffffff, /* dst_mask */
2467 FALSE), /* pcrel_offset */
2468 HOWTO3 (R_NDS32_TLS_IEGP_LW, /* type */
2470 2, /* size (0 = byte, 1 = short, 2 = long) */
2472 FALSE, /* pc_relative */
2474 complain_overflow_dont,/* complain_on_overflow */
2475 nds32_elf_ignore_reloc,/* special_function */
2476 "R_NDS32_TLS_IEGP_LW", /* name */
2477 FALSE, /* partial_inplace */
2478 0xffffffff, /* src_mask */
2479 0xffffffff, /* dst_mask */
2480 FALSE), /* pcrel_offset */
2481 /* LA and FLSI relaxation. */
2482 HOWTO3 (R_NDS32_LSI, /* type */
2484 2, /* size (0 = byte, 1 = short, 2 = long) */
2486 FALSE, /* pc_relative */
2488 complain_overflow_dont,/* complain_on_overflow */
2489 nds32_elf_ignore_reloc,/* special_function */
2490 "R_NDS32_LSI", /* name */
2491 FALSE, /* partial_inplace */
2492 0xffffffff, /* src_mask */
2493 0xffffffff, /* dst_mask */
2497 static unsigned long dl_tlsdesc_lazy_trampoline[] =
2499 0x46200000, /* sethi $r2,#0x0 */
2500 0x58210000, /* ori $r2,$r2,#0x0 */
2501 0x40217400, /* add $r2,$r2,$gp */
2502 0x04210000, /* lwi $r2,[$r2+#0x0] */
2503 0x46300000, /* sethi $r3,#0x0 */
2504 0x58318000, /* ori $r3,$r3,#0x0 */
2505 0x4031f400, /* add $r3,$r3,$gp */
2506 0x4a000800, /* jr $r2 */
2510 nds32_put_trampoline (void *contents, const unsigned long *template,
2515 for (ix = 0; ix != count; ix++)
2517 unsigned long insn = template[ix];
2518 bfd_putb32 (insn, (char *) contents + ix * 4);
2522 /* nds32_insertion_sort sorts an array with nmemb elements of size size.
2523 This prototype is the same as qsort (). */
2526 nds32_insertion_sort (void *base, size_t nmemb, size_t size,
2527 int (*compar) (const void *lhs, const void *rhs))
2529 char *ptr = (char *) base;
2531 char *tmp = xmalloc (size);
2533 /* If i is less than j, i is inserted before j.
2535 |---- j ----- i --------------|
2540 for (i = 1; i < (int) nmemb; i++)
2542 for (j = (i - 1); j >= 0; j--)
2543 if (compar (ptr + i * size, ptr + j * size) >= 0)
2549 continue; /* i is in order. */
2551 memcpy (tmp, ptr + i * size, size);
2552 memmove (ptr + (j + 1) * size, ptr + j * size, (i - j) * size);
2553 memcpy (ptr + j * size, tmp, size);
2558 /* Sort relocation by r_offset.
2560 We didn't use qsort () in stdlib, because quick-sort is not a stable sorting
2561 algorithm. Relocations at the same r_offset must keep their order.
2562 For example, RELAX_ENTRY must be the very first relocation entry.
2564 Currently, this function implements insertion-sort.
2566 FIXME: If we already sort them in assembler, why bother sort them
2570 compar_reloc (const void *lhs, const void *rhs)
2572 const Elf_Internal_Rela *l = (const Elf_Internal_Rela *) lhs;
2573 const Elf_Internal_Rela *r = (const Elf_Internal_Rela *) rhs;
2575 if (l->r_offset > r->r_offset)
2577 else if (l->r_offset == r->r_offset)
2583 /* Functions listed below are only used for old relocs.
2584 nds32_elf_9_pcrel_reloc
2585 nds32_elf_do_9_pcrel_reloc
2586 nds32_elf_hi20_reloc
2587 nds32_elf_relocate_hi20
2588 nds32_elf_lo12_reloc
2589 nds32_elf_sda15_reloc
2590 nds32_elf_generic_reloc. */
2592 /* Handle the R_NDS32_9_PCREL & R_NDS32_9_PCREL_RELA reloc. */
2594 static bfd_reloc_status_type
2595 nds32_elf_9_pcrel_reloc (bfd * abfd,
2596 arelent * reloc_entry,
2599 asection * input_section,
2601 char ** error_message ATTRIBUTE_UNUSED)
2603 /* This part is from bfd_elf_generic_reloc. */
2604 if (output_bfd != (bfd *) NULL
2605 && (symbol->flags & BSF_SECTION_SYM) == 0
2606 && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
2608 reloc_entry->address += input_section->output_offset;
2609 return bfd_reloc_ok;
2612 if (output_bfd != NULL)
2614 /* FIXME: See bfd_perform_relocation. Is this right? */
2615 return bfd_reloc_continue;
2618 return nds32_elf_do_9_pcrel_reloc (abfd, reloc_entry->howto,
2620 data, reloc_entry->address,
2623 + symbol->section->output_section->vma
2624 + symbol->section->output_offset),
2625 reloc_entry->addend);
2628 /* Utility to actually perform an R_NDS32_9_PCREL reloc. */
2629 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
2631 static bfd_reloc_status_type
2632 nds32_elf_do_9_pcrel_reloc (bfd * abfd,
2633 reloc_howto_type * howto,
2634 asection * input_section,
2637 asection * symbol_section ATTRIBUTE_UNUSED,
2638 bfd_vma symbol_value,
2641 bfd_signed_vma relocation;
2643 bfd_reloc_status_type status;
2645 /* Sanity check the address (offset in section). */
2646 if (offset > bfd_get_section_limit (abfd, input_section))
2647 return bfd_reloc_outofrange;
2649 relocation = symbol_value + addend;
2650 /* Make it pc relative. */
2651 relocation -= (input_section->output_section->vma
2652 + input_section->output_offset);
2653 /* These jumps mask off the lower two bits of the current address
2654 before doing pcrel calculations. */
2655 relocation -= (offset & -(bfd_vma) 2);
2657 if (relocation < -ACCURATE_8BIT_S1 || relocation >= ACCURATE_8BIT_S1)
2658 status = bfd_reloc_overflow;
2660 status = bfd_reloc_ok;
2662 x = bfd_getb16 (data + offset);
2664 relocation >>= howto->rightshift;
2665 relocation <<= howto->bitpos;
2666 x = (x & ~howto->dst_mask)
2667 | (((x & howto->src_mask) + relocation) & howto->dst_mask);
2669 bfd_putb16 ((bfd_vma) x, data + offset);
2674 /* Handle the R_NDS32_HI20_[SU]LO relocs.
2675 HI20_SLO is for the add3 and load/store with displacement instructions.
2676 HI20 is for the or3 instruction.
2677 For R_NDS32_HI20_SLO, the lower 16 bits are sign extended when added to
2678 the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
2679 we must add one to the high 16 bytes (which will get subtracted off when
2680 the low 16 bits are added).
2681 These relocs have to be done in combination with an R_NDS32_LO12 reloc
2682 because there is a carry from the LO12 to the HI20. Here we just save
2683 the information we need; we do the actual relocation when we see the LO12.
2684 This code is copied from the elf32-mips.c. We also support an arbitrary
2685 number of HI20 relocs to be associated with a single LO12 reloc. The
2686 assembler sorts the relocs to ensure each HI20 immediately precedes its
2687 LO12. However if there are multiple copies, the assembler may not find
2688 the real LO12 so it picks the first one it finds. */
2692 struct nds32_hi20 *next;
2697 static struct nds32_hi20 *nds32_hi20_list;
2699 static bfd_reloc_status_type
2700 nds32_elf_hi20_reloc (bfd *abfd ATTRIBUTE_UNUSED,
2701 arelent *reloc_entry,
2704 asection *input_section,
2706 char **error_message ATTRIBUTE_UNUSED)
2708 bfd_reloc_status_type ret;
2710 struct nds32_hi20 *n;
2712 /* This part is from bfd_elf_generic_reloc.
2713 If we're relocating, and this an external symbol, we don't want
2714 to change anything. */
2715 if (output_bfd != (bfd *) NULL
2716 && (symbol->flags & BSF_SECTION_SYM) == 0 && reloc_entry->addend == 0)
2718 reloc_entry->address += input_section->output_offset;
2719 return bfd_reloc_ok;
2722 /* Sanity check the address (offset in section). */
2723 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
2724 return bfd_reloc_outofrange;
2727 if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL)
2728 ret = bfd_reloc_undefined;
2730 if (bfd_is_com_section (symbol->section))
2733 relocation = symbol->value;
2735 relocation += symbol->section->output_section->vma;
2736 relocation += symbol->section->output_offset;
2737 relocation += reloc_entry->addend;
2739 /* Save the information, and let LO12 do the actual relocation. */
2740 n = (struct nds32_hi20 *) bfd_malloc ((bfd_size_type) sizeof *n);
2742 return bfd_reloc_outofrange;
2744 n->addr = (bfd_byte *) data + reloc_entry->address;
2745 n->addend = relocation;
2746 n->next = nds32_hi20_list;
2747 nds32_hi20_list = n;
2749 if (output_bfd != (bfd *) NULL)
2750 reloc_entry->address += input_section->output_offset;
2755 /* Handle an NDS32 ELF HI20 reloc. */
2758 nds32_elf_relocate_hi20 (bfd *input_bfd ATTRIBUTE_UNUSED,
2759 int type ATTRIBUTE_UNUSED,
2760 Elf_Internal_Rela *relhi,
2761 Elf_Internal_Rela *rello,
2768 insn = bfd_getb32 (contents + relhi->r_offset);
2770 addlo = bfd_getb32 (contents + rello->r_offset);
2773 addend += ((insn & 0xfffff) << 20) + addlo;
2775 insn = (insn & 0xfff00000) | ((addend >> 12) & 0xfffff);
2776 bfd_putb32 (insn, contents + relhi->r_offset);
2779 /* Do an R_NDS32_LO12 relocation. This is a straightforward 12 bit
2780 inplace relocation; this function exists in order to do the
2781 R_NDS32_HI20_[SU]LO relocation described above. */
2783 static bfd_reloc_status_type
2784 nds32_elf_lo12_reloc (bfd *input_bfd, arelent *reloc_entry, asymbol *symbol,
2785 void *data, asection *input_section, bfd *output_bfd,
2786 char **error_message)
2788 /* This part is from bfd_elf_generic_reloc.
2789 If we're relocating, and this an external symbol, we don't want
2790 to change anything. */
2791 if (output_bfd != NULL && (symbol->flags & BSF_SECTION_SYM) == 0
2792 && reloc_entry->addend == 0)
2794 reloc_entry->address += input_section->output_offset;
2795 return bfd_reloc_ok;
2798 if (nds32_hi20_list != NULL)
2800 struct nds32_hi20 *l;
2802 l = nds32_hi20_list;
2807 unsigned long vallo;
2808 struct nds32_hi20 *next;
2810 /* Do the HI20 relocation. Note that we actually don't need
2811 to know anything about the LO12 itself, except where to
2812 find the low 12 bits of the addend needed by the LO12. */
2813 insn = bfd_getb32 (l->addr);
2814 vallo = bfd_getb32 ((bfd_byte *) data + reloc_entry->address);
2816 switch (reloc_entry->howto->type)
2818 case R_NDS32_LO12S3:
2822 case R_NDS32_LO12S2:
2826 case R_NDS32_LO12S1:
2830 case R_NDS32_LO12S0:
2835 val = ((insn & 0xfffff) << 12) + vallo;
2838 insn = (insn & ~(bfd_vma) 0xfffff) | ((val >> 12) & 0xfffff);
2839 bfd_putb32 ((bfd_vma) insn, l->addr);
2846 nds32_hi20_list = NULL;
2849 /* Now do the LO12 reloc in the usual way.
2850 ??? It would be nice to call bfd_elf_generic_reloc here,
2851 but we have partial_inplace set. bfd_elf_generic_reloc will
2852 pass the handling back to bfd_install_relocation which will install
2853 a section relative addend which is wrong. */
2854 return nds32_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
2855 input_section, output_bfd, error_message);
2858 /* Do generic partial_inplace relocation.
2859 This is a local replacement for bfd_elf_generic_reloc. */
2861 static bfd_reloc_status_type
2862 nds32_elf_generic_reloc (bfd *input_bfd, arelent *reloc_entry,
2863 asymbol *symbol, void *data, asection *input_section,
2864 bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
2866 bfd_reloc_status_type ret;
2868 bfd_byte *inplace_address;
2870 /* This part is from bfd_elf_generic_reloc.
2871 If we're relocating, and this an external symbol, we don't want
2872 to change anything. */
2873 if (output_bfd != NULL && (symbol->flags & BSF_SECTION_SYM) == 0
2874 && reloc_entry->addend == 0)
2876 reloc_entry->address += input_section->output_offset;
2877 return bfd_reloc_ok;
2880 /* Now do the reloc in the usual way.
2881 ??? It would be nice to call bfd_elf_generic_reloc here,
2882 but we have partial_inplace set. bfd_elf_generic_reloc will
2883 pass the handling back to bfd_install_relocation which will install
2884 a section relative addend which is wrong. */
2886 /* Sanity check the address (offset in section). */
2887 if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
2888 return bfd_reloc_outofrange;
2891 if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL)
2892 ret = bfd_reloc_undefined;
2894 if (bfd_is_com_section (symbol->section) || output_bfd != (bfd *) NULL)
2897 relocation = symbol->value;
2899 /* Only do this for a final link. */
2900 if (output_bfd == (bfd *) NULL)
2902 relocation += symbol->section->output_section->vma;
2903 relocation += symbol->section->output_offset;
2906 relocation += reloc_entry->addend;
2907 switch (reloc_entry->howto->type)
2909 case R_NDS32_LO12S3:
2913 case R_NDS32_LO12S2:
2917 case R_NDS32_LO12S1:
2921 case R_NDS32_LO12S0:
2927 inplace_address = (bfd_byte *) data + reloc_entry->address;
2930 x = ((x & ~reloc_entry->howto->dst_mask) | \
2931 (((x & reloc_entry->howto->src_mask) + relocation) & \
2932 reloc_entry->howto->dst_mask))
2934 switch (reloc_entry->howto->size)
2938 short x = bfd_getb16 (inplace_address);
2941 bfd_putb16 ((bfd_vma) x, inplace_address);
2946 unsigned long x = bfd_getb32 (inplace_address);
2949 bfd_putb32 ((bfd_vma) x, inplace_address);
2956 if (output_bfd != (bfd *) NULL)
2957 reloc_entry->address += input_section->output_offset;
2962 /* Handle the R_NDS32_SDA15 reloc.
2963 This reloc is used to compute the address of objects in the small data area
2964 and to perform loads and stores from that area.
2965 The lower 15 bits are sign extended and added to the register specified
2966 in the instruction, which is assumed to point to _SDA_BASE_.
2968 Since the lower 15 bits offset is left-shifted 0, 1 or 2 bits depending on
2969 the access size, this must be taken care of. */
2971 static bfd_reloc_status_type
2972 nds32_elf_sda15_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
2973 asymbol *symbol, void *data ATTRIBUTE_UNUSED,
2974 asection *input_section, bfd *output_bfd,
2975 char **error_message ATTRIBUTE_UNUSED)
2977 /* This part is from bfd_elf_generic_reloc. */
2978 if (output_bfd != (bfd *) NULL
2979 && (symbol->flags & BSF_SECTION_SYM) == 0
2980 && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
2982 reloc_entry->address += input_section->output_offset;
2983 return bfd_reloc_ok;
2986 if (output_bfd != NULL)
2988 /* FIXME: See bfd_perform_relocation. Is this right? */
2989 return bfd_reloc_continue;
2992 /* FIXME: not sure what to do here yet. But then again, the linker
2993 may never call us. */
2997 /* nds32_elf_ignore_reloc is the special function for
2998 relocation types which don't need to be relocated
2999 like relaxation relocation types.
3000 This function simply return bfd_reloc_ok when it is
3003 static bfd_reloc_status_type
3004 nds32_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
3005 asymbol *symbol ATTRIBUTE_UNUSED,
3006 void *data ATTRIBUTE_UNUSED, asection *input_section,
3007 bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
3009 if (output_bfd != NULL)
3010 reloc_entry->address += input_section->output_offset;
3012 return bfd_reloc_ok;
3016 /* Map BFD reloc types to NDS32 ELF reloc types. */
3018 struct nds32_reloc_map_entry
3020 bfd_reloc_code_real_type bfd_reloc_val;
3021 unsigned char elf_reloc_val;
3024 static const struct nds32_reloc_map_entry nds32_reloc_map[] =
3026 {BFD_RELOC_NONE, R_NDS32_NONE},
3027 {BFD_RELOC_16, R_NDS32_16_RELA},
3028 {BFD_RELOC_32, R_NDS32_32_RELA},
3029 {BFD_RELOC_VTABLE_INHERIT, R_NDS32_RELA_GNU_VTINHERIT},
3030 {BFD_RELOC_VTABLE_ENTRY, R_NDS32_RELA_GNU_VTENTRY},
3032 {BFD_RELOC_NDS32_20, R_NDS32_20_RELA},
3033 {BFD_RELOC_NDS32_9_PCREL, R_NDS32_9_PCREL_RELA},
3034 {BFD_RELOC_NDS32_WORD_9_PCREL, R_NDS32_WORD_9_PCREL_RELA},
3035 {BFD_RELOC_NDS32_15_PCREL, R_NDS32_15_PCREL_RELA},
3036 {BFD_RELOC_NDS32_17_PCREL, R_NDS32_17_PCREL_RELA},
3037 {BFD_RELOC_NDS32_25_PCREL, R_NDS32_25_PCREL_RELA},
3038 {BFD_RELOC_NDS32_HI20, R_NDS32_HI20_RELA},
3039 {BFD_RELOC_NDS32_LO12S3, R_NDS32_LO12S3_RELA},
3040 {BFD_RELOC_NDS32_LO12S2, R_NDS32_LO12S2_RELA},
3041 {BFD_RELOC_NDS32_LO12S1, R_NDS32_LO12S1_RELA},
3042 {BFD_RELOC_NDS32_LO12S0, R_NDS32_LO12S0_RELA},
3043 {BFD_RELOC_NDS32_LO12S0_ORI, R_NDS32_LO12S0_ORI_RELA},
3044 {BFD_RELOC_NDS32_SDA15S3, R_NDS32_SDA15S3_RELA},
3045 {BFD_RELOC_NDS32_SDA15S2, R_NDS32_SDA15S2_RELA},
3046 {BFD_RELOC_NDS32_SDA15S1, R_NDS32_SDA15S1_RELA},
3047 {BFD_RELOC_NDS32_SDA15S0, R_NDS32_SDA15S0_RELA},
3048 {BFD_RELOC_NDS32_SDA16S3, R_NDS32_SDA16S3_RELA},
3049 {BFD_RELOC_NDS32_SDA17S2, R_NDS32_SDA17S2_RELA},
3050 {BFD_RELOC_NDS32_SDA18S1, R_NDS32_SDA18S1_RELA},
3051 {BFD_RELOC_NDS32_SDA19S0, R_NDS32_SDA19S0_RELA},
3052 {BFD_RELOC_NDS32_GOT20, R_NDS32_GOT20},
3053 {BFD_RELOC_NDS32_9_PLTREL, R_NDS32_9_PLTREL},
3054 {BFD_RELOC_NDS32_25_PLTREL, R_NDS32_25_PLTREL},
3055 {BFD_RELOC_NDS32_COPY, R_NDS32_COPY},
3056 {BFD_RELOC_NDS32_GLOB_DAT, R_NDS32_GLOB_DAT},
3057 {BFD_RELOC_NDS32_JMP_SLOT, R_NDS32_JMP_SLOT},
3058 {BFD_RELOC_NDS32_RELATIVE, R_NDS32_RELATIVE},
3059 {BFD_RELOC_NDS32_GOTOFF, R_NDS32_GOTOFF},
3060 {BFD_RELOC_NDS32_GOTOFF_HI20, R_NDS32_GOTOFF_HI20},
3061 {BFD_RELOC_NDS32_GOTOFF_LO12, R_NDS32_GOTOFF_LO12},
3062 {BFD_RELOC_NDS32_GOTPC20, R_NDS32_GOTPC20},
3063 {BFD_RELOC_NDS32_GOT_HI20, R_NDS32_GOT_HI20},
3064 {BFD_RELOC_NDS32_GOT_LO12, R_NDS32_GOT_LO12},
3065 {BFD_RELOC_NDS32_GOTPC_HI20, R_NDS32_GOTPC_HI20},
3066 {BFD_RELOC_NDS32_GOTPC_LO12, R_NDS32_GOTPC_LO12},
3067 {BFD_RELOC_NDS32_INSN16, R_NDS32_INSN16},
3068 {BFD_RELOC_NDS32_LABEL, R_NDS32_LABEL},
3069 {BFD_RELOC_NDS32_LONGCALL1, R_NDS32_LONGCALL1},
3070 {BFD_RELOC_NDS32_LONGCALL2, R_NDS32_LONGCALL2},
3071 {BFD_RELOC_NDS32_LONGCALL3, R_NDS32_LONGCALL3},
3072 {BFD_RELOC_NDS32_LONGJUMP1, R_NDS32_LONGJUMP1},
3073 {BFD_RELOC_NDS32_LONGJUMP2, R_NDS32_LONGJUMP2},
3074 {BFD_RELOC_NDS32_LONGJUMP3, R_NDS32_LONGJUMP3},
3075 {BFD_RELOC_NDS32_LOADSTORE, R_NDS32_LOADSTORE},
3076 {BFD_RELOC_NDS32_9_FIXED, R_NDS32_9_FIXED_RELA},
3077 {BFD_RELOC_NDS32_15_FIXED, R_NDS32_15_FIXED_RELA},
3078 {BFD_RELOC_NDS32_17_FIXED, R_NDS32_17_FIXED_RELA},
3079 {BFD_RELOC_NDS32_25_FIXED, R_NDS32_25_FIXED_RELA},
3080 {BFD_RELOC_NDS32_LONGCALL4, R_NDS32_LONGCALL4},
3081 {BFD_RELOC_NDS32_LONGCALL5, R_NDS32_LONGCALL5},
3082 {BFD_RELOC_NDS32_LONGCALL6, R_NDS32_LONGCALL6},
3083 {BFD_RELOC_NDS32_LONGJUMP4, R_NDS32_LONGJUMP4},
3084 {BFD_RELOC_NDS32_LONGJUMP5, R_NDS32_LONGJUMP5},
3085 {BFD_RELOC_NDS32_LONGJUMP6, R_NDS32_LONGJUMP6},
3086 {BFD_RELOC_NDS32_LONGJUMP7, R_NDS32_LONGJUMP7},
3087 {BFD_RELOC_NDS32_PLTREL_HI20, R_NDS32_PLTREL_HI20},
3088 {BFD_RELOC_NDS32_PLTREL_LO12, R_NDS32_PLTREL_LO12},
3089 {BFD_RELOC_NDS32_PLT_GOTREL_HI20, R_NDS32_PLT_GOTREL_HI20},
3090 {BFD_RELOC_NDS32_PLT_GOTREL_LO12, R_NDS32_PLT_GOTREL_LO12},
3091 {BFD_RELOC_NDS32_SDA12S2_DP, R_NDS32_SDA12S2_DP_RELA},
3092 {BFD_RELOC_NDS32_SDA12S2_SP, R_NDS32_SDA12S2_SP_RELA},
3093 {BFD_RELOC_NDS32_LO12S2_DP, R_NDS32_LO12S2_DP_RELA},
3094 {BFD_RELOC_NDS32_LO12S2_SP, R_NDS32_LO12S2_SP_RELA},
3095 {BFD_RELOC_NDS32_DWARF2_OP1, R_NDS32_DWARF2_OP1_RELA},
3096 {BFD_RELOC_NDS32_DWARF2_OP2, R_NDS32_DWARF2_OP2_RELA},
3097 {BFD_RELOC_NDS32_DWARF2_LEB, R_NDS32_DWARF2_LEB_RELA},
3098 {BFD_RELOC_NDS32_UPDATE_TA, R_NDS32_UPDATE_TA_RELA},
3099 {BFD_RELOC_NDS32_PLT_GOTREL_LO20, R_NDS32_PLT_GOTREL_LO20},
3100 {BFD_RELOC_NDS32_PLT_GOTREL_LO15, R_NDS32_PLT_GOTREL_LO15},
3101 {BFD_RELOC_NDS32_PLT_GOTREL_LO19, R_NDS32_PLT_GOTREL_LO19},
3102 {BFD_RELOC_NDS32_GOT_LO15, R_NDS32_GOT_LO15},
3103 {BFD_RELOC_NDS32_GOT_LO19, R_NDS32_GOT_LO19},
3104 {BFD_RELOC_NDS32_GOTOFF_LO15, R_NDS32_GOTOFF_LO15},
3105 {BFD_RELOC_NDS32_GOTOFF_LO19, R_NDS32_GOTOFF_LO19},
3106 {BFD_RELOC_NDS32_GOT15S2, R_NDS32_GOT15S2_RELA},
3107 {BFD_RELOC_NDS32_GOT17S2, R_NDS32_GOT17S2_RELA},
3108 {BFD_RELOC_NDS32_5, R_NDS32_5_RELA},
3109 {BFD_RELOC_NDS32_10_UPCREL, R_NDS32_10_UPCREL_RELA},
3110 {BFD_RELOC_NDS32_SDA_FP7U2_RELA, R_NDS32_SDA_FP7U2_RELA},
3111 {BFD_RELOC_NDS32_RELAX_ENTRY, R_NDS32_RELAX_ENTRY},
3112 {BFD_RELOC_NDS32_GOT_SUFF, R_NDS32_GOT_SUFF},
3113 {BFD_RELOC_NDS32_GOTOFF_SUFF, R_NDS32_GOTOFF_SUFF},
3114 {BFD_RELOC_NDS32_PLT_GOT_SUFF, R_NDS32_PLT_GOT_SUFF},
3115 {BFD_RELOC_NDS32_MULCALL_SUFF, R_NDS32_MULCALL_SUFF},
3116 {BFD_RELOC_NDS32_PTR, R_NDS32_PTR},
3117 {BFD_RELOC_NDS32_PTR_COUNT, R_NDS32_PTR_COUNT},
3118 {BFD_RELOC_NDS32_PTR_RESOLVED, R_NDS32_PTR_RESOLVED},
3119 {BFD_RELOC_NDS32_PLTBLOCK, R_NDS32_PLTBLOCK},
3120 {BFD_RELOC_NDS32_RELAX_REGION_BEGIN, R_NDS32_RELAX_REGION_BEGIN},
3121 {BFD_RELOC_NDS32_RELAX_REGION_END, R_NDS32_RELAX_REGION_END},
3122 {BFD_RELOC_NDS32_MINUEND, R_NDS32_MINUEND},
3123 {BFD_RELOC_NDS32_SUBTRAHEND, R_NDS32_SUBTRAHEND},
3124 {BFD_RELOC_NDS32_DIFF8, R_NDS32_DIFF8},
3125 {BFD_RELOC_NDS32_DIFF16, R_NDS32_DIFF16},
3126 {BFD_RELOC_NDS32_DIFF32, R_NDS32_DIFF32},
3127 {BFD_RELOC_NDS32_DIFF_ULEB128, R_NDS32_DIFF_ULEB128},
3128 {BFD_RELOC_NDS32_EMPTY, R_NDS32_EMPTY},
3129 {BFD_RELOC_NDS32_25_ABS, R_NDS32_25_ABS_RELA},
3130 {BFD_RELOC_NDS32_DATA, R_NDS32_DATA},
3131 {BFD_RELOC_NDS32_TRAN, R_NDS32_TRAN},
3132 {BFD_RELOC_NDS32_17IFC_PCREL, R_NDS32_17IFC_PCREL_RELA},
3133 {BFD_RELOC_NDS32_10IFCU_PCREL, R_NDS32_10IFCU_PCREL_RELA},
3135 {BFD_RELOC_NDS32_TPOFF, R_NDS32_TLS_TPOFF},
3136 /* Missing: BFD_RELOC_NDS32_GOTTPOFF. */
3137 {BFD_RELOC_NDS32_TLS_LE_HI20, R_NDS32_TLS_LE_HI20},
3138 {BFD_RELOC_NDS32_TLS_LE_LO12, R_NDS32_TLS_LE_LO12},
3139 {BFD_RELOC_NDS32_TLS_LE_20, R_NDS32_TLS_LE_20},
3140 {BFD_RELOC_NDS32_TLS_LE_15S0, R_NDS32_TLS_LE_15S0},
3141 {BFD_RELOC_NDS32_TLS_LE_15S1, R_NDS32_TLS_LE_15S1},
3142 {BFD_RELOC_NDS32_TLS_LE_15S2, R_NDS32_TLS_LE_15S2},
3143 {BFD_RELOC_NDS32_TLS_LE_ADD, R_NDS32_TLS_LE_ADD},
3144 {BFD_RELOC_NDS32_TLS_LE_LS, R_NDS32_TLS_LE_LS},
3145 {BFD_RELOC_NDS32_TLS_IE_HI20, R_NDS32_TLS_IE_HI20},
3146 {BFD_RELOC_NDS32_TLS_IE_LO12, R_NDS32_TLS_IE_LO12},
3147 {BFD_RELOC_NDS32_TLS_IE_LO12S2, R_NDS32_TLS_IE_LO12S2},
3148 {BFD_RELOC_NDS32_TLS_IEGP_HI20, R_NDS32_TLS_IEGP_HI20},
3149 {BFD_RELOC_NDS32_TLS_IEGP_LO12, R_NDS32_TLS_IEGP_LO12},
3150 {BFD_RELOC_NDS32_TLS_IEGP_LO12S2, R_NDS32_TLS_IEGP_LO12S2},
3151 {BFD_RELOC_NDS32_TLS_IEGP_LW, R_NDS32_TLS_IEGP_LW},
3152 {BFD_RELOC_NDS32_TLS_DESC, R_NDS32_TLS_DESC},
3153 {BFD_RELOC_NDS32_TLS_DESC_HI20, R_NDS32_TLS_DESC_HI20},
3154 {BFD_RELOC_NDS32_TLS_DESC_LO12, R_NDS32_TLS_DESC_LO12},
3155 {BFD_RELOC_NDS32_TLS_DESC_20, R_NDS32_TLS_DESC_20},
3156 {BFD_RELOC_NDS32_TLS_DESC_SDA17S2, R_NDS32_TLS_DESC_SDA17S2},
3157 {BFD_RELOC_NDS32_TLS_DESC_ADD, R_NDS32_TLS_DESC_ADD},
3158 {BFD_RELOC_NDS32_TLS_DESC_FUNC, R_NDS32_TLS_DESC_FUNC},
3159 {BFD_RELOC_NDS32_TLS_DESC_CALL, R_NDS32_TLS_DESC_CALL},
3160 {BFD_RELOC_NDS32_TLS_DESC_MEM, R_NDS32_TLS_DESC_MEM},
3161 {BFD_RELOC_NDS32_REMOVE, R_NDS32_RELAX_REMOVE},
3162 {BFD_RELOC_NDS32_GROUP, R_NDS32_RELAX_GROUP},
3163 {BFD_RELOC_NDS32_LSI, R_NDS32_LSI},
3168 static reloc_howto_type *
3169 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3174 for (i = 0; i < ARRAY_SIZE (nds32_elf_howto_table); i++)
3175 if (nds32_elf_howto_table[i].name != NULL
3176 && strcasecmp (nds32_elf_howto_table[i].name, r_name) == 0)
3177 return &nds32_elf_howto_table[i];
3179 for (i = 0; i < ARRAY_SIZE (nds32_elf_relax_howto_table); i++)
3180 if (nds32_elf_relax_howto_table[i].name != NULL
3181 && strcasecmp (nds32_elf_relax_howto_table[i].name, r_name) == 0)
3182 return &nds32_elf_relax_howto_table[i];
3187 static reloc_howto_type *
3188 bfd_elf32_bfd_reloc_type_table_lookup (enum elf_nds32_reloc_type code)
3190 if (code < R_NDS32_RELAX_ENTRY)
3192 BFD_ASSERT (code < ARRAY_SIZE (nds32_elf_howto_table));
3193 return &nds32_elf_howto_table[code];
3197 if ((size_t) (code - R_NDS32_RELAX_ENTRY)
3198 >= ARRAY_SIZE (nds32_elf_relax_howto_table))
3204 BFD_ASSERT ((size_t) (code - R_NDS32_RELAX_ENTRY)
3205 < ARRAY_SIZE (nds32_elf_relax_howto_table));
3206 return &nds32_elf_relax_howto_table[code - R_NDS32_RELAX_ENTRY];
3210 static reloc_howto_type *
3211 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3212 bfd_reloc_code_real_type code)
3216 for (i = 0; i < ARRAY_SIZE (nds32_reloc_map); i++)
3218 if (nds32_reloc_map[i].bfd_reloc_val == code)
3219 return bfd_elf32_bfd_reloc_type_table_lookup
3220 (nds32_reloc_map[i].elf_reloc_val);
3226 /* Set the howto pointer for an NDS32 ELF reloc. */
3229 nds32_info_to_howto_rel (bfd *abfd, arelent *cache_ptr,
3230 Elf_Internal_Rela *dst)
3232 enum elf_nds32_reloc_type r_type;
3234 r_type = ELF32_R_TYPE (dst->r_info);
3235 if (r_type > R_NDS32_GNU_VTENTRY)
3237 /* xgettext:c-format */
3238 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3240 bfd_set_error (bfd_error_bad_value);
3244 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) <= R_NDS32_GNU_VTENTRY);
3245 cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
3250 nds32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
3251 Elf_Internal_Rela *dst)
3253 unsigned int r_type = ELF32_R_TYPE (dst->r_info);
3255 if ((r_type == R_NDS32_NONE)
3256 || ((r_type > R_NDS32_GNU_VTENTRY)
3257 && (r_type < R_NDS32_max)))
3259 cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
3263 /* xgettext:c-format */
3264 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
3265 bfd_set_error (bfd_error_bad_value);
3269 /* Support for core dump NOTE sections.
3270 Reference to include/linux/elfcore.h in Linux. */
3273 nds32_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3278 switch (note->descsz)
3281 /* Linux/NDS32 32-bit, ABI1. */
3284 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3287 elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
3295 /* Linux/NDS32 32-bit. */
3298 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3301 elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
3312 /* Make a ".reg" section. */
3313 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3314 size, note->descpos + offset);
3318 nds32_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3320 switch (note->descsz)
3325 /* __kernel_uid_t, __kernel_gid_t are short on NDS32 platform. */
3326 elf_tdata (abfd)->core->program =
3327 _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
3328 elf_tdata (abfd)->core->command =
3329 _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
3336 /* Note that for some reason, a spurious space is tacked
3337 onto the end of the args in some (at least one anyway)
3338 implementations, so strip it off if it exists. */
3340 char *command = elf_tdata (abfd)->core->command;
3341 int n = strlen (command);
3343 if (0 < n && command[n - 1] == ' ')
3344 command[n - 1] = '\0';
3350 /* Hook called by the linker routine which adds symbols from an object
3351 file. We must handle the special NDS32 section numbers here.
3352 We also keep watching for whether we need to create the sdata special
3356 nds32_elf_add_symbol_hook (bfd *abfd,
3357 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3358 Elf_Internal_Sym *sym,
3359 const char **namep ATTRIBUTE_UNUSED,
3360 flagword *flagsp ATTRIBUTE_UNUSED,
3361 asection **secp, bfd_vma *valp)
3363 switch (sym->st_shndx)
3366 /* Common symbols less than the GP size are automatically
3367 treated as SHN_MIPS_SCOMMON symbols. */
3368 if (sym->st_size > elf_gp_size (abfd)
3369 || ELF_ST_TYPE (sym->st_info) == STT_TLS)
3372 /* st_value is the alignemnt constraint.
3373 That might be its actual size if it is an array or structure. */
3374 switch (sym->st_value)
3377 *secp = bfd_make_section_old_way (abfd, ".scommon_b");
3380 *secp = bfd_make_section_old_way (abfd, ".scommon_h");
3383 *secp = bfd_make_section_old_way (abfd, ".scommon_w");
3386 *secp = bfd_make_section_old_way (abfd, ".scommon_d");
3392 (*secp)->flags |= SEC_IS_COMMON;
3393 *valp = sym->st_size;
3400 /* This function can figure out the best location for a base register to access
3401 data relative to this base register
3403 sda_d0: size of first DOUBLE WORD data section
3404 sda_w0: size of first WORD data section
3405 sda_h0: size of first HALF WORD data section
3406 sda_b : size of BYTE data section
3407 sda_hi: size of second HALF WORD data section
3408 sda_w1: size of second WORD data section
3409 sda_d1: size of second DOUBLE WORD data section
3411 offset (always positive) from the beginning of sda_d0 if OK
3412 a negative error value if fail
3414 these 7 sections have to be located back to back if exist
3415 a pass in 0 value for non-existing section */
3417 /* Due to the interpretation of simm15 field of load/store depending on
3418 data accessing size, the organization of base register relative data shall
3419 like the following figure
3420 -------------------------------------------
3421 | DOUBLE WORD sized data (range +/- 128K)
3422 -------------------------------------------
3423 | WORD sized data (range +/- 64K)
3424 -------------------------------------------
3425 | HALF WORD sized data (range +/- 32K)
3426 -------------------------------------------
3427 | BYTE sized data (range +/- 16K)
3428 -------------------------------------------
3429 | HALF WORD sized data (range +/- 32K)
3430 -------------------------------------------
3431 | WORD sized data (range +/- 64K)
3432 -------------------------------------------
3433 | DOUBLE WORD sized data (range +/- 128K)
3434 -------------------------------------------
3435 Its base register shall be set to access these data freely. */
3437 /* We have to figure out the SDA_BASE value, so that we can adjust the
3438 symbol value correctly. We look up the symbol _SDA_BASE_ in the output
3439 BFD. If we can't find it, we're stuck. We cache it in the ELF
3440 target data. We don't need to adjust the symbol value for an
3441 external symbol if we are producing relocatable output. */
3443 static asection *sda_rela_sec = NULL;
3445 #define SDA_SECTION_NUM 10
3447 static bfd_reloc_status_type
3448 nds32_elf_final_sda_base (bfd * output_bfd,
3449 struct bfd_link_info * info,
3451 bfd_boolean add_symbol)
3454 struct elf_nds32_link_hash_table *table;
3455 struct bfd_link_hash_entry *h, *h2;
3456 long unsigned int total = 0;
3457 asection *first = NULL, *final = NULL, *temp;
3458 bfd_vma sda_base = 0;
3460 h = bfd_link_hash_lookup (info->hash, "_SDA_BASE_", FALSE, FALSE, TRUE);
3461 if (!h || (h->type != bfd_link_hash_defined
3462 && h->type != bfd_link_hash_defweak))
3464 /* The first section must be 4-byte aligned to promise _SDA_BASE_ being
3465 4 byte-aligned. Therefore, it has to set the first section ".data"
3467 static const char sec_name[SDA_SECTION_NUM][10] =
3469 ".data", ".got", ".sdata_d", ".sdata_w", ".sdata_h", ".sdata_b",
3470 ".sbss_b", ".sbss_h", ".sbss_w", ".sbss_d"
3474 if (output_bfd->sections == NULL)
3476 *psb = elf_gp (output_bfd);
3477 return bfd_reloc_ok;
3480 /* Get the first and final section. */
3481 while (i < ARRAY_SIZE (sec_name))
3483 temp = bfd_get_section_by_name (output_bfd, sec_name[i]);
3484 if (temp && !first && (temp->size != 0 || temp->rawsize != 0))
3486 if (temp && (temp->size != 0 || temp->rawsize != 0))
3489 /* Summarize the sections in order to check if joining .bss. */
3490 if (temp && temp->size != 0)
3491 total += temp->size;
3492 else if (temp && temp->rawsize != 0)
3493 total += temp->rawsize;
3498 /* Check .bss size. */
3499 temp = bfd_get_section_by_name (output_bfd, ".bss");
3502 if (temp->size != 0)
3503 total += temp->size;
3504 else if (temp->rawsize != 0)
3505 total += temp->rawsize;
3507 if (total < 0x80000)
3509 if (!first && (temp->size != 0 || temp->rawsize != 0))
3511 if ((temp->size != 0 || temp->rawsize != 0))
3518 /* The middle of data region. */
3519 sda_base = final->vma / 2 + final->rawsize / 2 + first->vma / 2;
3521 /* Find the section sda_base located. */
3523 while (i < ARRAY_SIZE (sec_name))
3525 final = bfd_get_section_by_name (output_bfd, sec_name[i]);
3526 if (final && (final->size != 0 || final->rawsize != 0)
3527 && sda_base >= final->vma)
3538 /* If there is not any default data section in output bfd, try to find
3539 the first data section. If no data section be found, just simplily
3540 choose the first output section. */
3541 temp = output_bfd->sections;
3544 if (temp->flags & SEC_ALLOC
3545 && (((temp->flags & SEC_DATA)
3546 && ((temp->flags & SEC_READONLY) == 0))
3547 || (temp->flags & SEC_LOAD) == 0)
3548 && (temp->size != 0 || temp->rawsize != 0))
3557 /* There is no data or bss section. */
3558 if (!first || (first->size == 0 && first->rawsize == 0))
3560 first = output_bfd->sections;
3561 while (first && first->size == 0 && first->rawsize == 0)
3562 first = first->next;
3565 /* There is no concrete section. */
3568 *psb = elf_gp (output_bfd);
3569 return bfd_reloc_ok;
3572 if (final && (final->vma + final->rawsize - first->vma) <= 0x4000)
3573 sda_base = final->vma / 2 + final->rawsize / 2 + first->vma / 2;
3575 sda_base = first->vma + 0x2000;
3578 sda_base -= first->vma;
3579 sda_base = sda_base & (~7);
3581 if (!_bfd_generic_link_add_one_symbol
3582 (info, output_bfd, "_SDA_BASE_", BSF_GLOBAL | BSF_WEAK, first,
3583 (bfd_vma) sda_base, (const char *) NULL, FALSE,
3584 get_elf_backend_data (output_bfd)->collect, &h))
3587 sda_rela_sec = first;
3590 /* Set _FP_BASE_ to _SDA_BASE_. */
3591 table = nds32_elf_hash_table (info);
3592 relax_fp_as_gp = table->relax_fp_as_gp;
3593 h2 = bfd_link_hash_lookup (info->hash, FP_BASE_NAME, FALSE, FALSE, FALSE);
3594 /* _SDA_BASE_ is difined in linker script. */
3597 first = h->u.def.section;
3598 sda_base = h->u.def.value;
3601 if (relax_fp_as_gp && h2
3602 && (h2->type == bfd_link_hash_undefweak
3603 || h2->type == bfd_link_hash_undefined))
3605 /* Define a weak FP_BASE_NAME here to prevent the undefined symbol.
3606 And set FP equal to SDA_BASE to do relaxation for
3607 la $fp, _FP_BASE_. */
3608 if (!_bfd_generic_link_add_one_symbol
3609 (info, output_bfd, FP_BASE_NAME, BSF_GLOBAL | BSF_WEAK,
3610 first, sda_base, (const char *) NULL,
3611 FALSE, get_elf_backend_data (output_bfd)->collect, &h2))
3620 elf_gp (output_bfd) = (h->u.def.value
3621 + h->u.def.section->output_section->vma
3622 + h->u.def.section->output_offset);
3626 _bfd_error_handler (_("error: can't find symbol: %s"), "_SDA_BASE_");
3627 return bfd_reloc_dangerous;
3631 *psb = h->u.def.value
3632 + h->u.def.section->output_section->vma
3633 + h->u.def.section->output_offset;
3634 return bfd_reloc_ok;
3638 /* Return size of a PLT entry. */
3639 #define elf_nds32_sizeof_plt(info) PLT_ENTRY_SIZE
3641 /* Create an entry in an nds32 ELF linker hash table. */
3643 static struct bfd_hash_entry *
3644 nds32_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
3645 struct bfd_hash_table *table,
3648 struct elf_nds32_link_hash_entry *ret;
3650 ret = (struct elf_nds32_link_hash_entry *) entry;
3652 /* Allocate the structure if it has not already been allocated by a
3655 ret = (struct elf_nds32_link_hash_entry *)
3656 bfd_hash_allocate (table, sizeof (struct elf_nds32_link_hash_entry));
3659 return (struct bfd_hash_entry *) ret;
3661 /* Call the allocation method of the superclass. */
3662 ret = (struct elf_nds32_link_hash_entry *)
3663 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string);
3667 struct elf_nds32_link_hash_entry *eh;
3669 eh = (struct elf_nds32_link_hash_entry *) ret;
3670 eh->dyn_relocs = NULL;
3671 eh->tls_type = GOT_UNKNOWN;
3672 eh->offset_to_gp = 0;
3675 return (struct bfd_hash_entry *) ret;
3678 /* Create an nds32 ELF linker hash table. */
3680 static struct bfd_link_hash_table *
3681 nds32_elf_link_hash_table_create (bfd *abfd)
3683 struct elf_nds32_link_hash_table *ret;
3685 bfd_size_type amt = sizeof (struct elf_nds32_link_hash_table);
3687 ret = (struct elf_nds32_link_hash_table *) bfd_zmalloc (amt);
3692 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
3693 nds32_elf_link_hash_newfunc,
3694 sizeof (struct elf_nds32_link_hash_entry),
3701 ret->sdynbss = NULL;
3702 ret->srelbss = NULL;
3703 ret->sym_ld_script = NULL;
3705 return &ret->root.root;
3708 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3709 shortcuts to them in our hash table. */
3712 create_got_section (bfd *dynobj, struct bfd_link_info *info)
3714 struct elf_link_hash_table *ehtab;
3716 if (!_bfd_elf_create_got_section (dynobj, info))
3719 ehtab = elf_hash_table (info);
3720 ehtab->sgot = bfd_get_section_by_name (dynobj, ".got");
3721 ehtab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3722 if (!ehtab->sgot || !ehtab->sgotplt)
3725 /* _bfd_elf_create_got_section will create it for us. */
3726 ehtab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
3727 if (ehtab->srelgot == NULL
3728 || !bfd_set_section_flags (dynobj, ehtab->srelgot,
3729 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3730 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3732 || !bfd_set_section_alignment (dynobj, ehtab->srelgot, 2))
3738 /* Create dynamic sections when linking against a dynamic object. */
3741 nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3743 struct elf_link_hash_table *ehtab;
3744 struct elf_nds32_link_hash_table *htab;
3745 flagword flags, pltflags;
3746 register asection *s;
3747 const struct elf_backend_data *bed;
3748 int ptralign = 2; /* 32-bit */
3749 const char *secname;
3754 bed = get_elf_backend_data (abfd);
3755 ehtab = elf_hash_table (info);
3756 htab = nds32_elf_hash_table (info);
3758 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3759 .rel[a].bss sections. */
3761 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3762 | SEC_LINKER_CREATED);
3765 pltflags |= SEC_CODE;
3766 if (bed->plt_not_loaded)
3767 pltflags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
3768 if (bed->plt_readonly)
3769 pltflags |= SEC_READONLY;
3771 s = bfd_make_section (abfd, ".plt");
3774 || !bfd_set_section_flags (abfd, s, pltflags)
3775 || !bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3778 if (bed->want_plt_sym)
3780 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3782 struct bfd_link_hash_entry *bh = NULL;
3783 struct elf_link_hash_entry *h;
3785 if (!(_bfd_generic_link_add_one_symbol
3786 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3787 (bfd_vma) 0, (const char *) NULL, FALSE,
3788 get_elf_backend_data (abfd)->collect, &bh)))
3791 h = (struct elf_link_hash_entry *) bh;
3793 h->type = STT_OBJECT;
3795 if (bfd_link_pic (info) && !bfd_elf_link_record_dynamic_symbol (info, h))
3799 s = bfd_make_section (abfd,
3800 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3803 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3804 || !bfd_set_section_alignment (abfd, s, ptralign))
3807 if (ehtab->sgot == NULL && !create_got_section (abfd, info))
3810 for (sec = abfd->sections; sec; sec = sec->next)
3812 secflags = bfd_get_section_flags (abfd, sec);
3813 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3814 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3816 secname = bfd_get_section_name (abfd, sec);
3817 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3818 strcpy (relname, ".rela");
3819 strcat (relname, secname);
3820 if (bfd_get_section_by_name (abfd, secname))
3822 s = bfd_make_section (abfd, relname);
3824 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3825 || !bfd_set_section_alignment (abfd, s, ptralign))
3829 if (bed->want_dynbss)
3831 /* The .dynbss section is a place to put symbols which are defined
3832 by dynamic objects, are referenced by regular objects, and are
3833 not functions. We must allocate space for them in the process
3834 image and use a R_*_COPY reloc to tell the dynamic linker to
3835 initialize them at run time. The linker script puts the .dynbss
3836 section into the .bss section of the final image. */
3837 s = bfd_make_section (abfd, ".dynbss");
3840 || !bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
3842 /* The .rel[a].bss section holds copy relocs. This section is not
3843 normally needed. We need to create it here, though, so that the
3844 linker will map it to an output section. We can't just create it
3845 only if we need it, because we will not know whether we need it
3846 until we have seen all the input files, and the first time the
3847 main linker code calls BFD after examining all the input files
3848 (size_dynamic_sections) the input sections have already been
3849 mapped to the output sections. If the section turns out not to
3850 be needed, we can discard it later. We will never need this
3851 section when generating a shared object, since they do not use
3853 if (!bfd_link_pic (info))
3855 s = bfd_make_section (abfd, (bed->default_use_rela_p
3856 ? ".rela.bss" : ".rel.bss"));
3859 || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3860 || !bfd_set_section_alignment (abfd, s, ptralign))
3868 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3870 nds32_elf_copy_indirect_symbol (struct bfd_link_info *info,
3871 struct elf_link_hash_entry *dir,
3872 struct elf_link_hash_entry *ind)
3874 struct elf_nds32_link_hash_entry *edir, *eind;
3876 edir = (struct elf_nds32_link_hash_entry *) dir;
3877 eind = (struct elf_nds32_link_hash_entry *) ind;
3879 if (eind->dyn_relocs != NULL)
3881 if (edir->dyn_relocs != NULL)
3883 struct elf_dyn_relocs **pp;
3884 struct elf_dyn_relocs *p;
3886 if (ind->root.type == bfd_link_hash_indirect)
3889 /* Add reloc counts against the weak sym to the strong sym
3890 list. Merge any entries against the same section. */
3891 for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
3893 struct elf_dyn_relocs *q;
3895 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3896 if (q->sec == p->sec)
3898 q->pc_count += p->pc_count;
3899 q->count += p->count;
3906 *pp = edir->dyn_relocs;
3909 edir->dyn_relocs = eind->dyn_relocs;
3910 eind->dyn_relocs = NULL;
3913 if (ind->root.type == bfd_link_hash_indirect)
3915 if (dir->got.refcount <= 0)
3917 edir->tls_type = eind->tls_type;
3918 eind->tls_type = GOT_UNKNOWN;
3922 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3926 /* Find dynamic relocs for H that apply to read-only sections. */
3929 readonly_dynrelocs (struct elf_link_hash_entry *h)
3931 struct elf_dyn_relocs *p;
3933 for (p = elf32_nds32_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3935 asection *s = p->sec->output_section;
3937 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3943 /* Adjust a symbol defined by a dynamic object and referenced by a
3944 regular object. The current definition is in some section of the
3945 dynamic object, but we're not including those sections. We have to
3946 change the definition to something the rest of the link can
3950 nds32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3951 struct elf_link_hash_entry *h)
3953 struct elf_nds32_link_hash_table *htab;
3956 unsigned int power_of_two;
3958 dynobj = elf_hash_table (info)->dynobj;
3960 /* Make sure we know what is going on here. */
3961 BFD_ASSERT (dynobj != NULL
3964 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
3967 /* If this is a function, put it in the procedure linkage table. We
3968 will fill in the contents of the procedure linkage table later,
3969 when we know the address of the .got section. */
3970 if (h->type == STT_FUNC || h->needs_plt)
3972 if (!bfd_link_pic (info)
3975 && h->root.type != bfd_link_hash_undefweak
3976 && h->root.type != bfd_link_hash_undefined)
3978 /* This case can occur if we saw a PLT reloc in an input
3979 file, but the symbol was never referred to by a dynamic
3980 object. In such a case, we don't actually need to build
3981 a procedure linkage table, and we can just do a PCREL
3983 h->plt.offset = (bfd_vma) - 1;
3990 h->plt.offset = (bfd_vma) - 1;
3992 /* If this is a weak symbol, and there is a real definition, the
3993 processor independent code will have arranged for us to see the
3994 real definition first, and we can just use the same value. */
3995 if (h->is_weakalias)
3997 struct elf_link_hash_entry *def = weakdef (h);
3998 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
3999 h->root.u.def.section = def->root.u.def.section;
4000 h->root.u.def.value = def->root.u.def.value;
4004 /* This is a reference to a symbol defined by a dynamic object which
4005 is not a function. */
4007 /* If we are creating a shared library, we must presume that the
4008 only references to the symbol are via the global offset table.
4009 For such cases we need not do anything here; the relocations will
4010 be handled correctly by relocate_section. */
4011 if (bfd_link_pic (info))
4014 /* If there are no references to this symbol that do not use the
4015 GOT, we don't need to generate a copy reloc. */
4016 if (!h->non_got_ref)
4019 /* If -z nocopyreloc was given, we won't generate them either. */
4020 if (0 && info->nocopyreloc)
4026 /* If we don't find any dynamic relocs in read-only sections, then
4027 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4028 if (!readonly_dynrelocs (h))
4034 /* We must allocate the symbol in our .dynbss section, which will
4035 become part of the .bss section of the executable. There will be
4036 an entry for this symbol in the .dynsym section. The dynamic
4037 object will contain position independent code, so all references
4038 from the dynamic object to this symbol will go through the global
4039 offset table. The dynamic linker will use the .dynsym entry to
4040 determine the address it must put in the global offset table, so
4041 both the dynamic object and the regular object will refer to the
4042 same memory location for the variable. */
4044 htab = nds32_elf_hash_table (info);
4046 BFD_ASSERT (s != NULL);
4048 /* We must generate a R_NDS32_COPY reloc to tell the dynamic linker
4049 to copy the initial value out of the dynamic object and into the
4050 runtime process image. We need to remember the offset into the
4051 .rela.bss section we are going to use. */
4052 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4056 srel = htab->srelbss;
4057 BFD_ASSERT (srel != NULL);
4058 srel->size += sizeof (Elf32_External_Rela);
4062 /* We need to figure out the alignment required for this symbol. I
4063 have no idea how ELF linkers handle this. */
4064 power_of_two = bfd_log2 (h->size);
4065 if (power_of_two > 3)
4068 /* Apply the required alignment. */
4069 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4070 if (power_of_two > bfd_get_section_alignment (dynobj, s))
4072 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
4076 /* Define the symbol as being at this point in the section. */
4077 h->root.u.def.section = s;
4078 h->root.u.def.value = s->size;
4080 /* Increment the section size to make room for the symbol. */
4086 /* Allocate space in .plt, .got and associated reloc sections for
4090 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4092 struct bfd_link_info *info;
4093 struct elf_link_hash_table *ehtab;
4094 struct elf_nds32_link_hash_table *htab;
4095 struct elf_nds32_link_hash_entry *eh;
4096 struct elf_dyn_relocs *p;
4098 if (h->root.type == bfd_link_hash_indirect)
4101 /* When warning symbols are created, they **replace** the "real"
4102 entry in the hash table, thus we never get to see the real
4103 symbol in a hash traversal. So look at it now. */
4104 if (h->root.type == bfd_link_hash_warning)
4105 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4107 eh = (struct elf_nds32_link_hash_entry *) h;
4109 info = (struct bfd_link_info *) inf;
4110 ehtab = elf_hash_table (info);
4111 htab = nds32_elf_hash_table (info);
4115 eh = (struct elf_nds32_link_hash_entry *) h;
4117 if ((htab->root.dynamic_sections_created || h->type == STT_GNU_IFUNC)
4118 && h->plt.refcount > 0
4119 && !(bfd_link_pie (info) && h->def_regular))
4121 /* Make sure this symbol is output as a dynamic symbol.
4122 Undefined weak syms won't yet be marked as dynamic. */
4123 if (h->dynindx == -1 && !h->forced_local)
4125 if (!bfd_elf_link_record_dynamic_symbol (info, h))
4129 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
4131 asection *s = ehtab->splt;
4133 /* If this is the first .plt entry, make room for the special
4136 s->size += PLT_ENTRY_SIZE;
4138 h->plt.offset = s->size;
4140 /* If this symbol is not defined in a regular file, and we are
4141 not generating a shared library, then set the symbol to this
4142 location in the .plt. This is required to make function
4143 pointers compare as equal between the normal executable and
4144 the shared library. */
4145 if (!bfd_link_pic (info) && !h->def_regular)
4147 h->root.u.def.section = s;
4148 h->root.u.def.value = h->plt.offset;
4151 /* Make room for this entry. */
4152 s->size += PLT_ENTRY_SIZE;
4154 /* We also need to make an entry in the .got.plt section, which
4155 will be placed in the .got section by the linker script. */
4156 ehtab->sgotplt->size += 4;
4158 /* We also need to make an entry in the .rel.plt section. */
4159 ehtab->srelplt->size += sizeof (Elf32_External_Rela);
4160 if (htab->tls_desc_trampoline)
4161 htab->next_tls_desc_index++;
4165 h->plt.offset = (bfd_vma) - 1;
4171 h->plt.offset = (bfd_vma) - 1;
4175 if (h->got.refcount > 0)
4179 int tls_type = elf32_nds32_hash_entry (h)->tls_type;
4181 /* Make sure this symbol is output as a dynamic symbol.
4182 Undefined weak syms won't yet be marked as dynamic. */
4183 if (h->dynindx == -1 && !h->forced_local)
4185 if (!bfd_elf_link_record_dynamic_symbol (info, h))
4189 sgot = elf_hash_table (info)->sgot;
4190 h->got.offset = sgot->size;
4192 if (tls_type == GOT_UNKNOWN)
4195 /* Non-TLS symbols, and TLS_IE need one GOT slot. */
4196 if (tls_type & (GOT_NORMAL | GOT_TLS_IE | GOT_TLS_IEGP))
4200 /* TLS_DESC, TLS_GD, and TLS_LD need 2 consecutive GOT slots. */
4201 if (tls_type & GOT_TLS_DESC)
4205 dyn = htab->root.dynamic_sections_created;
4207 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
4209 if (tls_type == GOT_TLS_DESC && htab->tls_desc_trampoline)
4211 /* TLS_DESC with trampoline needs a relocation slot
4212 within .rela.plt. */
4213 htab->num_tls_desc++;
4214 ehtab->srelplt->size += sizeof (Elf32_External_Rela);
4215 htab->tls_trampoline = -1;
4219 /* other relocations, including TLS_DESC without trampoline, need
4220 a relocation slot within .rela.got. */
4221 ehtab->srelgot->size += sizeof (Elf32_External_Rela);
4226 h->got.offset = (bfd_vma)-1;
4228 if (eh->dyn_relocs == NULL)
4231 /* In the shared -Bsymbolic case, discard space allocated for
4232 dynamic pc-relative relocs against symbols which turn out to be
4233 defined in regular objects. For the normal shared case, discard
4234 space for pc-relative relocs that have become local due to symbol
4235 visibility changes. */
4237 if (bfd_link_pic (info))
4239 if (h->def_regular && (h->forced_local || info->symbolic))
4241 struct elf_dyn_relocs **pp;
4243 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
4245 p->count -= p->pc_count;
4256 /* For the non-shared case, discard space for relocs against
4257 symbols which turn out to need copy relocs or are not dynamic. */
4262 || (htab->root.dynamic_sections_created
4263 && (h->root.type == bfd_link_hash_undefweak
4264 || h->root.type == bfd_link_hash_undefined))))
4266 /* Make sure this symbol is output as a dynamic symbol.
4267 Undefined weak syms won't yet be marked as dynamic. */
4268 if (h->dynindx == -1 && !h->forced_local)
4270 if (!bfd_elf_link_record_dynamic_symbol (info, h))
4274 /* If that succeeded, we know we'll be keeping all the
4276 if (h->dynindx != -1)
4280 eh->dyn_relocs = NULL;
4285 /* Finally, allocate space. */
4286 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4288 asection *sreloc = elf_section_data (p->sec)->sreloc;
4289 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4295 /* Add relocation REL to the end of relocation section SRELOC. */
4298 elf32_nds32_add_dynreloc (bfd *output_bfd,
4299 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4300 asection *sreloc, Elf_Internal_Rela *rel)
4306 loc = sreloc->contents;
4307 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4308 if (sreloc->reloc_count * sizeof (Elf32_External_Rela) > sreloc->size)
4311 bfd_elf32_swap_reloca_out (output_bfd, rel, loc);
4314 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
4315 read-only sections. */
4318 maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
4322 if (h->root.type == bfd_link_hash_indirect)
4325 sec = readonly_dynrelocs (h);
4328 struct bfd_link_info *info = (struct bfd_link_info *) info_p;
4330 info->flags |= DF_TEXTREL;
4331 info->callbacks->minfo
4332 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
4333 sec->owner, h->root.root.string, sec);
4335 /* Not an error, just cut short the traversal. */
4341 /* Set the sizes of the dynamic sections. */
4344 nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4345 struct bfd_link_info *info)
4347 struct elf_nds32_link_hash_table *htab;
4354 htab = nds32_elf_hash_table (info);
4358 dynobj = elf_hash_table (info)->dynobj;
4359 BFD_ASSERT (dynobj != NULL);
4361 if (elf_hash_table (info)->dynamic_sections_created)
4363 /* Set the contents of the .interp section to the interpreter. */
4364 if (bfd_link_executable (info) && !info->nointerp)
4366 s = bfd_get_section_by_name (dynobj, ".interp");
4367 BFD_ASSERT (s != NULL);
4368 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4369 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4373 /* Set up .got offsets for local syms, and space for local dynamic
4375 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
4377 bfd_signed_vma *local_got;
4378 bfd_signed_vma *end_local_got;
4379 bfd_size_type locsymcount;
4380 Elf_Internal_Shdr *symtab_hdr;
4382 char *local_tls_type;
4383 unsigned long symndx;
4384 bfd_vma *local_tlsdesc_gotent;
4386 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4389 for (s = ibfd->sections; s != NULL; s = s->next)
4391 struct elf_dyn_relocs *p;
4393 for (p = ((struct elf_dyn_relocs *)
4394 elf_section_data (s)->local_dynrel);
4395 p != NULL; p = p->next)
4397 if (!bfd_is_abs_section (p->sec)
4398 && bfd_is_abs_section (p->sec->output_section))
4400 /* Input section has been discarded, either because
4401 it is a copy of a linkonce section or due to
4402 linker script /DISCARD/, so we'll be discarding
4405 else if (p->count != 0)
4407 asection *sreloc = elf_section_data (p->sec)->sreloc;
4408 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4409 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4410 info->flags |= DF_TEXTREL;
4415 local_got = elf_local_got_refcounts (ibfd);
4419 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4420 locsymcount = symtab_hdr->sh_info;
4421 end_local_got = local_got + locsymcount;
4422 sgot = elf_hash_table (info)->sgot;
4423 local_tls_type = elf32_nds32_local_got_tls_type (ibfd);
4424 local_tlsdesc_gotent = elf32_nds32_local_tlsdesc_gotent (ibfd);
4425 for (symndx = 0; local_got < end_local_got;
4426 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent, ++symndx)
4430 int num_of_got_entry_needed = 0;
4431 *local_got = sgot->size;
4432 *local_tlsdesc_gotent = sgot->size;
4434 /* TLS_NORMAL, and TLS_IE need one slot in .got. */
4435 if (*local_tls_type & (GOT_NORMAL | GOT_TLS_IE | GOT_TLS_IEGP))
4436 num_of_got_entry_needed = 1;
4437 /* TLS_GD, TLS_LD, and TLS_DESC need an 8-byte structure in the GOT. */
4438 else if (*local_tls_type & GOT_TLS_DESC)
4439 num_of_got_entry_needed = 2;
4441 sgot->size += (num_of_got_entry_needed << 2);
4443 /* non-relax-able TLS_DESCs need a slot in .rela.plt.
4444 others need a slot in .rela.got. */
4445 if (*local_tls_type == GOT_TLS_DESC)
4447 if (bfd_link_pic (info))
4449 if (htab->tls_desc_trampoline)
4451 htab->num_tls_desc++;
4452 htab->root.srelplt->size += sizeof (Elf32_External_Rela);
4453 htab->tls_trampoline = -1;
4456 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
4460 /* TLS_DESC -> TLS_LE */
4465 htab->root.srelgot->size += sizeof (Elf32_External_Rela);
4470 *local_got = (bfd_vma) -1;
4471 *local_tlsdesc_gotent = (bfd_vma) -1;
4476 /* Allocate global sym .plt and .got entries, and space for global
4477 sym dynamic relocs. */
4478 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (void *) info);
4480 /* For every jump slot reserved in the sgotplt, reloc_count is
4481 incremented. However, when we reserve space for TLS descriptors,
4482 it's not incremented, so in order to compute the space reserved
4483 for them, it suffices to multiply the reloc count by the jump
4485 if (htab->tls_desc_trampoline && htab->root.srelplt)
4486 htab->sgotplt_jump_table_size = elf32_nds32_compute_jump_table_size (htab);
4488 if (htab->tls_trampoline)
4490 htab->tls_trampoline = htab->root.splt->size;
4492 /* If we're not using lazy TLS relocations, don't generate the
4493 PLT and GOT entries they require. */
4494 if (!(info->flags & DF_BIND_NOW))
4496 htab->dt_tlsdesc_got = htab->root.sgot->size;
4497 htab->root.sgot->size += 4;
4499 htab->dt_tlsdesc_plt = htab->root.splt->size;
4500 htab->root.splt->size += 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline);
4504 /* We now have determined the sizes of the various dynamic sections.
4505 Allocate memory for them. */
4506 /* The check_relocs and adjust_dynamic_symbol entry points have
4507 determined the sizes of the various dynamic sections. Allocate
4511 for (s = dynobj->sections; s != NULL; s = s->next)
4513 if ((s->flags & SEC_LINKER_CREATED) == 0)
4516 if (s == htab->root.splt)
4518 /* Strip this section if we don't need it; see the
4522 else if (s == elf_hash_table (info)->sgot)
4524 got_size += s->size;
4526 else if (s == elf_hash_table (info)->sgotplt)
4528 got_size += s->size;
4530 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4532 if (s->size != 0 && s != elf_hash_table (info)->srelplt)
4535 /* We use the reloc_count field as a counter if we need
4536 to copy relocs into the output file. */
4541 /* It's not one of our sections, so don't allocate space. */
4547 /* If we don't need this section, strip it from the
4548 output file. This is mostly to handle .rela.bss and
4549 .rela.plt. We must create both sections in
4550 create_dynamic_sections, because they must be created
4551 before the linker maps input sections to output
4552 sections. The linker does that before
4553 adjust_dynamic_symbol is called, and it is that
4554 function which decides whether anything needs to go
4555 into these sections. */
4556 s->flags |= SEC_EXCLUDE;
4560 /* Allocate memory for the section contents. We use bfd_zalloc
4561 here in case unused entries are not reclaimed before the
4562 section's contents are written out. This should not happen,
4563 but this way if it does, we get a R_NDS32_NONE reloc instead
4565 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4566 if (s->contents == NULL)
4571 if (htab->root.dynamic_sections_created)
4573 /* Add some entries to the .dynamic section. We fill in the
4574 values later, in nds32_elf_finish_dynamic_sections, but we
4575 must add the entries now so that we get the correct size for
4576 the .dynamic section. The DT_DEBUG entry is filled in by the
4577 dynamic linker and used by the debugger. */
4578 #define add_dynamic_entry(TAG, VAL) \
4579 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4581 if (bfd_link_executable (info))
4583 if (!add_dynamic_entry (DT_DEBUG, 0))
4587 if (elf_hash_table (info)->splt->size != 0)
4589 if (!add_dynamic_entry (DT_PLTGOT, 0)
4590 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4591 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4592 || !add_dynamic_entry (DT_JMPREL, 0))
4596 if (htab->tls_desc_trampoline && plt)
4598 if (htab->dt_tlsdesc_plt
4599 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
4600 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
4606 if (!add_dynamic_entry (DT_RELA, 0)
4607 || !add_dynamic_entry (DT_RELASZ, 0)
4608 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
4611 /* If any dynamic relocs apply to a read-only section,
4612 then we need a DT_TEXTREL entry. */
4613 if ((info->flags & DF_TEXTREL) == 0)
4614 elf_link_hash_traverse (&htab->root, maybe_set_textrel,
4617 if ((info->flags & DF_TEXTREL) != 0)
4619 if (!add_dynamic_entry (DT_TEXTREL, 0))
4624 #undef add_dynamic_entry
4629 static bfd_reloc_status_type
4630 nds32_relocate_contents (reloc_howto_type *howto, bfd *input_bfd,
4631 bfd_vma relocation, bfd_byte *location)
4635 bfd_reloc_status_type flag;
4636 unsigned int rightshift = howto->rightshift;
4637 unsigned int bitpos = howto->bitpos;
4639 /* If the size is negative, negate RELOCATION. This isn't very
4641 if (howto->size < 0)
4642 relocation = -relocation;
4644 /* Get the value we are going to relocate. */
4645 size = bfd_get_reloc_size (howto);
4652 return bfd_reloc_ok;
4654 x = bfd_getb16 (location);
4657 x = bfd_getb32 (location);
4661 /* Check for overflow. FIXME: We may drop bits during the addition
4662 which we don't check for. We must either check at every single
4663 operation, which would be tedious, or we must do the computations
4664 in a type larger than bfd_vma, which would be inefficient. */
4665 flag = bfd_reloc_ok;
4666 if (howto->complain_on_overflow != complain_overflow_dont)
4668 bfd_vma addrmask, fieldmask, signmask, ss;
4671 /* Get the values to be added together. For signed and unsigned
4672 relocations, we assume that all values should be truncated to
4673 the size of an address. For bitfields, all the bits matter.
4674 See also bfd_check_overflow. */
4675 fieldmask = N_ONES (howto->bitsize);
4676 signmask = ~fieldmask;
4677 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
4678 a = (relocation & addrmask) >> rightshift;
4679 b = (x & howto->src_mask & addrmask) >> bitpos;
4681 switch (howto->complain_on_overflow)
4683 case complain_overflow_signed:
4684 /* If any sign bits are set, all sign bits must be set.
4685 That is, A must be a valid negative address after
4687 signmask = ~(fieldmask >> 1);
4690 case complain_overflow_bitfield:
4691 /* Much like the signed check, but for a field one bit
4692 wider. We allow a bitfield to represent numbers in the
4693 range -2**n to 2**n-1, where n is the number of bits in the
4694 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
4695 can't overflow, which is exactly what we want. */
4697 if (ss != 0 && ss != ((addrmask >> rightshift) & signmask))
4698 flag = bfd_reloc_overflow;
4700 /* We only need this next bit of code if the sign bit of B
4701 is below the sign bit of A. This would only happen if
4702 SRC_MASK had fewer bits than BITSIZE. Note that if
4703 SRC_MASK has more bits than BITSIZE, we can get into
4704 trouble; we would need to verify that B is in range, as
4705 we do for A above. */
4706 ss = ((~howto->src_mask) >> 1) & howto->src_mask;
4709 /* Set all the bits above the sign bit. */
4712 /* Now we can do the addition. */
4715 /* See if the result has the correct sign. Bits above the
4716 sign bit are junk now; ignore them. If the sum is
4717 positive, make sure we did not have all negative inputs;
4718 if the sum is negative, make sure we did not have all
4719 positive inputs. The test below looks only at the sign
4720 bits, and it really just
4721 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
4723 We mask with addrmask here to explicitly allow an address
4724 wrap-around. The Linux kernel relies on it, and it is
4725 the only way to write assembler code which can run when
4726 loaded at a location 0x80000000 away from the location at
4727 which it is linked. */
4728 if (((~(a ^ b)) & (a ^ sum)) & signmask & addrmask)
4729 flag = bfd_reloc_overflow;
4733 case complain_overflow_unsigned:
4734 /* Checking for an unsigned overflow is relatively easy:
4735 trim the addresses and add, and trim the result as well.
4736 Overflow is normally indicated when the result does not
4737 fit in the field. However, we also need to consider the
4738 case when, e.g., fieldmask is 0x7fffffff or smaller, an
4739 input is 0x80000000, and bfd_vma is only 32 bits; then we
4740 will get sum == 0, but there is an overflow, since the
4741 inputs did not fit in the field. Instead of doing a
4742 separate test, we can check for this by or-ing in the
4743 operands when testing for the sum overflowing its final
4745 sum = (a + b) & addrmask;
4746 if ((a | b | sum) & signmask)
4747 flag = bfd_reloc_overflow;
4755 /* Put RELOCATION in the right bits. */
4756 relocation >>= (bfd_vma) rightshift;
4757 relocation <<= (bfd_vma) bitpos;
4759 /* Add RELOCATION to the right bits of X. */
4761 Because the relaxation may generate duplicate relocation at one address,
4762 an addition to immediate in the instruction may cause the relocation added
4764 This bug should be fixed in assembler, but a check is also needed here. */
4765 if (howto->partial_inplace)
4766 x = ((x & ~howto->dst_mask)
4767 | (((x & howto->src_mask) + relocation) & howto->dst_mask));
4769 x = ((x & ~howto->dst_mask) | ((relocation) & howto->dst_mask));
4772 /* Put the relocated value back in the object file. */
4782 bfd_putb16 (x, location);
4785 bfd_putb32 (x, location);
4792 static bfd_reloc_status_type
4793 nds32_elf_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
4794 asection *input_section, bfd_byte *contents,
4795 bfd_vma address, bfd_vma value, bfd_vma addend)
4799 /* Sanity check the address. */
4800 if (address > bfd_get_section_limit (input_bfd, input_section))
4801 return bfd_reloc_outofrange;
4803 /* This function assumes that we are dealing with a basic relocation
4804 against a symbol. We want to compute the value of the symbol to
4805 relocate to. This is just VALUE, the value of the symbol, plus
4806 ADDEND, any addend associated with the reloc. */
4807 relocation = value + addend;
4809 /* If the relocation is PC relative, we want to set RELOCATION to
4810 the distance between the symbol (currently in RELOCATION) and the
4811 location we are relocating. If pcrel_offset is FALSE we do not
4812 need to subtract out the offset of the location within the
4813 section (which is just ADDRESS). */
4814 if (howto->pc_relative)
4816 relocation -= (input_section->output_section->vma
4817 + input_section->output_offset);
4818 if (howto->pcrel_offset)
4819 relocation -= address;
4822 return nds32_relocate_contents (howto, input_bfd, relocation,
4823 contents + address);
4827 nds32_elf_output_symbol_hook (struct bfd_link_info *info,
4829 Elf_Internal_Sym *elfsym ATTRIBUTE_UNUSED,
4830 asection *input_sec,
4831 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
4834 FILE *sym_ld_script = NULL;
4835 struct elf_nds32_link_hash_table *table;
4837 table = nds32_elf_hash_table (info);
4838 sym_ld_script = table->sym_ld_script;
4842 if (!h || !name || *name == '\0')
4845 if (input_sec->flags & SEC_EXCLUDE)
4848 if (!check_start_export_sym)
4850 fprintf (sym_ld_script, "SECTIONS\n{\n");
4851 check_start_export_sym = 1;
4854 if (h->root.type == bfd_link_hash_defined
4855 || h->root.type == bfd_link_hash_defweak)
4857 if (!h->root.u.def.section->output_section)
4860 if (bfd_is_const_section (input_sec))
4861 source = input_sec->name;
4863 source = input_sec->owner->filename;
4865 fprintf (sym_ld_script, "\t%s = 0x%08lx;\t /* %s */\n",
4866 h->root.root.string,
4867 (long) (h->root.u.def.value
4868 + h->root.u.def.section->output_section->vma
4869 + h->root.u.def.section->output_offset), source);
4875 /* Relocate an NDS32/D ELF section.
4876 There is some attempt to make this function usable for many architectures,
4877 both for RELA and REL type relocs, if only to serve as a learning tool.
4879 The RELOCATE_SECTION function is called by the new ELF backend linker
4880 to handle the relocations for a section.
4882 The relocs are always passed as Rela structures; if the section
4883 actually uses Rel structures, the r_addend field will always be
4886 This function is responsible for adjust the section contents as
4887 necessary, and (if using Rela relocs and generating a
4888 relocatable output file) adjusting the reloc addend as
4891 This function does not have to worry about setting the reloc
4892 address or the reloc symbol index.
4894 LOCAL_SYMS is a pointer to the swapped in local symbols.
4896 LOCAL_SECTIONS is an array giving the section in the input file
4897 corresponding to the st_shndx field of each local symbol.
4899 The global hash table entry for the global symbols can be found
4900 via elf_sym_hashes (input_bfd).
4902 When generating relocatable output, this function must handle
4903 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4904 going to be the section symbol corresponding to the output
4905 section, which means that the addend must be adjusted
4908 /* Return the base VMA address which should be subtracted from real addresses
4909 when resolving @dtpoff relocation.
4910 This is PT_TLS segment p_vaddr. */
4912 /* Return the relocation value for @tpoff relocation
4913 if STT_TLS virtual address is ADDRESS. */
4915 /* Return the relocation value for @gottpoff relocation
4916 if STT_TLS virtual address is ADDRESS. */
4919 gottpoff (struct bfd_link_info *info, bfd_vma address)
4924 /* If tls_sec is NULL, we should have signalled an error already. */
4925 if (elf_hash_table (info)->tls_sec == NULL)
4928 tp_base = elf_hash_table (info)->tls_sec->vma;
4929 tp_offset = address - tp_base;
4935 patch_tls_desc_to_ie (bfd_byte *contents, Elf_Internal_Rela *rel, bfd *ibfd)
4937 /* TLS_GD/TLS_LD model #1
4938 46 00 00 00 sethi $r0,#0x0
4939 58 00 00 00 ori $r0,$r0,#0x0
4940 40 00 74 00 add $r0,$r0,$gp
4941 04 10 00 00 lwi $r1,[$r0+#0x0]
4942 4b e0 04 01 jral $lp,$r1 */
4944 /* TLS_GD/TLS_LD model #2
4945 46 00 00 00 sethi $r0,#0x0
4946 58 00 00 00 ori $r0,$r0,#0x0
4947 38 10 74 02 lw $r1,[$r0+($gp<<#0x0)]
4948 40 00 74 00 add $r0,$r0,$gp
4949 4b e0 04 01 jral $lp,$r1 */
4951 /* TLS_IE model (non-PIC)
4952 46 00 00 00 sethi $r0,#0x0
4953 04 00 00 00 lwi $r0,[$r0+#0x0]
4954 38 00 64 02 lw $r0,[$r0+($r25<<#0x0)] */
4956 /* TLS_IE model (PIC)
4957 46 00 00 00 sethi $r0,#0x0
4958 58 00 00 00 ori $r0,$r0,#0x0
4959 38 00 74 02 lw $r0,[$r0+($gp<<#0x0)]
4960 38 00 64 02 lw $r0,[$r0+($r25<<#0x0)] */
4962 /* TLS_GD_TO_IE model
4963 46 00 00 00 sethi $r0,#0x0
4964 58 00 00 00 ori $r0,$r0,#0x0
4965 40 00 74 00 add $r0,$rM,$gp
4966 04 00 00 01 lwi $r0,[$r0+#0x4]
4967 40 00 64 00 add $r0,$r0,$r25 */
4969 bfd_boolean rz = FALSE;
4979 0x40007400, /* add $r0,$rM,$gp */
4980 0x04000001, /* lwi $r0,[$r0+#0x4] */
4981 0x40006400, /* add $r0,$r0,$r25 */
4986 { 0x40000000, 0xfe0003ff },
4987 { 0x04000000, 0xfe000000 },
4988 { 0x4be00001, 0xffff83ff },
4993 { 0x38007402, 0xfe007fff },
4994 { 0x40007400, 0xfe007fff },
4995 { 0x4be00001, 0xffff83ff },
4998 unsigned char *p = contents + rel->r_offset;
5001 uint32_t regidx = 0;
5002 insn = bfd_getb32 (p);
5003 if (INSN_SETHI == (0xfe0fffffu & insn))
5005 regidx = 0x1f & (insn >> 20);
5009 insn = bfd_getb32 (p);
5010 if (INSN_ORI == (0xfe007fffu & insn))
5012 regidx = 0x1f & (insn >> 20);
5016 if (patch[2] == bfd_getb32 (p + 8)) /* Character instruction. */
5018 /* already patched? */
5019 if ((patch[0] == (0xfff07fffu & bfd_getb32 (p + 0))) &&
5020 (patch[1] == bfd_getb32 (p + 4)))
5023 else if (mode0[0].opcode == (mode0[0].mask & bfd_getb32 (p + 0)))
5025 if ((mode0[1].opcode == (mode0[1].mask & bfd_getb32 (p + 4))) &&
5026 (mode0[2].opcode == (mode0[2].mask & bfd_getb32 (p + 8))))
5028 bfd_putb32 (patch[0] | (regidx << 15), p + 0);
5029 bfd_putb32 (patch[1], p + 4);
5030 bfd_putb32 (patch[2], p + 8);
5034 else if (mode1[0].opcode == (mode1[0].mask & bfd_getb32 (p + 0)))
5036 if ((mode1[1].opcode == (mode1[1].mask & bfd_getb32 (p + 4))) &&
5037 (mode1[2].opcode == (mode1[2].mask & bfd_getb32 (p + 8))))
5039 bfd_putb32 (patch[0] | (regidx << 15), p + 0);
5040 bfd_putb32 (patch[1], p + 4);
5041 bfd_putb32 (patch[2], p + 8);
5048 printf ("%s: %s @ 0x%08x\n", __func__, ibfd->filename,
5049 (int) rel->r_offset);
5050 BFD_ASSERT(0); /* Unsupported pattern. */
5056 static enum elf_nds32_tls_type
5057 get_tls_type (enum elf_nds32_reloc_type r_type, struct elf_link_hash_entry *h);
5060 ones32 (register unsigned int x)
5062 /* 32-bit recursive reduction using SWAR...
5063 but first step is mapping 2-bit values
5064 into sum of 2 1-bit values in sneaky way. */
5065 x -= ((x >> 1) & 0x55555555);
5066 x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
5067 x = (((x >> 4) + x) & 0x0f0f0f0f);
5070 return (x & 0x0000003f);
5075 fls (register unsigned int x)
5077 return ffs (x & (-x));
5079 #endif /* !HAVE_FLS */
5081 #define nds32_elf_local_tlsdesc_gotent(bfd) \
5082 (elf_nds32_tdata (bfd)->local_tlsdesc_gotent)
5085 nds32_elf_relocate_section (bfd * output_bfd ATTRIBUTE_UNUSED,
5086 struct bfd_link_info * info,
5088 asection * input_section,
5089 bfd_byte * contents,
5090 Elf_Internal_Rela * relocs,
5091 Elf_Internal_Sym * local_syms,
5092 asection ** local_sections)
5094 Elf_Internal_Shdr *symtab_hdr;
5095 struct elf_link_hash_entry **sym_hashes;
5096 Elf_Internal_Rela *rel, *relend;
5097 bfd_boolean ret = TRUE; /* Assume success. */
5099 bfd_reloc_status_type r;
5100 const char *errmsg = NULL;
5102 struct elf_link_hash_table *ehtab;
5103 struct elf_nds32_link_hash_table *htab;
5105 bfd_vma *local_got_offsets;
5106 asection *sgot, *splt, *sreloc;
5107 bfd_vma high_address;
5108 struct elf_nds32_link_hash_table *table;
5109 int eliminate_gc_relocs;
5110 bfd_vma fpbase_addr;
5112 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5113 sym_hashes = elf_sym_hashes (input_bfd);
5114 ehtab = elf_hash_table (info);
5115 htab = nds32_elf_hash_table (info);
5116 high_address = bfd_get_section_limit (input_bfd, input_section);
5118 dynobj = htab->root.dynobj;
5119 local_got_offsets = elf_local_got_offsets (input_bfd);
5126 relend = relocs + input_section->reloc_count;
5128 table = nds32_elf_hash_table (info);
5129 eliminate_gc_relocs = table->eliminate_gc_relocs;
5131 /* By this time, we can adjust the value of _SDA_BASE_. */
5132 /* Explain _SDA_BASE_ */
5133 if ((!bfd_link_relocatable (info)))
5135 is_SDA_BASE_set = 1;
5136 r = nds32_elf_final_sda_base (output_bfd, info, &gp, TRUE);
5137 if (r != bfd_reloc_ok)
5141 /* Do TLS model conversion once at first. */
5142 nds32_elf_unify_tls_model (input_bfd, input_section, contents, info);
5144 /* Use gp as fp to prevent truncated fit. Because in relaxation time
5145 the fp value is set as gp, and it has be reverted for instruction
5147 fpbase_addr = elf_gp (output_bfd);
5149 /* Deal with (dynamic) relocations. */
5150 for (rel = relocs; rel < relend; rel++)
5152 enum elf_nds32_reloc_type r_type;
5153 reloc_howto_type *howto = NULL;
5154 unsigned long r_symndx;
5155 struct elf_link_hash_entry *h = NULL;
5156 Elf_Internal_Sym *sym = NULL;
5159 bfd_vma relocation_sym = 0xdeadbeef;
5160 Elf_Internal_Rela *lorel;
5163 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
5164 ensure it's zero (we use REL relocs, not RELA). Therefore this
5165 should be assigning zero to `addend', but for clarity we use
5168 bfd_vma addend = rel->r_addend;
5169 bfd_vma offset = rel->r_offset;
5171 r_type = ELF32_R_TYPE (rel->r_info);
5172 if (r_type >= R_NDS32_max)
5174 /* xgettext:c-format */
5175 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
5177 bfd_set_error (bfd_error_bad_value);
5182 if (r_type == R_NDS32_GNU_VTENTRY
5183 || r_type == R_NDS32_GNU_VTINHERIT
5184 || r_type == R_NDS32_NONE
5185 || r_type == R_NDS32_RELA_GNU_VTENTRY
5186 || r_type == R_NDS32_RELA_GNU_VTINHERIT
5187 || (r_type >= R_NDS32_INSN16 && r_type <= R_NDS32_25_FIXED_RELA)
5188 || r_type == R_NDS32_DATA
5189 || r_type == R_NDS32_TRAN)
5192 /* If we enter the fp-as-gp region. Resolve the address
5194 if (ELF32_R_TYPE (rel->r_info) == R_NDS32_RELAX_REGION_BEGIN
5195 && (rel->r_addend & R_NDS32_RELAX_REGION_OMIT_FP_FLAG))
5199 /* Distance to relocation of best fp-base is encoded in R_SYM. */
5200 dist = rel->r_addend >> 16;
5201 fpbase_addr = calculate_memory_address (input_bfd, rel + dist,
5202 local_syms, symtab_hdr);
5204 else if (ELF32_R_TYPE (rel->r_info) == R_NDS32_RELAX_REGION_END
5205 && (rel->r_addend & R_NDS32_RELAX_REGION_OMIT_FP_FLAG))
5207 fpbase_addr = elf_gp (output_bfd);
5210 /* Skip the relocations used for relaxation. */
5211 /* We have to update LONGCALL and LONGJUMP
5212 relocations when generating the relocatable files. */
5213 if (!bfd_link_relocatable (info)
5214 && (r_type >= R_NDS32_RELAX_ENTRY
5215 || (r_type >= R_NDS32_LONGCALL4
5216 && r_type <= R_NDS32_LONGJUMP7)))
5219 howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
5220 r_symndx = ELF32_R_SYM (rel->r_info);
5222 /* This is a final link. */
5227 if (r_symndx < symtab_hdr->sh_info)
5230 sym = local_syms + r_symndx;
5231 sec = local_sections[r_symndx];
5233 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5234 addend = rel->r_addend;
5236 /* keep symbol location for static TLS_IE GOT entry */
5237 relocation_sym = relocation;
5238 if (bfd_link_relocatable (info))
5240 /* This is a relocatable link. We don't have to change
5241 anything, unless the reloc is against a section symbol,
5242 in which case we have to adjust according to where the
5243 section symbol winds up in the output section. */
5244 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5245 rel->r_addend += sec->output_offset + sym->st_value;
5252 /* External symbol. */
5253 if (bfd_link_relocatable (info))
5255 bfd_boolean warned, ignored, unresolved_reloc;
5256 int symndx = r_symndx - symtab_hdr->sh_info;
5258 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5259 r_symndx, symtab_hdr, sym_hashes, h, sec,
5260 relocation, unresolved_reloc, warned,
5263 /* keep symbol location for static TLS_IE GOT entry */
5264 relocation_sym = relocation;
5266 /* la $fp, _FP_BASE_ is per-function (region).
5267 Handle it specially. */
5268 switch ((int) r_type)
5270 case R_NDS32_HI20_RELA:
5271 case R_NDS32_LO12S0_RELA:
5272 if (strcmp (elf_sym_hashes (input_bfd)[symndx]->root.root.string,
5275 if (!bfd_link_pie (info))
5278 ("%pB: warning: _FP_BASE_ setting insns relaxation failed.",
5281 relocation = fpbase_addr;
5284 case R_NDS32_SDA19S0_RELA:
5285 case R_NDS32_SDA15S0_RELA:
5286 case R_NDS32_20_RELA:
5287 if (strcmp (elf_sym_hashes (input_bfd)[symndx]->root.root.string,
5290 relocation = fpbase_addr;
5296 /* Sanity check the address. */
5297 if (offset > high_address)
5299 r = bfd_reloc_outofrange;
5303 if (r_type >= R_NDS32_RELAX_ENTRY)
5306 switch ((int) r_type)
5308 case R_NDS32_GOTOFF:
5309 /* Relocation is relative to the start of the global offset
5310 table (for ld24 rx, #uimm24), e.g. access at label+addend
5312 ld24 rx. #label@GOTOFF + addend
5314 case R_NDS32_GOTOFF_HI20:
5315 case R_NDS32_GOTOFF_LO12:
5316 case R_NDS32_GOTOFF_LO15:
5317 case R_NDS32_GOTOFF_LO19:
5318 BFD_ASSERT (sgot != NULL);
5320 relocation -= elf_gp (output_bfd);
5323 case R_NDS32_9_PLTREL:
5324 case R_NDS32_25_PLTREL:
5325 /* Relocation is to the entry for this symbol in the
5326 procedure linkage table. */
5328 /* The native assembler will generate a 25_PLTREL reloc
5329 for a local symbol if you assemble a call from one
5330 section to another when using -K pic. */
5334 if (h->forced_local)
5337 /* We didn't make a PLT entry for this symbol. This
5338 happens when statically linking PIC code, or when
5339 using -Bsymbolic. */
5340 if (h->plt.offset == (bfd_vma) - 1)
5343 relocation = (splt->output_section->vma
5344 + splt->output_offset + h->plt.offset);
5347 case R_NDS32_PLT_GOTREL_HI20:
5348 case R_NDS32_PLT_GOTREL_LO12:
5349 case R_NDS32_PLT_GOTREL_LO15:
5350 case R_NDS32_PLT_GOTREL_LO19:
5351 case R_NDS32_PLT_GOTREL_LO20:
5354 || h->plt.offset == (bfd_vma) -1
5355 || (bfd_link_pie (info) && h->def_regular))
5357 /* Maybe we should find better checking to optimize
5358 PIE PLT relocations. */
5359 /* We didn't make a PLT entry for this symbol. This
5360 happens when statically linking PIC code, or when
5361 using -Bsymbolic. */
5363 h->plt.offset = (bfd_vma) -1; /* Cancel PLT trampoline. */
5364 relocation -= elf_gp (output_bfd);
5368 relocation = (splt->output_section->vma
5369 + splt->output_offset + h->plt.offset);
5371 relocation -= elf_gp (output_bfd);
5374 case R_NDS32_PLTREL_HI20:
5375 case R_NDS32_PLTREL_LO12:
5377 /* Relocation is to the entry for this symbol in the
5378 procedure linkage table. */
5380 /* The native assembler will generate a 25_PLTREL reloc
5381 for a local symbol if you assemble a call from one
5382 section to another when using -K pic. */
5386 if (h->forced_local)
5389 if (h->plt.offset == (bfd_vma) - 1)
5390 /* We didn't make a PLT entry for this symbol. This
5391 happens when statically linking PIC code, or when
5392 using -Bsymbolic. */
5398 relocation = (splt->output_section->vma
5399 + splt->output_offset
5400 + h->plt.offset + 4)
5401 - (input_section->output_section->vma
5402 + input_section->output_offset
5407 case R_NDS32_GOTPC20:
5408 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5409 ld24 rx,#_GLOBAL_OFFSET_TABLE_ */
5410 relocation = elf_gp (output_bfd);
5413 case R_NDS32_GOTPC_HI20:
5414 case R_NDS32_GOTPC_LO12:
5415 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5417 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
5418 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
5421 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
5422 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4) */
5423 relocation = elf_gp (output_bfd);
5424 relocation -= (input_section->output_section->vma
5425 + input_section->output_offset + rel->r_offset);
5430 case R_NDS32_GOT_HI20:
5431 case R_NDS32_GOT_LO12:
5432 case R_NDS32_GOT_LO15:
5433 case R_NDS32_GOT_LO19:
5434 /* Relocation is to the entry for this symbol in the global
5436 BFD_ASSERT (sgot != NULL);
5440 /* External symbol */
5443 off = h->got.offset;
5444 BFD_ASSERT (off != (bfd_vma) - 1);
5445 dyn = htab->root.dynamic_sections_created;
5446 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
5447 bfd_link_pic (info),
5449 || (bfd_link_pic (info)
5452 || h->forced_local) && h->def_regular))
5454 /* This is actually a static link, or it is a
5455 -Bsymbolic link and the symbol is defined
5456 locally, or the symbol was forced to be local
5457 because of a version file. We must initialize
5458 this entry in the global offset table. Since the
5459 offset must always be a multiple of 4, we use the
5460 least significant bit to record whether we have
5461 initialized it already.
5463 When doing a dynamic link, we create a .rela.got
5464 relocation entry to initialize the value. This
5465 is done in the finish_dynamic_symbol routine. */
5466 if ((off & 1) != 0) /* clear LSB */
5470 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5474 relocation = sgot->output_section->vma + sgot->output_offset + off
5475 - elf_gp (output_bfd);
5482 BFD_ASSERT (local_got_offsets != NULL
5483 && local_got_offsets[r_symndx] != (bfd_vma) - 1);
5485 off = local_got_offsets[r_symndx];
5487 /* The offset must always be a multiple of 4. We use
5488 the least significant bit to record whether we have
5489 already processed this entry. */
5490 if ((off & 1) != 0) /* clear LSB */
5494 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5496 if (bfd_link_pic (info))
5499 Elf_Internal_Rela outrel;
5501 /* We need to generate a R_NDS32_RELATIVE reloc
5502 for the dynamic linker. */
5503 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5504 BFD_ASSERT (srelgot != NULL);
5506 outrel.r_offset = (elf_gp (output_bfd)
5507 + sgot->output_offset + off);
5508 outrel.r_info = ELF32_R_INFO (0, R_NDS32_RELATIVE);
5509 outrel.r_addend = relocation;
5510 loc = srelgot->contents;
5512 srelgot->reloc_count * sizeof (Elf32_External_Rela);
5513 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5514 ++srelgot->reloc_count;
5516 local_got_offsets[r_symndx] |= 1;
5518 relocation = sgot->output_section->vma + sgot->output_offset + off
5519 - elf_gp (output_bfd);
5524 case R_NDS32_16_RELA:
5525 case R_NDS32_20_RELA:
5526 case R_NDS32_5_RELA:
5527 case R_NDS32_32_RELA:
5528 case R_NDS32_9_PCREL_RELA:
5529 case R_NDS32_WORD_9_PCREL_RELA:
5530 case R_NDS32_10_UPCREL_RELA:
5531 case R_NDS32_15_PCREL_RELA:
5532 case R_NDS32_17_PCREL_RELA:
5533 case R_NDS32_25_PCREL_RELA:
5534 case R_NDS32_HI20_RELA:
5535 case R_NDS32_LO12S3_RELA:
5536 case R_NDS32_LO12S2_RELA:
5537 case R_NDS32_LO12S2_DP_RELA:
5538 case R_NDS32_LO12S2_SP_RELA:
5539 case R_NDS32_LO12S1_RELA:
5540 case R_NDS32_LO12S0_RELA:
5541 case R_NDS32_LO12S0_ORI_RELA:
5542 if (bfd_link_pic (info) && r_symndx != 0
5543 && (input_section->flags & SEC_ALLOC) != 0
5544 && (eliminate_gc_relocs == 0
5545 || (sec && (sec->flags & SEC_EXCLUDE) == 0))
5546 && ((r_type != R_NDS32_9_PCREL_RELA
5547 && r_type != R_NDS32_WORD_9_PCREL_RELA
5548 && r_type != R_NDS32_10_UPCREL_RELA
5549 && r_type != R_NDS32_15_PCREL_RELA
5550 && r_type != R_NDS32_17_PCREL_RELA
5551 && r_type != R_NDS32_25_PCREL_RELA
5552 && !(r_type == R_NDS32_32_RELA
5553 && strcmp (input_section->name, ".eh_frame") == 0))
5554 || (h != NULL && h->dynindx != -1
5555 && (!info->symbolic || !h->def_regular))))
5557 Elf_Internal_Rela outrel;
5558 bfd_boolean skip, relocate;
5561 /* When generating a shared object, these relocations
5562 are copied into the output file to be resolved at run
5569 name = bfd_elf_string_from_elf_section
5570 (input_bfd, elf_elfheader (input_bfd)->e_shstrndx,
5571 elf_section_data (input_section)->rela.hdr->sh_name);
5575 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5576 && strcmp (bfd_get_section_name (input_bfd,
5580 sreloc = bfd_get_section_by_name (dynobj, name);
5581 BFD_ASSERT (sreloc != NULL);
5587 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
5591 if (outrel.r_offset == (bfd_vma) - 1)
5593 else if (outrel.r_offset == (bfd_vma) - 2)
5594 skip = TRUE, relocate = TRUE;
5595 outrel.r_offset += (input_section->output_section->vma
5596 + input_section->output_offset);
5599 memset (&outrel, 0, sizeof outrel);
5600 else if (r_type == R_NDS32_17_PCREL_RELA
5601 || r_type == R_NDS32_15_PCREL_RELA
5602 || r_type == R_NDS32_25_PCREL_RELA)
5604 BFD_ASSERT (h != NULL && h->dynindx != -1);
5605 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5606 outrel.r_addend = rel->r_addend;
5610 /* h->dynindx may be -1 if this symbol was marked to
5613 || ((info->symbolic || h->dynindx == -1)
5615 || (bfd_link_pie (info) && h->def_regular))
5618 outrel.r_info = ELF32_R_INFO (0, R_NDS32_RELATIVE);
5619 outrel.r_addend = relocation + rel->r_addend;
5623 h->plt.offset = (bfd_vma) -1; /* cancel PLT trampoline. */
5625 BFD_ASSERT (sgot != NULL);
5626 /* If we did not allocate got entry for the symbol,
5627 we can not fill the nonexistent got entry. */
5628 if (h->got.offset != (bfd_vma) -1
5629 && (h->got.offset & 1) == 0)
5631 bfd_put_32 (output_bfd, outrel.r_addend,
5632 sgot->contents + h->got.offset);
5638 if (h->dynindx == -1)
5641 (_("%pB: relocation %s against `%s' can not be used when"
5642 "making a shared object; recompile with -fPIC"),
5643 input_bfd, nds32_elf_howto_table[r_type].name, h->root.root.string);
5644 bfd_set_error (bfd_error_bad_value);
5648 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5649 outrel.r_addend = rel->r_addend;
5653 loc = sreloc->contents;
5654 loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
5655 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5656 ++sreloc->reloc_count;
5658 /* If this reloc is against an external symbol, we do
5659 not want to fiddle with the addend. Otherwise, we
5660 need to include the symbol value so that it becomes
5661 an addend for the dynamic reloc. */
5667 case R_NDS32_25_ABS_RELA:
5668 if (bfd_link_pic (info))
5671 (_("%pB: warning: %s unsupported in shared mode"),
5672 input_bfd, "R_NDS32_25_ABS_RELA");
5677 case R_NDS32_9_PCREL:
5678 r = nds32_elf_do_9_pcrel_reloc (input_bfd, howto, input_section,
5680 sec, relocation, addend);
5684 /* We allow an arbitrary number of HI20 relocs before the
5685 LO12 reloc. This permits gcc to emit the HI and LO relocs
5687 for (lorel = rel + 1;
5689 && ELF32_R_TYPE (lorel->r_info) == R_NDS32_HI20); lorel++)
5692 && (ELF32_R_TYPE (lorel->r_info) == R_NDS32_LO12S3
5693 || ELF32_R_TYPE (lorel->r_info) == R_NDS32_LO12S2
5694 || ELF32_R_TYPE (lorel->r_info) == R_NDS32_LO12S1
5695 || ELF32_R_TYPE (lorel->r_info) == R_NDS32_LO12S0))
5697 nds32_elf_relocate_hi20 (input_bfd, r_type, rel, lorel,
5698 contents, relocation + addend);
5702 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
5703 contents, offset, relocation,
5707 case R_NDS32_GOT17S2_RELA:
5708 case R_NDS32_GOT15S2_RELA:
5709 BFD_ASSERT (sgot != NULL);
5715 off = h->got.offset;
5716 BFD_ASSERT (off != (bfd_vma) - 1);
5718 dyn = htab->root.dynamic_sections_created;
5719 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL
5720 (dyn, bfd_link_pic (info), h)
5721 || (bfd_link_pic (info)
5727 /* This is actually a static link, or it is a
5728 -Bsymbolic link and the symbol is defined
5729 locally, or the symbol was forced to be local
5730 because of a version file. We must initialize
5731 this entry in the global offset table. Since the
5732 offset must always be a multiple of 4, we use the
5733 least significant bit to record whether we have
5734 initialized it already.
5736 When doing a dynamic link, we create a .rela.got
5737 relocation entry to initialize the value. This
5738 is done in the finish_dynamic_symbol routine. */
5743 bfd_put_32 (output_bfd, relocation,
5744 sgot->contents + off);
5753 BFD_ASSERT (local_got_offsets != NULL
5754 && local_got_offsets[r_symndx] != (bfd_vma) - 1);
5756 off = local_got_offsets[r_symndx];
5758 /* The offset must always be a multiple of 4. We use
5759 the least significant bit to record whether we have
5760 already processed this entry. */
5765 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5767 if (bfd_link_pic (info))
5770 Elf_Internal_Rela outrel;
5772 /* We need to generate a R_NDS32_RELATIVE reloc
5773 for the dynamic linker. */
5774 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5775 BFD_ASSERT (srelgot != NULL);
5777 outrel.r_offset = (elf_gp (output_bfd)
5778 + sgot->output_offset + off);
5779 outrel.r_info = ELF32_R_INFO (0, R_NDS32_RELATIVE);
5780 outrel.r_addend = relocation;
5781 loc = srelgot->contents;
5783 srelgot->reloc_count * sizeof (Elf32_External_Rela);
5784 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5785 ++srelgot->reloc_count;
5787 local_got_offsets[r_symndx] |= 1;
5790 relocation = sgot->output_section->vma + sgot->output_offset + off
5791 - elf_gp (output_bfd);
5793 if (relocation & align)
5795 /* Incorrect alignment. */
5797 (_("%pB: warning: unaligned access to GOT entry"), input_bfd);
5799 r = bfd_reloc_dangerous;
5804 case R_NDS32_SDA16S3_RELA:
5805 case R_NDS32_SDA15S3_RELA:
5806 case R_NDS32_SDA15S3:
5810 case R_NDS32_SDA17S2_RELA:
5811 case R_NDS32_SDA15S2_RELA:
5812 case R_NDS32_SDA12S2_SP_RELA:
5813 case R_NDS32_SDA12S2_DP_RELA:
5814 case R_NDS32_SDA15S2:
5815 case R_NDS32_SDA_FP7U2_RELA:
5819 case R_NDS32_SDA18S1_RELA:
5820 case R_NDS32_SDA15S1_RELA:
5821 case R_NDS32_SDA15S1:
5825 case R_NDS32_SDA19S0_RELA:
5826 case R_NDS32_SDA15S0_RELA:
5827 case R_NDS32_SDA15S0:
5830 BFD_ASSERT (sec != NULL);
5832 /* If the symbol is in the abs section, the out_bfd will be null.
5833 This happens when the relocation has a symbol@GOTOFF. */
5834 r = nds32_elf_final_sda_base (output_bfd, info, &gp, FALSE);
5835 if (r != bfd_reloc_ok)
5838 (_("%pB: warning: relocate SDA_BASE failed"), input_bfd);
5843 /* At this point `relocation' contains the object's
5845 if (r_type == R_NDS32_SDA_FP7U2_RELA)
5847 relocation -= fpbase_addr;
5851 /* Now it contains the offset from _SDA_BASE_. */
5853 /* Make sure alignment is correct. */
5855 if (relocation & align)
5857 /* Incorrect alignment. */
5859 /* xgettext:c-format */
5860 (_("%pB(%pA): warning: unaligned small data access"
5862 input_bfd, input_section, r_type);
5868 case R_NDS32_17IFC_PCREL_RELA:
5869 case R_NDS32_10IFCU_PCREL_RELA:
5873 case R_NDS32_TLS_LE_HI20:
5874 case R_NDS32_TLS_LE_LO12:
5875 case R_NDS32_TLS_LE_20:
5876 case R_NDS32_TLS_LE_15S0:
5877 case R_NDS32_TLS_LE_15S1:
5878 case R_NDS32_TLS_LE_15S2:
5879 /* We do not have garbage collection for got entries.
5880 Therefore, IE to LE may have one empty entry, and DESC to
5882 if (elf_hash_table (info)->tls_sec != NULL)
5883 relocation -= (elf_hash_table (info)->tls_sec->vma + TP_OFFSET);
5886 case R_NDS32_TLS_IE_HI20:
5887 case R_NDS32_TLS_IE_LO12S2:
5888 case R_NDS32_TLS_DESC_HI20:
5889 case R_NDS32_TLS_DESC_LO12:
5890 case R_NDS32_TLS_IE_LO12:
5891 case R_NDS32_TLS_IEGP_HI20:
5892 case R_NDS32_TLS_IEGP_LO12:
5893 case R_NDS32_TLS_IEGP_LO12S2:
5895 /* Relocation is to the entry for this symbol in the global
5897 enum elf_nds32_tls_type tls_type, org_tls_type, eff_tls_type;
5899 Elf_Internal_Rela outrel;
5903 eff_tls_type = org_tls_type = get_tls_type (r_type, h);
5905 BFD_ASSERT (sgot != NULL);
5910 off = h->got.offset;
5911 BFD_ASSERT (off != (bfd_vma) -1);
5912 dyn = htab->root.dynamic_sections_created;
5913 tls_type = ((struct elf_nds32_link_hash_entry *) h)->tls_type;
5914 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
5915 && (!bfd_link_pic (info)
5916 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5921 BFD_ASSERT (local_got_offsets != NULL
5922 && local_got_offsets[r_symndx] != (bfd_vma) - 1);
5923 off = local_got_offsets[r_symndx];
5924 tls_type = elf32_nds32_local_got_tls_type (input_bfd)[r_symndx];
5927 relocation = sgot->output_section->vma + sgot->output_offset + off;
5929 if (1 < ones32 (tls_type))
5931 eff_tls_type = 1 << (fls (tls_type) - 1);
5932 /* TLS model shall be handled in nds32_elf_unify_tls_model (). */
5934 /* TLS model X -> LE is not implement yet!
5936 if (eff_tls_type == GOT_TLS_LE)
5938 eff_tls_type = 1 << (fls (tls_type ^ eff_tls_type) - 1);
5942 /* The offset must always be a multiple of 4. We use
5943 the least significant bit to record whether we have
5944 already processed this entry. */
5945 bfd_boolean need_relocs = FALSE;
5946 srelgot = ehtab->srelgot;
5947 if ((bfd_link_pic (info) || indx != 0)
5948 && (h == NULL || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5949 || h->root.type != bfd_link_hash_undefweak))
5952 BFD_ASSERT (srelgot != NULL);
5960 if (eff_tls_type & GOT_TLS_DESC)
5962 relocation -= elf_gp (output_bfd);
5963 if ((R_NDS32_TLS_DESC_HI20 == r_type) && (!need_relocs))
5965 /* TLS model shall be converted. */
5969 else if (eff_tls_type & GOT_TLS_IEGP)
5971 relocation -= elf_gp (output_bfd);
5976 if ((eff_tls_type & GOT_TLS_LE) && (tls_type ^ eff_tls_type))
5978 /* TLS model workaround shall be applied. */
5981 else if (eff_tls_type & (GOT_TLS_IE | GOT_TLS_IEGP))
5983 if (eff_tls_type & GOT_TLS_IEGP)
5984 relocation -= elf_gp(output_bfd);
5989 outrel.r_addend = gottpoff (info, relocation_sym);
5991 outrel.r_addend = 0;
5992 outrel.r_offset = (sgot->output_section->vma
5993 + sgot->output_offset + off);
5994 outrel.r_info = ELF32_R_INFO (indx, R_NDS32_TLS_TPOFF);
5996 elf32_nds32_add_dynreloc (output_bfd, info, srelgot,
6001 bfd_put_32 (output_bfd, gottpoff (info, relocation_sym),
6002 sgot->contents + off);
6005 else if (eff_tls_type & GOT_TLS_DESC)
6007 relocation -= elf_gp (output_bfd);
6011 outrel.r_addend = gottpoff (info, relocation_sym);
6013 outrel.r_addend = 0;
6014 outrel.r_offset = (sgot->output_section->vma
6015 + sgot->output_offset + off);
6016 outrel.r_info = ELF32_R_INFO (indx, R_NDS32_TLS_DESC);
6018 if (htab->tls_desc_trampoline)
6021 srelplt = ehtab->srelplt;
6022 loc = srelplt->contents;
6023 loc += htab->next_tls_desc_index++ * sizeof (Elf32_External_Rela);
6024 BFD_ASSERT (loc + sizeof (Elf32_External_Rela)
6025 <= srelplt->contents + srelplt->size);
6027 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
6031 loc = srelgot->contents;
6032 loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
6033 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
6034 ++srelgot->reloc_count;
6040 bfd_put_32 (output_bfd, 0xdeadbeef,
6041 sgot->contents + off);
6042 bfd_put_32 (output_bfd, gottpoff (info, relocation_sym),
6043 sgot->contents + off + 4);
6044 patch_tls_desc_to_ie (contents, rel, input_bfd);
6050 /* TLS model workaround shall be applied. */
6057 local_got_offsets[r_symndx] |= 1;
6061 /* DON'T fall through. */
6064 /* OLD_NDS32_RELOC. */
6066 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
6067 contents, offset, relocation, addend);
6071 switch ((int) r_type)
6073 case R_NDS32_20_RELA:
6074 case R_NDS32_5_RELA:
6075 case R_NDS32_9_PCREL_RELA:
6076 case R_NDS32_WORD_9_PCREL_RELA:
6077 case R_NDS32_10_UPCREL_RELA:
6078 case R_NDS32_15_PCREL_RELA:
6079 case R_NDS32_17_PCREL_RELA:
6080 case R_NDS32_25_PCREL_RELA:
6081 case R_NDS32_25_ABS_RELA:
6082 case R_NDS32_HI20_RELA:
6083 case R_NDS32_LO12S3_RELA:
6084 case R_NDS32_LO12S2_RELA:
6085 case R_NDS32_LO12S2_DP_RELA:
6086 case R_NDS32_LO12S2_SP_RELA:
6087 case R_NDS32_LO12S1_RELA:
6088 case R_NDS32_LO12S0_RELA:
6089 case R_NDS32_LO12S0_ORI_RELA:
6090 case R_NDS32_SDA16S3_RELA:
6091 case R_NDS32_SDA17S2_RELA:
6092 case R_NDS32_SDA18S1_RELA:
6093 case R_NDS32_SDA19S0_RELA:
6094 case R_NDS32_SDA15S3_RELA:
6095 case R_NDS32_SDA15S2_RELA:
6096 case R_NDS32_SDA12S2_DP_RELA:
6097 case R_NDS32_SDA12S2_SP_RELA:
6098 case R_NDS32_SDA15S1_RELA:
6099 case R_NDS32_SDA15S0_RELA:
6100 case R_NDS32_SDA_FP7U2_RELA:
6101 case R_NDS32_9_PLTREL:
6102 case R_NDS32_25_PLTREL:
6104 case R_NDS32_GOT_HI20:
6105 case R_NDS32_GOT_LO12:
6106 case R_NDS32_GOT_LO15:
6107 case R_NDS32_GOT_LO19:
6108 case R_NDS32_GOT15S2_RELA:
6109 case R_NDS32_GOT17S2_RELA:
6110 case R_NDS32_GOTPC20:
6111 case R_NDS32_GOTPC_HI20:
6112 case R_NDS32_GOTPC_LO12:
6113 case R_NDS32_GOTOFF:
6114 case R_NDS32_GOTOFF_HI20:
6115 case R_NDS32_GOTOFF_LO12:
6116 case R_NDS32_GOTOFF_LO15:
6117 case R_NDS32_GOTOFF_LO19:
6118 case R_NDS32_PLTREL_HI20:
6119 case R_NDS32_PLTREL_LO12:
6120 case R_NDS32_PLT_GOTREL_HI20:
6121 case R_NDS32_PLT_GOTREL_LO12:
6122 case R_NDS32_PLT_GOTREL_LO15:
6123 case R_NDS32_PLT_GOTREL_LO19:
6124 case R_NDS32_PLT_GOTREL_LO20:
6125 case R_NDS32_17IFC_PCREL_RELA:
6126 case R_NDS32_10IFCU_PCREL_RELA:
6127 case R_NDS32_TLS_LE_HI20:
6128 case R_NDS32_TLS_LE_LO12:
6129 case R_NDS32_TLS_IE_HI20:
6130 case R_NDS32_TLS_IE_LO12S2:
6131 case R_NDS32_TLS_LE_20:
6132 case R_NDS32_TLS_LE_15S0:
6133 case R_NDS32_TLS_LE_15S1:
6134 case R_NDS32_TLS_LE_15S2:
6135 case R_NDS32_TLS_DESC_HI20:
6136 case R_NDS32_TLS_DESC_LO12:
6137 case R_NDS32_TLS_IE_LO12:
6138 case R_NDS32_TLS_IEGP_HI20:
6139 case R_NDS32_TLS_IEGP_LO12:
6140 case R_NDS32_TLS_IEGP_LO12S2:
6141 /* Instruction related relocs must handle endian properly. */
6142 /* NOTE: PIC IS NOT HANDLE YET; DO IT LATER. */
6143 r = nds32_elf_final_link_relocate (howto, input_bfd,
6144 input_section, contents,
6145 rel->r_offset, relocation,
6150 /* All other relocs can use default handler. */
6151 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
6152 contents, rel->r_offset,
6153 relocation, rel->r_addend);
6159 if (r != bfd_reloc_ok)
6161 /* FIXME: This should be generic enough to go in a utility. */
6165 name = h->root.root.string;
6168 name = bfd_elf_string_from_elf_section
6169 (input_bfd, symtab_hdr->sh_link, sym->st_name);
6170 if (name == NULL || *name == '\0')
6171 name = bfd_section_name (input_bfd, sec);
6179 case bfd_reloc_overflow:
6180 (*info->callbacks->reloc_overflow)
6181 (info, (h ? &h->root : NULL), name, howto->name,
6182 (bfd_vma) 0, input_bfd, input_section, offset);
6185 case bfd_reloc_undefined:
6186 (*info->callbacks->undefined_symbol)
6187 (info, name, input_bfd, input_section, offset, TRUE);
6190 case bfd_reloc_outofrange:
6191 errmsg = _("internal error: out of range error");
6194 case bfd_reloc_notsupported:
6195 errmsg = _("internal error: unsupported relocation error");
6198 case bfd_reloc_dangerous:
6199 errmsg = _("internal error: dangerous error");
6203 errmsg = _("internal error: unknown error");
6207 (*info->callbacks->warning) (info, errmsg, name, input_bfd,
6208 input_section, offset);
6214 /* Resotre header size to avoid overflow load. */
6215 if (elf_nds32_tdata (input_bfd)->hdr_size != 0)
6216 symtab_hdr->sh_size = elf_nds32_tdata (input_bfd)->hdr_size;
6221 /* Finish up dynamic symbol handling. We set the contents of various
6222 dynamic sections here. */
6225 nds32_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6226 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)
6228 struct elf_link_hash_table *ehtab;
6229 struct elf_nds32_link_hash_entry *hent;
6232 ehtab = elf_hash_table (info);
6233 hent = (struct elf_nds32_link_hash_entry *) h;
6235 if (h->plt.offset != (bfd_vma) - 1)
6243 bfd_vma local_plt_offset;
6244 Elf_Internal_Rela rela;
6246 /* This symbol has an entry in the procedure linkage table. Set
6249 BFD_ASSERT (h->dynindx != -1);
6252 sgot = ehtab->sgotplt;
6253 srela = ehtab->srelplt;
6254 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
6256 /* Get the index in the procedure linkage table which
6257 corresponds to this symbol. This is the index of this symbol
6258 in all the symbols for which we are making plt entries. The
6259 first entry in the procedure linkage table is reserved. */
6260 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
6262 /* Get the offset into the .got table of the entry that
6263 corresponds to this function. Each .got entry is 4 bytes.
6264 The first three are reserved. */
6265 got_offset = (plt_index + 3) * 4;
6267 /* Fill in the entry in the procedure linkage table. */
6268 if (!bfd_link_pic (info))
6272 insn = PLT_ENTRY_WORD0 + (((sgot->output_section->vma
6273 + sgot->output_offset + got_offset) >> 12)
6275 bfd_putb32 (insn, splt->contents + h->plt.offset);
6277 insn = PLT_ENTRY_WORD1 + (((sgot->output_section->vma
6278 + sgot->output_offset + got_offset) & 0x0fff)
6280 bfd_putb32 (insn, splt->contents + h->plt.offset + 4);
6282 insn = PLT_ENTRY_WORD2;
6283 bfd_putb32 (insn, splt->contents + h->plt.offset + 8);
6285 insn = PLT_ENTRY_WORD3 + (plt_index & 0x7ffff);
6286 bfd_putb32 (insn, splt->contents + h->plt.offset + 12);
6288 insn = PLT_ENTRY_WORD4
6289 + (((unsigned int) ((-(h->plt.offset + 16)) >> 1)) & 0xffffff);
6290 bfd_putb32 (insn, splt->contents + h->plt.offset + 16);
6291 local_plt_offset = 12;
6295 /* sda_base must be set at this time. */
6299 offset = sgot->output_section->vma + sgot->output_offset + got_offset
6300 - elf_gp (output_bfd);
6301 insn = PLT_PIC_ENTRY_WORD0 + ((offset >> 12) & 0xfffff);
6302 bfd_putb32 (insn, splt->contents + h->plt.offset);
6304 insn = PLT_PIC_ENTRY_WORD1 + (offset & 0xfff);
6305 bfd_putb32 (insn, splt->contents + h->plt.offset + 4);
6307 insn = PLT_PIC_ENTRY_WORD2;
6308 bfd_putb32 (insn, splt->contents + h->plt.offset + 8);
6310 insn = PLT_PIC_ENTRY_WORD3;
6311 bfd_putb32 (insn, splt->contents + h->plt.offset + 12);
6313 insn = PLT_PIC_ENTRY_WORD4 + (plt_index & 0x7fffff);
6314 bfd_putb32 (insn, splt->contents + h->plt.offset + 16);
6316 insn = PLT_PIC_ENTRY_WORD5
6317 + (((unsigned int) ((-(h->plt.offset + 20)) >> 1)) & 0xffffff);
6318 bfd_putb32 (insn, splt->contents + h->plt.offset + 20);
6320 local_plt_offset = 16;
6323 /* Fill in the entry in the global offset table,
6324 so it will fall through to the next instruction for the first time. */
6325 bfd_put_32 (output_bfd,
6326 (splt->output_section->vma + splt->output_offset
6327 + h->plt.offset + local_plt_offset),
6328 sgot->contents + got_offset);
6330 /* Fill in the entry in the .rela.plt section. */
6331 rela.r_offset = (sgot->output_section->vma
6332 + sgot->output_offset + got_offset);
6333 rela.r_info = ELF32_R_INFO (h->dynindx, R_NDS32_JMP_SLOT);
6335 loc = srela->contents;
6336 loc += plt_index * sizeof (Elf32_External_Rela);
6337 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6339 if (!h->def_regular)
6341 /* Mark the symbol as undefined, rather than as defined in
6342 the .plt section. Leave the value alone. */
6343 sym->st_shndx = SHN_UNDEF;
6344 if (!h->ref_regular_nonweak)
6349 if (h->got.offset != (bfd_vma) - 1
6350 && hent->tls_type == GOT_NORMAL)
6354 Elf_Internal_Rela rela;
6356 /* This symbol has an entry in the global offset table.
6360 srelagot = ehtab->srelgot;
6361 BFD_ASSERT (sgot != NULL && srelagot != NULL);
6363 rela.r_offset = (sgot->output_section->vma
6364 + sgot->output_offset + (h->got.offset & ~1));
6366 /* If this is a -Bsymbolic link, and the symbol is defined
6367 locally, we just want to emit a RELATIVE reloc. Likewise if
6368 the symbol was forced to be local because of a version file.
6369 The entry in the global offset table will already have been
6370 initialized in the relocate_section function. */
6371 if ((bfd_link_pic (info)
6372 && (info->symbolic || h->dynindx == -1 || h->forced_local)
6374 || (bfd_link_pie (info) && h->def_regular))
6376 rela.r_info = ELF32_R_INFO (0, R_NDS32_RELATIVE);
6377 rela.r_addend = (h->root.u.def.value
6378 + h->root.u.def.section->output_section->vma
6379 + h->root.u.def.section->output_offset);
6381 if ((h->got.offset & 1) == 0)
6383 bfd_put_32 (output_bfd, rela.r_addend,
6384 sgot->contents + h->got.offset);
6389 BFD_ASSERT ((h->got.offset & 1) == 0);
6390 bfd_put_32 (output_bfd, (bfd_vma) 0,
6391 sgot->contents + h->got.offset);
6392 rela.r_info = ELF32_R_INFO (h->dynindx, R_NDS32_GLOB_DAT);
6396 loc = srelagot->contents;
6397 loc += srelagot->reloc_count * sizeof (Elf32_External_Rela);
6398 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6399 ++srelagot->reloc_count;
6400 BFD_ASSERT (loc < (srelagot->contents + srelagot->size));
6406 Elf_Internal_Rela rela;
6408 /* This symbols needs a copy reloc. Set it up. */
6410 BFD_ASSERT (h->dynindx != -1
6411 && (h->root.type == bfd_link_hash_defined
6412 || h->root.type == bfd_link_hash_defweak));
6414 s = bfd_get_section_by_name (h->root.u.def.section->owner, ".rela.bss");
6415 BFD_ASSERT (s != NULL);
6417 rela.r_offset = (h->root.u.def.value
6418 + h->root.u.def.section->output_section->vma
6419 + h->root.u.def.section->output_offset);
6420 rela.r_info = ELF32_R_INFO (h->dynindx, R_NDS32_COPY);
6423 loc += s->reloc_count * sizeof (Elf32_External_Rela);
6424 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6428 /* Mark some specially defined symbols as absolute. */
6429 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6430 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
6431 sym->st_shndx = SHN_ABS;
6437 /* Finish up the dynamic sections. */
6440 nds32_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
6445 struct elf_link_hash_table *ehtab;
6446 struct elf_nds32_link_hash_table *htab;
6448 ehtab = elf_hash_table (info);
6449 htab = nds32_elf_hash_table (info);
6453 dynobj = elf_hash_table (info)->dynobj;
6455 sgotplt = ehtab->sgotplt;
6456 /* A broken linker script might have discarded the dynamic sections.
6457 Catch this here so that we do not seg-fault later on. */
6458 if (sgotplt != NULL && bfd_is_abs_section (sgotplt->output_section))
6460 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6462 if (elf_hash_table (info)->dynamic_sections_created)
6465 Elf32_External_Dyn *dyncon, *dynconend;
6467 BFD_ASSERT (sgotplt != NULL && sdyn != NULL);
6469 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6470 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6472 for (; dyncon < dynconend; dyncon++)
6474 Elf_Internal_Dyn dyn;
6477 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
6485 /* name = ".got"; */
6486 s = ehtab->sgot->output_section;
6489 s = ehtab->srelplt->output_section;
6491 BFD_ASSERT (s != NULL);
6492 dyn.d_un.d_ptr = s->vma;
6493 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6497 s = ehtab->srelplt->output_section;
6498 BFD_ASSERT (s != NULL);
6499 dyn.d_un.d_val = s->size;
6500 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6504 /* My reading of the SVR4 ABI indicates that the
6505 procedure linkage table relocs (DT_JMPREL) should be
6506 included in the overall relocs (DT_RELA). This is
6507 what Solaris does. However, UnixWare can not handle
6508 that case. Therefore, we override the DT_RELASZ entry
6509 here to make it not include the JMPREL relocs. Since
6510 the linker script arranges for .rela.plt to follow all
6511 other relocation sections, we don't have to worry
6512 about changing the DT_RELA entry. */
6513 if (ehtab->srelplt != NULL)
6515 s = ehtab->srelplt->output_section;
6516 dyn.d_un.d_val -= s->size;
6518 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6521 case DT_TLSDESC_PLT:
6522 s = htab->root.splt;
6523 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
6524 + htab->dt_tlsdesc_plt);
6525 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6528 case DT_TLSDESC_GOT:
6529 s = htab->root.sgot;
6530 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
6531 + htab->dt_tlsdesc_got);
6532 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6537 /* Fill in the first entry in the procedure linkage table. */
6539 if (splt && splt->size > 0)
6541 if (bfd_link_pic (info))
6546 offset = sgotplt->output_section->vma + sgotplt->output_offset + 4
6547 - elf_gp (output_bfd);
6548 insn = PLT0_PIC_ENTRY_WORD0 | ((offset >> 12) & 0xfffff);
6549 bfd_putb32 (insn, splt->contents);
6551 /* here has a typo? */
6552 insn = PLT0_PIC_ENTRY_WORD1 | (offset & 0xfff);
6553 bfd_putb32 (insn, splt->contents + 4);
6555 insn = PLT0_PIC_ENTRY_WORD2;
6556 bfd_putb32 (insn, splt->contents + 8);
6558 insn = PLT0_PIC_ENTRY_WORD3;
6559 bfd_putb32 (insn, splt->contents + 12);
6561 insn = PLT0_PIC_ENTRY_WORD4;
6562 bfd_putb32 (insn, splt->contents + 16);
6564 insn = PLT0_PIC_ENTRY_WORD5;
6565 bfd_putb32 (insn, splt->contents + 20);
6572 /* addr = .got + 4 */
6573 addr = sgotplt->output_section->vma + sgotplt->output_offset + 4;
6574 insn = PLT0_ENTRY_WORD0 | ((addr >> 12) & 0xfffff);
6575 bfd_putb32 (insn, splt->contents);
6577 insn = PLT0_ENTRY_WORD1 | (addr & 0x0fff);
6578 bfd_putb32 (insn, splt->contents + 4);
6580 insn = PLT0_ENTRY_WORD2;
6581 bfd_putb32 (insn, splt->contents + 8);
6583 insn = PLT0_ENTRY_WORD3;
6584 bfd_putb32 (insn, splt->contents + 12);
6586 insn = PLT0_ENTRY_WORD4;
6587 bfd_putb32 (insn, splt->contents + 16);
6590 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
6594 if (htab->dt_tlsdesc_plt)
6596 /* Calculate addresses. */
6597 asection *sgot = sgot = ehtab->sgot;
6598 bfd_vma pltgot = sgotplt->output_section->vma
6599 + sgotplt->output_offset;
6600 bfd_vma tlsdesc_got = sgot->output_section->vma + sgot->output_offset
6601 + htab->dt_tlsdesc_got;
6603 /* Get GP offset. */
6604 pltgot -= elf_gp (output_bfd) - 4; /* PLTGOT[1] */
6605 tlsdesc_got -= elf_gp (output_bfd);
6607 /* Do relocation. */
6608 dl_tlsdesc_lazy_trampoline[0] += ((1 << 20) - 1) & (tlsdesc_got >> 12);
6609 dl_tlsdesc_lazy_trampoline[1] += 0xfff & tlsdesc_got;
6610 dl_tlsdesc_lazy_trampoline[4] += ((1 << 20) - 1) & (pltgot >> 12);
6611 dl_tlsdesc_lazy_trampoline[5] += 0xfff & pltgot;
6614 nds32_put_trampoline (splt->contents + htab->dt_tlsdesc_plt,
6615 dl_tlsdesc_lazy_trampoline,
6616 ARRAY_SIZE (dl_tlsdesc_lazy_trampoline));
6620 /* Fill in the first three entries in the global offset table. */
6621 if (sgotplt && sgotplt->size > 0)
6624 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents);
6626 bfd_put_32 (output_bfd,
6627 sdyn->output_section->vma + sdyn->output_offset,
6629 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 4);
6630 bfd_put_32 (output_bfd, (bfd_vma) 0, sgotplt->contents + 8);
6632 elf_section_data (sgotplt->output_section)->this_hdr.sh_entsize = 4;
6639 /* Set the right machine number. */
6642 nds32_elf_object_p (bfd *abfd)
6644 static unsigned int cur_arch = 0;
6646 if (E_N1_ARCH != (elf_elfheader (abfd)->e_flags & EF_NDS_ARCH))
6648 /* E_N1_ARCH is a wild card, so it is set only when no others exist. */
6649 cur_arch = (elf_elfheader (abfd)->e_flags & EF_NDS_ARCH);
6656 bfd_default_set_arch_mach (abfd, bfd_arch_nds32, bfd_mach_n1);
6659 bfd_default_set_arch_mach (abfd, bfd_arch_nds32, bfd_mach_n1h);
6661 case E_NDS_ARCH_STAR_V2_0:
6662 bfd_default_set_arch_mach (abfd, bfd_arch_nds32, bfd_mach_n1h_v2);
6664 case E_NDS_ARCH_STAR_V3_0:
6665 bfd_default_set_arch_mach (abfd, bfd_arch_nds32, bfd_mach_n1h_v3);
6667 case E_NDS_ARCH_STAR_V3_M:
6668 bfd_default_set_arch_mach (abfd, bfd_arch_nds32, bfd_mach_n1h_v3m);
6675 /* Store the machine number in the flags field. */
6678 nds32_elf_final_write_processing (bfd *abfd,
6679 bfd_boolean linker ATTRIBUTE_UNUSED)
6682 static unsigned int cur_mach = 0;
6684 if (bfd_mach_n1 != bfd_get_mach (abfd))
6686 cur_mach = bfd_get_mach (abfd);
6692 /* Only happen when object is empty, since the case is abandon. */
6694 val |= E_NDS_ABI_AABI;
6695 val |= E_NDS32_ELF_VER_1_4;
6700 case bfd_mach_n1h_v2:
6701 val = E_NDS_ARCH_STAR_V2_0;
6703 case bfd_mach_n1h_v3:
6704 val = E_NDS_ARCH_STAR_V3_0;
6706 case bfd_mach_n1h_v3m:
6707 val = E_NDS_ARCH_STAR_V3_M;
6714 elf_elfheader (abfd)->e_flags &= ~EF_NDS_ARCH;
6715 elf_elfheader (abfd)->e_flags |= val;
6718 /* Function to keep NDS32 specific file flags. */
6721 nds32_elf_set_private_flags (bfd *abfd, flagword flags)
6723 BFD_ASSERT (!elf_flags_init (abfd)
6724 || elf_elfheader (abfd)->e_flags == flags);
6726 elf_elfheader (abfd)->e_flags = flags;
6727 elf_flags_init (abfd) = TRUE;
6732 convert_e_flags (unsigned int e_flags, unsigned int arch)
6734 if ((e_flags & EF_NDS_ARCH) == E_NDS_ARCH_STAR_V0_9)
6736 /* From 0.9 to 1.0. */
6737 e_flags = (e_flags & (~EF_NDS_ARCH)) | E_NDS_ARCH_STAR_V1_0;
6739 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6740 e_flags ^= E_NDS32_HAS_NO_MAC_INST;
6741 if (arch == E_NDS_ARCH_STAR_V1_0)
6748 /* From 1.0 to 2.0. */
6749 e_flags = (e_flags & (~EF_NDS_ARCH)) | E_NDS_ARCH_STAR_V2_0;
6751 /* Clear E_NDS32_HAS_MFUSR_PC_INST. */
6752 e_flags &= ~E_NDS32_HAS_MFUSR_PC_INST;
6754 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6755 e_flags ^= E_NDS32_HAS_NO_MAC_INST;
6760 nds32_check_vec_size (bfd *ibfd)
6762 static unsigned int nds32_vec_size = 0;
6764 asection *sec_t = NULL;
6765 bfd_byte *contents = NULL;
6767 sec_t = bfd_get_section_by_name (ibfd, ".nds32_e_flags");
6769 if (sec_t && sec_t->size >= 4)
6771 /* Get vec_size in file. */
6772 unsigned int flag_t;
6774 nds32_get_section_contents (ibfd, sec_t, &contents, TRUE);
6775 flag_t = bfd_get_32 (ibfd, contents);
6777 /* The value could only be 4 or 16. */
6779 if (!nds32_vec_size)
6780 /* Set if not set yet. */
6781 nds32_vec_size = (flag_t & 0x3);
6782 else if (nds32_vec_size != (flag_t & 0x3))
6785 /* xgettext:c-format */
6786 (_("%pB: ISR vector size mismatch"
6787 " with previous modules, previous %u-byte, current %u-byte"),
6789 nds32_vec_size == 1 ? 4 : nds32_vec_size == 2 ? 16 : 0xffffffff,
6790 (flag_t & 0x3) == 1 ? 4 : (flag_t & 0x3) == 2 ? 16 : 0xffffffff);
6794 /* Only keep the first vec_size section. */
6795 sec_t->flags |= SEC_EXCLUDE;
6801 /* Merge backend specific data from an object file to the output
6802 object file when linking. */
6805 nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
6807 bfd *obfd = info->output_bfd;
6810 flagword out_16regs;
6812 flagword out_no_mac;
6814 flagword out_version;
6815 flagword in_version;
6816 flagword out_fpu_config;
6817 flagword in_fpu_config;
6819 /* TODO: Revise to use object-attributes instead. */
6820 if (!nds32_check_vec_size (ibfd))
6823 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6824 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6827 if (bfd_little_endian (ibfd) != bfd_little_endian (obfd))
6830 (_("%pB: warning: endian mismatch with previous modules"), ibfd);
6832 bfd_set_error (bfd_error_bad_value);
6836 /* -B option in objcopy cannot work as expected. e_flags = 0 shall be
6837 treat as generic one without checking and merging. */
6838 if (elf_elfheader (ibfd)->e_flags)
6840 in_version = elf_elfheader (ibfd)->e_flags & EF_NDS32_ELF_VERSION;
6841 if (in_version == E_NDS32_ELF_VER_1_2)
6844 (_("%pB: warning: older version of object file encountered, "
6845 "please recompile with current tool chain"), ibfd);
6848 /* We may need to merge V1 and V2 arch object files to V2. */
6849 if ((elf_elfheader (ibfd)->e_flags & EF_NDS_ARCH)
6850 != (elf_elfheader (obfd)->e_flags & EF_NDS_ARCH))
6852 /* Need to convert version. */
6853 if ((elf_elfheader (ibfd)->e_flags & EF_NDS_ARCH)
6854 == E_NDS_ARCH_STAR_RESERVED)
6856 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6858 else if ((elf_elfheader (ibfd)->e_flags & EF_NDS_ARCH)
6859 == E_NDS_ARCH_STAR_V3_M
6860 && (elf_elfheader (obfd)->e_flags & EF_NDS_ARCH)
6861 == E_NDS_ARCH_STAR_V3_0)
6863 elf_elfheader (ibfd)->e_flags =
6864 (elf_elfheader (ibfd)->e_flags & (~EF_NDS_ARCH))
6865 | E_NDS_ARCH_STAR_V3_0;
6867 else if ((elf_elfheader (obfd)->e_flags & EF_NDS_ARCH)
6868 == E_NDS_ARCH_STAR_V0_9
6869 || (elf_elfheader (ibfd)->e_flags & EF_NDS_ARCH)
6870 > (elf_elfheader (obfd)->e_flags & EF_NDS_ARCH))
6872 elf_elfheader (obfd)->e_flags =
6873 convert_e_flags (elf_elfheader (obfd)->e_flags,
6874 (elf_elfheader (ibfd)->e_flags & EF_NDS_ARCH));
6878 elf_elfheader (ibfd)->e_flags =
6879 convert_e_flags (elf_elfheader (ibfd)->e_flags,
6880 (elf_elfheader (obfd)->e_flags & EF_NDS_ARCH));
6884 /* Extract some flags. */
6885 in_flags = elf_elfheader (ibfd)->e_flags
6886 & (~(E_NDS32_HAS_REDUCED_REGS | EF_NDS32_ELF_VERSION
6887 | E_NDS32_HAS_NO_MAC_INST | E_NDS32_FPU_REG_CONF));
6889 /* The following flags need special treatment. */
6890 in_16regs = elf_elfheader (ibfd)->e_flags & E_NDS32_HAS_REDUCED_REGS;
6891 in_no_mac = elf_elfheader (ibfd)->e_flags & E_NDS32_HAS_NO_MAC_INST;
6892 in_fpu_config = elf_elfheader (ibfd)->e_flags & E_NDS32_FPU_REG_CONF;
6894 /* Extract some flags. */
6895 out_flags = elf_elfheader (obfd)->e_flags
6896 & (~(E_NDS32_HAS_REDUCED_REGS | EF_NDS32_ELF_VERSION
6897 | E_NDS32_HAS_NO_MAC_INST | E_NDS32_FPU_REG_CONF));
6899 /* The following flags need special treatment. */
6900 out_16regs = elf_elfheader (obfd)->e_flags & E_NDS32_HAS_REDUCED_REGS;
6901 out_no_mac = elf_elfheader (obfd)->e_flags & E_NDS32_HAS_NO_MAC_INST;
6902 out_fpu_config = elf_elfheader (obfd)->e_flags & E_NDS32_FPU_REG_CONF;
6903 out_version = elf_elfheader (obfd)->e_flags & EF_NDS32_ELF_VERSION;
6904 if (!elf_flags_init (obfd))
6906 /* If the input is the default architecture then do not
6907 bother setting the flags for the output architecture,
6908 instead allow future merges to do this. If no future
6909 merges ever set these flags then they will retain their
6910 unitialised values, which surprise surprise, correspond
6911 to the default values. */
6912 if (bfd_get_arch_info (ibfd)->the_default)
6915 elf_flags_init (obfd) = TRUE;
6916 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
6918 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6919 && bfd_get_arch_info (obfd)->the_default)
6921 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
6922 bfd_get_mach (ibfd));
6928 /* Check flag compatibility. */
6929 if ((in_flags & EF_NDS_ABI) != (out_flags & EF_NDS_ABI))
6932 (_("%pB: error: ABI mismatch with previous modules"), ibfd);
6933 bfd_set_error (bfd_error_bad_value);
6937 if ((in_flags & EF_NDS_ARCH) != (out_flags & EF_NDS_ARCH))
6939 if (((in_flags & EF_NDS_ARCH) != E_N1_ARCH))
6942 (_("%pB: error: instruction set mismatch with previous modules"),
6945 bfd_set_error (bfd_error_bad_value);
6950 /* When linking with V1.2 and V1.3 objects together the output is V1.2.
6951 and perf ext1 and DIV are mergerd to perf ext1. */
6952 if (in_version == E_NDS32_ELF_VER_1_2 || out_version == E_NDS32_ELF_VER_1_2)
6954 elf_elfheader (obfd)->e_flags =
6955 (in_flags & (~(E_NDS32_HAS_EXT_INST | E_NDS32_HAS_DIV_INST)))
6956 | (out_flags & (~(E_NDS32_HAS_EXT_INST | E_NDS32_HAS_DIV_INST)))
6957 | (((in_flags & (E_NDS32_HAS_EXT_INST | E_NDS32_HAS_DIV_INST)))
6958 ? E_NDS32_HAS_EXT_INST : 0)
6959 | (((out_flags & (E_NDS32_HAS_EXT_INST | E_NDS32_HAS_DIV_INST)))
6960 ? E_NDS32_HAS_EXT_INST : 0)
6961 | (in_16regs & out_16regs) | (in_no_mac & out_no_mac)
6962 | ((in_version > out_version) ? out_version : in_version);
6966 if (in_version != out_version)
6968 /* xgettext:c-format */
6969 (_("%pB: warning: incompatible elf-versions %s and %s"),
6970 ibfd, nds32_elfver_strtab[out_version],
6971 nds32_elfver_strtab[in_version]);
6973 elf_elfheader (obfd)->e_flags = in_flags | out_flags
6974 | (in_16regs & out_16regs) | (in_no_mac & out_no_mac)
6975 | (in_fpu_config > out_fpu_config ? in_fpu_config : out_fpu_config)
6976 | (in_version > out_version ? out_version : in_version);
6983 /* Display the flags field. */
6986 nds32_elf_print_private_bfd_data (bfd *abfd, void *ptr)
6988 FILE *file = (FILE *) ptr;
6990 BFD_ASSERT (abfd != NULL && ptr != NULL);
6992 _bfd_elf_print_private_bfd_data (abfd, ptr);
6994 fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);
6996 switch (elf_elfheader (abfd)->e_flags & EF_NDS_ARCH)
7000 fprintf (file, _(": n1 instructions"));
7003 fprintf (file, _(": n1h instructions"));
7013 nds32_elf_action_discarded (asection *sec)
7017 (".gcc_except_table", sec->name, sizeof (".gcc_except_table") - 1) == 0)
7020 return _bfd_elf_default_action_discarded (sec);
7024 nds32_elf_gc_mark_hook (asection *sec, struct bfd_link_info *info,
7025 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
7026 Elf_Internal_Sym *sym)
7029 switch (ELF32_R_TYPE (rel->r_info))
7031 case R_NDS32_GNU_VTINHERIT:
7032 case R_NDS32_GNU_VTENTRY:
7033 case R_NDS32_RELA_GNU_VTINHERIT:
7034 case R_NDS32_RELA_GNU_VTENTRY:
7038 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7041 static enum elf_nds32_tls_type
7042 get_tls_type (enum elf_nds32_reloc_type r_type,
7043 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
7045 enum elf_nds32_tls_type tls_type;
7049 case R_NDS32_TLS_LE_HI20:
7050 case R_NDS32_TLS_LE_LO12:
7051 tls_type = GOT_TLS_LE;
7053 case R_NDS32_TLS_IE_HI20:
7054 case R_NDS32_TLS_IE_LO12S2:
7055 case R_NDS32_TLS_IE_LO12:
7056 tls_type = GOT_TLS_IE;
7058 case R_NDS32_TLS_IEGP_HI20:
7059 case R_NDS32_TLS_IEGP_LO12:
7060 case R_NDS32_TLS_IEGP_LO12S2:
7061 tls_type = GOT_TLS_IEGP;
7063 case R_NDS32_TLS_DESC_HI20:
7064 case R_NDS32_TLS_DESC_LO12:
7065 case R_NDS32_TLS_DESC_ADD:
7066 case R_NDS32_TLS_DESC_FUNC:
7067 case R_NDS32_TLS_DESC_CALL:
7068 tls_type = GOT_TLS_DESC;
7071 tls_type = GOT_NORMAL;
7078 /* Ensure that we have allocated bookkeeping structures for ABFD's local
7082 elf32_nds32_allocate_local_sym_info (bfd *abfd)
7084 if (elf_local_got_refcounts (abfd) == NULL)
7086 bfd_size_type num_syms;
7090 num_syms = elf_tdata (abfd)->symtab_hdr.sh_info;
7091 /* This space is for got_refcounts, got_tls_type, tlsdesc_gotent, and
7092 gp_offset. The details can refer to struct elf_nds32_obj_tdata. */
7093 size = num_syms * (sizeof (bfd_signed_vma) + sizeof (char)
7094 + sizeof (bfd_vma) + sizeof (int)
7095 + sizeof (bfd_boolean) + sizeof (bfd_vma));
7096 data = bfd_zalloc (abfd, size);
7100 elf_local_got_refcounts (abfd) = (bfd_signed_vma *) data;
7101 data += num_syms * sizeof (bfd_signed_vma);
7103 elf32_nds32_local_got_tls_type (abfd) = (char *) data;
7104 data += num_syms * sizeof (char);
7106 elf32_nds32_local_tlsdesc_gotent (abfd) = (bfd_vma *) data;
7107 data += num_syms * sizeof (bfd_vma);
7109 elf32_nds32_local_gp_offset (abfd) = (int *) data;
7110 data += num_syms * sizeof (int);
7116 /* Look through the relocs for a section during the first phase.
7117 Since we don't do .gots or .plts, we just need to consider the
7118 virtual table relocs for gc. */
7121 nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
7122 asection *sec, const Elf_Internal_Rela *relocs)
7124 Elf_Internal_Shdr *symtab_hdr;
7125 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
7126 const Elf_Internal_Rela *rel;
7127 const Elf_Internal_Rela *rel_end;
7128 struct elf_link_hash_table *ehtab;
7129 struct elf_nds32_link_hash_table *htab;
7131 asection *sreloc = NULL;
7133 /* No need for relocation if relocatable already. */
7134 if (bfd_link_relocatable (info))
7136 elf32_nds32_check_relax_group (abfd, sec);
7140 /* Don't do anything special with non-loaded, non-alloced sections.
7141 In particular, any relocs in such sections should not affect GOT
7142 and PLT reference counting (ie. we don't allow them to create GOT
7143 or PLT entries), there's no possibility or desire to optimize TLS
7144 relocs, and there's not much point in propagating relocs to shared
7145 libs that the dynamic linker won't relocate. */
7146 if ((sec->flags & SEC_ALLOC) == 0)
7149 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7150 sym_hashes = elf_sym_hashes (abfd);
7152 sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7153 if (!elf_bad_symtab (abfd))
7154 sym_hashes_end -= symtab_hdr->sh_info;
7156 ehtab = elf_hash_table (info);
7157 htab = nds32_elf_hash_table (info);
7158 dynobj = htab->root.dynobj;
7160 rel_end = relocs + sec->reloc_count;
7161 for (rel = relocs; rel < rel_end; rel++)
7163 enum elf_nds32_reloc_type r_type;
7164 struct elf_link_hash_entry *h;
7165 unsigned long r_symndx;
7166 enum elf_nds32_tls_type tls_type, old_tls_type;
7168 r_symndx = ELF32_R_SYM (rel->r_info);
7169 r_type = ELF32_R_TYPE (rel->r_info);
7170 if (r_symndx < symtab_hdr->sh_info)
7174 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7175 while (h->root.type == bfd_link_hash_indirect
7176 || h->root.type == bfd_link_hash_warning)
7177 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7180 /* Create .got section if necessary.
7181 Some relocs require a global offset table. We create
7182 got section here, since these relocation need a got section
7183 and if it is not created yet. */
7184 if (ehtab->sgot == NULL)
7188 case R_NDS32_GOT_HI20:
7189 case R_NDS32_GOT_LO12:
7190 case R_NDS32_GOT_LO15:
7191 case R_NDS32_GOT_LO19:
7192 case R_NDS32_GOT17S2_RELA:
7193 case R_NDS32_GOT15S2_RELA:
7194 case R_NDS32_GOTOFF:
7195 case R_NDS32_GOTOFF_HI20:
7196 case R_NDS32_GOTOFF_LO12:
7197 case R_NDS32_GOTOFF_LO15:
7198 case R_NDS32_GOTOFF_LO19:
7199 case R_NDS32_GOTPC20:
7200 case R_NDS32_GOTPC_HI20:
7201 case R_NDS32_GOTPC_LO12:
7203 case R_NDS32_TLS_IE_HI20:
7204 case R_NDS32_TLS_IE_LO12:
7205 case R_NDS32_TLS_IE_LO12S2:
7206 case R_NDS32_TLS_IEGP_HI20:
7207 case R_NDS32_TLS_IEGP_LO12:
7208 case R_NDS32_TLS_IEGP_LO12S2:
7209 case R_NDS32_TLS_DESC_HI20:
7210 case R_NDS32_TLS_DESC_LO12:
7212 htab->root.dynobj = dynobj = abfd;
7213 if (!create_got_section (dynobj, info))
7222 /* Check relocation type. */
7223 switch ((int) r_type)
7225 case R_NDS32_GOT_HI20:
7226 case R_NDS32_GOT_LO12:
7227 case R_NDS32_GOT_LO15:
7228 case R_NDS32_GOT_LO19:
7230 case R_NDS32_TLS_LE_HI20:
7231 case R_NDS32_TLS_LE_LO12:
7232 case R_NDS32_TLS_IE_HI20:
7233 case R_NDS32_TLS_IE_LO12:
7234 case R_NDS32_TLS_IE_LO12S2:
7235 case R_NDS32_TLS_IEGP_HI20:
7236 case R_NDS32_TLS_IEGP_LO12:
7237 case R_NDS32_TLS_IEGP_LO12S2:
7238 case R_NDS32_TLS_DESC_HI20:
7239 case R_NDS32_TLS_DESC_LO12:
7240 tls_type = get_tls_type (r_type, h);
7243 if (tls_type != GOT_TLS_LE)
7244 h->got.refcount += 1;
7245 old_tls_type = elf32_nds32_hash_entry (h)->tls_type;
7249 /* This is a global offset table entry for a local symbol. */
7250 if (!elf32_nds32_allocate_local_sym_info (abfd))
7253 BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
7254 if (tls_type != GOT_TLS_LE)
7255 elf_local_got_refcounts (abfd)[r_symndx] += 1;
7256 old_tls_type = elf32_nds32_local_got_tls_type (abfd)[r_symndx];
7259 /* We would already have issued an error message if there
7260 is a TLS/non-TLS mismatch, based on the symbol
7261 type. So just combine any TLS types needed. */
7262 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7263 && tls_type != GOT_NORMAL)
7264 tls_type |= old_tls_type;
7266 /* DESC to IE/IEGP if link to executable. */
7267 if ((tls_type & (GOT_TLS_DESC | GOT_TLS_IEGP))
7268 && (bfd_link_executable (info)))
7269 tls_type |= (bfd_link_pie (info) ? GOT_TLS_IEGP : GOT_TLS_IE);
7271 if (old_tls_type != tls_type)
7274 elf32_nds32_hash_entry (h)->tls_type = tls_type;
7276 elf32_nds32_local_got_tls_type (abfd)[r_symndx] = tls_type;
7279 case R_NDS32_9_PLTREL:
7280 case R_NDS32_25_PLTREL:
7281 case R_NDS32_PLTREL_HI20:
7282 case R_NDS32_PLTREL_LO12:
7283 case R_NDS32_PLT_GOTREL_HI20:
7284 case R_NDS32_PLT_GOTREL_LO12:
7285 case R_NDS32_PLT_GOTREL_LO15:
7286 case R_NDS32_PLT_GOTREL_LO19:
7287 case R_NDS32_PLT_GOTREL_LO20:
7289 /* This symbol requires a procedure linkage table entry. We
7290 actually build the entry in adjust_dynamic_symbol,
7291 because this might be a case of linking PIC code without
7292 linking in any dynamic objects, in which case we don't
7293 need to generate a procedure linkage table after all. */
7295 /* If this is a local symbol, we resolve it directly without
7296 creating a procedure linkage table entry. */
7301 || (bfd_link_pie (info) && h->def_regular))
7304 elf32_nds32_hash_entry (h)->tls_type = GOT_NORMAL;
7306 h->plt.refcount += 1;
7309 case R_NDS32_16_RELA:
7310 case R_NDS32_20_RELA:
7311 case R_NDS32_5_RELA:
7312 case R_NDS32_32_RELA:
7313 case R_NDS32_HI20_RELA:
7314 case R_NDS32_LO12S3_RELA:
7315 case R_NDS32_LO12S2_RELA:
7316 case R_NDS32_LO12S2_DP_RELA:
7317 case R_NDS32_LO12S2_SP_RELA:
7318 case R_NDS32_LO12S1_RELA:
7319 case R_NDS32_LO12S0_RELA:
7320 case R_NDS32_LO12S0_ORI_RELA:
7321 case R_NDS32_SDA16S3_RELA:
7322 case R_NDS32_SDA17S2_RELA:
7323 case R_NDS32_SDA18S1_RELA:
7324 case R_NDS32_SDA19S0_RELA:
7325 case R_NDS32_SDA15S3_RELA:
7326 case R_NDS32_SDA15S2_RELA:
7327 case R_NDS32_SDA12S2_DP_RELA:
7328 case R_NDS32_SDA12S2_SP_RELA:
7329 case R_NDS32_SDA15S1_RELA:
7330 case R_NDS32_SDA15S0_RELA:
7331 case R_NDS32_SDA_FP7U2_RELA:
7332 case R_NDS32_15_PCREL_RELA:
7333 case R_NDS32_17_PCREL_RELA:
7334 case R_NDS32_25_PCREL_RELA:
7336 if (h != NULL && !bfd_link_pic (info))
7339 h->plt.refcount += 1;
7342 /* If we are creating a shared library, and this is a reloc against
7343 a global symbol, or a non PC relative reloc against a local
7344 symbol, then we need to copy the reloc into the shared library.
7345 However, if we are linking with -Bsymbolic, we do not need to
7346 copy a reloc against a global symbol which is defined in an
7347 object we are including in the link (i.e., DEF_REGULAR is set).
7348 At this point we have not seen all the input files, so it is
7349 possible that DEF_REGULAR is not set now but will be set later
7350 (it is never cleared). We account for that possibility below by
7351 storing information in the dyn_relocs field of the hash table
7352 entry. A similar situation occurs when creating shared libraries
7353 and symbol visibility changes render the symbol local.
7355 If on the other hand, we are creating an executable, we may need
7356 to keep relocations for symbols satisfied by a dynamic library
7357 if we manage to avoid copy relocs for the symbol. */
7358 if ((bfd_link_pic (info)
7359 && (sec->flags & SEC_ALLOC) != 0
7360 && ((r_type != R_NDS32_25_PCREL_RELA
7361 && r_type != R_NDS32_15_PCREL_RELA
7362 && r_type != R_NDS32_17_PCREL_RELA
7363 && !(r_type == R_NDS32_32_RELA
7364 && strcmp (sec->name, ".eh_frame") == 0))
7367 || h->root.type == bfd_link_hash_defweak
7368 || !h->def_regular))))
7369 || (!bfd_link_pic (info)
7370 && (sec->flags & SEC_ALLOC) != 0
7372 && (h->root.type == bfd_link_hash_defweak
7373 || !h->def_regular)))
7375 struct elf_dyn_relocs *p;
7376 struct elf_dyn_relocs **head;
7379 htab->root.dynobj = dynobj = abfd;
7381 /* When creating a shared object, we must copy these
7382 relocs into the output file. We create a reloc
7383 section in dynobj and make room for the reloc. */
7388 name = bfd_elf_string_from_elf_section
7389 (abfd, elf_elfheader (abfd)->e_shstrndx,
7390 elf_section_data (sec)->rela.hdr->sh_name);
7394 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
7395 && strcmp (bfd_get_section_name (abfd, sec),
7398 sreloc = bfd_get_section_by_name (dynobj, name);
7403 sreloc = bfd_make_section (dynobj, name);
7404 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7405 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7406 if ((sec->flags & SEC_ALLOC) != 0)
7407 flags |= SEC_ALLOC | SEC_LOAD;
7409 || !bfd_set_section_flags (dynobj, sreloc, flags)
7410 || !bfd_set_section_alignment (dynobj, sreloc, 2))
7413 elf_section_type (sreloc) = SHT_RELA;
7415 elf_section_data (sec)->sreloc = sreloc;
7418 /* If this is a global symbol, we count the number of
7419 relocations we need for this symbol. */
7421 head = &((struct elf_nds32_link_hash_entry *) h)->dyn_relocs;
7427 Elf_Internal_Sym *isym;
7428 isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
7432 /* Track dynamic relocs needed for local syms too. */
7433 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
7437 vpp = &elf_section_data (s)->local_dynrel;
7438 head = (struct elf_dyn_relocs **) vpp;
7442 if (p == NULL || p->sec != sec)
7444 bfd_size_type amt = sizeof (*p);
7445 p = (struct elf_dyn_relocs *) bfd_alloc (dynobj, amt);
7457 /* Since eh_frame is readonly, R_NDS32_32_RELA
7458 reloc for eh_frame will cause shared library has
7459 TEXTREL entry in the dynamic section. This lead glibc
7460 testsuites to failure (bug-13092) and cause kernel fail
7461 (bug-11819). I think the best solution is to replace
7462 absolute reloc with pc relative reloc in the eh_frame.
7463 To do that, we need to support the following issues:
7466 * gcc/config/nds32/nds32.h: Define
7467 ASM_PREFERRED_EH_DATA_FORMAT to encode DW_EH_PE_pcrel
7468 and DW_EH_PE_sdata4 into DWARF exception header when
7469 option have '-fpic'.
7471 === For binutils ===
7472 * bfd/: Define new reloc R_NDS32_32_PCREL_RELA.
7473 * gas/config/tc-nds32.h: Define DIFF_EXPR_OK. This
7474 may break our nds DIFF mechanism, therefore, we
7475 must disable all linker relaxations to ensure
7477 * gas/config/tc-nds32.c (nds32_apply_fix): Replace
7478 R_NDS32_32_RELA with R_NDS32_32_PCREL_RELA, and
7479 do the necessary modification.
7481 Unfortunately, it still have some problems for nds32
7482 to support pc relative reloc in the eh_frame. So I use
7483 another solution to fix this issue.
7485 However, I find that ld always emit TEXTREL marker for
7486 R_NDS32_NONE relocs in rel.dyn. These none relocs are
7487 correspond to R_NDS32_32_RELA for .eh_frame section.
7488 It means that we always reserve redundant entries of rel.dyn
7489 for these relocs which actually do nothing in dynamic linker.
7491 Therefore, we regard these relocs as pc relative relocs
7492 here and increase the pc_count. */
7493 if (ELF32_R_TYPE (rel->r_info) == R_NDS32_25_PCREL_RELA
7494 || ELF32_R_TYPE (rel->r_info) == R_NDS32_15_PCREL_RELA
7495 || ELF32_R_TYPE (rel->r_info) == R_NDS32_17_PCREL_RELA
7496 || (r_type == R_NDS32_32_RELA
7497 && strcmp (sec->name, ".eh_frame") == 0))
7502 /* This relocation describes the C++ object vtable hierarchy.
7503 Reconstruct it for later use during GC. */
7504 case R_NDS32_RELA_GNU_VTINHERIT:
7505 case R_NDS32_GNU_VTINHERIT:
7506 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7510 /* This relocation describes which C++ vtable entries are actually
7511 used. Record for later use during GC. */
7512 case R_NDS32_GNU_VTENTRY:
7513 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7516 case R_NDS32_RELA_GNU_VTENTRY:
7517 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
7526 /* Write VAL in uleb128 format to P, returning a pointer to the
7528 This code is copied from elf-attr.c. */
7531 write_uleb128 (bfd_byte *p, unsigned int val)
7546 static bfd_signed_vma
7547 calculate_offset (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
7548 Elf_Internal_Sym *isymbuf, Elf_Internal_Shdr *symtab_hdr)
7550 bfd_signed_vma foff;
7551 bfd_vma symval, addend;
7554 /* Get the value of the symbol referred to by the reloc. */
7555 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
7557 Elf_Internal_Sym *isym;
7559 /* A local symbol. */
7560 isym = isymbuf + ELF32_R_SYM (irel->r_info);
7562 if (isym->st_shndx == SHN_UNDEF)
7563 sym_sec = bfd_und_section_ptr;
7564 else if (isym->st_shndx == SHN_ABS)
7565 sym_sec = bfd_abs_section_ptr;
7566 else if (isym->st_shndx == SHN_COMMON)
7567 sym_sec = bfd_com_section_ptr;
7569 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
7570 symval = isym->st_value + sym_sec->output_section->vma
7571 + sym_sec->output_offset;
7576 struct elf_link_hash_entry *h;
7578 /* An external symbol. */
7579 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
7580 h = elf_sym_hashes (abfd)[indx];
7581 BFD_ASSERT (h != NULL);
7583 if (h->root.type != bfd_link_hash_defined
7584 && h->root.type != bfd_link_hash_defweak)
7585 /* This appears to be a reference to an undefined
7586 symbol. Just ignore it--it will be caught by the
7587 regular reloc processing. */
7590 if (h->root.u.def.section->flags & SEC_MERGE)
7592 sym_sec = h->root.u.def.section;
7593 symval = _bfd_merged_section_offset (abfd, &sym_sec,
7594 elf_section_data (sym_sec)->sec_info,
7595 h->root.u.def.value);
7596 symval = symval + sym_sec->output_section->vma
7597 + sym_sec->output_offset;
7600 symval = (h->root.u.def.value
7601 + h->root.u.def.section->output_section->vma
7602 + h->root.u.def.section->output_offset);
7605 addend = irel->r_addend;
7607 foff = (symval + addend
7608 - (irel->r_offset + sec->output_section->vma + sec->output_offset));
7613 /* Convert a 32-bit instruction to 16-bit one.
7614 INSN is the input 32-bit instruction, INSN16 is the output 16-bit
7615 instruction. If INSN_TYPE is not NULL, it the CGEN instruction
7616 type of INSN16. Return 1 if successful. */
7619 nds32_convert_32_to_16_alu1 (bfd *abfd, uint32_t insn, uint16_t *pinsn16,
7622 uint16_t insn16 = 0;
7624 unsigned long mach = bfd_get_mach (abfd);
7626 if (N32_SH5 (insn) != 0)
7629 switch (N32_SUB5 (insn))
7631 case N32_ALU1_ADD_SLLI:
7632 case N32_ALU1_ADD_SRLI:
7633 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn) && N32_IS_RB3 (insn))
7635 insn16 = N16_TYPE333 (ADD333, N32_RT5 (insn), N32_RA5 (insn),
7637 insn_type = NDS32_INSN_ADD333;
7639 else if (N32_IS_RT4 (insn))
7641 if (N32_RT5 (insn) == N32_RA5 (insn))
7642 insn16 = N16_TYPE45 (ADD45, N32_RT54 (insn), N32_RB5 (insn));
7643 else if (N32_RT5 (insn) == N32_RB5 (insn))
7644 insn16 = N16_TYPE45 (ADD45, N32_RT54 (insn), N32_RA5 (insn));
7645 insn_type = NDS32_INSN_ADD45;
7649 case N32_ALU1_SUB_SLLI:
7650 case N32_ALU1_SUB_SRLI:
7651 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn) && N32_IS_RB3 (insn))
7653 insn16 = N16_TYPE333 (SUB333, N32_RT5 (insn), N32_RA5 (insn),
7655 insn_type = NDS32_INSN_SUB333;
7657 else if (N32_IS_RT4 (insn) && N32_RT5 (insn) == N32_RA5 (insn))
7659 insn16 = N16_TYPE45 (SUB45, N32_RT54 (insn), N32_RB5 (insn));
7660 insn_type = NDS32_INSN_SUB45;
7664 case N32_ALU1_AND_SLLI:
7665 case N32_ALU1_AND_SRLI:
7666 /* and $rt, $rt, $rb -> and33 for v3, v3m. */
7667 if (mach >= MACH_V3 && N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
7668 && N32_IS_RB3 (insn))
7670 if (N32_RT5 (insn) == N32_RA5 (insn))
7671 insn16 = N16_MISC33 (AND33, N32_RT5 (insn), N32_RB5 (insn));
7672 else if (N32_RT5 (insn) == N32_RB5 (insn))
7673 insn16 = N16_MISC33 (AND33, N32_RT5 (insn), N32_RA5 (insn));
7675 insn_type = NDS32_INSN_AND33;
7679 case N32_ALU1_XOR_SLLI:
7680 case N32_ALU1_XOR_SRLI:
7681 /* xor $rt, $rt, $rb -> xor33 for v3, v3m. */
7682 if (mach >= MACH_V3 && N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
7683 && N32_IS_RB3 (insn))
7685 if (N32_RT5 (insn) == N32_RA5 (insn))
7686 insn16 = N16_MISC33 (XOR33, N32_RT5 (insn), N32_RB5 (insn));
7687 else if (N32_RT5 (insn) == N32_RB5 (insn))
7688 insn16 = N16_MISC33 (XOR33, N32_RT5 (insn), N32_RA5 (insn));
7690 insn_type = NDS32_INSN_XOR33;
7694 case N32_ALU1_OR_SLLI:
7695 case N32_ALU1_OR_SRLI:
7696 /* or $rt, $rt, $rb -> or33 for v3, v3m. */
7697 if (mach >= MACH_V3 && N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
7698 && N32_IS_RB3 (insn))
7700 if (N32_RT5 (insn) == N32_RA5 (insn))
7701 insn16 = N16_MISC33 (OR33, N32_RT5 (insn), N32_RB5 (insn));
7702 else if (N32_RT5 (insn) == N32_RB5 (insn))
7703 insn16 = N16_MISC33 (OR33, N32_RT5 (insn), N32_RA5 (insn));
7705 insn_type = NDS32_INSN_OR33;
7709 /* nor $rt, $ra, $ra -> not33 for v3, v3m. */
7710 if (mach >= MACH_V3 && N32_IS_RT3 (insn) && N32_IS_RB3 (insn)
7711 && N32_RA5 (insn) == N32_RB5 (insn))
7713 insn16 = N16_MISC33 (NOT33, N32_RT5 (insn), N32_RA5 (insn));
7714 insn_type = NDS32_INSN_NOT33;
7718 if (N32_IS_RT4 (insn) && N32_RT5 (insn) == N32_RA5 (insn))
7720 insn16 = N16_TYPE45 (SRAI45, N32_RT54 (insn), N32_UB5 (insn));
7721 insn_type = NDS32_INSN_SRAI45;
7726 if (N32_IS_RT4 (insn) && N32_RT5 (insn) == N32_RA5 (insn))
7728 insn16 = N16_TYPE45 (SRLI45, N32_RT54 (insn), N32_UB5 (insn));
7729 insn_type = NDS32_INSN_SRLI45;
7734 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn) && N32_UB5 (insn) < 8)
7736 insn16 = N16_TYPE333 (SLLI333, N32_RT5 (insn), N32_RA5 (insn),
7738 insn_type = NDS32_INSN_SLLI333;
7743 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn))
7745 insn16 = N16_BFMI333 (ZEH33, N32_RT5 (insn), N32_RA5 (insn));
7746 insn_type = NDS32_INSN_ZEH33;
7751 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn))
7753 insn16 = N16_BFMI333 (SEB33, N32_RT5 (insn), N32_RA5 (insn));
7754 insn_type = NDS32_INSN_SEB33;
7759 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn))
7761 insn16 = N16_BFMI333 (SEH33, N32_RT5 (insn), N32_RA5 (insn));
7762 insn_type = NDS32_INSN_SEH33;
7767 if (N32_RT5 (insn) == REG_R15 && N32_IS_RA4 (insn))
7770 insn16 = N16_TYPE45 (SLT45, N32_RA54 (insn), N32_RB5 (insn));
7771 insn_type = NDS32_INSN_SLT45;
7776 if (N32_RT5 (insn) == REG_R15 && N32_IS_RA4 (insn))
7779 insn16 = N16_TYPE45 (SLTS45, N32_RA54 (insn), N32_RB5 (insn));
7780 insn_type = NDS32_INSN_SLTS45;
7785 if ((insn16 & 0x8000) == 0)
7791 *pinsn_type = insn_type;
7796 nds32_convert_32_to_16_alu2 (bfd *abfd, uint32_t insn, uint16_t *pinsn16,
7799 uint16_t insn16 = 0;
7801 unsigned long mach = bfd_get_mach (abfd);
7803 /* TODO: bset, bclr, btgl, btst. */
7804 if (__GF (insn, 6, 4) != 0)
7807 switch (N32_IMMU (insn, 6))
7810 if (mach >= MACH_V3 && N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
7811 && N32_IS_RB3 (insn))
7813 if (N32_RT5 (insn) == N32_RA5 (insn))
7814 insn16 = N16_MISC33 (MUL33, N32_RT5 (insn), N32_RB5 (insn));
7815 else if (N32_RT5 (insn) == N32_RB5 (insn))
7816 insn16 = N16_MISC33 (MUL33, N32_RT5 (insn), N32_RA5 (insn));
7818 insn_type = NDS32_INSN_MUL33;
7822 if ((insn16 & 0x8000) == 0)
7828 *pinsn_type = insn_type;
7833 nds32_convert_32_to_16 (bfd *abfd, uint32_t insn, uint16_t *pinsn16,
7837 uint16_t insn16 = 0;
7839 unsigned long mach = bfd_get_mach (abfd);
7841 /* Decode 32-bit instruction. */
7842 if (insn & 0x80000000)
7844 /* Not 32-bit insn. */
7848 op6 = N32_OP6 (insn);
7850 /* Convert it to 16-bit instruction. */
7854 if (IS_WITHIN_S (N32_IMM20S (insn), 5))
7856 insn16 = N16_TYPE55 (MOVI55, N32_RT5 (insn), N32_IMM20S (insn));
7857 insn_type = NDS32_INSN_MOVI55;
7859 else if (mach >= MACH_V3 && N32_IMM20S (insn) >= 16
7860 && N32_IMM20S (insn) < 48 && N32_IS_RT4 (insn))
7862 insn16 = N16_TYPE45 (MOVPI45, N32_RT54 (insn),
7863 N32_IMM20S (insn) - 16);
7864 insn_type = NDS32_INSN_MOVPI45;
7869 if (N32_IMM15S (insn) == 0)
7871 /* Do not convert `addi $sp, $sp, 0' to `mov55 $sp, $sp',
7872 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7874 || N32_RT5 (insn) != REG_SP || N32_RA5 (insn) != REG_SP)
7876 insn16 = N16_TYPE55 (MOV55, N32_RT5 (insn), N32_RA5 (insn));
7877 insn_type = NDS32_INSN_MOV55;
7880 else if (N32_IMM15S (insn) > 0)
7882 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn) && N32_IMM15S (insn) < 8)
7884 insn16 = N16_TYPE333 (ADDI333, N32_RT5 (insn), N32_RA5 (insn),
7886 insn_type = NDS32_INSN_ADDI333;
7888 else if (N32_IS_RT4 (insn) && N32_RT5 (insn) == N32_RA5 (insn)
7889 && N32_IMM15S (insn) < 32)
7891 insn16 = N16_TYPE45 (ADDI45, N32_RT54 (insn), N32_IMM15S (insn));
7892 insn_type = NDS32_INSN_ADDI45;
7894 else if (mach >= MACH_V2 && N32_RT5 (insn) == REG_SP
7895 && N32_RT5 (insn) == N32_RA5 (insn)
7896 && N32_IMM15S (insn) < 512)
7898 insn16 = N16_TYPE10 (ADDI10S, N32_IMM15S (insn));
7899 insn_type = NDS32_INSN_ADDI10_SP;
7901 else if (mach >= MACH_V3 && N32_IS_RT3 (insn)
7902 && N32_RA5 (insn) == REG_SP && N32_IMM15S (insn) < 256
7903 && (N32_IMM15S (insn) % 4 == 0))
7905 insn16 = N16_TYPE36 (ADDRI36_SP, N32_RT5 (insn),
7906 N32_IMM15S (insn) >> 2);
7907 insn_type = NDS32_INSN_ADDRI36_SP;
7913 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn) && N32_IMM15S (insn) > -8)
7915 insn16 = N16_TYPE333 (SUBI333, N32_RT5 (insn), N32_RA5 (insn),
7916 0 - N32_IMM15S (insn));
7917 insn_type = NDS32_INSN_SUBI333;
7919 else if (N32_IS_RT4 (insn) && N32_RT5 (insn) == N32_RA5 (insn)
7920 && N32_IMM15S (insn) > -32)
7922 insn16 = N16_TYPE45 (SUBI45, N32_RT54 (insn),
7923 0 - N32_IMM15S (insn));
7924 insn_type = NDS32_INSN_SUBI45;
7926 else if (mach >= MACH_V2 && N32_RT5 (insn) == REG_SP
7927 && N32_RT5 (insn) == N32_RA5 (insn)
7928 && N32_IMM15S (insn) >= -512)
7930 insn16 = N16_TYPE10 (ADDI10S, N32_IMM15S (insn));
7931 insn_type = NDS32_INSN_ADDI10_SP;
7937 if (N32_IMM15S (insn) == 0)
7939 /* Do not convert `ori $sp, $sp, 0' to `mov55 $sp, $sp',
7940 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7942 || N32_RT5 (insn) != REG_SP || N32_RA5 (insn) != REG_SP)
7944 insn16 = N16_TYPE55 (MOV55, N32_RT5 (insn), N32_RA5 (insn));
7945 insn_type = NDS32_INSN_MOV55;
7951 if (mach >= MACH_V3 && N32_IS_RT3 (insn)
7952 && N32_IS_RA3 (insn) && N32_IMM15S (insn) == 0)
7954 insn16 = N16_MISC33 (NEG33, N32_RT5 (insn), N32_RA5 (insn));
7955 insn_type = NDS32_INSN_NEG33;
7960 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn))
7962 if (N32_IMM15U (insn) == 1)
7964 insn16 = N16_BFMI333 (XLSB33, N32_RT5 (insn), N32_RA5 (insn));
7965 insn_type = NDS32_INSN_XLSB33;
7967 else if (N32_IMM15U (insn) == 0x7ff)
7969 insn16 = N16_BFMI333 (X11B33, N32_RT5 (insn), N32_RA5 (insn));
7970 insn_type = NDS32_INSN_X11B33;
7972 else if (N32_IMM15U (insn) == 0xff)
7974 insn16 = N16_BFMI333 (ZEB33, N32_RT5 (insn), N32_RA5 (insn));
7975 insn_type = NDS32_INSN_ZEB33;
7977 else if (mach >= MACH_V3 && N32_RT5 (insn) == N32_RA5 (insn)
7978 && N32_IMM15U (insn) < 256)
7980 int imm15u = N32_IMM15U (insn);
7982 if (__builtin_popcount (imm15u) == 1)
7985 int imm3u = __builtin_ctz (imm15u);
7987 insn16 = N16_BFMI333 (BMSKI33, N32_RT5 (insn), imm3u);
7988 insn_type = NDS32_INSN_BMSKI33;
7990 else if (imm15u != 0 && __builtin_popcount (imm15u + 1) == 1)
7993 int imm3u = __builtin_ctz (imm15u + 1) - 1;
7995 insn16 = N16_BFMI333 (FEXTI33, N32_RT5 (insn), imm3u);
7996 insn_type = NDS32_INSN_FEXTI33;
8003 if (N32_RT5 (insn) == REG_R15 && N32_IS_RA4 (insn)
8004 && IS_WITHIN_U (N32_IMM15S (insn), 5))
8006 insn16 = N16_TYPE45 (SLTI45, N32_RA54 (insn), N32_IMM15S (insn));
8007 insn_type = NDS32_INSN_SLTI45;
8012 if (N32_RT5 (insn) == REG_R15 && N32_IS_RA4 (insn)
8013 && IS_WITHIN_U (N32_IMM15S (insn), 5))
8015 insn16 = N16_TYPE45 (SLTSI45, N32_RA54 (insn), N32_IMM15S (insn));
8016 insn_type = NDS32_INSN_SLTSI45;
8021 if (N32_IS_RT4 (insn) && N32_IMM15S (insn) == 0)
8023 insn16 = N16_TYPE45 (LWI450, N32_RT54 (insn), N32_RA5 (insn));
8024 insn_type = NDS32_INSN_LWI450;
8026 else if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8027 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8029 insn16 = N16_TYPE333 (LWI333, N32_RT5 (insn), N32_RA5 (insn),
8031 insn_type = NDS32_INSN_LWI333;
8033 else if (N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_FP
8034 && IS_WITHIN_U (N32_IMM15S (insn), 7))
8036 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 0, N32_IMM15S (insn));
8037 insn_type = NDS32_INSN_LWI37;
8039 else if (mach >= MACH_V2 && N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_SP
8040 && IS_WITHIN_U (N32_IMM15S (insn), 7))
8042 insn16 = N16_TYPE37 (XWI37SP, N32_RT5 (insn), 0, N32_IMM15S (insn));
8043 insn_type = NDS32_INSN_LWI37_SP;
8045 else if (mach >= MACH_V2 && N32_IS_RT4 (insn) && N32_RA5 (insn) == REG_R8
8046 && -32 <= N32_IMM15S (insn) && N32_IMM15S (insn) < 0)
8048 insn16 = N16_TYPE45 (LWI45_FE, N32_RT54 (insn),
8049 N32_IMM15S (insn) + 32);
8050 insn_type = NDS32_INSN_LWI45_FE;
8055 if (N32_IS_RT4 (insn) && N32_IMM15S (insn) == 0)
8057 insn16 = N16_TYPE45 (SWI450, N32_RT54 (insn), N32_RA5 (insn));
8058 insn_type = NDS32_INSN_SWI450;
8060 else if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8061 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8063 insn16 = N16_TYPE333 (SWI333, N32_RT5 (insn), N32_RA5 (insn),
8065 insn_type = NDS32_INSN_SWI333;
8067 else if (N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_FP
8068 && IS_WITHIN_U (N32_IMM15S (insn), 7))
8070 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 1, N32_IMM15S (insn));
8071 insn_type = NDS32_INSN_SWI37;
8073 else if (mach >= MACH_V2 && N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_SP
8074 && IS_WITHIN_U (N32_IMM15S (insn), 7))
8076 insn16 = N16_TYPE37 (XWI37SP, N32_RT5 (insn), 1, N32_IMM15S (insn));
8077 insn_type = NDS32_INSN_SWI37_SP;
8081 case N32_OP6_LWI_BI:
8082 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8083 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8085 insn16 = N16_TYPE333 (LWI333_BI, N32_RT5 (insn), N32_RA5 (insn),
8087 insn_type = NDS32_INSN_LWI333_BI;
8091 case N32_OP6_SWI_BI:
8092 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8093 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8095 insn16 = N16_TYPE333 (SWI333_BI, N32_RT5 (insn), N32_RA5 (insn),
8097 insn_type = NDS32_INSN_SWI333_BI;
8102 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8103 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8105 insn16 = N16_TYPE333 (LHI333, N32_RT5 (insn), N32_RA5 (insn),
8107 insn_type = NDS32_INSN_LHI333;
8112 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8113 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8115 insn16 = N16_TYPE333 (SHI333, N32_RT5 (insn), N32_RA5 (insn),
8117 insn_type = NDS32_INSN_SHI333;
8122 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8123 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8125 insn16 = N16_TYPE333 (LBI333, N32_RT5 (insn), N32_RA5 (insn),
8127 insn_type = NDS32_INSN_LBI333;
8132 if (N32_IS_RT3 (insn) && N32_IS_RA3 (insn)
8133 && IS_WITHIN_U (N32_IMM15S (insn), 3))
8135 insn16 = N16_TYPE333 (SBI333, N32_RT5 (insn), N32_RA5 (insn),
8137 insn_type = NDS32_INSN_SBI333;
8142 return nds32_convert_32_to_16_alu1 (abfd, insn, pinsn16, pinsn_type);
8145 return nds32_convert_32_to_16_alu2 (abfd, insn, pinsn16, pinsn_type);
8148 if (!IS_WITHIN_S (N32_IMM14S (insn), 8))
8151 if ((insn & N32_BIT (14)) == 0)
8154 if (N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_R5
8155 && N32_RT5 (insn) != REG_R5)
8156 insn16 = N16_TYPE38 (BEQS38, N32_RT5 (insn), N32_IMM14S (insn));
8157 else if (N32_IS_RA3 (insn) && N32_RT5 (insn) == REG_R5
8158 && N32_RA5 (insn) != REG_R5)
8159 insn16 = N16_TYPE38 (BEQS38, N32_RA5 (insn), N32_IMM14S (insn));
8160 insn_type = NDS32_INSN_BEQS38;
8166 if (N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_R5
8167 && N32_RT5 (insn) != REG_R5)
8168 insn16 = N16_TYPE38 (BNES38, N32_RT5 (insn), N32_IMM14S (insn));
8169 else if (N32_IS_RA3 (insn) && N32_RT5 (insn) == REG_R5
8170 && N32_RA5 (insn) != REG_R5)
8171 insn16 = N16_TYPE38 (BNES38, N32_RA5 (insn), N32_IMM14S (insn));
8172 insn_type = NDS32_INSN_BNES38;
8178 switch (N32_BR2_SUB (insn))
8181 if (N32_IS_RT3 (insn) && IS_WITHIN_S (N32_IMM16S (insn), 8))
8183 insn16 = N16_TYPE38 (BEQZ38, N32_RT5 (insn), N32_IMM16S (insn));
8184 insn_type = NDS32_INSN_BEQZ38;
8186 else if (N32_RT5 (insn) == REG_R15
8187 && IS_WITHIN_S (N32_IMM16S (insn), 8))
8189 insn16 = N16_TYPE8 (BEQZS8, N32_IMM16S (insn));
8190 insn_type = NDS32_INSN_BEQZS8;
8195 if (N32_IS_RT3 (insn) && IS_WITHIN_S (N32_IMM16S (insn), 8))
8197 insn16 = N16_TYPE38 (BNEZ38, N32_RT5 (insn), N32_IMM16S (insn));
8198 insn_type = NDS32_INSN_BNEZ38;
8200 else if (N32_RT5 (insn) == REG_R15
8201 && IS_WITHIN_S (N32_IMM16S (insn), 8))
8203 insn16 = N16_TYPE8 (BNEZS8, N32_IMM16S (insn));
8204 insn_type = NDS32_INSN_BNEZS8;
8209 if (__GF (insn, 20, 5) == 0 && IS_WITHIN_U (N32_IMM16S (insn), 9))
8211 insn16 = N16_TYPE9 (IFCALL9, N32_IMM16S (insn));
8212 insn_type = NDS32_INSN_IFCALL9;
8219 if ((insn & N32_BIT (24)) == 0)
8222 if (IS_WITHIN_S (N32_IMM24S (insn), 8))
8224 insn16 = N16_TYPE8 (J8, N32_IMM24S (insn));
8225 insn_type = NDS32_INSN_J8;
8231 if (__GF (insn, 8, 2) != 0)
8234 switch (N32_IMMU (insn, 5))
8237 if (N32_JREG_HINT (insn) == 0)
8240 insn16 = N16_TYPE5 (JR5, N32_RB5 (insn));
8241 insn_type = NDS32_INSN_JR5;
8243 else if (N32_JREG_HINT (insn) == 1)
8246 insn16 = N16_TYPE5 (RET5, N32_RB5 (insn));
8247 insn_type = NDS32_INSN_RET5;
8249 else if (N32_JREG_HINT (insn) == 3)
8251 /* ifret = mov55 $sp, $sp */
8252 insn16 = N16_TYPE55 (MOV55, REG_SP, REG_SP);
8253 insn_type = NDS32_INSN_IFRET;
8258 /* It's convertible when return rt5 is $lp and address
8259 translation is kept. */
8260 if (N32_RT5 (insn) == REG_LP && N32_JREG_HINT (insn) == 0)
8262 insn16 = N16_TYPE5 (JRAL5, N32_RB5 (insn));
8263 insn_type = NDS32_INSN_JRAL5;
8270 if (N32_SUB5 (insn) == N32_MISC_BREAK && N32_SWID (insn) < 32)
8272 /* For v3, swid above 31 are used for ex9.it. */
8273 insn16 = N16_TYPE5 (BREAK16, N32_SWID (insn));
8274 insn_type = NDS32_INSN_BREAK16;
8279 /* This instruction has no 16-bit variant. */
8284 /* Bit-15 of insn16 should be set for a valid instruction. */
8285 if ((insn16 & 0x8000) == 0)
8291 *pinsn_type = insn_type;
8296 special_convert_32_to_16 (unsigned long insn, uint16_t *pinsn16,
8297 Elf_Internal_Rela *reloc)
8299 uint16_t insn16 = 0;
8301 if ((reloc->r_addend & R_NDS32_INSN16_FP7U2_FLAG) == 0
8302 || (ELF32_R_TYPE (reloc->r_info) != R_NDS32_INSN16))
8305 if (!N32_IS_RT3 (insn))
8308 switch (N32_OP6 (insn))
8311 if (N32_RA5 (insn) == REG_GP && IS_WITHIN_U (N32_IMM15S (insn), 7))
8312 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 0, N32_IMM15S (insn));
8315 if (N32_RA5 (insn) == REG_GP && IS_WITHIN_U (N32_IMM15S (insn), 7))
8316 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 1, N32_IMM15S (insn));
8319 if (!IS_WITHIN_U (N32_IMM17S (insn), 7))
8322 if (__GF (insn, 17, 3) == 6)
8323 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 0, N32_IMM17S (insn));
8324 else if (__GF (insn, 17, 3) == 7)
8325 insn16 = N16_TYPE37 (XWI37, N32_RT5 (insn), 1, N32_IMM17S (insn));
8329 if ((insn16 & 0x8000) == 0)
8336 /* Convert a 16-bit instruction to 32-bit one.
8337 INSN16 it the input and PINSN it the point to output.
8338 Return non-zero on successful. Otherwise 0 is returned. */
8341 nds32_convert_16_to_32 (bfd *abfd, uint16_t insn16, uint32_t *pinsn)
8343 uint32_t insn = 0xffffffff;
8344 unsigned long mach = bfd_get_mach (abfd);
8346 /* NOTE: push25, pop25 and movd44 do not have 32-bit variants. */
8348 switch (__GF (insn16, 9, 6))
8350 case 0x4: /* add45 */
8351 insn = N32_ALU1 (ADD, N16_RT4 (insn16), N16_RT4 (insn16),
8354 case 0x5: /* sub45 */
8355 insn = N32_ALU1 (SUB, N16_RT4 (insn16), N16_RT4 (insn16),
8358 case 0x6: /* addi45 */
8359 insn = N32_TYPE2 (ADDI, N16_RT4 (insn16), N16_RT4 (insn16),
8360 N16_IMM5U (insn16));
8362 case 0x7: /* subi45 */
8363 insn = N32_TYPE2 (ADDI, N16_RT4 (insn16), N16_RT4 (insn16),
8364 -N16_IMM5U (insn16));
8366 case 0x8: /* srai45 */
8367 insn = N32_ALU1 (SRAI, N16_RT4 (insn16), N16_RT4 (insn16),
8368 N16_IMM5U (insn16));
8370 case 0x9: /* srli45 */
8371 insn = N32_ALU1 (SRLI, N16_RT4 (insn16), N16_RT4 (insn16),
8372 N16_IMM5U (insn16));
8374 case 0xa: /* slli333 */
8375 insn = N32_ALU1 (SLLI, N16_RT3 (insn16), N16_RA3 (insn16),
8376 N16_IMM3U (insn16));
8378 case 0xc: /* add333 */
8379 insn = N32_ALU1 (ADD, N16_RT3 (insn16), N16_RA3 (insn16),
8382 case 0xd: /* sub333 */
8383 insn = N32_ALU1 (SUB, N16_RT3 (insn16), N16_RA3 (insn16),
8386 case 0xe: /* addi333 */
8387 insn = N32_TYPE2 (ADDI, N16_RT3 (insn16), N16_RA3 (insn16),
8388 N16_IMM3U (insn16));
8390 case 0xf: /* subi333 */
8391 insn = N32_TYPE2 (ADDI, N16_RT3 (insn16), N16_RA3 (insn16),
8392 -N16_IMM3U (insn16));
8394 case 0x10: /* lwi333 */
8395 insn = N32_TYPE2 (LWI, N16_RT3 (insn16), N16_RA3 (insn16),
8396 N16_IMM3U (insn16));
8398 case 0x12: /* lhi333 */
8399 insn = N32_TYPE2 (LHI, N16_RT3 (insn16), N16_RA3 (insn16),
8400 N16_IMM3U (insn16));
8402 case 0x13: /* lbi333 */
8403 insn = N32_TYPE2 (LBI, N16_RT3 (insn16), N16_RA3 (insn16),
8404 N16_IMM3U (insn16));
8406 case 0x11: /* lwi333.bi */
8407 insn = N32_TYPE2 (LWI_BI, N16_RT3 (insn16), N16_RA3 (insn16),
8408 N16_IMM3U (insn16));
8410 case 0x14: /* swi333 */
8411 insn = N32_TYPE2 (SWI, N16_RT3 (insn16), N16_RA3 (insn16),
8412 N16_IMM3U (insn16));
8414 case 0x16: /* shi333 */
8415 insn = N32_TYPE2 (SHI, N16_RT3 (insn16), N16_RA3 (insn16),
8416 N16_IMM3U (insn16));
8418 case 0x17: /* sbi333 */
8419 insn = N32_TYPE2 (SBI, N16_RT3 (insn16), N16_RA3 (insn16),
8420 N16_IMM3U (insn16));
8422 case 0x15: /* swi333.bi */
8423 insn = N32_TYPE2 (SWI_BI, N16_RT3 (insn16), N16_RA3 (insn16),
8424 N16_IMM3U (insn16));
8426 case 0x18: /* addri36.sp */
8427 insn = N32_TYPE2 (ADDI, N16_RT3 (insn16), REG_SP,
8428 N16_IMM6U (insn16) << 2);
8430 case 0x19: /* lwi45.fe */
8431 insn = N32_TYPE2 (LWI, N16_RT4 (insn16), REG_R8,
8432 (N16_IMM5U (insn16) - 32));
8434 case 0x1a: /* lwi450 */
8435 insn = N32_TYPE2 (LWI, N16_RT4 (insn16), N16_RA5 (insn16), 0);
8437 case 0x1b: /* swi450 */
8438 insn = N32_TYPE2 (SWI, N16_RT4 (insn16), N16_RA5 (insn16), 0);
8441 /* These are r15 implied instructions. */
8442 case 0x30: /* slts45 */
8443 insn = N32_ALU1 (SLTS, REG_TA, N16_RT4 (insn16), N16_RA5 (insn16));
8445 case 0x31: /* slt45 */
8446 insn = N32_ALU1 (SLT, REG_TA, N16_RT4 (insn16), N16_RA5 (insn16));
8448 case 0x32: /* sltsi45 */
8449 insn = N32_TYPE2 (SLTSI, REG_TA, N16_RT4 (insn16), N16_IMM5U (insn16));
8451 case 0x33: /* slti45 */
8452 insn = N32_TYPE2 (SLTI, REG_TA, N16_RT4 (insn16), N16_IMM5U (insn16));
8454 case 0x34: /* beqzs8, bnezs8 */
8455 if (insn16 & N32_BIT (8))
8456 insn = N32_BR2 (BNEZ, REG_TA, N16_IMM8S (insn16));
8458 insn = N32_BR2 (BEQZ, REG_TA, N16_IMM8S (insn16));
8461 case 0x35: /* break16, ex9.it */
8462 /* Only consider range of v3 break16. */
8463 insn = N32_TYPE0 (MISC, (N16_IMM5U (insn16) << 5) | N32_MISC_BREAK);
8466 case 0x3c: /* ifcall9 */
8467 insn = N32_BR2 (SOP0, 0, N16_IMM9U (insn16));
8469 case 0x3d: /* movpi45 */
8470 insn = N32_TYPE1 (MOVI, N16_RT4 (insn16), N16_IMM5U (insn16) + 16);
8473 case 0x3f: /* MISC33 */
8474 switch (insn16 & 0x7)
8477 insn = N32_TYPE2 (SUBRI, N16_RT3 (insn16), N16_RA3 (insn16), 0);
8480 insn = N32_ALU1 (NOR, N16_RT3 (insn16), N16_RA3 (insn16),
8484 insn = N32_ALU2 (MUL, N16_RT3 (insn16), N16_RT3 (insn16),
8488 insn = N32_ALU1 (XOR, N16_RT3 (insn16), N16_RT3 (insn16),
8492 insn = N32_ALU1 (AND, N16_RT3 (insn16), N16_RT3 (insn16),
8496 insn = N32_ALU1 (OR, N16_RT3 (insn16), N16_RT3 (insn16),
8503 switch (insn16 & 0x7)
8506 insn = N32_TYPE2 (ANDI, N16_RT3 (insn16), N16_RA3 (insn16), 0xff);
8509 insn = N32_ALU1 (ZEH, N16_RT3 (insn16), N16_RA3 (insn16), 0);
8512 insn = N32_ALU1 (SEB, N16_RT3 (insn16), N16_RA3 (insn16), 0);
8515 insn = N32_ALU1 (SEH, N16_RT3 (insn16), N16_RA3 (insn16), 0);
8517 case 4: /* xlsb33 */
8518 insn = N32_TYPE2 (ANDI, N16_RT3 (insn16), N16_RA3 (insn16), 1);
8520 case 5: /* x11b33 */
8521 insn = N32_TYPE2 (ANDI, N16_RT3 (insn16), N16_RA3 (insn16), 0x7ff);
8523 case 6: /* bmski33 */
8524 insn = N32_TYPE2 (ANDI, N16_RT3 (insn16), N16_RT3 (insn16),
8525 1 << __GF (insn16, 3, 3));
8527 case 7: /* fexti33 */
8528 insn = N32_TYPE2 (ANDI, N16_RT3 (insn16), N16_RT3 (insn16),
8529 (1 << (__GF (insn16, 3, 3) + 1)) - 1);
8535 switch (__GF (insn16, 10, 5))
8537 case 0x0: /* mov55 or ifret16 */
8538 if (mach >= MACH_V3 && N16_RT5 (insn16) == REG_SP
8539 && N16_RT5 (insn16) == N16_RA5 (insn16))
8540 insn = N32_JREG (JR, 0, 0, 0, 3);
8542 insn = N32_TYPE2 (ADDI, N16_RT5 (insn16), N16_RA5 (insn16), 0);
8544 case 0x1: /* movi55 */
8545 insn = N32_TYPE1 (MOVI, N16_RT5 (insn16), N16_IMM5S (insn16));
8547 case 0x1b: /* addi10s (V2) */
8548 insn = N32_TYPE2 (ADDI, REG_SP, REG_SP, N16_IMM10S (insn16));
8552 switch (__GF (insn16, 11, 4))
8554 case 0x7: /* lwi37.fp/swi37.fp */
8555 if (insn16 & N32_BIT (7)) /* swi37.fp */
8556 insn = N32_TYPE2 (SWI, N16_RT38 (insn16), REG_FP, N16_IMM7U (insn16));
8558 insn = N32_TYPE2 (LWI, N16_RT38 (insn16), REG_FP, N16_IMM7U (insn16));
8560 case 0x8: /* beqz38 */
8561 insn = N32_BR2 (BEQZ, N16_RT38 (insn16), N16_IMM8S (insn16));
8563 case 0x9: /* bnez38 */
8564 insn = N32_BR2 (BNEZ, N16_RT38 (insn16), N16_IMM8S (insn16));
8566 case 0xa: /* beqs38/j8, implied r5 */
8567 if (N16_RT38 (insn16) == 5)
8568 insn = N32_JI (J, N16_IMM8S (insn16));
8570 insn = N32_BR1 (BEQ, N16_RT38 (insn16), REG_R5, N16_IMM8S (insn16));
8572 case 0xb: /* bnes38 and others. */
8573 if (N16_RT38 (insn16) == 5)
8575 switch (__GF (insn16, 5, 3))
8578 insn = N32_JREG (JR, 0, N16_RA5 (insn16), 0, 0);
8581 insn = N32_JREG (JR, 0, N16_RA5 (insn16), 0, 1);
8584 insn = N32_JREG (JRAL, REG_LP, N16_RA5 (insn16), 0, 0);
8586 case 2: /* ex9.it imm5 */
8587 /* ex9.it had no 32-bit variantl. */
8589 case 5: /* add5.pc */
8590 /* add5.pc had no 32-bit variantl. */
8595 insn = N32_BR1 (BNE, N16_RT38 (insn16), REG_R5, N16_IMM8S (insn16));
8597 case 0xe: /* lwi37/swi37 */
8598 if (insn16 & (1 << 7)) /* swi37.sp */
8599 insn = N32_TYPE2 (SWI, N16_RT38 (insn16), REG_SP, N16_IMM7U (insn16));
8601 insn = N32_TYPE2 (LWI, N16_RT38 (insn16), REG_SP, N16_IMM7U (insn16));
8606 if (insn & 0x80000000)
8616 is_sda_access_insn (unsigned long insn)
8618 switch (N32_OP6 (insn))
8639 static unsigned long
8640 turn_insn_to_sda_access (uint32_t insn, bfd_signed_vma type, uint32_t *pinsn)
8646 case R_NDS32_GOT_LO12:
8647 case R_NDS32_GOTOFF_LO12:
8648 case R_NDS32_PLTREL_LO12:
8649 case R_NDS32_PLT_GOTREL_LO12:
8650 case R_NDS32_LO12S0_RELA:
8651 switch (N32_OP6 (insn))
8655 oinsn = N32_TYPE1 (LBGP, N32_RT5 (insn), 0);
8659 oinsn = N32_TYPE1 (LBGP, N32_RT5 (insn), N32_BIT (19));
8663 oinsn = N32_TYPE1 (SBGP, N32_RT5 (insn), 0);
8667 oinsn = N32_TYPE1 (SBGP, N32_RT5 (insn), N32_BIT (19));
8672 case R_NDS32_LO12S1_RELA:
8673 switch (N32_OP6 (insn))
8677 oinsn = N32_TYPE1 (HWGP, N32_RT5 (insn), 0);
8681 oinsn = N32_TYPE1 (HWGP, N32_RT5 (insn), N32_BIT (18));
8685 oinsn = N32_TYPE1 (HWGP, N32_RT5 (insn), N32_BIT (19));
8690 case R_NDS32_LO12S2_RELA:
8691 switch (N32_OP6 (insn))
8695 oinsn = N32_TYPE1 (HWGP, N32_RT5 (insn), __MF (6, 17, 3));
8699 oinsn = N32_TYPE1 (HWGP, N32_RT5 (insn), __MF (7, 17, 3));
8704 case R_NDS32_LO12S2_DP_RELA:
8705 case R_NDS32_LO12S2_SP_RELA:
8706 oinsn = (insn & 0x7ff07000) | (REG_GP << 15);
8716 /* Linker hasn't found the correct merge section for non-section symbol
8717 in relax time, this work is left to the function elf_link_input_bfd().
8718 So for non-section symbol, _bfd_merged_section_offset is also needed
8719 to find the correct symbol address. */
8722 nds32_elf_rela_local_sym (bfd *abfd, Elf_Internal_Sym *sym,
8723 asection **psec, Elf_Internal_Rela *rel)
8725 asection *sec = *psec;
8728 relocation = (sec->output_section->vma
8729 + sec->output_offset + sym->st_value);
8730 if ((sec->flags & SEC_MERGE) && sec->sec_info_type == SEC_INFO_TYPE_MERGE)
8732 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8734 _bfd_merged_section_offset (abfd, psec,
8735 elf_section_data (sec)->sec_info,
8736 sym->st_value + rel->r_addend);
8739 _bfd_merged_section_offset (abfd, psec,
8740 elf_section_data (sec)->sec_info,
8741 sym->st_value) + rel->r_addend;
8745 /* If we have changed the section, and our original section is
8746 marked with SEC_EXCLUDE, it means that the original
8747 SEC_MERGE section has been completely subsumed in some
8748 other SEC_MERGE section. In this case, we need to leave
8749 some info around for --emit-relocs. */
8750 if ((sec->flags & SEC_EXCLUDE) != 0)
8751 sec->kept_section = *psec;
8754 rel->r_addend -= relocation;
8755 rel->r_addend += sec->output_section->vma + sec->output_offset;
8761 calculate_memory_address (bfd *abfd, Elf_Internal_Rela *irel,
8762 Elf_Internal_Sym *isymbuf,
8763 Elf_Internal_Shdr *symtab_hdr)
8765 bfd_signed_vma foff;
8766 bfd_vma symval, addend;
8767 Elf_Internal_Rela irel_fn;
8768 Elf_Internal_Sym *isym;
8771 /* Get the value of the symbol referred to by the reloc. */
8772 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
8774 /* A local symbol. */
8775 isym = isymbuf + ELF32_R_SYM (irel->r_info);
8777 if (isym->st_shndx == SHN_UNDEF)
8778 sym_sec = bfd_und_section_ptr;
8779 else if (isym->st_shndx == SHN_ABS)
8780 sym_sec = bfd_abs_section_ptr;
8781 else if (isym->st_shndx == SHN_COMMON)
8782 sym_sec = bfd_com_section_ptr;
8784 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
8785 memcpy (&irel_fn, irel, sizeof (Elf_Internal_Rela));
8786 symval = nds32_elf_rela_local_sym (abfd, isym, &sym_sec, &irel_fn);
8787 addend = irel_fn.r_addend;
8792 struct elf_link_hash_entry *h;
8794 /* An external symbol. */
8795 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
8796 h = elf_sym_hashes (abfd)[indx];
8797 BFD_ASSERT (h != NULL);
8799 while (h->root.type == bfd_link_hash_indirect
8800 || h->root.type == bfd_link_hash_warning)
8801 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8803 if (h->root.type != bfd_link_hash_defined
8804 && h->root.type != bfd_link_hash_defweak)
8805 /* This appears to be a reference to an undefined
8806 symbol. Just ignore it--it will be caught by the
8807 regular reloc processing. */
8810 if (h->root.u.def.section->flags & SEC_MERGE)
8812 sym_sec = h->root.u.def.section;
8813 symval = _bfd_merged_section_offset (abfd, &sym_sec, elf_section_data
8814 (sym_sec)->sec_info, h->root.u.def.value);
8815 symval = symval + sym_sec->output_section->vma
8816 + sym_sec->output_offset;
8819 symval = (h->root.u.def.value
8820 + h->root.u.def.section->output_section->vma
8821 + h->root.u.def.section->output_offset);
8822 addend = irel->r_addend;
8825 foff = symval + addend;
8831 is_16bit_NOP (bfd *abfd ATTRIBUTE_UNUSED,
8832 asection *sec, Elf_Internal_Rela *rel)
8835 unsigned short insn16;
8837 if (!(rel->r_addend & R_NDS32_INSN16_CONVERT_FLAG))
8839 contents = elf_section_data (sec)->this_hdr.contents;
8840 insn16 = bfd_getb16 (contents + rel->r_offset);
8841 if (insn16 == NDS32_NOP16)
8846 /* It checks whether the instruction could be converted to
8847 16-bit form and returns the converted one.
8849 `internal_relocs' is supposed to be sorted. */
8852 is_convert_32_to_16 (bfd *abfd, asection *sec,
8853 Elf_Internal_Rela *reloc,
8854 Elf_Internal_Rela *internal_relocs,
8855 Elf_Internal_Rela *irelend,
8858 #define NORMAL_32_TO_16 (1 << 0)
8859 #define SPECIAL_32_TO_16 (1 << 1)
8860 bfd_byte *contents = NULL;
8864 Elf_Internal_Rela *pc_rel;
8865 Elf_Internal_Shdr *symtab_hdr;
8866 Elf_Internal_Sym *isymbuf = NULL;
8870 if (reloc->r_offset + 4 > sec->size)
8873 offset = reloc->r_offset;
8875 if (!nds32_get_section_contents (abfd, sec, &contents, TRUE))
8877 insn = bfd_getb32 (contents + offset);
8879 if (nds32_convert_32_to_16 (abfd, insn, insn16, NULL))
8880 convert_type = NORMAL_32_TO_16;
8881 else if (special_convert_32_to_16 (insn, insn16, reloc))
8882 convert_type = SPECIAL_32_TO_16;
8886 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
8887 if (!nds32_get_local_syms (abfd, sec, &isymbuf))
8890 /* Find the first relocation of the same relocation-type,
8891 so we iteratie them forward. */
8893 while ((pc_rel - 1) >= internal_relocs && pc_rel[-1].r_offset == offset)
8896 for (; pc_rel < irelend && pc_rel->r_offset == offset; pc_rel++)
8898 if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_15_PCREL_RELA
8899 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_17_PCREL_RELA
8900 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_25_PCREL_RELA
8901 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_25_PLTREL)
8903 off = calculate_offset (abfd, sec, pc_rel, isymbuf, symtab_hdr);
8904 if (off >= ACCURATE_8BIT_S1 || off < -ACCURATE_8BIT_S1
8909 else if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_20_RELA)
8911 /* movi => movi55 */
8912 mem_addr = calculate_memory_address (abfd, pc_rel, isymbuf,
8914 /* mem_addr is unsigned, but the value should
8915 be between [-16, 15]. */
8916 if ((mem_addr + 0x10) >> 5)
8920 else if ((ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_TLS_LE_20)
8921 || (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_TLS_LE_LO12))
8923 /* It never happen movi to movi55 for R_NDS32_TLS_LE_20,
8924 because it can be relaxed to addi for TLS_LE_ADD. */
8927 else if ((ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_SDA15S2_RELA
8928 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_SDA17S2_RELA)
8929 && (reloc->r_addend & R_NDS32_INSN16_FP7U2_FLAG)
8930 && convert_type == SPECIAL_32_TO_16)
8933 We've selected a best fp-base for this access, so we can
8934 always resolve it anyway. Do nothing. */
8937 else if ((ELF32_R_TYPE (pc_rel->r_info) > R_NDS32_NONE
8938 && (ELF32_R_TYPE (pc_rel->r_info) < R_NDS32_RELA_GNU_VTINHERIT))
8939 || ((ELF32_R_TYPE (pc_rel->r_info) > R_NDS32_RELA_GNU_VTENTRY)
8940 && (ELF32_R_TYPE (pc_rel->r_info) < R_NDS32_INSN16))
8941 || ((ELF32_R_TYPE (pc_rel->r_info) > R_NDS32_LOADSTORE)
8942 && (ELF32_R_TYPE (pc_rel->r_info) < R_NDS32_DWARF2_OP1_RELA)))
8944 /* Prevent unresolved addi instruction translate
8945 to addi45 or addi333. */
8948 else if ((ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_17IFC_PCREL_RELA))
8950 off = calculate_offset (abfd, sec, pc_rel, isymbuf, symtab_hdr);
8951 if (off >= ACCURATE_U9BIT_S1 || off <= 0)
8961 nds32_elf_write_16 (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *contents,
8962 Elf_Internal_Rela *reloc,
8963 Elf_Internal_Rela *internal_relocs,
8964 Elf_Internal_Rela *irelend,
8965 unsigned short insn16)
8967 Elf_Internal_Rela *pc_rel;
8970 offset = reloc->r_offset;
8971 bfd_putb16 (insn16, contents + offset);
8972 /* Find the first relocation of the same relocation-type,
8973 so we iteratie them forward. */
8975 while ((pc_rel - 1) > internal_relocs && pc_rel[-1].r_offset == offset)
8978 for (; pc_rel < irelend && pc_rel->r_offset == offset; pc_rel++)
8980 if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_15_PCREL_RELA
8981 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_17_PCREL_RELA
8982 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_25_PCREL_RELA)
8985 ELF32_R_INFO (ELF32_R_SYM (pc_rel->r_info), R_NDS32_9_PCREL_RELA);
8987 else if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_25_PLTREL)
8989 ELF32_R_INFO (ELF32_R_SYM (pc_rel->r_info), R_NDS32_9_PLTREL);
8990 else if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_20_RELA)
8992 ELF32_R_INFO (ELF32_R_SYM (pc_rel->r_info), R_NDS32_5_RELA);
8993 else if (ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_SDA15S2_RELA
8994 || ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_SDA17S2_RELA)
8996 ELF32_R_INFO (ELF32_R_SYM (pc_rel->r_info), R_NDS32_SDA_FP7U2_RELA);
8997 else if ((ELF32_R_TYPE (pc_rel->r_info) == R_NDS32_17IFC_PCREL_RELA))
8999 ELF32_R_INFO (ELF32_R_SYM (pc_rel->r_info), R_NDS32_10IFCU_PCREL_RELA);
9003 /* Find a relocation of type specified by `reloc_type'
9004 of the same r_offset with reloc.
9005 If not found, return irelend.
9007 Assuming relocations are sorted by r_offset,
9008 we find the relocation from `reloc' backward untill relocs,
9009 or find it from `reloc' forward untill irelend. */
9011 static Elf_Internal_Rela *
9012 find_relocs_at_address (Elf_Internal_Rela *reloc,
9013 Elf_Internal_Rela *relocs,
9014 Elf_Internal_Rela *irelend,
9015 enum elf_nds32_reloc_type reloc_type)
9017 Elf_Internal_Rela *rel_t;
9019 /* Find backward. */
9021 rel_t >= relocs && rel_t->r_offset == reloc->r_offset;
9023 if (ELF32_R_TYPE (rel_t->r_info) == reloc_type)
9026 /* We didn't find it backward. Try find it forward. */
9028 rel_t < irelend && rel_t->r_offset == reloc->r_offset;
9030 if (ELF32_R_TYPE (rel_t->r_info) == reloc_type)
9036 /* Find a relocation of specified type and offset.
9037 `reloc' is just a refence point to find a relocation at specified offset.
9038 If not found, return irelend.
9040 Assuming relocations are sorted by r_offset,
9041 we find the relocation from `reloc' backward untill relocs,
9042 or find it from `reloc' forward untill irelend. */
9044 static Elf_Internal_Rela *
9045 find_relocs_at_address_addr (Elf_Internal_Rela *reloc,
9046 Elf_Internal_Rela *relocs,
9047 Elf_Internal_Rela *irelend,
9048 enum elf_nds32_reloc_type reloc_type,
9051 Elf_Internal_Rela *rel_t = NULL;
9053 /* First, we try to find a relocation of offset `offset_p',
9054 and then we use find_relocs_at_address to find specific type. */
9056 if (reloc->r_offset > offset_p)
9058 /* Find backward. */
9060 rel_t >= relocs && rel_t->r_offset > offset_p; rel_t--)
9063 else if (reloc->r_offset < offset_p)
9067 rel_t < irelend && rel_t->r_offset < offset_p; rel_t++)
9074 if (rel_t < relocs || rel_t == irelend || rel_t->r_offset != offset_p)
9077 return find_relocs_at_address (rel_t, relocs, irelend, reloc_type);
9080 typedef struct nds32_elf_blank nds32_elf_blank_t;
9081 struct nds32_elf_blank
9083 /* Where the blank begins. */
9085 /* The size of the blank. */
9087 /* The accumulative size before this blank. */
9089 nds32_elf_blank_t *next;
9090 nds32_elf_blank_t *prev;
9093 static nds32_elf_blank_t *blank_free_list = NULL;
9095 static nds32_elf_blank_t *
9096 create_nds32_elf_blank (bfd_vma offset_p, bfd_vma size_p)
9098 nds32_elf_blank_t *blank_t;
9100 if (blank_free_list)
9102 blank_t = blank_free_list;
9103 blank_free_list = blank_free_list->next;
9106 blank_t = bfd_malloc (sizeof (nds32_elf_blank_t));
9108 if (blank_t == NULL)
9111 blank_t->offset = offset_p;
9112 blank_t->size = size_p;
9113 blank_t->total_size = 0;
9114 blank_t->next = NULL;
9115 blank_t->prev = NULL;
9121 remove_nds32_elf_blank (nds32_elf_blank_t *blank_p)
9123 if (blank_free_list)
9125 blank_free_list->prev = blank_p;
9126 blank_p->next = blank_free_list;
9129 blank_p->next = NULL;
9131 blank_p->prev = NULL;
9132 blank_free_list = blank_p;
9136 clean_nds32_elf_blank (void)
9138 nds32_elf_blank_t *blank_t;
9140 while (blank_free_list)
9142 blank_t = blank_free_list;
9143 blank_free_list = blank_free_list->next;
9148 static nds32_elf_blank_t *
9149 search_nds32_elf_blank (nds32_elf_blank_t *blank_p, bfd_vma addr)
9151 nds32_elf_blank_t *blank_t;
9157 while (blank_t && addr < blank_t->offset)
9158 blank_t = blank_t->prev;
9159 while (blank_t && blank_t->next && addr >= blank_t->next->offset)
9160 blank_t = blank_t->next;
9166 get_nds32_elf_blank_total (nds32_elf_blank_t **blank_p, bfd_vma addr,
9169 nds32_elf_blank_t *blank_t;
9171 blank_t = search_nds32_elf_blank (*blank_p, addr);
9178 if (addr < blank_t->offset + blank_t->size)
9179 return blank_t->total_size + (addr - blank_t->offset);
9181 return blank_t->total_size + blank_t->size;
9185 insert_nds32_elf_blank (nds32_elf_blank_t **blank_p, bfd_vma addr, bfd_vma len)
9187 nds32_elf_blank_t *blank_t, *blank_t2;
9191 *blank_p = create_nds32_elf_blank (addr, len);
9192 return *blank_p ? TRUE : FALSE;
9195 blank_t = search_nds32_elf_blank (*blank_p, addr);
9197 if (blank_t == NULL)
9199 blank_t = create_nds32_elf_blank (addr, len);
9202 while ((*blank_p)->prev != NULL)
9203 *blank_p = (*blank_p)->prev;
9204 blank_t->next = *blank_p;
9205 (*blank_p)->prev = blank_t;
9206 (*blank_p) = blank_t;
9210 if (addr < blank_t->offset + blank_t->size)
9212 /* Extend the origin blank. */
9213 if (addr + len > blank_t->offset + blank_t->size)
9214 blank_t->size = addr + len - blank_t->offset;
9218 blank_t2 = create_nds32_elf_blank (addr, len);
9223 blank_t->next->prev = blank_t2;
9224 blank_t2->next = blank_t->next;
9226 blank_t2->prev = blank_t;
9227 blank_t->next = blank_t2;
9228 *blank_p = blank_t2;
9235 insert_nds32_elf_blank_recalc_total (nds32_elf_blank_t **blank_p, bfd_vma addr,
9238 nds32_elf_blank_t *blank_t;
9240 if (!insert_nds32_elf_blank (blank_p, addr, len))
9247 blank_t->total_size = 0;
9248 blank_t = blank_t->next;
9253 blank_t->total_size = blank_t->prev->total_size + blank_t->prev->size;
9254 blank_t = blank_t->next;
9261 calc_nds32_blank_total (nds32_elf_blank_t *blank_p)
9263 nds32_elf_blank_t *blank_t;
9264 bfd_vma total_size = 0;
9270 while (blank_t->prev)
9271 blank_t = blank_t->prev;
9274 blank_t->total_size = total_size;
9275 total_size += blank_t->size;
9276 blank_t = blank_t->next;
9281 nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
9282 nds32_elf_blank_t *blank_p)
9284 Elf_Internal_Shdr *symtab_hdr; /* Symbol table header of this bfd. */
9285 Elf_Internal_Sym *isym = NULL; /* Symbol table of this bfd. */
9286 Elf_Internal_Sym *isymend; /* Symbol entry iterator. */
9287 unsigned int sec_shndx; /* The section the be relaxed. */
9288 bfd_byte *contents; /* Contents data of iterating section. */
9289 Elf_Internal_Rela *internal_relocs;
9290 Elf_Internal_Rela *irel;
9291 Elf_Internal_Rela *irelend;
9292 struct elf_link_hash_entry **sym_hashes;
9293 struct elf_link_hash_entry **end_hashes;
9294 unsigned int symcount;
9296 nds32_elf_blank_t *blank_t;
9297 nds32_elf_blank_t *blank_t2;
9298 nds32_elf_blank_t *blank_head;
9300 blank_head = blank_t = blank_p;
9301 while (blank_head->prev != NULL)
9302 blank_head = blank_head->prev;
9303 while (blank_t->next != NULL)
9304 blank_t = blank_t->next;
9306 if (blank_t->offset + blank_t->size <= sec->size)
9308 blank_t->next = create_nds32_elf_blank (sec->size + 4, 0);
9309 blank_t->next->prev = blank_t;
9311 if (blank_head->offset > 0)
9313 blank_head->prev = create_nds32_elf_blank (0, 0);
9314 blank_head->prev->next = blank_head;
9315 blank_head = blank_head->prev;
9318 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
9320 /* The deletion must stop at the next ALIGN reloc for an alignment
9321 power larger than the number of bytes we are deleting. */
9323 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
9324 if (!nds32_get_local_syms (abfd, sec, &isym))
9329 isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
9330 symtab_hdr->sh_info, 0, NULL, NULL, NULL);
9331 symtab_hdr->contents = (bfd_byte *) isym;
9334 if (isym == NULL || symtab_hdr->sh_info == 0)
9337 blank_t = blank_head;
9338 calc_nds32_blank_total (blank_head);
9340 for (sect = abfd->sections; sect != NULL; sect = sect->next)
9342 /* Adjust all the relocs. */
9344 /* Relocations MUST be kept in memory, because relaxation adjust them. */
9345 internal_relocs = _bfd_elf_link_read_relocs (abfd, sect, NULL, NULL,
9346 TRUE /* keep_memory */);
9347 irelend = internal_relocs + sect->reloc_count;
9349 blank_t = blank_head;
9350 blank_t2 = blank_head;
9352 if (!(sect->flags & SEC_RELOC))
9355 nds32_get_section_contents (abfd, sect, &contents, TRUE);
9357 for (irel = internal_relocs; irel < irelend; irel++)
9361 if (ELF32_R_TYPE (irel->r_info) >= R_NDS32_DIFF8
9362 && ELF32_R_TYPE (irel->r_info) <= R_NDS32_DIFF32
9363 && isym[ELF32_R_SYM (irel->r_info)].st_shndx == sec_shndx)
9365 unsigned long val = 0;
9367 long before, between;
9370 switch (ELF32_R_TYPE (irel->r_info))
9373 offset = bfd_get_8 (abfd, contents + irel->r_offset);
9375 case R_NDS32_DIFF16:
9376 offset = bfd_get_16 (abfd, contents + irel->r_offset);
9378 case R_NDS32_DIFF32:
9379 val = bfd_get_32 (abfd, contents + irel->r_offset);
9380 /* Get the signed bit and mask for the high part. The
9381 gcc will alarm when right shift 32-bit since the
9382 type size of long may be 32-bit. */
9383 mask = 0 - (val >> 31);
9385 offset = (val | (mask - 0xffffffff));
9394 0 |encoded in location|
9395 |------------|-------------------|---------
9397 -- before ---| *****************
9398 --------------------- between ---|
9400 We only care how much data are relax between DIFF,
9403 before = get_nds32_elf_blank_total (&blank_t, irel->r_addend, 0);
9404 between = get_nds32_elf_blank_total (&blank_t,
9405 irel->r_addend + offset, 0);
9406 if (between == before)
9407 goto done_adjust_diff;
9409 switch (ELF32_R_TYPE (irel->r_info))
9412 bfd_put_8 (abfd, offset - (between - before),
9413 contents + irel->r_offset);
9415 case R_NDS32_DIFF16:
9416 bfd_put_16 (abfd, offset - (between - before),
9417 contents + irel->r_offset);
9419 case R_NDS32_DIFF32:
9420 bfd_put_32 (abfd, offset - (between - before),
9421 contents + irel->r_offset);
9425 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_DIFF_ULEB128
9426 && isym[ELF32_R_SYM (irel->r_info)].st_shndx == sec_shndx)
9429 unsigned int len = 0;
9430 unsigned long before, between;
9433 val = _bfd_read_unsigned_leb128 (abfd, contents + irel->r_offset,
9436 before = get_nds32_elf_blank_total (&blank_t, irel->r_addend, 0);
9437 between = get_nds32_elf_blank_total (&blank_t,
9438 irel->r_addend + val, 0);
9439 if (between == before)
9440 goto done_adjust_diff;
9442 p = contents + irel->r_offset;
9444 memset (p, 0x80, len);
9446 p = write_uleb128 (p, val - (between - before)) - 1;
9454 raddr = irel->r_offset;
9455 irel->r_offset -= get_nds32_elf_blank_total (&blank_t2,
9458 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_NONE)
9460 if (blank_t2 && blank_t2->next
9461 && (blank_t2->offset > raddr
9462 || blank_t2->next->offset <= raddr))
9464 (_("%pB: error: search_nds32_elf_blank reports wrong node"),
9467 /* Mark reloc in deleted portion as NONE.
9468 For some relocs like R_NDS32_LABEL that doesn't modify the
9469 content in the section. R_NDS32_LABEL doesn't belong to the
9470 instruction in the section, so we should preserve it. */
9471 if (raddr >= blank_t2->offset
9472 && raddr < blank_t2->offset + blank_t2->size
9473 && ELF32_R_TYPE (irel->r_info) != R_NDS32_LABEL
9474 && ELF32_R_TYPE (irel->r_info) != R_NDS32_RELAX_REGION_BEGIN
9475 && ELF32_R_TYPE (irel->r_info) != R_NDS32_RELAX_REGION_END
9476 && ELF32_R_TYPE (irel->r_info) != R_NDS32_RELAX_ENTRY
9477 && ELF32_R_TYPE (irel->r_info) != R_NDS32_SUBTRAHEND
9478 && ELF32_R_TYPE (irel->r_info) != R_NDS32_MINUEND)
9480 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
9486 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_NONE
9487 || ELF32_R_TYPE (irel->r_info) == R_NDS32_LABEL
9488 || ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_ENTRY)
9491 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info
9492 && isym[ELF32_R_SYM (irel->r_info)].st_shndx == sec_shndx
9493 && ELF_ST_TYPE (isym[ELF32_R_SYM (irel->r_info)].st_info) == STT_SECTION)
9495 if (irel->r_addend <= sec->size)
9497 get_nds32_elf_blank_total (&blank_t, irel->r_addend, 1);
9502 /* Adjust the local symbols defined in this section. */
9503 blank_t = blank_head;
9504 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
9506 if (isym->st_shndx == sec_shndx)
9508 if (isym->st_value <= sec->size)
9511 bfd_vma orig_addr = isym->st_value;
9513 ahead = get_nds32_elf_blank_total (&blank_t, isym->st_value, 1);
9514 isym->st_value -= ahead;
9516 /* Adjust function size. */
9517 if (ELF32_ST_TYPE (isym->st_info) == STT_FUNC
9518 && isym->st_size > 0)
9520 get_nds32_elf_blank_total
9521 (&blank_t, orig_addr + isym->st_size, 0) - ahead;
9526 /* Now adjust the global symbols defined in this section. */
9527 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
9528 - symtab_hdr->sh_info);
9529 sym_hashes = elf_sym_hashes (abfd);
9530 end_hashes = sym_hashes + symcount;
9531 blank_t = blank_head;
9532 for (; sym_hashes < end_hashes; sym_hashes++)
9534 struct elf_link_hash_entry *sym_hash = *sym_hashes;
9536 if ((sym_hash->root.type == bfd_link_hash_defined
9537 || sym_hash->root.type == bfd_link_hash_defweak)
9538 && sym_hash->root.u.def.section == sec)
9540 if (sym_hash->root.u.def.value <= sec->size)
9543 bfd_vma orig_addr = sym_hash->root.u.def.value;
9545 ahead = get_nds32_elf_blank_total (&blank_t, sym_hash->root.u.def.value, 1);
9546 sym_hash->root.u.def.value -= ahead;
9548 /* Adjust function size. */
9549 if (sym_hash->type == STT_FUNC)
9551 get_nds32_elf_blank_total
9552 (&blank_t, orig_addr + sym_hash->size, 0) - ahead;
9558 contents = elf_section_data (sec)->this_hdr.contents;
9559 blank_t = blank_head;
9560 while (blank_t->next)
9562 /* Actually delete the bytes. */
9564 /* If current blank is the last blank overlap with current section,
9565 go to finish process. */
9566 if (sec->size <= (blank_t->next->offset))
9569 memmove (contents + blank_t->offset - blank_t->total_size,
9570 contents + blank_t->offset + blank_t->size,
9571 blank_t->next->offset - (blank_t->offset + blank_t->size));
9573 blank_t = blank_t->next;
9576 if (sec->size > (blank_t->offset + blank_t->size))
9578 /* There are remaining code between blank and section boundary.
9579 Move the remaining code to appropriate location. */
9580 memmove (contents + blank_t->offset - blank_t->total_size,
9581 contents + blank_t->offset + blank_t->size,
9582 sec->size - (blank_t->offset + blank_t->size));
9583 sec->size -= blank_t->total_size + blank_t->size;
9586 /* This blank is not entirely included in the section,
9587 reduce the section size by only part of the blank size. */
9588 sec->size -= blank_t->total_size + (sec->size - blank_t->offset);
9592 blank_t = blank_head;
9593 blank_head = blank_head->next;
9594 remove_nds32_elf_blank (blank_t);
9600 /* Get the contents of a section. */
9603 nds32_get_section_contents (bfd *abfd, asection *sec,
9604 bfd_byte **contents_p, bfd_boolean cache)
9606 /* Get the section contents. */
9607 if (elf_section_data (sec)->this_hdr.contents != NULL)
9608 *contents_p = elf_section_data (sec)->this_hdr.contents;
9611 if (!bfd_malloc_and_get_section (abfd, sec, contents_p))
9614 elf_section_data (sec)->this_hdr.contents = *contents_p;
9620 /* Get the contents of the internal symbol of abfd. */
9623 nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
9624 Elf_Internal_Sym **isymbuf_p)
9626 Elf_Internal_Shdr *symtab_hdr;
9627 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
9629 /* Read this BFD's local symbols if we haven't done so already. */
9630 if (*isymbuf_p == NULL && symtab_hdr->sh_info != 0)
9632 *isymbuf_p = (Elf_Internal_Sym *) symtab_hdr->contents;
9633 if (*isymbuf_p == NULL)
9635 *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
9636 symtab_hdr->sh_info, 0,
9638 if (*isymbuf_p == NULL)
9642 symtab_hdr->contents = (bfd_byte *) (*isymbuf_p);
9647 /* Range of small data. */
9648 static bfd_vma sdata_range[2][2];
9649 static bfd_vma const sdata_init_range[2] =
9650 { ACCURATE_12BIT_S1, ACCURATE_19BIT };
9653 nds32_elf_insn_size (bfd *abfd ATTRIBUTE_UNUSED,
9654 bfd_byte *contents, bfd_vma addr)
9656 unsigned long insn = bfd_getb32 (contents + addr);
9658 if (insn & 0x80000000)
9664 /* Set the gp relax range. We have to measure the safe range
9665 to do gp relaxation. */
9668 relax_range_measurement (bfd *abfd)
9670 asection *sec_f, *sec_b;
9671 /* For upper bound. */
9672 bfd_vma maxpgsz = get_elf_backend_data (abfd)->maxpagesize;
9674 static int decide_relax_range = 0;
9676 int range_number = ARRAY_SIZE (sdata_init_range);
9678 if (decide_relax_range)
9680 decide_relax_range = 1;
9682 if (sda_rela_sec == NULL)
9684 /* Since there is no data sections, we assume the range is page size. */
9685 for (i = 0; i < range_number; i++)
9687 sdata_range[i][0] = sdata_init_range[i] - 0x1000;
9688 sdata_range[i][1] = sdata_init_range[i] - 0x1000;
9693 /* Get the biggest alignment power after the gp located section. */
9694 sec_f = sda_rela_sec->output_section;
9695 sec_b = sec_f->next;
9697 while (sec_b != NULL)
9699 if ((unsigned)(1 << sec_b->alignment_power) > align)
9700 align = (1 << sec_b->alignment_power);
9701 sec_b = sec_b->next;
9704 /* I guess we can not determine the section before
9705 gp located section, so we assume the align is max page size. */
9706 for (i = 0; i < range_number; i++)
9708 sdata_range[i][1] = sdata_init_range[i] - align;
9709 BFD_ASSERT (sdata_range[i][1] <= sdata_init_range[i]);
9710 sdata_range[i][0] = sdata_init_range[i] - maxpgsz;
9711 BFD_ASSERT (sdata_range[i][0] <= sdata_init_range[i]);
9715 /* These are macros used to check flags encoded in r_addend.
9716 They are only used by nds32_elf_relax_section (). */
9717 #define GET_SEQ_LEN(addend) ((addend) & 0x000000ff)
9718 #define IS_1ST_CONVERT(addend) ((addend) & 0x80000000)
9719 #define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
9720 #define IS_16BIT_ON(addend) ((addend) & 0x20000000)
9722 static const char * unrecognized_reloc_msg =
9723 /* xgettext:c-format */
9724 N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64);
9726 /* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
9729 nds32_elf_relax_longcall1 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
9730 Elf_Internal_Rela *internal_relocs, int *insn_len,
9731 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
9732 Elf_Internal_Shdr *symtab_hdr)
9734 /* There are 3 variations for LONGCALL1
9735 case 4-4-2; 16-bit on, optimize off or optimize for space
9736 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9737 ori ta, ta, lo12(symbol) ; LO12S0
9740 case 4-4-4; 16-bit off, optimize don't care
9741 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9742 ori ta, ta, lo12(symbol) ; LO12S0
9745 case 4-4-4; 16-bit on, optimize for speed
9746 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9747 ori ta, ta, lo12(symbol) ; LO12S0
9749 Check code for -mlong-calls output. */
9751 /* Get the reloc for the address from which the register is
9752 being loaded. This reloc will tell us which function is
9753 actually being called. */
9756 int seq_len; /* Original length of instruction sequence. */
9758 Elf_Internal_Rela *hi_irelfn, *lo_irelfn, *irelend;
9759 bfd_signed_vma foff;
9762 irelend = internal_relocs + sec->reloc_count;
9763 seq_len = GET_SEQ_LEN (irel->r_addend);
9764 laddr = irel->r_offset;
9765 *insn_len = seq_len;
9767 hi_irelfn = find_relocs_at_address_addr (irel, internal_relocs, irelend,
9768 R_NDS32_HI20_RELA, laddr);
9769 lo_irelfn = find_relocs_at_address_addr (irel, internal_relocs, irelend,
9770 R_NDS32_LO12S0_ORI_RELA,
9773 if (hi_irelfn == irelend || lo_irelfn == irelend)
9775 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL1",
9776 (uint64_t) irel->r_offset);
9780 /* Get the value of the symbol referred to by the reloc. */
9781 foff = calculate_offset (abfd, sec, hi_irelfn, isymbuf, symtab_hdr);
9783 /* This condition only happened when symbol is undefined. */
9785 || foff < -CONSERVATIVE_24BIT_S1
9786 || foff >= CONSERVATIVE_24BIT_S1)
9789 /* Relax to: jal symbol; 25_PCREL. */
9790 /* For simplicity of coding, we are going to modify the section
9791 contents, the section relocs, and the BFD symbol table. We
9792 must tell the rest of the code not to free up this
9793 information. It would be possible to instead create a table
9794 of changes which have to be made, as is done in coff-mips.c;
9795 that would be more work, but would require less memory when
9796 the linker is run. */
9798 /* Replace the long call with a jal. */
9799 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
9800 R_NDS32_25_PCREL_RELA);
9801 irel->r_addend = hi_irelfn->r_addend;
9803 /* We don't resolve this here but resolve it in relocate_section. */
9805 bfd_putb32 (insn, contents + irel->r_offset);
9808 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_NDS32_NONE);
9810 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_NONE);
9815 insn16 = NDS32_NOP16;
9816 bfd_putb16 (insn16, contents + irel->r_offset + *insn_len);
9818 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_INSN16);
9819 lo_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
9825 #define CONVERT_CONDITION_CALL(insn) (((insn) & 0xffff0000) ^ 0x90000)
9826 /* Relax LONGCALL2 relocation for nds32_elf_relax_section. */
9829 nds32_elf_relax_longcall2 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
9830 Elf_Internal_Rela *internal_relocs, int *insn_len,
9831 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
9832 Elf_Internal_Shdr *symtab_hdr)
9834 /* bltz rt, .L1 ; LONGCALL2
9835 jal symbol ; 25_PCREL
9838 /* Get the reloc for the address from which the register is
9839 being loaded. This reloc will tell us which function is
9840 actually being called. */
9844 Elf_Internal_Rela *i1_irelfn, *cond_irelfn, *irelend;
9845 bfd_signed_vma foff;
9847 irelend = internal_relocs + sec->reloc_count;
9848 laddr = irel->r_offset;
9850 find_relocs_at_address_addr (irel, internal_relocs, irelend,
9851 R_NDS32_25_PCREL_RELA, laddr + 4);
9853 if (i1_irelfn == irelend)
9855 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL2",
9856 (uint64_t) irel->r_offset);
9860 insn = bfd_getb32 (contents + laddr);
9862 /* Get the value of the symbol referred to by the reloc. */
9863 foff = calculate_offset (abfd, sec, i1_irelfn, isymbuf, symtab_hdr);
9866 || foff < -CONSERVATIVE_16BIT_S1
9867 || foff >= CONSERVATIVE_16BIT_S1)
9870 /* Relax to bgezal rt, label ; 17_PCREL
9871 or bltzal rt, label ; 17_PCREL */
9873 /* Convert to complimentary conditional call. */
9874 insn = CONVERT_CONDITION_CALL (insn);
9876 /* For simplicity of coding, we are going to modify the section
9877 contents, the section relocs, and the BFD symbol table. We
9878 must tell the rest of the code not to free up this
9879 information. It would be possible to instead create a table
9880 of changes which have to be made, as is done in coff-mips.c;
9881 that would be more work, but would require less memory when
9882 the linker is run. */
9884 /* Clean unnessary relocations. */
9886 ELF32_R_INFO (ELF32_R_SYM (i1_irelfn->r_info), R_NDS32_NONE);
9888 find_relocs_at_address_addr (irel, internal_relocs, irelend,
9889 R_NDS32_17_PCREL_RELA, laddr);
9890 if (cond_irelfn != irelend)
9891 cond_irelfn->r_info =
9892 ELF32_R_INFO (ELF32_R_SYM (cond_irelfn->r_info), R_NDS32_NONE);
9894 /* Replace the long call with a bgezal. */
9895 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (i1_irelfn->r_info),
9896 R_NDS32_17_PCREL_RELA);
9897 irel->r_addend = i1_irelfn->r_addend;
9899 bfd_putb32 (insn, contents + irel->r_offset);
9905 /* Relax LONGCALL3 relocation for nds32_elf_relax_section. */
9908 nds32_elf_relax_longcall3 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
9909 Elf_Internal_Rela *internal_relocs, int *insn_len,
9910 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
9911 Elf_Internal_Shdr *symtab_hdr)
9913 /* There are 3 variations for LONGCALL3
9914 case 4-4-4-2; 16-bit on, optimize off or optimize for space
9915 bltz rt, $1 ; LONGCALL3
9916 sethi ta, hi20(symbol) ; HI20
9917 ori ta, ta, lo12(symbol) ; LO12S0
9921 case 4-4-4-4; 16-bit off, optimize don't care
9922 bltz rt, $1 ; LONGCALL3
9923 sethi ta, hi20(symbol) ; HI20
9924 ori ta, ta, lo12(symbol) ; LO12S0
9928 case 4-4-4-4; 16-bit on, optimize for speed
9929 bltz rt, $1 ; LONGCALL3
9930 sethi ta, hi20(symbol) ; HI20
9931 ori ta, ta, lo12(symbol) ; LO12S0
9935 /* Get the reloc for the address from which the register is
9936 being loaded. This reloc will tell us which function is
9937 actually being called. */
9940 int seq_len; /* Original length of instruction sequence. */
9942 Elf_Internal_Rela *hi_irelfn, *lo_irelfn, *cond_irelfn, *irelend;
9943 bfd_signed_vma foff;
9946 irelend = internal_relocs + sec->reloc_count;
9947 seq_len = GET_SEQ_LEN (irel->r_addend);
9948 laddr = irel->r_offset;
9949 *insn_len = seq_len;
9952 find_relocs_at_address_addr (irel, internal_relocs, irelend,
9953 R_NDS32_HI20_RELA, laddr + 4);
9955 find_relocs_at_address_addr (irel, internal_relocs, irelend,
9956 R_NDS32_LO12S0_ORI_RELA, laddr + 8);
9958 if (hi_irelfn == irelend || lo_irelfn == irelend)
9960 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL3",
9961 (uint64_t) irel->r_offset);
9965 /* Get the value of the symbol referred to by the reloc. */
9966 foff = calculate_offset (abfd, sec, hi_irelfn, isymbuf, symtab_hdr);
9969 || foff < -CONSERVATIVE_24BIT_S1
9970 || foff >= CONSERVATIVE_24BIT_S1)
9973 insn = bfd_getb32 (contents + laddr);
9974 if (foff >= -CONSERVATIVE_16BIT_S1 && foff < CONSERVATIVE_16BIT_S1)
9976 /* Relax to bgezal rt, label ; 17_PCREL
9977 or bltzal rt, label ; 17_PCREL */
9979 /* Convert to complimentary conditional call. */
9980 insn = CONVERT_CONDITION_CALL (insn);
9981 bfd_putb32 (insn, contents + irel->r_offset);
9985 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_NDS32_NONE);
9987 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_NDS32_NONE);
9989 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_NONE);
9992 find_relocs_at_address_addr (irel, internal_relocs, irelend,
9993 R_NDS32_17_PCREL_RELA, laddr);
9994 if (cond_irelfn != irelend)
9996 cond_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
9997 R_NDS32_17_PCREL_RELA);
9998 cond_irelfn->r_addend = hi_irelfn->r_addend;
10003 insn16 = NDS32_NOP16;
10004 bfd_putb16 (insn16, contents + irel->r_offset + *insn_len);
10005 hi_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
10007 hi_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
10011 else if (foff >= -CONSERVATIVE_24BIT_S1 && foff < CONSERVATIVE_24BIT_S1)
10013 /* Relax to the following instruction sequence
10014 bltz rt, $1 ; LONGCALL2
10015 jal symbol ; 25_PCREL
10019 bfd_putb32 (insn, contents + hi_irelfn->r_offset);
10021 hi_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
10022 R_NDS32_25_PCREL_RELA);
10024 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_LONGCALL2);
10026 lo_irelfn->r_info =
10027 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_NONE);
10031 insn16 = NDS32_NOP16;
10032 bfd_putb16 (insn16, contents + irel->r_offset + *insn_len);
10033 lo_irelfn->r_info =
10034 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_INSN16);
10035 lo_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
10042 /* Relax LONGJUMP1 relocation for nds32_elf_relax_section. */
10045 nds32_elf_relax_longjump1 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10046 Elf_Internal_Rela *internal_relocs, int *insn_len,
10047 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10048 Elf_Internal_Shdr *symtab_hdr)
10050 /* There are 3 variations for LONGJUMP1
10051 case 4-4-2; 16-bit bit on, optimize off or optimize for space
10052 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10053 ori ta, ta, lo12(symbol) ; LO12S0
10056 case 4-4-4; 16-bit off, optimize don't care
10057 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10058 ori ta, ta, lo12(symbol) ; LO12S0
10061 case 4-4-4; 16-bit on, optimize for speed
10062 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10063 ori ta, ta, lo12(symbol) ; LO12S0
10066 /* Get the reloc for the address from which the register is
10067 being loaded. This reloc will tell us which function is
10068 actually being called. */
10071 int seq_len; /* Original length of instruction sequence. */
10072 int insn16_on; /* 16-bit on/off. */
10074 Elf_Internal_Rela *hi_irelfn, *lo_irelfn, *irelend;
10075 bfd_signed_vma foff;
10077 unsigned long reloc;
10079 irelend = internal_relocs + sec->reloc_count;
10080 seq_len = GET_SEQ_LEN (irel->r_addend);
10081 laddr = irel->r_offset;
10082 *insn_len = seq_len;
10083 insn16_on = IS_16BIT_ON (irel->r_addend);
10086 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10087 R_NDS32_HI20_RELA, laddr);
10089 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10090 R_NDS32_LO12S0_ORI_RELA, laddr + 4);
10091 if (hi_irelfn == irelend || lo_irelfn == irelend)
10093 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP1",
10094 (uint64_t) irel->r_offset);
10098 /* Get the value of the symbol referred to by the reloc. */
10099 foff = calculate_offset (abfd, sec, hi_irelfn, isymbuf, symtab_hdr);
10102 || foff >= CONSERVATIVE_24BIT_S1
10103 || foff < -CONSERVATIVE_24BIT_S1)
10107 && foff >= -ACCURATE_8BIT_S1
10108 && foff < ACCURATE_8BIT_S1
10109 && (seq_len & 0x2))
10112 /* 16-bit on, but not optimized for speed. */
10113 reloc = R_NDS32_9_PCREL_RELA;
10115 bfd_putb16 (insn16, contents + irel->r_offset);
10118 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
10123 reloc = R_NDS32_25_PCREL_RELA;
10125 bfd_putb32 (insn, contents + irel->r_offset);
10128 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_INSN16);
10129 irel->r_addend = 0;
10132 hi_irelfn->r_info =
10133 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), reloc);
10134 lo_irelfn->r_info =
10135 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_NDS32_NONE);
10137 if ((seq_len & 0x2) && ((*insn_len & 2) == 0))
10139 insn16 = NDS32_NOP16;
10140 bfd_putb16 (insn16, contents + irel->r_offset + *insn_len);
10141 lo_irelfn->r_info =
10142 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info),
10144 lo_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
10150 /* Revert condition branch. This function does not check if the input
10151 instruction is condition branch or not. */
10154 nds32_elf_convert_branch (uint16_t insn16, uint32_t insn,
10155 uint16_t *re_insn16, uint32_t *re_insn)
10157 uint32_t comp_insn = 0;
10158 uint16_t comp_insn16 = 0;
10162 if (N32_OP6 (insn) == N32_OP6_BR1)
10165 comp_insn = (insn ^ 0x4000) & 0xffffc000;
10166 if (N32_IS_RT3 (insn) && N32_RA5 (insn) == REG_R5)
10168 /* Insn can be contracted to 16-bit implied r5. */
10170 (comp_insn & 0x4000) ? INSN_BNES38 : INSN_BEQS38;
10171 comp_insn16 |= (N32_RT5 (insn) & 0x7) << 8;
10174 else if (N32_OP6 (insn) == N32_OP6_BR3)
10176 /* bnec $ta, imm11, label. */
10177 comp_insn = (insn ^ 0x80000) & 0xffffff00;
10181 comp_insn = (insn ^ 0x10000) & 0xffffc000;
10182 if (N32_BR2_SUB (insn) == N32_BR2_BEQZ
10183 || N32_BR2_SUB (insn) == N32_BR2_BNEZ)
10185 if (N32_IS_RT3 (insn))
10187 /* Insn can be contracted to 16-bit. */
10189 (comp_insn & 0x10000) ? INSN_BNEZ38 : INSN_BEQZ38;
10190 comp_insn16 |= (N32_RT5 (insn) & 0x7) << 8;
10192 else if (N32_RT5 (insn) == REG_R15)
10194 /* Insn can be contracted to 16-bit. */
10196 (comp_insn & 0x10000) ? INSN_BNES38 : INSN_BEQS38;
10203 switch ((insn16 & 0xf000) >> 12)
10206 /* beqz38 or bnez38 */
10207 comp_insn16 = (insn16 ^ 0x0800) & 0xff00;
10208 comp_insn = (comp_insn16 & 0x0800) ? INSN_BNEZ : INSN_BEQZ;
10209 comp_insn |= ((comp_insn16 & 0x0700) >> 8) << 20;
10213 /* beqs38 or bnes38 */
10214 comp_insn16 = (insn16 ^ 0x0800) & 0xff00;
10215 comp_insn = (comp_insn16 & 0x0800) ? INSN_BNE : INSN_BEQ;
10216 comp_insn |= (((comp_insn16 & 0x0700) >> 8) << 20)
10221 /* beqzS8 or bnezS8 */
10222 comp_insn16 = (insn16 ^ 0x0100) & 0xff00;
10223 comp_insn = (comp_insn16 & 0x0100) ? INSN_BNEZ : INSN_BEQZ;
10224 comp_insn |= REG_R15 << 20;
10231 if (comp_insn && re_insn)
10232 *re_insn = comp_insn;
10233 if (comp_insn16 && re_insn16)
10234 *re_insn16 = comp_insn16;
10237 /* Relax LONGJUMP2 relocation for nds32_elf_relax_section. */
10240 nds32_elf_relax_longjump2 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10241 Elf_Internal_Rela *internal_relocs, int *insn_len,
10242 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10243 Elf_Internal_Shdr *symtab_hdr)
10245 /* There are 3 variations for LONGJUMP2
10246 case 2-4; 1st insn convertible, 16-bit on,
10247 optimize off or optimize for space
10248 bnes38 rt, ra, $1 ; LONGJUMP2
10252 case 4-4; 1st insn not convertible
10253 bne rt, ra, $1 ; LONGJUMP2
10257 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10258 bne rt, ra, $1 ; LONGJUMP2
10262 /* Get the reloc for the address from which the register is
10263 being loaded. This reloc will tell us which function is
10264 actually being called. */
10267 int seq_len; /* Original length of instruction sequence. */
10268 Elf_Internal_Rela *i2_irelfn, *cond_irelfn, *irelend;
10271 bfd_signed_vma foff;
10272 uint32_t insn, re_insn = 0;
10273 uint16_t insn16, re_insn16 = 0;
10274 unsigned long reloc, cond_reloc;
10276 enum elf_nds32_reloc_type checked_types[] =
10277 { R_NDS32_15_PCREL_RELA, R_NDS32_9_PCREL_RELA };
10279 irelend = internal_relocs + sec->reloc_count;
10280 seq_len = GET_SEQ_LEN (irel->r_addend);
10281 laddr = irel->r_offset;
10282 *insn_len = seq_len;
10283 first_size = (seq_len == 6) ? 2 : 4;
10286 find_relocs_at_address_addr (irel, internal_relocs,
10287 irelend, R_NDS32_25_PCREL_RELA,
10288 laddr + first_size);
10290 for (i = 0; i < ARRAY_SIZE (checked_types); i++)
10293 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10294 checked_types[i], laddr);
10295 if (cond_irelfn != irelend)
10299 if (i2_irelfn == irelend || cond_irelfn == irelend)
10301 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP2",
10302 (uint64_t) irel->r_offset);
10306 /* Get the value of the symbol referred to by the reloc. */
10307 foff = calculate_offset (abfd, sec, i2_irelfn, isymbuf, symtab_hdr);
10309 || foff < -CONSERVATIVE_16BIT_S1
10310 || foff >= CONSERVATIVE_16BIT_S1)
10313 /* Get the all corresponding instructions. */
10314 if (first_size == 4)
10316 insn = bfd_getb32 (contents + laddr);
10317 nds32_elf_convert_branch (0, insn, &re_insn16, &re_insn);
10321 insn16 = bfd_getb16 (contents + laddr);
10322 nds32_elf_convert_branch (insn16, 0, &re_insn16, &re_insn);
10325 if (re_insn16 && foff >= -(ACCURATE_8BIT_S1 - first_size)
10326 && foff < ACCURATE_8BIT_S1 - first_size)
10328 if (first_size == 4)
10330 /* Don't convert it to 16-bit now, keep this as relaxable for
10331 ``label reloc; INSN16''. */
10333 /* Save comp_insn32 to buffer. */
10334 bfd_putb32 (re_insn, contents + irel->r_offset);
10336 reloc = (N32_OP6 (re_insn) == N32_OP6_BR1) ?
10337 R_NDS32_15_PCREL_RELA : R_NDS32_17_PCREL_RELA;
10338 cond_reloc = R_NDS32_INSN16;
10342 bfd_putb16 (re_insn16, contents + irel->r_offset);
10344 reloc = R_NDS32_9_PCREL_RELA;
10345 cond_reloc = R_NDS32_NONE;
10348 else if (N32_OP6 (re_insn) == N32_OP6_BR1
10349 && (foff >= -(ACCURATE_14BIT_S1 - first_size)
10350 && foff < ACCURATE_14BIT_S1 - first_size))
10352 /* beqs label ; 15_PCREL */
10353 bfd_putb32 (re_insn, contents + irel->r_offset);
10355 reloc = R_NDS32_15_PCREL_RELA;
10356 cond_reloc = R_NDS32_NONE;
10358 else if (N32_OP6 (re_insn) == N32_OP6_BR2
10359 && foff >= -CONSERVATIVE_16BIT_S1
10360 && foff < CONSERVATIVE_16BIT_S1)
10362 /* beqz label ; 17_PCREL */
10363 bfd_putb32 (re_insn, contents + irel->r_offset);
10365 reloc = R_NDS32_17_PCREL_RELA;
10366 cond_reloc = R_NDS32_NONE;
10371 /* Set all relocations. */
10372 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (i2_irelfn->r_info), reloc);
10373 irel->r_addend = i2_irelfn->r_addend;
10375 cond_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irelfn->r_info),
10377 cond_irelfn->r_addend = 0;
10379 if ((seq_len ^ *insn_len ) & 0x2)
10381 insn16 = NDS32_NOP16;
10382 bfd_putb16 (insn16, contents + irel->r_offset + 4);
10383 i2_irelfn->r_offset = 4;
10384 i2_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (i2_irelfn->r_info),
10386 i2_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
10390 i2_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (i2_irelfn->r_info),
10395 /* Relax LONGJUMP3 relocation for nds32_elf_relax_section. */
10398 nds32_elf_relax_longjump3 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10399 Elf_Internal_Rela *internal_relocs, int *insn_len,
10400 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10401 Elf_Internal_Shdr *symtab_hdr)
10403 /* There are 5 variations for LONGJUMP3
10404 case 1: 2-4-4-2; 1st insn convertible, 16-bit on,
10405 optimize off or optimize for space
10406 bnes38 rt, ra, $1 ; LONGJUMP3
10407 sethi ta, hi20(symbol) ; HI20
10408 ori ta, ta, lo12(symbol) ; LO12S0
10412 case 2: 2-4-4-2; 1st insn convertible, 16-bit on, optimize for speed
10413 bnes38 rt, ra, $1 ; LONGJUMP3
10414 sethi ta, hi20(symbol) ; HI20
10415 ori ta, ta, lo12(symbol) ; LO12S0
10419 case 3: 4-4-4-2; 1st insn not convertible, 16-bit on,
10420 optimize off or optimize for space
10421 bne rt, ra, $1 ; LONGJUMP3
10422 sethi ta, hi20(symbol) ; HI20
10423 ori ta, ta, lo12(symbol) ; LO12S0
10427 case 4: 4-4-4-4; 1st insn don't care, 16-bit off, optimize don't care
10428 16-bit off if no INSN16
10429 bne rt, ra, $1 ; LONGJUMP3
10430 sethi ta, hi20(symbol) ; HI20
10431 ori ta, ta, lo12(symbol) ; LO12S0
10435 case 5: 4-4-4-4; 1st insn not convertible, 16-bit on, optimize for speed
10436 16-bit off if no INSN16
10437 bne rt, ra, $1 ; LONGJUMP3
10438 sethi ta, hi20(symbol) ; HI20
10439 ori ta, ta, lo12(symbol) ; LO12S0
10443 /* Get the reloc for the address from which the register is
10444 being loaded. This reloc will tell us which function is
10445 actually being called. */
10446 enum elf_nds32_reloc_type checked_types[] =
10447 { R_NDS32_15_PCREL_RELA, R_NDS32_9_PCREL_RELA };
10449 int reloc_off = 0, cond_removed = 0, convertible;
10451 int seq_len; /* Original length of instruction sequence. */
10452 Elf_Internal_Rela *hi_irelfn, *lo_irelfn, *cond_irelfn, *irelend;
10455 bfd_signed_vma foff;
10456 uint32_t insn, re_insn = 0;
10457 uint16_t insn16, re_insn16 = 0;
10458 unsigned long reloc, cond_reloc;
10460 irelend = internal_relocs + sec->reloc_count;
10461 seq_len = GET_SEQ_LEN (irel->r_addend);
10462 laddr = irel->r_offset;
10463 *insn_len = seq_len;
10465 convertible = IS_1ST_CONVERT (irel->r_addend);
10472 /* Get all needed relocations. */
10474 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10475 R_NDS32_HI20_RELA, laddr + first_size);
10477 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10478 R_NDS32_LO12S0_ORI_RELA,
10479 laddr + first_size + 4);
10481 for (i = 0; i < ARRAY_SIZE (checked_types); i++)
10484 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10485 checked_types[i], laddr);
10486 if (cond_irelfn != irelend)
10490 if (hi_irelfn == irelend
10491 || lo_irelfn == irelend
10492 || cond_irelfn == irelend)
10494 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP3",
10495 (uint64_t) irel->r_offset);
10499 /* Get the value of the symbol referred to by the reloc. */
10500 foff = calculate_offset (abfd, sec, hi_irelfn, isymbuf, symtab_hdr);
10503 || foff < -CONSERVATIVE_24BIT_S1
10504 || foff >= CONSERVATIVE_24BIT_S1)
10507 /* Get the all corresponding instructions. */
10508 if (first_size == 4)
10510 insn = bfd_getb32 (contents + laddr);
10511 nds32_elf_convert_branch (0, insn, &re_insn16, &re_insn);
10515 insn16 = bfd_getb16 (contents + laddr);
10516 nds32_elf_convert_branch (insn16, 0, &re_insn16, &re_insn);
10519 /* For simplicity of coding, we are going to modify the section
10520 contents, the section relocs, and the BFD symbol table. We
10521 must tell the rest of the code not to free up this
10522 information. It would be possible to instead create a table
10523 of changes which have to be made, as is done in coff-mips.c;
10524 that would be more work, but would require less memory when
10525 the linker is run. */
10528 && foff >= -ACCURATE_8BIT_S1 - first_size
10529 && foff < ACCURATE_8BIT_S1 - first_size)
10531 if (!(seq_len & 0x2))
10533 /* Don't convert it to 16-bit now, keep this as relaxable
10534 for ``label reloc; INSN1a''6. */
10535 /* Save comp_insn32 to buffer. */
10536 bfd_putb32 (re_insn, contents + irel->r_offset);
10538 reloc = (N32_OP6 (re_insn) == N32_OP6_BR1) ?
10539 R_NDS32_15_PCREL_RELA : R_NDS32_17_PCREL_RELA;
10540 cond_reloc = R_NDS32_INSN16;
10544 /* Not optimize for speed; convert sequence to 16-bit. */
10545 /* Save comp_insn16 to buffer. */
10546 bfd_putb16 (re_insn16, contents + irel->r_offset);
10548 reloc = R_NDS32_9_PCREL_RELA;
10549 cond_reloc = R_NDS32_NONE;
10553 else if (N32_OP6 (re_insn) == N32_OP6_BR1
10554 && (foff >= -(ACCURATE_14BIT_S1 - first_size)
10555 && foff < ACCURATE_14BIT_S1 - first_size))
10557 /* beqs label ; 15_PCREL */
10558 bfd_putb32 (re_insn, contents + irel->r_offset);
10560 reloc = R_NDS32_15_PCREL_RELA;
10561 cond_reloc = R_NDS32_NONE;
10564 else if (N32_OP6 (re_insn) == N32_OP6_BR2
10565 && foff >= -CONSERVATIVE_16BIT_S1
10566 && foff < CONSERVATIVE_16BIT_S1)
10568 /* beqz label ; 17_PCREL */
10569 bfd_putb32 (re_insn, contents + irel->r_offset);
10571 reloc = R_NDS32_17_PCREL_RELA;
10572 cond_reloc = R_NDS32_NONE;
10575 else if (foff >= -CONSERVATIVE_24BIT_S1 - reloc_off
10576 && foff < CONSERVATIVE_24BIT_S1 - reloc_off)
10578 /* Relax to one of the following 3 variations
10580 case 2-4; 1st insn convertible, 16-bit on, optimize off or optimize
10582 bnes38 rt, $1 ; LONGJUMP2
10586 case 4-4; 1st insn not convertible, others don't care
10587 bne rt, ra, $1 ; LONGJUMP2
10591 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10592 bne rt, ra, $1 ; LONGJUMP2
10596 /* Offset for first instruction. */
10598 /* Use j label as second instruction. */
10599 *insn_len = 4 + first_size;
10601 bfd_putb32 (insn, contents + hi_irelfn->r_offset);
10602 reloc = R_NDS32_LONGJUMP2;
10603 cond_reloc = R_NDS32_25_PLTREL;
10608 if (cond_removed == 1)
10610 /* Set all relocations. */
10611 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), reloc);
10612 irel->r_addend = hi_irelfn->r_addend;
10614 cond_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irelfn->r_info),
10616 cond_irelfn->r_addend = 0;
10617 hi_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
10622 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), reloc);
10623 irel->r_addend = irel->r_addend;
10624 hi_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
10628 if ((seq_len ^ *insn_len ) & 0x2)
10630 insn16 = NDS32_NOP16;
10631 bfd_putb16 (insn16, contents + irel->r_offset + *insn_len);
10632 lo_irelfn->r_offset = *insn_len;
10633 lo_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info),
10635 lo_irelfn->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
10639 lo_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info),
10644 /* Relax LONGCALL4 relocation for nds32_elf_relax_section. */
10647 nds32_elf_relax_longcall4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10648 Elf_Internal_Rela *internal_relocs, int *insn_len,
10649 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10650 Elf_Internal_Shdr *symtab_hdr)
10652 /* The pattern for LONGCALL4. Support for function cse.
10653 sethi ta, hi20(symbol) ; LONGCALL4/HI20
10654 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10655 jral ta ; PTR_RES/EMPTY/INSN16 */
10659 Elf_Internal_Rela *hi_irel, *ptr_irel, *insn_irel, *em_irel, *call_irel;
10660 Elf_Internal_Rela *irelend;
10661 bfd_signed_vma foff;
10663 irelend = internal_relocs + sec->reloc_count;
10664 laddr = irel->r_offset;
10666 /* Get the reloc for the address from which the register is
10667 being loaded. This reloc will tell us which function is
10668 actually being called. */
10669 hi_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10670 R_NDS32_HI20_RELA, laddr);
10672 if (hi_irel == irelend)
10674 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
10675 (uint64_t) irel->r_offset);
10679 /* Get the value of the symbol referred to by the reloc. */
10680 foff = calculate_offset (abfd, sec, hi_irel, isymbuf, symtab_hdr);
10682 /* This condition only happened when symbol is undefined. */
10684 || foff < -CONSERVATIVE_24BIT_S1
10685 || foff >= CONSERVATIVE_24BIT_S1)
10688 /* Relax to: jal symbol; 25_PCREL. */
10689 /* For simplicity of coding, we are going to modify the section
10690 contents, the section relocs, and the BFD symbol table. We
10691 must tell the rest of the code not to free up this
10692 information. It would be possible to instead create a table
10693 of changes which have to be made, as is done in coff-mips.c;
10694 that would be more work, but would require less memory when
10695 the linker is run. */
10697 ptr_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10698 R_NDS32_PTR_RESOLVED, irel->r_addend);
10699 em_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10700 R_NDS32_EMPTY, irel->r_addend);
10702 if (ptr_irel == irelend || em_irel == irelend)
10704 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
10705 (uint64_t) irel->r_offset);
10708 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10709 insn = bfd_getb32 (contents + irel->r_addend);
10710 if (insn & 0x80000000)
10713 /* Replace the long call with a jal. */
10714 em_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (em_irel->r_info),
10715 R_NDS32_25_PCREL_RELA);
10716 ptr_irel->r_addend = 1;
10718 /* We don't resolve this here but resolve it in relocate_section. */
10720 bfd_putb32 (insn, contents + em_irel->r_offset);
10723 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
10725 /* If there is function cse, HI20 can not remove now. */
10726 call_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10727 R_NDS32_LONGCALL4, laddr);
10728 if (call_irel == irelend)
10732 ELF32_R_INFO (ELF32_R_SYM (hi_irel->r_info), R_NDS32_NONE);
10735 insn_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10736 R_NDS32_INSN16, irel->r_addend);
10737 if (insn_irel != irelend)
10738 insn_irel->r_info =
10739 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
10744 /* Relax LONGCALL5 relocation for nds32_elf_relax_section. */
10747 nds32_elf_relax_longcall5 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10748 Elf_Internal_Rela *internal_relocs, int *insn_len,
10749 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10750 Elf_Internal_Shdr *symtab_hdr)
10752 /* The pattern for LONGCALL5.
10753 bltz rt, .L1 ; LONGCALL5/17_PCREL
10754 jal symbol ; 25_PCREL
10759 Elf_Internal_Rela *cond_irel, *irelend;
10760 bfd_signed_vma foff;
10762 irelend = internal_relocs + sec->reloc_count;
10763 laddr = irel->r_offset;
10764 insn = bfd_getb32 (contents + laddr);
10766 /* Get the reloc for the address from which the register is
10767 being loaded. This reloc will tell us which function is
10768 actually being called. */
10770 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10771 R_NDS32_25_PCREL_RELA, irel->r_addend);
10772 if (cond_irel == irelend)
10774 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL5",
10775 (uint64_t) irel->r_offset);
10779 /* Get the value of the symbol referred to by the reloc. */
10780 foff = calculate_offset (abfd, sec, cond_irel, isymbuf, symtab_hdr);
10783 || foff < -CONSERVATIVE_16BIT_S1
10784 || foff >= CONSERVATIVE_16BIT_S1)
10787 /* Relax to bgezal rt, label ; 17_PCREL
10788 or bltzal rt, label ; 17_PCREL. */
10790 /* Convert to complimentary conditional call. */
10791 insn = CONVERT_CONDITION_CALL (insn);
10793 /* For simplicity of coding, we are going to modify the section
10794 contents, the section relocs, and the BFD symbol table. We
10795 must tell the rest of the code not to free up this
10796 information. It would be possible to instead create a table
10797 of changes which have to be made, as is done in coff-mips.c;
10798 that would be more work, but would require less memory when
10799 the linker is run. */
10801 /* Modify relocation and contents. */
10802 cond_irel->r_info =
10803 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_17_PCREL_RELA);
10805 /* Replace the long call with a bgezal. */
10806 bfd_putb32 (insn, contents + cond_irel->r_offset);
10809 /* Clean unnessary relocations. */
10810 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
10812 cond_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10813 R_NDS32_17_PCREL_RELA, laddr);
10814 cond_irel->r_info =
10815 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_NONE);
10820 /* Relax LONGCALL6 relocation for nds32_elf_relax_section. */
10823 nds32_elf_relax_longcall6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10824 Elf_Internal_Rela *internal_relocs, int *insn_len,
10825 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10826 Elf_Internal_Shdr *symtab_hdr)
10828 /* The pattern for LONGCALL6.
10829 bltz rt, .L1 ; LONGCALL6/17_PCREL
10830 sethi ta, hi20(symbol) ; HI20/PTR
10831 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10832 jral ta ; PTR_RES/EMPTY/INSN16
10837 Elf_Internal_Rela *em_irel, *cond_irel, *irelend;
10838 bfd_signed_vma foff;
10840 irelend = internal_relocs + sec->reloc_count;
10841 laddr = irel->r_offset;
10843 /* Get the reloc for the address from which the register is
10844 being loaded. This reloc will tell us which function is
10845 actually being called. */
10846 em_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10847 R_NDS32_EMPTY, irel->r_addend);
10849 if (em_irel == irelend)
10851 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL6",
10852 (uint64_t) irel->r_offset);
10856 /* Get the value of the symbol referred to by the reloc. */
10857 foff = calculate_offset (abfd, sec, em_irel, isymbuf, symtab_hdr);
10860 || foff < -CONSERVATIVE_24BIT_S1
10861 || foff >= CONSERVATIVE_24BIT_S1)
10864 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10865 insn = bfd_getb32 (contents + irel->r_addend);
10866 if (insn & 0x80000000)
10869 insn = bfd_getb32 (contents + laddr);
10870 if (foff >= -CONSERVATIVE_16BIT_S1 && foff < CONSERVATIVE_16BIT_S1)
10872 /* Relax to bgezal rt, label ; 17_PCREL
10873 or bltzal rt, label ; 17_PCREL. */
10875 /* Convert to complimentary conditional call. */
10877 insn = CONVERT_CONDITION_CALL (insn);
10878 bfd_putb32 (insn, contents + em_irel->r_offset);
10881 ELF32_R_INFO (ELF32_R_SYM (em_irel->r_info), R_NDS32_17_PCREL_RELA);
10883 /* Set resolved relocation. */
10885 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10886 R_NDS32_PTR_RESOLVED, irel->r_addend);
10887 if (cond_irel == irelend)
10889 _bfd_error_handler (unrecognized_reloc_msg, abfd,
10890 "R_NDS32_LONGCALL6", (uint64_t) irel->r_offset);
10893 cond_irel->r_addend = 1;
10895 /* Clear relocations. */
10898 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
10901 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10902 R_NDS32_17_PCREL_RELA, laddr);
10903 if (cond_irel != irelend)
10904 cond_irel->r_info =
10905 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_NONE);
10908 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10909 R_NDS32_INSN16, irel->r_addend);
10910 if (cond_irel != irelend)
10911 cond_irel->r_info =
10912 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_NONE);
10915 else if (foff >= -CONSERVATIVE_24BIT_S1 && foff < CONSERVATIVE_24BIT_S1)
10917 /* Relax to the following instruction sequence
10918 bltz rt, .L1 ; LONGCALL2/17_PCREL
10919 jal symbol ; 25_PCREL/PTR_RES
10922 /* Convert instruction. */
10924 bfd_putb32 (insn, contents + em_irel->r_offset);
10926 /* Convert relocations. */
10927 em_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (em_irel->r_info),
10928 R_NDS32_25_PCREL_RELA);
10930 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_LONGCALL5);
10932 /* Set resolved relocation. */
10934 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10935 R_NDS32_PTR_RESOLVED, irel->r_addend);
10936 if (cond_irel == irelend)
10938 _bfd_error_handler (unrecognized_reloc_msg, abfd,
10939 "R_NDS32_LONGCALL6", (uint64_t) irel->r_offset);
10942 cond_irel->r_addend = 1;
10945 find_relocs_at_address_addr (irel, internal_relocs, irelend,
10946 R_NDS32_INSN16, irel->r_addend);
10947 if (cond_irel != irelend)
10948 cond_irel->r_info =
10949 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_NONE);
10954 /* Relax LONGJUMP4 relocation for nds32_elf_relax_section. */
10957 nds32_elf_relax_longjump4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
10958 Elf_Internal_Rela *internal_relocs, int *insn_len,
10959 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
10960 Elf_Internal_Shdr *symtab_hdr)
10962 /* The pattern for LONGJUMP4.
10963 sethi ta, hi20(symbol) ; LONGJUMP4/HI20
10964 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10965 jr ta ; PTR_RES/INSN16/EMPTY */
10968 int seq_len; /* Original length of instruction sequence. */
10970 Elf_Internal_Rela *hi_irel, *ptr_irel, *em_irel, *call_irel, *irelend;
10971 bfd_signed_vma foff;
10973 irelend = internal_relocs + sec->reloc_count;
10974 seq_len = GET_SEQ_LEN (irel->r_addend);
10975 laddr = irel->r_offset;
10976 *insn_len = seq_len;
10978 /* Get the reloc for the address from which the register is
10979 being loaded. This reloc will tell us which function is
10980 actually being called. */
10982 hi_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
10983 R_NDS32_HI20_RELA, laddr);
10985 if (hi_irel == irelend)
10987 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
10988 (uint64_t) irel->r_offset);
10992 /* Get the value of the symbol referred to by the reloc. */
10993 foff = calculate_offset (abfd, sec, hi_irel, isymbuf, symtab_hdr);
10996 || foff >= CONSERVATIVE_24BIT_S1
10997 || foff < -CONSERVATIVE_24BIT_S1)
11000 /* Convert it to "j label", it may be converted to j8 in the final
11001 pass of relaxation. Therefore, we do not consider this currently. */
11002 ptr_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11003 R_NDS32_PTR_RESOLVED, irel->r_addend);
11004 em_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11005 R_NDS32_EMPTY, irel->r_addend);
11007 if (ptr_irel == irelend || em_irel == irelend)
11009 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
11010 (uint64_t) irel->r_offset);
11015 ELF32_R_INFO (ELF32_R_SYM (em_irel->r_info), R_NDS32_25_PCREL_RELA);
11016 ptr_irel->r_addend = 1;
11018 /* Write instruction. */
11020 bfd_putb32 (insn, contents + em_irel->r_offset);
11022 /* Clear relocations. */
11023 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11025 /* If there is function cse, HI20 can not remove now. */
11026 call_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11027 R_NDS32_LONGJUMP4, laddr);
11028 if (call_irel == irelend)
11032 ELF32_R_INFO (ELF32_R_SYM (hi_irel->r_info), R_NDS32_NONE);
11038 /* Relax LONGJUMP5 relocation for nds32_elf_relax_section. */
11041 nds32_elf_relax_longjump5 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
11042 Elf_Internal_Rela *internal_relocs, int *insn_len,
11043 int *seq_len, bfd_byte *contents,
11044 Elf_Internal_Sym *isymbuf,
11045 Elf_Internal_Shdr *symtab_hdr)
11047 /* There are 2 variations for LONGJUMP5
11048 case 2-4; 1st insn convertible, 16-bit on.
11049 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11050 j label ; 25_PCREL/INSN16
11053 case 4-4; 1st insn not convertible
11054 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11055 j label ; 25_PCREL/INSN16
11059 Elf_Internal_Rela *cond_irel, *irelend;
11061 bfd_signed_vma foff;
11062 uint32_t insn, re_insn = 0;
11063 uint16_t insn16, re_insn16 = 0;
11064 unsigned long reloc;
11066 enum elf_nds32_reloc_type checked_types[] =
11067 { R_NDS32_17_PCREL_RELA, R_NDS32_15_PCREL_RELA,
11068 R_NDS32_9_PCREL_RELA, R_NDS32_INSN16 };
11070 irelend = internal_relocs + sec->reloc_count;
11071 laddr = irel->r_offset;
11073 /* Get the reloc for the address from which the register is
11074 being loaded. This reloc will tell us which function is
11075 actually being called. */
11078 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11079 R_NDS32_25_PCREL_RELA, irel->r_addend);
11080 if (cond_irel == irelend)
11082 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP5",
11083 (uint64_t) irel->r_offset);
11087 /* Get the value of the symbol referred to by the reloc. */
11088 foff = calculate_offset (abfd, sec, cond_irel, isymbuf, symtab_hdr);
11091 || foff < -CONSERVATIVE_16BIT_S1
11092 || foff >= CONSERVATIVE_16BIT_S1)
11095 /* Get the all corresponding instructions. */
11096 insn = bfd_getb32 (contents + laddr);
11097 /* Check instruction size. */
11098 if (insn & 0x80000000)
11101 insn16 = insn >> 16;
11102 nds32_elf_convert_branch (insn16, 0, &re_insn16, &re_insn);
11105 nds32_elf_convert_branch (0, insn, &re_insn16, &re_insn);
11107 if (N32_OP6 (re_insn) == N32_OP6_BR1
11108 && (foff >= -CONSERVATIVE_14BIT_S1 && foff < CONSERVATIVE_14BIT_S1))
11110 /* beqs label ; 15_PCREL. */
11111 bfd_putb32 (re_insn, contents + cond_irel->r_offset);
11112 reloc = R_NDS32_15_PCREL_RELA;
11114 else if (N32_OP6 (re_insn) == N32_OP6_BR2
11115 && foff >= -CONSERVATIVE_16BIT_S1 && foff < CONSERVATIVE_16BIT_S1)
11117 /* beqz label ; 17_PCREL. */
11118 bfd_putb32 (re_insn, contents + cond_irel->r_offset);
11119 reloc = R_NDS32_17_PCREL_RELA;
11121 else if ( N32_OP6 (re_insn) == N32_OP6_BR3
11122 && foff >= -CONSERVATIVE_8BIT_S1 && foff < CONSERVATIVE_8BIT_S1)
11124 /* beqc label ; 9_PCREL. */
11125 bfd_putb32 (re_insn, contents + cond_irel->r_offset);
11126 reloc = R_NDS32_WORD_9_PCREL_RELA;
11131 /* Set all relocations. */
11132 cond_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), reloc);
11134 /* Clean relocations. */
11135 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11136 for (i = 0; i < ARRAY_SIZE (checked_types); i++)
11138 cond_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11139 checked_types[i], laddr);
11140 if (cond_irel != irelend)
11143 && (ELF32_R_TYPE (cond_irel->r_info) == R_NDS32_INSN16))
11145 /* If the branch instruction is 2 byte, it cannot remove
11146 directly. Only convert it to nop16 and remove it after
11147 checking alignment issue. */
11148 insn16 = NDS32_NOP16;
11149 bfd_putb16 (insn16, contents + laddr);
11150 cond_irel->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
11153 cond_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info),
11162 /* Relax LONGJUMP6 relocation for nds32_elf_relax_section. */
11165 nds32_elf_relax_longjump6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
11166 Elf_Internal_Rela *internal_relocs, int *insn_len,
11167 int *seq_len, bfd_byte *contents,
11168 Elf_Internal_Sym *isymbuf,
11169 Elf_Internal_Shdr *symtab_hdr)
11171 /* There are 5 variations for LONGJUMP6
11172 case : 2-4-4-4; 1st insn convertible, 16-bit on.
11173 bnes38 rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11174 sethi ta, hi20(symbol) ; HI20/PTR
11175 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11176 jr ta ; PTR_RES/INSN16/EMPTY
11179 case : 4-4-4-4; 1st insn not convertible, 16-bit on.
11180 bne rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11181 sethi ta, hi20(symbol) ; HI20/PTR
11182 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11183 jr ta ; PTR_RES/INSN16/EMPTY
11186 enum elf_nds32_reloc_type checked_types[] =
11187 { R_NDS32_17_PCREL_RELA, R_NDS32_15_PCREL_RELA,
11188 R_NDS32_9_PCREL_RELA, R_NDS32_INSN16 };
11190 int reloc_off = 0, cond_removed = 0;
11192 Elf_Internal_Rela *cond_irel, *em_irel, *irelend, *insn_irel;
11194 bfd_signed_vma foff;
11195 uint32_t insn, re_insn = 0;
11196 uint16_t insn16, re_insn16 = 0;
11197 unsigned long reloc;
11199 irelend = internal_relocs + sec->reloc_count;
11200 laddr = irel->r_offset;
11202 /* Get the reloc for the address from which the register is
11203 being loaded. This reloc will tell us which function is
11204 actually being called. */
11205 em_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11206 R_NDS32_EMPTY, irel->r_addend);
11208 if (em_irel == irelend)
11210 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP6",
11211 (uint64_t) irel->r_offset);
11215 /* Get the value of the symbol referred to by the reloc. */
11216 foff = calculate_offset (abfd, sec, em_irel, isymbuf, symtab_hdr);
11219 || foff < -CONSERVATIVE_24BIT_S1
11220 || foff >= CONSERVATIVE_24BIT_S1)
11223 insn = bfd_getb32 (contents + laddr);
11224 /* Check instruction size. */
11225 if (insn & 0x80000000)
11228 insn16 = insn >> 16;
11229 nds32_elf_convert_branch (insn16, 0, &re_insn16, &re_insn);
11232 nds32_elf_convert_branch (0, insn, &re_insn16, &re_insn);
11234 /* For simplicity of coding, we are going to modify the section
11235 contents, the section relocs, and the BFD symbol table. We
11236 must tell the rest of the code not to free up this
11237 information. It would be possible to instead create a table
11238 of changes which have to be made, as is done in coff-mips.c;
11239 that would be more work, but would require less memory when
11240 the linker is run. */
11242 if (N32_OP6 (re_insn) == N32_OP6_BR1
11243 && (foff >= -CONSERVATIVE_14BIT_S1 && foff < CONSERVATIVE_14BIT_S1))
11245 /* beqs label ; 15_PCREL. */
11246 bfd_putb32 (re_insn, contents + em_irel->r_offset);
11247 reloc = R_NDS32_15_PCREL_RELA;
11250 else if (N32_OP6 (re_insn) == N32_OP6_BR2
11251 && foff >= -CONSERVATIVE_16BIT_S1 && foff < CONSERVATIVE_16BIT_S1)
11253 /* beqz label ; 17_PCREL. */
11254 bfd_putb32 (re_insn, contents + em_irel->r_offset);
11255 reloc = R_NDS32_17_PCREL_RELA;
11258 else if (foff >= -CONSERVATIVE_24BIT_S1 - reloc_off
11259 && foff < CONSERVATIVE_24BIT_S1 - reloc_off)
11261 /* Relax to one of the following 2 variations
11263 case 2-4; 1st insn convertible, 16-bit on.
11264 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11265 j label ; 25_PCREL/INSN16
11268 case 4-4; 1st insn not convertible
11269 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11270 j label ; 25_PCREL/INSN16
11273 /* Use j label as second instruction. */
11275 reloc = R_NDS32_25_PCREL_RELA;
11276 bfd_putb32 (insn, contents + em_irel->r_offset);
11281 /* Set all relocations. */
11282 em_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (em_irel->r_info), reloc);
11285 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11286 R_NDS32_PTR_RESOLVED, em_irel->r_offset);
11287 cond_irel->r_addend = 1;
11289 /* Use INSN16 of first branch instruction to distinguish if keeping
11290 INSN16 of final instruction or not. */
11291 insn_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11292 R_NDS32_INSN16, irel->r_offset);
11293 if (insn_irel == irelend)
11295 /* Clean the final INSN16. */
11297 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11298 R_NDS32_INSN16, em_irel->r_offset);
11299 insn_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info),
11303 if (cond_removed == 1)
11307 /* Clear relocations. */
11308 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11310 for (i = 0; i < ARRAY_SIZE (checked_types); i++)
11313 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11314 checked_types[i], laddr);
11315 if (cond_irel != irelend)
11318 && (ELF32_R_TYPE (cond_irel->r_info) == R_NDS32_INSN16))
11320 /* If the branch instruction is 2 byte, it cannot remove
11321 directly. Only convert it to nop16 and remove it after
11322 checking alignment issue. */
11323 insn16 = NDS32_NOP16;
11324 bfd_putb16 (insn16, contents + laddr);
11325 cond_irel->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
11328 cond_irel->r_info =
11329 ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info), R_NDS32_NONE);
11335 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
11336 R_NDS32_LONGJUMP5);
11342 /* Relax LONGJUMP7 relocation for nds32_elf_relax_section. */
11345 nds32_elf_relax_longjump7 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
11346 Elf_Internal_Rela *internal_relocs, int *insn_len,
11347 int *seq_len, bfd_byte *contents,
11348 Elf_Internal_Sym *isymbuf,
11349 Elf_Internal_Shdr *symtab_hdr)
11351 /* There are 2 variations for LONGJUMP5
11352 case 2-4; 1st insn convertible, 16-bit on.
11353 movi55 ta, imm11 ; LONGJUMP7/INSN16
11354 beq rt, ta, label ; 15_PCREL
11356 case 4-4; 1st insn not convertible
11357 movi55 ta, imm11 ; LONGJUMP7/INSN16
11358 beq rt, ta, label ; 15_PCREL */
11361 Elf_Internal_Rela *cond_irel, *irelend, *insn_irel;
11362 bfd_signed_vma foff;
11363 uint32_t insn, re_insn = 0;
11367 irelend = internal_relocs + sec->reloc_count;
11368 laddr = irel->r_offset;
11370 /* Get the reloc for the address from which the register is
11371 being loaded. This reloc will tell us which function is
11372 actually being called. */
11375 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11376 R_NDS32_15_PCREL_RELA, irel->r_addend);
11377 if (cond_irel == irelend)
11379 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP7",
11380 (uint64_t) irel->r_offset);
11384 /* Get the value of the symbol referred to by the reloc. */
11385 foff = calculate_offset (abfd, sec, cond_irel, isymbuf, symtab_hdr);
11388 || foff < -CONSERVATIVE_8BIT_S1
11389 || foff >= CONSERVATIVE_8BIT_S1)
11392 /* Get the first instruction for its size. */
11393 insn = bfd_getb32 (contents + laddr);
11394 if (insn & 0x80000000)
11397 /* Get the immediate from movi55. */
11398 imm11 = N16_IMM5S (insn >> 16);
11402 /* Get the immediate from movi. */
11403 imm11 = N32_IMM20S (insn);
11406 /* Get the branch instruction. */
11407 insn = bfd_getb32 (contents + irel->r_addend);
11408 /* Convert instruction to BR3. */
11409 if ((insn >> 14) & 0x1)
11410 re_insn = N32_BR3 (BNEC, N32_RT5 (insn), imm11, 0);
11412 re_insn = N32_BR3 (BEQC, N32_RT5 (insn), imm11, 0);
11414 bfd_putb32 (re_insn, contents + cond_irel->r_offset);
11416 /* Set all relocations. */
11417 cond_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info),
11418 R_NDS32_WORD_9_PCREL_RELA);
11420 /* Clean relocations. */
11421 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11422 insn_irel = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11423 R_NDS32_INSN16, irel->r_offset);
11424 if (insn_irel != irelend)
11428 /* If the first insntruction is 16bit, convert it to nop16. */
11429 insn16 = NDS32_NOP16;
11430 bfd_putb16 (insn16, contents + laddr);
11431 insn_irel->r_addend = R_NDS32_INSN16_CONVERT_FLAG;
11434 cond_irel->r_info = ELF32_R_INFO (ELF32_R_SYM (cond_irel->r_info),
11442 /* We figure out and reassign the best gp value in nds32_elf_final_sda_base
11443 for each relax round. But the gp may changed dramatically and then cause
11444 the truncated to fit errors for the the converted gp instructions.
11445 Therefore, we must reserve the minimum but safe enough size to prevent it. */
11448 nds32_elf_relax_guard (bfd_vma *access_addr, bfd_vma local_sda, asection *sec,
11449 Elf_Internal_Rela *irel, bfd_boolean *again,
11451 struct elf_nds32_link_hash_table *table,
11452 Elf_Internal_Sym *isymbuf, Elf_Internal_Shdr *symtab_hdr)
11456 static bfd_boolean sec_pass = FALSE;
11457 static asection *first_sec = NULL, *sym_sec;
11458 /* Record the number of instructions which may be removed. */
11459 static int count = 0, record_count;
11460 Elf_Internal_Sym *isym;
11461 struct elf_link_hash_entry *h = NULL;
11463 unsigned long r_symndx;
11464 bfd *abfd = sec->owner;
11465 static bfd_vma record_sda = 0;
11466 int sda_offset = 0;
11468 /* Force doing relaxation when hyper-relax is high. */
11469 if (table->hyper_relax == 2)
11472 /* Do not relax the load/store patterns for the first
11478 else if (first_sec == sec)
11480 record_count = count;
11491 /* Generally, _SDA_BASE_ is fixed or smaller. But the large
11492 DATA_SEGMENT_ALIGN size in the linker script may make it
11493 get even bigger. */
11494 if (record_sda == 0)
11495 record_sda = local_sda;
11496 else if (local_sda > record_sda)
11497 sda_offset = local_sda - record_sda;
11499 /* Assume the instruction will be removed in the best case. */
11502 /* We record the offset to gp for each symbol, and then check
11503 if it is changed dramatically after relaxing.
11504 (global symbol): elf32_nds32_hash_entry (h)->offset_to_gp
11505 (local symbol) : elf32_nds32_local_gp_offset (abfd)[r_symndx]. */
11506 r_symndx = ELF32_R_SYM (irel->r_info);
11507 if (r_symndx >= symtab_hdr->sh_info)
11509 /* Global symbols. */
11510 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
11511 h = elf_sym_hashes (abfd)[indx];
11512 sym_sec = h->root.u.def.section;
11513 if (NDS32_GUARD_SEC_P (sym_sec->flags)
11514 || bfd_is_abs_section (sym_sec))
11516 /* Forbid doing relaxation when hyper-relax is low. */
11517 if (table->hyper_relax == 0)
11520 offset_to_gp = *access_addr - local_sda;
11521 if (elf32_nds32_hash_entry (h)->offset_to_gp == 0)
11522 elf32_nds32_hash_entry (h)->offset_to_gp = offset_to_gp;
11523 else if (abs (elf32_nds32_hash_entry (h)->offset_to_gp)
11524 < abs (offset_to_gp) - sda_offset)
11526 /* This may cause the error, so we reserve the
11527 safe enough size for relaxing. */
11528 if (*access_addr >= local_sda)
11529 *access_addr += (record_count * 4);
11531 *access_addr -= (record_count * 4);
11538 /* Local symbols. */
11539 if (!elf32_nds32_allocate_local_sym_info (abfd))
11541 isym = isymbuf + r_symndx;
11543 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
11544 if (NDS32_GUARD_SEC_P (sym_sec->flags))
11546 /* Forbid doing relaxation when hyper-relax is low. */
11547 if (table->hyper_relax == 0)
11550 offset_to_gp = *access_addr - local_sda;
11551 if (elf32_nds32_local_gp_offset (abfd)[r_symndx] == 0)
11552 elf32_nds32_local_gp_offset (abfd)[r_symndx] = offset_to_gp;
11553 else if (abs (elf32_nds32_local_gp_offset (abfd)[r_symndx])
11554 < abs (offset_to_gp) - sda_offset)
11556 /* This may cause the error, so we reserve the
11557 safe enough size for relaxing. */
11558 if (*access_addr >= local_sda)
11559 *access_addr += (record_count * 4);
11561 *access_addr -= (record_count * 4);
11570 #define GET_LOADSTORE_RANGE(addend) (((addend) >> 8) & 0x3f)
11572 /* Relax LOADSTORE relocation for nds32_elf_relax_section. */
11575 nds32_elf_relax_loadstore (struct bfd_link_info *link_info, bfd *abfd,
11576 asection *sec, Elf_Internal_Rela *irel,
11577 Elf_Internal_Rela *internal_relocs, int *insn_len,
11578 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
11579 Elf_Internal_Shdr *symtab_hdr, int load_store_relax,
11580 struct elf_nds32_link_hash_table *table)
11582 int eliminate_sethi = 0, range_type;
11584 bfd_vma local_sda, laddr;
11585 int seq_len; /* Original length of instruction sequence. */
11587 Elf_Internal_Rela *hi_irelfn = NULL, *irelend;
11588 bfd_vma access_addr = 0;
11589 bfd_vma range_l = 0, range_h = 0; /* Upper/lower bound. */
11590 struct elf_link_hash_entry *h = NULL;
11592 enum elf_nds32_reloc_type checked_types[] =
11593 { R_NDS32_HI20_RELA, R_NDS32_GOT_HI20,
11594 R_NDS32_GOTPC_HI20, R_NDS32_GOTOFF_HI20,
11595 R_NDS32_PLTREL_HI20, R_NDS32_PLT_GOTREL_HI20,
11596 R_NDS32_TLS_LE_HI20
11599 irelend = internal_relocs + sec->reloc_count;
11600 seq_len = GET_SEQ_LEN (irel->r_addend);
11601 laddr = irel->r_offset;
11602 *insn_len = seq_len;
11604 /* Get the high part relocation. */
11605 for (i = 0; i < ARRAY_SIZE (checked_types); i++)
11607 hi_irelfn = find_relocs_at_address_addr (irel, internal_relocs, irelend,
11608 checked_types[i], laddr);
11609 if (hi_irelfn != irelend)
11613 if (hi_irelfn == irelend)
11615 /* Not R_NDS32_HI20_RELA. */
11617 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LOADSTORE",
11618 (uint64_t) irel->r_offset);
11622 range_type = GET_LOADSTORE_RANGE (irel->r_addend);
11623 nds32_elf_final_sda_base (sec->output_section->owner,
11624 link_info, &local_sda, FALSE);
11626 switch (ELF32_R_TYPE (hi_irelfn->r_info))
11628 case R_NDS32_HI20_RELA:
11629 insn = bfd_getb32 (contents + laddr);
11631 calculate_memory_address (abfd, hi_irelfn, isymbuf, symtab_hdr);
11633 if (ELF32_R_SYM (hi_irelfn->r_info) >= symtab_hdr->sh_info)
11635 indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
11636 h = elf_sym_hashes (abfd)[indx];
11640 if (range_type == NDS32_LOADSTORE_IMM
11641 && access_addr < CONSERVATIVE_20BIT
11642 && (!h || (h && strcmp (h->root.root.string, FP_BASE_NAME) != 0)))
11644 eliminate_sethi = 1;
11648 if (h && strcmp (h->root.root.string, FP_BASE_NAME) == 0)
11650 eliminate_sethi = 1;
11653 else if (!nds32_elf_relax_guard (&access_addr, local_sda, sec, hi_irelfn,
11654 NULL, FALSE, table, isymbuf, symtab_hdr))
11657 if (!load_store_relax)
11660 /* Case for set gp register. */
11661 if (N32_RT5 (insn) == REG_GP)
11664 if (range_type == NDS32_LOADSTORE_FLOAT_S
11665 || range_type == NDS32_LOADSTORE_FLOAT_D)
11667 range_l = sdata_range[0][0];
11668 range_h = sdata_range[0][1];
11672 range_l = sdata_range[1][0];
11673 range_h = sdata_range[1][1];
11681 /* Delete sethi instruction. */
11682 if (eliminate_sethi == 1
11683 || (local_sda <= access_addr && (access_addr - local_sda) < range_h)
11684 || (local_sda > access_addr && (local_sda - access_addr) <= range_l))
11686 hi_irelfn->r_info =
11687 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_NDS32_NONE);
11689 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11697 /* Relax LO12 relocation for nds32_elf_relax_section. */
11700 nds32_elf_relax_lo12 (struct bfd_link_info *link_info, bfd *abfd,
11701 asection *sec, Elf_Internal_Rela *irel,
11702 Elf_Internal_Rela *internal_relocs, bfd_byte *contents,
11703 Elf_Internal_Sym *isymbuf, Elf_Internal_Shdr *symtab_hdr,
11704 struct elf_nds32_link_hash_table *table)
11707 bfd_vma local_sda, laddr;
11708 unsigned long reloc;
11709 bfd_vma access_addr;
11710 bfd_vma range_l = 0, range_h = 0; /* Upper/lower bound. */
11711 Elf_Internal_Rela *irelfn = NULL, *irelend;
11712 struct elf_link_hash_entry *h = NULL;
11715 /* For SDA base relative relaxation. */
11716 nds32_elf_final_sda_base (sec->output_section->owner, link_info,
11717 &local_sda, FALSE);
11719 irelend = internal_relocs + sec->reloc_count;
11720 laddr = irel->r_offset;
11721 insn = bfd_getb32 (contents + laddr);
11723 if (!is_sda_access_insn (insn) && N32_OP6 (insn) != N32_OP6_ORI)
11726 access_addr = calculate_memory_address (abfd, irel, isymbuf, symtab_hdr);
11728 if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
11730 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
11731 h = elf_sym_hashes (abfd)[indx];
11735 if (N32_OP6 (insn) == N32_OP6_ORI && access_addr < CONSERVATIVE_20BIT
11736 && (!h || (h && strcmp (h->root.root.string, FP_BASE_NAME) != 0)))
11738 reloc = R_NDS32_20_RELA;
11739 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), reloc);
11740 insn = N32_TYPE1 (MOVI, N32_RT5 (insn), 0);
11741 bfd_putb32 (insn, contents + laddr);
11745 if (h && strcmp (h->root.root.string, FP_BASE_NAME) == 0)
11747 /* Fall through. */
11749 else if (!nds32_elf_relax_guard (&access_addr, local_sda, sec, irel, NULL,
11750 FALSE, table, isymbuf, symtab_hdr))
11753 range_l = sdata_range[1][0];
11754 range_h = sdata_range[1][1];
11755 switch (ELF32_R_TYPE (irel->r_info))
11757 case R_NDS32_LO12S0_RELA:
11758 reloc = R_NDS32_SDA19S0_RELA;
11760 case R_NDS32_LO12S1_RELA:
11761 reloc = R_NDS32_SDA18S1_RELA;
11763 case R_NDS32_LO12S2_RELA:
11764 reloc = R_NDS32_SDA17S2_RELA;
11766 case R_NDS32_LO12S2_DP_RELA:
11767 range_l = sdata_range[0][0];
11768 range_h = sdata_range[0][1];
11769 reloc = R_NDS32_SDA12S2_DP_RELA;
11771 case R_NDS32_LO12S2_SP_RELA:
11772 range_l = sdata_range[0][0];
11773 range_h = sdata_range[0][1];
11774 reloc = R_NDS32_SDA12S2_SP_RELA;
11780 /* There are range_h and range_l because linker has to promise
11781 all sections move cross one page together. */
11782 if ((local_sda <= access_addr && (access_addr - local_sda) < range_h)
11783 || (local_sda > access_addr && (local_sda - access_addr) <= range_l)
11784 || (h && strcmp (h->root.root.string, FP_BASE_NAME) == 0))
11786 if (N32_OP6 (insn) == N32_OP6_ORI && N32_RT5 (insn) == REG_GP)
11788 /* Maybe we should add R_NDS32_INSN16 reloc type here
11789 or manually do some optimization. sethi can't be
11790 eliminated when updating $gp so the relative ori
11791 needs to be preserved. */
11794 if (!turn_insn_to_sda_access (insn, ELF32_R_TYPE (irel->r_info),
11797 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), reloc);
11798 bfd_putb32 (insn, contents + laddr);
11800 irelfn = find_relocs_at_address (irel, internal_relocs, irelend,
11802 /* SDA17 must keep INSN16 for converting fp_as_gp. */
11803 if (irelfn != irelend && reloc != R_NDS32_SDA17S2_RELA)
11805 ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_NDS32_NONE);
11812 /* Relax PTR relocation for nds32_elf_relax_section. */
11815 nds32_elf_relax_ptr (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
11816 Elf_Internal_Rela *internal_relocs, int *insn_len,
11817 int *seq_len, bfd_byte *contents)
11819 Elf_Internal_Rela *ptr_irel, *irelend, *count_irel, *re_irel;
11821 irelend = internal_relocs + sec->reloc_count;
11824 find_relocs_at_address_addr (irel, internal_relocs, irelend,
11825 R_NDS32_PTR_RESOLVED, irel->r_addend);
11827 if (re_irel == irelend)
11829 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_PTR",
11830 (uint64_t) irel->r_offset);
11834 if (re_irel->r_addend != 1)
11837 /* Pointed target is relaxed and no longer needs this void *,
11838 change the type to NONE. */
11839 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
11841 /* Find PTR_COUNT to decide remove it or not. If PTR_COUNT does
11842 not exist, it means only count 1 and remove it directly. */
11843 /* TODO: I hope we can obsolate R_NDS32_COUNT in the future. */
11844 count_irel = find_relocs_at_address (irel, internal_relocs, irelend,
11845 R_NDS32_PTR_COUNT);
11846 ptr_irel = find_relocs_at_address (irel, internal_relocs, irelend,
11848 if (count_irel != irelend)
11850 if (--count_irel->r_addend > 0)
11854 if (ptr_irel != irelend)
11857 /* If the PTR_COUNT is already 0, remove current instruction. */
11858 *seq_len = nds32_elf_insn_size (abfd, contents, irel->r_offset);
11863 /* Relax LWC relocation for nds32_elf_relax_section. */
11866 nds32_elf_relax_flsi (struct bfd_link_info *link_info, bfd *abfd,
11867 asection *sec, Elf_Internal_Rela *irel,
11868 Elf_Internal_Rela *internal_relocs,
11869 bfd_byte *contents, Elf_Internal_Sym *isymbuf,
11870 Elf_Internal_Shdr *symtab_hdr, bfd_boolean *again)
11873 sethi ra, hi20(symbol) ; HI20/LOADSTORE
11874 ori ra, ra, lo12(symbol) ; LO12S0/PTR/PTR/.../INSN16
11875 flsi fsa, [ra + offset1] ; LSI/PTR_RESOLVED/INSN16
11876 flsi fsb, [ra + offset2] ; LSI/PTR_RESOLVED/INSN16
11880 bfd_vma local_sda, laddr;
11881 unsigned long reloc;
11882 bfd_vma access_addr, flsi_offset;
11883 bfd_vma range_l = 0, range_h = 0; /* Upper/lower bound. */
11884 Elf_Internal_Rela *irelend, *re_irel;
11885 unsigned int opcode;
11887 irelend = internal_relocs + sec->reloc_count;
11888 laddr = irel->r_offset;
11889 insn = bfd_getb32 (contents + laddr);
11891 if ((insn & 0x80000000) || !is_sda_access_insn (insn))
11894 /* Can not do relaxation for bi format. */
11895 if ((insn & 0x1000))
11898 /* Only deal with flsi, fssi, fldi, fsdi, so far. */
11899 opcode = N32_OP6 (insn);
11900 if ((opcode == N32_OP6_LWC) || (opcode == N32_OP6_SWC))
11901 reloc = R_NDS32_SDA12S2_SP_RELA;
11902 else if ((opcode == N32_OP6_LDC) || (opcode == N32_OP6_SDC))
11903 reloc = R_NDS32_SDA12S2_DP_RELA;
11907 re_irel = find_relocs_at_address (irel, internal_relocs, irelend,
11908 R_NDS32_PTR_RESOLVED);
11909 if (re_irel == irelend)
11911 _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LSI",
11912 (uint64_t) irel->r_offset);
11916 /* For SDA base relative relaxation. */
11917 nds32_elf_final_sda_base (sec->output_section->owner, link_info,
11918 &local_sda, FALSE);
11919 access_addr = calculate_memory_address (abfd, irel, isymbuf, symtab_hdr);
11920 flsi_offset = (insn & 0xfff) << 2;
11921 access_addr += flsi_offset;
11922 range_l = sdata_range[0][0];
11923 range_h = sdata_range[0][1];
11925 if ((local_sda <= access_addr && (access_addr - local_sda) < range_h)
11926 || (local_sda > access_addr && (local_sda - access_addr) <= range_l))
11928 /* Turn flsi instruction into sda access format. */
11929 insn = (insn & 0x7ff07000) | (REG_GP << 15);
11931 /* Add relocation type to flsi. */
11932 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), reloc);
11933 irel->r_addend += flsi_offset;
11934 bfd_putb32 (insn, contents + re_irel->r_offset);
11936 re_irel->r_addend |= 1;
11942 nds32_relax_adjust_label (bfd *abfd, asection *sec,
11943 Elf_Internal_Rela *internal_relocs,
11944 bfd_byte *contents,
11945 nds32_elf_blank_t **relax_blank_list,
11946 int optimize, int opt_size)
11948 /* This code block is used to adjust 4-byte alignment by relax a pair
11949 of instruction a time.
11951 It recognizes three types of relocations.
11952 1. R_NDS32_LABEL - a alignment.
11953 2. R_NDS32_INSN16 - relax a 32-bit instruction to 16-bit.
11954 3. is_16bit_NOP () - remove a 16-bit instruction. */
11956 /* TODO: It seems currently implementation only support 4-byte alignment.
11957 We should handle any-alignment. */
11959 Elf_Internal_Rela *insn_rel = NULL, *label_rel = NULL, *irel;
11960 Elf_Internal_Rela *tmp_rel, *tmp2_rel = NULL;
11961 Elf_Internal_Rela rel_temp;
11962 Elf_Internal_Rela *irelend;
11966 /* Checking for branch relaxation relies on the relocations to
11967 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
11968 nds32_insertion_sort (internal_relocs, sec->reloc_count,
11969 sizeof (Elf_Internal_Rela), compar_reloc);
11971 irelend = internal_relocs + sec->reloc_count;
11973 /* Force R_NDS32_LABEL before R_NDS32_INSN16. */
11974 /* FIXME: Can we generate the right order in assembler?
11975 So we don't have to swapping them here. */
11977 for (label_rel = internal_relocs, insn_rel = internal_relocs;
11978 label_rel < irelend; label_rel++)
11980 if (ELF32_R_TYPE (label_rel->r_info) != R_NDS32_LABEL)
11983 /* Find the first reloc has the same offset with label_rel. */
11984 while (insn_rel < irelend && insn_rel->r_offset < label_rel->r_offset)
11987 for (;insn_rel < irelend && insn_rel->r_offset == label_rel->r_offset;
11989 /* Check if there were R_NDS32_INSN16 and R_NDS32_LABEL at the same
11991 if (ELF32_R_TYPE (insn_rel->r_info) == R_NDS32_INSN16)
11994 if (insn_rel < irelend && insn_rel->r_offset == label_rel->r_offset
11995 && insn_rel < label_rel)
11997 /* Swap the two reloc if the R_NDS32_INSN16 is
11998 before R_NDS32_LABEL. */
11999 memcpy (&rel_temp, insn_rel, sizeof (Elf_Internal_Rela));
12000 memcpy (insn_rel, label_rel, sizeof (Elf_Internal_Rela));
12001 memcpy (label_rel, &rel_temp, sizeof (Elf_Internal_Rela));
12007 /* If there were a sequence of R_NDS32_LABEL end up with .align 2
12008 or higher, remove other R_NDS32_LABEL with lower alignment.
12009 If an R_NDS32_INSN16 in between R_NDS32_LABELs must be converted,
12010 then the R_NDS32_LABEL sequence is broke. */
12011 for (tmp_rel = internal_relocs; tmp_rel < irelend; tmp_rel++)
12013 if (ELF32_R_TYPE (tmp_rel->r_info) == R_NDS32_LABEL)
12015 if (label_rel == NULL)
12017 if (tmp_rel->r_addend < 2)
12018 label_rel = tmp_rel;
12021 else if (tmp_rel->r_addend > 1)
12023 /* Remove all LABEL relocation from label_rel to tmp_rel
12024 including relocations with same offset as tmp_rel. */
12025 for (tmp2_rel = label_rel; tmp2_rel < tmp_rel; tmp2_rel++)
12027 if (tmp2_rel->r_offset == tmp_rel->r_offset)
12030 if (ELF32_R_TYPE (tmp2_rel->r_info) == R_NDS32_LABEL
12031 && tmp2_rel->r_addend < 2)
12033 ELF32_R_INFO (ELF32_R_SYM (tmp2_rel->r_info),
12039 else if (ELF32_R_TYPE (tmp_rel->r_info) == R_NDS32_INSN16 && label_rel)
12041 /* A new INSN16 which can be converted, so clear label_rel. */
12042 if (is_convert_32_to_16 (abfd, sec, tmp_rel, internal_relocs,
12044 || is_16bit_NOP (abfd, sec, tmp_rel))
12051 /* Optimized for speed and nothing has not been relaxed.
12052 It's time to align labels.
12053 We may convert a 16-bit instruction right before a label to
12054 32-bit, in order to align the label if necessary
12055 all reloc entries has been sorted by r_offset. */
12056 for (irel = internal_relocs;
12057 irel < irelend && irel->r_offset < sec->size; irel++)
12059 if (ELF32_R_TYPE (irel->r_info) != R_NDS32_INSN16
12060 && ELF32_R_TYPE (irel->r_info) != R_NDS32_LABEL)
12063 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_INSN16)
12065 /* A new INSN16 found, resize the old one. */
12066 if (is_convert_32_to_16
12067 (abfd, sec, irel, internal_relocs, irelend, &insn16)
12068 || is_16bit_NOP (abfd, sec, irel))
12072 /* Previous INSN16 reloc exists, reduce its
12074 if (is_convert_32_to_16 (abfd, sec, insn_rel, internal_relocs,
12077 nds32_elf_write_16 (abfd, contents, insn_rel,
12078 internal_relocs, irelend, insn16);
12080 if (!insert_nds32_elf_blank_recalc_total
12081 (relax_blank_list, insn_rel->r_offset + 2, 2))
12084 else if (is_16bit_NOP (abfd, sec, insn_rel))
12086 if (!insert_nds32_elf_blank_recalc_total
12087 (relax_blank_list, insn_rel->r_offset, 2))
12091 ELF32_R_INFO (ELF32_R_SYM (insn_rel->r_info), R_NDS32_NONE);
12093 /* Save the new one for later use. */
12097 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
12100 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_LABEL)
12102 /* Search for label. */
12103 int force_relax = 0;
12105 /* Label on 16-bit instruction or optimization
12106 needless, just reset this reloc. */
12107 insn16 = bfd_getb16 (contents + irel->r_offset);
12108 if ((irel->r_addend & 0x1f) < 2 && (!optimize || (insn16 & 0x8000)))
12111 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_NDS32_NONE);
12116 irel->r_offset - get_nds32_elf_blank_total (relax_blank_list,
12117 irel->r_offset, 1);
12121 /* Check if there is case which can not be aligned. */
12122 if (irel->r_addend == 2 && address & 0x2)
12127 /* Try to align this label. */
12129 if ((irel->r_addend & 0x1f) < 2)
12131 /* Check if there is a INSN16 at the same address.
12132 Label_rel always seats before insn_rel after
12135 /* Search for INSN16 at LABEL location. If INSN16 is at
12136 same location and this LABEL alignment is lower than 2,
12137 the INSN16 can be converted to 2-byte. */
12138 for (tmp_rel = irel;
12139 tmp_rel < irelend && tmp_rel->r_offset == irel->r_offset;
12142 if (ELF32_R_TYPE (tmp_rel->r_info) == R_NDS32_INSN16
12143 && (is_convert_32_to_16
12144 (abfd, sec, tmp_rel, internal_relocs,
12146 || is_16bit_NOP (abfd, sec, tmp_rel)))
12154 if (force_relax || irel->r_addend == 1 || address & 0x2)
12156 /* Label not aligned. */
12157 /* Previous reloc exists, reduce its size to 16-bit. */
12158 if (is_convert_32_to_16 (abfd, sec, insn_rel,
12159 internal_relocs, irelend, &insn16))
12161 nds32_elf_write_16 (abfd, contents, insn_rel,
12162 internal_relocs, irelend, insn16);
12164 if (!insert_nds32_elf_blank_recalc_total
12165 (relax_blank_list, insn_rel->r_offset + 2, 2))
12168 else if (is_16bit_NOP (abfd, sec, insn_rel))
12170 if (!insert_nds32_elf_blank_recalc_total
12171 (relax_blank_list, insn_rel->r_offset, 2))
12176 /* INSN16 reloc is used. */
12182 sec->size - get_nds32_elf_blank_total (relax_blank_list, sec->size, 0);
12183 if (insn_rel && (address & 0x2 || opt_size))
12185 if (is_convert_32_to_16 (abfd, sec, insn_rel, internal_relocs,
12188 nds32_elf_write_16 (abfd, contents, insn_rel, internal_relocs,
12190 if (!insert_nds32_elf_blank_recalc_total
12191 (relax_blank_list, insn_rel->r_offset + 2, 2))
12193 insn_rel->r_info = ELF32_R_INFO (ELF32_R_SYM (insn_rel->r_info),
12196 else if (is_16bit_NOP (abfd, sec, insn_rel))
12198 if (!insert_nds32_elf_blank_recalc_total
12199 (relax_blank_list, insn_rel->r_offset, 2))
12201 insn_rel->r_info = ELF32_R_INFO (ELF32_R_SYM (insn_rel->r_info),
12210 nds32_elf_relax_section (bfd *abfd, asection *sec,
12211 struct bfd_link_info *link_info, bfd_boolean *again)
12213 nds32_elf_blank_t *relax_blank_list = NULL;
12214 Elf_Internal_Shdr *symtab_hdr;
12215 Elf_Internal_Rela *internal_relocs;
12216 Elf_Internal_Rela *irel;
12217 Elf_Internal_Rela *irelend;
12218 Elf_Internal_Sym *isymbuf = NULL;
12219 bfd_byte *contents = NULL;
12220 bfd_boolean result = TRUE;
12226 /* Target dependnet option. */
12227 struct elf_nds32_link_hash_table *table;
12228 int load_store_relax;
12230 relax_blank_list = NULL;
12234 /* Nothing to do for
12235 * relocatable link or
12236 * non-relocatable section or
12237 * non-code section or
12239 * no reloc entry. */
12240 if (bfd_link_relocatable (link_info)
12241 || (sec->flags & SEC_RELOC) == 0
12242 || (sec->flags & SEC_EXCLUDE) != 0
12243 || (sec->flags & SEC_CODE) == 0
12245 || sec->reloc_count == 0)
12248 /* 09.12.11 Workaround. */
12249 /* We have to adjust align for R_NDS32_LABEL if needed.
12250 The adjust approach only can fix 2-byte align once. */
12251 if (sec->alignment_power > 2)
12254 /* Do TLS model conversion once at first. */
12255 nds32_elf_unify_tls_model (abfd, sec, contents, link_info);
12257 /* The optimization type to do. */
12259 table = nds32_elf_hash_table (link_info);
12261 /* Save the first section for abs symbol relaxation.
12262 This is used for checking gp relaxation in the
12263 nds32_elf_relax_loadstore and nds32_elf_relax_lo12. */
12264 nds32_elf_relax_guard (NULL, 0, sec, NULL, again, TRUE,
12265 table, NULL, NULL);
12267 /* The begining of general relaxation. */
12269 if (is_SDA_BASE_set == 0)
12272 is_SDA_BASE_set = 1;
12273 nds32_elf_final_sda_base (sec->output_section->owner, link_info,
12275 relax_range_measurement (abfd);
12278 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
12279 /* Relocations MUST be kept in memory, because relaxation adjust them. */
12280 internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
12281 TRUE /* keep_memory */);
12282 if (internal_relocs == NULL)
12285 irelend = internal_relocs + sec->reloc_count;
12286 irel = find_relocs_at_address (internal_relocs, internal_relocs,
12287 irelend, R_NDS32_RELAX_ENTRY);
12289 if (irel == irelend)
12292 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_ENTRY)
12294 if (irel->r_addend & R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG)
12297 if (irel->r_addend & R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG)
12300 if (irel->r_addend & R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG)
12304 load_store_relax = table->load_store_relax;
12306 /* Get symbol table and section content. */
12307 if (!nds32_get_section_contents (abfd, sec, &contents, TRUE)
12308 || !nds32_get_local_syms (abfd, sec, &isymbuf))
12311 /* Do relax loop only when finalize is not done.
12312 Take care of relaxable relocs except INSN16. */
12313 for (irel = internal_relocs; irel < irelend; irel++)
12315 int seq_len; /* Original length of instruction sequence. */
12316 int insn_len = 0; /* Final length of instruction sequence. */
12317 bfd_boolean removed;
12320 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_LABEL
12321 && (irel->r_addend & 0x1f) >= 2)
12324 /* Relocation Types
12325 R_NDS32_LONGCALL1 53
12326 R_NDS32_LONGCALL2 54
12327 R_NDS32_LONGCALL3 55
12328 R_NDS32_LONGJUMP1 56
12329 R_NDS32_LONGJUMP2 57
12330 R_NDS32_LONGJUMP3 58
12331 R_NDS32_LOADSTORE 59 */
12332 if (ELF32_R_TYPE (irel->r_info) >= R_NDS32_LONGCALL1
12333 && ELF32_R_TYPE (irel->r_info) <= R_NDS32_LOADSTORE)
12334 seq_len = GET_SEQ_LEN (irel->r_addend);
12336 /* Relocation Types
12337 R_NDS32_LONGCALL4 107
12338 R_NDS32_LONGCALL5 108
12339 R_NDS32_LONGCALL6 109
12340 R_NDS32_LONGJUMP4 110
12341 R_NDS32_LONGJUMP5 111
12342 R_NDS32_LONGJUMP6 112
12343 R_NDS32_LONGJUMP7 113 */
12344 else if (ELF32_R_TYPE (irel->r_info) >= R_NDS32_LONGCALL4
12345 && ELF32_R_TYPE (irel->r_info) <= R_NDS32_LONGJUMP7)
12348 /* Relocation Types
12349 R_NDS32_LO12S0_RELA 30
12350 R_NDS32_LO12S1_RELA 29
12351 R_NDS32_LO12S2_RELA 28
12352 R_NDS32_LO12S2_SP_RELA 71
12353 R_NDS32_LO12S2_DP_RELA 70
12354 R_NDS32_GOT_LO12 46
12355 R_NDS32_GOTOFF_LO12 50
12356 R_NDS32_PLTREL_LO12 65
12357 R_NDS32_PLT_GOTREL_LO12 67
12358 R_NDS32_17IFC_PCREL_RELA 96
12359 R_NDS32_GOT_SUFF 193
12360 R_NDS32_GOTOFF_SUFF 194
12361 R_NDS32_PLT_GOT_SUFF 195
12362 R_NDS32_MULCALL_SUFF 196
12364 else if ((ELF32_R_TYPE (irel->r_info) <= R_NDS32_LO12S0_RELA
12365 && ELF32_R_TYPE (irel->r_info) >= R_NDS32_LO12S2_RELA)
12366 || ELF32_R_TYPE (irel->r_info) == R_NDS32_LO12S2_SP_RELA
12367 || ELF32_R_TYPE (irel->r_info) == R_NDS32_LO12S2_DP_RELA
12368 || ELF32_R_TYPE (irel->r_info) == R_NDS32_GOT_LO12
12369 || ELF32_R_TYPE (irel->r_info) == R_NDS32_GOTOFF_LO12
12370 || ELF32_R_TYPE (irel->r_info) == R_NDS32_GOTPC_LO12
12371 || ELF32_R_TYPE (irel->r_info) == R_NDS32_PLTREL_LO12
12372 || ELF32_R_TYPE (irel->r_info) == R_NDS32_PLT_GOTREL_LO12
12373 || (ELF32_R_TYPE (irel->r_info) >= R_NDS32_GOT_SUFF
12374 && ELF32_R_TYPE (irel->r_info) <= R_NDS32_PTR)
12375 || ELF32_R_TYPE (irel->r_info) == R_NDS32_17IFC_PCREL_RELA
12376 || ELF32_R_TYPE (irel->r_info) == R_NDS32_TLS_LE_LO12
12377 || ELF32_R_TYPE (irel->r_info) == R_NDS32_TLS_LE_ADD
12378 || ELF32_R_TYPE (irel->r_info) == R_NDS32_TLS_LE_LS
12379 || ELF32_R_TYPE (irel->r_info) == R_NDS32_LSI)
12384 insn_len = seq_len;
12387 switch (ELF32_R_TYPE (irel->r_info))
12389 case R_NDS32_LONGCALL1:
12390 removed = nds32_elf_relax_longcall1 (abfd, sec, irel, internal_relocs,
12391 &insn_len, contents, isymbuf,
12394 case R_NDS32_LONGCALL2:
12395 removed = nds32_elf_relax_longcall2 (abfd, sec, irel, internal_relocs,
12396 &insn_len, contents, isymbuf,
12399 case R_NDS32_LONGCALL3:
12400 removed = nds32_elf_relax_longcall3 (abfd, sec, irel, internal_relocs,
12401 &insn_len, contents, isymbuf,
12404 case R_NDS32_LONGJUMP1:
12405 removed = nds32_elf_relax_longjump1 (abfd, sec, irel, internal_relocs,
12406 &insn_len, contents, isymbuf,
12409 case R_NDS32_LONGJUMP2:
12410 removed = nds32_elf_relax_longjump2 (abfd, sec, irel, internal_relocs,
12411 &insn_len, contents, isymbuf,
12414 case R_NDS32_LONGJUMP3:
12415 removed = nds32_elf_relax_longjump3 (abfd, sec, irel, internal_relocs,
12416 &insn_len, contents, isymbuf,
12419 case R_NDS32_LONGCALL4:
12420 removed = nds32_elf_relax_longcall4 (abfd, sec, irel, internal_relocs,
12421 &insn_len, contents, isymbuf,
12424 case R_NDS32_LONGCALL5:
12425 removed = nds32_elf_relax_longcall5 (abfd, sec, irel, internal_relocs,
12426 &insn_len, contents, isymbuf,
12429 case R_NDS32_LONGCALL6:
12430 removed = nds32_elf_relax_longcall6 (abfd, sec, irel, internal_relocs,
12431 &insn_len, contents, isymbuf,
12434 case R_NDS32_LONGJUMP4:
12435 removed = nds32_elf_relax_longjump4 (abfd, sec, irel, internal_relocs,
12436 &insn_len, contents, isymbuf,
12439 case R_NDS32_LONGJUMP5:
12440 removed = nds32_elf_relax_longjump5 (abfd, sec, irel, internal_relocs,
12441 &insn_len, &seq_len, contents,
12442 isymbuf, symtab_hdr);
12444 case R_NDS32_LONGJUMP6:
12445 removed = nds32_elf_relax_longjump6 (abfd, sec, irel, internal_relocs,
12446 &insn_len, &seq_len, contents,
12447 isymbuf, symtab_hdr);
12449 case R_NDS32_LONGJUMP7:
12450 removed = nds32_elf_relax_longjump7 (abfd, sec, irel, internal_relocs,
12451 &insn_len, &seq_len, contents,
12452 isymbuf, symtab_hdr);
12454 case R_NDS32_LOADSTORE:
12455 removed = nds32_elf_relax_loadstore (link_info, abfd, sec, irel,
12456 internal_relocs, &insn_len,
12457 contents, isymbuf, symtab_hdr,
12458 load_store_relax, table);
12460 case R_NDS32_LO12S0_RELA:
12461 case R_NDS32_LO12S1_RELA:
12462 case R_NDS32_LO12S2_RELA:
12463 case R_NDS32_LO12S2_DP_RELA:
12464 case R_NDS32_LO12S2_SP_RELA:
12465 /* Relax for low part. */
12466 nds32_elf_relax_lo12 (link_info, abfd, sec, irel, internal_relocs,
12467 contents, isymbuf, symtab_hdr, table);
12469 /* It is impossible to delete blank, so just continue. */
12472 removed = nds32_elf_relax_ptr (abfd, sec, irel, internal_relocs,
12473 &insn_len, &seq_len, contents);
12476 nds32_elf_relax_flsi (link_info, abfd, sec, irel, internal_relocs,
12477 contents, isymbuf, symtab_hdr, again);
12479 case R_NDS32_GOT_LO12:
12480 case R_NDS32_GOTOFF_LO12:
12481 case R_NDS32_PLTREL_LO12:
12482 case R_NDS32_PLT_GOTREL_LO12:
12483 case R_NDS32_GOTPC_LO12:
12484 case R_NDS32_TLS_LE_LO12:
12485 case R_NDS32_TLS_LE_ADD:
12486 case R_NDS32_TLS_LE_LS:
12487 case R_NDS32_PLT_GOT_SUFF:
12488 case R_NDS32_GOT_SUFF:
12489 case R_NDS32_GOTOFF_SUFF:
12495 if (removed && seq_len - insn_len > 0)
12497 if (!insert_nds32_elf_blank
12498 (&relax_blank_list, irel->r_offset + insn_len,
12499 seq_len - insn_len))
12505 calc_nds32_blank_total (relax_blank_list);
12507 if (table->relax_fp_as_gp)
12509 if (!nds32_relax_fp_as_gp (link_info, abfd, sec, internal_relocs,
12515 if (!nds32_fag_remove_unused_fpbase (abfd, sec, internal_relocs,
12523 if (!nds32_relax_adjust_label (abfd, sec, internal_relocs, contents,
12524 &relax_blank_list, optimize, opt_size))
12528 /* It doesn't matter optimize_for_space_no_align anymore.
12529 If object file is assembled with flag '-Os',
12530 the we don't adjust jump-destination on 4-byte boundary. */
12532 if (relax_blank_list)
12534 nds32_elf_relax_delete_blanks (abfd, sec, relax_blank_list);
12535 relax_blank_list = NULL;
12540 /* Closing the section, so we don't relax it anymore. */
12541 bfd_vma sec_size_align;
12542 Elf_Internal_Rela *tmp_rel;
12544 /* Pad to alignment boundary. Only handle current section alignment. */
12545 sec_size_align = (sec->size + (~((-1U) << sec->alignment_power)))
12546 & ((-1U) << sec->alignment_power);
12547 if ((sec_size_align - sec->size) & 0x2)
12549 insn16 = NDS32_NOP16;
12550 bfd_putb16 (insn16, contents + sec->size);
12554 while (sec_size_align != sec->size)
12556 insn = NDS32_NOP32;
12557 bfd_putb32 (insn, contents + sec->size);
12561 tmp_rel = find_relocs_at_address (internal_relocs, internal_relocs,
12562 irelend, R_NDS32_RELAX_ENTRY);
12563 if (tmp_rel != irelend)
12564 tmp_rel->r_addend |= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG;
12566 clean_nds32_elf_blank ();
12570 if (internal_relocs != NULL
12571 && elf_section_data (sec)->relocs != internal_relocs)
12572 free (internal_relocs);
12574 if (contents != NULL
12575 && elf_section_data (sec)->this_hdr.contents != contents)
12578 if (isymbuf != NULL && symtab_hdr->contents != (bfd_byte *) isymbuf)
12588 static struct bfd_elf_special_section const nds32_elf_special_sections[] =
12590 {".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE},
12591 {".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE},
12596 nds32_elf_output_arch_syms (bfd *output_bfd ATTRIBUTE_UNUSED,
12597 struct bfd_link_info *info,
12598 void *finfo ATTRIBUTE_UNUSED,
12599 bfd_boolean (*func) (void *, const char *,
12600 Elf_Internal_Sym *,
12602 struct elf_link_hash_entry *)
12605 FILE *sym_ld_script = NULL;
12606 struct elf_nds32_link_hash_table *table;
12608 table = nds32_elf_hash_table (info);
12609 sym_ld_script = table->sym_ld_script;
12611 if (check_start_export_sym)
12612 fprintf (sym_ld_script, "}\n");
12617 static enum elf_reloc_type_class
12618 nds32_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
12619 const asection *rel_sec ATTRIBUTE_UNUSED,
12620 const Elf_Internal_Rela *rela)
12622 switch ((int) ELF32_R_TYPE (rela->r_info))
12624 case R_NDS32_RELATIVE:
12625 return reloc_class_relative;
12626 case R_NDS32_JMP_SLOT:
12627 return reloc_class_plt;
12629 return reloc_class_copy;
12631 return reloc_class_normal;
12635 /* Put target dependent option into info hash table. */
12637 bfd_elf32_nds32_set_target_option (struct bfd_link_info *link_info,
12638 int relax_fp_as_gp,
12639 int eliminate_gc_relocs,
12640 FILE * sym_ld_script,
12642 int tls_desc_trampoline,
12643 int load_store_relax)
12645 struct elf_nds32_link_hash_table *table;
12647 table = nds32_elf_hash_table (link_info);
12651 table->relax_fp_as_gp = relax_fp_as_gp;
12652 table->eliminate_gc_relocs = eliminate_gc_relocs;
12653 table->sym_ld_script = sym_ld_script;
12654 table->hyper_relax = hyper_relax;
12655 table->tls_desc_trampoline = tls_desc_trampoline;
12656 table ->load_store_relax = load_store_relax;
12660 /* These functions and data-structures are used for fp-as-gp
12663 #define FAG_THRESHOLD 3 /* At least 3 gp-access. */
12664 /* lwi37.fp covers 508 bytes, but there may be 32-byte padding between
12665 the read-only section and read-write section. */
12666 #define FAG_WINDOW (508 - 32)
12668 /* An nds32_fag represent a gp-relative access.
12669 We find best fp-base by using a sliding window
12670 to find a base address which can cover most gp-access. */
12673 struct nds32_fag *next; /* NULL-teminated linked list. */
12674 bfd_vma addr; /* The address of this fag. */
12675 Elf_Internal_Rela **relas; /* The relocations associated with this fag.
12676 It is used for applying FP7U2_FLAG. */
12677 int count; /* How many times this address is referred.
12678 There should be exactly `count' relocations
12680 int relas_capcity; /* The buffer size of relas.
12681 We use an array instead of linked-list,
12682 and realloc is used to adjust buffer size. */
12686 nds32_fag_init (struct nds32_fag *head)
12688 memset (head, 0, sizeof (struct nds32_fag));
12692 nds32_fag_verify (struct nds32_fag *head)
12694 struct nds32_fag *iter;
12695 struct nds32_fag *prev;
12701 if (prev && prev->addr >= iter->addr)
12702 puts ("Bug in fp-as-gp insertion.");
12708 /* Insert a fag in ascending order.
12709 If a fag of the same address already exists,
12710 they are chained by relas array. */
12713 nds32_fag_insert (struct nds32_fag *head, bfd_vma addr,
12714 Elf_Internal_Rela * rel)
12716 struct nds32_fag *iter;
12717 struct nds32_fag *new_fag;
12718 const int INIT_RELAS_CAP = 4;
12721 iter->next && iter->next->addr <= addr;
12723 /* Find somewhere to insert. */ ;
12725 /* `iter' will be equal to `head' if the list is empty. */
12726 if (iter != head && iter->addr == addr)
12728 /* The address exists in the list.
12729 Insert `rel' into relocation list, relas. */
12731 /* Check whether relas is big enough. */
12732 if (iter->count >= iter->relas_capcity)
12734 iter->relas_capcity *= 2;
12735 iter->relas = bfd_realloc
12736 (iter->relas, iter->relas_capcity * sizeof (void *));
12738 iter->relas[iter->count++] = rel;
12742 /* This is a new address. Create a fag node for it. */
12743 new_fag = bfd_malloc (sizeof (struct nds32_fag));
12744 memset (new_fag, 0, sizeof (*new_fag));
12745 new_fag->addr = addr;
12746 new_fag->count = 1;
12747 new_fag->next = iter->next;
12748 new_fag->relas_capcity = INIT_RELAS_CAP;
12749 new_fag->relas = (Elf_Internal_Rela **)
12750 bfd_malloc (new_fag->relas_capcity * sizeof (void *));
12751 new_fag->relas[0] = rel;
12752 iter->next = new_fag;
12754 nds32_fag_verify (head);
12758 nds32_fag_free_list (struct nds32_fag *head)
12760 struct nds32_fag *iter;
12765 struct nds32_fag *tmp = iter;
12773 /* Find the best fp-base address.
12774 The relocation associated with that address is returned,
12775 so we can track the symbol instead of a fixed address.
12777 When relaxation, the address of an datum may change,
12778 because a text section is shrinked, so the data section
12779 moves forward. If the aligments of text and data section
12780 are different, their distance may change too.
12781 Therefore, tracking a fixed address is not appriate. */
12784 nds32_fag_find_base (struct nds32_fag *head, struct nds32_fag **bestpp)
12786 struct nds32_fag *base; /* First fag in the window. */
12787 struct nds32_fag *last; /* First fag outside the window. */
12788 int accu = 0; /* Usage accumulation. */
12789 struct nds32_fag *best; /* Best fag. */
12790 int baccu = 0; /* Best accumulation. */
12792 /* Use first fag for initial, and find the last fag in the window.
12794 In each iteration, we could simply subtract previous fag
12795 and accumulate following fags which are inside the window,
12796 untill we each the end. */
12798 if (head->next == NULL)
12804 /* Initialize base. */
12808 last && last->addr < base->addr + FAG_WINDOW;
12810 accu += last->count;
12814 /* Record the best base in each iteration. */
12817 accu -= base->count;
12819 /* Account fags in window. */
12820 for (/* Nothing. */;
12821 last && last->addr < base->addr + FAG_WINDOW;
12823 accu += last->count;
12825 /* A better fp-base? */
12838 /* Apply R_NDS32_INSN16_FP7U2_FLAG on gp-relative accesses,
12839 so we can convert it fo fp-relative access later.
12840 `best_fag' is the best fp-base. Only those inside the window
12841 of best_fag is applied the flag. */
12844 nds32_fag_mark_relax (struct bfd_link_info *link_info,
12845 asection *sec, struct nds32_fag *best_fag,
12846 Elf_Internal_Rela *internal_relocs,
12847 Elf_Internal_Rela *irelend)
12849 struct nds32_fag *ifag;
12850 bfd_vma best_fpbase, gp;
12853 output_bfd = sec->output_section->owner;
12854 nds32_elf_final_sda_base (output_bfd, link_info, &gp, FALSE);
12855 best_fpbase = best_fag->addr;
12857 if (best_fpbase > gp + sdata_range[1][1]
12858 || best_fpbase < gp - sdata_range[1][0])
12861 /* Mark these inside the window R_NDS32_INSN16_FP7U2_FLAG flag,
12862 so we know they can be converted to lwi37.fp. */
12863 for (ifag = best_fag;
12864 ifag && ifag->addr < best_fpbase + FAG_WINDOW; ifag = ifag->next)
12868 for (i = 0; i < ifag->count; i++)
12870 Elf_Internal_Rela *insn16_rel;
12871 Elf_Internal_Rela *fag_rel;
12873 fag_rel = ifag->relas[i];
12875 /* Only if this is within the WINDOWS, FP7U2_FLAG
12878 insn16_rel = find_relocs_at_address
12879 (fag_rel, internal_relocs, irelend, R_NDS32_INSN16);
12881 if (insn16_rel != irelend)
12882 insn16_rel->r_addend = R_NDS32_INSN16_FP7U2_FLAG;
12888 /* Reset INSN16 to clean fp as gp. */
12891 nds32_fag_unmark_relax (struct nds32_fag *fag,
12892 Elf_Internal_Rela *internal_relocs,
12893 Elf_Internal_Rela *irelend)
12895 struct nds32_fag *ifag;
12897 Elf_Internal_Rela *insn16_rel;
12898 Elf_Internal_Rela *fag_rel;
12900 for (ifag = fag; ifag; ifag = ifag->next)
12902 for (i = 0; i < ifag->count; i++)
12904 fag_rel = ifag->relas[i];
12906 /* Restore the INSN16 relocation. */
12907 insn16_rel = find_relocs_at_address
12908 (fag_rel, internal_relocs, irelend, R_NDS32_INSN16);
12910 if (insn16_rel != irelend)
12911 insn16_rel->r_addend &= ~R_NDS32_INSN16_FP7U2_FLAG;
12916 /* This is the main function of fp-as-gp optimization.
12917 It should be called by relax_section. */
12920 nds32_relax_fp_as_gp (struct bfd_link_info *link_info,
12921 bfd *abfd, asection *sec,
12922 Elf_Internal_Rela *internal_relocs,
12923 Elf_Internal_Rela *irelend,
12924 Elf_Internal_Sym *isymbuf)
12926 Elf_Internal_Rela *begin_rel = NULL;
12927 Elf_Internal_Rela *irel;
12928 struct nds32_fag fag_head;
12929 Elf_Internal_Shdr *symtab_hdr;
12930 bfd_byte *contents;
12931 bfd_boolean ifc_inside = FALSE;
12933 /* FIXME: Can we bfd_elf_link_read_relocs for the relocs? */
12935 /* Per-function fp-base selection.
12936 1. Create a list for all the gp-relative access.
12937 2. Base on those gp-relative address,
12938 find a fp-base which can cover most access.
12939 3. Use the fp-base for fp-as-gp relaxation.
12941 NOTE: If fp-as-gp is not worth to do, (e.g., less than 3 times),
12943 1. delete the `la $fp, _FP_BASE_' instruction and
12944 2. not convert lwi.gp to lwi37.fp.
12946 To delete the _FP_BASE_ instruction, we simply apply
12947 R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG flag in the r_addend to disable it.
12949 To suppress the conversion, we simply NOT to apply
12950 R_NDS32_INSN16_FP7U2_FLAG flag. */
12952 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
12954 if (!nds32_get_section_contents (abfd, sec, &contents, TRUE)
12955 || !nds32_get_local_syms (abfd, sec, &isymbuf))
12958 /* Check whether it is worth for fp-as-gp optimization,
12959 i.e., at least 3 gp-load.
12961 Set R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG if we should NOT
12962 apply this optimization. */
12964 for (irel = internal_relocs; irel < irelend; irel++)
12966 /* We recognize R_NDS32_RELAX_REGION_BEGIN/_END for the region.
12967 One we enter the begin of the region, we track all the LW/ST
12968 instructions, so when we leave the region, we try to find
12969 the best fp-base address for those LW/ST instructions. */
12971 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_REGION_BEGIN
12972 && (irel->r_addend & R_NDS32_RELAX_REGION_OMIT_FP_FLAG))
12974 /* Begin of the region. */
12976 /* xgettext:c-format */
12977 _bfd_error_handler (_("%pB: nested OMIT_FP in %pA"), abfd, sec);
12980 nds32_fag_init (&fag_head);
12981 ifc_inside = FALSE;
12983 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_REGION_END
12984 && (irel->r_addend & R_NDS32_RELAX_REGION_OMIT_FP_FLAG))
12987 struct nds32_fag *best_fag, *tmp_fag;
12990 /* End of the region.
12991 Check whether it is worth to do fp-as-gp. */
12993 if (begin_rel == NULL)
12995 /* xgettext:c-format */
12996 _bfd_error_handler (_("%pB: unmatched OMIT_FP in %pA"),
13001 accu = nds32_fag_find_base (&fag_head, &best_fag);
13003 /* Clean FP7U2_FLAG because they may set ever. */
13004 tmp_fag = fag_head.next;
13005 nds32_fag_unmark_relax (tmp_fag, internal_relocs, irelend);
13007 /* Check if it is worth, and FP_BASE is near enough to SDA_BASE. */
13008 if (accu < FAG_THRESHOLD
13009 || !nds32_fag_mark_relax (link_info, sec, best_fag,
13010 internal_relocs, irelend))
13012 /* Not worth to do fp-as-gp. */
13013 begin_rel->r_addend |= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG;
13014 begin_rel->r_addend &= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG;
13015 irel->r_addend |= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG;
13016 irel->r_addend &= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG;
13017 nds32_fag_free_list (&fag_head);
13022 /* R_SYM of R_NDS32_RELAX_REGION_BEGIN is not used by assembler,
13023 so we use it to record the distance to the reloction of best
13025 dist = best_fag->relas[0] - begin_rel;
13026 BFD_ASSERT (dist > 0 && dist < 0xffffff);
13027 /* Use high 16 bits of addend to record the _FP_BASE_ matched
13028 relocation. And get the base value when relocating. */
13029 begin_rel->r_addend &= (0x1 << 16) - 1;
13030 begin_rel->r_addend |= dist << 16;
13032 nds32_fag_free_list (&fag_head);
13036 if (begin_rel == NULL || ifc_inside)
13037 /* Skip if we are not in the region of fp-as-gp. */
13040 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_SDA15S2_RELA
13041 || ELF32_R_TYPE (irel->r_info) == R_NDS32_SDA17S2_RELA)
13046 /* A gp-relative access is found. Insert it to the fag-list. */
13048 /* Rt is necessary an RT3, so it can be converted to lwi37.fp. */
13049 insn = bfd_getb32 (contents + irel->r_offset);
13050 if (!N32_IS_RT3 (insn))
13053 addr = calculate_memory_address (abfd, irel, isymbuf, symtab_hdr);
13054 nds32_fag_insert (&fag_head, addr, irel);
13056 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_SDA_FP7U2_RELA)
13060 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_17IFC_PCREL_RELA
13061 || ELF32_R_TYPE (irel->r_info) == R_NDS32_10IFCU_PCREL_RELA)
13063 /* Suppress fp as gp when encounter ifc. */
13071 /* Remove unused `la $fp, _FD_BASE_' instruction. */
13074 nds32_fag_remove_unused_fpbase (bfd *abfd, asection *sec,
13075 Elf_Internal_Rela *internal_relocs,
13076 Elf_Internal_Rela *irelend)
13078 Elf_Internal_Rela *irel;
13079 Elf_Internal_Shdr *symtab_hdr;
13080 bfd_byte *contents = NULL;
13081 nds32_elf_blank_t *relax_blank_list = NULL;
13082 bfd_boolean result = TRUE;
13083 bfd_boolean unused_region = FALSE;
13086 NOTE: Disable fp-as-gp if we encounter ifcall relocations:
13087 R_NDS32_17IFC_PCREL_RELA
13088 R_NDS32_10IFCU_PCREL_RELA. */
13090 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
13091 nds32_get_section_contents (abfd, sec, &contents, TRUE);
13093 for (irel = internal_relocs; irel < irelend; irel++)
13095 /* To remove unused fp-base, we simply find the REGION_NOT_OMIT_FP
13096 we marked to in previous pass.
13097 DO NOT scan relocations again, since we've alreadly decided it
13098 and set the flag. */
13099 const char *syname;
13103 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_REGION_BEGIN
13104 && (irel->r_addend & R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG))
13105 unused_region = TRUE;
13106 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_RELAX_REGION_END
13107 && (irel->r_addend & R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG))
13108 unused_region = FALSE;
13110 /* We're not in the region. */
13111 if (!unused_region)
13114 /* _FP_BASE_ must be a GLOBAL symbol. */
13115 syndx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
13116 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
13119 /* The symbol name must be _FP_BASE_. */
13120 syname = elf_sym_hashes (abfd)[syndx]->root.root.string;
13121 if (strcmp (syname, FP_BASE_NAME) != 0)
13124 if (ELF32_R_TYPE (irel->r_info) == R_NDS32_SDA19S0_RELA)
13126 /* addi.gp $fp, -256 */
13127 insn = bfd_getb32 (contents + irel->r_offset);
13128 if (insn != INSN_ADDIGP_TO_FP)
13131 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_SDA15S0_RELA)
13133 /* addi $fp, $gp, -256 */
13134 insn = bfd_getb32 (contents + irel->r_offset);
13135 if (insn != INSN_ADDI_GP_TO_FP)
13138 else if (ELF32_R_TYPE (irel->r_info) == R_NDS32_20_RELA)
13140 /* movi $fp, FP_BASE */
13141 insn = bfd_getb32 (contents + irel->r_offset);
13142 if (insn != INSN_MOVI_TO_FP)
13148 /* We got here because a FP_BASE instruction is found. */
13149 if (!insert_nds32_elf_blank_recalc_total
13150 (&relax_blank_list, irel->r_offset, 4))
13155 if (relax_blank_list)
13157 nds32_elf_relax_delete_blanks (abfd, sec, relax_blank_list);
13158 relax_blank_list = NULL;
13167 /* This is a version of bfd_generic_get_relocated_section_contents.
13168 We need this variety because relaxation will modify the dwarf
13169 infomation. When there is undefined symbol reference error mesage,
13170 linker need to dump line number where the symbol be used. However
13171 the address is be relaxed, it can not get the original dwarf contents.
13172 The variety only modify function call for reading in the section. */
13175 nds32_elf_get_relocated_section_contents (bfd *abfd,
13176 struct bfd_link_info *link_info,
13177 struct bfd_link_order *link_order,
13179 bfd_boolean relocatable,
13182 bfd *input_bfd = link_order->u.indirect.section->owner;
13183 asection *input_section = link_order->u.indirect.section;
13185 arelent **reloc_vector;
13188 reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
13189 if (reloc_size < 0)
13192 /* Read in the section. */
13193 if (!nds32_get_section_contents (input_bfd, input_section, &data, FALSE))
13196 if (reloc_size == 0)
13199 reloc_vector = (arelent **) bfd_malloc (reloc_size);
13200 if (reloc_vector == NULL)
13203 reloc_count = bfd_canonicalize_reloc (input_bfd, input_section,
13204 reloc_vector, symbols);
13205 if (reloc_count < 0)
13208 if (reloc_count > 0)
13211 for (parent = reloc_vector; *parent != NULL; parent++)
13213 char *error_message = NULL;
13215 bfd_reloc_status_type r;
13217 symbol = *(*parent)->sym_ptr_ptr;
13218 if (symbol->section && discarded_section (symbol->section))
13221 static reloc_howto_type none_howto
13222 = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
13223 "unused", FALSE, 0, 0, FALSE);
13225 off = (*parent)->address * bfd_octets_per_byte (input_bfd);
13226 _bfd_clear_contents ((*parent)->howto, input_bfd,
13227 input_section, data, off);
13228 (*parent)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
13229 (*parent)->addend = 0;
13230 (*parent)->howto = &none_howto;
13234 r = bfd_perform_relocation (input_bfd, *parent, data,
13236 relocatable ? abfd : NULL,
13241 asection *os = input_section->output_section;
13243 /* A partial link, so keep the relocs. */
13244 os->orelocation[os->reloc_count] = *parent;
13248 if (r != bfd_reloc_ok)
13252 case bfd_reloc_undefined:
13253 (*link_info->callbacks->undefined_symbol)
13254 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
13255 input_bfd, input_section, (*parent)->address, TRUE);
13257 case bfd_reloc_dangerous:
13258 BFD_ASSERT (error_message != NULL);
13259 (*link_info->callbacks->reloc_dangerous)
13260 (link_info, error_message,
13261 input_bfd, input_section, (*parent)->address);
13263 case bfd_reloc_overflow:
13264 (*link_info->callbacks->reloc_overflow)
13266 bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
13267 (*parent)->howto->name, (*parent)->addend,
13268 input_bfd, input_section, (*parent)->address);
13270 case bfd_reloc_outofrange:
13272 This error can result when processing some partially
13273 complete binaries. Do not abort, but issue an error
13274 message instead. */
13275 link_info->callbacks->einfo
13276 /* xgettext:c-format */
13277 (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
13278 abfd, input_section, * parent);
13289 free (reloc_vector);
13293 free (reloc_vector);
13297 /* Check target symbol. */
13300 nds32_elf_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
13302 if (!sym || !sym->name || sym->name[0] != '$')
13307 /* nds32 find maybe function sym. Ignore target special symbol
13308 first, and then go the general function. */
13310 static bfd_size_type
13311 nds32_elf_maybe_function_sym (const asymbol *sym, asection *sec,
13314 if (nds32_elf_is_target_special_symbol (NULL, (asymbol *) sym))
13317 return _bfd_elf_maybe_function_sym (sym, sec, code_off);
13321 /* Do TLS model conversion. */
13323 typedef struct relax_group_list_t
13325 Elf_Internal_Rela *relo;
13326 struct relax_group_list_t *next;
13327 struct relax_group_list_t *next_sibling;
13329 } relax_group_list_t;
13332 list_insert (relax_group_list_t *pHead, Elf_Internal_Rela *pElem);
13335 list_insert_sibling (relax_group_list_t *pNode, Elf_Internal_Rela *pElem);
13338 dump_chain (relax_group_list_t *pHead);
13341 list_insert (relax_group_list_t *pHead, Elf_Internal_Rela *pElem)
13343 relax_group_list_t *pNext = pHead;
13346 while (pNext->next)
13348 if (pNext->next->id > (int) pElem->r_addend)
13351 pNext = pNext->next;
13355 relax_group_list_t *pNew = bfd_malloc (sizeof (relax_group_list_t));
13359 relax_group_list_t *tmp = pNext->next;
13360 pNext->next = pNew;
13362 pNew->id = pElem->r_addend;
13363 pNew->relo = pElem;
13365 pNew->next_sibling = NULL;
13371 list_insert_sibling (relax_group_list_t *pNode, Elf_Internal_Rela *pElem)
13373 relax_group_list_t *pNext = pNode;
13376 while (pNext->next_sibling)
13378 pNext = pNext->next_sibling;
13382 relax_group_list_t *pNew = bfd_malloc (sizeof (relax_group_list_t));
13386 relax_group_list_t *tmp = pNext->next_sibling;
13387 pNext->next_sibling = pNew;
13390 pNew->relo = pElem;
13392 pNew->next_sibling = tmp;
13398 dump_chain (relax_group_list_t *pHead)
13400 relax_group_list_t *pNext = pHead->next;
13403 printf("group %d @ 0x%08x", pNext->id, (unsigned)pNext->relo->r_offset);
13404 relax_group_list_t *pNextSib = pNext->next_sibling;
13407 printf(", %d", (unsigned) ELF32_R_TYPE (pNextSib->relo->r_info));
13408 pNextSib = pNextSib->next_sibling;
13410 pNext = pNext->next;
13415 /* Check R_NDS32_RELAX_GROUP of each section.
13416 There might be multiple sections in one object file. */
13419 elf32_nds32_check_relax_group (bfd *abfd, asection *asec)
13421 elf32_nds32_relax_group_t *relax_group_ptr =
13422 elf32_nds32_relax_group_ptr (abfd);
13424 int min_id = relax_group_ptr->min_id;
13425 int max_id = relax_group_ptr->max_id;
13427 Elf_Internal_Rela *rel;
13428 Elf_Internal_Rela *relend;
13429 Elf_Internal_Rela *relocs;
13430 enum elf_nds32_reloc_type rtype;
13434 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13435 relocs = _bfd_elf_link_read_relocs (abfd, asec, NULL, NULL,
13436 TRUE /* keep_memory */);
13437 if (relocs == NULL)
13440 /* Check R_NDS32_RELAX_GROUP. */
13441 relend = relocs + asec->reloc_count;
13442 for (rel = relocs; rel < relend; rel++)
13445 rtype = ELF32_R_TYPE (rel->r_info);
13446 if (rtype != R_NDS32_RELAX_GROUP)
13449 id = rel->r_addend;
13452 else if (id > max_id)
13458 if ((relocs != NULL) && (elf_section_data (asec)->relocs != relocs))
13461 if ((min_id != relax_group_ptr->min_id)
13462 || (max_id != relax_group_ptr->max_id))
13464 relax_group_ptr->count = max_id - min_id + 1;
13465 BFD_ASSERT(min_id <= relax_group_ptr->min_id);
13466 relax_group_ptr->min_id = min_id;
13467 BFD_ASSERT(max_id >= relax_group_ptr->max_id);
13468 relax_group_ptr->max_id = max_id;
13471 return relax_group_ptr->count;
13474 /* Reorder RELAX_GROUP ID when command line option '-r' is applied. */
13475 struct section_id_list_t *relax_group_section_id_list = NULL;
13477 struct section_id_list_t *
13478 elf32_nds32_lookup_section_id (int id, struct section_id_list_t **lst_ptr)
13480 struct section_id_list_t *result = NULL;
13481 struct section_id_list_t *lst = *lst_ptr;
13485 result = (struct section_id_list_t *) calloc
13486 (1, sizeof (struct section_id_list_t));
13487 BFD_ASSERT (result); /* Feed me. */
13493 struct section_id_list_t *cur = lst;
13494 struct section_id_list_t *prv = NULL;
13495 struct section_id_list_t *sec = NULL;
13508 cur = NULL; /* To insert after prv. */
13509 sec = cur; /* In case prv == NULL. */
13517 /* Insert after prv. */
13518 result = (struct section_id_list_t *) calloc
13519 (1, sizeof (struct section_id_list_t));
13520 BFD_ASSERT (result); /* Feed me. */
13524 result->next = prv->next;
13525 prv->next = result;
13530 result->next = sec;
13539 elf32_nds32_unify_relax_group (bfd *abfd, asection *asec)
13541 static int next_relax_group_bias = 0;
13543 elf32_nds32_relax_group_t *relax_group_ptr =
13544 elf32_nds32_relax_group_ptr (abfd);
13546 bfd_boolean result = TRUE;
13547 Elf_Internal_Rela *rel;
13548 Elf_Internal_Rela *relend;
13549 Elf_Internal_Rela *relocs = NULL;
13550 enum elf_nds32_reloc_type rtype;
13551 struct section_id_list_t *node = NULL;
13556 if (0 == relax_group_ptr->count)
13559 /* Check if this section has been handled. */
13560 node = elf32_nds32_lookup_section_id (asec->id, &relax_group_section_id_list);
13562 break; /* Hit, the section id has handled. */
13564 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13565 relocs = _bfd_elf_link_read_relocs (abfd, asec, NULL, NULL,
13566 TRUE /* keep_memory */);
13567 if (relocs == NULL)
13569 BFD_ASSERT (0); /* feed me */
13573 /* Allocate group id bias for this bfd! */
13574 if (0 == relax_group_ptr->init)
13576 relax_group_ptr->bias = next_relax_group_bias;
13577 next_relax_group_bias += relax_group_ptr->count;
13578 relax_group_ptr->init = 1;
13581 /* Reorder relax group groups. */
13582 relend = relocs + asec->reloc_count;
13583 for (rel = relocs; rel < relend; rel++)
13585 rtype = ELF32_R_TYPE(rel->r_info);
13586 if (rtype != R_NDS32_RELAX_GROUP)
13590 rel->r_addend += relax_group_ptr->bias;
13591 /* Debugging count. */
13597 if (relocs != NULL && elf_section_data (asec)->relocs != relocs)
13604 nds32_elf_unify_tls_model (bfd *inbfd, asection *insec, bfd_byte *incontents,
13605 struct bfd_link_info *lnkinfo)
13607 bfd_boolean result = TRUE;
13608 Elf_Internal_Rela *irel;
13609 Elf_Internal_Rela *irelend;
13610 Elf_Internal_Rela *internal_relocs;
13611 unsigned long r_symndx;
13612 enum elf_nds32_reloc_type r_type;
13614 Elf_Internal_Sym *local_syms = NULL;
13615 bfd_byte *contents = NULL;
13617 relax_group_list_t chain = { .id = -1, .next = NULL, .next_sibling = NULL };
13619 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (inbfd)->symtab_hdr;
13620 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
13621 sym_hashes = elf_sym_hashes (inbfd);
13623 sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
13624 if (!elf_bad_symtab (inbfd))
13625 sym_hashes_end -= symtab_hdr->sh_info;
13627 /* Reorder RELAX_GROUP when command line option '-r' is applied. */
13628 if (bfd_link_relocatable (lnkinfo))
13630 elf32_nds32_unify_relax_group (inbfd, insec);
13634 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13635 internal_relocs = _bfd_elf_link_read_relocs (inbfd, insec, NULL, NULL,
13636 TRUE /* keep_memory */);
13637 if (internal_relocs == NULL)
13640 irelend = internal_relocs + insec->reloc_count;
13641 irel = find_relocs_at_address (internal_relocs, internal_relocs,
13642 irelend, R_NDS32_RELAX_ENTRY);
13643 if (irel == irelend)
13646 /* Chain/remove groups. */
13647 for (irel = internal_relocs; irel < irelend; irel++)
13649 r_symndx = ELF32_R_SYM (irel->r_info);
13650 r_type = ELF32_R_TYPE (irel->r_info);
13651 if (r_type != R_NDS32_RELAX_GROUP)
13655 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_NONE);
13656 /* Chain it now. */
13657 if (!list_insert (&chain, irel))
13661 /* Collect group relocations. */
13662 /* Presume relocations are sorted. */
13663 relax_group_list_t *pNext = chain.next;
13666 for (irel = internal_relocs; irel < irelend; irel++)
13668 if (irel->r_offset == pNext->relo->r_offset)
13670 /* Ignore Non-TLS relocation types. */
13671 r_type = ELF32_R_TYPE (irel->r_info);
13672 if ((R_NDS32_TLS_LE_HI20 > r_type)
13673 || (R_NDS32_RELAX_ENTRY == r_type))
13676 if (!list_insert_sibling (pNext, irel))
13679 else if (irel->r_offset > pNext->relo->r_offset)
13681 pNext = pNext->next;
13685 bfd_vma current_offset = pNext->relo->r_offset;
13686 if (irel->r_offset > current_offset)
13687 irel = internal_relocs; /* restart from head */
13689 --irel; /* Check current irel again. */
13694 /* This shouldn't be reached. */
13698 pNext = pNext->next;
13701 #ifdef DUBUG_VERBOSE
13702 dump_chain(&chain);
13705 /* Get symbol table and section content. */
13707 contents = incontents;
13708 else if (!nds32_get_section_contents (inbfd, insec, &contents, TRUE)
13709 || !nds32_get_local_syms (inbfd, insec, &local_syms))
13712 char *local_got_tls_type = elf32_nds32_local_got_tls_type (inbfd);
13714 /* Convert TLS model each group if necessary. */
13715 pNext = chain.next;
13717 int cur_grp_id = -1;
13720 enum elf_nds32_tls_type tls_type, org_tls_type, eff_tls_type;
13722 tls_type = org_tls_type = eff_tls_type = 0;
13726 relax_group_list_t *pNextSig = pNext->next_sibling;
13729 struct elf_link_hash_entry *h = NULL;
13731 irel = pNextSig->relo;
13732 r_symndx = ELF32_R_SYM(irel->r_info);
13733 r_type = ELF32_R_TYPE(irel->r_info);
13735 if (pNext->id != cur_grp_id)
13737 cur_grp_id = pNext->id;
13738 org_tls_type = get_tls_type (r_type, NULL);
13739 if (r_symndx >= symtab_hdr->sh_info)
13741 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
13742 while (h->root.type == bfd_link_hash_indirect
13743 || h->root.type == bfd_link_hash_warning)
13744 h = (struct elf_link_hash_entry *) h->root.u.i.link;
13745 tls_type = ((struct elf_nds32_link_hash_entry *) h)->tls_type;
13749 tls_type = local_got_tls_type
13750 ? local_got_tls_type[r_symndx]
13754 eff_tls_type = 1 << (fls (tls_type) - 1);
13755 sethi_rt = N32_RT5(bfd_getb32 (contents + irel->r_offset));
13758 if (eff_tls_type != org_tls_type)
13760 switch (org_tls_type)
13762 /* DESC to IEGP/IE/LE. */
13764 switch (eff_tls_type)
13769 case R_NDS32_TLS_DESC_HI20:
13770 irel->r_info = ELF32_R_INFO(r_symndx,
13771 R_NDS32_TLS_IE_HI20);
13773 case R_NDS32_TLS_DESC_LO12:
13774 irel->r_info = ELF32_R_INFO(r_symndx,
13775 R_NDS32_TLS_IE_LO12);
13777 case R_NDS32_TLS_DESC_ADD:
13779 uint32_t insn = bfd_getb32 (contents + irel->r_offset);
13780 add_rt = N32_RT5 (insn);
13781 insn = N32_TYPE2 (LWI, add_rt, sethi_rt, 0);
13782 bfd_putb32 (insn, contents + irel->r_offset);
13784 irel->r_info = ELF32_R_INFO(r_symndx, R_NDS32_NONE);
13787 case R_NDS32_TLS_DESC_FUNC:
13788 bfd_putb32 (INSN_NOP, contents + irel->r_offset);
13789 irel->r_info = ELF32_R_INFO(r_symndx,
13790 R_NDS32_RELAX_REMOVE);
13792 case R_NDS32_TLS_DESC_CALL:
13794 uint32_t insn = N32_ALU1(ADD, REG_R0, add_rt,
13796 bfd_putb32 (insn, contents + irel->r_offset);
13798 irel->r_info = ELF32_R_INFO(r_symndx, R_NDS32_NONE);
13801 case R_NDS32_LOADSTORE:
13803 case R_NDS32_PTR_RESOLVED:
13805 case R_NDS32_LABEL:
13815 case R_NDS32_TLS_DESC_HI20:
13816 irel->r_info = ELF32_R_INFO(r_symndx,
13817 R_NDS32_TLS_IEGP_HI20);
13819 case R_NDS32_TLS_DESC_LO12:
13820 irel->r_info = ELF32_R_INFO(r_symndx,
13821 R_NDS32_TLS_IEGP_LO12);
13823 case R_NDS32_TLS_DESC_ADD:
13825 uint32_t insn = bfd_getb32 (contents + irel->r_offset);
13826 add_rt = N32_RT5 (insn);
13827 insn = N32_MEM(LW, add_rt, sethi_rt, REG_GP, 0);
13828 bfd_putb32 (insn, contents + irel->r_offset);
13830 irel->r_info = ELF32_R_INFO(r_symndx, R_NDS32_NONE);
13833 case R_NDS32_TLS_DESC_FUNC:
13834 bfd_putb32 (INSN_NOP, contents + irel->r_offset);
13835 irel->r_info = ELF32_R_INFO(r_symndx,
13836 R_NDS32_RELAX_REMOVE);
13838 case R_NDS32_TLS_DESC_CALL:
13840 uint32_t insn = N32_ALU1(ADD, REG_R0, add_rt,
13842 bfd_putb32 (insn, contents + irel->r_offset);
13844 irel->r_info = ELF32_R_INFO(r_symndx, R_NDS32_NONE);
13847 case R_NDS32_LOADSTORE:
13849 case R_NDS32_PTR_RESOLVED:
13851 case R_NDS32_LABEL:
13861 case R_NDS32_TLS_DESC_HI20:
13862 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_HI20);
13864 case R_NDS32_TLS_DESC_LO12:
13865 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_LO12);
13867 case R_NDS32_TLS_DESC_ADD:
13869 uint32_t insn = bfd_getb32 (contents + irel->r_offset);
13871 add_rt = N32_RT5 (insn);
13872 insn = N32_ALU1 (ADD, REG_R0, sethi_rt, REG_TP);
13873 bfd_putb32 (insn, contents + irel->r_offset);
13875 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_ADD);
13878 case R_NDS32_TLS_DESC_FUNC:
13879 bfd_putb32 (INSN_NOP, contents + irel->r_offset);
13880 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_RELAX_REMOVE);
13882 case R_NDS32_TLS_DESC_CALL:
13883 bfd_putb32 (INSN_NOP, contents + irel->r_offset);
13884 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_RELAX_REMOVE);
13886 case R_NDS32_LOADSTORE:
13888 case R_NDS32_PTR_RESOLVED:
13890 case R_NDS32_LABEL:
13901 /* IEGP to IE/LE. */
13903 switch (eff_tls_type)
13908 case R_NDS32_TLS_IEGP_HI20:
13909 irel->r_info = ELF32_R_INFO(r_symndx,
13910 R_NDS32_TLS_IE_HI20);
13912 case R_NDS32_TLS_IEGP_LO12:
13913 irel->r_info = ELF32_R_INFO(r_symndx,
13914 R_NDS32_TLS_IE_LO12);
13916 case R_NDS32_PTR_RESOLVED:
13918 uint32_t insn = bfd_getb32 (contents + irel->r_offset);
13920 add_rt = N32_RT5 (insn);
13921 insn = N32_TYPE2 (LWI, add_rt, sethi_rt, 0);
13922 bfd_putb32 (insn, contents + irel->r_offset);
13925 case R_NDS32_TLS_IEGP_LW:
13927 case R_NDS32_LOADSTORE:
13930 case R_NDS32_LABEL:
13940 case R_NDS32_TLS_IEGP_HI20:
13941 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_HI20);
13943 case R_NDS32_TLS_IEGP_LO12:
13944 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_LO12);
13946 case R_NDS32_TLS_IEGP_LW:
13947 bfd_putb32 (INSN_NOP, contents + irel->r_offset);
13948 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_RELAX_REMOVE);
13950 case R_NDS32_LOADSTORE:
13953 case R_NDS32_LABEL:
13954 case R_NDS32_PTR_RESOLVED:
13967 switch (eff_tls_type)
13972 case R_NDS32_TLS_IE_HI20:
13973 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_HI20);
13975 case R_NDS32_TLS_IE_LO12S2:
13977 uint32_t insn = bfd_getb32 (contents + irel->r_offset);
13979 add_rt = N32_RT5 (insn);
13980 insn = N32_TYPE2 (ORI, add_rt, sethi_rt, 0);
13981 bfd_putb32 (insn, contents + irel->r_offset);
13983 irel->r_info = ELF32_R_INFO (r_symndx, R_NDS32_TLS_LE_LO12);
13986 case R_NDS32_LOADSTORE:
13989 case R_NDS32_LABEL:
14004 pNextSig = pNextSig->next_sibling;
14008 pNext = pNext->next;
14012 if (pNext->id != cur_grp_id)
14014 pNext = pNext->next;
14023 if (internal_relocs != NULL
14024 && elf_section_data (insec)->relocs != internal_relocs)
14025 free (internal_relocs);
14027 if (contents != NULL
14028 && elf_section_data (insec)->this_hdr.contents != contents)
14031 if (local_syms != NULL && symtab_hdr->contents != (bfd_byte *) local_syms)
14036 pNext = chain.next;
14037 relax_group_list_t *pDel;
14041 pNext = pNext->next;
14053 /* End TLS model conversion. */
14055 #define ELF_ARCH bfd_arch_nds32
14056 #define ELF_MACHINE_CODE EM_NDS32
14057 #define ELF_MAXPAGESIZE 0x1000
14058 #define ELF_TARGET_ID NDS32_ELF_DATA
14060 #define TARGET_BIG_SYM nds32_elf32_be_vec
14061 #define TARGET_BIG_NAME "elf32-nds32be"
14062 #define TARGET_LITTLE_SYM nds32_elf32_le_vec
14063 #define TARGET_LITTLE_NAME "elf32-nds32le"
14065 #define elf_info_to_howto nds32_info_to_howto
14066 #define elf_info_to_howto_rel nds32_info_to_howto_rel
14068 #define bfd_elf32_bfd_link_hash_table_create nds32_elf_link_hash_table_create
14069 #define bfd_elf32_bfd_merge_private_bfd_data nds32_elf_merge_private_bfd_data
14070 #define bfd_elf32_bfd_print_private_bfd_data nds32_elf_print_private_bfd_data
14071 #define bfd_elf32_bfd_relax_section nds32_elf_relax_section
14072 #define bfd_elf32_bfd_set_private_flags nds32_elf_set_private_flags
14074 #define bfd_elf32_mkobject nds32_elf_mkobject
14075 #define elf_backend_action_discarded nds32_elf_action_discarded
14076 #define elf_backend_add_symbol_hook nds32_elf_add_symbol_hook
14077 #define elf_backend_check_relocs nds32_elf_check_relocs
14078 #define elf_backend_adjust_dynamic_symbol nds32_elf_adjust_dynamic_symbol
14079 #define elf_backend_create_dynamic_sections nds32_elf_create_dynamic_sections
14080 #define elf_backend_finish_dynamic_sections nds32_elf_finish_dynamic_sections
14081 #define elf_backend_finish_dynamic_symbol nds32_elf_finish_dynamic_symbol
14082 #define elf_backend_size_dynamic_sections nds32_elf_size_dynamic_sections
14083 #define elf_backend_relocate_section nds32_elf_relocate_section
14084 #define elf_backend_gc_mark_hook nds32_elf_gc_mark_hook
14085 #define elf_backend_grok_prstatus nds32_elf_grok_prstatus
14086 #define elf_backend_grok_psinfo nds32_elf_grok_psinfo
14087 #define elf_backend_reloc_type_class nds32_elf_reloc_type_class
14088 #define elf_backend_copy_indirect_symbol nds32_elf_copy_indirect_symbol
14089 #define elf_backend_link_output_symbol_hook nds32_elf_output_symbol_hook
14090 #define elf_backend_output_arch_syms nds32_elf_output_arch_syms
14091 #define elf_backend_object_p nds32_elf_object_p
14092 #define elf_backend_final_write_processing nds32_elf_final_write_processing
14093 #define elf_backend_special_sections nds32_elf_special_sections
14094 #define bfd_elf32_bfd_get_relocated_section_contents \
14095 nds32_elf_get_relocated_section_contents
14096 #define bfd_elf32_bfd_is_target_special_symbol nds32_elf_is_target_special_symbol
14097 #define elf_backend_maybe_function_sym nds32_elf_maybe_function_sym
14099 #define elf_backend_can_gc_sections 1
14100 #define elf_backend_can_refcount 1
14101 #define elf_backend_want_got_plt 1
14102 #define elf_backend_plt_readonly 1
14103 #define elf_backend_want_plt_sym 0
14104 #define elf_backend_got_header_size 12
14105 #define elf_backend_may_use_rel_p 1
14106 #define elf_backend_default_use_rela_p 1
14107 #define elf_backend_may_use_rela_p 1
14108 #define elf_backend_dtrel_excludes_plt 0
14110 #include "elf32-target.h"
14112 #undef ELF_MAXPAGESIZE
14113 #define ELF_MAXPAGESIZE 0x2000
14115 #undef TARGET_BIG_SYM
14116 #define TARGET_BIG_SYM nds32_elf32_linux_be_vec
14117 #undef TARGET_BIG_NAME
14118 #define TARGET_BIG_NAME "elf32-nds32be-linux"
14119 #undef TARGET_LITTLE_SYM
14120 #define TARGET_LITTLE_SYM nds32_elf32_linux_le_vec
14121 #undef TARGET_LITTLE_NAME
14122 #define TARGET_LITTLE_NAME "elf32-nds32le-linux"
14124 #define elf32_bed elf32_nds32_lin_bed
14126 #include "elf32-target.h"