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 /* Reserve space for COUNT dynamic relocations in relocation selection
3172 elf32_nds32_allocate_dynrelocs (struct bfd_link_info
*info
, asection
*sreloc
,
3173 bfd_size_type count
)
3175 BFD_ASSERT (elf_hash_table (info
)->dynamic_sections_created
);
3178 sreloc
->size
+= sizeof (Elf32_External_Rela
) * count
;
3181 static reloc_howto_type
*
3182 bfd_elf32_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
3187 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_howto_table
); i
++)
3188 if (nds32_elf_howto_table
[i
].name
!= NULL
3189 && strcasecmp (nds32_elf_howto_table
[i
].name
, r_name
) == 0)
3190 return &nds32_elf_howto_table
[i
];
3192 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_relax_howto_table
); i
++)
3193 if (nds32_elf_relax_howto_table
[i
].name
!= NULL
3194 && strcasecmp (nds32_elf_relax_howto_table
[i
].name
, r_name
) == 0)
3195 return &nds32_elf_relax_howto_table
[i
];
3200 static reloc_howto_type
*
3201 bfd_elf32_bfd_reloc_type_table_lookup (enum elf_nds32_reloc_type code
)
3203 if (code
< R_NDS32_RELAX_ENTRY
)
3205 BFD_ASSERT (code
< ARRAY_SIZE (nds32_elf_howto_table
));
3206 return &nds32_elf_howto_table
[code
];
3210 if ((size_t) (code
- R_NDS32_RELAX_ENTRY
)
3211 >= ARRAY_SIZE (nds32_elf_relax_howto_table
))
3217 BFD_ASSERT ((size_t) (code
- R_NDS32_RELAX_ENTRY
)
3218 < ARRAY_SIZE (nds32_elf_relax_howto_table
));
3219 return &nds32_elf_relax_howto_table
[code
- R_NDS32_RELAX_ENTRY
];
3223 static reloc_howto_type
*
3224 bfd_elf32_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
3225 bfd_reloc_code_real_type code
)
3229 for (i
= 0; i
< ARRAY_SIZE (nds32_reloc_map
); i
++)
3231 if (nds32_reloc_map
[i
].bfd_reloc_val
== code
)
3232 return bfd_elf32_bfd_reloc_type_table_lookup
3233 (nds32_reloc_map
[i
].elf_reloc_val
);
3239 /* Set the howto pointer for an NDS32 ELF reloc. */
3242 nds32_info_to_howto_rel (bfd
*abfd
, arelent
*cache_ptr
,
3243 Elf_Internal_Rela
*dst
)
3245 enum elf_nds32_reloc_type r_type
;
3247 r_type
= ELF32_R_TYPE (dst
->r_info
);
3248 if (r_type
> R_NDS32_GNU_VTENTRY
)
3250 /* xgettext:c-format */
3251 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3253 bfd_set_error (bfd_error_bad_value
);
3257 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) <= R_NDS32_GNU_VTENTRY
);
3258 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
3263 nds32_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
3264 Elf_Internal_Rela
*dst
)
3266 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
3268 if ((r_type
== R_NDS32_NONE
)
3269 || ((r_type
> R_NDS32_GNU_VTENTRY
)
3270 && (r_type
< R_NDS32_max
)))
3272 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
3276 /* xgettext:c-format */
3277 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, r_type
);
3278 bfd_set_error (bfd_error_bad_value
);
3282 /* Support for core dump NOTE sections.
3283 Reference to include/linux/elfcore.h in Linux. */
3286 nds32_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
3291 switch (note
->descsz
)
3294 /* Linux/NDS32 32-bit, ABI1. */
3297 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3300 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3308 /* Linux/NDS32 32-bit. */
3311 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3314 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3325 /* Make a ".reg" section. */
3326 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3327 size
, note
->descpos
+ offset
);
3331 nds32_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3333 switch (note
->descsz
)
3338 /* __kernel_uid_t, __kernel_gid_t are short on NDS32 platform. */
3339 elf_tdata (abfd
)->core
->program
=
3340 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
3341 elf_tdata (abfd
)->core
->command
=
3342 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
3349 /* Note that for some reason, a spurious space is tacked
3350 onto the end of the args in some (at least one anyway)
3351 implementations, so strip it off if it exists. */
3353 char *command
= elf_tdata (abfd
)->core
->command
;
3354 int n
= strlen (command
);
3356 if (0 < n
&& command
[n
- 1] == ' ')
3357 command
[n
- 1] = '\0';
3363 /* Hook called by the linker routine which adds symbols from an object
3364 file. We must handle the special NDS32 section numbers here.
3365 We also keep watching for whether we need to create the sdata special
3369 nds32_elf_add_symbol_hook (bfd
*abfd
,
3370 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3371 Elf_Internal_Sym
*sym
,
3372 const char **namep ATTRIBUTE_UNUSED
,
3373 flagword
*flagsp ATTRIBUTE_UNUSED
,
3374 asection
**secp
, bfd_vma
*valp
)
3376 switch (sym
->st_shndx
)
3379 /* Common symbols less than the GP size are automatically
3380 treated as SHN_MIPS_SCOMMON symbols. */
3381 if (sym
->st_size
> elf_gp_size (abfd
)
3382 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
)
3385 /* st_value is the alignemnt constraint.
3386 That might be its actual size if it is an array or structure. */
3387 switch (sym
->st_value
)
3390 *secp
= bfd_make_section_old_way (abfd
, ".scommon_b");
3393 *secp
= bfd_make_section_old_way (abfd
, ".scommon_h");
3396 *secp
= bfd_make_section_old_way (abfd
, ".scommon_w");
3399 *secp
= bfd_make_section_old_way (abfd
, ".scommon_d");
3405 (*secp
)->flags
|= SEC_IS_COMMON
;
3406 *valp
= sym
->st_size
;
3413 /* This function can figure out the best location for a base register to access
3414 data relative to this base register
3416 sda_d0: size of first DOUBLE WORD data section
3417 sda_w0: size of first WORD data section
3418 sda_h0: size of first HALF WORD data section
3419 sda_b : size of BYTE data section
3420 sda_hi: size of second HALF WORD data section
3421 sda_w1: size of second WORD data section
3422 sda_d1: size of second DOUBLE WORD data section
3424 offset (always positive) from the beginning of sda_d0 if OK
3425 a negative error value if fail
3427 these 7 sections have to be located back to back if exist
3428 a pass in 0 value for non-existing section */
3430 /* Due to the interpretation of simm15 field of load/store depending on
3431 data accessing size, the organization of base register relative data shall
3432 like the following figure
3433 -------------------------------------------
3434 | DOUBLE WORD sized data (range +/- 128K)
3435 -------------------------------------------
3436 | WORD sized data (range +/- 64K)
3437 -------------------------------------------
3438 | HALF WORD sized data (range +/- 32K)
3439 -------------------------------------------
3440 | BYTE sized data (range +/- 16K)
3441 -------------------------------------------
3442 | HALF WORD sized data (range +/- 32K)
3443 -------------------------------------------
3444 | WORD sized data (range +/- 64K)
3445 -------------------------------------------
3446 | DOUBLE WORD sized data (range +/- 128K)
3447 -------------------------------------------
3448 Its base register shall be set to access these data freely. */
3450 /* We have to figure out the SDA_BASE value, so that we can adjust the
3451 symbol value correctly. We look up the symbol _SDA_BASE_ in the output
3452 BFD. If we can't find it, we're stuck. We cache it in the ELF
3453 target data. We don't need to adjust the symbol value for an
3454 external symbol if we are producing relocatable output. */
3456 static asection
*sda_rela_sec
= NULL
;
3458 #define SDA_SECTION_NUM 10
3460 static bfd_reloc_status_type
3461 nds32_elf_final_sda_base (bfd
* output_bfd
,
3462 struct bfd_link_info
* info
,
3464 bfd_boolean add_symbol
)
3467 struct elf_nds32_link_hash_table
*table
;
3468 struct bfd_link_hash_entry
*h
, *h2
;
3469 long unsigned int total
= 0;
3470 asection
*first
= NULL
, *final
= NULL
, *temp
;
3471 bfd_vma sda_base
= 0;
3473 h
= bfd_link_hash_lookup (info
->hash
, "_SDA_BASE_", FALSE
, FALSE
, TRUE
);
3474 if (!h
|| (h
->type
!= bfd_link_hash_defined
3475 && h
->type
!= bfd_link_hash_defweak
))
3477 /* The first section must be 4-byte aligned to promise _SDA_BASE_ being
3478 4 byte-aligned. Therefore, it has to set the first section ".data"
3480 static const char sec_name
[SDA_SECTION_NUM
][10] =
3482 ".data", ".got", ".sdata_d", ".sdata_w", ".sdata_h", ".sdata_b",
3483 ".sbss_b", ".sbss_h", ".sbss_w", ".sbss_d"
3487 if (output_bfd
->sections
== NULL
)
3489 *psb
= elf_gp (output_bfd
);
3490 return bfd_reloc_ok
;
3493 /* Get the first and final section. */
3494 while (i
< ARRAY_SIZE (sec_name
))
3496 temp
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3497 if (temp
&& !first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3499 if (temp
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3502 /* Summarize the sections in order to check if joining .bss. */
3503 if (temp
&& temp
->size
!= 0)
3504 total
+= temp
->size
;
3505 else if (temp
&& temp
->rawsize
!= 0)
3506 total
+= temp
->rawsize
;
3511 /* Check .bss size. */
3512 temp
= bfd_get_section_by_name (output_bfd
, ".bss");
3515 if (temp
->size
!= 0)
3516 total
+= temp
->size
;
3517 else if (temp
->rawsize
!= 0)
3518 total
+= temp
->rawsize
;
3520 if (total
< 0x80000)
3522 if (!first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3524 if ((temp
->size
!= 0 || temp
->rawsize
!= 0))
3531 /* The middle of data region. */
3532 sda_base
= final
->vma
/ 2 + final
->rawsize
/ 2 + first
->vma
/ 2;
3534 /* Find the section sda_base located. */
3536 while (i
< ARRAY_SIZE (sec_name
))
3538 final
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3539 if (final
&& (final
->size
!= 0 || final
->rawsize
!= 0)
3540 && sda_base
>= final
->vma
)
3551 /* If there is not any default data section in output bfd, try to find
3552 the first data section. If no data section be found, just simplily
3553 choose the first output section. */
3554 temp
= output_bfd
->sections
;
3557 if (temp
->flags
& SEC_ALLOC
3558 && (((temp
->flags
& SEC_DATA
)
3559 && ((temp
->flags
& SEC_READONLY
) == 0))
3560 || (temp
->flags
& SEC_LOAD
) == 0)
3561 && (temp
->size
!= 0 || temp
->rawsize
!= 0))
3570 /* There is no data or bss section. */
3571 if (!first
|| (first
->size
== 0 && first
->rawsize
== 0))
3573 first
= output_bfd
->sections
;
3574 while (first
&& first
->size
== 0 && first
->rawsize
== 0)
3575 first
= first
->next
;
3578 /* There is no concrete section. */
3581 *psb
= elf_gp (output_bfd
);
3582 return bfd_reloc_ok
;
3585 if (final
&& (final
->vma
+ final
->rawsize
- first
->vma
) <= 0x4000)
3586 sda_base
= final
->vma
/ 2 + final
->rawsize
/ 2 + first
->vma
/ 2;
3588 sda_base
= first
->vma
+ 0x2000;
3591 sda_base
-= first
->vma
;
3592 sda_base
= sda_base
& (~7);
3594 if (!_bfd_generic_link_add_one_symbol
3595 (info
, output_bfd
, "_SDA_BASE_", BSF_GLOBAL
| BSF_WEAK
, first
,
3596 (bfd_vma
) sda_base
, (const char *) NULL
, FALSE
,
3597 get_elf_backend_data (output_bfd
)->collect
, &h
))
3600 sda_rela_sec
= first
;
3603 /* Set _FP_BASE_ to _SDA_BASE_. */
3604 table
= nds32_elf_hash_table (info
);
3605 relax_fp_as_gp
= table
->relax_fp_as_gp
;
3606 h2
= bfd_link_hash_lookup (info
->hash
, FP_BASE_NAME
, FALSE
, FALSE
, FALSE
);
3607 /* _SDA_BASE_ is difined in linker script. */
3610 first
= h
->u
.def
.section
;
3611 sda_base
= h
->u
.def
.value
;
3614 if (relax_fp_as_gp
&& h2
3615 && (h2
->type
== bfd_link_hash_undefweak
3616 || h2
->type
== bfd_link_hash_undefined
))
3618 /* Define a weak FP_BASE_NAME here to prevent the undefined symbol.
3619 And set FP equal to SDA_BASE to do relaxation for
3620 la $fp, _FP_BASE_. */
3621 if (!_bfd_generic_link_add_one_symbol
3622 (info
, output_bfd
, FP_BASE_NAME
, BSF_GLOBAL
| BSF_WEAK
,
3623 first
, sda_base
, (const char *) NULL
,
3624 FALSE
, get_elf_backend_data (output_bfd
)->collect
, &h2
))
3633 elf_gp (output_bfd
) = (h
->u
.def
.value
3634 + h
->u
.def
.section
->output_section
->vma
3635 + h
->u
.def
.section
->output_offset
);
3639 _bfd_error_handler (_("error: can't find symbol: %s"), "_SDA_BASE_");
3640 return bfd_reloc_dangerous
;
3644 *psb
= h
->u
.def
.value
3645 + h
->u
.def
.section
->output_section
->vma
3646 + h
->u
.def
.section
->output_offset
;
3647 return bfd_reloc_ok
;
3651 /* Return size of a PLT entry. */
3652 #define elf_nds32_sizeof_plt(info) PLT_ENTRY_SIZE
3654 /* Create an entry in an nds32 ELF linker hash table. */
3656 static struct bfd_hash_entry
*
3657 nds32_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3658 struct bfd_hash_table
*table
,
3661 struct elf_nds32_link_hash_entry
*ret
;
3663 ret
= (struct elf_nds32_link_hash_entry
*) entry
;
3665 /* Allocate the structure if it has not already been allocated by a
3668 ret
= (struct elf_nds32_link_hash_entry
*)
3669 bfd_hash_allocate (table
, sizeof (struct elf_nds32_link_hash_entry
));
3672 return (struct bfd_hash_entry
*) ret
;
3674 /* Call the allocation method of the superclass. */
3675 ret
= (struct elf_nds32_link_hash_entry
*)
3676 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
);
3680 struct elf_nds32_link_hash_entry
*eh
;
3682 eh
= (struct elf_nds32_link_hash_entry
*) ret
;
3683 eh
->dyn_relocs
= NULL
;
3684 eh
->tls_type
= GOT_UNKNOWN
;
3685 eh
->offset_to_gp
= 0;
3688 return (struct bfd_hash_entry
*) ret
;
3691 /* Create an nds32 ELF linker hash table. */
3693 static struct bfd_link_hash_table
*
3694 nds32_elf_link_hash_table_create (bfd
*abfd
)
3696 struct elf_nds32_link_hash_table
*ret
;
3698 bfd_size_type amt
= sizeof (struct elf_nds32_link_hash_table
);
3700 ret
= (struct elf_nds32_link_hash_table
*) bfd_zmalloc (amt
);
3705 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3706 nds32_elf_link_hash_newfunc
,
3707 sizeof (struct elf_nds32_link_hash_entry
),
3714 ret
->sdynbss
= NULL
;
3715 ret
->srelbss
= NULL
;
3716 ret
->sym_ld_script
= NULL
;
3718 return &ret
->root
.root
;
3721 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3722 shortcuts to them in our hash table. */
3725 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3727 struct elf_link_hash_table
*ehtab
;
3729 if (!_bfd_elf_create_got_section (dynobj
, info
))
3732 ehtab
= elf_hash_table (info
);
3733 ehtab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3734 ehtab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3735 if (!ehtab
->sgot
|| !ehtab
->sgotplt
)
3738 /* _bfd_elf_create_got_section will create it for us. */
3739 ehtab
->srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3740 if (ehtab
->srelgot
== NULL
3741 || !bfd_set_section_flags (dynobj
, ehtab
->srelgot
,
3742 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3743 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
3745 || !bfd_set_section_alignment (dynobj
, ehtab
->srelgot
, 2))
3751 /* Create dynamic sections when linking against a dynamic object. */
3754 nds32_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3756 struct elf_link_hash_table
*ehtab
;
3757 struct elf_nds32_link_hash_table
*htab
;
3758 flagword flags
, pltflags
;
3759 register asection
*s
;
3760 const struct elf_backend_data
*bed
;
3761 int ptralign
= 2; /* 32-bit */
3762 const char *secname
;
3767 bed
= get_elf_backend_data (abfd
);
3768 ehtab
= elf_hash_table (info
);
3769 htab
= nds32_elf_hash_table (info
);
3771 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3772 .rel[a].bss sections. */
3774 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3775 | SEC_LINKER_CREATED
);
3778 pltflags
|= SEC_CODE
;
3779 if (bed
->plt_not_loaded
)
3780 pltflags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
3781 if (bed
->plt_readonly
)
3782 pltflags
|= SEC_READONLY
;
3784 s
= bfd_make_section (abfd
, ".plt");
3787 || !bfd_set_section_flags (abfd
, s
, pltflags
)
3788 || !bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3791 if (bed
->want_plt_sym
)
3793 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3795 struct bfd_link_hash_entry
*bh
= NULL
;
3796 struct elf_link_hash_entry
*h
;
3798 if (!(_bfd_generic_link_add_one_symbol
3799 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3800 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3801 get_elf_backend_data (abfd
)->collect
, &bh
)))
3804 h
= (struct elf_link_hash_entry
*) bh
;
3806 h
->type
= STT_OBJECT
;
3808 if (bfd_link_pic (info
) && !bfd_elf_link_record_dynamic_symbol (info
, h
))
3812 s
= bfd_make_section (abfd
,
3813 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3816 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3817 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3820 if (ehtab
->sgot
== NULL
&& !create_got_section (abfd
, info
))
3823 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3825 secflags
= bfd_get_section_flags (abfd
, sec
);
3826 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3827 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3829 secname
= bfd_get_section_name (abfd
, sec
);
3830 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3831 strcpy (relname
, ".rela");
3832 strcat (relname
, secname
);
3833 if (bfd_get_section_by_name (abfd
, secname
))
3835 s
= bfd_make_section (abfd
, relname
);
3837 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3838 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3842 if (bed
->want_dynbss
)
3844 /* The .dynbss section is a place to put symbols which are defined
3845 by dynamic objects, are referenced by regular objects, and are
3846 not functions. We must allocate space for them in the process
3847 image and use a R_*_COPY reloc to tell the dynamic linker to
3848 initialize them at run time. The linker script puts the .dynbss
3849 section into the .bss section of the final image. */
3850 s
= bfd_make_section (abfd
, ".dynbss");
3853 || !bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
3855 /* The .rel[a].bss section holds copy relocs. This section is not
3856 normally needed. We need to create it here, though, so that the
3857 linker will map it to an output section. We can't just create it
3858 only if we need it, because we will not know whether we need it
3859 until we have seen all the input files, and the first time the
3860 main linker code calls BFD after examining all the input files
3861 (size_dynamic_sections) the input sections have already been
3862 mapped to the output sections. If the section turns out not to
3863 be needed, we can discard it later. We will never need this
3864 section when generating a shared object, since they do not use
3866 if (!bfd_link_pic (info
))
3868 s
= bfd_make_section (abfd
, (bed
->default_use_rela_p
3869 ? ".rela.bss" : ".rel.bss"));
3872 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3873 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3881 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3883 nds32_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3884 struct elf_link_hash_entry
*dir
,
3885 struct elf_link_hash_entry
*ind
)
3887 struct elf_nds32_link_hash_entry
*edir
, *eind
;
3889 edir
= (struct elf_nds32_link_hash_entry
*) dir
;
3890 eind
= (struct elf_nds32_link_hash_entry
*) ind
;
3892 if (eind
->dyn_relocs
!= NULL
)
3894 if (edir
->dyn_relocs
!= NULL
)
3896 struct elf_dyn_relocs
**pp
;
3897 struct elf_dyn_relocs
*p
;
3899 if (ind
->root
.type
== bfd_link_hash_indirect
)
3902 /* Add reloc counts against the weak sym to the strong sym
3903 list. Merge any entries against the same section. */
3904 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
3906 struct elf_dyn_relocs
*q
;
3908 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3909 if (q
->sec
== p
->sec
)
3911 q
->pc_count
+= p
->pc_count
;
3912 q
->count
+= p
->count
;
3919 *pp
= edir
->dyn_relocs
;
3922 edir
->dyn_relocs
= eind
->dyn_relocs
;
3923 eind
->dyn_relocs
= NULL
;
3926 if (ind
->root
.type
== bfd_link_hash_indirect
)
3928 if (dir
->got
.refcount
<= 0)
3930 edir
->tls_type
= eind
->tls_type
;
3931 eind
->tls_type
= GOT_UNKNOWN
;
3935 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3939 /* Find dynamic relocs for H that apply to read-only sections. */
3942 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
3944 struct elf_dyn_relocs
*p
;
3946 for (p
= elf32_nds32_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3948 asection
*s
= p
->sec
->output_section
;
3950 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3956 /* Adjust a symbol defined by a dynamic object and referenced by a
3957 regular object. The current definition is in some section of the
3958 dynamic object, but we're not including those sections. We have to
3959 change the definition to something the rest of the link can
3963 nds32_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3964 struct elf_link_hash_entry
*h
)
3966 struct elf_nds32_link_hash_table
*htab
;
3969 unsigned int power_of_two
;
3971 dynobj
= elf_hash_table (info
)->dynobj
;
3973 /* Make sure we know what is going on here. */
3974 BFD_ASSERT (dynobj
!= NULL
3977 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
3980 /* If this is a function, put it in the procedure linkage table. We
3981 will fill in the contents of the procedure linkage table later,
3982 when we know the address of the .got section. */
3983 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
3985 if (!bfd_link_pic (info
)
3988 && h
->root
.type
!= bfd_link_hash_undefweak
3989 && h
->root
.type
!= bfd_link_hash_undefined
)
3991 /* This case can occur if we saw a PLT reloc in an input
3992 file, but the symbol was never referred to by a dynamic
3993 object. In such a case, we don't actually need to build
3994 a procedure linkage table, and we can just do a PCREL
3996 h
->plt
.offset
= (bfd_vma
) - 1;
4003 h
->plt
.offset
= (bfd_vma
) - 1;
4005 /* If this is a weak symbol, and there is a real definition, the
4006 processor independent code will have arranged for us to see the
4007 real definition first, and we can just use the same value. */
4008 if (h
->is_weakalias
)
4010 struct elf_link_hash_entry
*def
= weakdef (h
);
4011 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
4012 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
4013 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
4017 /* This is a reference to a symbol defined by a dynamic object which
4018 is not a function. */
4020 /* If we are creating a shared library, we must presume that the
4021 only references to the symbol are via the global offset table.
4022 For such cases we need not do anything here; the relocations will
4023 be handled correctly by relocate_section. */
4024 if (bfd_link_pic (info
))
4027 /* If there are no references to this symbol that do not use the
4028 GOT, we don't need to generate a copy reloc. */
4029 if (!h
->non_got_ref
)
4032 /* If -z nocopyreloc was given, we won't generate them either. */
4033 if (0 && info
->nocopyreloc
)
4039 /* If we don't find any dynamic relocs in read-only sections, then
4040 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4041 if (!readonly_dynrelocs (h
))
4047 /* We must allocate the symbol in our .dynbss section, which will
4048 become part of the .bss section of the executable. There will be
4049 an entry for this symbol in the .dynsym section. The dynamic
4050 object will contain position independent code, so all references
4051 from the dynamic object to this symbol will go through the global
4052 offset table. The dynamic linker will use the .dynsym entry to
4053 determine the address it must put in the global offset table, so
4054 both the dynamic object and the regular object will refer to the
4055 same memory location for the variable. */
4057 htab
= nds32_elf_hash_table (info
);
4059 BFD_ASSERT (s
!= NULL
);
4061 /* We must generate a R_NDS32_COPY reloc to tell the dynamic linker
4062 to copy the initial value out of the dynamic object and into the
4063 runtime process image. We need to remember the offset into the
4064 .rela.bss section we are going to use. */
4065 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4069 srel
= htab
->srelbss
;
4070 BFD_ASSERT (srel
!= NULL
);
4071 srel
->size
+= sizeof (Elf32_External_Rela
);
4075 /* We need to figure out the alignment required for this symbol. I
4076 have no idea how ELF linkers handle this. */
4077 power_of_two
= bfd_log2 (h
->size
);
4078 if (power_of_two
> 3)
4081 /* Apply the required alignment. */
4082 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
4083 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
4085 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
4089 /* Define the symbol as being at this point in the section. */
4090 h
->root
.u
.def
.section
= s
;
4091 h
->root
.u
.def
.value
= s
->size
;
4093 /* Increment the section size to make room for the symbol. */
4099 /* Allocate space in .plt, .got and associated reloc sections for
4103 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4105 struct bfd_link_info
*info
;
4106 struct elf_link_hash_table
*ehtab
;
4107 struct elf_nds32_link_hash_table
*htab
;
4108 struct elf_nds32_link_hash_entry
*eh
;
4109 struct elf_dyn_relocs
*p
;
4111 if (h
->root
.type
== bfd_link_hash_indirect
)
4114 /* When warning symbols are created, they **replace** the "real"
4115 entry in the hash table, thus we never get to see the real
4116 symbol in a hash traversal. So look at it now. */
4117 if (h
->root
.type
== bfd_link_hash_warning
)
4118 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4120 eh
= (struct elf_nds32_link_hash_entry
*) h
;
4122 info
= (struct bfd_link_info
*) inf
;
4123 ehtab
= elf_hash_table (info
);
4124 htab
= nds32_elf_hash_table (info
);
4128 eh
= (struct elf_nds32_link_hash_entry
*) h
;
4130 if ((htab
->root
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
4131 && h
->plt
.refcount
> 0
4132 && !(bfd_link_pie (info
) && h
->def_regular
))
4134 /* Make sure this symbol is output as a dynamic symbol.
4135 Undefined weak syms won't yet be marked as dynamic. */
4136 if (h
->dynindx
== -1 && !h
->forced_local
)
4138 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
4142 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
4144 asection
*s
= ehtab
->splt
;
4146 /* If this is the first .plt entry, make room for the special
4149 s
->size
+= PLT_ENTRY_SIZE
;
4151 h
->plt
.offset
= s
->size
;
4153 /* If this symbol is not defined in a regular file, and we are
4154 not generating a shared library, then set the symbol to this
4155 location in the .plt. This is required to make function
4156 pointers compare as equal between the normal executable and
4157 the shared library. */
4158 if (!bfd_link_pic (info
) && !h
->def_regular
)
4160 h
->root
.u
.def
.section
= s
;
4161 h
->root
.u
.def
.value
= h
->plt
.offset
;
4164 /* Make room for this entry. */
4165 s
->size
+= PLT_ENTRY_SIZE
;
4167 /* We also need to make an entry in the .got.plt section, which
4168 will be placed in the .got section by the linker script. */
4169 ehtab
->sgotplt
->size
+= 4;
4171 /* We also need to make an entry in the .rel.plt section. */
4172 ehtab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
4173 if (htab
->tls_desc_trampoline
)
4174 htab
->next_tls_desc_index
++;
4178 h
->plt
.offset
= (bfd_vma
) - 1;
4184 h
->plt
.offset
= (bfd_vma
) - 1;
4188 if (h
->got
.refcount
> 0)
4192 int tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
4194 /* Make sure this symbol is output as a dynamic symbol.
4195 Undefined weak syms won't yet be marked as dynamic. */
4196 if (h
->dynindx
== -1 && !h
->forced_local
)
4198 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
4202 sgot
= elf_hash_table (info
)->sgot
;
4203 h
->got
.offset
= sgot
->size
;
4205 if (tls_type
== GOT_UNKNOWN
)
4208 /* Non-TLS symbols, and TLS_IE need one GOT slot. */
4209 if (tls_type
& (GOT_NORMAL
| GOT_TLS_IE
| GOT_TLS_IEGP
))
4213 /* TLS_DESC, TLS_GD, and TLS_LD need 2 consecutive GOT slots. */
4214 if (tls_type
& GOT_TLS_DESC
)
4218 dyn
= htab
->root
.dynamic_sections_created
;
4220 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
))
4222 if (tls_type
== GOT_TLS_DESC
&& htab
->tls_desc_trampoline
)
4224 /* TLS_DESC with trampoline needs a relocation slot
4225 within .rela.plt. */
4226 htab
->num_tls_desc
++;
4227 ehtab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
4228 htab
->tls_trampoline
= -1;
4232 /* other relocations, including TLS_DESC without trampoline, need
4233 a relocation slot within .rela.got. */
4234 ehtab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
4239 h
->got
.offset
= (bfd_vma
)-1;
4241 if (eh
->dyn_relocs
== NULL
)
4244 /* In the shared -Bsymbolic case, discard space allocated for
4245 dynamic pc-relative relocs against symbols which turn out to be
4246 defined in regular objects. For the normal shared case, discard
4247 space for pc-relative relocs that have become local due to symbol
4248 visibility changes. */
4250 if (bfd_link_pic (info
))
4252 if (h
->def_regular
&& (h
->forced_local
|| info
->symbolic
))
4254 struct elf_dyn_relocs
**pp
;
4256 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
4258 p
->count
-= p
->pc_count
;
4269 /* For the non-shared case, discard space for relocs against
4270 symbols which turn out to need copy relocs or are not dynamic. */
4275 || (htab
->root
.dynamic_sections_created
4276 && (h
->root
.type
== bfd_link_hash_undefweak
4277 || h
->root
.type
== bfd_link_hash_undefined
))))
4279 /* Make sure this symbol is output as a dynamic symbol.
4280 Undefined weak syms won't yet be marked as dynamic. */
4281 if (h
->dynindx
== -1 && !h
->forced_local
)
4283 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
4287 /* If that succeeded, we know we'll be keeping all the
4289 if (h
->dynindx
!= -1)
4293 eh
->dyn_relocs
= NULL
;
4298 /* Finally, allocate space. */
4299 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4301 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4302 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
4308 /* Add relocation REL to the end of relocation section SRELOC. */
4311 elf32_nds32_add_dynreloc (bfd
*output_bfd
,
4312 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4313 asection
*sreloc
, Elf_Internal_Rela
*rel
)
4319 loc
= sreloc
->contents
;
4320 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4321 if (sreloc
->reloc_count
* sizeof (Elf32_External_Rela
) > sreloc
->size
)
4324 bfd_elf32_swap_reloca_out (output_bfd
, rel
, loc
);
4327 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
4328 read-only sections. */
4331 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
4335 if (h
->root
.type
== bfd_link_hash_indirect
)
4338 sec
= readonly_dynrelocs (h
);
4341 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
4343 info
->flags
|= DF_TEXTREL
;
4344 info
->callbacks
->minfo
4345 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
4346 sec
->owner
, h
->root
.root
.string
, sec
);
4348 /* Not an error, just cut short the traversal. */
4354 /* Set the sizes of the dynamic sections. */
4357 nds32_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4358 struct bfd_link_info
*info
)
4360 struct elf_nds32_link_hash_table
*htab
;
4367 htab
= nds32_elf_hash_table (info
);
4371 dynobj
= elf_hash_table (info
)->dynobj
;
4372 BFD_ASSERT (dynobj
!= NULL
);
4374 if (elf_hash_table (info
)->dynamic_sections_created
)
4376 /* Set the contents of the .interp section to the interpreter. */
4377 if (bfd_link_executable (info
) && !info
->nointerp
)
4379 s
= bfd_get_section_by_name (dynobj
, ".interp");
4380 BFD_ASSERT (s
!= NULL
);
4381 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4382 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4386 /* Set up .got offsets for local syms, and space for local dynamic
4388 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
4390 bfd_signed_vma
*local_got
;
4391 bfd_signed_vma
*end_local_got
;
4392 bfd_size_type locsymcount
;
4393 Elf_Internal_Shdr
*symtab_hdr
;
4395 char *local_tls_type
;
4396 unsigned long symndx
;
4397 bfd_vma
*local_tlsdesc_gotent
;
4399 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4402 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4404 struct elf_dyn_relocs
*p
;
4406 for (p
= ((struct elf_dyn_relocs
*)
4407 elf_section_data (s
)->local_dynrel
);
4408 p
!= NULL
; p
= p
->next
)
4410 if (!bfd_is_abs_section (p
->sec
)
4411 && bfd_is_abs_section (p
->sec
->output_section
))
4413 /* Input section has been discarded, either because
4414 it is a copy of a linkonce section or due to
4415 linker script /DISCARD/, so we'll be discarding
4418 else if (p
->count
!= 0)
4420 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4421 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
4422 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4423 info
->flags
|= DF_TEXTREL
;
4428 local_got
= elf_local_got_refcounts (ibfd
);
4432 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4433 locsymcount
= symtab_hdr
->sh_info
;
4434 end_local_got
= local_got
+ locsymcount
;
4435 sgot
= elf_hash_table (info
)->sgot
;
4436 local_tls_type
= elf32_nds32_local_got_tls_type (ibfd
);
4437 local_tlsdesc_gotent
= elf32_nds32_local_tlsdesc_gotent (ibfd
);
4438 for (symndx
= 0; local_got
< end_local_got
;
4439 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
, ++symndx
)
4443 int num_of_got_entry_needed
= 0;
4444 *local_got
= sgot
->size
;
4445 *local_tlsdesc_gotent
= sgot
->size
;
4447 /* TLS_NORMAL, and TLS_IE need one slot in .got. */
4448 if (*local_tls_type
& (GOT_NORMAL
| GOT_TLS_IE
| GOT_TLS_IEGP
))
4449 num_of_got_entry_needed
= 1;
4450 /* TLS_GD, TLS_LD, and TLS_DESC need an 8-byte structure in the GOT. */
4451 else if (*local_tls_type
& GOT_TLS_DESC
)
4452 num_of_got_entry_needed
= 2;
4454 sgot
->size
+= (num_of_got_entry_needed
<< 2);
4456 /* non-relax-able TLS_DESCs need a slot in .rela.plt.
4457 others need a slot in .rela.got. */
4458 if (*local_tls_type
== GOT_TLS_DESC
)
4460 if (bfd_link_pic (info
))
4462 if (htab
->tls_desc_trampoline
)
4464 htab
->num_tls_desc
++;
4465 htab
->root
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
4466 htab
->tls_trampoline
= -1;
4469 htab
->root
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
4473 /* TLS_DESC -> TLS_LE */
4478 htab
->root
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
4483 *local_got
= (bfd_vma
) -1;
4484 *local_tlsdesc_gotent
= (bfd_vma
) -1;
4489 /* Allocate global sym .plt and .got entries, and space for global
4490 sym dynamic relocs. */
4491 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (void *) info
);
4493 /* For every jump slot reserved in the sgotplt, reloc_count is
4494 incremented. However, when we reserve space for TLS descriptors,
4495 it's not incremented, so in order to compute the space reserved
4496 for them, it suffices to multiply the reloc count by the jump
4498 if (htab
->tls_desc_trampoline
&& htab
->root
.srelplt
)
4499 htab
->sgotplt_jump_table_size
= elf32_nds32_compute_jump_table_size (htab
);
4501 if (htab
->tls_trampoline
)
4503 htab
->tls_trampoline
= htab
->root
.splt
->size
;
4505 /* If we're not using lazy TLS relocations, don't generate the
4506 PLT and GOT entries they require. */
4507 if (!(info
->flags
& DF_BIND_NOW
))
4509 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
4510 htab
->root
.sgot
->size
+= 4;
4512 htab
->dt_tlsdesc_plt
= htab
->root
.splt
->size
;
4513 htab
->root
.splt
->size
+= 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
);
4517 /* We now have determined the sizes of the various dynamic sections.
4518 Allocate memory for them. */
4519 /* The check_relocs and adjust_dynamic_symbol entry points have
4520 determined the sizes of the various dynamic sections. Allocate
4524 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4526 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4529 if (s
== htab
->root
.splt
)
4531 /* Strip this section if we don't need it; see the
4535 else if (s
== elf_hash_table (info
)->sgot
)
4537 got_size
+= s
->size
;
4539 else if (s
== elf_hash_table (info
)->sgotplt
)
4541 got_size
+= s
->size
;
4543 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4545 if (s
->size
!= 0 && s
!= elf_hash_table (info
)->srelplt
)
4548 /* We use the reloc_count field as a counter if we need
4549 to copy relocs into the output file. */
4554 /* It's not one of our sections, so don't allocate space. */
4560 /* If we don't need this section, strip it from the
4561 output file. This is mostly to handle .rela.bss and
4562 .rela.plt. We must create both sections in
4563 create_dynamic_sections, because they must be created
4564 before the linker maps input sections to output
4565 sections. The linker does that before
4566 adjust_dynamic_symbol is called, and it is that
4567 function which decides whether anything needs to go
4568 into these sections. */
4569 s
->flags
|= SEC_EXCLUDE
;
4573 /* Allocate memory for the section contents. We use bfd_zalloc
4574 here in case unused entries are not reclaimed before the
4575 section's contents are written out. This should not happen,
4576 but this way if it does, we get a R_NDS32_NONE reloc instead
4578 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4579 if (s
->contents
== NULL
)
4584 if (htab
->root
.dynamic_sections_created
)
4586 /* Add some entries to the .dynamic section. We fill in the
4587 values later, in nds32_elf_finish_dynamic_sections, but we
4588 must add the entries now so that we get the correct size for
4589 the .dynamic section. The DT_DEBUG entry is filled in by the
4590 dynamic linker and used by the debugger. */
4591 #define add_dynamic_entry(TAG, VAL) \
4592 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4594 if (bfd_link_executable (info
))
4596 if (!add_dynamic_entry (DT_DEBUG
, 0))
4600 if (elf_hash_table (info
)->splt
->size
!= 0)
4602 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4603 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4604 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4605 || !add_dynamic_entry (DT_JMPREL
, 0))
4609 if (htab
->tls_desc_trampoline
&& plt
)
4611 if (htab
->dt_tlsdesc_plt
4612 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
4613 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
4619 if (!add_dynamic_entry (DT_RELA
, 0)
4620 || !add_dynamic_entry (DT_RELASZ
, 0)
4621 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4624 /* If any dynamic relocs apply to a read-only section,
4625 then we need a DT_TEXTREL entry. */
4626 if ((info
->flags
& DF_TEXTREL
) == 0)
4627 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
,
4630 if ((info
->flags
& DF_TEXTREL
) != 0)
4632 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4637 #undef add_dynamic_entry
4642 static bfd_reloc_status_type
4643 nds32_relocate_contents (reloc_howto_type
*howto
, bfd
*input_bfd
,
4644 bfd_vma relocation
, bfd_byte
*location
)
4648 bfd_reloc_status_type flag
;
4649 unsigned int rightshift
= howto
->rightshift
;
4650 unsigned int bitpos
= howto
->bitpos
;
4652 /* If the size is negative, negate RELOCATION. This isn't very
4654 if (howto
->size
< 0)
4655 relocation
= -relocation
;
4657 /* Get the value we are going to relocate. */
4658 size
= bfd_get_reloc_size (howto
);
4665 return bfd_reloc_ok
;
4667 x
= bfd_getb16 (location
);
4670 x
= bfd_getb32 (location
);
4674 /* Check for overflow. FIXME: We may drop bits during the addition
4675 which we don't check for. We must either check at every single
4676 operation, which would be tedious, or we must do the computations
4677 in a type larger than bfd_vma, which would be inefficient. */
4678 flag
= bfd_reloc_ok
;
4679 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
4681 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
4684 /* Get the values to be added together. For signed and unsigned
4685 relocations, we assume that all values should be truncated to
4686 the size of an address. For bitfields, all the bits matter.
4687 See also bfd_check_overflow. */
4688 fieldmask
= N_ONES (howto
->bitsize
);
4689 signmask
= ~fieldmask
;
4690 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
4691 a
= (relocation
& addrmask
) >> rightshift
;
4692 b
= (x
& howto
->src_mask
& addrmask
) >> bitpos
;
4694 switch (howto
->complain_on_overflow
)
4696 case complain_overflow_signed
:
4697 /* If any sign bits are set, all sign bits must be set.
4698 That is, A must be a valid negative address after
4700 signmask
= ~(fieldmask
>> 1);
4703 case complain_overflow_bitfield
:
4704 /* Much like the signed check, but for a field one bit
4705 wider. We allow a bitfield to represent numbers in the
4706 range -2**n to 2**n-1, where n is the number of bits in the
4707 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
4708 can't overflow, which is exactly what we want. */
4710 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
4711 flag
= bfd_reloc_overflow
;
4713 /* We only need this next bit of code if the sign bit of B
4714 is below the sign bit of A. This would only happen if
4715 SRC_MASK had fewer bits than BITSIZE. Note that if
4716 SRC_MASK has more bits than BITSIZE, we can get into
4717 trouble; we would need to verify that B is in range, as
4718 we do for A above. */
4719 ss
= ((~howto
->src_mask
) >> 1) & howto
->src_mask
;
4722 /* Set all the bits above the sign bit. */
4725 /* Now we can do the addition. */
4728 /* See if the result has the correct sign. Bits above the
4729 sign bit are junk now; ignore them. If the sum is
4730 positive, make sure we did not have all negative inputs;
4731 if the sum is negative, make sure we did not have all
4732 positive inputs. The test below looks only at the sign
4733 bits, and it really just
4734 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
4736 We mask with addrmask here to explicitly allow an address
4737 wrap-around. The Linux kernel relies on it, and it is
4738 the only way to write assembler code which can run when
4739 loaded at a location 0x80000000 away from the location at
4740 which it is linked. */
4741 if (((~(a
^ b
)) & (a
^ sum
)) & signmask
& addrmask
)
4742 flag
= bfd_reloc_overflow
;
4746 case complain_overflow_unsigned
:
4747 /* Checking for an unsigned overflow is relatively easy:
4748 trim the addresses and add, and trim the result as well.
4749 Overflow is normally indicated when the result does not
4750 fit in the field. However, we also need to consider the
4751 case when, e.g., fieldmask is 0x7fffffff or smaller, an
4752 input is 0x80000000, and bfd_vma is only 32 bits; then we
4753 will get sum == 0, but there is an overflow, since the
4754 inputs did not fit in the field. Instead of doing a
4755 separate test, we can check for this by or-ing in the
4756 operands when testing for the sum overflowing its final
4758 sum
= (a
+ b
) & addrmask
;
4759 if ((a
| b
| sum
) & signmask
)
4760 flag
= bfd_reloc_overflow
;
4768 /* Put RELOCATION in the right bits. */
4769 relocation
>>= (bfd_vma
) rightshift
;
4770 relocation
<<= (bfd_vma
) bitpos
;
4772 /* Add RELOCATION to the right bits of X. */
4774 Because the relaxation may generate duplicate relocation at one address,
4775 an addition to immediate in the instruction may cause the relocation added
4777 This bug should be fixed in assembler, but a check is also needed here. */
4778 if (howto
->partial_inplace
)
4779 x
= ((x
& ~howto
->dst_mask
)
4780 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
4782 x
= ((x
& ~howto
->dst_mask
) | ((relocation
) & howto
->dst_mask
));
4785 /* Put the relocated value back in the object file. */
4795 bfd_putb16 (x
, location
);
4798 bfd_putb32 (x
, location
);
4805 static bfd_reloc_status_type
4806 nds32_elf_final_link_relocate (reloc_howto_type
*howto
, bfd
*input_bfd
,
4807 asection
*input_section
, bfd_byte
*contents
,
4808 bfd_vma address
, bfd_vma value
, bfd_vma addend
)
4812 /* Sanity check the address. */
4813 if (address
> bfd_get_section_limit (input_bfd
, input_section
))
4814 return bfd_reloc_outofrange
;
4816 /* This function assumes that we are dealing with a basic relocation
4817 against a symbol. We want to compute the value of the symbol to
4818 relocate to. This is just VALUE, the value of the symbol, plus
4819 ADDEND, any addend associated with the reloc. */
4820 relocation
= value
+ addend
;
4822 /* If the relocation is PC relative, we want to set RELOCATION to
4823 the distance between the symbol (currently in RELOCATION) and the
4824 location we are relocating. If pcrel_offset is FALSE we do not
4825 need to subtract out the offset of the location within the
4826 section (which is just ADDRESS). */
4827 if (howto
->pc_relative
)
4829 relocation
-= (input_section
->output_section
->vma
4830 + input_section
->output_offset
);
4831 if (howto
->pcrel_offset
)
4832 relocation
-= address
;
4835 return nds32_relocate_contents (howto
, input_bfd
, relocation
,
4836 contents
+ address
);
4840 nds32_elf_output_symbol_hook (struct bfd_link_info
*info
,
4842 Elf_Internal_Sym
*elfsym ATTRIBUTE_UNUSED
,
4843 asection
*input_sec
,
4844 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4847 FILE *sym_ld_script
= NULL
;
4848 struct elf_nds32_link_hash_table
*table
;
4850 table
= nds32_elf_hash_table (info
);
4851 sym_ld_script
= table
->sym_ld_script
;
4855 if (!h
|| !name
|| *name
== '\0')
4858 if (input_sec
->flags
& SEC_EXCLUDE
)
4861 if (!check_start_export_sym
)
4863 fprintf (sym_ld_script
, "SECTIONS\n{\n");
4864 check_start_export_sym
= 1;
4867 if (h
->root
.type
== bfd_link_hash_defined
4868 || h
->root
.type
== bfd_link_hash_defweak
)
4870 if (!h
->root
.u
.def
.section
->output_section
)
4873 if (bfd_is_const_section (input_sec
))
4874 source
= input_sec
->name
;
4876 source
= input_sec
->owner
->filename
;
4878 fprintf (sym_ld_script
, "\t%s = 0x%08lx;\t /* %s */\n",
4879 h
->root
.root
.string
,
4880 (long) (h
->root
.u
.def
.value
4881 + h
->root
.u
.def
.section
->output_section
->vma
4882 + h
->root
.u
.def
.section
->output_offset
), source
);
4888 /* Relocate an NDS32/D ELF section.
4889 There is some attempt to make this function usable for many architectures,
4890 both for RELA and REL type relocs, if only to serve as a learning tool.
4892 The RELOCATE_SECTION function is called by the new ELF backend linker
4893 to handle the relocations for a section.
4895 The relocs are always passed as Rela structures; if the section
4896 actually uses Rel structures, the r_addend field will always be
4899 This function is responsible for adjust the section contents as
4900 necessary, and (if using Rela relocs and generating a
4901 relocatable output file) adjusting the reloc addend as
4904 This function does not have to worry about setting the reloc
4905 address or the reloc symbol index.
4907 LOCAL_SYMS is a pointer to the swapped in local symbols.
4909 LOCAL_SECTIONS is an array giving the section in the input file
4910 corresponding to the st_shndx field of each local symbol.
4912 The global hash table entry for the global symbols can be found
4913 via elf_sym_hashes (input_bfd).
4915 When generating relocatable output, this function must handle
4916 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4917 going to be the section symbol corresponding to the output
4918 section, which means that the addend must be adjusted
4921 /* Return the base VMA address which should be subtracted from real addresses
4922 when resolving @dtpoff relocation.
4923 This is PT_TLS segment p_vaddr. */
4925 /* Return the relocation value for @tpoff relocation
4926 if STT_TLS virtual address is ADDRESS. */
4928 /* Return the relocation value for @gottpoff relocation
4929 if STT_TLS virtual address is ADDRESS. */
4932 gottpoff (struct bfd_link_info
*info
, bfd_vma address
)
4937 /* If tls_sec is NULL, we should have signalled an error already. */
4938 if (elf_hash_table (info
)->tls_sec
== NULL
)
4941 tp_base
= elf_hash_table (info
)->tls_sec
->vma
;
4942 tp_offset
= address
- tp_base
;
4948 patch_tls_desc_to_ie (bfd_byte
*contents
, Elf_Internal_Rela
*rel
, bfd
*ibfd
)
4950 /* TLS_GD/TLS_LD model #1
4951 46 00 00 00 sethi $r0,#0x0
4952 58 00 00 00 ori $r0,$r0,#0x0
4953 40 00 74 00 add $r0,$r0,$gp
4954 04 10 00 00 lwi $r1,[$r0+#0x0]
4955 4b e0 04 01 jral $lp,$r1 */
4957 /* TLS_GD/TLS_LD model #2
4958 46 00 00 00 sethi $r0,#0x0
4959 58 00 00 00 ori $r0,$r0,#0x0
4960 38 10 74 02 lw $r1,[$r0+($gp<<#0x0)]
4961 40 00 74 00 add $r0,$r0,$gp
4962 4b e0 04 01 jral $lp,$r1 */
4964 /* TLS_IE model (non-PIC)
4965 46 00 00 00 sethi $r0,#0x0
4966 04 00 00 00 lwi $r0,[$r0+#0x0]
4967 38 00 64 02 lw $r0,[$r0+($r25<<#0x0)] */
4969 /* TLS_IE model (PIC)
4970 46 00 00 00 sethi $r0,#0x0
4971 58 00 00 00 ori $r0,$r0,#0x0
4972 38 00 74 02 lw $r0,[$r0+($gp<<#0x0)]
4973 38 00 64 02 lw $r0,[$r0+($r25<<#0x0)] */
4975 /* TLS_GD_TO_IE model
4976 46 00 00 00 sethi $r0,#0x0
4977 58 00 00 00 ori $r0,$r0,#0x0
4978 40 00 74 00 add $r0,$rM,$gp
4979 04 00 00 01 lwi $r0,[$r0+#0x4]
4980 40 00 64 00 add $r0,$r0,$r25 */
4982 bfd_boolean rz
= FALSE
;
4992 0x40007400, /* add $r0,$rM,$gp */
4993 0x04000001, /* lwi $r0,[$r0+#0x4] */
4994 0x40006400, /* add $r0,$r0,$r25 */
4999 { 0x40000000, 0xfe0003ff },
5000 { 0x04000000, 0xfe000000 },
5001 { 0x4be00001, 0xffff83ff },
5006 { 0x38007402, 0xfe007fff },
5007 { 0x40007400, 0xfe007fff },
5008 { 0x4be00001, 0xffff83ff },
5011 unsigned char *p
= contents
+ rel
->r_offset
;
5014 uint32_t regidx
= 0;
5015 insn
= bfd_getb32 (p
);
5016 if (INSN_SETHI
== (0xfe0fffffu
& insn
))
5018 regidx
= 0x1f & (insn
>> 20);
5022 insn
= bfd_getb32 (p
);
5023 if (INSN_ORI
== (0xfe007fffu
& insn
))
5025 regidx
= 0x1f & (insn
>> 20);
5029 if (patch
[2] == bfd_getb32 (p
+ 8)) /* Character instruction. */
5031 /* already patched? */
5032 if ((patch
[0] == (0xfff07fffu
& bfd_getb32 (p
+ 0))) &&
5033 (patch
[1] == bfd_getb32 (p
+ 4)))
5036 else if (mode0
[0].opcode
== (mode0
[0].mask
& bfd_getb32 (p
+ 0)))
5038 if ((mode0
[1].opcode
== (mode0
[1].mask
& bfd_getb32 (p
+ 4))) &&
5039 (mode0
[2].opcode
== (mode0
[2].mask
& bfd_getb32 (p
+ 8))))
5041 bfd_putb32 (patch
[0] | (regidx
<< 15), p
+ 0);
5042 bfd_putb32 (patch
[1], p
+ 4);
5043 bfd_putb32 (patch
[2], p
+ 8);
5047 else if (mode1
[0].opcode
== (mode1
[0].mask
& bfd_getb32 (p
+ 0)))
5049 if ((mode1
[1].opcode
== (mode1
[1].mask
& bfd_getb32 (p
+ 4))) &&
5050 (mode1
[2].opcode
== (mode1
[2].mask
& bfd_getb32 (p
+ 8))))
5052 bfd_putb32 (patch
[0] | (regidx
<< 15), p
+ 0);
5053 bfd_putb32 (patch
[1], p
+ 4);
5054 bfd_putb32 (patch
[2], p
+ 8);
5061 printf ("%s: %s @ 0x%08x\n", __func__
, ibfd
->filename
,
5062 (int) rel
->r_offset
);
5063 BFD_ASSERT(0); /* Unsupported pattern. */
5069 static enum elf_nds32_tls_type
5070 get_tls_type (enum elf_nds32_reloc_type r_type
, struct elf_link_hash_entry
*h
);
5073 ones32 (register unsigned int x
)
5075 /* 32-bit recursive reduction using SWAR...
5076 but first step is mapping 2-bit values
5077 into sum of 2 1-bit values in sneaky way. */
5078 x
-= ((x
>> 1) & 0x55555555);
5079 x
= (((x
>> 2) & 0x33333333) + (x
& 0x33333333));
5080 x
= (((x
>> 4) + x
) & 0x0f0f0f0f);
5083 return (x
& 0x0000003f);
5087 fls (register unsigned int x
)
5089 return ffs (x
& (-x
));
5092 #define nds32_elf_local_tlsdesc_gotent(bfd) \
5093 (elf_nds32_tdata (bfd)->local_tlsdesc_gotent)
5096 nds32_elf_relocate_section (bfd
* output_bfd ATTRIBUTE_UNUSED
,
5097 struct bfd_link_info
* info
,
5099 asection
* input_section
,
5100 bfd_byte
* contents
,
5101 Elf_Internal_Rela
* relocs
,
5102 Elf_Internal_Sym
* local_syms
,
5103 asection
** local_sections
)
5105 Elf_Internal_Shdr
*symtab_hdr
;
5106 struct elf_link_hash_entry
**sym_hashes
;
5107 Elf_Internal_Rela
*rel
, *relend
;
5108 bfd_boolean ret
= TRUE
; /* Assume success. */
5110 bfd_reloc_status_type r
;
5111 const char *errmsg
= NULL
;
5113 struct elf_link_hash_table
*ehtab
;
5114 struct elf_nds32_link_hash_table
*htab
;
5116 bfd_vma
*local_got_offsets
;
5117 asection
*sgot
, *splt
, *sreloc
;
5118 bfd_vma high_address
;
5119 struct elf_nds32_link_hash_table
*table
;
5120 int eliminate_gc_relocs
;
5121 bfd_vma fpbase_addr
;
5123 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5124 sym_hashes
= elf_sym_hashes (input_bfd
);
5125 ehtab
= elf_hash_table (info
);
5126 htab
= nds32_elf_hash_table (info
);
5127 high_address
= bfd_get_section_limit (input_bfd
, input_section
);
5129 dynobj
= htab
->root
.dynobj
;
5130 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5137 relend
= relocs
+ input_section
->reloc_count
;
5139 table
= nds32_elf_hash_table (info
);
5140 eliminate_gc_relocs
= table
->eliminate_gc_relocs
;
5142 /* By this time, we can adjust the value of _SDA_BASE_. */
5143 /* Explain _SDA_BASE_ */
5144 if ((!bfd_link_relocatable (info
)))
5146 is_SDA_BASE_set
= 1;
5147 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, TRUE
);
5148 if (r
!= bfd_reloc_ok
)
5152 /* Do TLS model conversion once at first. */
5153 nds32_elf_unify_tls_model (input_bfd
, input_section
, contents
, info
);
5155 /* Use gp as fp to prevent truncated fit. Because in relaxation time
5156 the fp value is set as gp, and it has be reverted for instruction
5158 fpbase_addr
= elf_gp (output_bfd
);
5160 /* Deal with (dynamic) relocations. */
5161 for (rel
= relocs
; rel
< relend
; rel
++)
5163 enum elf_nds32_reloc_type r_type
;
5164 reloc_howto_type
*howto
= NULL
;
5165 unsigned long r_symndx
;
5166 struct elf_link_hash_entry
*h
= NULL
;
5167 Elf_Internal_Sym
*sym
= NULL
;
5170 bfd_vma relocation_sym
= 0xdeadbeef;
5171 Elf_Internal_Rela
*lorel
;
5174 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
5175 ensure it's zero (we use REL relocs, not RELA). Therefore this
5176 should be assigning zero to `addend', but for clarity we use
5179 bfd_vma addend
= rel
->r_addend
;
5180 bfd_vma offset
= rel
->r_offset
;
5182 r_type
= ELF32_R_TYPE (rel
->r_info
);
5183 if (r_type
>= R_NDS32_max
)
5185 /* xgettext:c-format */
5186 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
5188 bfd_set_error (bfd_error_bad_value
);
5193 if (r_type
== R_NDS32_GNU_VTENTRY
5194 || r_type
== R_NDS32_GNU_VTINHERIT
5195 || r_type
== R_NDS32_NONE
5196 || r_type
== R_NDS32_RELA_GNU_VTENTRY
5197 || r_type
== R_NDS32_RELA_GNU_VTINHERIT
5198 || (r_type
>= R_NDS32_INSN16
&& r_type
<= R_NDS32_25_FIXED_RELA
)
5199 || r_type
== R_NDS32_DATA
5200 || r_type
== R_NDS32_TRAN
)
5203 /* If we enter the fp-as-gp region. Resolve the address
5205 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
5206 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
5210 /* Distance to relocation of best fp-base is encoded in R_SYM. */
5211 dist
= rel
->r_addend
>> 16;
5212 fpbase_addr
= calculate_memory_address (input_bfd
, rel
+ dist
,
5213 local_syms
, symtab_hdr
);
5215 else if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_END
5216 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
5218 fpbase_addr
= elf_gp (output_bfd
);
5221 /* Skip the relocations used for relaxation. */
5222 /* We have to update LONGCALL and LONGJUMP
5223 relocations when generating the relocatable files. */
5224 if (!bfd_link_relocatable (info
)
5225 && (r_type
>= R_NDS32_RELAX_ENTRY
5226 || (r_type
>= R_NDS32_LONGCALL4
5227 && r_type
<= R_NDS32_LONGJUMP7
)))
5230 howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
5231 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5233 /* This is a final link. */
5238 if (r_symndx
< symtab_hdr
->sh_info
)
5241 sym
= local_syms
+ r_symndx
;
5242 sec
= local_sections
[r_symndx
];
5244 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5245 addend
= rel
->r_addend
;
5247 /* keep symbol location for static TLS_IE GOT entry */
5248 relocation_sym
= relocation
;
5249 if (bfd_link_relocatable (info
))
5251 /* This is a relocatable link. We don't have to change
5252 anything, unless the reloc is against a section symbol,
5253 in which case we have to adjust according to where the
5254 section symbol winds up in the output section. */
5255 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5256 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
5263 /* External symbol. */
5264 if (bfd_link_relocatable (info
))
5266 bfd_boolean warned
, ignored
, unresolved_reloc
;
5267 int symndx
= r_symndx
- symtab_hdr
->sh_info
;
5269 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5270 r_symndx
, symtab_hdr
, sym_hashes
, h
, sec
,
5271 relocation
, unresolved_reloc
, warned
,
5274 /* keep symbol location for static TLS_IE GOT entry */
5275 relocation_sym
= relocation
;
5277 /* la $fp, _FP_BASE_ is per-function (region).
5278 Handle it specially. */
5279 switch ((int) r_type
)
5281 case R_NDS32_HI20_RELA
:
5282 case R_NDS32_LO12S0_RELA
:
5283 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
5286 if (!bfd_link_pie (info
))
5289 ("%pB: warning: _FP_BASE_ setting insns relaxation failed.",
5292 relocation
= fpbase_addr
;
5295 case R_NDS32_SDA19S0_RELA
:
5296 case R_NDS32_SDA15S0_RELA
:
5297 case R_NDS32_20_RELA
:
5298 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
5301 relocation
= fpbase_addr
;
5307 /* Sanity check the address. */
5308 if (offset
> high_address
)
5310 r
= bfd_reloc_outofrange
;
5314 if (r_type
>= R_NDS32_RELAX_ENTRY
)
5317 switch ((int) r_type
)
5319 case R_NDS32_GOTOFF
:
5320 /* Relocation is relative to the start of the global offset
5321 table (for ld24 rx, #uimm24), e.g. access at label+addend
5323 ld24 rx. #label@GOTOFF + addend
5325 case R_NDS32_GOTOFF_HI20
:
5326 case R_NDS32_GOTOFF_LO12
:
5327 case R_NDS32_GOTOFF_LO15
:
5328 case R_NDS32_GOTOFF_LO19
:
5329 BFD_ASSERT (sgot
!= NULL
);
5331 relocation
-= elf_gp (output_bfd
);
5334 case R_NDS32_9_PLTREL
:
5335 case R_NDS32_25_PLTREL
:
5336 /* Relocation is to the entry for this symbol in the
5337 procedure linkage table. */
5339 /* The native assembler will generate a 25_PLTREL reloc
5340 for a local symbol if you assemble a call from one
5341 section to another when using -K pic. */
5345 if (h
->forced_local
)
5348 /* We didn't make a PLT entry for this symbol. This
5349 happens when statically linking PIC code, or when
5350 using -Bsymbolic. */
5351 if (h
->plt
.offset
== (bfd_vma
) - 1)
5354 relocation
= (splt
->output_section
->vma
5355 + splt
->output_offset
+ h
->plt
.offset
);
5358 case R_NDS32_PLT_GOTREL_HI20
:
5359 case R_NDS32_PLT_GOTREL_LO12
:
5360 case R_NDS32_PLT_GOTREL_LO15
:
5361 case R_NDS32_PLT_GOTREL_LO19
:
5362 case R_NDS32_PLT_GOTREL_LO20
:
5365 || h
->plt
.offset
== (bfd_vma
) -1
5366 || (bfd_link_pie (info
) && h
->def_regular
))
5368 /* Maybe we should find better checking to optimize
5369 PIE PLT relocations. */
5370 /* We didn't make a PLT entry for this symbol. This
5371 happens when statically linking PIC code, or when
5372 using -Bsymbolic. */
5374 h
->plt
.offset
= (bfd_vma
) -1; /* Cancel PLT trampoline. */
5375 relocation
-= elf_gp (output_bfd
);
5379 relocation
= (splt
->output_section
->vma
5380 + splt
->output_offset
+ h
->plt
.offset
);
5382 relocation
-= elf_gp (output_bfd
);
5385 case R_NDS32_PLTREL_HI20
:
5386 case R_NDS32_PLTREL_LO12
:
5388 /* Relocation is to the entry for this symbol in the
5389 procedure linkage table. */
5391 /* The native assembler will generate a 25_PLTREL reloc
5392 for a local symbol if you assemble a call from one
5393 section to another when using -K pic. */
5397 if (h
->forced_local
)
5400 if (h
->plt
.offset
== (bfd_vma
) - 1)
5401 /* We didn't make a PLT entry for this symbol. This
5402 happens when statically linking PIC code, or when
5403 using -Bsymbolic. */
5409 relocation
= (splt
->output_section
->vma
5410 + splt
->output_offset
5411 + h
->plt
.offset
+ 4)
5412 - (input_section
->output_section
->vma
5413 + input_section
->output_offset
5418 case R_NDS32_GOTPC20
:
5419 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5420 ld24 rx,#_GLOBAL_OFFSET_TABLE_ */
5421 relocation
= elf_gp (output_bfd
);
5424 case R_NDS32_GOTPC_HI20
:
5425 case R_NDS32_GOTPC_LO12
:
5426 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5428 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
5429 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
5432 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
5433 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4) */
5434 relocation
= elf_gp (output_bfd
);
5435 relocation
-= (input_section
->output_section
->vma
5436 + input_section
->output_offset
+ rel
->r_offset
);
5441 case R_NDS32_GOT_HI20
:
5442 case R_NDS32_GOT_LO12
:
5443 case R_NDS32_GOT_LO15
:
5444 case R_NDS32_GOT_LO19
:
5445 /* Relocation is to the entry for this symbol in the global
5447 BFD_ASSERT (sgot
!= NULL
);
5451 /* External symbol */
5454 off
= h
->got
.offset
;
5455 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5456 dyn
= htab
->root
.dynamic_sections_created
;
5457 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
5458 bfd_link_pic (info
),
5460 || (bfd_link_pic (info
)
5463 || h
->forced_local
) && h
->def_regular
))
5465 /* This is actually a static link, or it is a
5466 -Bsymbolic link and the symbol is defined
5467 locally, or the symbol was forced to be local
5468 because of a version file. We must initialize
5469 this entry in the global offset table. Since the
5470 offset must always be a multiple of 4, we use the
5471 least significant bit to record whether we have
5472 initialized it already.
5474 When doing a dynamic link, we create a .rela.got
5475 relocation entry to initialize the value. This
5476 is done in the finish_dynamic_symbol routine. */
5477 if ((off
& 1) != 0) /* clear LSB */
5481 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5485 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5486 - elf_gp (output_bfd
);
5493 BFD_ASSERT (local_got_offsets
!= NULL
5494 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5496 off
= local_got_offsets
[r_symndx
];
5498 /* The offset must always be a multiple of 4. We use
5499 the least significant bit to record whether we have
5500 already processed this entry. */
5501 if ((off
& 1) != 0) /* clear LSB */
5505 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5507 if (bfd_link_pic (info
))
5510 Elf_Internal_Rela outrel
;
5512 /* We need to generate a R_NDS32_RELATIVE reloc
5513 for the dynamic linker. */
5514 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5515 BFD_ASSERT (srelgot
!= NULL
);
5517 outrel
.r_offset
= (elf_gp (output_bfd
)
5518 + sgot
->output_offset
+ off
);
5519 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5520 outrel
.r_addend
= relocation
;
5521 loc
= srelgot
->contents
;
5523 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5524 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5525 ++srelgot
->reloc_count
;
5527 local_got_offsets
[r_symndx
] |= 1;
5529 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5530 - elf_gp (output_bfd
);
5535 case R_NDS32_16_RELA
:
5536 case R_NDS32_20_RELA
:
5537 case R_NDS32_5_RELA
:
5538 case R_NDS32_32_RELA
:
5539 case R_NDS32_9_PCREL_RELA
:
5540 case R_NDS32_WORD_9_PCREL_RELA
:
5541 case R_NDS32_10_UPCREL_RELA
:
5542 case R_NDS32_15_PCREL_RELA
:
5543 case R_NDS32_17_PCREL_RELA
:
5544 case R_NDS32_25_PCREL_RELA
:
5545 case R_NDS32_HI20_RELA
:
5546 case R_NDS32_LO12S3_RELA
:
5547 case R_NDS32_LO12S2_RELA
:
5548 case R_NDS32_LO12S2_DP_RELA
:
5549 case R_NDS32_LO12S2_SP_RELA
:
5550 case R_NDS32_LO12S1_RELA
:
5551 case R_NDS32_LO12S0_RELA
:
5552 case R_NDS32_LO12S0_ORI_RELA
:
5553 if (bfd_link_pic (info
) && r_symndx
!= 0
5554 && (input_section
->flags
& SEC_ALLOC
) != 0
5555 && (eliminate_gc_relocs
== 0
5556 || (sec
&& (sec
->flags
& SEC_EXCLUDE
) == 0))
5557 && ((r_type
!= R_NDS32_9_PCREL_RELA
5558 && r_type
!= R_NDS32_WORD_9_PCREL_RELA
5559 && r_type
!= R_NDS32_10_UPCREL_RELA
5560 && r_type
!= R_NDS32_15_PCREL_RELA
5561 && r_type
!= R_NDS32_17_PCREL_RELA
5562 && r_type
!= R_NDS32_25_PCREL_RELA
5563 && !(r_type
== R_NDS32_32_RELA
5564 && strcmp (input_section
->name
, ".eh_frame") == 0))
5565 || (h
!= NULL
&& h
->dynindx
!= -1
5566 && (!info
->symbolic
|| !h
->def_regular
))))
5568 Elf_Internal_Rela outrel
;
5569 bfd_boolean skip
, relocate
;
5572 /* When generating a shared object, these relocations
5573 are copied into the output file to be resolved at run
5580 name
= bfd_elf_string_from_elf_section
5581 (input_bfd
, elf_elfheader (input_bfd
)->e_shstrndx
,
5582 elf_section_data (input_section
)->rela
.hdr
->sh_name
);
5586 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5587 && strcmp (bfd_get_section_name (input_bfd
,
5591 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5592 BFD_ASSERT (sreloc
!= NULL
);
5598 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5602 if (outrel
.r_offset
== (bfd_vma
) - 1)
5604 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5605 skip
= TRUE
, relocate
= TRUE
;
5606 outrel
.r_offset
+= (input_section
->output_section
->vma
5607 + input_section
->output_offset
);
5610 memset (&outrel
, 0, sizeof outrel
);
5611 else if (r_type
== R_NDS32_17_PCREL_RELA
5612 || r_type
== R_NDS32_15_PCREL_RELA
5613 || r_type
== R_NDS32_25_PCREL_RELA
)
5615 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5616 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5617 outrel
.r_addend
= rel
->r_addend
;
5621 /* h->dynindx may be -1 if this symbol was marked to
5624 || ((info
->symbolic
|| h
->dynindx
== -1)
5626 || (bfd_link_pie (info
) && h
->def_regular
))
5629 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5630 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5634 h
->plt
.offset
= (bfd_vma
) -1; /* cancel PLT trampoline. */
5636 BFD_ASSERT (sgot
!= NULL
);
5637 /* If we did not allocate got entry for the symbol,
5638 we can not fill the nonexistent got entry. */
5639 if (h
->got
.offset
!= (bfd_vma
) -1
5640 && (h
->got
.offset
& 1) == 0)
5642 bfd_put_32 (output_bfd
, outrel
.r_addend
,
5643 sgot
->contents
+ h
->got
.offset
);
5649 if (h
->dynindx
== -1)
5652 (_("%pB: relocation %s against `%s' can not be used when"
5653 "making a shared object; recompile with -fPIC"),
5654 input_bfd
, nds32_elf_howto_table
[r_type
].name
, h
->root
.root
.string
);
5655 bfd_set_error (bfd_error_bad_value
);
5659 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5660 outrel
.r_addend
= rel
->r_addend
;
5664 loc
= sreloc
->contents
;
5665 loc
+= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
5666 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5667 ++sreloc
->reloc_count
;
5669 /* If this reloc is against an external symbol, we do
5670 not want to fiddle with the addend. Otherwise, we
5671 need to include the symbol value so that it becomes
5672 an addend for the dynamic reloc. */
5678 case R_NDS32_25_ABS_RELA
:
5679 if (bfd_link_pic (info
))
5682 (_("%pB: warning: %s unsupported in shared mode"),
5683 input_bfd
, "R_NDS32_25_ABS_RELA");
5688 case R_NDS32_9_PCREL
:
5689 r
= nds32_elf_do_9_pcrel_reloc (input_bfd
, howto
, input_section
,
5691 sec
, relocation
, addend
);
5695 /* We allow an arbitrary number of HI20 relocs before the
5696 LO12 reloc. This permits gcc to emit the HI and LO relocs
5698 for (lorel
= rel
+ 1;
5700 && ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_HI20
); lorel
++)
5703 && (ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S3
5704 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S2
5705 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S1
5706 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S0
))
5708 nds32_elf_relocate_hi20 (input_bfd
, r_type
, rel
, lorel
,
5709 contents
, relocation
+ addend
);
5713 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5714 contents
, offset
, relocation
,
5718 case R_NDS32_GOT17S2_RELA
:
5719 case R_NDS32_GOT15S2_RELA
:
5720 BFD_ASSERT (sgot
!= NULL
);
5726 off
= h
->got
.offset
;
5727 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5729 dyn
= htab
->root
.dynamic_sections_created
;
5730 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL
5731 (dyn
, bfd_link_pic (info
), h
)
5732 || (bfd_link_pic (info
)
5738 /* This is actually a static link, or it is a
5739 -Bsymbolic link and the symbol is defined
5740 locally, or the symbol was forced to be local
5741 because of a version file. We must initialize
5742 this entry in the global offset table. Since the
5743 offset must always be a multiple of 4, we use the
5744 least significant bit to record whether we have
5745 initialized it already.
5747 When doing a dynamic link, we create a .rela.got
5748 relocation entry to initialize the value. This
5749 is done in the finish_dynamic_symbol routine. */
5754 bfd_put_32 (output_bfd
, relocation
,
5755 sgot
->contents
+ off
);
5764 BFD_ASSERT (local_got_offsets
!= NULL
5765 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5767 off
= local_got_offsets
[r_symndx
];
5769 /* The offset must always be a multiple of 4. We use
5770 the least significant bit to record whether we have
5771 already processed this entry. */
5776 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5778 if (bfd_link_pic (info
))
5781 Elf_Internal_Rela outrel
;
5783 /* We need to generate a R_NDS32_RELATIVE reloc
5784 for the dynamic linker. */
5785 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5786 BFD_ASSERT (srelgot
!= NULL
);
5788 outrel
.r_offset
= (elf_gp (output_bfd
)
5789 + sgot
->output_offset
+ off
);
5790 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5791 outrel
.r_addend
= relocation
;
5792 loc
= srelgot
->contents
;
5794 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5795 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5796 ++srelgot
->reloc_count
;
5798 local_got_offsets
[r_symndx
] |= 1;
5801 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5802 - elf_gp (output_bfd
);
5804 if (relocation
& align
)
5806 /* Incorrect alignment. */
5808 (_("%pB: warning: unaligned access to GOT entry"), input_bfd
);
5810 r
= bfd_reloc_dangerous
;
5815 case R_NDS32_SDA16S3_RELA
:
5816 case R_NDS32_SDA15S3_RELA
:
5817 case R_NDS32_SDA15S3
:
5821 case R_NDS32_SDA17S2_RELA
:
5822 case R_NDS32_SDA15S2_RELA
:
5823 case R_NDS32_SDA12S2_SP_RELA
:
5824 case R_NDS32_SDA12S2_DP_RELA
:
5825 case R_NDS32_SDA15S2
:
5826 case R_NDS32_SDA_FP7U2_RELA
:
5830 case R_NDS32_SDA18S1_RELA
:
5831 case R_NDS32_SDA15S1_RELA
:
5832 case R_NDS32_SDA15S1
:
5836 case R_NDS32_SDA19S0_RELA
:
5837 case R_NDS32_SDA15S0_RELA
:
5838 case R_NDS32_SDA15S0
:
5841 BFD_ASSERT (sec
!= NULL
);
5843 /* If the symbol is in the abs section, the out_bfd will be null.
5844 This happens when the relocation has a symbol@GOTOFF. */
5845 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, FALSE
);
5846 if (r
!= bfd_reloc_ok
)
5849 (_("%pB: warning: relocate SDA_BASE failed"), input_bfd
);
5854 /* At this point `relocation' contains the object's
5856 if (r_type
== R_NDS32_SDA_FP7U2_RELA
)
5858 relocation
-= fpbase_addr
;
5862 /* Now it contains the offset from _SDA_BASE_. */
5864 /* Make sure alignment is correct. */
5866 if (relocation
& align
)
5868 /* Incorrect alignment. */
5870 /* xgettext:c-format */
5871 (_("%pB(%pA): warning: unaligned small data access"
5873 input_bfd
, input_section
, r_type
);
5879 case R_NDS32_17IFC_PCREL_RELA
:
5880 case R_NDS32_10IFCU_PCREL_RELA
:
5884 case R_NDS32_TLS_LE_HI20
:
5885 case R_NDS32_TLS_LE_LO12
:
5886 case R_NDS32_TLS_LE_20
:
5887 case R_NDS32_TLS_LE_15S0
:
5888 case R_NDS32_TLS_LE_15S1
:
5889 case R_NDS32_TLS_LE_15S2
:
5890 /* We do not have garbage collection for got entries.
5891 Therefore, IE to LE may have one empty entry, and DESC to
5893 if (elf_hash_table (info
)->tls_sec
!= NULL
)
5894 relocation
-= (elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
);
5897 case R_NDS32_TLS_IE_HI20
:
5898 case R_NDS32_TLS_IE_LO12S2
:
5899 case R_NDS32_TLS_DESC_HI20
:
5900 case R_NDS32_TLS_DESC_LO12
:
5901 case R_NDS32_TLS_IE_LO12
:
5902 case R_NDS32_TLS_IEGP_HI20
:
5903 case R_NDS32_TLS_IEGP_LO12
:
5904 case R_NDS32_TLS_IEGP_LO12S2
:
5906 /* Relocation is to the entry for this symbol in the global
5908 enum elf_nds32_tls_type tls_type
, org_tls_type
, eff_tls_type
;
5910 Elf_Internal_Rela outrel
;
5914 eff_tls_type
= org_tls_type
= get_tls_type (r_type
, h
);
5916 BFD_ASSERT (sgot
!= NULL
);
5921 off
= h
->got
.offset
;
5922 BFD_ASSERT (off
!= (bfd_vma
) -1);
5923 dyn
= htab
->root
.dynamic_sections_created
;
5924 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
5925 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
5926 && (!bfd_link_pic (info
)
5927 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
5932 BFD_ASSERT (local_got_offsets
!= NULL
5933 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5934 off
= local_got_offsets
[r_symndx
];
5935 tls_type
= elf32_nds32_local_got_tls_type (input_bfd
)[r_symndx
];
5938 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
;
5940 if (1 < ones32 (tls_type
))
5942 eff_tls_type
= 1 << (fls (tls_type
) - 1);
5943 /* TLS model shall be handled in nds32_elf_unify_tls_model (). */
5945 /* TLS model X -> LE is not implement yet!
5947 if (eff_tls_type
== GOT_TLS_LE
)
5949 eff_tls_type
= 1 << (fls (tls_type
^ eff_tls_type
) - 1);
5953 /* The offset must always be a multiple of 4. We use
5954 the least significant bit to record whether we have
5955 already processed this entry. */
5956 bfd_boolean need_relocs
= FALSE
;
5957 srelgot
= ehtab
->srelgot
;
5958 if ((bfd_link_pic (info
) || indx
!= 0)
5959 && (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5960 || h
->root
.type
!= bfd_link_hash_undefweak
))
5963 BFD_ASSERT (srelgot
!= NULL
);
5971 if (eff_tls_type
& GOT_TLS_DESC
)
5973 relocation
-= elf_gp (output_bfd
);
5974 if ((R_NDS32_TLS_DESC_HI20
== r_type
) && (!need_relocs
))
5976 /* TLS model shall be converted. */
5980 else if (eff_tls_type
& GOT_TLS_IEGP
)
5982 relocation
-= elf_gp (output_bfd
);
5987 if ((eff_tls_type
& GOT_TLS_LE
) && (tls_type
^ eff_tls_type
))
5989 /* TLS model workaround shall be applied. */
5992 else if (eff_tls_type
& (GOT_TLS_IE
| GOT_TLS_IEGP
))
5994 if (eff_tls_type
& GOT_TLS_IEGP
)
5995 relocation
-= elf_gp(output_bfd
);
6000 outrel
.r_addend
= gottpoff (info
, relocation_sym
);
6002 outrel
.r_addend
= 0;
6003 outrel
.r_offset
= (sgot
->output_section
->vma
6004 + sgot
->output_offset
+ off
);
6005 outrel
.r_info
= ELF32_R_INFO (indx
, R_NDS32_TLS_TPOFF
);
6007 elf32_nds32_add_dynreloc (output_bfd
, info
, srelgot
,
6012 bfd_put_32 (output_bfd
, gottpoff (info
, relocation_sym
),
6013 sgot
->contents
+ off
);
6016 else if (eff_tls_type
& GOT_TLS_DESC
)
6018 relocation
-= elf_gp (output_bfd
);
6022 outrel
.r_addend
= gottpoff (info
, relocation_sym
);
6024 outrel
.r_addend
= 0;
6025 outrel
.r_offset
= (sgot
->output_section
->vma
6026 + sgot
->output_offset
+ off
);
6027 outrel
.r_info
= ELF32_R_INFO (indx
, R_NDS32_TLS_DESC
);
6029 if (htab
->tls_desc_trampoline
)
6032 srelplt
= ehtab
->srelplt
;
6033 loc
= srelplt
->contents
;
6034 loc
+= htab
->next_tls_desc_index
++ * sizeof (Elf32_External_Rela
);
6035 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rela
)
6036 <= srelplt
->contents
+ srelplt
->size
);
6038 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
6042 loc
= srelgot
->contents
;
6043 loc
+= srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
6044 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
6045 ++srelgot
->reloc_count
;
6051 bfd_put_32 (output_bfd
, 0xdeadbeef,
6052 sgot
->contents
+ off
);
6053 bfd_put_32 (output_bfd
, gottpoff (info
, relocation_sym
),
6054 sgot
->contents
+ off
+ 4);
6055 patch_tls_desc_to_ie (contents
, rel
, input_bfd
);
6061 /* TLS model workaround shall be applied. */
6068 local_got_offsets
[r_symndx
] |= 1;
6072 /* DON'T fall through. */
6075 /* OLD_NDS32_RELOC. */
6077 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6078 contents
, offset
, relocation
, addend
);
6082 switch ((int) r_type
)
6084 case R_NDS32_20_RELA
:
6085 case R_NDS32_5_RELA
:
6086 case R_NDS32_9_PCREL_RELA
:
6087 case R_NDS32_WORD_9_PCREL_RELA
:
6088 case R_NDS32_10_UPCREL_RELA
:
6089 case R_NDS32_15_PCREL_RELA
:
6090 case R_NDS32_17_PCREL_RELA
:
6091 case R_NDS32_25_PCREL_RELA
:
6092 case R_NDS32_25_ABS_RELA
:
6093 case R_NDS32_HI20_RELA
:
6094 case R_NDS32_LO12S3_RELA
:
6095 case R_NDS32_LO12S2_RELA
:
6096 case R_NDS32_LO12S2_DP_RELA
:
6097 case R_NDS32_LO12S2_SP_RELA
:
6098 case R_NDS32_LO12S1_RELA
:
6099 case R_NDS32_LO12S0_RELA
:
6100 case R_NDS32_LO12S0_ORI_RELA
:
6101 case R_NDS32_SDA16S3_RELA
:
6102 case R_NDS32_SDA17S2_RELA
:
6103 case R_NDS32_SDA18S1_RELA
:
6104 case R_NDS32_SDA19S0_RELA
:
6105 case R_NDS32_SDA15S3_RELA
:
6106 case R_NDS32_SDA15S2_RELA
:
6107 case R_NDS32_SDA12S2_DP_RELA
:
6108 case R_NDS32_SDA12S2_SP_RELA
:
6109 case R_NDS32_SDA15S1_RELA
:
6110 case R_NDS32_SDA15S0_RELA
:
6111 case R_NDS32_SDA_FP7U2_RELA
:
6112 case R_NDS32_9_PLTREL
:
6113 case R_NDS32_25_PLTREL
:
6115 case R_NDS32_GOT_HI20
:
6116 case R_NDS32_GOT_LO12
:
6117 case R_NDS32_GOT_LO15
:
6118 case R_NDS32_GOT_LO19
:
6119 case R_NDS32_GOT15S2_RELA
:
6120 case R_NDS32_GOT17S2_RELA
:
6121 case R_NDS32_GOTPC20
:
6122 case R_NDS32_GOTPC_HI20
:
6123 case R_NDS32_GOTPC_LO12
:
6124 case R_NDS32_GOTOFF
:
6125 case R_NDS32_GOTOFF_HI20
:
6126 case R_NDS32_GOTOFF_LO12
:
6127 case R_NDS32_GOTOFF_LO15
:
6128 case R_NDS32_GOTOFF_LO19
:
6129 case R_NDS32_PLTREL_HI20
:
6130 case R_NDS32_PLTREL_LO12
:
6131 case R_NDS32_PLT_GOTREL_HI20
:
6132 case R_NDS32_PLT_GOTREL_LO12
:
6133 case R_NDS32_PLT_GOTREL_LO15
:
6134 case R_NDS32_PLT_GOTREL_LO19
:
6135 case R_NDS32_PLT_GOTREL_LO20
:
6136 case R_NDS32_17IFC_PCREL_RELA
:
6137 case R_NDS32_10IFCU_PCREL_RELA
:
6138 case R_NDS32_TLS_LE_HI20
:
6139 case R_NDS32_TLS_LE_LO12
:
6140 case R_NDS32_TLS_IE_HI20
:
6141 case R_NDS32_TLS_IE_LO12S2
:
6142 case R_NDS32_TLS_LE_20
:
6143 case R_NDS32_TLS_LE_15S0
:
6144 case R_NDS32_TLS_LE_15S1
:
6145 case R_NDS32_TLS_LE_15S2
:
6146 case R_NDS32_TLS_DESC_HI20
:
6147 case R_NDS32_TLS_DESC_LO12
:
6148 case R_NDS32_TLS_IE_LO12
:
6149 case R_NDS32_TLS_IEGP_HI20
:
6150 case R_NDS32_TLS_IEGP_LO12
:
6151 case R_NDS32_TLS_IEGP_LO12S2
:
6152 /* Instruction related relocs must handle endian properly. */
6153 /* NOTE: PIC IS NOT HANDLE YET; DO IT LATER. */
6154 r
= nds32_elf_final_link_relocate (howto
, input_bfd
,
6155 input_section
, contents
,
6156 rel
->r_offset
, relocation
,
6161 /* All other relocs can use default handler. */
6162 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6163 contents
, rel
->r_offset
,
6164 relocation
, rel
->r_addend
);
6170 if (r
!= bfd_reloc_ok
)
6172 /* FIXME: This should be generic enough to go in a utility. */
6176 name
= h
->root
.root
.string
;
6179 name
= bfd_elf_string_from_elf_section
6180 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
6181 if (name
== NULL
|| *name
== '\0')
6182 name
= bfd_section_name (input_bfd
, sec
);
6190 case bfd_reloc_overflow
:
6191 (*info
->callbacks
->reloc_overflow
)
6192 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
6193 (bfd_vma
) 0, input_bfd
, input_section
, offset
);
6196 case bfd_reloc_undefined
:
6197 (*info
->callbacks
->undefined_symbol
)
6198 (info
, name
, input_bfd
, input_section
, offset
, TRUE
);
6201 case bfd_reloc_outofrange
:
6202 errmsg
= _("internal error: out of range error");
6205 case bfd_reloc_notsupported
:
6206 errmsg
= _("internal error: unsupported relocation error");
6209 case bfd_reloc_dangerous
:
6210 errmsg
= _("internal error: dangerous error");
6214 errmsg
= _("internal error: unknown error");
6218 (*info
->callbacks
->warning
) (info
, errmsg
, name
, input_bfd
,
6219 input_section
, offset
);
6225 /* Resotre header size to avoid overflow load. */
6226 if (elf_nds32_tdata (input_bfd
)->hdr_size
!= 0)
6227 symtab_hdr
->sh_size
= elf_nds32_tdata (input_bfd
)->hdr_size
;
6232 /* Finish up dynamic symbol handling. We set the contents of various
6233 dynamic sections here. */
6236 nds32_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6237 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
)
6239 struct elf_link_hash_table
*ehtab
;
6240 struct elf_nds32_link_hash_entry
*hent
;
6243 ehtab
= elf_hash_table (info
);
6244 hent
= (struct elf_nds32_link_hash_entry
*) h
;
6246 if (h
->plt
.offset
!= (bfd_vma
) - 1)
6254 bfd_vma local_plt_offset
;
6255 Elf_Internal_Rela rela
;
6257 /* This symbol has an entry in the procedure linkage table. Set
6260 BFD_ASSERT (h
->dynindx
!= -1);
6263 sgot
= ehtab
->sgotplt
;
6264 srela
= ehtab
->srelplt
;
6265 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
6267 /* Get the index in the procedure linkage table which
6268 corresponds to this symbol. This is the index of this symbol
6269 in all the symbols for which we are making plt entries. The
6270 first entry in the procedure linkage table is reserved. */
6271 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
6273 /* Get the offset into the .got table of the entry that
6274 corresponds to this function. Each .got entry is 4 bytes.
6275 The first three are reserved. */
6276 got_offset
= (plt_index
+ 3) * 4;
6278 /* Fill in the entry in the procedure linkage table. */
6279 if (!bfd_link_pic (info
))
6283 insn
= PLT_ENTRY_WORD0
+ (((sgot
->output_section
->vma
6284 + sgot
->output_offset
+ got_offset
) >> 12)
6286 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
6288 insn
= PLT_ENTRY_WORD1
+ (((sgot
->output_section
->vma
6289 + sgot
->output_offset
+ got_offset
) & 0x0fff)
6291 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
6293 insn
= PLT_ENTRY_WORD2
;
6294 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
6296 insn
= PLT_ENTRY_WORD3
+ (plt_index
& 0x7ffff);
6297 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
6299 insn
= PLT_ENTRY_WORD4
6300 + (((unsigned int) ((-(h
->plt
.offset
+ 16)) >> 1)) & 0xffffff);
6301 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
6302 local_plt_offset
= 12;
6306 /* sda_base must be set at this time. */
6310 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ got_offset
6311 - elf_gp (output_bfd
);
6312 insn
= PLT_PIC_ENTRY_WORD0
+ ((offset
>> 12) & 0xfffff);
6313 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
6315 insn
= PLT_PIC_ENTRY_WORD1
+ (offset
& 0xfff);
6316 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
6318 insn
= PLT_PIC_ENTRY_WORD2
;
6319 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
6321 insn
= PLT_PIC_ENTRY_WORD3
;
6322 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
6324 insn
= PLT_PIC_ENTRY_WORD4
+ (plt_index
& 0x7fffff);
6325 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
6327 insn
= PLT_PIC_ENTRY_WORD5
6328 + (((unsigned int) ((-(h
->plt
.offset
+ 20)) >> 1)) & 0xffffff);
6329 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 20);
6331 local_plt_offset
= 16;
6334 /* Fill in the entry in the global offset table,
6335 so it will fall through to the next instruction for the first time. */
6336 bfd_put_32 (output_bfd
,
6337 (splt
->output_section
->vma
+ splt
->output_offset
6338 + h
->plt
.offset
+ local_plt_offset
),
6339 sgot
->contents
+ got_offset
);
6341 /* Fill in the entry in the .rela.plt section. */
6342 rela
.r_offset
= (sgot
->output_section
->vma
6343 + sgot
->output_offset
+ got_offset
);
6344 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_JMP_SLOT
);
6346 loc
= srela
->contents
;
6347 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
6348 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6350 if (!h
->def_regular
)
6352 /* Mark the symbol as undefined, rather than as defined in
6353 the .plt section. Leave the value alone. */
6354 sym
->st_shndx
= SHN_UNDEF
;
6355 if (!h
->ref_regular_nonweak
)
6360 if (h
->got
.offset
!= (bfd_vma
) - 1
6361 && hent
->tls_type
== GOT_NORMAL
)
6365 Elf_Internal_Rela rela
;
6367 /* This symbol has an entry in the global offset table.
6371 srelagot
= ehtab
->srelgot
;
6372 BFD_ASSERT (sgot
!= NULL
&& srelagot
!= NULL
);
6374 rela
.r_offset
= (sgot
->output_section
->vma
6375 + sgot
->output_offset
+ (h
->got
.offset
& ~1));
6377 /* If this is a -Bsymbolic link, and the symbol is defined
6378 locally, we just want to emit a RELATIVE reloc. Likewise if
6379 the symbol was forced to be local because of a version file.
6380 The entry in the global offset table will already have been
6381 initialized in the relocate_section function. */
6382 if ((bfd_link_pic (info
)
6383 && (info
->symbolic
|| h
->dynindx
== -1 || h
->forced_local
)
6385 || (bfd_link_pie (info
) && h
->def_regular
))
6387 rela
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
6388 rela
.r_addend
= (h
->root
.u
.def
.value
6389 + h
->root
.u
.def
.section
->output_section
->vma
6390 + h
->root
.u
.def
.section
->output_offset
);
6392 if ((h
->got
.offset
& 1) == 0)
6394 bfd_put_32 (output_bfd
, rela
.r_addend
,
6395 sgot
->contents
+ h
->got
.offset
);
6400 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6401 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
6402 sgot
->contents
+ h
->got
.offset
);
6403 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_GLOB_DAT
);
6407 loc
= srelagot
->contents
;
6408 loc
+= srelagot
->reloc_count
* sizeof (Elf32_External_Rela
);
6409 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6410 ++srelagot
->reloc_count
;
6411 BFD_ASSERT (loc
< (srelagot
->contents
+ srelagot
->size
));
6417 Elf_Internal_Rela rela
;
6419 /* This symbols needs a copy reloc. Set it up. */
6421 BFD_ASSERT (h
->dynindx
!= -1
6422 && (h
->root
.type
== bfd_link_hash_defined
6423 || h
->root
.type
== bfd_link_hash_defweak
));
6425 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
, ".rela.bss");
6426 BFD_ASSERT (s
!= NULL
);
6428 rela
.r_offset
= (h
->root
.u
.def
.value
6429 + h
->root
.u
.def
.section
->output_section
->vma
6430 + h
->root
.u
.def
.section
->output_offset
);
6431 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_COPY
);
6434 loc
+= s
->reloc_count
* sizeof (Elf32_External_Rela
);
6435 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6439 /* Mark some specially defined symbols as absolute. */
6440 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6441 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
6442 sym
->st_shndx
= SHN_ABS
;
6448 /* Finish up the dynamic sections. */
6451 nds32_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
6456 struct elf_link_hash_table
*ehtab
;
6457 struct elf_nds32_link_hash_table
*htab
;
6459 ehtab
= elf_hash_table (info
);
6460 htab
= nds32_elf_hash_table (info
);
6464 dynobj
= elf_hash_table (info
)->dynobj
;
6466 sgotplt
= ehtab
->sgotplt
;
6467 /* A broken linker script might have discarded the dynamic sections.
6468 Catch this here so that we do not seg-fault later on. */
6469 if (sgotplt
!= NULL
&& bfd_is_abs_section (sgotplt
->output_section
))
6471 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6473 if (elf_hash_table (info
)->dynamic_sections_created
)
6476 Elf32_External_Dyn
*dyncon
, *dynconend
;
6478 BFD_ASSERT (sgotplt
!= NULL
&& sdyn
!= NULL
);
6480 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6481 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6483 for (; dyncon
< dynconend
; dyncon
++)
6485 Elf_Internal_Dyn dyn
;
6488 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6496 /* name = ".got"; */
6497 s
= ehtab
->sgot
->output_section
;
6500 s
= ehtab
->srelplt
->output_section
;
6502 BFD_ASSERT (s
!= NULL
);
6503 dyn
.d_un
.d_ptr
= s
->vma
;
6504 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6508 s
= ehtab
->srelplt
->output_section
;
6509 BFD_ASSERT (s
!= NULL
);
6510 dyn
.d_un
.d_val
= s
->size
;
6511 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6515 /* My reading of the SVR4 ABI indicates that the
6516 procedure linkage table relocs (DT_JMPREL) should be
6517 included in the overall relocs (DT_RELA). This is
6518 what Solaris does. However, UnixWare can not handle
6519 that case. Therefore, we override the DT_RELASZ entry
6520 here to make it not include the JMPREL relocs. Since
6521 the linker script arranges for .rela.plt to follow all
6522 other relocation sections, we don't have to worry
6523 about changing the DT_RELA entry. */
6524 if (ehtab
->srelplt
!= NULL
)
6526 s
= ehtab
->srelplt
->output_section
;
6527 dyn
.d_un
.d_val
-= s
->size
;
6529 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6532 case DT_TLSDESC_PLT
:
6533 s
= htab
->root
.splt
;
6534 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
6535 + htab
->dt_tlsdesc_plt
);
6536 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6539 case DT_TLSDESC_GOT
:
6540 s
= htab
->root
.sgot
;
6541 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
6542 + htab
->dt_tlsdesc_got
);
6543 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6548 /* Fill in the first entry in the procedure linkage table. */
6550 if (splt
&& splt
->size
> 0)
6552 if (bfd_link_pic (info
))
6557 offset
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
+ 4
6558 - elf_gp (output_bfd
);
6559 insn
= PLT0_PIC_ENTRY_WORD0
| ((offset
>> 12) & 0xfffff);
6560 bfd_putb32 (insn
, splt
->contents
);
6562 /* here has a typo? */
6563 insn
= PLT0_PIC_ENTRY_WORD1
| (offset
& 0xfff);
6564 bfd_putb32 (insn
, splt
->contents
+ 4);
6566 insn
= PLT0_PIC_ENTRY_WORD2
;
6567 bfd_putb32 (insn
, splt
->contents
+ 8);
6569 insn
= PLT0_PIC_ENTRY_WORD3
;
6570 bfd_putb32 (insn
, splt
->contents
+ 12);
6572 insn
= PLT0_PIC_ENTRY_WORD4
;
6573 bfd_putb32 (insn
, splt
->contents
+ 16);
6575 insn
= PLT0_PIC_ENTRY_WORD5
;
6576 bfd_putb32 (insn
, splt
->contents
+ 20);
6583 /* addr = .got + 4 */
6584 addr
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
+ 4;
6585 insn
= PLT0_ENTRY_WORD0
| ((addr
>> 12) & 0xfffff);
6586 bfd_putb32 (insn
, splt
->contents
);
6588 insn
= PLT0_ENTRY_WORD1
| (addr
& 0x0fff);
6589 bfd_putb32 (insn
, splt
->contents
+ 4);
6591 insn
= PLT0_ENTRY_WORD2
;
6592 bfd_putb32 (insn
, splt
->contents
+ 8);
6594 insn
= PLT0_ENTRY_WORD3
;
6595 bfd_putb32 (insn
, splt
->contents
+ 12);
6597 insn
= PLT0_ENTRY_WORD4
;
6598 bfd_putb32 (insn
, splt
->contents
+ 16);
6601 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
6605 if (htab
->dt_tlsdesc_plt
)
6607 /* Calculate addresses. */
6608 asection
*sgot
= sgot
= ehtab
->sgot
;
6609 bfd_vma pltgot
= sgotplt
->output_section
->vma
6610 + sgotplt
->output_offset
;
6611 bfd_vma tlsdesc_got
= sgot
->output_section
->vma
+ sgot
->output_offset
6612 + htab
->dt_tlsdesc_got
;
6614 /* Get GP offset. */
6615 pltgot
-= elf_gp (output_bfd
) - 4; /* PLTGOT[1] */
6616 tlsdesc_got
-= elf_gp (output_bfd
);
6618 /* Do relocation. */
6619 dl_tlsdesc_lazy_trampoline
[0] += ((1 << 20) - 1) & (tlsdesc_got
>> 12);
6620 dl_tlsdesc_lazy_trampoline
[1] += 0xfff & tlsdesc_got
;
6621 dl_tlsdesc_lazy_trampoline
[4] += ((1 << 20) - 1) & (pltgot
>> 12);
6622 dl_tlsdesc_lazy_trampoline
[5] += 0xfff & pltgot
;
6625 nds32_put_trampoline (splt
->contents
+ htab
->dt_tlsdesc_plt
,
6626 dl_tlsdesc_lazy_trampoline
,
6627 ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
));
6631 /* Fill in the first three entries in the global offset table. */
6632 if (sgotplt
&& sgotplt
->size
> 0)
6635 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
);
6637 bfd_put_32 (output_bfd
,
6638 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6640 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 4);
6641 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 8);
6643 elf_section_data (sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
6650 /* Set the right machine number. */
6653 nds32_elf_object_p (bfd
*abfd
)
6655 static unsigned int cur_arch
= 0;
6657 if (E_N1_ARCH
!= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
))
6659 /* E_N1_ARCH is a wild card, so it is set only when no others exist. */
6660 cur_arch
= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
);
6667 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1
);
6670 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h
);
6672 case E_NDS_ARCH_STAR_V2_0
:
6673 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v2
);
6675 case E_NDS_ARCH_STAR_V3_0
:
6676 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3
);
6678 case E_NDS_ARCH_STAR_V3_M
:
6679 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3m
);
6686 /* Store the machine number in the flags field. */
6689 nds32_elf_final_write_processing (bfd
*abfd
,
6690 bfd_boolean linker ATTRIBUTE_UNUSED
)
6693 static unsigned int cur_mach
= 0;
6695 if (bfd_mach_n1
!= bfd_get_mach (abfd
))
6697 cur_mach
= bfd_get_mach (abfd
);
6703 /* Only happen when object is empty, since the case is abandon. */
6705 val
|= E_NDS_ABI_AABI
;
6706 val
|= E_NDS32_ELF_VER_1_4
;
6711 case bfd_mach_n1h_v2
:
6712 val
= E_NDS_ARCH_STAR_V2_0
;
6714 case bfd_mach_n1h_v3
:
6715 val
= E_NDS_ARCH_STAR_V3_0
;
6717 case bfd_mach_n1h_v3m
:
6718 val
= E_NDS_ARCH_STAR_V3_M
;
6725 elf_elfheader (abfd
)->e_flags
&= ~EF_NDS_ARCH
;
6726 elf_elfheader (abfd
)->e_flags
|= val
;
6729 /* Function to keep NDS32 specific file flags. */
6732 nds32_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6734 BFD_ASSERT (!elf_flags_init (abfd
)
6735 || elf_elfheader (abfd
)->e_flags
== flags
);
6737 elf_elfheader (abfd
)->e_flags
= flags
;
6738 elf_flags_init (abfd
) = TRUE
;
6743 convert_e_flags (unsigned int e_flags
, unsigned int arch
)
6745 if ((e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
)
6747 /* From 0.9 to 1.0. */
6748 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V1_0
;
6750 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6751 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
6752 if (arch
== E_NDS_ARCH_STAR_V1_0
)
6759 /* From 1.0 to 2.0. */
6760 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V2_0
;
6762 /* Clear E_NDS32_HAS_MFUSR_PC_INST. */
6763 e_flags
&= ~E_NDS32_HAS_MFUSR_PC_INST
;
6765 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6766 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
6771 nds32_check_vec_size (bfd
*ibfd
)
6773 static unsigned int nds32_vec_size
= 0;
6775 asection
*sec_t
= NULL
;
6776 bfd_byte
*contents
= NULL
;
6778 sec_t
= bfd_get_section_by_name (ibfd
, ".nds32_e_flags");
6780 if (sec_t
&& sec_t
->size
>= 4)
6782 /* Get vec_size in file. */
6783 unsigned int flag_t
;
6785 nds32_get_section_contents (ibfd
, sec_t
, &contents
, TRUE
);
6786 flag_t
= bfd_get_32 (ibfd
, contents
);
6788 /* The value could only be 4 or 16. */
6790 if (!nds32_vec_size
)
6791 /* Set if not set yet. */
6792 nds32_vec_size
= (flag_t
& 0x3);
6793 else if (nds32_vec_size
!= (flag_t
& 0x3))
6796 /* xgettext:c-format */
6797 (_("%pB: ISR vector size mismatch"
6798 " with previous modules, previous %u-byte, current %u-byte"),
6800 nds32_vec_size
== 1 ? 4 : nds32_vec_size
== 2 ? 16 : 0xffffffff,
6801 (flag_t
& 0x3) == 1 ? 4 : (flag_t
& 0x3) == 2 ? 16 : 0xffffffff);
6805 /* Only keep the first vec_size section. */
6806 sec_t
->flags
|= SEC_EXCLUDE
;
6812 /* Merge backend specific data from an object file to the output
6813 object file when linking. */
6816 nds32_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6818 bfd
*obfd
= info
->output_bfd
;
6821 flagword out_16regs
;
6823 flagword out_no_mac
;
6825 flagword out_version
;
6826 flagword in_version
;
6827 flagword out_fpu_config
;
6828 flagword in_fpu_config
;
6830 /* TODO: Revise to use object-attributes instead. */
6831 if (!nds32_check_vec_size (ibfd
))
6834 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6835 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6838 if (bfd_little_endian (ibfd
) != bfd_little_endian (obfd
))
6841 (_("%pB: warning: endian mismatch with previous modules"), ibfd
);
6843 bfd_set_error (bfd_error_bad_value
);
6847 /* -B option in objcopy cannot work as expected. e_flags = 0 shall be
6848 treat as generic one without checking and merging. */
6849 if (elf_elfheader (ibfd
)->e_flags
)
6851 in_version
= elf_elfheader (ibfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
6852 if (in_version
== E_NDS32_ELF_VER_1_2
)
6855 (_("%pB: warning: older version of object file encountered, "
6856 "please recompile with current tool chain"), ibfd
);
6859 /* We may need to merge V1 and V2 arch object files to V2. */
6860 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6861 != (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
6863 /* Need to convert version. */
6864 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6865 == E_NDS_ARCH_STAR_RESERVED
)
6867 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6869 else if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6870 == E_NDS_ARCH_STAR_V3_M
6871 && (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
)
6872 == E_NDS_ARCH_STAR_V3_0
)
6874 elf_elfheader (ibfd
)->e_flags
=
6875 (elf_elfheader (ibfd
)->e_flags
& (~EF_NDS_ARCH
))
6876 | E_NDS_ARCH_STAR_V3_0
;
6878 else if ((elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
)
6879 == E_NDS_ARCH_STAR_V0_9
6880 || (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6881 > (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
6883 elf_elfheader (obfd
)->e_flags
=
6884 convert_e_flags (elf_elfheader (obfd
)->e_flags
,
6885 (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
));
6889 elf_elfheader (ibfd
)->e_flags
=
6890 convert_e_flags (elf_elfheader (ibfd
)->e_flags
,
6891 (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
));
6895 /* Extract some flags. */
6896 in_flags
= elf_elfheader (ibfd
)->e_flags
6897 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
6898 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
6900 /* The following flags need special treatment. */
6901 in_16regs
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
6902 in_no_mac
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
6903 in_fpu_config
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
6905 /* Extract some flags. */
6906 out_flags
= elf_elfheader (obfd
)->e_flags
6907 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
6908 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
6910 /* The following flags need special treatment. */
6911 out_16regs
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
6912 out_no_mac
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
6913 out_fpu_config
= elf_elfheader (obfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
6914 out_version
= elf_elfheader (obfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
6915 if (!elf_flags_init (obfd
))
6917 /* If the input is the default architecture then do not
6918 bother setting the flags for the output architecture,
6919 instead allow future merges to do this. If no future
6920 merges ever set these flags then they will retain their
6921 unitialised values, which surprise surprise, correspond
6922 to the default values. */
6923 if (bfd_get_arch_info (ibfd
)->the_default
)
6926 elf_flags_init (obfd
) = TRUE
;
6927 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6929 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6930 && bfd_get_arch_info (obfd
)->the_default
)
6932 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6933 bfd_get_mach (ibfd
));
6939 /* Check flag compatibility. */
6940 if ((in_flags
& EF_NDS_ABI
) != (out_flags
& EF_NDS_ABI
))
6943 (_("%pB: error: ABI mismatch with previous modules"), ibfd
);
6944 bfd_set_error (bfd_error_bad_value
);
6948 if ((in_flags
& EF_NDS_ARCH
) != (out_flags
& EF_NDS_ARCH
))
6950 if (((in_flags
& EF_NDS_ARCH
) != E_N1_ARCH
))
6953 (_("%pB: error: instruction set mismatch with previous modules"),
6956 bfd_set_error (bfd_error_bad_value
);
6961 /* When linking with V1.2 and V1.3 objects together the output is V1.2.
6962 and perf ext1 and DIV are mergerd to perf ext1. */
6963 if (in_version
== E_NDS32_ELF_VER_1_2
|| out_version
== E_NDS32_ELF_VER_1_2
)
6965 elf_elfheader (obfd
)->e_flags
=
6966 (in_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6967 | (out_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6968 | (((in_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6969 ? E_NDS32_HAS_EXT_INST
: 0)
6970 | (((out_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6971 ? E_NDS32_HAS_EXT_INST
: 0)
6972 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6973 | ((in_version
> out_version
) ? out_version
: in_version
);
6977 if (in_version
!= out_version
)
6979 /* xgettext:c-format */
6980 (_("%pB: warning: incompatible elf-versions %s and %s"),
6981 ibfd
, nds32_elfver_strtab
[out_version
],
6982 nds32_elfver_strtab
[in_version
]);
6984 elf_elfheader (obfd
)->e_flags
= in_flags
| out_flags
6985 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6986 | (in_fpu_config
> out_fpu_config
? in_fpu_config
: out_fpu_config
)
6987 | (in_version
> out_version
? out_version
: in_version
);
6994 /* Display the flags field. */
6997 nds32_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6999 FILE *file
= (FILE *) ptr
;
7001 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7003 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7005 fprintf (file
, _("private flags = %lx"), elf_elfheader (abfd
)->e_flags
);
7007 switch (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
)
7011 fprintf (file
, _(": n1 instructions"));
7014 fprintf (file
, _(": n1h instructions"));
7024 nds32_elf_action_discarded (asection
*sec
)
7028 (".gcc_except_table", sec
->name
, sizeof (".gcc_except_table") - 1) == 0)
7031 return _bfd_elf_default_action_discarded (sec
);
7035 nds32_elf_gc_mark_hook (asection
*sec
, struct bfd_link_info
*info
,
7036 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
7037 Elf_Internal_Sym
*sym
)
7040 switch (ELF32_R_TYPE (rel
->r_info
))
7042 case R_NDS32_GNU_VTINHERIT
:
7043 case R_NDS32_GNU_VTENTRY
:
7044 case R_NDS32_RELA_GNU_VTINHERIT
:
7045 case R_NDS32_RELA_GNU_VTENTRY
:
7049 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
7052 static enum elf_nds32_tls_type
7053 get_tls_type (enum elf_nds32_reloc_type r_type
,
7054 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
7056 enum elf_nds32_tls_type tls_type
;
7060 case R_NDS32_TLS_LE_HI20
:
7061 case R_NDS32_TLS_LE_LO12
:
7062 tls_type
= GOT_TLS_LE
;
7064 case R_NDS32_TLS_IE_HI20
:
7065 case R_NDS32_TLS_IE_LO12S2
:
7066 case R_NDS32_TLS_IE_LO12
:
7067 tls_type
= GOT_TLS_IE
;
7069 case R_NDS32_TLS_IEGP_HI20
:
7070 case R_NDS32_TLS_IEGP_LO12
:
7071 case R_NDS32_TLS_IEGP_LO12S2
:
7072 tls_type
= GOT_TLS_IEGP
;
7074 case R_NDS32_TLS_DESC_HI20
:
7075 case R_NDS32_TLS_DESC_LO12
:
7076 case R_NDS32_TLS_DESC_ADD
:
7077 case R_NDS32_TLS_DESC_FUNC
:
7078 case R_NDS32_TLS_DESC_CALL
:
7079 tls_type
= GOT_TLS_DESC
;
7082 tls_type
= GOT_NORMAL
;
7089 /* Ensure that we have allocated bookkeeping structures for ABFD's local
7093 elf32_nds32_allocate_local_sym_info (bfd
*abfd
)
7095 if (elf_local_got_refcounts (abfd
) == NULL
)
7097 bfd_size_type num_syms
;
7101 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
7102 /* This space is for got_refcounts, got_tls_type, tlsdesc_gotent, and
7103 gp_offset. The details can refer to struct elf_nds32_obj_tdata. */
7104 size
= num_syms
* (sizeof (bfd_signed_vma
) + sizeof (char)
7105 + sizeof (bfd_vma
) + sizeof (int)
7106 + sizeof (bfd_boolean
) + sizeof (bfd_vma
));
7107 data
= bfd_zalloc (abfd
, size
);
7111 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
7112 data
+= num_syms
* sizeof (bfd_signed_vma
);
7114 elf32_nds32_local_got_tls_type (abfd
) = (char *) data
;
7115 data
+= num_syms
* sizeof (char);
7117 elf32_nds32_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
7118 data
+= num_syms
* sizeof (bfd_vma
);
7120 elf32_nds32_local_gp_offset (abfd
) = (int *) data
;
7121 data
+= num_syms
* sizeof (int);
7127 /* Look through the relocs for a section during the first phase.
7128 Since we don't do .gots or .plts, we just need to consider the
7129 virtual table relocs for gc. */
7132 nds32_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7133 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7135 Elf_Internal_Shdr
*symtab_hdr
;
7136 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
7137 const Elf_Internal_Rela
*rel
;
7138 const Elf_Internal_Rela
*rel_end
;
7139 struct elf_link_hash_table
*ehtab
;
7140 struct elf_nds32_link_hash_table
*htab
;
7142 asection
*sreloc
= NULL
;
7144 /* No need for relocation if relocatable already. */
7145 if (bfd_link_relocatable (info
))
7147 elf32_nds32_check_relax_group (abfd
, sec
);
7151 /* Don't do anything special with non-loaded, non-alloced sections.
7152 In particular, any relocs in such sections should not affect GOT
7153 and PLT reference counting (ie. we don't allow them to create GOT
7154 or PLT entries), there's no possibility or desire to optimize TLS
7155 relocs, and there's not much point in propagating relocs to shared
7156 libs that the dynamic linker won't relocate. */
7157 if ((sec
->flags
& SEC_ALLOC
) == 0)
7160 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7161 sym_hashes
= elf_sym_hashes (abfd
);
7163 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
7164 if (!elf_bad_symtab (abfd
))
7165 sym_hashes_end
-= symtab_hdr
->sh_info
;
7167 ehtab
= elf_hash_table (info
);
7168 htab
= nds32_elf_hash_table (info
);
7169 dynobj
= htab
->root
.dynobj
;
7171 rel_end
= relocs
+ sec
->reloc_count
;
7172 for (rel
= relocs
; rel
< rel_end
; rel
++)
7174 enum elf_nds32_reloc_type r_type
;
7175 struct elf_link_hash_entry
*h
;
7176 unsigned long r_symndx
;
7177 enum elf_nds32_tls_type tls_type
, old_tls_type
;
7179 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7180 r_type
= ELF32_R_TYPE (rel
->r_info
);
7181 if (r_symndx
< symtab_hdr
->sh_info
)
7185 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7186 while (h
->root
.type
== bfd_link_hash_indirect
7187 || h
->root
.type
== bfd_link_hash_warning
)
7188 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7191 /* Create .got section if necessary.
7192 Some relocs require a global offset table. We create
7193 got section here, since these relocation need a got section
7194 and if it is not created yet. */
7195 if (ehtab
->sgot
== NULL
)
7199 case R_NDS32_GOT_HI20
:
7200 case R_NDS32_GOT_LO12
:
7201 case R_NDS32_GOT_LO15
:
7202 case R_NDS32_GOT_LO19
:
7203 case R_NDS32_GOT17S2_RELA
:
7204 case R_NDS32_GOT15S2_RELA
:
7205 case R_NDS32_GOTOFF
:
7206 case R_NDS32_GOTOFF_HI20
:
7207 case R_NDS32_GOTOFF_LO12
:
7208 case R_NDS32_GOTOFF_LO15
:
7209 case R_NDS32_GOTOFF_LO19
:
7210 case R_NDS32_GOTPC20
:
7211 case R_NDS32_GOTPC_HI20
:
7212 case R_NDS32_GOTPC_LO12
:
7214 case R_NDS32_TLS_IE_HI20
:
7215 case R_NDS32_TLS_IE_LO12
:
7216 case R_NDS32_TLS_IE_LO12S2
:
7217 case R_NDS32_TLS_IEGP_HI20
:
7218 case R_NDS32_TLS_IEGP_LO12
:
7219 case R_NDS32_TLS_IEGP_LO12S2
:
7220 case R_NDS32_TLS_DESC_HI20
:
7221 case R_NDS32_TLS_DESC_LO12
:
7223 htab
->root
.dynobj
= dynobj
= abfd
;
7224 if (!create_got_section (dynobj
, info
))
7233 /* Check relocation type. */
7234 switch ((int) r_type
)
7236 case R_NDS32_GOT_HI20
:
7237 case R_NDS32_GOT_LO12
:
7238 case R_NDS32_GOT_LO15
:
7239 case R_NDS32_GOT_LO19
:
7241 case R_NDS32_TLS_LE_HI20
:
7242 case R_NDS32_TLS_LE_LO12
:
7243 case R_NDS32_TLS_IE_HI20
:
7244 case R_NDS32_TLS_IE_LO12
:
7245 case R_NDS32_TLS_IE_LO12S2
:
7246 case R_NDS32_TLS_IEGP_HI20
:
7247 case R_NDS32_TLS_IEGP_LO12
:
7248 case R_NDS32_TLS_IEGP_LO12S2
:
7249 case R_NDS32_TLS_DESC_HI20
:
7250 case R_NDS32_TLS_DESC_LO12
:
7251 tls_type
= get_tls_type (r_type
, h
);
7254 if (tls_type
!= GOT_TLS_LE
)
7255 h
->got
.refcount
+= 1;
7256 old_tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
7260 /* This is a global offset table entry for a local symbol. */
7261 if (!elf32_nds32_allocate_local_sym_info (abfd
))
7264 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7265 if (tls_type
!= GOT_TLS_LE
)
7266 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
7267 old_tls_type
= elf32_nds32_local_got_tls_type (abfd
)[r_symndx
];
7270 /* We would already have issued an error message if there
7271 is a TLS/non-TLS mismatch, based on the symbol
7272 type. So just combine any TLS types needed. */
7273 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
7274 && tls_type
!= GOT_NORMAL
)
7275 tls_type
|= old_tls_type
;
7277 /* DESC to IE/IEGP if link to executable. */
7278 if ((tls_type
& (GOT_TLS_DESC
| GOT_TLS_IEGP
))
7279 && (bfd_link_executable (info
)))
7280 tls_type
|= (bfd_link_pie (info
) ? GOT_TLS_IEGP
: GOT_TLS_IE
);
7282 if (old_tls_type
!= tls_type
)
7285 elf32_nds32_hash_entry (h
)->tls_type
= tls_type
;
7287 elf32_nds32_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
7290 case R_NDS32_9_PLTREL
:
7291 case R_NDS32_25_PLTREL
:
7292 case R_NDS32_PLTREL_HI20
:
7293 case R_NDS32_PLTREL_LO12
:
7294 case R_NDS32_PLT_GOTREL_HI20
:
7295 case R_NDS32_PLT_GOTREL_LO12
:
7296 case R_NDS32_PLT_GOTREL_LO15
:
7297 case R_NDS32_PLT_GOTREL_LO19
:
7298 case R_NDS32_PLT_GOTREL_LO20
:
7300 /* This symbol requires a procedure linkage table entry. We
7301 actually build the entry in adjust_dynamic_symbol,
7302 because this might be a case of linking PIC code without
7303 linking in any dynamic objects, in which case we don't
7304 need to generate a procedure linkage table after all. */
7306 /* If this is a local symbol, we resolve it directly without
7307 creating a procedure linkage table entry. */
7312 || (bfd_link_pie (info
) && h
->def_regular
))
7315 elf32_nds32_hash_entry (h
)->tls_type
= GOT_NORMAL
;
7317 h
->plt
.refcount
+= 1;
7320 case R_NDS32_16_RELA
:
7321 case R_NDS32_20_RELA
:
7322 case R_NDS32_5_RELA
:
7323 case R_NDS32_32_RELA
:
7324 case R_NDS32_HI20_RELA
:
7325 case R_NDS32_LO12S3_RELA
:
7326 case R_NDS32_LO12S2_RELA
:
7327 case R_NDS32_LO12S2_DP_RELA
:
7328 case R_NDS32_LO12S2_SP_RELA
:
7329 case R_NDS32_LO12S1_RELA
:
7330 case R_NDS32_LO12S0_RELA
:
7331 case R_NDS32_LO12S0_ORI_RELA
:
7332 case R_NDS32_SDA16S3_RELA
:
7333 case R_NDS32_SDA17S2_RELA
:
7334 case R_NDS32_SDA18S1_RELA
:
7335 case R_NDS32_SDA19S0_RELA
:
7336 case R_NDS32_SDA15S3_RELA
:
7337 case R_NDS32_SDA15S2_RELA
:
7338 case R_NDS32_SDA12S2_DP_RELA
:
7339 case R_NDS32_SDA12S2_SP_RELA
:
7340 case R_NDS32_SDA15S1_RELA
:
7341 case R_NDS32_SDA15S0_RELA
:
7342 case R_NDS32_SDA_FP7U2_RELA
:
7343 case R_NDS32_15_PCREL_RELA
:
7344 case R_NDS32_17_PCREL_RELA
:
7345 case R_NDS32_25_PCREL_RELA
:
7347 if (h
!= NULL
&& !bfd_link_pic (info
))
7350 h
->plt
.refcount
+= 1;
7353 /* If we are creating a shared library, and this is a reloc against
7354 a global symbol, or a non PC relative reloc against a local
7355 symbol, then we need to copy the reloc into the shared library.
7356 However, if we are linking with -Bsymbolic, we do not need to
7357 copy a reloc against a global symbol which is defined in an
7358 object we are including in the link (i.e., DEF_REGULAR is set).
7359 At this point we have not seen all the input files, so it is
7360 possible that DEF_REGULAR is not set now but will be set later
7361 (it is never cleared). We account for that possibility below by
7362 storing information in the dyn_relocs field of the hash table
7363 entry. A similar situation occurs when creating shared libraries
7364 and symbol visibility changes render the symbol local.
7366 If on the other hand, we are creating an executable, we may need
7367 to keep relocations for symbols satisfied by a dynamic library
7368 if we manage to avoid copy relocs for the symbol. */
7369 if ((bfd_link_pic (info
)
7370 && (sec
->flags
& SEC_ALLOC
) != 0
7371 && ((r_type
!= R_NDS32_25_PCREL_RELA
7372 && r_type
!= R_NDS32_15_PCREL_RELA
7373 && r_type
!= R_NDS32_17_PCREL_RELA
7374 && !(r_type
== R_NDS32_32_RELA
7375 && strcmp (sec
->name
, ".eh_frame") == 0))
7378 || h
->root
.type
== bfd_link_hash_defweak
7379 || !h
->def_regular
))))
7380 || (!bfd_link_pic (info
)
7381 && (sec
->flags
& SEC_ALLOC
) != 0
7383 && (h
->root
.type
== bfd_link_hash_defweak
7384 || !h
->def_regular
)))
7386 struct elf_dyn_relocs
*p
;
7387 struct elf_dyn_relocs
**head
;
7390 htab
->root
.dynobj
= dynobj
= abfd
;
7392 /* When creating a shared object, we must copy these
7393 relocs into the output file. We create a reloc
7394 section in dynobj and make room for the reloc. */
7399 name
= bfd_elf_string_from_elf_section
7400 (abfd
, elf_elfheader (abfd
)->e_shstrndx
,
7401 elf_section_data (sec
)->rela
.hdr
->sh_name
);
7405 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
7406 && strcmp (bfd_get_section_name (abfd
, sec
),
7409 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7414 sreloc
= bfd_make_section (dynobj
, name
);
7415 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
7416 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
7417 if ((sec
->flags
& SEC_ALLOC
) != 0)
7418 flags
|= SEC_ALLOC
| SEC_LOAD
;
7420 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
7421 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
7424 elf_section_type (sreloc
) = SHT_RELA
;
7426 elf_section_data (sec
)->sreloc
= sreloc
;
7429 /* If this is a global symbol, we count the number of
7430 relocations we need for this symbol. */
7432 head
= &((struct elf_nds32_link_hash_entry
*) h
)->dyn_relocs
;
7438 Elf_Internal_Sym
*isym
;
7439 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
7443 /* Track dynamic relocs needed for local syms too. */
7444 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7448 vpp
= &elf_section_data (s
)->local_dynrel
;
7449 head
= (struct elf_dyn_relocs
**) vpp
;
7453 if (p
== NULL
|| p
->sec
!= sec
)
7455 bfd_size_type amt
= sizeof (*p
);
7456 p
= (struct elf_dyn_relocs
*) bfd_alloc (dynobj
, amt
);
7468 /* Since eh_frame is readonly, R_NDS32_32_RELA
7469 reloc for eh_frame will cause shared library has
7470 TEXTREL entry in the dynamic section. This lead glibc
7471 testsuites to failure (bug-13092) and cause kernel fail
7472 (bug-11819). I think the best solution is to replace
7473 absolute reloc with pc relative reloc in the eh_frame.
7474 To do that, we need to support the following issues:
7477 * gcc/config/nds32/nds32.h: Define
7478 ASM_PREFERRED_EH_DATA_FORMAT to encode DW_EH_PE_pcrel
7479 and DW_EH_PE_sdata4 into DWARF exception header when
7480 option have '-fpic'.
7482 === For binutils ===
7483 * bfd/: Define new reloc R_NDS32_32_PCREL_RELA.
7484 * gas/config/tc-nds32.h: Define DIFF_EXPR_OK. This
7485 may break our nds DIFF mechanism, therefore, we
7486 must disable all linker relaxations to ensure
7488 * gas/config/tc-nds32.c (nds32_apply_fix): Replace
7489 R_NDS32_32_RELA with R_NDS32_32_PCREL_RELA, and
7490 do the necessary modification.
7492 Unfortunately, it still have some problems for nds32
7493 to support pc relative reloc in the eh_frame. So I use
7494 another solution to fix this issue.
7496 However, I find that ld always emit TEXTREL marker for
7497 R_NDS32_NONE relocs in rel.dyn. These none relocs are
7498 correspond to R_NDS32_32_RELA for .eh_frame section.
7499 It means that we always reserve redundant entries of rel.dyn
7500 for these relocs which actually do nothing in dynamic linker.
7502 Therefore, we regard these relocs as pc relative relocs
7503 here and increase the pc_count. */
7504 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_25_PCREL_RELA
7505 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_15_PCREL_RELA
7506 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_17_PCREL_RELA
7507 || (r_type
== R_NDS32_32_RELA
7508 && strcmp (sec
->name
, ".eh_frame") == 0))
7513 /* This relocation describes the C++ object vtable hierarchy.
7514 Reconstruct it for later use during GC. */
7515 case R_NDS32_RELA_GNU_VTINHERIT
:
7516 case R_NDS32_GNU_VTINHERIT
:
7517 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7521 /* This relocation describes which C++ vtable entries are actually
7522 used. Record for later use during GC. */
7523 case R_NDS32_GNU_VTENTRY
:
7524 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7527 case R_NDS32_RELA_GNU_VTENTRY
:
7528 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
7537 /* Write VAL in uleb128 format to P, returning a pointer to the
7539 This code is copied from elf-attr.c. */
7542 write_uleb128 (bfd_byte
*p
, unsigned int val
)
7557 static bfd_signed_vma
7558 calculate_offset (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
7559 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
7561 bfd_signed_vma foff
;
7562 bfd_vma symval
, addend
;
7565 /* Get the value of the symbol referred to by the reloc. */
7566 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
7568 Elf_Internal_Sym
*isym
;
7570 /* A local symbol. */
7571 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
7573 if (isym
->st_shndx
== SHN_UNDEF
)
7574 sym_sec
= bfd_und_section_ptr
;
7575 else if (isym
->st_shndx
== SHN_ABS
)
7576 sym_sec
= bfd_abs_section_ptr
;
7577 else if (isym
->st_shndx
== SHN_COMMON
)
7578 sym_sec
= bfd_com_section_ptr
;
7580 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7581 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
7582 + sym_sec
->output_offset
;
7587 struct elf_link_hash_entry
*h
;
7589 /* An external symbol. */
7590 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7591 h
= elf_sym_hashes (abfd
)[indx
];
7592 BFD_ASSERT (h
!= NULL
);
7594 if (h
->root
.type
!= bfd_link_hash_defined
7595 && h
->root
.type
!= bfd_link_hash_defweak
)
7596 /* This appears to be a reference to an undefined
7597 symbol. Just ignore it--it will be caught by the
7598 regular reloc processing. */
7601 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
7603 sym_sec
= h
->root
.u
.def
.section
;
7604 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
,
7605 elf_section_data (sym_sec
)->sec_info
,
7606 h
->root
.u
.def
.value
);
7607 symval
= symval
+ sym_sec
->output_section
->vma
7608 + sym_sec
->output_offset
;
7611 symval
= (h
->root
.u
.def
.value
7612 + h
->root
.u
.def
.section
->output_section
->vma
7613 + h
->root
.u
.def
.section
->output_offset
);
7616 addend
= irel
->r_addend
;
7618 foff
= (symval
+ addend
7619 - (irel
->r_offset
+ sec
->output_section
->vma
+ sec
->output_offset
));
7624 /* Convert a 32-bit instruction to 16-bit one.
7625 INSN is the input 32-bit instruction, INSN16 is the output 16-bit
7626 instruction. If INSN_TYPE is not NULL, it the CGEN instruction
7627 type of INSN16. Return 1 if successful. */
7630 nds32_convert_32_to_16_alu1 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7633 uint16_t insn16
= 0;
7635 unsigned long mach
= bfd_get_mach (abfd
);
7637 if (N32_SH5 (insn
) != 0)
7640 switch (N32_SUB5 (insn
))
7642 case N32_ALU1_ADD_SLLI
:
7643 case N32_ALU1_ADD_SRLI
:
7644 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
7646 insn16
= N16_TYPE333 (ADD333
, N32_RT5 (insn
), N32_RA5 (insn
),
7648 insn_type
= NDS32_INSN_ADD333
;
7650 else if (N32_IS_RT4 (insn
))
7652 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7653 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RB5 (insn
));
7654 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7655 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RA5 (insn
));
7656 insn_type
= NDS32_INSN_ADD45
;
7660 case N32_ALU1_SUB_SLLI
:
7661 case N32_ALU1_SUB_SRLI
:
7662 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
7664 insn16
= N16_TYPE333 (SUB333
, N32_RT5 (insn
), N32_RA5 (insn
),
7666 insn_type
= NDS32_INSN_SUB333
;
7668 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7670 insn16
= N16_TYPE45 (SUB45
, N32_RT54 (insn
), N32_RB5 (insn
));
7671 insn_type
= NDS32_INSN_SUB45
;
7675 case N32_ALU1_AND_SLLI
:
7676 case N32_ALU1_AND_SRLI
:
7677 /* and $rt, $rt, $rb -> and33 for v3, v3m. */
7678 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7679 && N32_IS_RB3 (insn
))
7681 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7682 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RB5 (insn
));
7683 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7684 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RA5 (insn
));
7686 insn_type
= NDS32_INSN_AND33
;
7690 case N32_ALU1_XOR_SLLI
:
7691 case N32_ALU1_XOR_SRLI
:
7692 /* xor $rt, $rt, $rb -> xor33 for v3, v3m. */
7693 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7694 && N32_IS_RB3 (insn
))
7696 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7697 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RB5 (insn
));
7698 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7699 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RA5 (insn
));
7701 insn_type
= NDS32_INSN_XOR33
;
7705 case N32_ALU1_OR_SLLI
:
7706 case N32_ALU1_OR_SRLI
:
7707 /* or $rt, $rt, $rb -> or33 for v3, v3m. */
7708 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7709 && N32_IS_RB3 (insn
))
7711 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7712 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RB5 (insn
));
7713 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7714 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RA5 (insn
));
7716 insn_type
= NDS32_INSN_OR33
;
7720 /* nor $rt, $ra, $ra -> not33 for v3, v3m. */
7721 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RB3 (insn
)
7722 && N32_RA5 (insn
) == N32_RB5 (insn
))
7724 insn16
= N16_MISC33 (NOT33
, N32_RT5 (insn
), N32_RA5 (insn
));
7725 insn_type
= NDS32_INSN_NOT33
;
7729 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7731 insn16
= N16_TYPE45 (SRAI45
, N32_RT54 (insn
), N32_UB5 (insn
));
7732 insn_type
= NDS32_INSN_SRAI45
;
7737 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7739 insn16
= N16_TYPE45 (SRLI45
, N32_RT54 (insn
), N32_UB5 (insn
));
7740 insn_type
= NDS32_INSN_SRLI45
;
7745 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_UB5 (insn
) < 8)
7747 insn16
= N16_TYPE333 (SLLI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7749 insn_type
= NDS32_INSN_SLLI333
;
7754 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7756 insn16
= N16_BFMI333 (ZEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
7757 insn_type
= NDS32_INSN_ZEH33
;
7762 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7764 insn16
= N16_BFMI333 (SEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7765 insn_type
= NDS32_INSN_SEB33
;
7770 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7772 insn16
= N16_BFMI333 (SEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
7773 insn_type
= NDS32_INSN_SEH33
;
7778 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
7781 insn16
= N16_TYPE45 (SLT45
, N32_RA54 (insn
), N32_RB5 (insn
));
7782 insn_type
= NDS32_INSN_SLT45
;
7787 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
7790 insn16
= N16_TYPE45 (SLTS45
, N32_RA54 (insn
), N32_RB5 (insn
));
7791 insn_type
= NDS32_INSN_SLTS45
;
7796 if ((insn16
& 0x8000) == 0)
7802 *pinsn_type
= insn_type
;
7807 nds32_convert_32_to_16_alu2 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7810 uint16_t insn16
= 0;
7812 unsigned long mach
= bfd_get_mach (abfd
);
7814 /* TODO: bset, bclr, btgl, btst. */
7815 if (__GF (insn
, 6, 4) != 0)
7818 switch (N32_IMMU (insn
, 6))
7821 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7822 && N32_IS_RB3 (insn
))
7824 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7825 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RB5 (insn
));
7826 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7827 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RA5 (insn
));
7829 insn_type
= NDS32_INSN_MUL33
;
7833 if ((insn16
& 0x8000) == 0)
7839 *pinsn_type
= insn_type
;
7844 nds32_convert_32_to_16 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7848 uint16_t insn16
= 0;
7850 unsigned long mach
= bfd_get_mach (abfd
);
7852 /* Decode 32-bit instruction. */
7853 if (insn
& 0x80000000)
7855 /* Not 32-bit insn. */
7859 op6
= N32_OP6 (insn
);
7861 /* Convert it to 16-bit instruction. */
7865 if (IS_WITHIN_S (N32_IMM20S (insn
), 5))
7867 insn16
= N16_TYPE55 (MOVI55
, N32_RT5 (insn
), N32_IMM20S (insn
));
7868 insn_type
= NDS32_INSN_MOVI55
;
7870 else if (mach
>= MACH_V3
&& N32_IMM20S (insn
) >= 16
7871 && N32_IMM20S (insn
) < 48 && N32_IS_RT4 (insn
))
7873 insn16
= N16_TYPE45 (MOVPI45
, N32_RT54 (insn
),
7874 N32_IMM20S (insn
) - 16);
7875 insn_type
= NDS32_INSN_MOVPI45
;
7880 if (N32_IMM15S (insn
) == 0)
7882 /* Do not convert `addi $sp, $sp, 0' to `mov55 $sp, $sp',
7883 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7885 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
7887 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
7888 insn_type
= NDS32_INSN_MOV55
;
7891 else if (N32_IMM15S (insn
) > 0)
7893 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) < 8)
7895 insn16
= N16_TYPE333 (ADDI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7897 insn_type
= NDS32_INSN_ADDI333
;
7899 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
7900 && N32_IMM15S (insn
) < 32)
7902 insn16
= N16_TYPE45 (ADDI45
, N32_RT54 (insn
), N32_IMM15S (insn
));
7903 insn_type
= NDS32_INSN_ADDI45
;
7905 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
7906 && N32_RT5 (insn
) == N32_RA5 (insn
)
7907 && N32_IMM15S (insn
) < 512)
7909 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
7910 insn_type
= NDS32_INSN_ADDI10_SP
;
7912 else if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
7913 && N32_RA5 (insn
) == REG_SP
&& N32_IMM15S (insn
) < 256
7914 && (N32_IMM15S (insn
) % 4 == 0))
7916 insn16
= N16_TYPE36 (ADDRI36_SP
, N32_RT5 (insn
),
7917 N32_IMM15S (insn
) >> 2);
7918 insn_type
= NDS32_INSN_ADDRI36_SP
;
7924 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) > -8)
7926 insn16
= N16_TYPE333 (SUBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7927 0 - N32_IMM15S (insn
));
7928 insn_type
= NDS32_INSN_SUBI333
;
7930 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
7931 && N32_IMM15S (insn
) > -32)
7933 insn16
= N16_TYPE45 (SUBI45
, N32_RT54 (insn
),
7934 0 - N32_IMM15S (insn
));
7935 insn_type
= NDS32_INSN_SUBI45
;
7937 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
7938 && N32_RT5 (insn
) == N32_RA5 (insn
)
7939 && N32_IMM15S (insn
) >= -512)
7941 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
7942 insn_type
= NDS32_INSN_ADDI10_SP
;
7948 if (N32_IMM15S (insn
) == 0)
7950 /* Do not convert `ori $sp, $sp, 0' to `mov55 $sp, $sp',
7951 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7953 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
7955 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
7956 insn_type
= NDS32_INSN_MOV55
;
7962 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
7963 && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) == 0)
7965 insn16
= N16_MISC33 (NEG33
, N32_RT5 (insn
), N32_RA5 (insn
));
7966 insn_type
= NDS32_INSN_NEG33
;
7971 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7973 if (N32_IMM15U (insn
) == 1)
7975 insn16
= N16_BFMI333 (XLSB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7976 insn_type
= NDS32_INSN_XLSB33
;
7978 else if (N32_IMM15U (insn
) == 0x7ff)
7980 insn16
= N16_BFMI333 (X11B33
, N32_RT5 (insn
), N32_RA5 (insn
));
7981 insn_type
= NDS32_INSN_X11B33
;
7983 else if (N32_IMM15U (insn
) == 0xff)
7985 insn16
= N16_BFMI333 (ZEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7986 insn_type
= NDS32_INSN_ZEB33
;
7988 else if (mach
>= MACH_V3
&& N32_RT5 (insn
) == N32_RA5 (insn
)
7989 && N32_IMM15U (insn
) < 256)
7991 int imm15u
= N32_IMM15U (insn
);
7993 if (__builtin_popcount (imm15u
) == 1)
7996 int imm3u
= __builtin_ctz (imm15u
);
7998 insn16
= N16_BFMI333 (BMSKI33
, N32_RT5 (insn
), imm3u
);
7999 insn_type
= NDS32_INSN_BMSKI33
;
8001 else if (imm15u
!= 0 && __builtin_popcount (imm15u
+ 1) == 1)
8004 int imm3u
= __builtin_ctz (imm15u
+ 1) - 1;
8006 insn16
= N16_BFMI333 (FEXTI33
, N32_RT5 (insn
), imm3u
);
8007 insn_type
= NDS32_INSN_FEXTI33
;
8014 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
8015 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
8017 insn16
= N16_TYPE45 (SLTI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
8018 insn_type
= NDS32_INSN_SLTI45
;
8023 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
8024 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
8026 insn16
= N16_TYPE45 (SLTSI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
8027 insn_type
= NDS32_INSN_SLTSI45
;
8032 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
8034 insn16
= N16_TYPE45 (LWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
8035 insn_type
= NDS32_INSN_LWI450
;
8037 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8038 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8040 insn16
= N16_TYPE333 (LWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8042 insn_type
= NDS32_INSN_LWI333
;
8044 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
8045 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8047 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8048 insn_type
= NDS32_INSN_LWI37
;
8050 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
8051 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8053 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8054 insn_type
= NDS32_INSN_LWI37_SP
;
8056 else if (mach
>= MACH_V2
&& N32_IS_RT4 (insn
) && N32_RA5 (insn
) == REG_R8
8057 && -32 <= N32_IMM15S (insn
) && N32_IMM15S (insn
) < 0)
8059 insn16
= N16_TYPE45 (LWI45_FE
, N32_RT54 (insn
),
8060 N32_IMM15S (insn
) + 32);
8061 insn_type
= NDS32_INSN_LWI45_FE
;
8066 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
8068 insn16
= N16_TYPE45 (SWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
8069 insn_type
= NDS32_INSN_SWI450
;
8071 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8072 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8074 insn16
= N16_TYPE333 (SWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8076 insn_type
= NDS32_INSN_SWI333
;
8078 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
8079 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8081 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8082 insn_type
= NDS32_INSN_SWI37
;
8084 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
8085 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8087 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8088 insn_type
= NDS32_INSN_SWI37_SP
;
8092 case N32_OP6_LWI_BI
:
8093 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8094 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8096 insn16
= N16_TYPE333 (LWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
8098 insn_type
= NDS32_INSN_LWI333_BI
;
8102 case N32_OP6_SWI_BI
:
8103 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8104 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8106 insn16
= N16_TYPE333 (SWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
8108 insn_type
= NDS32_INSN_SWI333_BI
;
8113 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8114 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8116 insn16
= N16_TYPE333 (LHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8118 insn_type
= NDS32_INSN_LHI333
;
8123 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8124 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8126 insn16
= N16_TYPE333 (SHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8128 insn_type
= NDS32_INSN_SHI333
;
8133 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8134 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8136 insn16
= N16_TYPE333 (LBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8138 insn_type
= NDS32_INSN_LBI333
;
8143 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8144 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8146 insn16
= N16_TYPE333 (SBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8148 insn_type
= NDS32_INSN_SBI333
;
8153 return nds32_convert_32_to_16_alu1 (abfd
, insn
, pinsn16
, pinsn_type
);
8156 return nds32_convert_32_to_16_alu2 (abfd
, insn
, pinsn16
, pinsn_type
);
8159 if (!IS_WITHIN_S (N32_IMM14S (insn
), 8))
8162 if ((insn
& N32_BIT (14)) == 0)
8165 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
8166 && N32_RT5 (insn
) != REG_R5
)
8167 insn16
= N16_TYPE38 (BEQS38
, N32_RT5 (insn
), N32_IMM14S (insn
));
8168 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
8169 && N32_RA5 (insn
) != REG_R5
)
8170 insn16
= N16_TYPE38 (BEQS38
, N32_RA5 (insn
), N32_IMM14S (insn
));
8171 insn_type
= NDS32_INSN_BEQS38
;
8177 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
8178 && N32_RT5 (insn
) != REG_R5
)
8179 insn16
= N16_TYPE38 (BNES38
, N32_RT5 (insn
), N32_IMM14S (insn
));
8180 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
8181 && N32_RA5 (insn
) != REG_R5
)
8182 insn16
= N16_TYPE38 (BNES38
, N32_RA5 (insn
), N32_IMM14S (insn
));
8183 insn_type
= NDS32_INSN_BNES38
;
8189 switch (N32_BR2_SUB (insn
))
8192 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8194 insn16
= N16_TYPE38 (BEQZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
8195 insn_type
= NDS32_INSN_BEQZ38
;
8197 else if (N32_RT5 (insn
) == REG_R15
8198 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8200 insn16
= N16_TYPE8 (BEQZS8
, N32_IMM16S (insn
));
8201 insn_type
= NDS32_INSN_BEQZS8
;
8206 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8208 insn16
= N16_TYPE38 (BNEZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
8209 insn_type
= NDS32_INSN_BNEZ38
;
8211 else if (N32_RT5 (insn
) == REG_R15
8212 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8214 insn16
= N16_TYPE8 (BNEZS8
, N32_IMM16S (insn
));
8215 insn_type
= NDS32_INSN_BNEZS8
;
8220 if (__GF (insn
, 20, 5) == 0 && IS_WITHIN_U (N32_IMM16S (insn
), 9))
8222 insn16
= N16_TYPE9 (IFCALL9
, N32_IMM16S (insn
));
8223 insn_type
= NDS32_INSN_IFCALL9
;
8230 if ((insn
& N32_BIT (24)) == 0)
8233 if (IS_WITHIN_S (N32_IMM24S (insn
), 8))
8235 insn16
= N16_TYPE8 (J8
, N32_IMM24S (insn
));
8236 insn_type
= NDS32_INSN_J8
;
8242 if (__GF (insn
, 8, 2) != 0)
8245 switch (N32_IMMU (insn
, 5))
8248 if (N32_JREG_HINT (insn
) == 0)
8251 insn16
= N16_TYPE5 (JR5
, N32_RB5 (insn
));
8252 insn_type
= NDS32_INSN_JR5
;
8254 else if (N32_JREG_HINT (insn
) == 1)
8257 insn16
= N16_TYPE5 (RET5
, N32_RB5 (insn
));
8258 insn_type
= NDS32_INSN_RET5
;
8260 else if (N32_JREG_HINT (insn
) == 3)
8262 /* ifret = mov55 $sp, $sp */
8263 insn16
= N16_TYPE55 (MOV55
, REG_SP
, REG_SP
);
8264 insn_type
= NDS32_INSN_IFRET
;
8269 /* It's convertible when return rt5 is $lp and address
8270 translation is kept. */
8271 if (N32_RT5 (insn
) == REG_LP
&& N32_JREG_HINT (insn
) == 0)
8273 insn16
= N16_TYPE5 (JRAL5
, N32_RB5 (insn
));
8274 insn_type
= NDS32_INSN_JRAL5
;
8281 if (N32_SUB5 (insn
) == N32_MISC_BREAK
&& N32_SWID (insn
) < 32)
8283 /* For v3, swid above 31 are used for ex9.it. */
8284 insn16
= N16_TYPE5 (BREAK16
, N32_SWID (insn
));
8285 insn_type
= NDS32_INSN_BREAK16
;
8290 /* This instruction has no 16-bit variant. */
8295 /* Bit-15 of insn16 should be set for a valid instruction. */
8296 if ((insn16
& 0x8000) == 0)
8302 *pinsn_type
= insn_type
;
8307 special_convert_32_to_16 (unsigned long insn
, uint16_t *pinsn16
,
8308 Elf_Internal_Rela
*reloc
)
8310 uint16_t insn16
= 0;
8312 if ((reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
) == 0
8313 || (ELF32_R_TYPE (reloc
->r_info
) != R_NDS32_INSN16
))
8316 if (!N32_IS_RT3 (insn
))
8319 switch (N32_OP6 (insn
))
8322 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
8323 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8326 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
8327 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8330 if (!IS_WITHIN_U (N32_IMM17S (insn
), 7))
8333 if (__GF (insn
, 17, 3) == 6)
8334 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM17S (insn
));
8335 else if (__GF (insn
, 17, 3) == 7)
8336 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM17S (insn
));
8340 if ((insn16
& 0x8000) == 0)
8347 /* Convert a 16-bit instruction to 32-bit one.
8348 INSN16 it the input and PINSN it the point to output.
8349 Return non-zero on successful. Otherwise 0 is returned. */
8352 nds32_convert_16_to_32 (bfd
*abfd
, uint16_t insn16
, uint32_t *pinsn
)
8354 uint32_t insn
= 0xffffffff;
8355 unsigned long mach
= bfd_get_mach (abfd
);
8357 /* NOTE: push25, pop25 and movd44 do not have 32-bit variants. */
8359 switch (__GF (insn16
, 9, 6))
8361 case 0x4: /* add45 */
8362 insn
= N32_ALU1 (ADD
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8365 case 0x5: /* sub45 */
8366 insn
= N32_ALU1 (SUB
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8369 case 0x6: /* addi45 */
8370 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8371 N16_IMM5U (insn16
));
8373 case 0x7: /* subi45 */
8374 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8375 -N16_IMM5U (insn16
));
8377 case 0x8: /* srai45 */
8378 insn
= N32_ALU1 (SRAI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8379 N16_IMM5U (insn16
));
8381 case 0x9: /* srli45 */
8382 insn
= N32_ALU1 (SRLI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8383 N16_IMM5U (insn16
));
8385 case 0xa: /* slli333 */
8386 insn
= N32_ALU1 (SLLI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8387 N16_IMM3U (insn16
));
8389 case 0xc: /* add333 */
8390 insn
= N32_ALU1 (ADD
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8393 case 0xd: /* sub333 */
8394 insn
= N32_ALU1 (SUB
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8397 case 0xe: /* addi333 */
8398 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8399 N16_IMM3U (insn16
));
8401 case 0xf: /* subi333 */
8402 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8403 -N16_IMM3U (insn16
));
8405 case 0x10: /* lwi333 */
8406 insn
= N32_TYPE2 (LWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8407 N16_IMM3U (insn16
));
8409 case 0x12: /* lhi333 */
8410 insn
= N32_TYPE2 (LHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8411 N16_IMM3U (insn16
));
8413 case 0x13: /* lbi333 */
8414 insn
= N32_TYPE2 (LBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8415 N16_IMM3U (insn16
));
8417 case 0x11: /* lwi333.bi */
8418 insn
= N32_TYPE2 (LWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8419 N16_IMM3U (insn16
));
8421 case 0x14: /* swi333 */
8422 insn
= N32_TYPE2 (SWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8423 N16_IMM3U (insn16
));
8425 case 0x16: /* shi333 */
8426 insn
= N32_TYPE2 (SHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8427 N16_IMM3U (insn16
));
8429 case 0x17: /* sbi333 */
8430 insn
= N32_TYPE2 (SBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8431 N16_IMM3U (insn16
));
8433 case 0x15: /* swi333.bi */
8434 insn
= N32_TYPE2 (SWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8435 N16_IMM3U (insn16
));
8437 case 0x18: /* addri36.sp */
8438 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), REG_SP
,
8439 N16_IMM6U (insn16
) << 2);
8441 case 0x19: /* lwi45.fe */
8442 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), REG_R8
,
8443 (N16_IMM5U (insn16
) - 32));
8445 case 0x1a: /* lwi450 */
8446 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
8448 case 0x1b: /* swi450 */
8449 insn
= N32_TYPE2 (SWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
8452 /* These are r15 implied instructions. */
8453 case 0x30: /* slts45 */
8454 insn
= N32_ALU1 (SLTS
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
8456 case 0x31: /* slt45 */
8457 insn
= N32_ALU1 (SLT
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
8459 case 0x32: /* sltsi45 */
8460 insn
= N32_TYPE2 (SLTSI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
8462 case 0x33: /* slti45 */
8463 insn
= N32_TYPE2 (SLTI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
8465 case 0x34: /* beqzs8, bnezs8 */
8466 if (insn16
& N32_BIT (8))
8467 insn
= N32_BR2 (BNEZ
, REG_TA
, N16_IMM8S (insn16
));
8469 insn
= N32_BR2 (BEQZ
, REG_TA
, N16_IMM8S (insn16
));
8472 case 0x35: /* break16, ex9.it */
8473 /* Only consider range of v3 break16. */
8474 insn
= N32_TYPE0 (MISC
, (N16_IMM5U (insn16
) << 5) | N32_MISC_BREAK
);
8477 case 0x3c: /* ifcall9 */
8478 insn
= N32_BR2 (SOP0
, 0, N16_IMM9U (insn16
));
8480 case 0x3d: /* movpi45 */
8481 insn
= N32_TYPE1 (MOVI
, N16_RT4 (insn16
), N16_IMM5U (insn16
) + 16);
8484 case 0x3f: /* MISC33 */
8485 switch (insn16
& 0x7)
8488 insn
= N32_TYPE2 (SUBRI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8491 insn
= N32_ALU1 (NOR
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8495 insn
= N32_ALU2 (MUL
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8499 insn
= N32_ALU1 (XOR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8503 insn
= N32_ALU1 (AND
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8507 insn
= N32_ALU1 (OR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8514 switch (insn16
& 0x7)
8517 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0xff);
8520 insn
= N32_ALU1 (ZEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8523 insn
= N32_ALU1 (SEB
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8526 insn
= N32_ALU1 (SEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8528 case 4: /* xlsb33 */
8529 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 1);
8531 case 5: /* x11b33 */
8532 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0x7ff);
8534 case 6: /* bmski33 */
8535 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8536 1 << __GF (insn16
, 3, 3));
8538 case 7: /* fexti33 */
8539 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8540 (1 << (__GF (insn16
, 3, 3) + 1)) - 1);
8546 switch (__GF (insn16
, 10, 5))
8548 case 0x0: /* mov55 or ifret16 */
8549 if (mach
>= MACH_V3
&& N16_RT5 (insn16
) == REG_SP
8550 && N16_RT5 (insn16
) == N16_RA5 (insn16
))
8551 insn
= N32_JREG (JR
, 0, 0, 0, 3);
8553 insn
= N32_TYPE2 (ADDI
, N16_RT5 (insn16
), N16_RA5 (insn16
), 0);
8555 case 0x1: /* movi55 */
8556 insn
= N32_TYPE1 (MOVI
, N16_RT5 (insn16
), N16_IMM5S (insn16
));
8558 case 0x1b: /* addi10s (V2) */
8559 insn
= N32_TYPE2 (ADDI
, REG_SP
, REG_SP
, N16_IMM10S (insn16
));
8563 switch (__GF (insn16
, 11, 4))
8565 case 0x7: /* lwi37.fp/swi37.fp */
8566 if (insn16
& N32_BIT (7)) /* swi37.fp */
8567 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
8569 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
8571 case 0x8: /* beqz38 */
8572 insn
= N32_BR2 (BEQZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
8574 case 0x9: /* bnez38 */
8575 insn
= N32_BR2 (BNEZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
8577 case 0xa: /* beqs38/j8, implied r5 */
8578 if (N16_RT38 (insn16
) == 5)
8579 insn
= N32_JI (J
, N16_IMM8S (insn16
));
8581 insn
= N32_BR1 (BEQ
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
8583 case 0xb: /* bnes38 and others. */
8584 if (N16_RT38 (insn16
) == 5)
8586 switch (__GF (insn16
, 5, 3))
8589 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 0);
8592 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 1);
8595 insn
= N32_JREG (JRAL
, REG_LP
, N16_RA5 (insn16
), 0, 0);
8597 case 2: /* ex9.it imm5 */
8598 /* ex9.it had no 32-bit variantl. */
8600 case 5: /* add5.pc */
8601 /* add5.pc had no 32-bit variantl. */
8606 insn
= N32_BR1 (BNE
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
8608 case 0xe: /* lwi37/swi37 */
8609 if (insn16
& (1 << 7)) /* swi37.sp */
8610 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
8612 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
8617 if (insn
& 0x80000000)
8627 is_sda_access_insn (unsigned long insn
)
8629 switch (N32_OP6 (insn
))
8650 static unsigned long
8651 turn_insn_to_sda_access (uint32_t insn
, bfd_signed_vma type
, uint32_t *pinsn
)
8657 case R_NDS32_GOT_LO12
:
8658 case R_NDS32_GOTOFF_LO12
:
8659 case R_NDS32_PLTREL_LO12
:
8660 case R_NDS32_PLT_GOTREL_LO12
:
8661 case R_NDS32_LO12S0_RELA
:
8662 switch (N32_OP6 (insn
))
8666 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
8670 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
8674 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
8678 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
8683 case R_NDS32_LO12S1_RELA
:
8684 switch (N32_OP6 (insn
))
8688 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
8692 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
8696 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
8701 case R_NDS32_LO12S2_RELA
:
8702 switch (N32_OP6 (insn
))
8706 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
8710 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
8715 case R_NDS32_LO12S2_DP_RELA
:
8716 case R_NDS32_LO12S2_SP_RELA
:
8717 oinsn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
8727 /* Linker hasn't found the correct merge section for non-section symbol
8728 in relax time, this work is left to the function elf_link_input_bfd().
8729 So for non-section symbol, _bfd_merged_section_offset is also needed
8730 to find the correct symbol address. */
8733 nds32_elf_rela_local_sym (bfd
*abfd
, Elf_Internal_Sym
*sym
,
8734 asection
**psec
, Elf_Internal_Rela
*rel
)
8736 asection
*sec
= *psec
;
8739 relocation
= (sec
->output_section
->vma
8740 + sec
->output_offset
+ sym
->st_value
);
8741 if ((sec
->flags
& SEC_MERGE
) && sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
8743 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8745 _bfd_merged_section_offset (abfd
, psec
,
8746 elf_section_data (sec
)->sec_info
,
8747 sym
->st_value
+ rel
->r_addend
);
8750 _bfd_merged_section_offset (abfd
, psec
,
8751 elf_section_data (sec
)->sec_info
,
8752 sym
->st_value
) + rel
->r_addend
;
8756 /* If we have changed the section, and our original section is
8757 marked with SEC_EXCLUDE, it means that the original
8758 SEC_MERGE section has been completely subsumed in some
8759 other SEC_MERGE section. In this case, we need to leave
8760 some info around for --emit-relocs. */
8761 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
8762 sec
->kept_section
= *psec
;
8765 rel
->r_addend
-= relocation
;
8766 rel
->r_addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
8772 calculate_memory_address (bfd
*abfd
, Elf_Internal_Rela
*irel
,
8773 Elf_Internal_Sym
*isymbuf
,
8774 Elf_Internal_Shdr
*symtab_hdr
)
8776 bfd_signed_vma foff
;
8777 bfd_vma symval
, addend
;
8778 Elf_Internal_Rela irel_fn
;
8779 Elf_Internal_Sym
*isym
;
8782 /* Get the value of the symbol referred to by the reloc. */
8783 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
8785 /* A local symbol. */
8786 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
8788 if (isym
->st_shndx
== SHN_UNDEF
)
8789 sym_sec
= bfd_und_section_ptr
;
8790 else if (isym
->st_shndx
== SHN_ABS
)
8791 sym_sec
= bfd_abs_section_ptr
;
8792 else if (isym
->st_shndx
== SHN_COMMON
)
8793 sym_sec
= bfd_com_section_ptr
;
8795 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
8796 memcpy (&irel_fn
, irel
, sizeof (Elf_Internal_Rela
));
8797 symval
= nds32_elf_rela_local_sym (abfd
, isym
, &sym_sec
, &irel_fn
);
8798 addend
= irel_fn
.r_addend
;
8803 struct elf_link_hash_entry
*h
;
8805 /* An external symbol. */
8806 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
8807 h
= elf_sym_hashes (abfd
)[indx
];
8808 BFD_ASSERT (h
!= NULL
);
8810 while (h
->root
.type
== bfd_link_hash_indirect
8811 || h
->root
.type
== bfd_link_hash_warning
)
8812 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8814 if (h
->root
.type
!= bfd_link_hash_defined
8815 && h
->root
.type
!= bfd_link_hash_defweak
)
8816 /* This appears to be a reference to an undefined
8817 symbol. Just ignore it--it will be caught by the
8818 regular reloc processing. */
8821 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
8823 sym_sec
= h
->root
.u
.def
.section
;
8824 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
, elf_section_data
8825 (sym_sec
)->sec_info
, h
->root
.u
.def
.value
);
8826 symval
= symval
+ sym_sec
->output_section
->vma
8827 + sym_sec
->output_offset
;
8830 symval
= (h
->root
.u
.def
.value
8831 + h
->root
.u
.def
.section
->output_section
->vma
8832 + h
->root
.u
.def
.section
->output_offset
);
8833 addend
= irel
->r_addend
;
8836 foff
= symval
+ addend
;
8842 is_16bit_NOP (bfd
*abfd ATTRIBUTE_UNUSED
,
8843 asection
*sec
, Elf_Internal_Rela
*rel
)
8846 unsigned short insn16
;
8848 if (!(rel
->r_addend
& R_NDS32_INSN16_CONVERT_FLAG
))
8850 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8851 insn16
= bfd_getb16 (contents
+ rel
->r_offset
);
8852 if (insn16
== NDS32_NOP16
)
8857 /* It checks whether the instruction could be converted to
8858 16-bit form and returns the converted one.
8860 `internal_relocs' is supposed to be sorted. */
8863 is_convert_32_to_16 (bfd
*abfd
, asection
*sec
,
8864 Elf_Internal_Rela
*reloc
,
8865 Elf_Internal_Rela
*internal_relocs
,
8866 Elf_Internal_Rela
*irelend
,
8869 #define NORMAL_32_TO_16 (1 << 0)
8870 #define SPECIAL_32_TO_16 (1 << 1)
8871 bfd_byte
*contents
= NULL
;
8875 Elf_Internal_Rela
*pc_rel
;
8876 Elf_Internal_Shdr
*symtab_hdr
;
8877 Elf_Internal_Sym
*isymbuf
= NULL
;
8881 if (reloc
->r_offset
+ 4 > sec
->size
)
8884 offset
= reloc
->r_offset
;
8886 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
8888 insn
= bfd_getb32 (contents
+ offset
);
8890 if (nds32_convert_32_to_16 (abfd
, insn
, insn16
, NULL
))
8891 convert_type
= NORMAL_32_TO_16
;
8892 else if (special_convert_32_to_16 (insn
, insn16
, reloc
))
8893 convert_type
= SPECIAL_32_TO_16
;
8897 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8898 if (!nds32_get_local_syms (abfd
, sec
, &isymbuf
))
8901 /* Find the first relocation of the same relocation-type,
8902 so we iteratie them forward. */
8904 while ((pc_rel
- 1) >= internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
8907 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
8909 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
8910 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8911 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
8912 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
8914 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
);
8915 if (off
>= ACCURATE_8BIT_S1
|| off
< -ACCURATE_8BIT_S1
8920 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
8922 /* movi => movi55 */
8923 mem_addr
= calculate_memory_address (abfd
, pc_rel
, isymbuf
,
8925 /* mem_addr is unsigned, but the value should
8926 be between [-16, 15]. */
8927 if ((mem_addr
+ 0x10) >> 5)
8931 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_20
)
8932 || (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_LO12
))
8934 /* It never happen movi to movi55 for R_NDS32_TLS_LE_20,
8935 because it can be relaxed to addi for TLS_LE_ADD. */
8938 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
8939 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
8940 && (reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
)
8941 && convert_type
== SPECIAL_32_TO_16
)
8944 We've selected a best fp-base for this access, so we can
8945 always resolve it anyway. Do nothing. */
8948 else if ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_NONE
8949 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_RELA_GNU_VTINHERIT
))
8950 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_RELA_GNU_VTENTRY
)
8951 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_INSN16
))
8952 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_LOADSTORE
)
8953 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_DWARF2_OP1_RELA
)))
8955 /* Prevent unresolved addi instruction translate
8956 to addi45 or addi333. */
8959 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
8961 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
);
8962 if (off
>= ACCURATE_U9BIT_S1
|| off
<= 0)
8972 nds32_elf_write_16 (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*contents
,
8973 Elf_Internal_Rela
*reloc
,
8974 Elf_Internal_Rela
*internal_relocs
,
8975 Elf_Internal_Rela
*irelend
,
8976 unsigned short insn16
)
8978 Elf_Internal_Rela
*pc_rel
;
8981 offset
= reloc
->r_offset
;
8982 bfd_putb16 (insn16
, contents
+ offset
);
8983 /* Find the first relocation of the same relocation-type,
8984 so we iteratie them forward. */
8986 while ((pc_rel
- 1) > internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
8989 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
8991 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
8992 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8993 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
)
8996 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PCREL_RELA
);
8998 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
9000 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PLTREL
);
9001 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
9003 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_5_RELA
);
9004 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
9005 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
9007 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_SDA_FP7U2_RELA
);
9008 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
9010 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_10IFCU_PCREL_RELA
);
9014 /* Find a relocation of type specified by `reloc_type'
9015 of the same r_offset with reloc.
9016 If not found, return irelend.
9018 Assuming relocations are sorted by r_offset,
9019 we find the relocation from `reloc' backward untill relocs,
9020 or find it from `reloc' forward untill irelend. */
9022 static Elf_Internal_Rela
*
9023 find_relocs_at_address (Elf_Internal_Rela
*reloc
,
9024 Elf_Internal_Rela
*relocs
,
9025 Elf_Internal_Rela
*irelend
,
9026 enum elf_nds32_reloc_type reloc_type
)
9028 Elf_Internal_Rela
*rel_t
;
9030 /* Find backward. */
9032 rel_t
>= relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
9034 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
9037 /* We didn't find it backward. Try find it forward. */
9039 rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
9041 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
9047 /* Find a relocation of specified type and offset.
9048 `reloc' is just a refence point to find a relocation at specified offset.
9049 If not found, return irelend.
9051 Assuming relocations are sorted by r_offset,
9052 we find the relocation from `reloc' backward untill relocs,
9053 or find it from `reloc' forward untill irelend. */
9055 static Elf_Internal_Rela
*
9056 find_relocs_at_address_addr (Elf_Internal_Rela
*reloc
,
9057 Elf_Internal_Rela
*relocs
,
9058 Elf_Internal_Rela
*irelend
,
9059 enum elf_nds32_reloc_type reloc_type
,
9062 Elf_Internal_Rela
*rel_t
= NULL
;
9064 /* First, we try to find a relocation of offset `offset_p',
9065 and then we use find_relocs_at_address to find specific type. */
9067 if (reloc
->r_offset
> offset_p
)
9069 /* Find backward. */
9071 rel_t
>= relocs
&& rel_t
->r_offset
> offset_p
; rel_t
--)
9074 else if (reloc
->r_offset
< offset_p
)
9078 rel_t
< irelend
&& rel_t
->r_offset
< offset_p
; rel_t
++)
9085 if (rel_t
< relocs
|| rel_t
== irelend
|| rel_t
->r_offset
!= offset_p
)
9088 return find_relocs_at_address (rel_t
, relocs
, irelend
, reloc_type
);
9091 typedef struct nds32_elf_blank nds32_elf_blank_t
;
9092 struct nds32_elf_blank
9094 /* Where the blank begins. */
9096 /* The size of the blank. */
9098 /* The accumulative size before this blank. */
9100 nds32_elf_blank_t
*next
;
9101 nds32_elf_blank_t
*prev
;
9104 static nds32_elf_blank_t
*blank_free_list
= NULL
;
9106 static nds32_elf_blank_t
*
9107 create_nds32_elf_blank (bfd_vma offset_p
, bfd_vma size_p
)
9109 nds32_elf_blank_t
*blank_t
;
9111 if (blank_free_list
)
9113 blank_t
= blank_free_list
;
9114 blank_free_list
= blank_free_list
->next
;
9117 blank_t
= bfd_malloc (sizeof (nds32_elf_blank_t
));
9119 if (blank_t
== NULL
)
9122 blank_t
->offset
= offset_p
;
9123 blank_t
->size
= size_p
;
9124 blank_t
->total_size
= 0;
9125 blank_t
->next
= NULL
;
9126 blank_t
->prev
= NULL
;
9132 remove_nds32_elf_blank (nds32_elf_blank_t
*blank_p
)
9134 if (blank_free_list
)
9136 blank_free_list
->prev
= blank_p
;
9137 blank_p
->next
= blank_free_list
;
9140 blank_p
->next
= NULL
;
9142 blank_p
->prev
= NULL
;
9143 blank_free_list
= blank_p
;
9147 clean_nds32_elf_blank (void)
9149 nds32_elf_blank_t
*blank_t
;
9151 while (blank_free_list
)
9153 blank_t
= blank_free_list
;
9154 blank_free_list
= blank_free_list
->next
;
9159 static nds32_elf_blank_t
*
9160 search_nds32_elf_blank (nds32_elf_blank_t
*blank_p
, bfd_vma addr
)
9162 nds32_elf_blank_t
*blank_t
;
9168 while (blank_t
&& addr
< blank_t
->offset
)
9169 blank_t
= blank_t
->prev
;
9170 while (blank_t
&& blank_t
->next
&& addr
>= blank_t
->next
->offset
)
9171 blank_t
= blank_t
->next
;
9177 get_nds32_elf_blank_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
9180 nds32_elf_blank_t
*blank_t
;
9182 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
9189 if (addr
< blank_t
->offset
+ blank_t
->size
)
9190 return blank_t
->total_size
+ (addr
- blank_t
->offset
);
9192 return blank_t
->total_size
+ blank_t
->size
;
9196 insert_nds32_elf_blank (nds32_elf_blank_t
**blank_p
, bfd_vma addr
, bfd_vma len
)
9198 nds32_elf_blank_t
*blank_t
, *blank_t2
;
9202 *blank_p
= create_nds32_elf_blank (addr
, len
);
9203 return *blank_p
? TRUE
: FALSE
;
9206 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
9208 if (blank_t
== NULL
)
9210 blank_t
= create_nds32_elf_blank (addr
, len
);
9213 while ((*blank_p
)->prev
!= NULL
)
9214 *blank_p
= (*blank_p
)->prev
;
9215 blank_t
->next
= *blank_p
;
9216 (*blank_p
)->prev
= blank_t
;
9217 (*blank_p
) = blank_t
;
9221 if (addr
< blank_t
->offset
+ blank_t
->size
)
9223 /* Extend the origin blank. */
9224 if (addr
+ len
> blank_t
->offset
+ blank_t
->size
)
9225 blank_t
->size
= addr
+ len
- blank_t
->offset
;
9229 blank_t2
= create_nds32_elf_blank (addr
, len
);
9234 blank_t
->next
->prev
= blank_t2
;
9235 blank_t2
->next
= blank_t
->next
;
9237 blank_t2
->prev
= blank_t
;
9238 blank_t
->next
= blank_t2
;
9239 *blank_p
= blank_t2
;
9246 insert_nds32_elf_blank_recalc_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
9249 nds32_elf_blank_t
*blank_t
;
9251 if (!insert_nds32_elf_blank (blank_p
, addr
, len
))
9258 blank_t
->total_size
= 0;
9259 blank_t
= blank_t
->next
;
9264 blank_t
->total_size
= blank_t
->prev
->total_size
+ blank_t
->prev
->size
;
9265 blank_t
= blank_t
->next
;
9272 calc_nds32_blank_total (nds32_elf_blank_t
*blank_p
)
9274 nds32_elf_blank_t
*blank_t
;
9275 bfd_vma total_size
= 0;
9281 while (blank_t
->prev
)
9282 blank_t
= blank_t
->prev
;
9285 blank_t
->total_size
= total_size
;
9286 total_size
+= blank_t
->size
;
9287 blank_t
= blank_t
->next
;
9292 nds32_elf_relax_delete_blanks (bfd
*abfd
, asection
*sec
,
9293 nds32_elf_blank_t
*blank_p
)
9295 Elf_Internal_Shdr
*symtab_hdr
; /* Symbol table header of this bfd. */
9296 Elf_Internal_Sym
*isym
= NULL
; /* Symbol table of this bfd. */
9297 Elf_Internal_Sym
*isymend
; /* Symbol entry iterator. */
9298 unsigned int sec_shndx
; /* The section the be relaxed. */
9299 bfd_byte
*contents
; /* Contents data of iterating section. */
9300 Elf_Internal_Rela
*internal_relocs
;
9301 Elf_Internal_Rela
*irel
;
9302 Elf_Internal_Rela
*irelend
;
9303 struct elf_link_hash_entry
**sym_hashes
;
9304 struct elf_link_hash_entry
**end_hashes
;
9305 unsigned int symcount
;
9307 nds32_elf_blank_t
*blank_t
;
9308 nds32_elf_blank_t
*blank_t2
;
9309 nds32_elf_blank_t
*blank_head
;
9311 blank_head
= blank_t
= blank_p
;
9312 while (blank_head
->prev
!= NULL
)
9313 blank_head
= blank_head
->prev
;
9314 while (blank_t
->next
!= NULL
)
9315 blank_t
= blank_t
->next
;
9317 if (blank_t
->offset
+ blank_t
->size
<= sec
->size
)
9319 blank_t
->next
= create_nds32_elf_blank (sec
->size
+ 4, 0);
9320 blank_t
->next
->prev
= blank_t
;
9322 if (blank_head
->offset
> 0)
9324 blank_head
->prev
= create_nds32_elf_blank (0, 0);
9325 blank_head
->prev
->next
= blank_head
;
9326 blank_head
= blank_head
->prev
;
9329 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
9331 /* The deletion must stop at the next ALIGN reloc for an alignment
9332 power larger than the number of bytes we are deleting. */
9334 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9335 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
9340 isym
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
9341 symtab_hdr
->sh_info
, 0, NULL
, NULL
, NULL
);
9342 symtab_hdr
->contents
= (bfd_byte
*) isym
;
9345 if (isym
== NULL
|| symtab_hdr
->sh_info
== 0)
9348 blank_t
= blank_head
;
9349 calc_nds32_blank_total (blank_head
);
9351 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
9353 /* Adjust all the relocs. */
9355 /* Relocations MUST be kept in memory, because relaxation adjust them. */
9356 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sect
, NULL
, NULL
,
9357 TRUE
/* keep_memory */);
9358 irelend
= internal_relocs
+ sect
->reloc_count
;
9360 blank_t
= blank_head
;
9361 blank_t2
= blank_head
;
9363 if (!(sect
->flags
& SEC_RELOC
))
9366 nds32_get_section_contents (abfd
, sect
, &contents
, TRUE
);
9368 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
9372 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_DIFF8
9373 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_DIFF32
9374 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
9376 unsigned long val
= 0;
9378 long before
, between
;
9381 switch (ELF32_R_TYPE (irel
->r_info
))
9384 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
9386 case R_NDS32_DIFF16
:
9387 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
9389 case R_NDS32_DIFF32
:
9390 val
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
9391 /* Get the signed bit and mask for the high part. The
9392 gcc will alarm when right shift 32-bit since the
9393 type size of long may be 32-bit. */
9394 mask
= 0 - (val
>> 31);
9396 offset
= (val
| (mask
- 0xffffffff));
9405 0 |encoded in location|
9406 |------------|-------------------|---------
9408 -- before ---| *****************
9409 --------------------- between ---|
9411 We only care how much data are relax between DIFF,
9414 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
9415 between
= get_nds32_elf_blank_total (&blank_t
,
9416 irel
->r_addend
+ offset
, 0);
9417 if (between
== before
)
9418 goto done_adjust_diff
;
9420 switch (ELF32_R_TYPE (irel
->r_info
))
9423 bfd_put_8 (abfd
, offset
- (between
- before
),
9424 contents
+ irel
->r_offset
);
9426 case R_NDS32_DIFF16
:
9427 bfd_put_16 (abfd
, offset
- (between
- before
),
9428 contents
+ irel
->r_offset
);
9430 case R_NDS32_DIFF32
:
9431 bfd_put_32 (abfd
, offset
- (between
- before
),
9432 contents
+ irel
->r_offset
);
9436 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_DIFF_ULEB128
9437 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
9440 unsigned int len
= 0;
9441 unsigned long before
, between
;
9444 val
= _bfd_read_unsigned_leb128 (abfd
, contents
+ irel
->r_offset
,
9447 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
9448 between
= get_nds32_elf_blank_total (&blank_t
,
9449 irel
->r_addend
+ val
, 0);
9450 if (between
== before
)
9451 goto done_adjust_diff
;
9453 p
= contents
+ irel
->r_offset
;
9455 memset (p
, 0x80, len
);
9457 p
= write_uleb128 (p
, val
- (between
- before
)) - 1;
9465 raddr
= irel
->r_offset
;
9466 irel
->r_offset
-= get_nds32_elf_blank_total (&blank_t2
,
9469 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
9471 if (blank_t2
&& blank_t2
->next
9472 && (blank_t2
->offset
> raddr
9473 || blank_t2
->next
->offset
<= raddr
))
9475 (_("%pB: error: search_nds32_elf_blank reports wrong node"),
9478 /* Mark reloc in deleted portion as NONE.
9479 For some relocs like R_NDS32_LABEL that doesn't modify the
9480 content in the section. R_NDS32_LABEL doesn't belong to the
9481 instruction in the section, so we should preserve it. */
9482 if (raddr
>= blank_t2
->offset
9483 && raddr
< blank_t2
->offset
+ blank_t2
->size
9484 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
9485 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_BEGIN
9486 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_END
9487 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
9488 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_SUBTRAHEND
9489 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_MINUEND
)
9491 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
9497 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
9498 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
9499 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
9502 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
9503 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
9504 && ELF_ST_TYPE (isym
[ELF32_R_SYM (irel
->r_info
)].st_info
) == STT_SECTION
)
9506 if (irel
->r_addend
<= sec
->size
)
9508 get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 1);
9513 /* Adjust the local symbols defined in this section. */
9514 blank_t
= blank_head
;
9515 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
9517 if (isym
->st_shndx
== sec_shndx
)
9519 if (isym
->st_value
<= sec
->size
)
9522 bfd_vma orig_addr
= isym
->st_value
;
9524 ahead
= get_nds32_elf_blank_total (&blank_t
, isym
->st_value
, 1);
9525 isym
->st_value
-= ahead
;
9527 /* Adjust function size. */
9528 if (ELF32_ST_TYPE (isym
->st_info
) == STT_FUNC
9529 && isym
->st_size
> 0)
9531 get_nds32_elf_blank_total
9532 (&blank_t
, orig_addr
+ isym
->st_size
, 0) - ahead
;
9537 /* Now adjust the global symbols defined in this section. */
9538 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
9539 - symtab_hdr
->sh_info
);
9540 sym_hashes
= elf_sym_hashes (abfd
);
9541 end_hashes
= sym_hashes
+ symcount
;
9542 blank_t
= blank_head
;
9543 for (; sym_hashes
< end_hashes
; sym_hashes
++)
9545 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
9547 if ((sym_hash
->root
.type
== bfd_link_hash_defined
9548 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
9549 && sym_hash
->root
.u
.def
.section
== sec
)
9551 if (sym_hash
->root
.u
.def
.value
<= sec
->size
)
9554 bfd_vma orig_addr
= sym_hash
->root
.u
.def
.value
;
9556 ahead
= get_nds32_elf_blank_total (&blank_t
, sym_hash
->root
.u
.def
.value
, 1);
9557 sym_hash
->root
.u
.def
.value
-= ahead
;
9559 /* Adjust function size. */
9560 if (sym_hash
->type
== STT_FUNC
)
9562 get_nds32_elf_blank_total
9563 (&blank_t
, orig_addr
+ sym_hash
->size
, 0) - ahead
;
9569 contents
= elf_section_data (sec
)->this_hdr
.contents
;
9570 blank_t
= blank_head
;
9571 while (blank_t
->next
)
9573 /* Actually delete the bytes. */
9575 /* If current blank is the last blank overlap with current section,
9576 go to finish process. */
9577 if (sec
->size
<= (blank_t
->next
->offset
))
9580 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
9581 contents
+ blank_t
->offset
+ blank_t
->size
,
9582 blank_t
->next
->offset
- (blank_t
->offset
+ blank_t
->size
));
9584 blank_t
= blank_t
->next
;
9587 if (sec
->size
> (blank_t
->offset
+ blank_t
->size
))
9589 /* There are remaining code between blank and section boundary.
9590 Move the remaining code to appropriate location. */
9591 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
9592 contents
+ blank_t
->offset
+ blank_t
->size
,
9593 sec
->size
- (blank_t
->offset
+ blank_t
->size
));
9594 sec
->size
-= blank_t
->total_size
+ blank_t
->size
;
9597 /* This blank is not entirely included in the section,
9598 reduce the section size by only part of the blank size. */
9599 sec
->size
-= blank_t
->total_size
+ (sec
->size
- blank_t
->offset
);
9603 blank_t
= blank_head
;
9604 blank_head
= blank_head
->next
;
9605 remove_nds32_elf_blank (blank_t
);
9611 /* Get the contents of a section. */
9614 nds32_get_section_contents (bfd
*abfd
, asection
*sec
,
9615 bfd_byte
**contents_p
, bfd_boolean cache
)
9617 /* Get the section contents. */
9618 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
9619 *contents_p
= elf_section_data (sec
)->this_hdr
.contents
;
9622 if (!bfd_malloc_and_get_section (abfd
, sec
, contents_p
))
9625 elf_section_data (sec
)->this_hdr
.contents
= *contents_p
;
9631 /* Get the contents of the internal symbol of abfd. */
9634 nds32_get_local_syms (bfd
*abfd
, asection
*sec ATTRIBUTE_UNUSED
,
9635 Elf_Internal_Sym
**isymbuf_p
)
9637 Elf_Internal_Shdr
*symtab_hdr
;
9638 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9640 /* Read this BFD's local symbols if we haven't done so already. */
9641 if (*isymbuf_p
== NULL
&& symtab_hdr
->sh_info
!= 0)
9643 *isymbuf_p
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
9644 if (*isymbuf_p
== NULL
)
9646 *isymbuf_p
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
9647 symtab_hdr
->sh_info
, 0,
9649 if (*isymbuf_p
== NULL
)
9653 symtab_hdr
->contents
= (bfd_byte
*) (*isymbuf_p
);
9658 /* Range of small data. */
9659 static bfd_vma sdata_range
[2][2];
9660 static bfd_vma
const sdata_init_range
[2] =
9661 { ACCURATE_12BIT_S1
, ACCURATE_19BIT
};
9664 nds32_elf_insn_size (bfd
*abfd ATTRIBUTE_UNUSED
,
9665 bfd_byte
*contents
, bfd_vma addr
)
9667 unsigned long insn
= bfd_getb32 (contents
+ addr
);
9669 if (insn
& 0x80000000)
9675 /* Set the gp relax range. We have to measure the safe range
9676 to do gp relaxation. */
9679 relax_range_measurement (bfd
*abfd
)
9681 asection
*sec_f
, *sec_b
;
9682 /* For upper bound. */
9683 bfd_vma maxpgsz
= get_elf_backend_data (abfd
)->maxpagesize
;
9685 static int decide_relax_range
= 0;
9687 int range_number
= ARRAY_SIZE (sdata_init_range
);
9689 if (decide_relax_range
)
9691 decide_relax_range
= 1;
9693 if (sda_rela_sec
== NULL
)
9695 /* Since there is no data sections, we assume the range is page size. */
9696 for (i
= 0; i
< range_number
; i
++)
9698 sdata_range
[i
][0] = sdata_init_range
[i
] - 0x1000;
9699 sdata_range
[i
][1] = sdata_init_range
[i
] - 0x1000;
9704 /* Get the biggest alignment power after the gp located section. */
9705 sec_f
= sda_rela_sec
->output_section
;
9706 sec_b
= sec_f
->next
;
9708 while (sec_b
!= NULL
)
9710 if ((unsigned)(1 << sec_b
->alignment_power
) > align
)
9711 align
= (1 << sec_b
->alignment_power
);
9712 sec_b
= sec_b
->next
;
9715 /* I guess we can not determine the section before
9716 gp located section, so we assume the align is max page size. */
9717 for (i
= 0; i
< range_number
; i
++)
9719 sdata_range
[i
][1] = sdata_init_range
[i
] - align
;
9720 BFD_ASSERT (sdata_range
[i
][1] <= sdata_init_range
[i
]);
9721 sdata_range
[i
][0] = sdata_init_range
[i
] - maxpgsz
;
9722 BFD_ASSERT (sdata_range
[i
][0] <= sdata_init_range
[i
]);
9726 /* These are macros used to check flags encoded in r_addend.
9727 They are only used by nds32_elf_relax_section (). */
9728 #define GET_SEQ_LEN(addend) ((addend) & 0x000000ff)
9729 #define IS_1ST_CONVERT(addend) ((addend) & 0x80000000)
9730 #define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
9731 #define IS_16BIT_ON(addend) ((addend) & 0x20000000)
9733 static const char * unrecognized_reloc_msg
=
9734 /* xgettext:c-format */
9735 N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64
);
9737 /* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
9740 nds32_elf_relax_longcall1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9741 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9742 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9743 Elf_Internal_Shdr
*symtab_hdr
)
9745 /* There are 3 variations for LONGCALL1
9746 case 4-4-2; 16-bit on, optimize off or optimize for space
9747 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9748 ori ta, ta, lo12(symbol) ; LO12S0
9751 case 4-4-4; 16-bit off, optimize don't care
9752 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9753 ori ta, ta, lo12(symbol) ; LO12S0
9756 case 4-4-4; 16-bit on, optimize for speed
9757 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9758 ori ta, ta, lo12(symbol) ; LO12S0
9760 Check code for -mlong-calls output. */
9762 /* Get the reloc for the address from which the register is
9763 being loaded. This reloc will tell us which function is
9764 actually being called. */
9767 int seq_len
; /* Original length of instruction sequence. */
9769 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
9770 bfd_signed_vma foff
;
9773 irelend
= internal_relocs
+ sec
->reloc_count
;
9774 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9775 laddr
= irel
->r_offset
;
9776 *insn_len
= seq_len
;
9778 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9779 R_NDS32_HI20_RELA
, laddr
);
9780 lo_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9781 R_NDS32_LO12S0_ORI_RELA
,
9784 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9786 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL1",
9787 (uint64_t) irel
->r_offset
);
9791 /* Get the value of the symbol referred to by the reloc. */
9792 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
9794 /* This condition only happened when symbol is undefined. */
9796 || foff
< -CONSERVATIVE_24BIT_S1
9797 || foff
>= CONSERVATIVE_24BIT_S1
)
9800 /* Relax to: jal symbol; 25_PCREL. */
9801 /* For simplicity of coding, we are going to modify the section
9802 contents, the section relocs, and the BFD symbol table. We
9803 must tell the rest of the code not to free up this
9804 information. It would be possible to instead create a table
9805 of changes which have to be made, as is done in coff-mips.c;
9806 that would be more work, but would require less memory when
9807 the linker is run. */
9809 /* Replace the long call with a jal. */
9810 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9811 R_NDS32_25_PCREL_RELA
);
9812 irel
->r_addend
= hi_irelfn
->r_addend
;
9814 /* We don't resolve this here but resolve it in relocate_section. */
9816 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9819 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9821 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9826 insn16
= NDS32_NOP16
;
9827 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9829 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
9830 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9836 #define CONVERT_CONDITION_CALL(insn) (((insn) & 0xffff0000) ^ 0x90000)
9837 /* Relax LONGCALL2 relocation for nds32_elf_relax_section. */
9840 nds32_elf_relax_longcall2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9841 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9842 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9843 Elf_Internal_Shdr
*symtab_hdr
)
9845 /* bltz rt, .L1 ; LONGCALL2
9846 jal symbol ; 25_PCREL
9849 /* Get the reloc for the address from which the register is
9850 being loaded. This reloc will tell us which function is
9851 actually being called. */
9855 Elf_Internal_Rela
*i1_irelfn
, *cond_irelfn
, *irelend
;
9856 bfd_signed_vma foff
;
9858 irelend
= internal_relocs
+ sec
->reloc_count
;
9859 laddr
= irel
->r_offset
;
9861 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9862 R_NDS32_25_PCREL_RELA
, laddr
+ 4);
9864 if (i1_irelfn
== irelend
)
9866 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL2",
9867 (uint64_t) irel
->r_offset
);
9871 insn
= bfd_getb32 (contents
+ laddr
);
9873 /* Get the value of the symbol referred to by the reloc. */
9874 foff
= calculate_offset (abfd
, sec
, i1_irelfn
, isymbuf
, symtab_hdr
);
9877 || foff
< -CONSERVATIVE_16BIT_S1
9878 || foff
>= CONSERVATIVE_16BIT_S1
)
9881 /* Relax to bgezal rt, label ; 17_PCREL
9882 or bltzal rt, label ; 17_PCREL */
9884 /* Convert to complimentary conditional call. */
9885 insn
= CONVERT_CONDITION_CALL (insn
);
9887 /* For simplicity of coding, we are going to modify the section
9888 contents, the section relocs, and the BFD symbol table. We
9889 must tell the rest of the code not to free up this
9890 information. It would be possible to instead create a table
9891 of changes which have to be made, as is done in coff-mips.c;
9892 that would be more work, but would require less memory when
9893 the linker is run. */
9895 /* Clean unnessary relocations. */
9897 ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
), R_NDS32_NONE
);
9899 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9900 R_NDS32_17_PCREL_RELA
, laddr
);
9901 if (cond_irelfn
!= irelend
)
9902 cond_irelfn
->r_info
=
9903 ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
), R_NDS32_NONE
);
9905 /* Replace the long call with a bgezal. */
9906 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
),
9907 R_NDS32_17_PCREL_RELA
);
9908 irel
->r_addend
= i1_irelfn
->r_addend
;
9910 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9916 /* Relax LONGCALL3 relocation for nds32_elf_relax_section. */
9919 nds32_elf_relax_longcall3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9920 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9921 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9922 Elf_Internal_Shdr
*symtab_hdr
)
9924 /* There are 3 variations for LONGCALL3
9925 case 4-4-4-2; 16-bit on, optimize off or optimize for space
9926 bltz rt, $1 ; LONGCALL3
9927 sethi ta, hi20(symbol) ; HI20
9928 ori ta, ta, lo12(symbol) ; LO12S0
9932 case 4-4-4-4; 16-bit off, optimize don't care
9933 bltz rt, $1 ; LONGCALL3
9934 sethi ta, hi20(symbol) ; HI20
9935 ori ta, ta, lo12(symbol) ; LO12S0
9939 case 4-4-4-4; 16-bit on, optimize for speed
9940 bltz rt, $1 ; LONGCALL3
9941 sethi ta, hi20(symbol) ; HI20
9942 ori ta, ta, lo12(symbol) ; LO12S0
9946 /* Get the reloc for the address from which the register is
9947 being loaded. This reloc will tell us which function is
9948 actually being called. */
9951 int seq_len
; /* Original length of instruction sequence. */
9953 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
9954 bfd_signed_vma foff
;
9957 irelend
= internal_relocs
+ sec
->reloc_count
;
9958 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9959 laddr
= irel
->r_offset
;
9960 *insn_len
= seq_len
;
9963 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9964 R_NDS32_HI20_RELA
, laddr
+ 4);
9966 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9967 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 8);
9969 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9971 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL3",
9972 (uint64_t) irel
->r_offset
);
9976 /* Get the value of the symbol referred to by the reloc. */
9977 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
9980 || foff
< -CONSERVATIVE_24BIT_S1
9981 || foff
>= CONSERVATIVE_24BIT_S1
)
9984 insn
= bfd_getb32 (contents
+ laddr
);
9985 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9987 /* Relax to bgezal rt, label ; 17_PCREL
9988 or bltzal rt, label ; 17_PCREL */
9990 /* Convert to complimentary conditional call. */
9991 insn
= CONVERT_CONDITION_CALL (insn
);
9992 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9996 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9998 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
10000 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10003 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10004 R_NDS32_17_PCREL_RELA
, laddr
);
10005 if (cond_irelfn
!= irelend
)
10007 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10008 R_NDS32_17_PCREL_RELA
);
10009 cond_irelfn
->r_addend
= hi_irelfn
->r_addend
;
10014 insn16
= NDS32_NOP16
;
10015 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10016 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10018 hi_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10022 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
10024 /* Relax to the following instruction sequence
10025 bltz rt, $1 ; LONGCALL2
10026 jal symbol ; 25_PCREL
10030 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
10032 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10033 R_NDS32_25_PCREL_RELA
);
10035 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL2
);
10037 lo_irelfn
->r_info
=
10038 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10042 insn16
= NDS32_NOP16
;
10043 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10044 lo_irelfn
->r_info
=
10045 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
10046 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10053 /* Relax LONGJUMP1 relocation for nds32_elf_relax_section. */
10056 nds32_elf_relax_longjump1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10057 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10058 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10059 Elf_Internal_Shdr
*symtab_hdr
)
10061 /* There are 3 variations for LONGJUMP1
10062 case 4-4-2; 16-bit bit on, optimize off or optimize for space
10063 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10064 ori ta, ta, lo12(symbol) ; LO12S0
10067 case 4-4-4; 16-bit off, optimize don't care
10068 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10069 ori ta, ta, lo12(symbol) ; LO12S0
10072 case 4-4-4; 16-bit on, optimize for speed
10073 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10074 ori ta, ta, lo12(symbol) ; LO12S0
10077 /* Get the reloc for the address from which the register is
10078 being loaded. This reloc will tell us which function is
10079 actually being called. */
10082 int seq_len
; /* Original length of instruction sequence. */
10083 int insn16_on
; /* 16-bit on/off. */
10085 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
10086 bfd_signed_vma foff
;
10088 unsigned long reloc
;
10090 irelend
= internal_relocs
+ sec
->reloc_count
;
10091 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10092 laddr
= irel
->r_offset
;
10093 *insn_len
= seq_len
;
10094 insn16_on
= IS_16BIT_ON (irel
->r_addend
);
10097 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10098 R_NDS32_HI20_RELA
, laddr
);
10100 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10101 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 4);
10102 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
10104 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP1",
10105 (uint64_t) irel
->r_offset
);
10109 /* Get the value of the symbol referred to by the reloc. */
10110 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
10113 || foff
>= CONSERVATIVE_24BIT_S1
10114 || foff
< -CONSERVATIVE_24BIT_S1
)
10118 && foff
>= -ACCURATE_8BIT_S1
10119 && foff
< ACCURATE_8BIT_S1
10120 && (seq_len
& 0x2))
10123 /* 16-bit on, but not optimized for speed. */
10124 reloc
= R_NDS32_9_PCREL_RELA
;
10126 bfd_putb16 (insn16
, contents
+ irel
->r_offset
);
10129 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10134 reloc
= R_NDS32_25_PCREL_RELA
;
10136 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
10139 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_INSN16
);
10140 irel
->r_addend
= 0;
10143 hi_irelfn
->r_info
=
10144 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
10145 lo_irelfn
->r_info
=
10146 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10148 if ((seq_len
& 0x2) && ((*insn_len
& 2) == 0))
10150 insn16
= NDS32_NOP16
;
10151 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10152 lo_irelfn
->r_info
=
10153 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10155 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10161 /* Revert condition branch. This function does not check if the input
10162 instruction is condition branch or not. */
10165 nds32_elf_convert_branch (uint16_t insn16
, uint32_t insn
,
10166 uint16_t *re_insn16
, uint32_t *re_insn
)
10168 uint32_t comp_insn
= 0;
10169 uint16_t comp_insn16
= 0;
10173 if (N32_OP6 (insn
) == N32_OP6_BR1
)
10176 comp_insn
= (insn
^ 0x4000) & 0xffffc000;
10177 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
)
10179 /* Insn can be contracted to 16-bit implied r5. */
10181 (comp_insn
& 0x4000) ? INSN_BNES38
: INSN_BEQS38
;
10182 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
10185 else if (N32_OP6 (insn
) == N32_OP6_BR3
)
10187 /* bnec $ta, imm11, label. */
10188 comp_insn
= (insn
^ 0x80000) & 0xffffff00;
10192 comp_insn
= (insn
^ 0x10000) & 0xffffc000;
10193 if (N32_BR2_SUB (insn
) == N32_BR2_BEQZ
10194 || N32_BR2_SUB (insn
) == N32_BR2_BNEZ
)
10196 if (N32_IS_RT3 (insn
))
10198 /* Insn can be contracted to 16-bit. */
10200 (comp_insn
& 0x10000) ? INSN_BNEZ38
: INSN_BEQZ38
;
10201 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
10203 else if (N32_RT5 (insn
) == REG_R15
)
10205 /* Insn can be contracted to 16-bit. */
10207 (comp_insn
& 0x10000) ? INSN_BNES38
: INSN_BEQS38
;
10214 switch ((insn16
& 0xf000) >> 12)
10217 /* beqz38 or bnez38 */
10218 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
10219 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNEZ
: INSN_BEQZ
;
10220 comp_insn
|= ((comp_insn16
& 0x0700) >> 8) << 20;
10224 /* beqs38 or bnes38 */
10225 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
10226 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNE
: INSN_BEQ
;
10227 comp_insn
|= (((comp_insn16
& 0x0700) >> 8) << 20)
10232 /* beqzS8 or bnezS8 */
10233 comp_insn16
= (insn16
^ 0x0100) & 0xff00;
10234 comp_insn
= (comp_insn16
& 0x0100) ? INSN_BNEZ
: INSN_BEQZ
;
10235 comp_insn
|= REG_R15
<< 20;
10242 if (comp_insn
&& re_insn
)
10243 *re_insn
= comp_insn
;
10244 if (comp_insn16
&& re_insn16
)
10245 *re_insn16
= comp_insn16
;
10248 /* Relax LONGJUMP2 relocation for nds32_elf_relax_section. */
10251 nds32_elf_relax_longjump2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10252 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10253 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10254 Elf_Internal_Shdr
*symtab_hdr
)
10256 /* There are 3 variations for LONGJUMP2
10257 case 2-4; 1st insn convertible, 16-bit on,
10258 optimize off or optimize for space
10259 bnes38 rt, ra, $1 ; LONGJUMP2
10263 case 4-4; 1st insn not convertible
10264 bne rt, ra, $1 ; LONGJUMP2
10268 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10269 bne rt, ra, $1 ; LONGJUMP2
10273 /* Get the reloc for the address from which the register is
10274 being loaded. This reloc will tell us which function is
10275 actually being called. */
10278 int seq_len
; /* Original length of instruction sequence. */
10279 Elf_Internal_Rela
*i2_irelfn
, *cond_irelfn
, *irelend
;
10282 bfd_signed_vma foff
;
10283 uint32_t insn
, re_insn
= 0;
10284 uint16_t insn16
, re_insn16
= 0;
10285 unsigned long reloc
, cond_reloc
;
10287 enum elf_nds32_reloc_type checked_types
[] =
10288 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
10290 irelend
= internal_relocs
+ sec
->reloc_count
;
10291 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10292 laddr
= irel
->r_offset
;
10293 *insn_len
= seq_len
;
10294 first_size
= (seq_len
== 6) ? 2 : 4;
10297 find_relocs_at_address_addr (irel
, internal_relocs
,
10298 irelend
, R_NDS32_25_PCREL_RELA
,
10299 laddr
+ first_size
);
10301 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10304 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10305 checked_types
[i
], laddr
);
10306 if (cond_irelfn
!= irelend
)
10310 if (i2_irelfn
== irelend
|| cond_irelfn
== irelend
)
10312 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP2",
10313 (uint64_t) irel
->r_offset
);
10317 /* Get the value of the symbol referred to by the reloc. */
10318 foff
= calculate_offset (abfd
, sec
, i2_irelfn
, isymbuf
, symtab_hdr
);
10320 || foff
< -CONSERVATIVE_16BIT_S1
10321 || foff
>= CONSERVATIVE_16BIT_S1
)
10324 /* Get the all corresponding instructions. */
10325 if (first_size
== 4)
10327 insn
= bfd_getb32 (contents
+ laddr
);
10328 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10332 insn16
= bfd_getb16 (contents
+ laddr
);
10333 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10336 if (re_insn16
&& foff
>= -(ACCURATE_8BIT_S1
- first_size
)
10337 && foff
< ACCURATE_8BIT_S1
- first_size
)
10339 if (first_size
== 4)
10341 /* Don't convert it to 16-bit now, keep this as relaxable for
10342 ``label reloc; INSN16''. */
10344 /* Save comp_insn32 to buffer. */
10345 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10347 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
10348 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
10349 cond_reloc
= R_NDS32_INSN16
;
10353 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
10355 reloc
= R_NDS32_9_PCREL_RELA
;
10356 cond_reloc
= R_NDS32_NONE
;
10359 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
10360 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
10361 && foff
< ACCURATE_14BIT_S1
- first_size
))
10363 /* beqs label ; 15_PCREL */
10364 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10366 reloc
= R_NDS32_15_PCREL_RELA
;
10367 cond_reloc
= R_NDS32_NONE
;
10369 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10370 && foff
>= -CONSERVATIVE_16BIT_S1
10371 && foff
< CONSERVATIVE_16BIT_S1
)
10373 /* beqz label ; 17_PCREL */
10374 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10376 reloc
= R_NDS32_17_PCREL_RELA
;
10377 cond_reloc
= R_NDS32_NONE
;
10382 /* Set all relocations. */
10383 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
), reloc
);
10384 irel
->r_addend
= i2_irelfn
->r_addend
;
10386 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
10388 cond_irelfn
->r_addend
= 0;
10390 if ((seq_len
^ *insn_len
) & 0x2)
10392 insn16
= NDS32_NOP16
;
10393 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ 4);
10394 i2_irelfn
->r_offset
= 4;
10395 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
10397 i2_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10401 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
10406 /* Relax LONGJUMP3 relocation for nds32_elf_relax_section. */
10409 nds32_elf_relax_longjump3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10410 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10411 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10412 Elf_Internal_Shdr
*symtab_hdr
)
10414 /* There are 5 variations for LONGJUMP3
10415 case 1: 2-4-4-2; 1st insn convertible, 16-bit on,
10416 optimize off or optimize for space
10417 bnes38 rt, ra, $1 ; LONGJUMP3
10418 sethi ta, hi20(symbol) ; HI20
10419 ori ta, ta, lo12(symbol) ; LO12S0
10423 case 2: 2-4-4-2; 1st insn convertible, 16-bit on, optimize for speed
10424 bnes38 rt, ra, $1 ; LONGJUMP3
10425 sethi ta, hi20(symbol) ; HI20
10426 ori ta, ta, lo12(symbol) ; LO12S0
10430 case 3: 4-4-4-2; 1st insn not convertible, 16-bit on,
10431 optimize off or optimize for space
10432 bne rt, ra, $1 ; LONGJUMP3
10433 sethi ta, hi20(symbol) ; HI20
10434 ori ta, ta, lo12(symbol) ; LO12S0
10438 case 4: 4-4-4-4; 1st insn don't care, 16-bit off, optimize don't care
10439 16-bit off if no INSN16
10440 bne rt, ra, $1 ; LONGJUMP3
10441 sethi ta, hi20(symbol) ; HI20
10442 ori ta, ta, lo12(symbol) ; LO12S0
10446 case 5: 4-4-4-4; 1st insn not convertible, 16-bit on, optimize for speed
10447 16-bit off if no INSN16
10448 bne rt, ra, $1 ; LONGJUMP3
10449 sethi ta, hi20(symbol) ; HI20
10450 ori ta, ta, lo12(symbol) ; LO12S0
10454 /* Get the reloc for the address from which the register is
10455 being loaded. This reloc will tell us which function is
10456 actually being called. */
10457 enum elf_nds32_reloc_type checked_types
[] =
10458 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
10460 int reloc_off
= 0, cond_removed
= 0, convertible
;
10462 int seq_len
; /* Original length of instruction sequence. */
10463 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
10466 bfd_signed_vma foff
;
10467 uint32_t insn
, re_insn
= 0;
10468 uint16_t insn16
, re_insn16
= 0;
10469 unsigned long reloc
, cond_reloc
;
10471 irelend
= internal_relocs
+ sec
->reloc_count
;
10472 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10473 laddr
= irel
->r_offset
;
10474 *insn_len
= seq_len
;
10476 convertible
= IS_1ST_CONVERT (irel
->r_addend
);
10483 /* Get all needed relocations. */
10485 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10486 R_NDS32_HI20_RELA
, laddr
+ first_size
);
10488 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10489 R_NDS32_LO12S0_ORI_RELA
,
10490 laddr
+ first_size
+ 4);
10492 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10495 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10496 checked_types
[i
], laddr
);
10497 if (cond_irelfn
!= irelend
)
10501 if (hi_irelfn
== irelend
10502 || lo_irelfn
== irelend
10503 || cond_irelfn
== irelend
)
10505 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP3",
10506 (uint64_t) irel
->r_offset
);
10510 /* Get the value of the symbol referred to by the reloc. */
10511 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
10514 || foff
< -CONSERVATIVE_24BIT_S1
10515 || foff
>= CONSERVATIVE_24BIT_S1
)
10518 /* Get the all corresponding instructions. */
10519 if (first_size
== 4)
10521 insn
= bfd_getb32 (contents
+ laddr
);
10522 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10526 insn16
= bfd_getb16 (contents
+ laddr
);
10527 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10530 /* For simplicity of coding, we are going to modify the section
10531 contents, the section relocs, and the BFD symbol table. We
10532 must tell the rest of the code not to free up this
10533 information. It would be possible to instead create a table
10534 of changes which have to be made, as is done in coff-mips.c;
10535 that would be more work, but would require less memory when
10536 the linker is run. */
10539 && foff
>= -ACCURATE_8BIT_S1
- first_size
10540 && foff
< ACCURATE_8BIT_S1
- first_size
)
10542 if (!(seq_len
& 0x2))
10544 /* Don't convert it to 16-bit now, keep this as relaxable
10545 for ``label reloc; INSN1a''6. */
10546 /* Save comp_insn32 to buffer. */
10547 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10549 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
10550 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
10551 cond_reloc
= R_NDS32_INSN16
;
10555 /* Not optimize for speed; convert sequence to 16-bit. */
10556 /* Save comp_insn16 to buffer. */
10557 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
10559 reloc
= R_NDS32_9_PCREL_RELA
;
10560 cond_reloc
= R_NDS32_NONE
;
10564 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
10565 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
10566 && foff
< ACCURATE_14BIT_S1
- first_size
))
10568 /* beqs label ; 15_PCREL */
10569 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10571 reloc
= R_NDS32_15_PCREL_RELA
;
10572 cond_reloc
= R_NDS32_NONE
;
10575 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10576 && foff
>= -CONSERVATIVE_16BIT_S1
10577 && foff
< CONSERVATIVE_16BIT_S1
)
10579 /* beqz label ; 17_PCREL */
10580 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10582 reloc
= R_NDS32_17_PCREL_RELA
;
10583 cond_reloc
= R_NDS32_NONE
;
10586 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
10587 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
10589 /* Relax to one of the following 3 variations
10591 case 2-4; 1st insn convertible, 16-bit on, optimize off or optimize
10593 bnes38 rt, $1 ; LONGJUMP2
10597 case 4-4; 1st insn not convertible, others don't care
10598 bne rt, ra, $1 ; LONGJUMP2
10602 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10603 bne rt, ra, $1 ; LONGJUMP2
10607 /* Offset for first instruction. */
10609 /* Use j label as second instruction. */
10610 *insn_len
= 4 + first_size
;
10612 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
10613 reloc
= R_NDS32_LONGJUMP2
;
10614 cond_reloc
= R_NDS32_25_PLTREL
;
10619 if (cond_removed
== 1)
10621 /* Set all relocations. */
10622 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
10623 irel
->r_addend
= hi_irelfn
->r_addend
;
10625 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
10627 cond_irelfn
->r_addend
= 0;
10628 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10633 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10634 irel
->r_addend
= irel
->r_addend
;
10635 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10639 if ((seq_len
^ *insn_len
) & 0x2)
10641 insn16
= NDS32_NOP16
;
10642 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10643 lo_irelfn
->r_offset
= *insn_len
;
10644 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10646 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10650 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10655 /* Relax LONGCALL4 relocation for nds32_elf_relax_section. */
10658 nds32_elf_relax_longcall4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10659 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10660 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10661 Elf_Internal_Shdr
*symtab_hdr
)
10663 /* The pattern for LONGCALL4. Support for function cse.
10664 sethi ta, hi20(symbol) ; LONGCALL4/HI20
10665 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10666 jral ta ; PTR_RES/EMPTY/INSN16 */
10670 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *insn_irel
, *em_irel
, *call_irel
;
10671 Elf_Internal_Rela
*irelend
;
10672 bfd_signed_vma foff
;
10674 irelend
= internal_relocs
+ sec
->reloc_count
;
10675 laddr
= irel
->r_offset
;
10677 /* Get the reloc for the address from which the register is
10678 being loaded. This reloc will tell us which function is
10679 actually being called. */
10680 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10681 R_NDS32_HI20_RELA
, laddr
);
10683 if (hi_irel
== irelend
)
10685 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
10686 (uint64_t) irel
->r_offset
);
10690 /* Get the value of the symbol referred to by the reloc. */
10691 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
);
10693 /* This condition only happened when symbol is undefined. */
10695 || foff
< -CONSERVATIVE_24BIT_S1
10696 || foff
>= CONSERVATIVE_24BIT_S1
)
10699 /* Relax to: jal symbol; 25_PCREL. */
10700 /* For simplicity of coding, we are going to modify the section
10701 contents, the section relocs, and the BFD symbol table. We
10702 must tell the rest of the code not to free up this
10703 information. It would be possible to instead create a table
10704 of changes which have to be made, as is done in coff-mips.c;
10705 that would be more work, but would require less memory when
10706 the linker is run. */
10708 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10709 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10710 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10711 R_NDS32_EMPTY
, irel
->r_addend
);
10713 if (ptr_irel
== irelend
|| em_irel
== irelend
)
10715 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
10716 (uint64_t) irel
->r_offset
);
10719 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10720 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10721 if (insn
& 0x80000000)
10724 /* Replace the long call with a jal. */
10725 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
10726 R_NDS32_25_PCREL_RELA
);
10727 ptr_irel
->r_addend
= 1;
10729 /* We don't resolve this here but resolve it in relocate_section. */
10731 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10734 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10736 /* If there is function cse, HI20 can not remove now. */
10737 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10738 R_NDS32_LONGCALL4
, laddr
);
10739 if (call_irel
== irelend
)
10743 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
10746 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10747 R_NDS32_INSN16
, irel
->r_addend
);
10748 if (insn_irel
!= irelend
)
10749 insn_irel
->r_info
=
10750 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10755 /* Relax LONGCALL5 relocation for nds32_elf_relax_section. */
10758 nds32_elf_relax_longcall5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10759 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10760 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10761 Elf_Internal_Shdr
*symtab_hdr
)
10763 /* The pattern for LONGCALL5.
10764 bltz rt, .L1 ; LONGCALL5/17_PCREL
10765 jal symbol ; 25_PCREL
10770 Elf_Internal_Rela
*cond_irel
, *irelend
;
10771 bfd_signed_vma foff
;
10773 irelend
= internal_relocs
+ sec
->reloc_count
;
10774 laddr
= irel
->r_offset
;
10775 insn
= bfd_getb32 (contents
+ laddr
);
10777 /* Get the reloc for the address from which the register is
10778 being loaded. This reloc will tell us which function is
10779 actually being called. */
10781 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10782 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
10783 if (cond_irel
== irelend
)
10785 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL5",
10786 (uint64_t) irel
->r_offset
);
10790 /* Get the value of the symbol referred to by the reloc. */
10791 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
10794 || foff
< -CONSERVATIVE_16BIT_S1
10795 || foff
>= CONSERVATIVE_16BIT_S1
)
10798 /* Relax to bgezal rt, label ; 17_PCREL
10799 or bltzal rt, label ; 17_PCREL. */
10801 /* Convert to complimentary conditional call. */
10802 insn
= CONVERT_CONDITION_CALL (insn
);
10804 /* For simplicity of coding, we are going to modify the section
10805 contents, the section relocs, and the BFD symbol table. We
10806 must tell the rest of the code not to free up this
10807 information. It would be possible to instead create a table
10808 of changes which have to be made, as is done in coff-mips.c;
10809 that would be more work, but would require less memory when
10810 the linker is run. */
10812 /* Modify relocation and contents. */
10813 cond_irel
->r_info
=
10814 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
10816 /* Replace the long call with a bgezal. */
10817 bfd_putb32 (insn
, contents
+ cond_irel
->r_offset
);
10820 /* Clean unnessary relocations. */
10821 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10823 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10824 R_NDS32_17_PCREL_RELA
, laddr
);
10825 cond_irel
->r_info
=
10826 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10831 /* Relax LONGCALL6 relocation for nds32_elf_relax_section. */
10834 nds32_elf_relax_longcall6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10835 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10836 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10837 Elf_Internal_Shdr
*symtab_hdr
)
10839 /* The pattern for LONGCALL6.
10840 bltz rt, .L1 ; LONGCALL6/17_PCREL
10841 sethi ta, hi20(symbol) ; HI20/PTR
10842 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10843 jral ta ; PTR_RES/EMPTY/INSN16
10848 Elf_Internal_Rela
*em_irel
, *cond_irel
, *irelend
;
10849 bfd_signed_vma foff
;
10851 irelend
= internal_relocs
+ sec
->reloc_count
;
10852 laddr
= irel
->r_offset
;
10854 /* Get the reloc for the address from which the register is
10855 being loaded. This reloc will tell us which function is
10856 actually being called. */
10857 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10858 R_NDS32_EMPTY
, irel
->r_addend
);
10860 if (em_irel
== irelend
)
10862 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL6",
10863 (uint64_t) irel
->r_offset
);
10867 /* Get the value of the symbol referred to by the reloc. */
10868 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
);
10871 || foff
< -CONSERVATIVE_24BIT_S1
10872 || foff
>= CONSERVATIVE_24BIT_S1
)
10875 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10876 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10877 if (insn
& 0x80000000)
10880 insn
= bfd_getb32 (contents
+ laddr
);
10881 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10883 /* Relax to bgezal rt, label ; 17_PCREL
10884 or bltzal rt, label ; 17_PCREL. */
10886 /* Convert to complimentary conditional call. */
10888 insn
= CONVERT_CONDITION_CALL (insn
);
10889 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10892 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
10894 /* Set resolved relocation. */
10896 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10897 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10898 if (cond_irel
== irelend
)
10900 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
10901 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
10904 cond_irel
->r_addend
= 1;
10906 /* Clear relocations. */
10909 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10912 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10913 R_NDS32_17_PCREL_RELA
, laddr
);
10914 if (cond_irel
!= irelend
)
10915 cond_irel
->r_info
=
10916 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10919 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10920 R_NDS32_INSN16
, irel
->r_addend
);
10921 if (cond_irel
!= irelend
)
10922 cond_irel
->r_info
=
10923 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10926 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
10928 /* Relax to the following instruction sequence
10929 bltz rt, .L1 ; LONGCALL2/17_PCREL
10930 jal symbol ; 25_PCREL/PTR_RES
10933 /* Convert instruction. */
10935 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10937 /* Convert relocations. */
10938 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
10939 R_NDS32_25_PCREL_RELA
);
10941 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL5
);
10943 /* Set resolved relocation. */
10945 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10946 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10947 if (cond_irel
== irelend
)
10949 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
10950 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
10953 cond_irel
->r_addend
= 1;
10956 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10957 R_NDS32_INSN16
, irel
->r_addend
);
10958 if (cond_irel
!= irelend
)
10959 cond_irel
->r_info
=
10960 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10965 /* Relax LONGJUMP4 relocation for nds32_elf_relax_section. */
10968 nds32_elf_relax_longjump4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10969 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10970 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10971 Elf_Internal_Shdr
*symtab_hdr
)
10973 /* The pattern for LONGJUMP4.
10974 sethi ta, hi20(symbol) ; LONGJUMP4/HI20
10975 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10976 jr ta ; PTR_RES/INSN16/EMPTY */
10979 int seq_len
; /* Original length of instruction sequence. */
10981 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *em_irel
, *call_irel
, *irelend
;
10982 bfd_signed_vma foff
;
10984 irelend
= internal_relocs
+ sec
->reloc_count
;
10985 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10986 laddr
= irel
->r_offset
;
10987 *insn_len
= seq_len
;
10989 /* Get the reloc for the address from which the register is
10990 being loaded. This reloc will tell us which function is
10991 actually being called. */
10993 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10994 R_NDS32_HI20_RELA
, laddr
);
10996 if (hi_irel
== irelend
)
10998 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
10999 (uint64_t) irel
->r_offset
);
11003 /* Get the value of the symbol referred to by the reloc. */
11004 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
);
11007 || foff
>= CONSERVATIVE_24BIT_S1
11008 || foff
< -CONSERVATIVE_24BIT_S1
)
11011 /* Convert it to "j label", it may be converted to j8 in the final
11012 pass of relaxation. Therefore, we do not consider this currently. */
11013 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11014 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11015 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11016 R_NDS32_EMPTY
, irel
->r_addend
);
11018 if (ptr_irel
== irelend
|| em_irel
== irelend
)
11020 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
11021 (uint64_t) irel
->r_offset
);
11026 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_25_PCREL_RELA
);
11027 ptr_irel
->r_addend
= 1;
11029 /* Write instruction. */
11031 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
11033 /* Clear relocations. */
11034 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11036 /* If there is function cse, HI20 can not remove now. */
11037 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11038 R_NDS32_LONGJUMP4
, laddr
);
11039 if (call_irel
== irelend
)
11043 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
11049 /* Relax LONGJUMP5 relocation for nds32_elf_relax_section. */
11052 nds32_elf_relax_longjump5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11053 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11054 int *seq_len
, bfd_byte
*contents
,
11055 Elf_Internal_Sym
*isymbuf
,
11056 Elf_Internal_Shdr
*symtab_hdr
)
11058 /* There are 2 variations for LONGJUMP5
11059 case 2-4; 1st insn convertible, 16-bit on.
11060 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11061 j label ; 25_PCREL/INSN16
11064 case 4-4; 1st insn not convertible
11065 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11066 j label ; 25_PCREL/INSN16
11070 Elf_Internal_Rela
*cond_irel
, *irelend
;
11072 bfd_signed_vma foff
;
11073 uint32_t insn
, re_insn
= 0;
11074 uint16_t insn16
, re_insn16
= 0;
11075 unsigned long reloc
;
11077 enum elf_nds32_reloc_type checked_types
[] =
11078 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
11079 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
11081 irelend
= internal_relocs
+ sec
->reloc_count
;
11082 laddr
= irel
->r_offset
;
11084 /* Get the reloc for the address from which the register is
11085 being loaded. This reloc will tell us which function is
11086 actually being called. */
11089 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11090 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
11091 if (cond_irel
== irelend
)
11093 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP5",
11094 (uint64_t) irel
->r_offset
);
11098 /* Get the value of the symbol referred to by the reloc. */
11099 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
11102 || foff
< -CONSERVATIVE_16BIT_S1
11103 || foff
>= CONSERVATIVE_16BIT_S1
)
11106 /* Get the all corresponding instructions. */
11107 insn
= bfd_getb32 (contents
+ laddr
);
11108 /* Check instruction size. */
11109 if (insn
& 0x80000000)
11112 insn16
= insn
>> 16;
11113 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
11116 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
11118 if (N32_OP6 (re_insn
) == N32_OP6_BR1
11119 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
11121 /* beqs label ; 15_PCREL. */
11122 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11123 reloc
= R_NDS32_15_PCREL_RELA
;
11125 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
11126 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
11128 /* beqz label ; 17_PCREL. */
11129 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11130 reloc
= R_NDS32_17_PCREL_RELA
;
11132 else if ( N32_OP6 (re_insn
) == N32_OP6_BR3
11133 && foff
>= -CONSERVATIVE_8BIT_S1
&& foff
< CONSERVATIVE_8BIT_S1
)
11135 /* beqc label ; 9_PCREL. */
11136 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11137 reloc
= R_NDS32_WORD_9_PCREL_RELA
;
11142 /* Set all relocations. */
11143 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), reloc
);
11145 /* Clean relocations. */
11146 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11147 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11149 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11150 checked_types
[i
], laddr
);
11151 if (cond_irel
!= irelend
)
11154 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
11156 /* If the branch instruction is 2 byte, it cannot remove
11157 directly. Only convert it to nop16 and remove it after
11158 checking alignment issue. */
11159 insn16
= NDS32_NOP16
;
11160 bfd_putb16 (insn16
, contents
+ laddr
);
11161 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11164 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11173 /* Relax LONGJUMP6 relocation for nds32_elf_relax_section. */
11176 nds32_elf_relax_longjump6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11177 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11178 int *seq_len
, bfd_byte
*contents
,
11179 Elf_Internal_Sym
*isymbuf
,
11180 Elf_Internal_Shdr
*symtab_hdr
)
11182 /* There are 5 variations for LONGJUMP6
11183 case : 2-4-4-4; 1st insn convertible, 16-bit on.
11184 bnes38 rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11185 sethi ta, hi20(symbol) ; HI20/PTR
11186 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11187 jr ta ; PTR_RES/INSN16/EMPTY
11190 case : 4-4-4-4; 1st insn not convertible, 16-bit on.
11191 bne rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11192 sethi ta, hi20(symbol) ; HI20/PTR
11193 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11194 jr ta ; PTR_RES/INSN16/EMPTY
11197 enum elf_nds32_reloc_type checked_types
[] =
11198 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
11199 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
11201 int reloc_off
= 0, cond_removed
= 0;
11203 Elf_Internal_Rela
*cond_irel
, *em_irel
, *irelend
, *insn_irel
;
11205 bfd_signed_vma foff
;
11206 uint32_t insn
, re_insn
= 0;
11207 uint16_t insn16
, re_insn16
= 0;
11208 unsigned long reloc
;
11210 irelend
= internal_relocs
+ sec
->reloc_count
;
11211 laddr
= irel
->r_offset
;
11213 /* Get the reloc for the address from which the register is
11214 being loaded. This reloc will tell us which function is
11215 actually being called. */
11216 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11217 R_NDS32_EMPTY
, irel
->r_addend
);
11219 if (em_irel
== irelend
)
11221 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP6",
11222 (uint64_t) irel
->r_offset
);
11226 /* Get the value of the symbol referred to by the reloc. */
11227 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
);
11230 || foff
< -CONSERVATIVE_24BIT_S1
11231 || foff
>= CONSERVATIVE_24BIT_S1
)
11234 insn
= bfd_getb32 (contents
+ laddr
);
11235 /* Check instruction size. */
11236 if (insn
& 0x80000000)
11239 insn16
= insn
>> 16;
11240 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
11243 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
11245 /* For simplicity of coding, we are going to modify the section
11246 contents, the section relocs, and the BFD symbol table. We
11247 must tell the rest of the code not to free up this
11248 information. It would be possible to instead create a table
11249 of changes which have to be made, as is done in coff-mips.c;
11250 that would be more work, but would require less memory when
11251 the linker is run. */
11253 if (N32_OP6 (re_insn
) == N32_OP6_BR1
11254 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
11256 /* beqs label ; 15_PCREL. */
11257 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
11258 reloc
= R_NDS32_15_PCREL_RELA
;
11261 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
11262 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
11264 /* beqz label ; 17_PCREL. */
11265 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
11266 reloc
= R_NDS32_17_PCREL_RELA
;
11269 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
11270 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
11272 /* Relax to one of the following 2 variations
11274 case 2-4; 1st insn convertible, 16-bit on.
11275 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11276 j label ; 25_PCREL/INSN16
11279 case 4-4; 1st insn not convertible
11280 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11281 j label ; 25_PCREL/INSN16
11284 /* Use j label as second instruction. */
11286 reloc
= R_NDS32_25_PCREL_RELA
;
11287 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
11292 /* Set all relocations. */
11293 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), reloc
);
11296 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11297 R_NDS32_PTR_RESOLVED
, em_irel
->r_offset
);
11298 cond_irel
->r_addend
= 1;
11300 /* Use INSN16 of first branch instruction to distinguish if keeping
11301 INSN16 of final instruction or not. */
11302 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11303 R_NDS32_INSN16
, irel
->r_offset
);
11304 if (insn_irel
== irelend
)
11306 /* Clean the final INSN16. */
11308 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11309 R_NDS32_INSN16
, em_irel
->r_offset
);
11310 insn_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11314 if (cond_removed
== 1)
11318 /* Clear relocations. */
11319 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11321 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11324 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11325 checked_types
[i
], laddr
);
11326 if (cond_irel
!= irelend
)
11329 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
11331 /* If the branch instruction is 2 byte, it cannot remove
11332 directly. Only convert it to nop16 and remove it after
11333 checking alignment issue. */
11334 insn16
= NDS32_NOP16
;
11335 bfd_putb16 (insn16
, contents
+ laddr
);
11336 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11339 cond_irel
->r_info
=
11340 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
11346 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11347 R_NDS32_LONGJUMP5
);
11353 /* Relax LONGJUMP7 relocation for nds32_elf_relax_section. */
11356 nds32_elf_relax_longjump7 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11357 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11358 int *seq_len
, bfd_byte
*contents
,
11359 Elf_Internal_Sym
*isymbuf
,
11360 Elf_Internal_Shdr
*symtab_hdr
)
11362 /* There are 2 variations for LONGJUMP5
11363 case 2-4; 1st insn convertible, 16-bit on.
11364 movi55 ta, imm11 ; LONGJUMP7/INSN16
11365 beq rt, ta, label ; 15_PCREL
11367 case 4-4; 1st insn not convertible
11368 movi55 ta, imm11 ; LONGJUMP7/INSN16
11369 beq rt, ta, label ; 15_PCREL */
11372 Elf_Internal_Rela
*cond_irel
, *irelend
, *insn_irel
;
11373 bfd_signed_vma foff
;
11374 uint32_t insn
, re_insn
= 0;
11378 irelend
= internal_relocs
+ sec
->reloc_count
;
11379 laddr
= irel
->r_offset
;
11381 /* Get the reloc for the address from which the register is
11382 being loaded. This reloc will tell us which function is
11383 actually being called. */
11386 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11387 R_NDS32_15_PCREL_RELA
, irel
->r_addend
);
11388 if (cond_irel
== irelend
)
11390 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP7",
11391 (uint64_t) irel
->r_offset
);
11395 /* Get the value of the symbol referred to by the reloc. */
11396 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
11399 || foff
< -CONSERVATIVE_8BIT_S1
11400 || foff
>= CONSERVATIVE_8BIT_S1
)
11403 /* Get the first instruction for its size. */
11404 insn
= bfd_getb32 (contents
+ laddr
);
11405 if (insn
& 0x80000000)
11408 /* Get the immediate from movi55. */
11409 imm11
= N16_IMM5S (insn
>> 16);
11413 /* Get the immediate from movi. */
11414 imm11
= N32_IMM20S (insn
);
11417 /* Get the branch instruction. */
11418 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
11419 /* Convert instruction to BR3. */
11420 if ((insn
>> 14) & 0x1)
11421 re_insn
= N32_BR3 (BNEC
, N32_RT5 (insn
), imm11
, 0);
11423 re_insn
= N32_BR3 (BEQC
, N32_RT5 (insn
), imm11
, 0);
11425 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11427 /* Set all relocations. */
11428 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11429 R_NDS32_WORD_9_PCREL_RELA
);
11431 /* Clean relocations. */
11432 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11433 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11434 R_NDS32_INSN16
, irel
->r_offset
);
11435 if (insn_irel
!= irelend
)
11439 /* If the first insntruction is 16bit, convert it to nop16. */
11440 insn16
= NDS32_NOP16
;
11441 bfd_putb16 (insn16
, contents
+ laddr
);
11442 insn_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11445 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11453 /* We figure out and reassign the best gp value in nds32_elf_final_sda_base
11454 for each relax round. But the gp may changed dramatically and then cause
11455 the truncated to fit errors for the the converted gp instructions.
11456 Therefore, we must reserve the minimum but safe enough size to prevent it. */
11459 nds32_elf_relax_guard (bfd_vma
*access_addr
, bfd_vma local_sda
, asection
*sec
,
11460 Elf_Internal_Rela
*irel
, bfd_boolean
*again
,
11462 struct elf_nds32_link_hash_table
*table
,
11463 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
11467 static bfd_boolean sec_pass
= FALSE
;
11468 static asection
*first_sec
= NULL
, *sym_sec
;
11469 /* Record the number of instructions which may be removed. */
11470 static int count
= 0, record_count
;
11471 Elf_Internal_Sym
*isym
;
11472 struct elf_link_hash_entry
*h
= NULL
;
11474 unsigned long r_symndx
;
11475 bfd
*abfd
= sec
->owner
;
11476 static bfd_vma record_sda
= 0;
11477 int sda_offset
= 0;
11479 /* Force doing relaxation when hyper-relax is high. */
11480 if (table
->hyper_relax
== 2)
11483 /* Do not relax the load/store patterns for the first
11489 else if (first_sec
== sec
)
11491 record_count
= count
;
11502 /* Generally, _SDA_BASE_ is fixed or smaller. But the large
11503 DATA_SEGMENT_ALIGN size in the linker script may make it
11504 get even bigger. */
11505 if (record_sda
== 0)
11506 record_sda
= local_sda
;
11507 else if (local_sda
> record_sda
)
11508 sda_offset
= local_sda
- record_sda
;
11510 /* Assume the instruction will be removed in the best case. */
11513 /* We record the offset to gp for each symbol, and then check
11514 if it is changed dramatically after relaxing.
11515 (global symbol): elf32_nds32_hash_entry (h)->offset_to_gp
11516 (local symbol) : elf32_nds32_local_gp_offset (abfd)[r_symndx]. */
11517 r_symndx
= ELF32_R_SYM (irel
->r_info
);
11518 if (r_symndx
>= symtab_hdr
->sh_info
)
11520 /* Global symbols. */
11521 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
11522 h
= elf_sym_hashes (abfd
)[indx
];
11523 sym_sec
= h
->root
.u
.def
.section
;
11524 if (NDS32_GUARD_SEC_P (sym_sec
->flags
)
11525 || bfd_is_abs_section (sym_sec
))
11527 /* Forbid doing relaxation when hyper-relax is low. */
11528 if (table
->hyper_relax
== 0)
11531 offset_to_gp
= *access_addr
- local_sda
;
11532 if (elf32_nds32_hash_entry (h
)->offset_to_gp
== 0)
11533 elf32_nds32_hash_entry (h
)->offset_to_gp
= offset_to_gp
;
11534 else if (abs (elf32_nds32_hash_entry (h
)->offset_to_gp
)
11535 < abs (offset_to_gp
) - sda_offset
)
11537 /* This may cause the error, so we reserve the
11538 safe enough size for relaxing. */
11539 if (*access_addr
>= local_sda
)
11540 *access_addr
+= (record_count
* 4);
11542 *access_addr
-= (record_count
* 4);
11549 /* Local symbols. */
11550 if (!elf32_nds32_allocate_local_sym_info (abfd
))
11552 isym
= isymbuf
+ r_symndx
;
11554 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
11555 if (NDS32_GUARD_SEC_P (sym_sec
->flags
))
11557 /* Forbid doing relaxation when hyper-relax is low. */
11558 if (table
->hyper_relax
== 0)
11561 offset_to_gp
= *access_addr
- local_sda
;
11562 if (elf32_nds32_local_gp_offset (abfd
)[r_symndx
] == 0)
11563 elf32_nds32_local_gp_offset (abfd
)[r_symndx
] = offset_to_gp
;
11564 else if (abs (elf32_nds32_local_gp_offset (abfd
)[r_symndx
])
11565 < abs (offset_to_gp
) - sda_offset
)
11567 /* This may cause the error, so we reserve the
11568 safe enough size for relaxing. */
11569 if (*access_addr
>= local_sda
)
11570 *access_addr
+= (record_count
* 4);
11572 *access_addr
-= (record_count
* 4);
11581 #define GET_LOADSTORE_RANGE(addend) (((addend) >> 8) & 0x3f)
11583 /* Relax LOADSTORE relocation for nds32_elf_relax_section. */
11586 nds32_elf_relax_loadstore (struct bfd_link_info
*link_info
, bfd
*abfd
,
11587 asection
*sec
, Elf_Internal_Rela
*irel
,
11588 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11589 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11590 Elf_Internal_Shdr
*symtab_hdr
, int load_store_relax
,
11591 struct elf_nds32_link_hash_table
*table
)
11593 int eliminate_sethi
= 0, range_type
;
11595 bfd_vma local_sda
, laddr
;
11596 int seq_len
; /* Original length of instruction sequence. */
11598 Elf_Internal_Rela
*hi_irelfn
= NULL
, *irelend
;
11599 bfd_vma access_addr
= 0;
11600 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11601 struct elf_link_hash_entry
*h
= NULL
;
11603 enum elf_nds32_reloc_type checked_types
[] =
11604 { R_NDS32_HI20_RELA
, R_NDS32_GOT_HI20
,
11605 R_NDS32_GOTPC_HI20
, R_NDS32_GOTOFF_HI20
,
11606 R_NDS32_PLTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
,
11607 R_NDS32_TLS_LE_HI20
11610 irelend
= internal_relocs
+ sec
->reloc_count
;
11611 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
11612 laddr
= irel
->r_offset
;
11613 *insn_len
= seq_len
;
11615 /* Get the high part relocation. */
11616 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11618 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11619 checked_types
[i
], laddr
);
11620 if (hi_irelfn
!= irelend
)
11624 if (hi_irelfn
== irelend
)
11626 /* Not R_NDS32_HI20_RELA. */
11628 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LOADSTORE",
11629 (uint64_t) irel
->r_offset
);
11633 range_type
= GET_LOADSTORE_RANGE (irel
->r_addend
);
11634 nds32_elf_final_sda_base (sec
->output_section
->owner
,
11635 link_info
, &local_sda
, FALSE
);
11637 switch (ELF32_R_TYPE (hi_irelfn
->r_info
))
11639 case R_NDS32_HI20_RELA
:
11640 insn
= bfd_getb32 (contents
+ laddr
);
11642 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
11644 if (ELF32_R_SYM (hi_irelfn
->r_info
) >= symtab_hdr
->sh_info
)
11646 indx
= ELF32_R_SYM (hi_irelfn
->r_info
) - symtab_hdr
->sh_info
;
11647 h
= elf_sym_hashes (abfd
)[indx
];
11651 if (range_type
== NDS32_LOADSTORE_IMM
11652 && access_addr
< CONSERVATIVE_20BIT
11653 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
11655 eliminate_sethi
= 1;
11659 if (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0)
11661 eliminate_sethi
= 1;
11664 else if (!nds32_elf_relax_guard (&access_addr
, local_sda
, sec
, hi_irelfn
,
11665 NULL
, FALSE
, table
, isymbuf
, symtab_hdr
))
11668 if (!load_store_relax
)
11671 /* Case for set gp register. */
11672 if (N32_RT5 (insn
) == REG_GP
)
11675 if (range_type
== NDS32_LOADSTORE_FLOAT_S
11676 || range_type
== NDS32_LOADSTORE_FLOAT_D
)
11678 range_l
= sdata_range
[0][0];
11679 range_h
= sdata_range
[0][1];
11683 range_l
= sdata_range
[1][0];
11684 range_h
= sdata_range
[1][1];
11692 /* Delete sethi instruction. */
11693 if (eliminate_sethi
== 1
11694 || (local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11695 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
11697 hi_irelfn
->r_info
=
11698 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
11700 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11708 /* Relax LO12 relocation for nds32_elf_relax_section. */
11711 nds32_elf_relax_lo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
11712 asection
*sec
, Elf_Internal_Rela
*irel
,
11713 Elf_Internal_Rela
*internal_relocs
, bfd_byte
*contents
,
11714 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
,
11715 struct elf_nds32_link_hash_table
*table
)
11718 bfd_vma local_sda
, laddr
;
11719 unsigned long reloc
;
11720 bfd_vma access_addr
;
11721 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11722 Elf_Internal_Rela
*irelfn
= NULL
, *irelend
;
11723 struct elf_link_hash_entry
*h
= NULL
;
11726 /* For SDA base relative relaxation. */
11727 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11728 &local_sda
, FALSE
);
11730 irelend
= internal_relocs
+ sec
->reloc_count
;
11731 laddr
= irel
->r_offset
;
11732 insn
= bfd_getb32 (contents
+ laddr
);
11734 if (!is_sda_access_insn (insn
) && N32_OP6 (insn
) != N32_OP6_ORI
)
11737 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11739 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
11741 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
11742 h
= elf_sym_hashes (abfd
)[indx
];
11746 if (N32_OP6 (insn
) == N32_OP6_ORI
&& access_addr
< CONSERVATIVE_20BIT
11747 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
11749 reloc
= R_NDS32_20_RELA
;
11750 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11751 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
11752 bfd_putb32 (insn
, contents
+ laddr
);
11756 if (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0)
11758 /* Fall through. */
11760 else if (!nds32_elf_relax_guard (&access_addr
, local_sda
, sec
, irel
, NULL
,
11761 FALSE
, table
, isymbuf
, symtab_hdr
))
11764 range_l
= sdata_range
[1][0];
11765 range_h
= sdata_range
[1][1];
11766 switch (ELF32_R_TYPE (irel
->r_info
))
11768 case R_NDS32_LO12S0_RELA
:
11769 reloc
= R_NDS32_SDA19S0_RELA
;
11771 case R_NDS32_LO12S1_RELA
:
11772 reloc
= R_NDS32_SDA18S1_RELA
;
11774 case R_NDS32_LO12S2_RELA
:
11775 reloc
= R_NDS32_SDA17S2_RELA
;
11777 case R_NDS32_LO12S2_DP_RELA
:
11778 range_l
= sdata_range
[0][0];
11779 range_h
= sdata_range
[0][1];
11780 reloc
= R_NDS32_SDA12S2_DP_RELA
;
11782 case R_NDS32_LO12S2_SP_RELA
:
11783 range_l
= sdata_range
[0][0];
11784 range_h
= sdata_range
[0][1];
11785 reloc
= R_NDS32_SDA12S2_SP_RELA
;
11791 /* There are range_h and range_l because linker has to promise
11792 all sections move cross one page together. */
11793 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11794 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
)
11795 || (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0))
11797 if (N32_OP6 (insn
) == N32_OP6_ORI
&& N32_RT5 (insn
) == REG_GP
)
11799 /* Maybe we should add R_NDS32_INSN16 reloc type here
11800 or manually do some optimization. sethi can't be
11801 eliminated when updating $gp so the relative ori
11802 needs to be preserved. */
11805 if (!turn_insn_to_sda_access (insn
, ELF32_R_TYPE (irel
->r_info
),
11808 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11809 bfd_putb32 (insn
, contents
+ laddr
);
11811 irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11813 /* SDA17 must keep INSN16 for converting fp_as_gp. */
11814 if (irelfn
!= irelend
&& reloc
!= R_NDS32_SDA17S2_RELA
)
11816 ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_NDS32_NONE
);
11823 /* Relax PTR relocation for nds32_elf_relax_section. */
11826 nds32_elf_relax_ptr (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11827 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11828 int *seq_len
, bfd_byte
*contents
)
11830 Elf_Internal_Rela
*ptr_irel
, *irelend
, *count_irel
, *re_irel
;
11832 irelend
= internal_relocs
+ sec
->reloc_count
;
11835 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11836 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11838 if (re_irel
== irelend
)
11840 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_PTR",
11841 (uint64_t) irel
->r_offset
);
11845 if (re_irel
->r_addend
!= 1)
11848 /* Pointed target is relaxed and no longer needs this void *,
11849 change the type to NONE. */
11850 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11852 /* Find PTR_COUNT to decide remove it or not. If PTR_COUNT does
11853 not exist, it means only count 1 and remove it directly. */
11854 /* TODO: I hope we can obsolate R_NDS32_COUNT in the future. */
11855 count_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11856 R_NDS32_PTR_COUNT
);
11857 ptr_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11859 if (count_irel
!= irelend
)
11861 if (--count_irel
->r_addend
> 0)
11865 if (ptr_irel
!= irelend
)
11868 /* If the PTR_COUNT is already 0, remove current instruction. */
11869 *seq_len
= nds32_elf_insn_size (abfd
, contents
, irel
->r_offset
);
11874 /* Relax LWC relocation for nds32_elf_relax_section. */
11877 nds32_elf_relax_flsi (struct bfd_link_info
*link_info
, bfd
*abfd
,
11878 asection
*sec
, Elf_Internal_Rela
*irel
,
11879 Elf_Internal_Rela
*internal_relocs
,
11880 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11881 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11884 sethi ra, hi20(symbol) ; HI20/LOADSTORE
11885 ori ra, ra, lo12(symbol) ; LO12S0/PTR/PTR/.../INSN16
11886 flsi fsa, [ra + offset1] ; LSI/PTR_RESOLVED/INSN16
11887 flsi fsb, [ra + offset2] ; LSI/PTR_RESOLVED/INSN16
11891 bfd_vma local_sda
, laddr
;
11892 unsigned long reloc
;
11893 bfd_vma access_addr
, flsi_offset
;
11894 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11895 Elf_Internal_Rela
*irelend
, *re_irel
;
11896 unsigned int opcode
;
11898 irelend
= internal_relocs
+ sec
->reloc_count
;
11899 laddr
= irel
->r_offset
;
11900 insn
= bfd_getb32 (contents
+ laddr
);
11902 if ((insn
& 0x80000000) || !is_sda_access_insn (insn
))
11905 /* Can not do relaxation for bi format. */
11906 if ((insn
& 0x1000))
11909 /* Only deal with flsi, fssi, fldi, fsdi, so far. */
11910 opcode
= N32_OP6 (insn
);
11911 if ((opcode
== N32_OP6_LWC
) || (opcode
== N32_OP6_SWC
))
11912 reloc
= R_NDS32_SDA12S2_SP_RELA
;
11913 else if ((opcode
== N32_OP6_LDC
) || (opcode
== N32_OP6_SDC
))
11914 reloc
= R_NDS32_SDA12S2_DP_RELA
;
11918 re_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11919 R_NDS32_PTR_RESOLVED
);
11920 if (re_irel
== irelend
)
11922 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LSI",
11923 (uint64_t) irel
->r_offset
);
11927 /* For SDA base relative relaxation. */
11928 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11929 &local_sda
, FALSE
);
11930 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11931 flsi_offset
= (insn
& 0xfff) << 2;
11932 access_addr
+= flsi_offset
;
11933 range_l
= sdata_range
[0][0];
11934 range_h
= sdata_range
[0][1];
11936 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11937 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
11939 /* Turn flsi instruction into sda access format. */
11940 insn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
11942 /* Add relocation type to flsi. */
11943 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11944 irel
->r_addend
+= flsi_offset
;
11945 bfd_putb32 (insn
, contents
+ re_irel
->r_offset
);
11947 re_irel
->r_addend
|= 1;
11953 nds32_relax_adjust_label (bfd
*abfd
, asection
*sec
,
11954 Elf_Internal_Rela
*internal_relocs
,
11955 bfd_byte
*contents
,
11956 nds32_elf_blank_t
**relax_blank_list
,
11957 int optimize
, int opt_size
)
11959 /* This code block is used to adjust 4-byte alignment by relax a pair
11960 of instruction a time.
11962 It recognizes three types of relocations.
11963 1. R_NDS32_LABEL - a alignment.
11964 2. R_NDS32_INSN16 - relax a 32-bit instruction to 16-bit.
11965 3. is_16bit_NOP () - remove a 16-bit instruction. */
11967 /* TODO: It seems currently implementation only support 4-byte alignment.
11968 We should handle any-alignment. */
11970 Elf_Internal_Rela
*insn_rel
= NULL
, *label_rel
= NULL
, *irel
;
11971 Elf_Internal_Rela
*tmp_rel
, *tmp2_rel
= NULL
;
11972 Elf_Internal_Rela rel_temp
;
11973 Elf_Internal_Rela
*irelend
;
11977 /* Checking for branch relaxation relies on the relocations to
11978 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
11979 nds32_insertion_sort (internal_relocs
, sec
->reloc_count
,
11980 sizeof (Elf_Internal_Rela
), compar_reloc
);
11982 irelend
= internal_relocs
+ sec
->reloc_count
;
11984 /* Force R_NDS32_LABEL before R_NDS32_INSN16. */
11985 /* FIXME: Can we generate the right order in assembler?
11986 So we don't have to swapping them here. */
11988 for (label_rel
= internal_relocs
, insn_rel
= internal_relocs
;
11989 label_rel
< irelend
; label_rel
++)
11991 if (ELF32_R_TYPE (label_rel
->r_info
) != R_NDS32_LABEL
)
11994 /* Find the first reloc has the same offset with label_rel. */
11995 while (insn_rel
< irelend
&& insn_rel
->r_offset
< label_rel
->r_offset
)
11998 for (;insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
;
12000 /* Check if there were R_NDS32_INSN16 and R_NDS32_LABEL at the same
12002 if (ELF32_R_TYPE (insn_rel
->r_info
) == R_NDS32_INSN16
)
12005 if (insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
12006 && insn_rel
< label_rel
)
12008 /* Swap the two reloc if the R_NDS32_INSN16 is
12009 before R_NDS32_LABEL. */
12010 memcpy (&rel_temp
, insn_rel
, sizeof (Elf_Internal_Rela
));
12011 memcpy (insn_rel
, label_rel
, sizeof (Elf_Internal_Rela
));
12012 memcpy (label_rel
, &rel_temp
, sizeof (Elf_Internal_Rela
));
12018 /* If there were a sequence of R_NDS32_LABEL end up with .align 2
12019 or higher, remove other R_NDS32_LABEL with lower alignment.
12020 If an R_NDS32_INSN16 in between R_NDS32_LABELs must be converted,
12021 then the R_NDS32_LABEL sequence is broke. */
12022 for (tmp_rel
= internal_relocs
; tmp_rel
< irelend
; tmp_rel
++)
12024 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_LABEL
)
12026 if (label_rel
== NULL
)
12028 if (tmp_rel
->r_addend
< 2)
12029 label_rel
= tmp_rel
;
12032 else if (tmp_rel
->r_addend
> 1)
12034 /* Remove all LABEL relocation from label_rel to tmp_rel
12035 including relocations with same offset as tmp_rel. */
12036 for (tmp2_rel
= label_rel
; tmp2_rel
< tmp_rel
; tmp2_rel
++)
12038 if (tmp2_rel
->r_offset
== tmp_rel
->r_offset
)
12041 if (ELF32_R_TYPE (tmp2_rel
->r_info
) == R_NDS32_LABEL
12042 && tmp2_rel
->r_addend
< 2)
12044 ELF32_R_INFO (ELF32_R_SYM (tmp2_rel
->r_info
),
12050 else if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
&& label_rel
)
12052 /* A new INSN16 which can be converted, so clear label_rel. */
12053 if (is_convert_32_to_16 (abfd
, sec
, tmp_rel
, internal_relocs
,
12055 || is_16bit_NOP (abfd
, sec
, tmp_rel
))
12062 /* Optimized for speed and nothing has not been relaxed.
12063 It's time to align labels.
12064 We may convert a 16-bit instruction right before a label to
12065 32-bit, in order to align the label if necessary
12066 all reloc entries has been sorted by r_offset. */
12067 for (irel
= internal_relocs
;
12068 irel
< irelend
&& irel
->r_offset
< sec
->size
; irel
++)
12070 if (ELF32_R_TYPE (irel
->r_info
) != R_NDS32_INSN16
12071 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
)
12074 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_INSN16
)
12076 /* A new INSN16 found, resize the old one. */
12077 if (is_convert_32_to_16
12078 (abfd
, sec
, irel
, internal_relocs
, irelend
, &insn16
)
12079 || is_16bit_NOP (abfd
, sec
, irel
))
12083 /* Previous INSN16 reloc exists, reduce its
12085 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
12088 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
12089 internal_relocs
, irelend
, insn16
);
12091 if (!insert_nds32_elf_blank_recalc_total
12092 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12095 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12097 if (!insert_nds32_elf_blank_recalc_total
12098 (relax_blank_list
, insn_rel
->r_offset
, 2))
12102 ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
), R_NDS32_NONE
);
12104 /* Save the new one for later use. */
12108 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
12111 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
)
12113 /* Search for label. */
12114 int force_relax
= 0;
12116 /* Label on 16-bit instruction or optimization
12117 needless, just reset this reloc. */
12118 insn16
= bfd_getb16 (contents
+ irel
->r_offset
);
12119 if ((irel
->r_addend
& 0x1f) < 2 && (!optimize
|| (insn16
& 0x8000)))
12122 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
12127 irel
->r_offset
- get_nds32_elf_blank_total (relax_blank_list
,
12128 irel
->r_offset
, 1);
12132 /* Check if there is case which can not be aligned. */
12133 if (irel
->r_addend
== 2 && address
& 0x2)
12138 /* Try to align this label. */
12140 if ((irel
->r_addend
& 0x1f) < 2)
12142 /* Check if there is a INSN16 at the same address.
12143 Label_rel always seats before insn_rel after
12146 /* Search for INSN16 at LABEL location. If INSN16 is at
12147 same location and this LABEL alignment is lower than 2,
12148 the INSN16 can be converted to 2-byte. */
12149 for (tmp_rel
= irel
;
12150 tmp_rel
< irelend
&& tmp_rel
->r_offset
== irel
->r_offset
;
12153 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
12154 && (is_convert_32_to_16
12155 (abfd
, sec
, tmp_rel
, internal_relocs
,
12157 || is_16bit_NOP (abfd
, sec
, tmp_rel
)))
12165 if (force_relax
|| irel
->r_addend
== 1 || address
& 0x2)
12167 /* Label not aligned. */
12168 /* Previous reloc exists, reduce its size to 16-bit. */
12169 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
,
12170 internal_relocs
, irelend
, &insn16
))
12172 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
12173 internal_relocs
, irelend
, insn16
);
12175 if (!insert_nds32_elf_blank_recalc_total
12176 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12179 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12181 if (!insert_nds32_elf_blank_recalc_total
12182 (relax_blank_list
, insn_rel
->r_offset
, 2))
12187 /* INSN16 reloc is used. */
12193 sec
->size
- get_nds32_elf_blank_total (relax_blank_list
, sec
->size
, 0);
12194 if (insn_rel
&& (address
& 0x2 || opt_size
))
12196 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
12199 nds32_elf_write_16 (abfd
, contents
, insn_rel
, internal_relocs
,
12201 if (!insert_nds32_elf_blank_recalc_total
12202 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12204 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
12207 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12209 if (!insert_nds32_elf_blank_recalc_total
12210 (relax_blank_list
, insn_rel
->r_offset
, 2))
12212 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
12221 nds32_elf_relax_section (bfd
*abfd
, asection
*sec
,
12222 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
12224 nds32_elf_blank_t
*relax_blank_list
= NULL
;
12225 Elf_Internal_Shdr
*symtab_hdr
;
12226 Elf_Internal_Rela
*internal_relocs
;
12227 Elf_Internal_Rela
*irel
;
12228 Elf_Internal_Rela
*irelend
;
12229 Elf_Internal_Sym
*isymbuf
= NULL
;
12230 bfd_byte
*contents
= NULL
;
12231 bfd_boolean result
= TRUE
;
12237 /* Target dependnet option. */
12238 struct elf_nds32_link_hash_table
*table
;
12239 int load_store_relax
;
12241 relax_blank_list
= NULL
;
12245 /* Nothing to do for
12246 * relocatable link or
12247 * non-relocatable section or
12248 * non-code section or
12250 * no reloc entry. */
12251 if (bfd_link_relocatable (link_info
)
12252 || (sec
->flags
& SEC_RELOC
) == 0
12253 || (sec
->flags
& SEC_EXCLUDE
) != 0
12254 || (sec
->flags
& SEC_CODE
) == 0
12256 || sec
->reloc_count
== 0)
12259 /* 09.12.11 Workaround. */
12260 /* We have to adjust align for R_NDS32_LABEL if needed.
12261 The adjust approach only can fix 2-byte align once. */
12262 if (sec
->alignment_power
> 2)
12265 /* Do TLS model conversion once at first. */
12266 nds32_elf_unify_tls_model (abfd
, sec
, contents
, link_info
);
12268 /* The optimization type to do. */
12270 table
= nds32_elf_hash_table (link_info
);
12272 /* Save the first section for abs symbol relaxation.
12273 This is used for checking gp relaxation in the
12274 nds32_elf_relax_loadstore and nds32_elf_relax_lo12. */
12275 nds32_elf_relax_guard (NULL
, 0, sec
, NULL
, again
, TRUE
,
12276 table
, NULL
, NULL
);
12278 /* The begining of general relaxation. */
12280 if (is_SDA_BASE_set
== 0)
12283 is_SDA_BASE_set
= 1;
12284 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
12286 relax_range_measurement (abfd
);
12289 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12290 /* Relocations MUST be kept in memory, because relaxation adjust them. */
12291 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
12292 TRUE
/* keep_memory */);
12293 if (internal_relocs
== NULL
)
12296 irelend
= internal_relocs
+ sec
->reloc_count
;
12297 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
12298 irelend
, R_NDS32_RELAX_ENTRY
);
12300 if (irel
== irelend
)
12303 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
12305 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
)
12308 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG
)
12311 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG
)
12315 load_store_relax
= table
->load_store_relax
;
12317 /* Get symbol table and section content. */
12318 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12319 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12322 /* Do relax loop only when finalize is not done.
12323 Take care of relaxable relocs except INSN16. */
12324 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12326 int seq_len
; /* Original length of instruction sequence. */
12327 int insn_len
= 0; /* Final length of instruction sequence. */
12328 bfd_boolean removed
;
12331 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
12332 && (irel
->r_addend
& 0x1f) >= 2)
12335 /* Relocation Types
12336 R_NDS32_LONGCALL1 53
12337 R_NDS32_LONGCALL2 54
12338 R_NDS32_LONGCALL3 55
12339 R_NDS32_LONGJUMP1 56
12340 R_NDS32_LONGJUMP2 57
12341 R_NDS32_LONGJUMP3 58
12342 R_NDS32_LOADSTORE 59 */
12343 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL1
12344 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LOADSTORE
)
12345 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
12347 /* Relocation Types
12348 R_NDS32_LONGCALL4 107
12349 R_NDS32_LONGCALL5 108
12350 R_NDS32_LONGCALL6 109
12351 R_NDS32_LONGJUMP4 110
12352 R_NDS32_LONGJUMP5 111
12353 R_NDS32_LONGJUMP6 112
12354 R_NDS32_LONGJUMP7 113 */
12355 else if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL4
12356 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LONGJUMP7
)
12359 /* Relocation Types
12360 R_NDS32_LO12S0_RELA 30
12361 R_NDS32_LO12S1_RELA 29
12362 R_NDS32_LO12S2_RELA 28
12363 R_NDS32_LO12S2_SP_RELA 71
12364 R_NDS32_LO12S2_DP_RELA 70
12365 R_NDS32_GOT_LO12 46
12366 R_NDS32_GOTOFF_LO12 50
12367 R_NDS32_PLTREL_LO12 65
12368 R_NDS32_PLT_GOTREL_LO12 67
12369 R_NDS32_17IFC_PCREL_RELA 96
12370 R_NDS32_GOT_SUFF 193
12371 R_NDS32_GOTOFF_SUFF 194
12372 R_NDS32_PLT_GOT_SUFF 195
12373 R_NDS32_MULCALL_SUFF 196
12375 else if ((ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LO12S0_RELA
12376 && ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LO12S2_RELA
)
12377 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_SP_RELA
12378 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_DP_RELA
12379 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
12380 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
12381 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
12382 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLTREL_LO12
12383 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
12384 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_GOT_SUFF
12385 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_PTR
)
12386 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
12387 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LO12
12388 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_ADD
12389 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LS
12390 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LSI
)
12395 insn_len
= seq_len
;
12398 switch (ELF32_R_TYPE (irel
->r_info
))
12400 case R_NDS32_LONGCALL1
:
12401 removed
= nds32_elf_relax_longcall1 (abfd
, sec
, irel
, internal_relocs
,
12402 &insn_len
, contents
, isymbuf
,
12405 case R_NDS32_LONGCALL2
:
12406 removed
= nds32_elf_relax_longcall2 (abfd
, sec
, irel
, internal_relocs
,
12407 &insn_len
, contents
, isymbuf
,
12410 case R_NDS32_LONGCALL3
:
12411 removed
= nds32_elf_relax_longcall3 (abfd
, sec
, irel
, internal_relocs
,
12412 &insn_len
, contents
, isymbuf
,
12415 case R_NDS32_LONGJUMP1
:
12416 removed
= nds32_elf_relax_longjump1 (abfd
, sec
, irel
, internal_relocs
,
12417 &insn_len
, contents
, isymbuf
,
12420 case R_NDS32_LONGJUMP2
:
12421 removed
= nds32_elf_relax_longjump2 (abfd
, sec
, irel
, internal_relocs
,
12422 &insn_len
, contents
, isymbuf
,
12425 case R_NDS32_LONGJUMP3
:
12426 removed
= nds32_elf_relax_longjump3 (abfd
, sec
, irel
, internal_relocs
,
12427 &insn_len
, contents
, isymbuf
,
12430 case R_NDS32_LONGCALL4
:
12431 removed
= nds32_elf_relax_longcall4 (abfd
, sec
, irel
, internal_relocs
,
12432 &insn_len
, contents
, isymbuf
,
12435 case R_NDS32_LONGCALL5
:
12436 removed
= nds32_elf_relax_longcall5 (abfd
, sec
, irel
, internal_relocs
,
12437 &insn_len
, contents
, isymbuf
,
12440 case R_NDS32_LONGCALL6
:
12441 removed
= nds32_elf_relax_longcall6 (abfd
, sec
, irel
, internal_relocs
,
12442 &insn_len
, contents
, isymbuf
,
12445 case R_NDS32_LONGJUMP4
:
12446 removed
= nds32_elf_relax_longjump4 (abfd
, sec
, irel
, internal_relocs
,
12447 &insn_len
, contents
, isymbuf
,
12450 case R_NDS32_LONGJUMP5
:
12451 removed
= nds32_elf_relax_longjump5 (abfd
, sec
, irel
, internal_relocs
,
12452 &insn_len
, &seq_len
, contents
,
12453 isymbuf
, symtab_hdr
);
12455 case R_NDS32_LONGJUMP6
:
12456 removed
= nds32_elf_relax_longjump6 (abfd
, sec
, irel
, internal_relocs
,
12457 &insn_len
, &seq_len
, contents
,
12458 isymbuf
, symtab_hdr
);
12460 case R_NDS32_LONGJUMP7
:
12461 removed
= nds32_elf_relax_longjump7 (abfd
, sec
, irel
, internal_relocs
,
12462 &insn_len
, &seq_len
, contents
,
12463 isymbuf
, symtab_hdr
);
12465 case R_NDS32_LOADSTORE
:
12466 removed
= nds32_elf_relax_loadstore (link_info
, abfd
, sec
, irel
,
12467 internal_relocs
, &insn_len
,
12468 contents
, isymbuf
, symtab_hdr
,
12469 load_store_relax
, table
);
12471 case R_NDS32_LO12S0_RELA
:
12472 case R_NDS32_LO12S1_RELA
:
12473 case R_NDS32_LO12S2_RELA
:
12474 case R_NDS32_LO12S2_DP_RELA
:
12475 case R_NDS32_LO12S2_SP_RELA
:
12476 /* Relax for low part. */
12477 nds32_elf_relax_lo12 (link_info
, abfd
, sec
, irel
, internal_relocs
,
12478 contents
, isymbuf
, symtab_hdr
, table
);
12480 /* It is impossible to delete blank, so just continue. */
12483 removed
= nds32_elf_relax_ptr (abfd
, sec
, irel
, internal_relocs
,
12484 &insn_len
, &seq_len
, contents
);
12487 nds32_elf_relax_flsi (link_info
, abfd
, sec
, irel
, internal_relocs
,
12488 contents
, isymbuf
, symtab_hdr
, again
);
12490 case R_NDS32_GOT_LO12
:
12491 case R_NDS32_GOTOFF_LO12
:
12492 case R_NDS32_PLTREL_LO12
:
12493 case R_NDS32_PLT_GOTREL_LO12
:
12494 case R_NDS32_GOTPC_LO12
:
12495 case R_NDS32_TLS_LE_LO12
:
12496 case R_NDS32_TLS_LE_ADD
:
12497 case R_NDS32_TLS_LE_LS
:
12498 case R_NDS32_PLT_GOT_SUFF
:
12499 case R_NDS32_GOT_SUFF
:
12500 case R_NDS32_GOTOFF_SUFF
:
12506 if (removed
&& seq_len
- insn_len
> 0)
12508 if (!insert_nds32_elf_blank
12509 (&relax_blank_list
, irel
->r_offset
+ insn_len
,
12510 seq_len
- insn_len
))
12516 calc_nds32_blank_total (relax_blank_list
);
12518 if (table
->relax_fp_as_gp
)
12520 if (!nds32_relax_fp_as_gp (link_info
, abfd
, sec
, internal_relocs
,
12526 if (!nds32_fag_remove_unused_fpbase (abfd
, sec
, internal_relocs
,
12534 if (!nds32_relax_adjust_label (abfd
, sec
, internal_relocs
, contents
,
12535 &relax_blank_list
, optimize
, opt_size
))
12539 /* It doesn't matter optimize_for_space_no_align anymore.
12540 If object file is assembled with flag '-Os',
12541 the we don't adjust jump-destination on 4-byte boundary. */
12543 if (relax_blank_list
)
12545 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
12546 relax_blank_list
= NULL
;
12551 /* Closing the section, so we don't relax it anymore. */
12552 bfd_vma sec_size_align
;
12553 Elf_Internal_Rela
*tmp_rel
;
12555 /* Pad to alignment boundary. Only handle current section alignment. */
12556 sec_size_align
= (sec
->size
+ (~((-1U) << sec
->alignment_power
)))
12557 & ((-1U) << sec
->alignment_power
);
12558 if ((sec_size_align
- sec
->size
) & 0x2)
12560 insn16
= NDS32_NOP16
;
12561 bfd_putb16 (insn16
, contents
+ sec
->size
);
12565 while (sec_size_align
!= sec
->size
)
12567 insn
= NDS32_NOP32
;
12568 bfd_putb32 (insn
, contents
+ sec
->size
);
12572 tmp_rel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
12573 irelend
, R_NDS32_RELAX_ENTRY
);
12574 if (tmp_rel
!= irelend
)
12575 tmp_rel
->r_addend
|= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
;
12577 clean_nds32_elf_blank ();
12581 if (internal_relocs
!= NULL
12582 && elf_section_data (sec
)->relocs
!= internal_relocs
)
12583 free (internal_relocs
);
12585 if (contents
!= NULL
12586 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
12589 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) isymbuf
)
12599 static struct bfd_elf_special_section
const nds32_elf_special_sections
[] =
12601 {".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
12602 {".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
12607 nds32_elf_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
12608 struct bfd_link_info
*info
,
12609 void *finfo ATTRIBUTE_UNUSED
,
12610 bfd_boolean (*func
) (void *, const char *,
12611 Elf_Internal_Sym
*,
12613 struct elf_link_hash_entry
*)
12616 FILE *sym_ld_script
= NULL
;
12617 struct elf_nds32_link_hash_table
*table
;
12619 table
= nds32_elf_hash_table (info
);
12620 sym_ld_script
= table
->sym_ld_script
;
12622 if (check_start_export_sym
)
12623 fprintf (sym_ld_script
, "}\n");
12628 static enum elf_reloc_type_class
12629 nds32_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
12630 const asection
*rel_sec ATTRIBUTE_UNUSED
,
12631 const Elf_Internal_Rela
*rela
)
12633 switch ((int) ELF32_R_TYPE (rela
->r_info
))
12635 case R_NDS32_RELATIVE
:
12636 return reloc_class_relative
;
12637 case R_NDS32_JMP_SLOT
:
12638 return reloc_class_plt
;
12640 return reloc_class_copy
;
12642 return reloc_class_normal
;
12646 /* Put target dependent option into info hash table. */
12648 bfd_elf32_nds32_set_target_option (struct bfd_link_info
*link_info
,
12649 int relax_fp_as_gp
,
12650 int eliminate_gc_relocs
,
12651 FILE * sym_ld_script
,
12653 int tls_desc_trampoline
,
12654 int load_store_relax
)
12656 struct elf_nds32_link_hash_table
*table
;
12658 table
= nds32_elf_hash_table (link_info
);
12662 table
->relax_fp_as_gp
= relax_fp_as_gp
;
12663 table
->eliminate_gc_relocs
= eliminate_gc_relocs
;
12664 table
->sym_ld_script
= sym_ld_script
;
12665 table
->hyper_relax
= hyper_relax
;
12666 table
->tls_desc_trampoline
= tls_desc_trampoline
;
12667 table
->load_store_relax
= load_store_relax
;
12671 /* These functions and data-structures are used for fp-as-gp
12674 #define FAG_THRESHOLD 3 /* At least 3 gp-access. */
12675 /* lwi37.fp covers 508 bytes, but there may be 32-byte padding between
12676 the read-only section and read-write section. */
12677 #define FAG_WINDOW (508 - 32)
12679 /* An nds32_fag represent a gp-relative access.
12680 We find best fp-base by using a sliding window
12681 to find a base address which can cover most gp-access. */
12684 struct nds32_fag
*next
; /* NULL-teminated linked list. */
12685 bfd_vma addr
; /* The address of this fag. */
12686 Elf_Internal_Rela
**relas
; /* The relocations associated with this fag.
12687 It is used for applying FP7U2_FLAG. */
12688 int count
; /* How many times this address is referred.
12689 There should be exactly `count' relocations
12691 int relas_capcity
; /* The buffer size of relas.
12692 We use an array instead of linked-list,
12693 and realloc is used to adjust buffer size. */
12697 nds32_fag_init (struct nds32_fag
*head
)
12699 memset (head
, 0, sizeof (struct nds32_fag
));
12703 nds32_fag_verify (struct nds32_fag
*head
)
12705 struct nds32_fag
*iter
;
12706 struct nds32_fag
*prev
;
12712 if (prev
&& prev
->addr
>= iter
->addr
)
12713 puts ("Bug in fp-as-gp insertion.");
12719 /* Insert a fag in ascending order.
12720 If a fag of the same address already exists,
12721 they are chained by relas array. */
12724 nds32_fag_insert (struct nds32_fag
*head
, bfd_vma addr
,
12725 Elf_Internal_Rela
* rel
)
12727 struct nds32_fag
*iter
;
12728 struct nds32_fag
*new_fag
;
12729 const int INIT_RELAS_CAP
= 4;
12732 iter
->next
&& iter
->next
->addr
<= addr
;
12734 /* Find somewhere to insert. */ ;
12736 /* `iter' will be equal to `head' if the list is empty. */
12737 if (iter
!= head
&& iter
->addr
== addr
)
12739 /* The address exists in the list.
12740 Insert `rel' into relocation list, relas. */
12742 /* Check whether relas is big enough. */
12743 if (iter
->count
>= iter
->relas_capcity
)
12745 iter
->relas_capcity
*= 2;
12746 iter
->relas
= bfd_realloc
12747 (iter
->relas
, iter
->relas_capcity
* sizeof (void *));
12749 iter
->relas
[iter
->count
++] = rel
;
12753 /* This is a new address. Create a fag node for it. */
12754 new_fag
= bfd_malloc (sizeof (struct nds32_fag
));
12755 memset (new_fag
, 0, sizeof (*new_fag
));
12756 new_fag
->addr
= addr
;
12757 new_fag
->count
= 1;
12758 new_fag
->next
= iter
->next
;
12759 new_fag
->relas_capcity
= INIT_RELAS_CAP
;
12760 new_fag
->relas
= (Elf_Internal_Rela
**)
12761 bfd_malloc (new_fag
->relas_capcity
* sizeof (void *));
12762 new_fag
->relas
[0] = rel
;
12763 iter
->next
= new_fag
;
12765 nds32_fag_verify (head
);
12769 nds32_fag_free_list (struct nds32_fag
*head
)
12771 struct nds32_fag
*iter
;
12776 struct nds32_fag
*tmp
= iter
;
12784 /* Find the best fp-base address.
12785 The relocation associated with that address is returned,
12786 so we can track the symbol instead of a fixed address.
12788 When relaxation, the address of an datum may change,
12789 because a text section is shrinked, so the data section
12790 moves forward. If the aligments of text and data section
12791 are different, their distance may change too.
12792 Therefore, tracking a fixed address is not appriate. */
12795 nds32_fag_find_base (struct nds32_fag
*head
, struct nds32_fag
**bestpp
)
12797 struct nds32_fag
*base
; /* First fag in the window. */
12798 struct nds32_fag
*last
; /* First fag outside the window. */
12799 int accu
= 0; /* Usage accumulation. */
12800 struct nds32_fag
*best
; /* Best fag. */
12801 int baccu
= 0; /* Best accumulation. */
12803 /* Use first fag for initial, and find the last fag in the window.
12805 In each iteration, we could simply subtract previous fag
12806 and accumulate following fags which are inside the window,
12807 untill we each the end. */
12809 if (head
->next
== NULL
)
12815 /* Initialize base. */
12819 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12821 accu
+= last
->count
;
12825 /* Record the best base in each iteration. */
12828 accu
-= base
->count
;
12830 /* Account fags in window. */
12831 for (/* Nothing. */;
12832 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12834 accu
+= last
->count
;
12836 /* A better fp-base? */
12849 /* Apply R_NDS32_INSN16_FP7U2_FLAG on gp-relative accesses,
12850 so we can convert it fo fp-relative access later.
12851 `best_fag' is the best fp-base. Only those inside the window
12852 of best_fag is applied the flag. */
12855 nds32_fag_mark_relax (struct bfd_link_info
*link_info
,
12856 asection
*sec
, struct nds32_fag
*best_fag
,
12857 Elf_Internal_Rela
*internal_relocs
,
12858 Elf_Internal_Rela
*irelend
)
12860 struct nds32_fag
*ifag
;
12861 bfd_vma best_fpbase
, gp
;
12864 output_bfd
= sec
->output_section
->owner
;
12865 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
12866 best_fpbase
= best_fag
->addr
;
12868 if (best_fpbase
> gp
+ sdata_range
[1][1]
12869 || best_fpbase
< gp
- sdata_range
[1][0])
12872 /* Mark these inside the window R_NDS32_INSN16_FP7U2_FLAG flag,
12873 so we know they can be converted to lwi37.fp. */
12874 for (ifag
= best_fag
;
12875 ifag
&& ifag
->addr
< best_fpbase
+ FAG_WINDOW
; ifag
= ifag
->next
)
12879 for (i
= 0; i
< ifag
->count
; i
++)
12881 Elf_Internal_Rela
*insn16_rel
;
12882 Elf_Internal_Rela
*fag_rel
;
12884 fag_rel
= ifag
->relas
[i
];
12886 /* Only if this is within the WINDOWS, FP7U2_FLAG
12889 insn16_rel
= find_relocs_at_address
12890 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12892 if (insn16_rel
!= irelend
)
12893 insn16_rel
->r_addend
= R_NDS32_INSN16_FP7U2_FLAG
;
12899 /* Reset INSN16 to clean fp as gp. */
12902 nds32_fag_unmark_relax (struct nds32_fag
*fag
,
12903 Elf_Internal_Rela
*internal_relocs
,
12904 Elf_Internal_Rela
*irelend
)
12906 struct nds32_fag
*ifag
;
12908 Elf_Internal_Rela
*insn16_rel
;
12909 Elf_Internal_Rela
*fag_rel
;
12911 for (ifag
= fag
; ifag
; ifag
= ifag
->next
)
12913 for (i
= 0; i
< ifag
->count
; i
++)
12915 fag_rel
= ifag
->relas
[i
];
12917 /* Restore the INSN16 relocation. */
12918 insn16_rel
= find_relocs_at_address
12919 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12921 if (insn16_rel
!= irelend
)
12922 insn16_rel
->r_addend
&= ~R_NDS32_INSN16_FP7U2_FLAG
;
12927 /* This is the main function of fp-as-gp optimization.
12928 It should be called by relax_section. */
12931 nds32_relax_fp_as_gp (struct bfd_link_info
*link_info
,
12932 bfd
*abfd
, asection
*sec
,
12933 Elf_Internal_Rela
*internal_relocs
,
12934 Elf_Internal_Rela
*irelend
,
12935 Elf_Internal_Sym
*isymbuf
)
12937 Elf_Internal_Rela
*begin_rel
= NULL
;
12938 Elf_Internal_Rela
*irel
;
12939 struct nds32_fag fag_head
;
12940 Elf_Internal_Shdr
*symtab_hdr
;
12941 bfd_byte
*contents
;
12942 bfd_boolean ifc_inside
= FALSE
;
12944 /* FIXME: Can we bfd_elf_link_read_relocs for the relocs? */
12946 /* Per-function fp-base selection.
12947 1. Create a list for all the gp-relative access.
12948 2. Base on those gp-relative address,
12949 find a fp-base which can cover most access.
12950 3. Use the fp-base for fp-as-gp relaxation.
12952 NOTE: If fp-as-gp is not worth to do, (e.g., less than 3 times),
12954 1. delete the `la $fp, _FP_BASE_' instruction and
12955 2. not convert lwi.gp to lwi37.fp.
12957 To delete the _FP_BASE_ instruction, we simply apply
12958 R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG flag in the r_addend to disable it.
12960 To suppress the conversion, we simply NOT to apply
12961 R_NDS32_INSN16_FP7U2_FLAG flag. */
12963 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12965 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12966 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12969 /* Check whether it is worth for fp-as-gp optimization,
12970 i.e., at least 3 gp-load.
12972 Set R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG if we should NOT
12973 apply this optimization. */
12975 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12977 /* We recognize R_NDS32_RELAX_REGION_BEGIN/_END for the region.
12978 One we enter the begin of the region, we track all the LW/ST
12979 instructions, so when we leave the region, we try to find
12980 the best fp-base address for those LW/ST instructions. */
12982 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12983 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12985 /* Begin of the region. */
12987 /* xgettext:c-format */
12988 _bfd_error_handler (_("%pB: nested OMIT_FP in %pA"), abfd
, sec
);
12991 nds32_fag_init (&fag_head
);
12992 ifc_inside
= FALSE
;
12994 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12995 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12998 struct nds32_fag
*best_fag
, *tmp_fag
;
13001 /* End of the region.
13002 Check whether it is worth to do fp-as-gp. */
13004 if (begin_rel
== NULL
)
13006 /* xgettext:c-format */
13007 _bfd_error_handler (_("%pB: unmatched OMIT_FP in %pA"),
13012 accu
= nds32_fag_find_base (&fag_head
, &best_fag
);
13014 /* Clean FP7U2_FLAG because they may set ever. */
13015 tmp_fag
= fag_head
.next
;
13016 nds32_fag_unmark_relax (tmp_fag
, internal_relocs
, irelend
);
13018 /* Check if it is worth, and FP_BASE is near enough to SDA_BASE. */
13019 if (accu
< FAG_THRESHOLD
13020 || !nds32_fag_mark_relax (link_info
, sec
, best_fag
,
13021 internal_relocs
, irelend
))
13023 /* Not worth to do fp-as-gp. */
13024 begin_rel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
13025 begin_rel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
13026 irel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
13027 irel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
13028 nds32_fag_free_list (&fag_head
);
13033 /* R_SYM of R_NDS32_RELAX_REGION_BEGIN is not used by assembler,
13034 so we use it to record the distance to the reloction of best
13036 dist
= best_fag
->relas
[0] - begin_rel
;
13037 BFD_ASSERT (dist
> 0 && dist
< 0xffffff);
13038 /* Use high 16 bits of addend to record the _FP_BASE_ matched
13039 relocation. And get the base value when relocating. */
13040 begin_rel
->r_addend
&= (0x1 << 16) - 1;
13041 begin_rel
->r_addend
|= dist
<< 16;
13043 nds32_fag_free_list (&fag_head
);
13047 if (begin_rel
== NULL
|| ifc_inside
)
13048 /* Skip if we are not in the region of fp-as-gp. */
13051 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S2_RELA
13052 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA17S2_RELA
)
13057 /* A gp-relative access is found. Insert it to the fag-list. */
13059 /* Rt is necessary an RT3, so it can be converted to lwi37.fp. */
13060 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13061 if (!N32_IS_RT3 (insn
))
13064 addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
13065 nds32_fag_insert (&fag_head
, addr
, irel
);
13067 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA_FP7U2_RELA
)
13071 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
13072 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
13074 /* Suppress fp as gp when encounter ifc. */
13082 /* Remove unused `la $fp, _FD_BASE_' instruction. */
13085 nds32_fag_remove_unused_fpbase (bfd
*abfd
, asection
*sec
,
13086 Elf_Internal_Rela
*internal_relocs
,
13087 Elf_Internal_Rela
*irelend
)
13089 Elf_Internal_Rela
*irel
;
13090 Elf_Internal_Shdr
*symtab_hdr
;
13091 bfd_byte
*contents
= NULL
;
13092 nds32_elf_blank_t
*relax_blank_list
= NULL
;
13093 bfd_boolean result
= TRUE
;
13094 bfd_boolean unused_region
= FALSE
;
13097 NOTE: Disable fp-as-gp if we encounter ifcall relocations:
13098 R_NDS32_17IFC_PCREL_RELA
13099 R_NDS32_10IFCU_PCREL_RELA. */
13101 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13102 nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
);
13104 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13106 /* To remove unused fp-base, we simply find the REGION_NOT_OMIT_FP
13107 we marked to in previous pass.
13108 DO NOT scan relocations again, since we've alreadly decided it
13109 and set the flag. */
13110 const char *syname
;
13114 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
13115 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
13116 unused_region
= TRUE
;
13117 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
13118 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
13119 unused_region
= FALSE
;
13121 /* We're not in the region. */
13122 if (!unused_region
)
13125 /* _FP_BASE_ must be a GLOBAL symbol. */
13126 syndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
13127 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
13130 /* The symbol name must be _FP_BASE_. */
13131 syname
= elf_sym_hashes (abfd
)[syndx
]->root
.root
.string
;
13132 if (strcmp (syname
, FP_BASE_NAME
) != 0)
13135 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA19S0_RELA
)
13137 /* addi.gp $fp, -256 */
13138 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13139 if (insn
!= INSN_ADDIGP_TO_FP
)
13142 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S0_RELA
)
13144 /* addi $fp, $gp, -256 */
13145 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13146 if (insn
!= INSN_ADDI_GP_TO_FP
)
13149 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_20_RELA
)
13151 /* movi $fp, FP_BASE */
13152 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13153 if (insn
!= INSN_MOVI_TO_FP
)
13159 /* We got here because a FP_BASE instruction is found. */
13160 if (!insert_nds32_elf_blank_recalc_total
13161 (&relax_blank_list
, irel
->r_offset
, 4))
13166 if (relax_blank_list
)
13168 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
13169 relax_blank_list
= NULL
;
13178 /* This is a version of bfd_generic_get_relocated_section_contents.
13179 We need this variety because relaxation will modify the dwarf
13180 infomation. When there is undefined symbol reference error mesage,
13181 linker need to dump line number where the symbol be used. However
13182 the address is be relaxed, it can not get the original dwarf contents.
13183 The variety only modify function call for reading in the section. */
13186 nds32_elf_get_relocated_section_contents (bfd
*abfd
,
13187 struct bfd_link_info
*link_info
,
13188 struct bfd_link_order
*link_order
,
13190 bfd_boolean relocatable
,
13193 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
13194 asection
*input_section
= link_order
->u
.indirect
.section
;
13196 arelent
**reloc_vector
;
13199 reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
13200 if (reloc_size
< 0)
13203 /* Read in the section. */
13204 if (!nds32_get_section_contents (input_bfd
, input_section
, &data
, FALSE
))
13207 if (reloc_size
== 0)
13210 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
13211 if (reloc_vector
== NULL
)
13214 reloc_count
= bfd_canonicalize_reloc (input_bfd
, input_section
,
13215 reloc_vector
, symbols
);
13216 if (reloc_count
< 0)
13219 if (reloc_count
> 0)
13222 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
13224 char *error_message
= NULL
;
13226 bfd_reloc_status_type r
;
13228 symbol
= *(*parent
)->sym_ptr_ptr
;
13229 if (symbol
->section
&& discarded_section (symbol
->section
))
13232 static reloc_howto_type none_howto
13233 = HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, NULL
,
13234 "unused", FALSE
, 0, 0, FALSE
);
13236 p
= data
+ (*parent
)->address
* bfd_octets_per_byte (input_bfd
);
13237 _bfd_clear_contents ((*parent
)->howto
, input_bfd
, input_section
,
13239 (*parent
)->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
13240 (*parent
)->addend
= 0;
13241 (*parent
)->howto
= &none_howto
;
13245 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
13247 relocatable
? abfd
: NULL
,
13252 asection
*os
= input_section
->output_section
;
13254 /* A partial link, so keep the relocs. */
13255 os
->orelocation
[os
->reloc_count
] = *parent
;
13259 if (r
!= bfd_reloc_ok
)
13263 case bfd_reloc_undefined
:
13264 (*link_info
->callbacks
->undefined_symbol
)
13265 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13266 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
13268 case bfd_reloc_dangerous
:
13269 BFD_ASSERT (error_message
!= NULL
);
13270 (*link_info
->callbacks
->reloc_dangerous
)
13271 (link_info
, error_message
,
13272 input_bfd
, input_section
, (*parent
)->address
);
13274 case bfd_reloc_overflow
:
13275 (*link_info
->callbacks
->reloc_overflow
)
13277 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13278 (*parent
)->howto
->name
, (*parent
)->addend
,
13279 input_bfd
, input_section
, (*parent
)->address
);
13281 case bfd_reloc_outofrange
:
13283 This error can result when processing some partially
13284 complete binaries. Do not abort, but issue an error
13285 message instead. */
13286 link_info
->callbacks
->einfo
13287 /* xgettext:c-format */
13288 (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
13289 abfd
, input_section
, * parent
);
13300 free (reloc_vector
);
13304 free (reloc_vector
);
13308 /* Check target symbol. */
13311 nds32_elf_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*sym
)
13313 if (!sym
|| !sym
->name
|| sym
->name
[0] != '$')
13318 /* nds32 find maybe function sym. Ignore target special symbol
13319 first, and then go the general function. */
13321 static bfd_size_type
13322 nds32_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
13325 if (nds32_elf_is_target_special_symbol (NULL
, (asymbol
*) sym
))
13328 return _bfd_elf_maybe_function_sym (sym
, sec
, code_off
);
13332 /* Do TLS model conversion. */
13334 typedef struct relax_group_list_t
13336 Elf_Internal_Rela
*relo
;
13337 struct relax_group_list_t
*next
;
13338 struct relax_group_list_t
*next_sibling
;
13340 } relax_group_list_t
;
13343 list_insert (relax_group_list_t
*pHead
, Elf_Internal_Rela
*pElem
);
13346 list_insert_sibling (relax_group_list_t
*pNode
, Elf_Internal_Rela
*pElem
);
13349 dump_chain (relax_group_list_t
*pHead
);
13352 list_insert (relax_group_list_t
*pHead
, Elf_Internal_Rela
*pElem
)
13354 relax_group_list_t
*pNext
= pHead
;
13357 while (pNext
->next
)
13359 if (pNext
->next
->id
> (int) pElem
->r_addend
)
13362 pNext
= pNext
->next
;
13366 relax_group_list_t
*pNew
= bfd_malloc (sizeof (relax_group_list_t
));
13370 relax_group_list_t
*tmp
= pNext
->next
;
13371 pNext
->next
= pNew
;
13373 pNew
->id
= pElem
->r_addend
;
13374 pNew
->relo
= pElem
;
13376 pNew
->next_sibling
= NULL
;
13382 list_insert_sibling (relax_group_list_t
*pNode
, Elf_Internal_Rela
*pElem
)
13384 relax_group_list_t
*pNext
= pNode
;
13387 while (pNext
->next_sibling
)
13389 pNext
= pNext
->next_sibling
;
13393 relax_group_list_t
*pNew
= bfd_malloc (sizeof (relax_group_list_t
));
13397 relax_group_list_t
*tmp
= pNext
->next_sibling
;
13398 pNext
->next_sibling
= pNew
;
13401 pNew
->relo
= pElem
;
13403 pNew
->next_sibling
= tmp
;
13409 dump_chain (relax_group_list_t
*pHead
)
13411 relax_group_list_t
*pNext
= pHead
->next
;
13414 printf("group %d @ 0x%08x", pNext
->id
, (unsigned)pNext
->relo
->r_offset
);
13415 relax_group_list_t
*pNextSib
= pNext
->next_sibling
;
13418 printf(", %d", (unsigned) ELF32_R_TYPE (pNextSib
->relo
->r_info
));
13419 pNextSib
= pNextSib
->next_sibling
;
13421 pNext
= pNext
->next
;
13426 /* Check R_NDS32_RELAX_GROUP of each section.
13427 There might be multiple sections in one object file. */
13430 elf32_nds32_check_relax_group (bfd
*abfd
, asection
*asec
)
13432 elf32_nds32_relax_group_t
*relax_group_ptr
=
13433 elf32_nds32_relax_group_ptr (abfd
);
13435 int min_id
= relax_group_ptr
->min_id
;
13436 int max_id
= relax_group_ptr
->max_id
;
13438 Elf_Internal_Rela
*rel
;
13439 Elf_Internal_Rela
*relend
;
13440 Elf_Internal_Rela
*relocs
;
13441 enum elf_nds32_reloc_type rtype
;
13445 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13446 relocs
= _bfd_elf_link_read_relocs (abfd
, asec
, NULL
, NULL
,
13447 TRUE
/* keep_memory */);
13448 if (relocs
== NULL
)
13451 /* Check R_NDS32_RELAX_GROUP. */
13452 relend
= relocs
+ asec
->reloc_count
;
13453 for (rel
= relocs
; rel
< relend
; rel
++)
13456 rtype
= ELF32_R_TYPE (rel
->r_info
);
13457 if (rtype
!= R_NDS32_RELAX_GROUP
)
13460 id
= rel
->r_addend
;
13463 else if (id
> max_id
)
13469 if ((relocs
!= NULL
) && (elf_section_data (asec
)->relocs
!= relocs
))
13472 if ((min_id
!= relax_group_ptr
->min_id
)
13473 || (max_id
!= relax_group_ptr
->max_id
))
13475 relax_group_ptr
->count
= max_id
- min_id
+ 1;
13476 BFD_ASSERT(min_id
<= relax_group_ptr
->min_id
);
13477 relax_group_ptr
->min_id
= min_id
;
13478 BFD_ASSERT(max_id
>= relax_group_ptr
->max_id
);
13479 relax_group_ptr
->max_id
= max_id
;
13482 return relax_group_ptr
->count
;
13485 /* Reorder RELAX_GROUP ID when command line option '-r' is applied. */
13486 struct section_id_list_t
*relax_group_section_id_list
= NULL
;
13488 struct section_id_list_t
*
13489 elf32_nds32_lookup_section_id (int id
, struct section_id_list_t
**lst_ptr
)
13491 struct section_id_list_t
*result
= NULL
;
13492 struct section_id_list_t
*lst
= *lst_ptr
;
13496 result
= (struct section_id_list_t
*) calloc
13497 (1, sizeof (struct section_id_list_t
));
13498 BFD_ASSERT (result
); /* Feed me. */
13504 struct section_id_list_t
*cur
= lst
;
13505 struct section_id_list_t
*prv
= NULL
;
13506 struct section_id_list_t
*sec
= NULL
;
13519 cur
= NULL
; /* To insert after prv. */
13520 sec
= cur
; /* In case prv == NULL. */
13528 /* Insert after prv. */
13529 result
= (struct section_id_list_t
*) calloc
13530 (1, sizeof (struct section_id_list_t
));
13531 BFD_ASSERT (result
); /* Feed me. */
13535 result
->next
= prv
->next
;
13536 prv
->next
= result
;
13541 result
->next
= sec
;
13550 elf32_nds32_unify_relax_group (bfd
*abfd
, asection
*asec
)
13552 static int next_relax_group_bias
= 0;
13554 elf32_nds32_relax_group_t
*relax_group_ptr
=
13555 elf32_nds32_relax_group_ptr (abfd
);
13557 bfd_boolean result
= TRUE
;
13558 Elf_Internal_Rela
*rel
;
13559 Elf_Internal_Rela
*relend
;
13560 Elf_Internal_Rela
*relocs
= NULL
;
13561 enum elf_nds32_reloc_type rtype
;
13562 struct section_id_list_t
*node
= NULL
;
13567 if (0 == relax_group_ptr
->count
)
13570 /* Check if this section has been handled. */
13571 node
= elf32_nds32_lookup_section_id (asec
->id
, &relax_group_section_id_list
);
13573 break; /* Hit, the section id has handled. */
13575 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13576 relocs
= _bfd_elf_link_read_relocs (abfd
, asec
, NULL
, NULL
,
13577 TRUE
/* keep_memory */);
13578 if (relocs
== NULL
)
13580 BFD_ASSERT (0); /* feed me */
13584 /* Allocate group id bias for this bfd! */
13585 if (0 == relax_group_ptr
->init
)
13587 relax_group_ptr
->bias
= next_relax_group_bias
;
13588 next_relax_group_bias
+= relax_group_ptr
->count
;
13589 relax_group_ptr
->init
= 1;
13592 /* Reorder relax group groups. */
13593 relend
= relocs
+ asec
->reloc_count
;
13594 for (rel
= relocs
; rel
< relend
; rel
++)
13596 rtype
= ELF32_R_TYPE(rel
->r_info
);
13597 if (rtype
!= R_NDS32_RELAX_GROUP
)
13601 rel
->r_addend
+= relax_group_ptr
->bias
;
13602 /* Debugging count. */
13608 if (relocs
!= NULL
&& elf_section_data (asec
)->relocs
!= relocs
)
13615 nds32_elf_unify_tls_model (bfd
*inbfd
, asection
*insec
, bfd_byte
*incontents
,
13616 struct bfd_link_info
*lnkinfo
)
13618 bfd_boolean result
= TRUE
;
13619 Elf_Internal_Rela
*irel
;
13620 Elf_Internal_Rela
*irelend
;
13621 Elf_Internal_Rela
*internal_relocs
;
13622 unsigned long r_symndx
;
13623 enum elf_nds32_reloc_type r_type
;
13625 Elf_Internal_Sym
*local_syms
= NULL
;
13626 bfd_byte
*contents
= NULL
;
13628 relax_group_list_t chain
= { .id
= -1, .next
= NULL
, .next_sibling
= NULL
};
13630 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (inbfd
)->symtab_hdr
;
13631 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
13632 sym_hashes
= elf_sym_hashes (inbfd
);
13634 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
13635 if (!elf_bad_symtab (inbfd
))
13636 sym_hashes_end
-= symtab_hdr
->sh_info
;
13638 /* Reorder RELAX_GROUP when command line option '-r' is applied. */
13639 if (bfd_link_relocatable (lnkinfo
))
13641 elf32_nds32_unify_relax_group (inbfd
, insec
);
13645 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13646 internal_relocs
= _bfd_elf_link_read_relocs (inbfd
, insec
, NULL
, NULL
,
13647 TRUE
/* keep_memory */);
13648 if (internal_relocs
== NULL
)
13651 irelend
= internal_relocs
+ insec
->reloc_count
;
13652 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
13653 irelend
, R_NDS32_RELAX_ENTRY
);
13654 if (irel
== irelend
)
13657 /* Chain/remove groups. */
13658 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13660 r_symndx
= ELF32_R_SYM (irel
->r_info
);
13661 r_type
= ELF32_R_TYPE (irel
->r_info
);
13662 if (r_type
!= R_NDS32_RELAX_GROUP
)
13666 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_NONE
);
13667 /* Chain it now. */
13668 if (!list_insert (&chain
, irel
))
13672 /* Collect group relocations. */
13673 /* Presume relocations are sorted. */
13674 relax_group_list_t
*pNext
= chain
.next
;
13677 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13679 if (irel
->r_offset
== pNext
->relo
->r_offset
)
13681 /* Ignore Non-TLS relocation types. */
13682 r_type
= ELF32_R_TYPE (irel
->r_info
);
13683 if ((R_NDS32_TLS_LE_HI20
> r_type
)
13684 || (R_NDS32_RELAX_ENTRY
== r_type
))
13687 if (!list_insert_sibling (pNext
, irel
))
13690 else if (irel
->r_offset
> pNext
->relo
->r_offset
)
13692 pNext
= pNext
->next
;
13696 bfd_vma current_offset
= pNext
->relo
->r_offset
;
13697 if (irel
->r_offset
> current_offset
)
13698 irel
= internal_relocs
; /* restart from head */
13700 --irel
; /* Check current irel again. */
13705 /* This shouldn't be reached. */
13709 pNext
= pNext
->next
;
13712 #ifdef DUBUG_VERBOSE
13713 dump_chain(&chain
);
13716 /* Get symbol table and section content. */
13718 contents
= incontents
;
13719 else if (!nds32_get_section_contents (inbfd
, insec
, &contents
, TRUE
)
13720 || !nds32_get_local_syms (inbfd
, insec
, &local_syms
))
13723 char *local_got_tls_type
= elf32_nds32_local_got_tls_type (inbfd
);
13725 /* Convert TLS model each group if necessary. */
13726 pNext
= chain
.next
;
13728 int cur_grp_id
= -1;
13731 enum elf_nds32_tls_type tls_type
, org_tls_type
, eff_tls_type
;
13733 tls_type
= org_tls_type
= eff_tls_type
= 0;
13737 relax_group_list_t
*pNextSig
= pNext
->next_sibling
;
13740 struct elf_link_hash_entry
*h
= NULL
;
13742 irel
= pNextSig
->relo
;
13743 r_symndx
= ELF32_R_SYM(irel
->r_info
);
13744 r_type
= ELF32_R_TYPE(irel
->r_info
);
13746 if (pNext
->id
!= cur_grp_id
)
13748 cur_grp_id
= pNext
->id
;
13749 org_tls_type
= get_tls_type (r_type
, NULL
);
13750 if (r_symndx
>= symtab_hdr
->sh_info
)
13752 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
13753 while (h
->root
.type
== bfd_link_hash_indirect
13754 || h
->root
.type
== bfd_link_hash_warning
)
13755 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
13756 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
13760 tls_type
= local_got_tls_type
13761 ? local_got_tls_type
[r_symndx
]
13765 eff_tls_type
= 1 << (fls (tls_type
) - 1);
13766 sethi_rt
= N32_RT5(bfd_getb32 (contents
+ irel
->r_offset
));
13769 if (eff_tls_type
!= org_tls_type
)
13771 switch (org_tls_type
)
13773 /* DESC to IEGP/IE/LE. */
13775 switch (eff_tls_type
)
13780 case R_NDS32_TLS_DESC_HI20
:
13781 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13782 R_NDS32_TLS_IE_HI20
);
13784 case R_NDS32_TLS_DESC_LO12
:
13785 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13786 R_NDS32_TLS_IE_LO12
);
13788 case R_NDS32_TLS_DESC_ADD
:
13790 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13791 add_rt
= N32_RT5 (insn
);
13792 insn
= N32_TYPE2 (LWI
, add_rt
, sethi_rt
, 0);
13793 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13795 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13798 case R_NDS32_TLS_DESC_FUNC
:
13799 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13800 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13801 R_NDS32_RELAX_REMOVE
);
13803 case R_NDS32_TLS_DESC_CALL
:
13805 uint32_t insn
= N32_ALU1(ADD
, REG_R0
, add_rt
,
13807 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13809 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13812 case R_NDS32_LOADSTORE
:
13814 case R_NDS32_PTR_RESOLVED
:
13816 case R_NDS32_LABEL
:
13826 case R_NDS32_TLS_DESC_HI20
:
13827 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13828 R_NDS32_TLS_IEGP_HI20
);
13830 case R_NDS32_TLS_DESC_LO12
:
13831 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13832 R_NDS32_TLS_IEGP_LO12
);
13834 case R_NDS32_TLS_DESC_ADD
:
13836 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13837 add_rt
= N32_RT5 (insn
);
13838 insn
= N32_MEM(LW
, add_rt
, sethi_rt
, REG_GP
, 0);
13839 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13841 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13844 case R_NDS32_TLS_DESC_FUNC
:
13845 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13846 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13847 R_NDS32_RELAX_REMOVE
);
13849 case R_NDS32_TLS_DESC_CALL
:
13851 uint32_t insn
= N32_ALU1(ADD
, REG_R0
, add_rt
,
13853 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13855 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13858 case R_NDS32_LOADSTORE
:
13860 case R_NDS32_PTR_RESOLVED
:
13862 case R_NDS32_LABEL
:
13872 case R_NDS32_TLS_DESC_HI20
:
13873 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13875 case R_NDS32_TLS_DESC_LO12
:
13876 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13878 case R_NDS32_TLS_DESC_ADD
:
13880 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13882 add_rt
= N32_RT5 (insn
);
13883 insn
= N32_ALU1 (ADD
, REG_R0
, sethi_rt
, REG_TP
);
13884 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13886 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_ADD
);
13889 case R_NDS32_TLS_DESC_FUNC
:
13890 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13891 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13893 case R_NDS32_TLS_DESC_CALL
:
13894 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13895 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13897 case R_NDS32_LOADSTORE
:
13899 case R_NDS32_PTR_RESOLVED
:
13901 case R_NDS32_LABEL
:
13912 /* IEGP to IE/LE. */
13914 switch (eff_tls_type
)
13919 case R_NDS32_TLS_IEGP_HI20
:
13920 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13921 R_NDS32_TLS_IE_HI20
);
13923 case R_NDS32_TLS_IEGP_LO12
:
13924 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13925 R_NDS32_TLS_IE_LO12
);
13927 case R_NDS32_PTR_RESOLVED
:
13929 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13931 add_rt
= N32_RT5 (insn
);
13932 insn
= N32_TYPE2 (LWI
, add_rt
, sethi_rt
, 0);
13933 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13936 case R_NDS32_TLS_IEGP_LW
:
13938 case R_NDS32_LOADSTORE
:
13941 case R_NDS32_LABEL
:
13951 case R_NDS32_TLS_IEGP_HI20
:
13952 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13954 case R_NDS32_TLS_IEGP_LO12
:
13955 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13957 case R_NDS32_TLS_IEGP_LW
:
13958 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13959 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13961 case R_NDS32_LOADSTORE
:
13964 case R_NDS32_LABEL
:
13965 case R_NDS32_PTR_RESOLVED
:
13978 switch (eff_tls_type
)
13983 case R_NDS32_TLS_IE_HI20
:
13984 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13986 case R_NDS32_TLS_IE_LO12S2
:
13988 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13990 add_rt
= N32_RT5 (insn
);
13991 insn
= N32_TYPE2 (ORI
, add_rt
, sethi_rt
, 0);
13992 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13994 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13997 case R_NDS32_LOADSTORE
:
14000 case R_NDS32_LABEL
:
14015 pNextSig
= pNextSig
->next_sibling
;
14019 pNext
= pNext
->next
;
14023 if (pNext
->id
!= cur_grp_id
)
14025 pNext
= pNext
->next
;
14034 if (internal_relocs
!= NULL
14035 && elf_section_data (insec
)->relocs
!= internal_relocs
)
14036 free (internal_relocs
);
14038 if (contents
!= NULL
14039 && elf_section_data (insec
)->this_hdr
.contents
!= contents
)
14042 if (local_syms
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
14047 pNext
= chain
.next
;
14048 relax_group_list_t
*pDel
;
14052 pNext
= pNext
->next
;
14064 /* End TLS model conversion. */
14066 #define ELF_ARCH bfd_arch_nds32
14067 #define ELF_MACHINE_CODE EM_NDS32
14068 #define ELF_MAXPAGESIZE 0x1000
14069 #define ELF_TARGET_ID NDS32_ELF_DATA
14071 #define TARGET_BIG_SYM nds32_elf32_be_vec
14072 #define TARGET_BIG_NAME "elf32-nds32be"
14073 #define TARGET_LITTLE_SYM nds32_elf32_le_vec
14074 #define TARGET_LITTLE_NAME "elf32-nds32le"
14076 #define elf_info_to_howto nds32_info_to_howto
14077 #define elf_info_to_howto_rel nds32_info_to_howto_rel
14079 #define bfd_elf32_bfd_link_hash_table_create nds32_elf_link_hash_table_create
14080 #define bfd_elf32_bfd_merge_private_bfd_data nds32_elf_merge_private_bfd_data
14081 #define bfd_elf32_bfd_print_private_bfd_data nds32_elf_print_private_bfd_data
14082 #define bfd_elf32_bfd_relax_section nds32_elf_relax_section
14083 #define bfd_elf32_bfd_set_private_flags nds32_elf_set_private_flags
14085 #define bfd_elf32_mkobject nds32_elf_mkobject
14086 #define elf_backend_action_discarded nds32_elf_action_discarded
14087 #define elf_backend_add_symbol_hook nds32_elf_add_symbol_hook
14088 #define elf_backend_check_relocs nds32_elf_check_relocs
14089 #define elf_backend_adjust_dynamic_symbol nds32_elf_adjust_dynamic_symbol
14090 #define elf_backend_create_dynamic_sections nds32_elf_create_dynamic_sections
14091 #define elf_backend_finish_dynamic_sections nds32_elf_finish_dynamic_sections
14092 #define elf_backend_finish_dynamic_symbol nds32_elf_finish_dynamic_symbol
14093 #define elf_backend_size_dynamic_sections nds32_elf_size_dynamic_sections
14094 #define elf_backend_relocate_section nds32_elf_relocate_section
14095 #define elf_backend_gc_mark_hook nds32_elf_gc_mark_hook
14096 #define elf_backend_grok_prstatus nds32_elf_grok_prstatus
14097 #define elf_backend_grok_psinfo nds32_elf_grok_psinfo
14098 #define elf_backend_reloc_type_class nds32_elf_reloc_type_class
14099 #define elf_backend_copy_indirect_symbol nds32_elf_copy_indirect_symbol
14100 #define elf_backend_link_output_symbol_hook nds32_elf_output_symbol_hook
14101 #define elf_backend_output_arch_syms nds32_elf_output_arch_syms
14102 #define elf_backend_object_p nds32_elf_object_p
14103 #define elf_backend_final_write_processing nds32_elf_final_write_processing
14104 #define elf_backend_special_sections nds32_elf_special_sections
14105 #define bfd_elf32_bfd_get_relocated_section_contents \
14106 nds32_elf_get_relocated_section_contents
14107 #define bfd_elf32_bfd_is_target_special_symbol nds32_elf_is_target_special_symbol
14108 #define elf_backend_maybe_function_sym nds32_elf_maybe_function_sym
14110 #define elf_backend_can_gc_sections 1
14111 #define elf_backend_can_refcount 1
14112 #define elf_backend_want_got_plt 1
14113 #define elf_backend_plt_readonly 1
14114 #define elf_backend_want_plt_sym 0
14115 #define elf_backend_got_header_size 12
14116 #define elf_backend_may_use_rel_p 1
14117 #define elf_backend_default_use_rela_p 1
14118 #define elf_backend_may_use_rela_p 1
14119 #define elf_backend_dtrel_excludes_plt 0
14121 #include "elf32-target.h"
14123 #undef ELF_MAXPAGESIZE
14124 #define ELF_MAXPAGESIZE 0x2000
14126 #undef TARGET_BIG_SYM
14127 #define TARGET_BIG_SYM nds32_elf32_linux_be_vec
14128 #undef TARGET_BIG_NAME
14129 #define TARGET_BIG_NAME "elf32-nds32be-linux"
14130 #undef TARGET_LITTLE_SYM
14131 #define TARGET_LITTLE_SYM nds32_elf32_linux_le_vec
14132 #undef TARGET_LITTLE_NAME
14133 #define TARGET_LITTLE_NAME "elf32-nds32le-linux"
14135 #define elf32_bed elf32_nds32_lin_bed
14137 #include "elf32-target.h"