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);
5088 fls (register unsigned int x
)
5090 return ffs (x
& (-x
));
5092 #endif /* !HAVE_FLS */
5094 #define nds32_elf_local_tlsdesc_gotent(bfd) \
5095 (elf_nds32_tdata (bfd)->local_tlsdesc_gotent)
5098 nds32_elf_relocate_section (bfd
* output_bfd ATTRIBUTE_UNUSED
,
5099 struct bfd_link_info
* info
,
5101 asection
* input_section
,
5102 bfd_byte
* contents
,
5103 Elf_Internal_Rela
* relocs
,
5104 Elf_Internal_Sym
* local_syms
,
5105 asection
** local_sections
)
5107 Elf_Internal_Shdr
*symtab_hdr
;
5108 struct elf_link_hash_entry
**sym_hashes
;
5109 Elf_Internal_Rela
*rel
, *relend
;
5110 bfd_boolean ret
= TRUE
; /* Assume success. */
5112 bfd_reloc_status_type r
;
5113 const char *errmsg
= NULL
;
5115 struct elf_link_hash_table
*ehtab
;
5116 struct elf_nds32_link_hash_table
*htab
;
5118 bfd_vma
*local_got_offsets
;
5119 asection
*sgot
, *splt
, *sreloc
;
5120 bfd_vma high_address
;
5121 struct elf_nds32_link_hash_table
*table
;
5122 int eliminate_gc_relocs
;
5123 bfd_vma fpbase_addr
;
5125 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5126 sym_hashes
= elf_sym_hashes (input_bfd
);
5127 ehtab
= elf_hash_table (info
);
5128 htab
= nds32_elf_hash_table (info
);
5129 high_address
= bfd_get_section_limit (input_bfd
, input_section
);
5131 dynobj
= htab
->root
.dynobj
;
5132 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5139 relend
= relocs
+ input_section
->reloc_count
;
5141 table
= nds32_elf_hash_table (info
);
5142 eliminate_gc_relocs
= table
->eliminate_gc_relocs
;
5144 /* By this time, we can adjust the value of _SDA_BASE_. */
5145 /* Explain _SDA_BASE_ */
5146 if ((!bfd_link_relocatable (info
)))
5148 is_SDA_BASE_set
= 1;
5149 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, TRUE
);
5150 if (r
!= bfd_reloc_ok
)
5154 /* Do TLS model conversion once at first. */
5155 nds32_elf_unify_tls_model (input_bfd
, input_section
, contents
, info
);
5157 /* Use gp as fp to prevent truncated fit. Because in relaxation time
5158 the fp value is set as gp, and it has be reverted for instruction
5160 fpbase_addr
= elf_gp (output_bfd
);
5162 /* Deal with (dynamic) relocations. */
5163 for (rel
= relocs
; rel
< relend
; rel
++)
5165 enum elf_nds32_reloc_type r_type
;
5166 reloc_howto_type
*howto
= NULL
;
5167 unsigned long r_symndx
;
5168 struct elf_link_hash_entry
*h
= NULL
;
5169 Elf_Internal_Sym
*sym
= NULL
;
5172 bfd_vma relocation_sym
= 0xdeadbeef;
5173 Elf_Internal_Rela
*lorel
;
5176 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
5177 ensure it's zero (we use REL relocs, not RELA). Therefore this
5178 should be assigning zero to `addend', but for clarity we use
5181 bfd_vma addend
= rel
->r_addend
;
5182 bfd_vma offset
= rel
->r_offset
;
5184 r_type
= ELF32_R_TYPE (rel
->r_info
);
5185 if (r_type
>= R_NDS32_max
)
5187 /* xgettext:c-format */
5188 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
5190 bfd_set_error (bfd_error_bad_value
);
5195 if (r_type
== R_NDS32_GNU_VTENTRY
5196 || r_type
== R_NDS32_GNU_VTINHERIT
5197 || r_type
== R_NDS32_NONE
5198 || r_type
== R_NDS32_RELA_GNU_VTENTRY
5199 || r_type
== R_NDS32_RELA_GNU_VTINHERIT
5200 || (r_type
>= R_NDS32_INSN16
&& r_type
<= R_NDS32_25_FIXED_RELA
)
5201 || r_type
== R_NDS32_DATA
5202 || r_type
== R_NDS32_TRAN
)
5205 /* If we enter the fp-as-gp region. Resolve the address
5207 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
5208 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
5212 /* Distance to relocation of best fp-base is encoded in R_SYM. */
5213 dist
= rel
->r_addend
>> 16;
5214 fpbase_addr
= calculate_memory_address (input_bfd
, rel
+ dist
,
5215 local_syms
, symtab_hdr
);
5217 else if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_END
5218 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
5220 fpbase_addr
= elf_gp (output_bfd
);
5223 /* Skip the relocations used for relaxation. */
5224 /* We have to update LONGCALL and LONGJUMP
5225 relocations when generating the relocatable files. */
5226 if (!bfd_link_relocatable (info
)
5227 && (r_type
>= R_NDS32_RELAX_ENTRY
5228 || (r_type
>= R_NDS32_LONGCALL4
5229 && r_type
<= R_NDS32_LONGJUMP7
)))
5232 howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
5233 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5235 /* This is a final link. */
5240 if (r_symndx
< symtab_hdr
->sh_info
)
5243 sym
= local_syms
+ r_symndx
;
5244 sec
= local_sections
[r_symndx
];
5246 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5247 addend
= rel
->r_addend
;
5249 /* keep symbol location for static TLS_IE GOT entry */
5250 relocation_sym
= relocation
;
5251 if (bfd_link_relocatable (info
))
5253 /* This is a relocatable link. We don't have to change
5254 anything, unless the reloc is against a section symbol,
5255 in which case we have to adjust according to where the
5256 section symbol winds up in the output section. */
5257 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5258 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
5265 /* External symbol. */
5266 if (bfd_link_relocatable (info
))
5268 bfd_boolean warned
, ignored
, unresolved_reloc
;
5269 int symndx
= r_symndx
- symtab_hdr
->sh_info
;
5271 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5272 r_symndx
, symtab_hdr
, sym_hashes
, h
, sec
,
5273 relocation
, unresolved_reloc
, warned
,
5276 /* keep symbol location for static TLS_IE GOT entry */
5277 relocation_sym
= relocation
;
5279 /* la $fp, _FP_BASE_ is per-function (region).
5280 Handle it specially. */
5281 switch ((int) r_type
)
5283 case R_NDS32_HI20_RELA
:
5284 case R_NDS32_LO12S0_RELA
:
5285 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
5288 if (!bfd_link_pie (info
))
5291 ("%pB: warning: _FP_BASE_ setting insns relaxation failed.",
5294 relocation
= fpbase_addr
;
5297 case R_NDS32_SDA19S0_RELA
:
5298 case R_NDS32_SDA15S0_RELA
:
5299 case R_NDS32_20_RELA
:
5300 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
5303 relocation
= fpbase_addr
;
5309 /* Sanity check the address. */
5310 if (offset
> high_address
)
5312 r
= bfd_reloc_outofrange
;
5316 if (r_type
>= R_NDS32_RELAX_ENTRY
)
5319 switch ((int) r_type
)
5321 case R_NDS32_GOTOFF
:
5322 /* Relocation is relative to the start of the global offset
5323 table (for ld24 rx, #uimm24), e.g. access at label+addend
5325 ld24 rx. #label@GOTOFF + addend
5327 case R_NDS32_GOTOFF_HI20
:
5328 case R_NDS32_GOTOFF_LO12
:
5329 case R_NDS32_GOTOFF_LO15
:
5330 case R_NDS32_GOTOFF_LO19
:
5331 BFD_ASSERT (sgot
!= NULL
);
5333 relocation
-= elf_gp (output_bfd
);
5336 case R_NDS32_9_PLTREL
:
5337 case R_NDS32_25_PLTREL
:
5338 /* Relocation is to the entry for this symbol in the
5339 procedure linkage table. */
5341 /* The native assembler will generate a 25_PLTREL reloc
5342 for a local symbol if you assemble a call from one
5343 section to another when using -K pic. */
5347 if (h
->forced_local
)
5350 /* We didn't make a PLT entry for this symbol. This
5351 happens when statically linking PIC code, or when
5352 using -Bsymbolic. */
5353 if (h
->plt
.offset
== (bfd_vma
) - 1)
5356 relocation
= (splt
->output_section
->vma
5357 + splt
->output_offset
+ h
->plt
.offset
);
5360 case R_NDS32_PLT_GOTREL_HI20
:
5361 case R_NDS32_PLT_GOTREL_LO12
:
5362 case R_NDS32_PLT_GOTREL_LO15
:
5363 case R_NDS32_PLT_GOTREL_LO19
:
5364 case R_NDS32_PLT_GOTREL_LO20
:
5367 || h
->plt
.offset
== (bfd_vma
) -1
5368 || (bfd_link_pie (info
) && h
->def_regular
))
5370 /* Maybe we should find better checking to optimize
5371 PIE PLT relocations. */
5372 /* We didn't make a PLT entry for this symbol. This
5373 happens when statically linking PIC code, or when
5374 using -Bsymbolic. */
5376 h
->plt
.offset
= (bfd_vma
) -1; /* Cancel PLT trampoline. */
5377 relocation
-= elf_gp (output_bfd
);
5381 relocation
= (splt
->output_section
->vma
5382 + splt
->output_offset
+ h
->plt
.offset
);
5384 relocation
-= elf_gp (output_bfd
);
5387 case R_NDS32_PLTREL_HI20
:
5388 case R_NDS32_PLTREL_LO12
:
5390 /* Relocation is to the entry for this symbol in the
5391 procedure linkage table. */
5393 /* The native assembler will generate a 25_PLTREL reloc
5394 for a local symbol if you assemble a call from one
5395 section to another when using -K pic. */
5399 if (h
->forced_local
)
5402 if (h
->plt
.offset
== (bfd_vma
) - 1)
5403 /* We didn't make a PLT entry for this symbol. This
5404 happens when statically linking PIC code, or when
5405 using -Bsymbolic. */
5411 relocation
= (splt
->output_section
->vma
5412 + splt
->output_offset
5413 + h
->plt
.offset
+ 4)
5414 - (input_section
->output_section
->vma
5415 + input_section
->output_offset
5420 case R_NDS32_GOTPC20
:
5421 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5422 ld24 rx,#_GLOBAL_OFFSET_TABLE_ */
5423 relocation
= elf_gp (output_bfd
);
5426 case R_NDS32_GOTPC_HI20
:
5427 case R_NDS32_GOTPC_LO12
:
5428 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
5430 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
5431 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
5434 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
5435 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4) */
5436 relocation
= elf_gp (output_bfd
);
5437 relocation
-= (input_section
->output_section
->vma
5438 + input_section
->output_offset
+ rel
->r_offset
);
5443 case R_NDS32_GOT_HI20
:
5444 case R_NDS32_GOT_LO12
:
5445 case R_NDS32_GOT_LO15
:
5446 case R_NDS32_GOT_LO19
:
5447 /* Relocation is to the entry for this symbol in the global
5449 BFD_ASSERT (sgot
!= NULL
);
5453 /* External symbol */
5456 off
= h
->got
.offset
;
5457 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5458 dyn
= htab
->root
.dynamic_sections_created
;
5459 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
5460 bfd_link_pic (info
),
5462 || (bfd_link_pic (info
)
5465 || h
->forced_local
) && h
->def_regular
))
5467 /* This is actually a static link, or it is a
5468 -Bsymbolic link and the symbol is defined
5469 locally, or the symbol was forced to be local
5470 because of a version file. We must initialize
5471 this entry in the global offset table. Since the
5472 offset must always be a multiple of 4, we use the
5473 least significant bit to record whether we have
5474 initialized it already.
5476 When doing a dynamic link, we create a .rela.got
5477 relocation entry to initialize the value. This
5478 is done in the finish_dynamic_symbol routine. */
5479 if ((off
& 1) != 0) /* clear LSB */
5483 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5487 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5488 - elf_gp (output_bfd
);
5495 BFD_ASSERT (local_got_offsets
!= NULL
5496 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5498 off
= local_got_offsets
[r_symndx
];
5500 /* The offset must always be a multiple of 4. We use
5501 the least significant bit to record whether we have
5502 already processed this entry. */
5503 if ((off
& 1) != 0) /* clear LSB */
5507 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5509 if (bfd_link_pic (info
))
5512 Elf_Internal_Rela outrel
;
5514 /* We need to generate a R_NDS32_RELATIVE reloc
5515 for the dynamic linker. */
5516 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5517 BFD_ASSERT (srelgot
!= NULL
);
5519 outrel
.r_offset
= (elf_gp (output_bfd
)
5520 + sgot
->output_offset
+ off
);
5521 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5522 outrel
.r_addend
= relocation
;
5523 loc
= srelgot
->contents
;
5525 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5526 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5527 ++srelgot
->reloc_count
;
5529 local_got_offsets
[r_symndx
] |= 1;
5531 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5532 - elf_gp (output_bfd
);
5537 case R_NDS32_16_RELA
:
5538 case R_NDS32_20_RELA
:
5539 case R_NDS32_5_RELA
:
5540 case R_NDS32_32_RELA
:
5541 case R_NDS32_9_PCREL_RELA
:
5542 case R_NDS32_WORD_9_PCREL_RELA
:
5543 case R_NDS32_10_UPCREL_RELA
:
5544 case R_NDS32_15_PCREL_RELA
:
5545 case R_NDS32_17_PCREL_RELA
:
5546 case R_NDS32_25_PCREL_RELA
:
5547 case R_NDS32_HI20_RELA
:
5548 case R_NDS32_LO12S3_RELA
:
5549 case R_NDS32_LO12S2_RELA
:
5550 case R_NDS32_LO12S2_DP_RELA
:
5551 case R_NDS32_LO12S2_SP_RELA
:
5552 case R_NDS32_LO12S1_RELA
:
5553 case R_NDS32_LO12S0_RELA
:
5554 case R_NDS32_LO12S0_ORI_RELA
:
5555 if (bfd_link_pic (info
) && r_symndx
!= 0
5556 && (input_section
->flags
& SEC_ALLOC
) != 0
5557 && (eliminate_gc_relocs
== 0
5558 || (sec
&& (sec
->flags
& SEC_EXCLUDE
) == 0))
5559 && ((r_type
!= R_NDS32_9_PCREL_RELA
5560 && r_type
!= R_NDS32_WORD_9_PCREL_RELA
5561 && r_type
!= R_NDS32_10_UPCREL_RELA
5562 && r_type
!= R_NDS32_15_PCREL_RELA
5563 && r_type
!= R_NDS32_17_PCREL_RELA
5564 && r_type
!= R_NDS32_25_PCREL_RELA
5565 && !(r_type
== R_NDS32_32_RELA
5566 && strcmp (input_section
->name
, ".eh_frame") == 0))
5567 || (h
!= NULL
&& h
->dynindx
!= -1
5568 && (!info
->symbolic
|| !h
->def_regular
))))
5570 Elf_Internal_Rela outrel
;
5571 bfd_boolean skip
, relocate
;
5574 /* When generating a shared object, these relocations
5575 are copied into the output file to be resolved at run
5582 name
= bfd_elf_string_from_elf_section
5583 (input_bfd
, elf_elfheader (input_bfd
)->e_shstrndx
,
5584 elf_section_data (input_section
)->rela
.hdr
->sh_name
);
5588 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5589 && strcmp (bfd_get_section_name (input_bfd
,
5593 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5594 BFD_ASSERT (sreloc
!= NULL
);
5600 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
5604 if (outrel
.r_offset
== (bfd_vma
) - 1)
5606 else if (outrel
.r_offset
== (bfd_vma
) - 2)
5607 skip
= TRUE
, relocate
= TRUE
;
5608 outrel
.r_offset
+= (input_section
->output_section
->vma
5609 + input_section
->output_offset
);
5612 memset (&outrel
, 0, sizeof outrel
);
5613 else if (r_type
== R_NDS32_17_PCREL_RELA
5614 || r_type
== R_NDS32_15_PCREL_RELA
5615 || r_type
== R_NDS32_25_PCREL_RELA
)
5617 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5618 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5619 outrel
.r_addend
= rel
->r_addend
;
5623 /* h->dynindx may be -1 if this symbol was marked to
5626 || ((info
->symbolic
|| h
->dynindx
== -1)
5628 || (bfd_link_pie (info
) && h
->def_regular
))
5631 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5632 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5636 h
->plt
.offset
= (bfd_vma
) -1; /* cancel PLT trampoline. */
5638 BFD_ASSERT (sgot
!= NULL
);
5639 /* If we did not allocate got entry for the symbol,
5640 we can not fill the nonexistent got entry. */
5641 if (h
->got
.offset
!= (bfd_vma
) -1
5642 && (h
->got
.offset
& 1) == 0)
5644 bfd_put_32 (output_bfd
, outrel
.r_addend
,
5645 sgot
->contents
+ h
->got
.offset
);
5651 if (h
->dynindx
== -1)
5654 (_("%pB: relocation %s against `%s' can not be used when"
5655 "making a shared object; recompile with -fPIC"),
5656 input_bfd
, nds32_elf_howto_table
[r_type
].name
, h
->root
.root
.string
);
5657 bfd_set_error (bfd_error_bad_value
);
5661 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5662 outrel
.r_addend
= rel
->r_addend
;
5666 loc
= sreloc
->contents
;
5667 loc
+= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
5668 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5669 ++sreloc
->reloc_count
;
5671 /* If this reloc is against an external symbol, we do
5672 not want to fiddle with the addend. Otherwise, we
5673 need to include the symbol value so that it becomes
5674 an addend for the dynamic reloc. */
5680 case R_NDS32_25_ABS_RELA
:
5681 if (bfd_link_pic (info
))
5684 (_("%pB: warning: %s unsupported in shared mode"),
5685 input_bfd
, "R_NDS32_25_ABS_RELA");
5690 case R_NDS32_9_PCREL
:
5691 r
= nds32_elf_do_9_pcrel_reloc (input_bfd
, howto
, input_section
,
5693 sec
, relocation
, addend
);
5697 /* We allow an arbitrary number of HI20 relocs before the
5698 LO12 reloc. This permits gcc to emit the HI and LO relocs
5700 for (lorel
= rel
+ 1;
5702 && ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_HI20
); lorel
++)
5705 && (ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S3
5706 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S2
5707 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S1
5708 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S0
))
5710 nds32_elf_relocate_hi20 (input_bfd
, r_type
, rel
, lorel
,
5711 contents
, relocation
+ addend
);
5715 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5716 contents
, offset
, relocation
,
5720 case R_NDS32_GOT17S2_RELA
:
5721 case R_NDS32_GOT15S2_RELA
:
5722 BFD_ASSERT (sgot
!= NULL
);
5728 off
= h
->got
.offset
;
5729 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5731 dyn
= htab
->root
.dynamic_sections_created
;
5732 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL
5733 (dyn
, bfd_link_pic (info
), h
)
5734 || (bfd_link_pic (info
)
5740 /* This is actually a static link, or it is a
5741 -Bsymbolic link and the symbol is defined
5742 locally, or the symbol was forced to be local
5743 because of a version file. We must initialize
5744 this entry in the global offset table. Since the
5745 offset must always be a multiple of 4, we use the
5746 least significant bit to record whether we have
5747 initialized it already.
5749 When doing a dynamic link, we create a .rela.got
5750 relocation entry to initialize the value. This
5751 is done in the finish_dynamic_symbol routine. */
5756 bfd_put_32 (output_bfd
, relocation
,
5757 sgot
->contents
+ off
);
5766 BFD_ASSERT (local_got_offsets
!= NULL
5767 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5769 off
= local_got_offsets
[r_symndx
];
5771 /* The offset must always be a multiple of 4. We use
5772 the least significant bit to record whether we have
5773 already processed this entry. */
5778 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5780 if (bfd_link_pic (info
))
5783 Elf_Internal_Rela outrel
;
5785 /* We need to generate a R_NDS32_RELATIVE reloc
5786 for the dynamic linker. */
5787 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5788 BFD_ASSERT (srelgot
!= NULL
);
5790 outrel
.r_offset
= (elf_gp (output_bfd
)
5791 + sgot
->output_offset
+ off
);
5792 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5793 outrel
.r_addend
= relocation
;
5794 loc
= srelgot
->contents
;
5796 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5797 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5798 ++srelgot
->reloc_count
;
5800 local_got_offsets
[r_symndx
] |= 1;
5803 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5804 - elf_gp (output_bfd
);
5806 if (relocation
& align
)
5808 /* Incorrect alignment. */
5810 (_("%pB: warning: unaligned access to GOT entry"), input_bfd
);
5812 r
= bfd_reloc_dangerous
;
5817 case R_NDS32_SDA16S3_RELA
:
5818 case R_NDS32_SDA15S3_RELA
:
5819 case R_NDS32_SDA15S3
:
5823 case R_NDS32_SDA17S2_RELA
:
5824 case R_NDS32_SDA15S2_RELA
:
5825 case R_NDS32_SDA12S2_SP_RELA
:
5826 case R_NDS32_SDA12S2_DP_RELA
:
5827 case R_NDS32_SDA15S2
:
5828 case R_NDS32_SDA_FP7U2_RELA
:
5832 case R_NDS32_SDA18S1_RELA
:
5833 case R_NDS32_SDA15S1_RELA
:
5834 case R_NDS32_SDA15S1
:
5838 case R_NDS32_SDA19S0_RELA
:
5839 case R_NDS32_SDA15S0_RELA
:
5840 case R_NDS32_SDA15S0
:
5843 BFD_ASSERT (sec
!= NULL
);
5845 /* If the symbol is in the abs section, the out_bfd will be null.
5846 This happens when the relocation has a symbol@GOTOFF. */
5847 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, FALSE
);
5848 if (r
!= bfd_reloc_ok
)
5851 (_("%pB: warning: relocate SDA_BASE failed"), input_bfd
);
5856 /* At this point `relocation' contains the object's
5858 if (r_type
== R_NDS32_SDA_FP7U2_RELA
)
5860 relocation
-= fpbase_addr
;
5864 /* Now it contains the offset from _SDA_BASE_. */
5866 /* Make sure alignment is correct. */
5868 if (relocation
& align
)
5870 /* Incorrect alignment. */
5872 /* xgettext:c-format */
5873 (_("%pB(%pA): warning: unaligned small data access"
5875 input_bfd
, input_section
, r_type
);
5881 case R_NDS32_17IFC_PCREL_RELA
:
5882 case R_NDS32_10IFCU_PCREL_RELA
:
5886 case R_NDS32_TLS_LE_HI20
:
5887 case R_NDS32_TLS_LE_LO12
:
5888 case R_NDS32_TLS_LE_20
:
5889 case R_NDS32_TLS_LE_15S0
:
5890 case R_NDS32_TLS_LE_15S1
:
5891 case R_NDS32_TLS_LE_15S2
:
5892 /* We do not have garbage collection for got entries.
5893 Therefore, IE to LE may have one empty entry, and DESC to
5895 if (elf_hash_table (info
)->tls_sec
!= NULL
)
5896 relocation
-= (elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
);
5899 case R_NDS32_TLS_IE_HI20
:
5900 case R_NDS32_TLS_IE_LO12S2
:
5901 case R_NDS32_TLS_DESC_HI20
:
5902 case R_NDS32_TLS_DESC_LO12
:
5903 case R_NDS32_TLS_IE_LO12
:
5904 case R_NDS32_TLS_IEGP_HI20
:
5905 case R_NDS32_TLS_IEGP_LO12
:
5906 case R_NDS32_TLS_IEGP_LO12S2
:
5908 /* Relocation is to the entry for this symbol in the global
5910 enum elf_nds32_tls_type tls_type
, org_tls_type
, eff_tls_type
;
5912 Elf_Internal_Rela outrel
;
5916 eff_tls_type
= org_tls_type
= get_tls_type (r_type
, h
);
5918 BFD_ASSERT (sgot
!= NULL
);
5923 off
= h
->got
.offset
;
5924 BFD_ASSERT (off
!= (bfd_vma
) -1);
5925 dyn
= htab
->root
.dynamic_sections_created
;
5926 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
5927 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
5928 && (!bfd_link_pic (info
)
5929 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
5934 BFD_ASSERT (local_got_offsets
!= NULL
5935 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5936 off
= local_got_offsets
[r_symndx
];
5937 tls_type
= elf32_nds32_local_got_tls_type (input_bfd
)[r_symndx
];
5940 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
;
5942 if (1 < ones32 (tls_type
))
5944 eff_tls_type
= 1 << (fls (tls_type
) - 1);
5945 /* TLS model shall be handled in nds32_elf_unify_tls_model (). */
5947 /* TLS model X -> LE is not implement yet!
5949 if (eff_tls_type
== GOT_TLS_LE
)
5951 eff_tls_type
= 1 << (fls (tls_type
^ eff_tls_type
) - 1);
5955 /* The offset must always be a multiple of 4. We use
5956 the least significant bit to record whether we have
5957 already processed this entry. */
5958 bfd_boolean need_relocs
= FALSE
;
5959 srelgot
= ehtab
->srelgot
;
5960 if ((bfd_link_pic (info
) || indx
!= 0)
5961 && (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5962 || h
->root
.type
!= bfd_link_hash_undefweak
))
5965 BFD_ASSERT (srelgot
!= NULL
);
5973 if (eff_tls_type
& GOT_TLS_DESC
)
5975 relocation
-= elf_gp (output_bfd
);
5976 if ((R_NDS32_TLS_DESC_HI20
== r_type
) && (!need_relocs
))
5978 /* TLS model shall be converted. */
5982 else if (eff_tls_type
& GOT_TLS_IEGP
)
5984 relocation
-= elf_gp (output_bfd
);
5989 if ((eff_tls_type
& GOT_TLS_LE
) && (tls_type
^ eff_tls_type
))
5991 /* TLS model workaround shall be applied. */
5994 else if (eff_tls_type
& (GOT_TLS_IE
| GOT_TLS_IEGP
))
5996 if (eff_tls_type
& GOT_TLS_IEGP
)
5997 relocation
-= elf_gp(output_bfd
);
6002 outrel
.r_addend
= gottpoff (info
, relocation_sym
);
6004 outrel
.r_addend
= 0;
6005 outrel
.r_offset
= (sgot
->output_section
->vma
6006 + sgot
->output_offset
+ off
);
6007 outrel
.r_info
= ELF32_R_INFO (indx
, R_NDS32_TLS_TPOFF
);
6009 elf32_nds32_add_dynreloc (output_bfd
, info
, srelgot
,
6014 bfd_put_32 (output_bfd
, gottpoff (info
, relocation_sym
),
6015 sgot
->contents
+ off
);
6018 else if (eff_tls_type
& GOT_TLS_DESC
)
6020 relocation
-= elf_gp (output_bfd
);
6024 outrel
.r_addend
= gottpoff (info
, relocation_sym
);
6026 outrel
.r_addend
= 0;
6027 outrel
.r_offset
= (sgot
->output_section
->vma
6028 + sgot
->output_offset
+ off
);
6029 outrel
.r_info
= ELF32_R_INFO (indx
, R_NDS32_TLS_DESC
);
6031 if (htab
->tls_desc_trampoline
)
6034 srelplt
= ehtab
->srelplt
;
6035 loc
= srelplt
->contents
;
6036 loc
+= htab
->next_tls_desc_index
++ * sizeof (Elf32_External_Rela
);
6037 BFD_ASSERT (loc
+ sizeof (Elf32_External_Rela
)
6038 <= srelplt
->contents
+ srelplt
->size
);
6040 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
6044 loc
= srelgot
->contents
;
6045 loc
+= srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
6046 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
6047 ++srelgot
->reloc_count
;
6053 bfd_put_32 (output_bfd
, 0xdeadbeef,
6054 sgot
->contents
+ off
);
6055 bfd_put_32 (output_bfd
, gottpoff (info
, relocation_sym
),
6056 sgot
->contents
+ off
+ 4);
6057 patch_tls_desc_to_ie (contents
, rel
, input_bfd
);
6063 /* TLS model workaround shall be applied. */
6070 local_got_offsets
[r_symndx
] |= 1;
6074 /* DON'T fall through. */
6077 /* OLD_NDS32_RELOC. */
6079 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6080 contents
, offset
, relocation
, addend
);
6084 switch ((int) r_type
)
6086 case R_NDS32_20_RELA
:
6087 case R_NDS32_5_RELA
:
6088 case R_NDS32_9_PCREL_RELA
:
6089 case R_NDS32_WORD_9_PCREL_RELA
:
6090 case R_NDS32_10_UPCREL_RELA
:
6091 case R_NDS32_15_PCREL_RELA
:
6092 case R_NDS32_17_PCREL_RELA
:
6093 case R_NDS32_25_PCREL_RELA
:
6094 case R_NDS32_25_ABS_RELA
:
6095 case R_NDS32_HI20_RELA
:
6096 case R_NDS32_LO12S3_RELA
:
6097 case R_NDS32_LO12S2_RELA
:
6098 case R_NDS32_LO12S2_DP_RELA
:
6099 case R_NDS32_LO12S2_SP_RELA
:
6100 case R_NDS32_LO12S1_RELA
:
6101 case R_NDS32_LO12S0_RELA
:
6102 case R_NDS32_LO12S0_ORI_RELA
:
6103 case R_NDS32_SDA16S3_RELA
:
6104 case R_NDS32_SDA17S2_RELA
:
6105 case R_NDS32_SDA18S1_RELA
:
6106 case R_NDS32_SDA19S0_RELA
:
6107 case R_NDS32_SDA15S3_RELA
:
6108 case R_NDS32_SDA15S2_RELA
:
6109 case R_NDS32_SDA12S2_DP_RELA
:
6110 case R_NDS32_SDA12S2_SP_RELA
:
6111 case R_NDS32_SDA15S1_RELA
:
6112 case R_NDS32_SDA15S0_RELA
:
6113 case R_NDS32_SDA_FP7U2_RELA
:
6114 case R_NDS32_9_PLTREL
:
6115 case R_NDS32_25_PLTREL
:
6117 case R_NDS32_GOT_HI20
:
6118 case R_NDS32_GOT_LO12
:
6119 case R_NDS32_GOT_LO15
:
6120 case R_NDS32_GOT_LO19
:
6121 case R_NDS32_GOT15S2_RELA
:
6122 case R_NDS32_GOT17S2_RELA
:
6123 case R_NDS32_GOTPC20
:
6124 case R_NDS32_GOTPC_HI20
:
6125 case R_NDS32_GOTPC_LO12
:
6126 case R_NDS32_GOTOFF
:
6127 case R_NDS32_GOTOFF_HI20
:
6128 case R_NDS32_GOTOFF_LO12
:
6129 case R_NDS32_GOTOFF_LO15
:
6130 case R_NDS32_GOTOFF_LO19
:
6131 case R_NDS32_PLTREL_HI20
:
6132 case R_NDS32_PLTREL_LO12
:
6133 case R_NDS32_PLT_GOTREL_HI20
:
6134 case R_NDS32_PLT_GOTREL_LO12
:
6135 case R_NDS32_PLT_GOTREL_LO15
:
6136 case R_NDS32_PLT_GOTREL_LO19
:
6137 case R_NDS32_PLT_GOTREL_LO20
:
6138 case R_NDS32_17IFC_PCREL_RELA
:
6139 case R_NDS32_10IFCU_PCREL_RELA
:
6140 case R_NDS32_TLS_LE_HI20
:
6141 case R_NDS32_TLS_LE_LO12
:
6142 case R_NDS32_TLS_IE_HI20
:
6143 case R_NDS32_TLS_IE_LO12S2
:
6144 case R_NDS32_TLS_LE_20
:
6145 case R_NDS32_TLS_LE_15S0
:
6146 case R_NDS32_TLS_LE_15S1
:
6147 case R_NDS32_TLS_LE_15S2
:
6148 case R_NDS32_TLS_DESC_HI20
:
6149 case R_NDS32_TLS_DESC_LO12
:
6150 case R_NDS32_TLS_IE_LO12
:
6151 case R_NDS32_TLS_IEGP_HI20
:
6152 case R_NDS32_TLS_IEGP_LO12
:
6153 case R_NDS32_TLS_IEGP_LO12S2
:
6154 /* Instruction related relocs must handle endian properly. */
6155 /* NOTE: PIC IS NOT HANDLE YET; DO IT LATER. */
6156 r
= nds32_elf_final_link_relocate (howto
, input_bfd
,
6157 input_section
, contents
,
6158 rel
->r_offset
, relocation
,
6163 /* All other relocs can use default handler. */
6164 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6165 contents
, rel
->r_offset
,
6166 relocation
, rel
->r_addend
);
6172 if (r
!= bfd_reloc_ok
)
6174 /* FIXME: This should be generic enough to go in a utility. */
6178 name
= h
->root
.root
.string
;
6181 name
= bfd_elf_string_from_elf_section
6182 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
6183 if (name
== NULL
|| *name
== '\0')
6184 name
= bfd_section_name (input_bfd
, sec
);
6192 case bfd_reloc_overflow
:
6193 (*info
->callbacks
->reloc_overflow
)
6194 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
6195 (bfd_vma
) 0, input_bfd
, input_section
, offset
);
6198 case bfd_reloc_undefined
:
6199 (*info
->callbacks
->undefined_symbol
)
6200 (info
, name
, input_bfd
, input_section
, offset
, TRUE
);
6203 case bfd_reloc_outofrange
:
6204 errmsg
= _("internal error: out of range error");
6207 case bfd_reloc_notsupported
:
6208 errmsg
= _("internal error: unsupported relocation error");
6211 case bfd_reloc_dangerous
:
6212 errmsg
= _("internal error: dangerous error");
6216 errmsg
= _("internal error: unknown error");
6220 (*info
->callbacks
->warning
) (info
, errmsg
, name
, input_bfd
,
6221 input_section
, offset
);
6227 /* Resotre header size to avoid overflow load. */
6228 if (elf_nds32_tdata (input_bfd
)->hdr_size
!= 0)
6229 symtab_hdr
->sh_size
= elf_nds32_tdata (input_bfd
)->hdr_size
;
6234 /* Finish up dynamic symbol handling. We set the contents of various
6235 dynamic sections here. */
6238 nds32_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6239 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
)
6241 struct elf_link_hash_table
*ehtab
;
6242 struct elf_nds32_link_hash_entry
*hent
;
6245 ehtab
= elf_hash_table (info
);
6246 hent
= (struct elf_nds32_link_hash_entry
*) h
;
6248 if (h
->plt
.offset
!= (bfd_vma
) - 1)
6256 bfd_vma local_plt_offset
;
6257 Elf_Internal_Rela rela
;
6259 /* This symbol has an entry in the procedure linkage table. Set
6262 BFD_ASSERT (h
->dynindx
!= -1);
6265 sgot
= ehtab
->sgotplt
;
6266 srela
= ehtab
->srelplt
;
6267 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
6269 /* Get the index in the procedure linkage table which
6270 corresponds to this symbol. This is the index of this symbol
6271 in all the symbols for which we are making plt entries. The
6272 first entry in the procedure linkage table is reserved. */
6273 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
6275 /* Get the offset into the .got table of the entry that
6276 corresponds to this function. Each .got entry is 4 bytes.
6277 The first three are reserved. */
6278 got_offset
= (plt_index
+ 3) * 4;
6280 /* Fill in the entry in the procedure linkage table. */
6281 if (!bfd_link_pic (info
))
6285 insn
= PLT_ENTRY_WORD0
+ (((sgot
->output_section
->vma
6286 + sgot
->output_offset
+ got_offset
) >> 12)
6288 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
6290 insn
= PLT_ENTRY_WORD1
+ (((sgot
->output_section
->vma
6291 + sgot
->output_offset
+ got_offset
) & 0x0fff)
6293 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
6295 insn
= PLT_ENTRY_WORD2
;
6296 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
6298 insn
= PLT_ENTRY_WORD3
+ (plt_index
& 0x7ffff);
6299 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
6301 insn
= PLT_ENTRY_WORD4
6302 + (((unsigned int) ((-(h
->plt
.offset
+ 16)) >> 1)) & 0xffffff);
6303 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
6304 local_plt_offset
= 12;
6308 /* sda_base must be set at this time. */
6312 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ got_offset
6313 - elf_gp (output_bfd
);
6314 insn
= PLT_PIC_ENTRY_WORD0
+ ((offset
>> 12) & 0xfffff);
6315 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
6317 insn
= PLT_PIC_ENTRY_WORD1
+ (offset
& 0xfff);
6318 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
6320 insn
= PLT_PIC_ENTRY_WORD2
;
6321 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
6323 insn
= PLT_PIC_ENTRY_WORD3
;
6324 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
6326 insn
= PLT_PIC_ENTRY_WORD4
+ (plt_index
& 0x7fffff);
6327 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
6329 insn
= PLT_PIC_ENTRY_WORD5
6330 + (((unsigned int) ((-(h
->plt
.offset
+ 20)) >> 1)) & 0xffffff);
6331 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 20);
6333 local_plt_offset
= 16;
6336 /* Fill in the entry in the global offset table,
6337 so it will fall through to the next instruction for the first time. */
6338 bfd_put_32 (output_bfd
,
6339 (splt
->output_section
->vma
+ splt
->output_offset
6340 + h
->plt
.offset
+ local_plt_offset
),
6341 sgot
->contents
+ got_offset
);
6343 /* Fill in the entry in the .rela.plt section. */
6344 rela
.r_offset
= (sgot
->output_section
->vma
6345 + sgot
->output_offset
+ got_offset
);
6346 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_JMP_SLOT
);
6348 loc
= srela
->contents
;
6349 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
6350 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6352 if (!h
->def_regular
)
6354 /* Mark the symbol as undefined, rather than as defined in
6355 the .plt section. Leave the value alone. */
6356 sym
->st_shndx
= SHN_UNDEF
;
6357 if (!h
->ref_regular_nonweak
)
6362 if (h
->got
.offset
!= (bfd_vma
) - 1
6363 && hent
->tls_type
== GOT_NORMAL
)
6367 Elf_Internal_Rela rela
;
6369 /* This symbol has an entry in the global offset table.
6373 srelagot
= ehtab
->srelgot
;
6374 BFD_ASSERT (sgot
!= NULL
&& srelagot
!= NULL
);
6376 rela
.r_offset
= (sgot
->output_section
->vma
6377 + sgot
->output_offset
+ (h
->got
.offset
& ~1));
6379 /* If this is a -Bsymbolic link, and the symbol is defined
6380 locally, we just want to emit a RELATIVE reloc. Likewise if
6381 the symbol was forced to be local because of a version file.
6382 The entry in the global offset table will already have been
6383 initialized in the relocate_section function. */
6384 if ((bfd_link_pic (info
)
6385 && (info
->symbolic
|| h
->dynindx
== -1 || h
->forced_local
)
6387 || (bfd_link_pie (info
) && h
->def_regular
))
6389 rela
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
6390 rela
.r_addend
= (h
->root
.u
.def
.value
6391 + h
->root
.u
.def
.section
->output_section
->vma
6392 + h
->root
.u
.def
.section
->output_offset
);
6394 if ((h
->got
.offset
& 1) == 0)
6396 bfd_put_32 (output_bfd
, rela
.r_addend
,
6397 sgot
->contents
+ h
->got
.offset
);
6402 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6403 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
6404 sgot
->contents
+ h
->got
.offset
);
6405 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_GLOB_DAT
);
6409 loc
= srelagot
->contents
;
6410 loc
+= srelagot
->reloc_count
* sizeof (Elf32_External_Rela
);
6411 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6412 ++srelagot
->reloc_count
;
6413 BFD_ASSERT (loc
< (srelagot
->contents
+ srelagot
->size
));
6419 Elf_Internal_Rela rela
;
6421 /* This symbols needs a copy reloc. Set it up. */
6423 BFD_ASSERT (h
->dynindx
!= -1
6424 && (h
->root
.type
== bfd_link_hash_defined
6425 || h
->root
.type
== bfd_link_hash_defweak
));
6427 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
, ".rela.bss");
6428 BFD_ASSERT (s
!= NULL
);
6430 rela
.r_offset
= (h
->root
.u
.def
.value
6431 + h
->root
.u
.def
.section
->output_section
->vma
6432 + h
->root
.u
.def
.section
->output_offset
);
6433 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_COPY
);
6436 loc
+= s
->reloc_count
* sizeof (Elf32_External_Rela
);
6437 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6441 /* Mark some specially defined symbols as absolute. */
6442 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6443 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
6444 sym
->st_shndx
= SHN_ABS
;
6450 /* Finish up the dynamic sections. */
6453 nds32_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
6458 struct elf_link_hash_table
*ehtab
;
6459 struct elf_nds32_link_hash_table
*htab
;
6461 ehtab
= elf_hash_table (info
);
6462 htab
= nds32_elf_hash_table (info
);
6466 dynobj
= elf_hash_table (info
)->dynobj
;
6468 sgotplt
= ehtab
->sgotplt
;
6469 /* A broken linker script might have discarded the dynamic sections.
6470 Catch this here so that we do not seg-fault later on. */
6471 if (sgotplt
!= NULL
&& bfd_is_abs_section (sgotplt
->output_section
))
6473 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6475 if (elf_hash_table (info
)->dynamic_sections_created
)
6478 Elf32_External_Dyn
*dyncon
, *dynconend
;
6480 BFD_ASSERT (sgotplt
!= NULL
&& sdyn
!= NULL
);
6482 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6483 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6485 for (; dyncon
< dynconend
; dyncon
++)
6487 Elf_Internal_Dyn dyn
;
6490 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6498 /* name = ".got"; */
6499 s
= ehtab
->sgot
->output_section
;
6502 s
= ehtab
->srelplt
->output_section
;
6504 BFD_ASSERT (s
!= NULL
);
6505 dyn
.d_un
.d_ptr
= s
->vma
;
6506 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6510 s
= ehtab
->srelplt
->output_section
;
6511 BFD_ASSERT (s
!= NULL
);
6512 dyn
.d_un
.d_val
= s
->size
;
6513 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6517 /* My reading of the SVR4 ABI indicates that the
6518 procedure linkage table relocs (DT_JMPREL) should be
6519 included in the overall relocs (DT_RELA). This is
6520 what Solaris does. However, UnixWare can not handle
6521 that case. Therefore, we override the DT_RELASZ entry
6522 here to make it not include the JMPREL relocs. Since
6523 the linker script arranges for .rela.plt to follow all
6524 other relocation sections, we don't have to worry
6525 about changing the DT_RELA entry. */
6526 if (ehtab
->srelplt
!= NULL
)
6528 s
= ehtab
->srelplt
->output_section
;
6529 dyn
.d_un
.d_val
-= s
->size
;
6531 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6534 case DT_TLSDESC_PLT
:
6535 s
= htab
->root
.splt
;
6536 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
6537 + htab
->dt_tlsdesc_plt
);
6538 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6541 case DT_TLSDESC_GOT
:
6542 s
= htab
->root
.sgot
;
6543 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
6544 + htab
->dt_tlsdesc_got
);
6545 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6550 /* Fill in the first entry in the procedure linkage table. */
6552 if (splt
&& splt
->size
> 0)
6554 if (bfd_link_pic (info
))
6559 offset
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
+ 4
6560 - elf_gp (output_bfd
);
6561 insn
= PLT0_PIC_ENTRY_WORD0
| ((offset
>> 12) & 0xfffff);
6562 bfd_putb32 (insn
, splt
->contents
);
6564 /* here has a typo? */
6565 insn
= PLT0_PIC_ENTRY_WORD1
| (offset
& 0xfff);
6566 bfd_putb32 (insn
, splt
->contents
+ 4);
6568 insn
= PLT0_PIC_ENTRY_WORD2
;
6569 bfd_putb32 (insn
, splt
->contents
+ 8);
6571 insn
= PLT0_PIC_ENTRY_WORD3
;
6572 bfd_putb32 (insn
, splt
->contents
+ 12);
6574 insn
= PLT0_PIC_ENTRY_WORD4
;
6575 bfd_putb32 (insn
, splt
->contents
+ 16);
6577 insn
= PLT0_PIC_ENTRY_WORD5
;
6578 bfd_putb32 (insn
, splt
->contents
+ 20);
6585 /* addr = .got + 4 */
6586 addr
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
+ 4;
6587 insn
= PLT0_ENTRY_WORD0
| ((addr
>> 12) & 0xfffff);
6588 bfd_putb32 (insn
, splt
->contents
);
6590 insn
= PLT0_ENTRY_WORD1
| (addr
& 0x0fff);
6591 bfd_putb32 (insn
, splt
->contents
+ 4);
6593 insn
= PLT0_ENTRY_WORD2
;
6594 bfd_putb32 (insn
, splt
->contents
+ 8);
6596 insn
= PLT0_ENTRY_WORD3
;
6597 bfd_putb32 (insn
, splt
->contents
+ 12);
6599 insn
= PLT0_ENTRY_WORD4
;
6600 bfd_putb32 (insn
, splt
->contents
+ 16);
6603 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
6607 if (htab
->dt_tlsdesc_plt
)
6609 /* Calculate addresses. */
6610 asection
*sgot
= sgot
= ehtab
->sgot
;
6611 bfd_vma pltgot
= sgotplt
->output_section
->vma
6612 + sgotplt
->output_offset
;
6613 bfd_vma tlsdesc_got
= sgot
->output_section
->vma
+ sgot
->output_offset
6614 + htab
->dt_tlsdesc_got
;
6616 /* Get GP offset. */
6617 pltgot
-= elf_gp (output_bfd
) - 4; /* PLTGOT[1] */
6618 tlsdesc_got
-= elf_gp (output_bfd
);
6620 /* Do relocation. */
6621 dl_tlsdesc_lazy_trampoline
[0] += ((1 << 20) - 1) & (tlsdesc_got
>> 12);
6622 dl_tlsdesc_lazy_trampoline
[1] += 0xfff & tlsdesc_got
;
6623 dl_tlsdesc_lazy_trampoline
[4] += ((1 << 20) - 1) & (pltgot
>> 12);
6624 dl_tlsdesc_lazy_trampoline
[5] += 0xfff & pltgot
;
6627 nds32_put_trampoline (splt
->contents
+ htab
->dt_tlsdesc_plt
,
6628 dl_tlsdesc_lazy_trampoline
,
6629 ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
));
6633 /* Fill in the first three entries in the global offset table. */
6634 if (sgotplt
&& sgotplt
->size
> 0)
6637 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
);
6639 bfd_put_32 (output_bfd
,
6640 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6642 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 4);
6643 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgotplt
->contents
+ 8);
6645 elf_section_data (sgotplt
->output_section
)->this_hdr
.sh_entsize
= 4;
6652 /* Set the right machine number. */
6655 nds32_elf_object_p (bfd
*abfd
)
6657 static unsigned int cur_arch
= 0;
6659 if (E_N1_ARCH
!= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
))
6661 /* E_N1_ARCH is a wild card, so it is set only when no others exist. */
6662 cur_arch
= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
);
6669 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1
);
6672 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h
);
6674 case E_NDS_ARCH_STAR_V2_0
:
6675 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v2
);
6677 case E_NDS_ARCH_STAR_V3_0
:
6678 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3
);
6680 case E_NDS_ARCH_STAR_V3_M
:
6681 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3m
);
6688 /* Store the machine number in the flags field. */
6691 nds32_elf_final_write_processing (bfd
*abfd
,
6692 bfd_boolean linker ATTRIBUTE_UNUSED
)
6695 static unsigned int cur_mach
= 0;
6697 if (bfd_mach_n1
!= bfd_get_mach (abfd
))
6699 cur_mach
= bfd_get_mach (abfd
);
6705 /* Only happen when object is empty, since the case is abandon. */
6707 val
|= E_NDS_ABI_AABI
;
6708 val
|= E_NDS32_ELF_VER_1_4
;
6713 case bfd_mach_n1h_v2
:
6714 val
= E_NDS_ARCH_STAR_V2_0
;
6716 case bfd_mach_n1h_v3
:
6717 val
= E_NDS_ARCH_STAR_V3_0
;
6719 case bfd_mach_n1h_v3m
:
6720 val
= E_NDS_ARCH_STAR_V3_M
;
6727 elf_elfheader (abfd
)->e_flags
&= ~EF_NDS_ARCH
;
6728 elf_elfheader (abfd
)->e_flags
|= val
;
6731 /* Function to keep NDS32 specific file flags. */
6734 nds32_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6736 BFD_ASSERT (!elf_flags_init (abfd
)
6737 || elf_elfheader (abfd
)->e_flags
== flags
);
6739 elf_elfheader (abfd
)->e_flags
= flags
;
6740 elf_flags_init (abfd
) = TRUE
;
6745 convert_e_flags (unsigned int e_flags
, unsigned int arch
)
6747 if ((e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
)
6749 /* From 0.9 to 1.0. */
6750 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V1_0
;
6752 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6753 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
6754 if (arch
== E_NDS_ARCH_STAR_V1_0
)
6761 /* From 1.0 to 2.0. */
6762 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V2_0
;
6764 /* Clear E_NDS32_HAS_MFUSR_PC_INST. */
6765 e_flags
&= ~E_NDS32_HAS_MFUSR_PC_INST
;
6767 /* Invert E_NDS32_HAS_NO_MAC_INST. */
6768 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
6773 nds32_check_vec_size (bfd
*ibfd
)
6775 static unsigned int nds32_vec_size
= 0;
6777 asection
*sec_t
= NULL
;
6778 bfd_byte
*contents
= NULL
;
6780 sec_t
= bfd_get_section_by_name (ibfd
, ".nds32_e_flags");
6782 if (sec_t
&& sec_t
->size
>= 4)
6784 /* Get vec_size in file. */
6785 unsigned int flag_t
;
6787 nds32_get_section_contents (ibfd
, sec_t
, &contents
, TRUE
);
6788 flag_t
= bfd_get_32 (ibfd
, contents
);
6790 /* The value could only be 4 or 16. */
6792 if (!nds32_vec_size
)
6793 /* Set if not set yet. */
6794 nds32_vec_size
= (flag_t
& 0x3);
6795 else if (nds32_vec_size
!= (flag_t
& 0x3))
6798 /* xgettext:c-format */
6799 (_("%pB: ISR vector size mismatch"
6800 " with previous modules, previous %u-byte, current %u-byte"),
6802 nds32_vec_size
== 1 ? 4 : nds32_vec_size
== 2 ? 16 : 0xffffffff,
6803 (flag_t
& 0x3) == 1 ? 4 : (flag_t
& 0x3) == 2 ? 16 : 0xffffffff);
6807 /* Only keep the first vec_size section. */
6808 sec_t
->flags
|= SEC_EXCLUDE
;
6814 /* Merge backend specific data from an object file to the output
6815 object file when linking. */
6818 nds32_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6820 bfd
*obfd
= info
->output_bfd
;
6823 flagword out_16regs
;
6825 flagword out_no_mac
;
6827 flagword out_version
;
6828 flagword in_version
;
6829 flagword out_fpu_config
;
6830 flagword in_fpu_config
;
6832 /* TODO: Revise to use object-attributes instead. */
6833 if (!nds32_check_vec_size (ibfd
))
6836 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6837 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6840 if (bfd_little_endian (ibfd
) != bfd_little_endian (obfd
))
6843 (_("%pB: warning: endian mismatch with previous modules"), ibfd
);
6845 bfd_set_error (bfd_error_bad_value
);
6849 /* -B option in objcopy cannot work as expected. e_flags = 0 shall be
6850 treat as generic one without checking and merging. */
6851 if (elf_elfheader (ibfd
)->e_flags
)
6853 in_version
= elf_elfheader (ibfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
6854 if (in_version
== E_NDS32_ELF_VER_1_2
)
6857 (_("%pB: warning: older version of object file encountered, "
6858 "please recompile with current tool chain"), ibfd
);
6861 /* We may need to merge V1 and V2 arch object files to V2. */
6862 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6863 != (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
6865 /* Need to convert version. */
6866 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6867 == E_NDS_ARCH_STAR_RESERVED
)
6869 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6871 else if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6872 == E_NDS_ARCH_STAR_V3_M
6873 && (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
)
6874 == E_NDS_ARCH_STAR_V3_0
)
6876 elf_elfheader (ibfd
)->e_flags
=
6877 (elf_elfheader (ibfd
)->e_flags
& (~EF_NDS_ARCH
))
6878 | E_NDS_ARCH_STAR_V3_0
;
6880 else if ((elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
)
6881 == E_NDS_ARCH_STAR_V0_9
6882 || (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
6883 > (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
6885 elf_elfheader (obfd
)->e_flags
=
6886 convert_e_flags (elf_elfheader (obfd
)->e_flags
,
6887 (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
));
6891 elf_elfheader (ibfd
)->e_flags
=
6892 convert_e_flags (elf_elfheader (ibfd
)->e_flags
,
6893 (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
));
6897 /* Extract some flags. */
6898 in_flags
= elf_elfheader (ibfd
)->e_flags
6899 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
6900 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
6902 /* The following flags need special treatment. */
6903 in_16regs
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
6904 in_no_mac
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
6905 in_fpu_config
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
6907 /* Extract some flags. */
6908 out_flags
= elf_elfheader (obfd
)->e_flags
6909 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
6910 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
6912 /* The following flags need special treatment. */
6913 out_16regs
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
6914 out_no_mac
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
6915 out_fpu_config
= elf_elfheader (obfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
6916 out_version
= elf_elfheader (obfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
6917 if (!elf_flags_init (obfd
))
6919 /* If the input is the default architecture then do not
6920 bother setting the flags for the output architecture,
6921 instead allow future merges to do this. If no future
6922 merges ever set these flags then they will retain their
6923 unitialised values, which surprise surprise, correspond
6924 to the default values. */
6925 if (bfd_get_arch_info (ibfd
)->the_default
)
6928 elf_flags_init (obfd
) = TRUE
;
6929 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
6931 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6932 && bfd_get_arch_info (obfd
)->the_default
)
6934 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
6935 bfd_get_mach (ibfd
));
6941 /* Check flag compatibility. */
6942 if ((in_flags
& EF_NDS_ABI
) != (out_flags
& EF_NDS_ABI
))
6945 (_("%pB: error: ABI mismatch with previous modules"), ibfd
);
6946 bfd_set_error (bfd_error_bad_value
);
6950 if ((in_flags
& EF_NDS_ARCH
) != (out_flags
& EF_NDS_ARCH
))
6952 if (((in_flags
& EF_NDS_ARCH
) != E_N1_ARCH
))
6955 (_("%pB: error: instruction set mismatch with previous modules"),
6958 bfd_set_error (bfd_error_bad_value
);
6963 /* When linking with V1.2 and V1.3 objects together the output is V1.2.
6964 and perf ext1 and DIV are mergerd to perf ext1. */
6965 if (in_version
== E_NDS32_ELF_VER_1_2
|| out_version
== E_NDS32_ELF_VER_1_2
)
6967 elf_elfheader (obfd
)->e_flags
=
6968 (in_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6969 | (out_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6970 | (((in_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6971 ? E_NDS32_HAS_EXT_INST
: 0)
6972 | (((out_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6973 ? E_NDS32_HAS_EXT_INST
: 0)
6974 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6975 | ((in_version
> out_version
) ? out_version
: in_version
);
6979 if (in_version
!= out_version
)
6981 /* xgettext:c-format */
6982 (_("%pB: warning: incompatible elf-versions %s and %s"),
6983 ibfd
, nds32_elfver_strtab
[out_version
],
6984 nds32_elfver_strtab
[in_version
]);
6986 elf_elfheader (obfd
)->e_flags
= in_flags
| out_flags
6987 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6988 | (in_fpu_config
> out_fpu_config
? in_fpu_config
: out_fpu_config
)
6989 | (in_version
> out_version
? out_version
: in_version
);
6996 /* Display the flags field. */
6999 nds32_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
7001 FILE *file
= (FILE *) ptr
;
7003 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
7005 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
7007 fprintf (file
, _("private flags = %lx"), elf_elfheader (abfd
)->e_flags
);
7009 switch (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
)
7013 fprintf (file
, _(": n1 instructions"));
7016 fprintf (file
, _(": n1h instructions"));
7026 nds32_elf_action_discarded (asection
*sec
)
7030 (".gcc_except_table", sec
->name
, sizeof (".gcc_except_table") - 1) == 0)
7033 return _bfd_elf_default_action_discarded (sec
);
7037 nds32_elf_gc_mark_hook (asection
*sec
, struct bfd_link_info
*info
,
7038 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
7039 Elf_Internal_Sym
*sym
)
7042 switch (ELF32_R_TYPE (rel
->r_info
))
7044 case R_NDS32_GNU_VTINHERIT
:
7045 case R_NDS32_GNU_VTENTRY
:
7046 case R_NDS32_RELA_GNU_VTINHERIT
:
7047 case R_NDS32_RELA_GNU_VTENTRY
:
7051 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
7054 static enum elf_nds32_tls_type
7055 get_tls_type (enum elf_nds32_reloc_type r_type
,
7056 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
7058 enum elf_nds32_tls_type tls_type
;
7062 case R_NDS32_TLS_LE_HI20
:
7063 case R_NDS32_TLS_LE_LO12
:
7064 tls_type
= GOT_TLS_LE
;
7066 case R_NDS32_TLS_IE_HI20
:
7067 case R_NDS32_TLS_IE_LO12S2
:
7068 case R_NDS32_TLS_IE_LO12
:
7069 tls_type
= GOT_TLS_IE
;
7071 case R_NDS32_TLS_IEGP_HI20
:
7072 case R_NDS32_TLS_IEGP_LO12
:
7073 case R_NDS32_TLS_IEGP_LO12S2
:
7074 tls_type
= GOT_TLS_IEGP
;
7076 case R_NDS32_TLS_DESC_HI20
:
7077 case R_NDS32_TLS_DESC_LO12
:
7078 case R_NDS32_TLS_DESC_ADD
:
7079 case R_NDS32_TLS_DESC_FUNC
:
7080 case R_NDS32_TLS_DESC_CALL
:
7081 tls_type
= GOT_TLS_DESC
;
7084 tls_type
= GOT_NORMAL
;
7091 /* Ensure that we have allocated bookkeeping structures for ABFD's local
7095 elf32_nds32_allocate_local_sym_info (bfd
*abfd
)
7097 if (elf_local_got_refcounts (abfd
) == NULL
)
7099 bfd_size_type num_syms
;
7103 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
7104 /* This space is for got_refcounts, got_tls_type, tlsdesc_gotent, and
7105 gp_offset. The details can refer to struct elf_nds32_obj_tdata. */
7106 size
= num_syms
* (sizeof (bfd_signed_vma
) + sizeof (char)
7107 + sizeof (bfd_vma
) + sizeof (int)
7108 + sizeof (bfd_boolean
) + sizeof (bfd_vma
));
7109 data
= bfd_zalloc (abfd
, size
);
7113 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
7114 data
+= num_syms
* sizeof (bfd_signed_vma
);
7116 elf32_nds32_local_got_tls_type (abfd
) = (char *) data
;
7117 data
+= num_syms
* sizeof (char);
7119 elf32_nds32_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
7120 data
+= num_syms
* sizeof (bfd_vma
);
7122 elf32_nds32_local_gp_offset (abfd
) = (int *) data
;
7123 data
+= num_syms
* sizeof (int);
7129 /* Look through the relocs for a section during the first phase.
7130 Since we don't do .gots or .plts, we just need to consider the
7131 virtual table relocs for gc. */
7134 nds32_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7135 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7137 Elf_Internal_Shdr
*symtab_hdr
;
7138 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
7139 const Elf_Internal_Rela
*rel
;
7140 const Elf_Internal_Rela
*rel_end
;
7141 struct elf_link_hash_table
*ehtab
;
7142 struct elf_nds32_link_hash_table
*htab
;
7144 asection
*sreloc
= NULL
;
7146 /* No need for relocation if relocatable already. */
7147 if (bfd_link_relocatable (info
))
7149 elf32_nds32_check_relax_group (abfd
, sec
);
7153 /* Don't do anything special with non-loaded, non-alloced sections.
7154 In particular, any relocs in such sections should not affect GOT
7155 and PLT reference counting (ie. we don't allow them to create GOT
7156 or PLT entries), there's no possibility or desire to optimize TLS
7157 relocs, and there's not much point in propagating relocs to shared
7158 libs that the dynamic linker won't relocate. */
7159 if ((sec
->flags
& SEC_ALLOC
) == 0)
7162 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7163 sym_hashes
= elf_sym_hashes (abfd
);
7165 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
7166 if (!elf_bad_symtab (abfd
))
7167 sym_hashes_end
-= symtab_hdr
->sh_info
;
7169 ehtab
= elf_hash_table (info
);
7170 htab
= nds32_elf_hash_table (info
);
7171 dynobj
= htab
->root
.dynobj
;
7173 rel_end
= relocs
+ sec
->reloc_count
;
7174 for (rel
= relocs
; rel
< rel_end
; rel
++)
7176 enum elf_nds32_reloc_type r_type
;
7177 struct elf_link_hash_entry
*h
;
7178 unsigned long r_symndx
;
7179 enum elf_nds32_tls_type tls_type
, old_tls_type
;
7181 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7182 r_type
= ELF32_R_TYPE (rel
->r_info
);
7183 if (r_symndx
< symtab_hdr
->sh_info
)
7187 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7188 while (h
->root
.type
== bfd_link_hash_indirect
7189 || h
->root
.type
== bfd_link_hash_warning
)
7190 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7193 /* Create .got section if necessary.
7194 Some relocs require a global offset table. We create
7195 got section here, since these relocation need a got section
7196 and if it is not created yet. */
7197 if (ehtab
->sgot
== NULL
)
7201 case R_NDS32_GOT_HI20
:
7202 case R_NDS32_GOT_LO12
:
7203 case R_NDS32_GOT_LO15
:
7204 case R_NDS32_GOT_LO19
:
7205 case R_NDS32_GOT17S2_RELA
:
7206 case R_NDS32_GOT15S2_RELA
:
7207 case R_NDS32_GOTOFF
:
7208 case R_NDS32_GOTOFF_HI20
:
7209 case R_NDS32_GOTOFF_LO12
:
7210 case R_NDS32_GOTOFF_LO15
:
7211 case R_NDS32_GOTOFF_LO19
:
7212 case R_NDS32_GOTPC20
:
7213 case R_NDS32_GOTPC_HI20
:
7214 case R_NDS32_GOTPC_LO12
:
7216 case R_NDS32_TLS_IE_HI20
:
7217 case R_NDS32_TLS_IE_LO12
:
7218 case R_NDS32_TLS_IE_LO12S2
:
7219 case R_NDS32_TLS_IEGP_HI20
:
7220 case R_NDS32_TLS_IEGP_LO12
:
7221 case R_NDS32_TLS_IEGP_LO12S2
:
7222 case R_NDS32_TLS_DESC_HI20
:
7223 case R_NDS32_TLS_DESC_LO12
:
7225 htab
->root
.dynobj
= dynobj
= abfd
;
7226 if (!create_got_section (dynobj
, info
))
7235 /* Check relocation type. */
7236 switch ((int) r_type
)
7238 case R_NDS32_GOT_HI20
:
7239 case R_NDS32_GOT_LO12
:
7240 case R_NDS32_GOT_LO15
:
7241 case R_NDS32_GOT_LO19
:
7243 case R_NDS32_TLS_LE_HI20
:
7244 case R_NDS32_TLS_LE_LO12
:
7245 case R_NDS32_TLS_IE_HI20
:
7246 case R_NDS32_TLS_IE_LO12
:
7247 case R_NDS32_TLS_IE_LO12S2
:
7248 case R_NDS32_TLS_IEGP_HI20
:
7249 case R_NDS32_TLS_IEGP_LO12
:
7250 case R_NDS32_TLS_IEGP_LO12S2
:
7251 case R_NDS32_TLS_DESC_HI20
:
7252 case R_NDS32_TLS_DESC_LO12
:
7253 tls_type
= get_tls_type (r_type
, h
);
7256 if (tls_type
!= GOT_TLS_LE
)
7257 h
->got
.refcount
+= 1;
7258 old_tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
7262 /* This is a global offset table entry for a local symbol. */
7263 if (!elf32_nds32_allocate_local_sym_info (abfd
))
7266 BFD_ASSERT (r_symndx
< symtab_hdr
->sh_info
);
7267 if (tls_type
!= GOT_TLS_LE
)
7268 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
7269 old_tls_type
= elf32_nds32_local_got_tls_type (abfd
)[r_symndx
];
7272 /* We would already have issued an error message if there
7273 is a TLS/non-TLS mismatch, based on the symbol
7274 type. So just combine any TLS types needed. */
7275 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
7276 && tls_type
!= GOT_NORMAL
)
7277 tls_type
|= old_tls_type
;
7279 /* DESC to IE/IEGP if link to executable. */
7280 if ((tls_type
& (GOT_TLS_DESC
| GOT_TLS_IEGP
))
7281 && (bfd_link_executable (info
)))
7282 tls_type
|= (bfd_link_pie (info
) ? GOT_TLS_IEGP
: GOT_TLS_IE
);
7284 if (old_tls_type
!= tls_type
)
7287 elf32_nds32_hash_entry (h
)->tls_type
= tls_type
;
7289 elf32_nds32_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
7292 case R_NDS32_9_PLTREL
:
7293 case R_NDS32_25_PLTREL
:
7294 case R_NDS32_PLTREL_HI20
:
7295 case R_NDS32_PLTREL_LO12
:
7296 case R_NDS32_PLT_GOTREL_HI20
:
7297 case R_NDS32_PLT_GOTREL_LO12
:
7298 case R_NDS32_PLT_GOTREL_LO15
:
7299 case R_NDS32_PLT_GOTREL_LO19
:
7300 case R_NDS32_PLT_GOTREL_LO20
:
7302 /* This symbol requires a procedure linkage table entry. We
7303 actually build the entry in adjust_dynamic_symbol,
7304 because this might be a case of linking PIC code without
7305 linking in any dynamic objects, in which case we don't
7306 need to generate a procedure linkage table after all. */
7308 /* If this is a local symbol, we resolve it directly without
7309 creating a procedure linkage table entry. */
7314 || (bfd_link_pie (info
) && h
->def_regular
))
7317 elf32_nds32_hash_entry (h
)->tls_type
= GOT_NORMAL
;
7319 h
->plt
.refcount
+= 1;
7322 case R_NDS32_16_RELA
:
7323 case R_NDS32_20_RELA
:
7324 case R_NDS32_5_RELA
:
7325 case R_NDS32_32_RELA
:
7326 case R_NDS32_HI20_RELA
:
7327 case R_NDS32_LO12S3_RELA
:
7328 case R_NDS32_LO12S2_RELA
:
7329 case R_NDS32_LO12S2_DP_RELA
:
7330 case R_NDS32_LO12S2_SP_RELA
:
7331 case R_NDS32_LO12S1_RELA
:
7332 case R_NDS32_LO12S0_RELA
:
7333 case R_NDS32_LO12S0_ORI_RELA
:
7334 case R_NDS32_SDA16S3_RELA
:
7335 case R_NDS32_SDA17S2_RELA
:
7336 case R_NDS32_SDA18S1_RELA
:
7337 case R_NDS32_SDA19S0_RELA
:
7338 case R_NDS32_SDA15S3_RELA
:
7339 case R_NDS32_SDA15S2_RELA
:
7340 case R_NDS32_SDA12S2_DP_RELA
:
7341 case R_NDS32_SDA12S2_SP_RELA
:
7342 case R_NDS32_SDA15S1_RELA
:
7343 case R_NDS32_SDA15S0_RELA
:
7344 case R_NDS32_SDA_FP7U2_RELA
:
7345 case R_NDS32_15_PCREL_RELA
:
7346 case R_NDS32_17_PCREL_RELA
:
7347 case R_NDS32_25_PCREL_RELA
:
7349 if (h
!= NULL
&& !bfd_link_pic (info
))
7352 h
->plt
.refcount
+= 1;
7355 /* If we are creating a shared library, and this is a reloc against
7356 a global symbol, or a non PC relative reloc against a local
7357 symbol, then we need to copy the reloc into the shared library.
7358 However, if we are linking with -Bsymbolic, we do not need to
7359 copy a reloc against a global symbol which is defined in an
7360 object we are including in the link (i.e., DEF_REGULAR is set).
7361 At this point we have not seen all the input files, so it is
7362 possible that DEF_REGULAR is not set now but will be set later
7363 (it is never cleared). We account for that possibility below by
7364 storing information in the dyn_relocs field of the hash table
7365 entry. A similar situation occurs when creating shared libraries
7366 and symbol visibility changes render the symbol local.
7368 If on the other hand, we are creating an executable, we may need
7369 to keep relocations for symbols satisfied by a dynamic library
7370 if we manage to avoid copy relocs for the symbol. */
7371 if ((bfd_link_pic (info
)
7372 && (sec
->flags
& SEC_ALLOC
) != 0
7373 && ((r_type
!= R_NDS32_25_PCREL_RELA
7374 && r_type
!= R_NDS32_15_PCREL_RELA
7375 && r_type
!= R_NDS32_17_PCREL_RELA
7376 && !(r_type
== R_NDS32_32_RELA
7377 && strcmp (sec
->name
, ".eh_frame") == 0))
7380 || h
->root
.type
== bfd_link_hash_defweak
7381 || !h
->def_regular
))))
7382 || (!bfd_link_pic (info
)
7383 && (sec
->flags
& SEC_ALLOC
) != 0
7385 && (h
->root
.type
== bfd_link_hash_defweak
7386 || !h
->def_regular
)))
7388 struct elf_dyn_relocs
*p
;
7389 struct elf_dyn_relocs
**head
;
7392 htab
->root
.dynobj
= dynobj
= abfd
;
7394 /* When creating a shared object, we must copy these
7395 relocs into the output file. We create a reloc
7396 section in dynobj and make room for the reloc. */
7401 name
= bfd_elf_string_from_elf_section
7402 (abfd
, elf_elfheader (abfd
)->e_shstrndx
,
7403 elf_section_data (sec
)->rela
.hdr
->sh_name
);
7407 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
7408 && strcmp (bfd_get_section_name (abfd
, sec
),
7411 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7416 sreloc
= bfd_make_section (dynobj
, name
);
7417 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
7418 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
7419 if ((sec
->flags
& SEC_ALLOC
) != 0)
7420 flags
|= SEC_ALLOC
| SEC_LOAD
;
7422 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
7423 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
7426 elf_section_type (sreloc
) = SHT_RELA
;
7428 elf_section_data (sec
)->sreloc
= sreloc
;
7431 /* If this is a global symbol, we count the number of
7432 relocations we need for this symbol. */
7434 head
= &((struct elf_nds32_link_hash_entry
*) h
)->dyn_relocs
;
7440 Elf_Internal_Sym
*isym
;
7441 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
7445 /* Track dynamic relocs needed for local syms too. */
7446 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7450 vpp
= &elf_section_data (s
)->local_dynrel
;
7451 head
= (struct elf_dyn_relocs
**) vpp
;
7455 if (p
== NULL
|| p
->sec
!= sec
)
7457 bfd_size_type amt
= sizeof (*p
);
7458 p
= (struct elf_dyn_relocs
*) bfd_alloc (dynobj
, amt
);
7470 /* Since eh_frame is readonly, R_NDS32_32_RELA
7471 reloc for eh_frame will cause shared library has
7472 TEXTREL entry in the dynamic section. This lead glibc
7473 testsuites to failure (bug-13092) and cause kernel fail
7474 (bug-11819). I think the best solution is to replace
7475 absolute reloc with pc relative reloc in the eh_frame.
7476 To do that, we need to support the following issues:
7479 * gcc/config/nds32/nds32.h: Define
7480 ASM_PREFERRED_EH_DATA_FORMAT to encode DW_EH_PE_pcrel
7481 and DW_EH_PE_sdata4 into DWARF exception header when
7482 option have '-fpic'.
7484 === For binutils ===
7485 * bfd/: Define new reloc R_NDS32_32_PCREL_RELA.
7486 * gas/config/tc-nds32.h: Define DIFF_EXPR_OK. This
7487 may break our nds DIFF mechanism, therefore, we
7488 must disable all linker relaxations to ensure
7490 * gas/config/tc-nds32.c (nds32_apply_fix): Replace
7491 R_NDS32_32_RELA with R_NDS32_32_PCREL_RELA, and
7492 do the necessary modification.
7494 Unfortunately, it still have some problems for nds32
7495 to support pc relative reloc in the eh_frame. So I use
7496 another solution to fix this issue.
7498 However, I find that ld always emit TEXTREL marker for
7499 R_NDS32_NONE relocs in rel.dyn. These none relocs are
7500 correspond to R_NDS32_32_RELA for .eh_frame section.
7501 It means that we always reserve redundant entries of rel.dyn
7502 for these relocs which actually do nothing in dynamic linker.
7504 Therefore, we regard these relocs as pc relative relocs
7505 here and increase the pc_count. */
7506 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_25_PCREL_RELA
7507 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_15_PCREL_RELA
7508 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_17_PCREL_RELA
7509 || (r_type
== R_NDS32_32_RELA
7510 && strcmp (sec
->name
, ".eh_frame") == 0))
7515 /* This relocation describes the C++ object vtable hierarchy.
7516 Reconstruct it for later use during GC. */
7517 case R_NDS32_RELA_GNU_VTINHERIT
:
7518 case R_NDS32_GNU_VTINHERIT
:
7519 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7523 /* This relocation describes which C++ vtable entries are actually
7524 used. Record for later use during GC. */
7525 case R_NDS32_GNU_VTENTRY
:
7526 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7529 case R_NDS32_RELA_GNU_VTENTRY
:
7530 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
7539 /* Write VAL in uleb128 format to P, returning a pointer to the
7541 This code is copied from elf-attr.c. */
7544 write_uleb128 (bfd_byte
*p
, unsigned int val
)
7559 static bfd_signed_vma
7560 calculate_offset (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
7561 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
7563 bfd_signed_vma foff
;
7564 bfd_vma symval
, addend
;
7567 /* Get the value of the symbol referred to by the reloc. */
7568 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
7570 Elf_Internal_Sym
*isym
;
7572 /* A local symbol. */
7573 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
7575 if (isym
->st_shndx
== SHN_UNDEF
)
7576 sym_sec
= bfd_und_section_ptr
;
7577 else if (isym
->st_shndx
== SHN_ABS
)
7578 sym_sec
= bfd_abs_section_ptr
;
7579 else if (isym
->st_shndx
== SHN_COMMON
)
7580 sym_sec
= bfd_com_section_ptr
;
7582 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7583 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
7584 + sym_sec
->output_offset
;
7589 struct elf_link_hash_entry
*h
;
7591 /* An external symbol. */
7592 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7593 h
= elf_sym_hashes (abfd
)[indx
];
7594 BFD_ASSERT (h
!= NULL
);
7596 if (h
->root
.type
!= bfd_link_hash_defined
7597 && h
->root
.type
!= bfd_link_hash_defweak
)
7598 /* This appears to be a reference to an undefined
7599 symbol. Just ignore it--it will be caught by the
7600 regular reloc processing. */
7603 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
7605 sym_sec
= h
->root
.u
.def
.section
;
7606 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
,
7607 elf_section_data (sym_sec
)->sec_info
,
7608 h
->root
.u
.def
.value
);
7609 symval
= symval
+ sym_sec
->output_section
->vma
7610 + sym_sec
->output_offset
;
7613 symval
= (h
->root
.u
.def
.value
7614 + h
->root
.u
.def
.section
->output_section
->vma
7615 + h
->root
.u
.def
.section
->output_offset
);
7618 addend
= irel
->r_addend
;
7620 foff
= (symval
+ addend
7621 - (irel
->r_offset
+ sec
->output_section
->vma
+ sec
->output_offset
));
7626 /* Convert a 32-bit instruction to 16-bit one.
7627 INSN is the input 32-bit instruction, INSN16 is the output 16-bit
7628 instruction. If INSN_TYPE is not NULL, it the CGEN instruction
7629 type of INSN16. Return 1 if successful. */
7632 nds32_convert_32_to_16_alu1 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7635 uint16_t insn16
= 0;
7637 unsigned long mach
= bfd_get_mach (abfd
);
7639 if (N32_SH5 (insn
) != 0)
7642 switch (N32_SUB5 (insn
))
7644 case N32_ALU1_ADD_SLLI
:
7645 case N32_ALU1_ADD_SRLI
:
7646 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
7648 insn16
= N16_TYPE333 (ADD333
, N32_RT5 (insn
), N32_RA5 (insn
),
7650 insn_type
= NDS32_INSN_ADD333
;
7652 else if (N32_IS_RT4 (insn
))
7654 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7655 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RB5 (insn
));
7656 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7657 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RA5 (insn
));
7658 insn_type
= NDS32_INSN_ADD45
;
7662 case N32_ALU1_SUB_SLLI
:
7663 case N32_ALU1_SUB_SRLI
:
7664 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
7666 insn16
= N16_TYPE333 (SUB333
, N32_RT5 (insn
), N32_RA5 (insn
),
7668 insn_type
= NDS32_INSN_SUB333
;
7670 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7672 insn16
= N16_TYPE45 (SUB45
, N32_RT54 (insn
), N32_RB5 (insn
));
7673 insn_type
= NDS32_INSN_SUB45
;
7677 case N32_ALU1_AND_SLLI
:
7678 case N32_ALU1_AND_SRLI
:
7679 /* and $rt, $rt, $rb -> and33 for v3, v3m. */
7680 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7681 && N32_IS_RB3 (insn
))
7683 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7684 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RB5 (insn
));
7685 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7686 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RA5 (insn
));
7688 insn_type
= NDS32_INSN_AND33
;
7692 case N32_ALU1_XOR_SLLI
:
7693 case N32_ALU1_XOR_SRLI
:
7694 /* xor $rt, $rt, $rb -> xor33 for v3, v3m. */
7695 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7696 && N32_IS_RB3 (insn
))
7698 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7699 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RB5 (insn
));
7700 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7701 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RA5 (insn
));
7703 insn_type
= NDS32_INSN_XOR33
;
7707 case N32_ALU1_OR_SLLI
:
7708 case N32_ALU1_OR_SRLI
:
7709 /* or $rt, $rt, $rb -> or33 for v3, v3m. */
7710 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7711 && N32_IS_RB3 (insn
))
7713 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7714 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RB5 (insn
));
7715 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7716 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RA5 (insn
));
7718 insn_type
= NDS32_INSN_OR33
;
7722 /* nor $rt, $ra, $ra -> not33 for v3, v3m. */
7723 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RB3 (insn
)
7724 && N32_RA5 (insn
) == N32_RB5 (insn
))
7726 insn16
= N16_MISC33 (NOT33
, N32_RT5 (insn
), N32_RA5 (insn
));
7727 insn_type
= NDS32_INSN_NOT33
;
7731 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7733 insn16
= N16_TYPE45 (SRAI45
, N32_RT54 (insn
), N32_UB5 (insn
));
7734 insn_type
= NDS32_INSN_SRAI45
;
7739 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
7741 insn16
= N16_TYPE45 (SRLI45
, N32_RT54 (insn
), N32_UB5 (insn
));
7742 insn_type
= NDS32_INSN_SRLI45
;
7747 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_UB5 (insn
) < 8)
7749 insn16
= N16_TYPE333 (SLLI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7751 insn_type
= NDS32_INSN_SLLI333
;
7756 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7758 insn16
= N16_BFMI333 (ZEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
7759 insn_type
= NDS32_INSN_ZEH33
;
7764 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7766 insn16
= N16_BFMI333 (SEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7767 insn_type
= NDS32_INSN_SEB33
;
7772 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7774 insn16
= N16_BFMI333 (SEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
7775 insn_type
= NDS32_INSN_SEH33
;
7780 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
7783 insn16
= N16_TYPE45 (SLT45
, N32_RA54 (insn
), N32_RB5 (insn
));
7784 insn_type
= NDS32_INSN_SLT45
;
7789 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
7792 insn16
= N16_TYPE45 (SLTS45
, N32_RA54 (insn
), N32_RB5 (insn
));
7793 insn_type
= NDS32_INSN_SLTS45
;
7798 if ((insn16
& 0x8000) == 0)
7804 *pinsn_type
= insn_type
;
7809 nds32_convert_32_to_16_alu2 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7812 uint16_t insn16
= 0;
7814 unsigned long mach
= bfd_get_mach (abfd
);
7816 /* TODO: bset, bclr, btgl, btst. */
7817 if (__GF (insn
, 6, 4) != 0)
7820 switch (N32_IMMU (insn
, 6))
7823 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7824 && N32_IS_RB3 (insn
))
7826 if (N32_RT5 (insn
) == N32_RA5 (insn
))
7827 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RB5 (insn
));
7828 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
7829 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RA5 (insn
));
7831 insn_type
= NDS32_INSN_MUL33
;
7835 if ((insn16
& 0x8000) == 0)
7841 *pinsn_type
= insn_type
;
7846 nds32_convert_32_to_16 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
7850 uint16_t insn16
= 0;
7852 unsigned long mach
= bfd_get_mach (abfd
);
7854 /* Decode 32-bit instruction. */
7855 if (insn
& 0x80000000)
7857 /* Not 32-bit insn. */
7861 op6
= N32_OP6 (insn
);
7863 /* Convert it to 16-bit instruction. */
7867 if (IS_WITHIN_S (N32_IMM20S (insn
), 5))
7869 insn16
= N16_TYPE55 (MOVI55
, N32_RT5 (insn
), N32_IMM20S (insn
));
7870 insn_type
= NDS32_INSN_MOVI55
;
7872 else if (mach
>= MACH_V3
&& N32_IMM20S (insn
) >= 16
7873 && N32_IMM20S (insn
) < 48 && N32_IS_RT4 (insn
))
7875 insn16
= N16_TYPE45 (MOVPI45
, N32_RT54 (insn
),
7876 N32_IMM20S (insn
) - 16);
7877 insn_type
= NDS32_INSN_MOVPI45
;
7882 if (N32_IMM15S (insn
) == 0)
7884 /* Do not convert `addi $sp, $sp, 0' to `mov55 $sp, $sp',
7885 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7887 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
7889 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
7890 insn_type
= NDS32_INSN_MOV55
;
7893 else if (N32_IMM15S (insn
) > 0)
7895 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) < 8)
7897 insn16
= N16_TYPE333 (ADDI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7899 insn_type
= NDS32_INSN_ADDI333
;
7901 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
7902 && N32_IMM15S (insn
) < 32)
7904 insn16
= N16_TYPE45 (ADDI45
, N32_RT54 (insn
), N32_IMM15S (insn
));
7905 insn_type
= NDS32_INSN_ADDI45
;
7907 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
7908 && N32_RT5 (insn
) == N32_RA5 (insn
)
7909 && N32_IMM15S (insn
) < 512)
7911 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
7912 insn_type
= NDS32_INSN_ADDI10_SP
;
7914 else if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
7915 && N32_RA5 (insn
) == REG_SP
&& N32_IMM15S (insn
) < 256
7916 && (N32_IMM15S (insn
) % 4 == 0))
7918 insn16
= N16_TYPE36 (ADDRI36_SP
, N32_RT5 (insn
),
7919 N32_IMM15S (insn
) >> 2);
7920 insn_type
= NDS32_INSN_ADDRI36_SP
;
7926 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) > -8)
7928 insn16
= N16_TYPE333 (SUBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7929 0 - N32_IMM15S (insn
));
7930 insn_type
= NDS32_INSN_SUBI333
;
7932 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
7933 && N32_IMM15S (insn
) > -32)
7935 insn16
= N16_TYPE45 (SUBI45
, N32_RT54 (insn
),
7936 0 - N32_IMM15S (insn
));
7937 insn_type
= NDS32_INSN_SUBI45
;
7939 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
7940 && N32_RT5 (insn
) == N32_RA5 (insn
)
7941 && N32_IMM15S (insn
) >= -512)
7943 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
7944 insn_type
= NDS32_INSN_ADDI10_SP
;
7950 if (N32_IMM15S (insn
) == 0)
7952 /* Do not convert `ori $sp, $sp, 0' to `mov55 $sp, $sp',
7953 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
7955 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
7957 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
7958 insn_type
= NDS32_INSN_MOV55
;
7964 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
7965 && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) == 0)
7967 insn16
= N16_MISC33 (NEG33
, N32_RT5 (insn
), N32_RA5 (insn
));
7968 insn_type
= NDS32_INSN_NEG33
;
7973 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
7975 if (N32_IMM15U (insn
) == 1)
7977 insn16
= N16_BFMI333 (XLSB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7978 insn_type
= NDS32_INSN_XLSB33
;
7980 else if (N32_IMM15U (insn
) == 0x7ff)
7982 insn16
= N16_BFMI333 (X11B33
, N32_RT5 (insn
), N32_RA5 (insn
));
7983 insn_type
= NDS32_INSN_X11B33
;
7985 else if (N32_IMM15U (insn
) == 0xff)
7987 insn16
= N16_BFMI333 (ZEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
7988 insn_type
= NDS32_INSN_ZEB33
;
7990 else if (mach
>= MACH_V3
&& N32_RT5 (insn
) == N32_RA5 (insn
)
7991 && N32_IMM15U (insn
) < 256)
7993 int imm15u
= N32_IMM15U (insn
);
7995 if (__builtin_popcount (imm15u
) == 1)
7998 int imm3u
= __builtin_ctz (imm15u
);
8000 insn16
= N16_BFMI333 (BMSKI33
, N32_RT5 (insn
), imm3u
);
8001 insn_type
= NDS32_INSN_BMSKI33
;
8003 else if (imm15u
!= 0 && __builtin_popcount (imm15u
+ 1) == 1)
8006 int imm3u
= __builtin_ctz (imm15u
+ 1) - 1;
8008 insn16
= N16_BFMI333 (FEXTI33
, N32_RT5 (insn
), imm3u
);
8009 insn_type
= NDS32_INSN_FEXTI33
;
8016 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
8017 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
8019 insn16
= N16_TYPE45 (SLTI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
8020 insn_type
= NDS32_INSN_SLTI45
;
8025 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
8026 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
8028 insn16
= N16_TYPE45 (SLTSI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
8029 insn_type
= NDS32_INSN_SLTSI45
;
8034 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
8036 insn16
= N16_TYPE45 (LWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
8037 insn_type
= NDS32_INSN_LWI450
;
8039 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8040 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8042 insn16
= N16_TYPE333 (LWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8044 insn_type
= NDS32_INSN_LWI333
;
8046 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
8047 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8049 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8050 insn_type
= NDS32_INSN_LWI37
;
8052 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
8053 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8055 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8056 insn_type
= NDS32_INSN_LWI37_SP
;
8058 else if (mach
>= MACH_V2
&& N32_IS_RT4 (insn
) && N32_RA5 (insn
) == REG_R8
8059 && -32 <= N32_IMM15S (insn
) && N32_IMM15S (insn
) < 0)
8061 insn16
= N16_TYPE45 (LWI45_FE
, N32_RT54 (insn
),
8062 N32_IMM15S (insn
) + 32);
8063 insn_type
= NDS32_INSN_LWI45_FE
;
8068 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
8070 insn16
= N16_TYPE45 (SWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
8071 insn_type
= NDS32_INSN_SWI450
;
8073 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8074 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8076 insn16
= N16_TYPE333 (SWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8078 insn_type
= NDS32_INSN_SWI333
;
8080 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
8081 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8083 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8084 insn_type
= NDS32_INSN_SWI37
;
8086 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
8087 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
8089 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8090 insn_type
= NDS32_INSN_SWI37_SP
;
8094 case N32_OP6_LWI_BI
:
8095 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8096 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8098 insn16
= N16_TYPE333 (LWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
8100 insn_type
= NDS32_INSN_LWI333_BI
;
8104 case N32_OP6_SWI_BI
:
8105 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8106 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8108 insn16
= N16_TYPE333 (SWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
8110 insn_type
= NDS32_INSN_SWI333_BI
;
8115 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8116 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8118 insn16
= N16_TYPE333 (LHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8120 insn_type
= NDS32_INSN_LHI333
;
8125 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8126 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8128 insn16
= N16_TYPE333 (SHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8130 insn_type
= NDS32_INSN_SHI333
;
8135 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8136 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8138 insn16
= N16_TYPE333 (LBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8140 insn_type
= NDS32_INSN_LBI333
;
8145 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
8146 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
8148 insn16
= N16_TYPE333 (SBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
8150 insn_type
= NDS32_INSN_SBI333
;
8155 return nds32_convert_32_to_16_alu1 (abfd
, insn
, pinsn16
, pinsn_type
);
8158 return nds32_convert_32_to_16_alu2 (abfd
, insn
, pinsn16
, pinsn_type
);
8161 if (!IS_WITHIN_S (N32_IMM14S (insn
), 8))
8164 if ((insn
& N32_BIT (14)) == 0)
8167 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
8168 && N32_RT5 (insn
) != REG_R5
)
8169 insn16
= N16_TYPE38 (BEQS38
, N32_RT5 (insn
), N32_IMM14S (insn
));
8170 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
8171 && N32_RA5 (insn
) != REG_R5
)
8172 insn16
= N16_TYPE38 (BEQS38
, N32_RA5 (insn
), N32_IMM14S (insn
));
8173 insn_type
= NDS32_INSN_BEQS38
;
8179 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
8180 && N32_RT5 (insn
) != REG_R5
)
8181 insn16
= N16_TYPE38 (BNES38
, N32_RT5 (insn
), N32_IMM14S (insn
));
8182 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
8183 && N32_RA5 (insn
) != REG_R5
)
8184 insn16
= N16_TYPE38 (BNES38
, N32_RA5 (insn
), N32_IMM14S (insn
));
8185 insn_type
= NDS32_INSN_BNES38
;
8191 switch (N32_BR2_SUB (insn
))
8194 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8196 insn16
= N16_TYPE38 (BEQZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
8197 insn_type
= NDS32_INSN_BEQZ38
;
8199 else if (N32_RT5 (insn
) == REG_R15
8200 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8202 insn16
= N16_TYPE8 (BEQZS8
, N32_IMM16S (insn
));
8203 insn_type
= NDS32_INSN_BEQZS8
;
8208 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8210 insn16
= N16_TYPE38 (BNEZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
8211 insn_type
= NDS32_INSN_BNEZ38
;
8213 else if (N32_RT5 (insn
) == REG_R15
8214 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
8216 insn16
= N16_TYPE8 (BNEZS8
, N32_IMM16S (insn
));
8217 insn_type
= NDS32_INSN_BNEZS8
;
8222 if (__GF (insn
, 20, 5) == 0 && IS_WITHIN_U (N32_IMM16S (insn
), 9))
8224 insn16
= N16_TYPE9 (IFCALL9
, N32_IMM16S (insn
));
8225 insn_type
= NDS32_INSN_IFCALL9
;
8232 if ((insn
& N32_BIT (24)) == 0)
8235 if (IS_WITHIN_S (N32_IMM24S (insn
), 8))
8237 insn16
= N16_TYPE8 (J8
, N32_IMM24S (insn
));
8238 insn_type
= NDS32_INSN_J8
;
8244 if (__GF (insn
, 8, 2) != 0)
8247 switch (N32_IMMU (insn
, 5))
8250 if (N32_JREG_HINT (insn
) == 0)
8253 insn16
= N16_TYPE5 (JR5
, N32_RB5 (insn
));
8254 insn_type
= NDS32_INSN_JR5
;
8256 else if (N32_JREG_HINT (insn
) == 1)
8259 insn16
= N16_TYPE5 (RET5
, N32_RB5 (insn
));
8260 insn_type
= NDS32_INSN_RET5
;
8262 else if (N32_JREG_HINT (insn
) == 3)
8264 /* ifret = mov55 $sp, $sp */
8265 insn16
= N16_TYPE55 (MOV55
, REG_SP
, REG_SP
);
8266 insn_type
= NDS32_INSN_IFRET
;
8271 /* It's convertible when return rt5 is $lp and address
8272 translation is kept. */
8273 if (N32_RT5 (insn
) == REG_LP
&& N32_JREG_HINT (insn
) == 0)
8275 insn16
= N16_TYPE5 (JRAL5
, N32_RB5 (insn
));
8276 insn_type
= NDS32_INSN_JRAL5
;
8283 if (N32_SUB5 (insn
) == N32_MISC_BREAK
&& N32_SWID (insn
) < 32)
8285 /* For v3, swid above 31 are used for ex9.it. */
8286 insn16
= N16_TYPE5 (BREAK16
, N32_SWID (insn
));
8287 insn_type
= NDS32_INSN_BREAK16
;
8292 /* This instruction has no 16-bit variant. */
8297 /* Bit-15 of insn16 should be set for a valid instruction. */
8298 if ((insn16
& 0x8000) == 0)
8304 *pinsn_type
= insn_type
;
8309 special_convert_32_to_16 (unsigned long insn
, uint16_t *pinsn16
,
8310 Elf_Internal_Rela
*reloc
)
8312 uint16_t insn16
= 0;
8314 if ((reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
) == 0
8315 || (ELF32_R_TYPE (reloc
->r_info
) != R_NDS32_INSN16
))
8318 if (!N32_IS_RT3 (insn
))
8321 switch (N32_OP6 (insn
))
8324 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
8325 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
8328 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
8329 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
8332 if (!IS_WITHIN_U (N32_IMM17S (insn
), 7))
8335 if (__GF (insn
, 17, 3) == 6)
8336 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM17S (insn
));
8337 else if (__GF (insn
, 17, 3) == 7)
8338 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM17S (insn
));
8342 if ((insn16
& 0x8000) == 0)
8349 /* Convert a 16-bit instruction to 32-bit one.
8350 INSN16 it the input and PINSN it the point to output.
8351 Return non-zero on successful. Otherwise 0 is returned. */
8354 nds32_convert_16_to_32 (bfd
*abfd
, uint16_t insn16
, uint32_t *pinsn
)
8356 uint32_t insn
= 0xffffffff;
8357 unsigned long mach
= bfd_get_mach (abfd
);
8359 /* NOTE: push25, pop25 and movd44 do not have 32-bit variants. */
8361 switch (__GF (insn16
, 9, 6))
8363 case 0x4: /* add45 */
8364 insn
= N32_ALU1 (ADD
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8367 case 0x5: /* sub45 */
8368 insn
= N32_ALU1 (SUB
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8371 case 0x6: /* addi45 */
8372 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8373 N16_IMM5U (insn16
));
8375 case 0x7: /* subi45 */
8376 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8377 -N16_IMM5U (insn16
));
8379 case 0x8: /* srai45 */
8380 insn
= N32_ALU1 (SRAI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8381 N16_IMM5U (insn16
));
8383 case 0x9: /* srli45 */
8384 insn
= N32_ALU1 (SRLI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
8385 N16_IMM5U (insn16
));
8387 case 0xa: /* slli333 */
8388 insn
= N32_ALU1 (SLLI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8389 N16_IMM3U (insn16
));
8391 case 0xc: /* add333 */
8392 insn
= N32_ALU1 (ADD
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8395 case 0xd: /* sub333 */
8396 insn
= N32_ALU1 (SUB
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8399 case 0xe: /* addi333 */
8400 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8401 N16_IMM3U (insn16
));
8403 case 0xf: /* subi333 */
8404 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8405 -N16_IMM3U (insn16
));
8407 case 0x10: /* lwi333 */
8408 insn
= N32_TYPE2 (LWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8409 N16_IMM3U (insn16
));
8411 case 0x12: /* lhi333 */
8412 insn
= N32_TYPE2 (LHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8413 N16_IMM3U (insn16
));
8415 case 0x13: /* lbi333 */
8416 insn
= N32_TYPE2 (LBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8417 N16_IMM3U (insn16
));
8419 case 0x11: /* lwi333.bi */
8420 insn
= N32_TYPE2 (LWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8421 N16_IMM3U (insn16
));
8423 case 0x14: /* swi333 */
8424 insn
= N32_TYPE2 (SWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8425 N16_IMM3U (insn16
));
8427 case 0x16: /* shi333 */
8428 insn
= N32_TYPE2 (SHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8429 N16_IMM3U (insn16
));
8431 case 0x17: /* sbi333 */
8432 insn
= N32_TYPE2 (SBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8433 N16_IMM3U (insn16
));
8435 case 0x15: /* swi333.bi */
8436 insn
= N32_TYPE2 (SWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8437 N16_IMM3U (insn16
));
8439 case 0x18: /* addri36.sp */
8440 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), REG_SP
,
8441 N16_IMM6U (insn16
) << 2);
8443 case 0x19: /* lwi45.fe */
8444 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), REG_R8
,
8445 (N16_IMM5U (insn16
) - 32));
8447 case 0x1a: /* lwi450 */
8448 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
8450 case 0x1b: /* swi450 */
8451 insn
= N32_TYPE2 (SWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
8454 /* These are r15 implied instructions. */
8455 case 0x30: /* slts45 */
8456 insn
= N32_ALU1 (SLTS
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
8458 case 0x31: /* slt45 */
8459 insn
= N32_ALU1 (SLT
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
8461 case 0x32: /* sltsi45 */
8462 insn
= N32_TYPE2 (SLTSI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
8464 case 0x33: /* slti45 */
8465 insn
= N32_TYPE2 (SLTI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
8467 case 0x34: /* beqzs8, bnezs8 */
8468 if (insn16
& N32_BIT (8))
8469 insn
= N32_BR2 (BNEZ
, REG_TA
, N16_IMM8S (insn16
));
8471 insn
= N32_BR2 (BEQZ
, REG_TA
, N16_IMM8S (insn16
));
8474 case 0x35: /* break16, ex9.it */
8475 /* Only consider range of v3 break16. */
8476 insn
= N32_TYPE0 (MISC
, (N16_IMM5U (insn16
) << 5) | N32_MISC_BREAK
);
8479 case 0x3c: /* ifcall9 */
8480 insn
= N32_BR2 (SOP0
, 0, N16_IMM9U (insn16
));
8482 case 0x3d: /* movpi45 */
8483 insn
= N32_TYPE1 (MOVI
, N16_RT4 (insn16
), N16_IMM5U (insn16
) + 16);
8486 case 0x3f: /* MISC33 */
8487 switch (insn16
& 0x7)
8490 insn
= N32_TYPE2 (SUBRI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8493 insn
= N32_ALU1 (NOR
, N16_RT3 (insn16
), N16_RA3 (insn16
),
8497 insn
= N32_ALU2 (MUL
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8501 insn
= N32_ALU1 (XOR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8505 insn
= N32_ALU1 (AND
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8509 insn
= N32_ALU1 (OR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8516 switch (insn16
& 0x7)
8519 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0xff);
8522 insn
= N32_ALU1 (ZEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8525 insn
= N32_ALU1 (SEB
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8528 insn
= N32_ALU1 (SEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
8530 case 4: /* xlsb33 */
8531 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 1);
8533 case 5: /* x11b33 */
8534 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0x7ff);
8536 case 6: /* bmski33 */
8537 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8538 1 << __GF (insn16
, 3, 3));
8540 case 7: /* fexti33 */
8541 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
8542 (1 << (__GF (insn16
, 3, 3) + 1)) - 1);
8548 switch (__GF (insn16
, 10, 5))
8550 case 0x0: /* mov55 or ifret16 */
8551 if (mach
>= MACH_V3
&& N16_RT5 (insn16
) == REG_SP
8552 && N16_RT5 (insn16
) == N16_RA5 (insn16
))
8553 insn
= N32_JREG (JR
, 0, 0, 0, 3);
8555 insn
= N32_TYPE2 (ADDI
, N16_RT5 (insn16
), N16_RA5 (insn16
), 0);
8557 case 0x1: /* movi55 */
8558 insn
= N32_TYPE1 (MOVI
, N16_RT5 (insn16
), N16_IMM5S (insn16
));
8560 case 0x1b: /* addi10s (V2) */
8561 insn
= N32_TYPE2 (ADDI
, REG_SP
, REG_SP
, N16_IMM10S (insn16
));
8565 switch (__GF (insn16
, 11, 4))
8567 case 0x7: /* lwi37.fp/swi37.fp */
8568 if (insn16
& N32_BIT (7)) /* swi37.fp */
8569 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
8571 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
8573 case 0x8: /* beqz38 */
8574 insn
= N32_BR2 (BEQZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
8576 case 0x9: /* bnez38 */
8577 insn
= N32_BR2 (BNEZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
8579 case 0xa: /* beqs38/j8, implied r5 */
8580 if (N16_RT38 (insn16
) == 5)
8581 insn
= N32_JI (J
, N16_IMM8S (insn16
));
8583 insn
= N32_BR1 (BEQ
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
8585 case 0xb: /* bnes38 and others. */
8586 if (N16_RT38 (insn16
) == 5)
8588 switch (__GF (insn16
, 5, 3))
8591 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 0);
8594 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 1);
8597 insn
= N32_JREG (JRAL
, REG_LP
, N16_RA5 (insn16
), 0, 0);
8599 case 2: /* ex9.it imm5 */
8600 /* ex9.it had no 32-bit variantl. */
8602 case 5: /* add5.pc */
8603 /* add5.pc had no 32-bit variantl. */
8608 insn
= N32_BR1 (BNE
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
8610 case 0xe: /* lwi37/swi37 */
8611 if (insn16
& (1 << 7)) /* swi37.sp */
8612 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
8614 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
8619 if (insn
& 0x80000000)
8629 is_sda_access_insn (unsigned long insn
)
8631 switch (N32_OP6 (insn
))
8652 static unsigned long
8653 turn_insn_to_sda_access (uint32_t insn
, bfd_signed_vma type
, uint32_t *pinsn
)
8659 case R_NDS32_GOT_LO12
:
8660 case R_NDS32_GOTOFF_LO12
:
8661 case R_NDS32_PLTREL_LO12
:
8662 case R_NDS32_PLT_GOTREL_LO12
:
8663 case R_NDS32_LO12S0_RELA
:
8664 switch (N32_OP6 (insn
))
8668 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
8672 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
8676 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
8680 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
8685 case R_NDS32_LO12S1_RELA
:
8686 switch (N32_OP6 (insn
))
8690 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
8694 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
8698 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
8703 case R_NDS32_LO12S2_RELA
:
8704 switch (N32_OP6 (insn
))
8708 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
8712 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
8717 case R_NDS32_LO12S2_DP_RELA
:
8718 case R_NDS32_LO12S2_SP_RELA
:
8719 oinsn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
8729 /* Linker hasn't found the correct merge section for non-section symbol
8730 in relax time, this work is left to the function elf_link_input_bfd().
8731 So for non-section symbol, _bfd_merged_section_offset is also needed
8732 to find the correct symbol address. */
8735 nds32_elf_rela_local_sym (bfd
*abfd
, Elf_Internal_Sym
*sym
,
8736 asection
**psec
, Elf_Internal_Rela
*rel
)
8738 asection
*sec
= *psec
;
8741 relocation
= (sec
->output_section
->vma
8742 + sec
->output_offset
+ sym
->st_value
);
8743 if ((sec
->flags
& SEC_MERGE
) && sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
8745 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8747 _bfd_merged_section_offset (abfd
, psec
,
8748 elf_section_data (sec
)->sec_info
,
8749 sym
->st_value
+ rel
->r_addend
);
8752 _bfd_merged_section_offset (abfd
, psec
,
8753 elf_section_data (sec
)->sec_info
,
8754 sym
->st_value
) + rel
->r_addend
;
8758 /* If we have changed the section, and our original section is
8759 marked with SEC_EXCLUDE, it means that the original
8760 SEC_MERGE section has been completely subsumed in some
8761 other SEC_MERGE section. In this case, we need to leave
8762 some info around for --emit-relocs. */
8763 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
8764 sec
->kept_section
= *psec
;
8767 rel
->r_addend
-= relocation
;
8768 rel
->r_addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
8774 calculate_memory_address (bfd
*abfd
, Elf_Internal_Rela
*irel
,
8775 Elf_Internal_Sym
*isymbuf
,
8776 Elf_Internal_Shdr
*symtab_hdr
)
8778 bfd_signed_vma foff
;
8779 bfd_vma symval
, addend
;
8780 Elf_Internal_Rela irel_fn
;
8781 Elf_Internal_Sym
*isym
;
8784 /* Get the value of the symbol referred to by the reloc. */
8785 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
8787 /* A local symbol. */
8788 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
8790 if (isym
->st_shndx
== SHN_UNDEF
)
8791 sym_sec
= bfd_und_section_ptr
;
8792 else if (isym
->st_shndx
== SHN_ABS
)
8793 sym_sec
= bfd_abs_section_ptr
;
8794 else if (isym
->st_shndx
== SHN_COMMON
)
8795 sym_sec
= bfd_com_section_ptr
;
8797 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
8798 memcpy (&irel_fn
, irel
, sizeof (Elf_Internal_Rela
));
8799 symval
= nds32_elf_rela_local_sym (abfd
, isym
, &sym_sec
, &irel_fn
);
8800 addend
= irel_fn
.r_addend
;
8805 struct elf_link_hash_entry
*h
;
8807 /* An external symbol. */
8808 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
8809 h
= elf_sym_hashes (abfd
)[indx
];
8810 BFD_ASSERT (h
!= NULL
);
8812 while (h
->root
.type
== bfd_link_hash_indirect
8813 || h
->root
.type
== bfd_link_hash_warning
)
8814 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8816 if (h
->root
.type
!= bfd_link_hash_defined
8817 && h
->root
.type
!= bfd_link_hash_defweak
)
8818 /* This appears to be a reference to an undefined
8819 symbol. Just ignore it--it will be caught by the
8820 regular reloc processing. */
8823 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
8825 sym_sec
= h
->root
.u
.def
.section
;
8826 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
, elf_section_data
8827 (sym_sec
)->sec_info
, h
->root
.u
.def
.value
);
8828 symval
= symval
+ sym_sec
->output_section
->vma
8829 + sym_sec
->output_offset
;
8832 symval
= (h
->root
.u
.def
.value
8833 + h
->root
.u
.def
.section
->output_section
->vma
8834 + h
->root
.u
.def
.section
->output_offset
);
8835 addend
= irel
->r_addend
;
8838 foff
= symval
+ addend
;
8844 is_16bit_NOP (bfd
*abfd ATTRIBUTE_UNUSED
,
8845 asection
*sec
, Elf_Internal_Rela
*rel
)
8848 unsigned short insn16
;
8850 if (!(rel
->r_addend
& R_NDS32_INSN16_CONVERT_FLAG
))
8852 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8853 insn16
= bfd_getb16 (contents
+ rel
->r_offset
);
8854 if (insn16
== NDS32_NOP16
)
8859 /* It checks whether the instruction could be converted to
8860 16-bit form and returns the converted one.
8862 `internal_relocs' is supposed to be sorted. */
8865 is_convert_32_to_16 (bfd
*abfd
, asection
*sec
,
8866 Elf_Internal_Rela
*reloc
,
8867 Elf_Internal_Rela
*internal_relocs
,
8868 Elf_Internal_Rela
*irelend
,
8871 #define NORMAL_32_TO_16 (1 << 0)
8872 #define SPECIAL_32_TO_16 (1 << 1)
8873 bfd_byte
*contents
= NULL
;
8877 Elf_Internal_Rela
*pc_rel
;
8878 Elf_Internal_Shdr
*symtab_hdr
;
8879 Elf_Internal_Sym
*isymbuf
= NULL
;
8883 if (reloc
->r_offset
+ 4 > sec
->size
)
8886 offset
= reloc
->r_offset
;
8888 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
8890 insn
= bfd_getb32 (contents
+ offset
);
8892 if (nds32_convert_32_to_16 (abfd
, insn
, insn16
, NULL
))
8893 convert_type
= NORMAL_32_TO_16
;
8894 else if (special_convert_32_to_16 (insn
, insn16
, reloc
))
8895 convert_type
= SPECIAL_32_TO_16
;
8899 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8900 if (!nds32_get_local_syms (abfd
, sec
, &isymbuf
))
8903 /* Find the first relocation of the same relocation-type,
8904 so we iteratie them forward. */
8906 while ((pc_rel
- 1) >= internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
8909 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
8911 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
8912 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8913 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
8914 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
8916 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
);
8917 if (off
>= ACCURATE_8BIT_S1
|| off
< -ACCURATE_8BIT_S1
8922 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
8924 /* movi => movi55 */
8925 mem_addr
= calculate_memory_address (abfd
, pc_rel
, isymbuf
,
8927 /* mem_addr is unsigned, but the value should
8928 be between [-16, 15]. */
8929 if ((mem_addr
+ 0x10) >> 5)
8933 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_20
)
8934 || (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_LO12
))
8936 /* It never happen movi to movi55 for R_NDS32_TLS_LE_20,
8937 because it can be relaxed to addi for TLS_LE_ADD. */
8940 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
8941 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
8942 && (reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
)
8943 && convert_type
== SPECIAL_32_TO_16
)
8946 We've selected a best fp-base for this access, so we can
8947 always resolve it anyway. Do nothing. */
8950 else if ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_NONE
8951 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_RELA_GNU_VTINHERIT
))
8952 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_RELA_GNU_VTENTRY
)
8953 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_INSN16
))
8954 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_LOADSTORE
)
8955 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_DWARF2_OP1_RELA
)))
8957 /* Prevent unresolved addi instruction translate
8958 to addi45 or addi333. */
8961 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
8963 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
);
8964 if (off
>= ACCURATE_U9BIT_S1
|| off
<= 0)
8974 nds32_elf_write_16 (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*contents
,
8975 Elf_Internal_Rela
*reloc
,
8976 Elf_Internal_Rela
*internal_relocs
,
8977 Elf_Internal_Rela
*irelend
,
8978 unsigned short insn16
)
8980 Elf_Internal_Rela
*pc_rel
;
8983 offset
= reloc
->r_offset
;
8984 bfd_putb16 (insn16
, contents
+ offset
);
8985 /* Find the first relocation of the same relocation-type,
8986 so we iteratie them forward. */
8988 while ((pc_rel
- 1) > internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
8991 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
8993 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
8994 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8995 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
)
8998 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PCREL_RELA
);
9000 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
9002 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PLTREL
);
9003 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
9005 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_5_RELA
);
9006 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
9007 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
9009 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_SDA_FP7U2_RELA
);
9010 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
9012 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_10IFCU_PCREL_RELA
);
9016 /* Find a relocation of type specified by `reloc_type'
9017 of the same r_offset with reloc.
9018 If not found, return irelend.
9020 Assuming relocations are sorted by r_offset,
9021 we find the relocation from `reloc' backward untill relocs,
9022 or find it from `reloc' forward untill irelend. */
9024 static Elf_Internal_Rela
*
9025 find_relocs_at_address (Elf_Internal_Rela
*reloc
,
9026 Elf_Internal_Rela
*relocs
,
9027 Elf_Internal_Rela
*irelend
,
9028 enum elf_nds32_reloc_type reloc_type
)
9030 Elf_Internal_Rela
*rel_t
;
9032 /* Find backward. */
9034 rel_t
>= relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
9036 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
9039 /* We didn't find it backward. Try find it forward. */
9041 rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
9043 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
9049 /* Find a relocation of specified type and offset.
9050 `reloc' is just a refence point to find a relocation at specified offset.
9051 If not found, return irelend.
9053 Assuming relocations are sorted by r_offset,
9054 we find the relocation from `reloc' backward untill relocs,
9055 or find it from `reloc' forward untill irelend. */
9057 static Elf_Internal_Rela
*
9058 find_relocs_at_address_addr (Elf_Internal_Rela
*reloc
,
9059 Elf_Internal_Rela
*relocs
,
9060 Elf_Internal_Rela
*irelend
,
9061 enum elf_nds32_reloc_type reloc_type
,
9064 Elf_Internal_Rela
*rel_t
= NULL
;
9066 /* First, we try to find a relocation of offset `offset_p',
9067 and then we use find_relocs_at_address to find specific type. */
9069 if (reloc
->r_offset
> offset_p
)
9071 /* Find backward. */
9073 rel_t
>= relocs
&& rel_t
->r_offset
> offset_p
; rel_t
--)
9076 else if (reloc
->r_offset
< offset_p
)
9080 rel_t
< irelend
&& rel_t
->r_offset
< offset_p
; rel_t
++)
9087 if (rel_t
< relocs
|| rel_t
== irelend
|| rel_t
->r_offset
!= offset_p
)
9090 return find_relocs_at_address (rel_t
, relocs
, irelend
, reloc_type
);
9093 typedef struct nds32_elf_blank nds32_elf_blank_t
;
9094 struct nds32_elf_blank
9096 /* Where the blank begins. */
9098 /* The size of the blank. */
9100 /* The accumulative size before this blank. */
9102 nds32_elf_blank_t
*next
;
9103 nds32_elf_blank_t
*prev
;
9106 static nds32_elf_blank_t
*blank_free_list
= NULL
;
9108 static nds32_elf_blank_t
*
9109 create_nds32_elf_blank (bfd_vma offset_p
, bfd_vma size_p
)
9111 nds32_elf_blank_t
*blank_t
;
9113 if (blank_free_list
)
9115 blank_t
= blank_free_list
;
9116 blank_free_list
= blank_free_list
->next
;
9119 blank_t
= bfd_malloc (sizeof (nds32_elf_blank_t
));
9121 if (blank_t
== NULL
)
9124 blank_t
->offset
= offset_p
;
9125 blank_t
->size
= size_p
;
9126 blank_t
->total_size
= 0;
9127 blank_t
->next
= NULL
;
9128 blank_t
->prev
= NULL
;
9134 remove_nds32_elf_blank (nds32_elf_blank_t
*blank_p
)
9136 if (blank_free_list
)
9138 blank_free_list
->prev
= blank_p
;
9139 blank_p
->next
= blank_free_list
;
9142 blank_p
->next
= NULL
;
9144 blank_p
->prev
= NULL
;
9145 blank_free_list
= blank_p
;
9149 clean_nds32_elf_blank (void)
9151 nds32_elf_blank_t
*blank_t
;
9153 while (blank_free_list
)
9155 blank_t
= blank_free_list
;
9156 blank_free_list
= blank_free_list
->next
;
9161 static nds32_elf_blank_t
*
9162 search_nds32_elf_blank (nds32_elf_blank_t
*blank_p
, bfd_vma addr
)
9164 nds32_elf_blank_t
*blank_t
;
9170 while (blank_t
&& addr
< blank_t
->offset
)
9171 blank_t
= blank_t
->prev
;
9172 while (blank_t
&& blank_t
->next
&& addr
>= blank_t
->next
->offset
)
9173 blank_t
= blank_t
->next
;
9179 get_nds32_elf_blank_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
9182 nds32_elf_blank_t
*blank_t
;
9184 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
9191 if (addr
< blank_t
->offset
+ blank_t
->size
)
9192 return blank_t
->total_size
+ (addr
- blank_t
->offset
);
9194 return blank_t
->total_size
+ blank_t
->size
;
9198 insert_nds32_elf_blank (nds32_elf_blank_t
**blank_p
, bfd_vma addr
, bfd_vma len
)
9200 nds32_elf_blank_t
*blank_t
, *blank_t2
;
9204 *blank_p
= create_nds32_elf_blank (addr
, len
);
9205 return *blank_p
? TRUE
: FALSE
;
9208 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
9210 if (blank_t
== NULL
)
9212 blank_t
= create_nds32_elf_blank (addr
, len
);
9215 while ((*blank_p
)->prev
!= NULL
)
9216 *blank_p
= (*blank_p
)->prev
;
9217 blank_t
->next
= *blank_p
;
9218 (*blank_p
)->prev
= blank_t
;
9219 (*blank_p
) = blank_t
;
9223 if (addr
< blank_t
->offset
+ blank_t
->size
)
9225 /* Extend the origin blank. */
9226 if (addr
+ len
> blank_t
->offset
+ blank_t
->size
)
9227 blank_t
->size
= addr
+ len
- blank_t
->offset
;
9231 blank_t2
= create_nds32_elf_blank (addr
, len
);
9236 blank_t
->next
->prev
= blank_t2
;
9237 blank_t2
->next
= blank_t
->next
;
9239 blank_t2
->prev
= blank_t
;
9240 blank_t
->next
= blank_t2
;
9241 *blank_p
= blank_t2
;
9248 insert_nds32_elf_blank_recalc_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
9251 nds32_elf_blank_t
*blank_t
;
9253 if (!insert_nds32_elf_blank (blank_p
, addr
, len
))
9260 blank_t
->total_size
= 0;
9261 blank_t
= blank_t
->next
;
9266 blank_t
->total_size
= blank_t
->prev
->total_size
+ blank_t
->prev
->size
;
9267 blank_t
= blank_t
->next
;
9274 calc_nds32_blank_total (nds32_elf_blank_t
*blank_p
)
9276 nds32_elf_blank_t
*blank_t
;
9277 bfd_vma total_size
= 0;
9283 while (blank_t
->prev
)
9284 blank_t
= blank_t
->prev
;
9287 blank_t
->total_size
= total_size
;
9288 total_size
+= blank_t
->size
;
9289 blank_t
= blank_t
->next
;
9294 nds32_elf_relax_delete_blanks (bfd
*abfd
, asection
*sec
,
9295 nds32_elf_blank_t
*blank_p
)
9297 Elf_Internal_Shdr
*symtab_hdr
; /* Symbol table header of this bfd. */
9298 Elf_Internal_Sym
*isym
= NULL
; /* Symbol table of this bfd. */
9299 Elf_Internal_Sym
*isymend
; /* Symbol entry iterator. */
9300 unsigned int sec_shndx
; /* The section the be relaxed. */
9301 bfd_byte
*contents
; /* Contents data of iterating section. */
9302 Elf_Internal_Rela
*internal_relocs
;
9303 Elf_Internal_Rela
*irel
;
9304 Elf_Internal_Rela
*irelend
;
9305 struct elf_link_hash_entry
**sym_hashes
;
9306 struct elf_link_hash_entry
**end_hashes
;
9307 unsigned int symcount
;
9309 nds32_elf_blank_t
*blank_t
;
9310 nds32_elf_blank_t
*blank_t2
;
9311 nds32_elf_blank_t
*blank_head
;
9313 blank_head
= blank_t
= blank_p
;
9314 while (blank_head
->prev
!= NULL
)
9315 blank_head
= blank_head
->prev
;
9316 while (blank_t
->next
!= NULL
)
9317 blank_t
= blank_t
->next
;
9319 if (blank_t
->offset
+ blank_t
->size
<= sec
->size
)
9321 blank_t
->next
= create_nds32_elf_blank (sec
->size
+ 4, 0);
9322 blank_t
->next
->prev
= blank_t
;
9324 if (blank_head
->offset
> 0)
9326 blank_head
->prev
= create_nds32_elf_blank (0, 0);
9327 blank_head
->prev
->next
= blank_head
;
9328 blank_head
= blank_head
->prev
;
9331 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
9333 /* The deletion must stop at the next ALIGN reloc for an alignment
9334 power larger than the number of bytes we are deleting. */
9336 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9337 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
9342 isym
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
9343 symtab_hdr
->sh_info
, 0, NULL
, NULL
, NULL
);
9344 symtab_hdr
->contents
= (bfd_byte
*) isym
;
9347 if (isym
== NULL
|| symtab_hdr
->sh_info
== 0)
9350 blank_t
= blank_head
;
9351 calc_nds32_blank_total (blank_head
);
9353 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
9355 /* Adjust all the relocs. */
9357 /* Relocations MUST be kept in memory, because relaxation adjust them. */
9358 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sect
, NULL
, NULL
,
9359 TRUE
/* keep_memory */);
9360 irelend
= internal_relocs
+ sect
->reloc_count
;
9362 blank_t
= blank_head
;
9363 blank_t2
= blank_head
;
9365 if (!(sect
->flags
& SEC_RELOC
))
9368 nds32_get_section_contents (abfd
, sect
, &contents
, TRUE
);
9370 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
9374 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_DIFF8
9375 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_DIFF32
9376 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
9378 unsigned long val
= 0;
9380 long before
, between
;
9383 switch (ELF32_R_TYPE (irel
->r_info
))
9386 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
9388 case R_NDS32_DIFF16
:
9389 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
9391 case R_NDS32_DIFF32
:
9392 val
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
9393 /* Get the signed bit and mask for the high part. The
9394 gcc will alarm when right shift 32-bit since the
9395 type size of long may be 32-bit. */
9396 mask
= 0 - (val
>> 31);
9398 offset
= (val
| (mask
- 0xffffffff));
9407 0 |encoded in location|
9408 |------------|-------------------|---------
9410 -- before ---| *****************
9411 --------------------- between ---|
9413 We only care how much data are relax between DIFF,
9416 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
9417 between
= get_nds32_elf_blank_total (&blank_t
,
9418 irel
->r_addend
+ offset
, 0);
9419 if (between
== before
)
9420 goto done_adjust_diff
;
9422 switch (ELF32_R_TYPE (irel
->r_info
))
9425 bfd_put_8 (abfd
, offset
- (between
- before
),
9426 contents
+ irel
->r_offset
);
9428 case R_NDS32_DIFF16
:
9429 bfd_put_16 (abfd
, offset
- (between
- before
),
9430 contents
+ irel
->r_offset
);
9432 case R_NDS32_DIFF32
:
9433 bfd_put_32 (abfd
, offset
- (between
- before
),
9434 contents
+ irel
->r_offset
);
9438 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_DIFF_ULEB128
9439 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
9442 unsigned int len
= 0;
9443 unsigned long before
, between
;
9446 val
= _bfd_read_unsigned_leb128 (abfd
, contents
+ irel
->r_offset
,
9449 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
9450 between
= get_nds32_elf_blank_total (&blank_t
,
9451 irel
->r_addend
+ val
, 0);
9452 if (between
== before
)
9453 goto done_adjust_diff
;
9455 p
= contents
+ irel
->r_offset
;
9457 memset (p
, 0x80, len
);
9459 p
= write_uleb128 (p
, val
- (between
- before
)) - 1;
9467 raddr
= irel
->r_offset
;
9468 irel
->r_offset
-= get_nds32_elf_blank_total (&blank_t2
,
9471 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
9473 if (blank_t2
&& blank_t2
->next
9474 && (blank_t2
->offset
> raddr
9475 || blank_t2
->next
->offset
<= raddr
))
9477 (_("%pB: error: search_nds32_elf_blank reports wrong node"),
9480 /* Mark reloc in deleted portion as NONE.
9481 For some relocs like R_NDS32_LABEL that doesn't modify the
9482 content in the section. R_NDS32_LABEL doesn't belong to the
9483 instruction in the section, so we should preserve it. */
9484 if (raddr
>= blank_t2
->offset
9485 && raddr
< blank_t2
->offset
+ blank_t2
->size
9486 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
9487 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_BEGIN
9488 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_END
9489 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
9490 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_SUBTRAHEND
9491 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_MINUEND
)
9493 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
9499 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
9500 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
9501 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
9504 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
9505 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
9506 && ELF_ST_TYPE (isym
[ELF32_R_SYM (irel
->r_info
)].st_info
) == STT_SECTION
)
9508 if (irel
->r_addend
<= sec
->size
)
9510 get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 1);
9515 /* Adjust the local symbols defined in this section. */
9516 blank_t
= blank_head
;
9517 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
9519 if (isym
->st_shndx
== sec_shndx
)
9521 if (isym
->st_value
<= sec
->size
)
9524 bfd_vma orig_addr
= isym
->st_value
;
9526 ahead
= get_nds32_elf_blank_total (&blank_t
, isym
->st_value
, 1);
9527 isym
->st_value
-= ahead
;
9529 /* Adjust function size. */
9530 if (ELF32_ST_TYPE (isym
->st_info
) == STT_FUNC
9531 && isym
->st_size
> 0)
9533 get_nds32_elf_blank_total
9534 (&blank_t
, orig_addr
+ isym
->st_size
, 0) - ahead
;
9539 /* Now adjust the global symbols defined in this section. */
9540 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
9541 - symtab_hdr
->sh_info
);
9542 sym_hashes
= elf_sym_hashes (abfd
);
9543 end_hashes
= sym_hashes
+ symcount
;
9544 blank_t
= blank_head
;
9545 for (; sym_hashes
< end_hashes
; sym_hashes
++)
9547 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
9549 if ((sym_hash
->root
.type
== bfd_link_hash_defined
9550 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
9551 && sym_hash
->root
.u
.def
.section
== sec
)
9553 if (sym_hash
->root
.u
.def
.value
<= sec
->size
)
9556 bfd_vma orig_addr
= sym_hash
->root
.u
.def
.value
;
9558 ahead
= get_nds32_elf_blank_total (&blank_t
, sym_hash
->root
.u
.def
.value
, 1);
9559 sym_hash
->root
.u
.def
.value
-= ahead
;
9561 /* Adjust function size. */
9562 if (sym_hash
->type
== STT_FUNC
)
9564 get_nds32_elf_blank_total
9565 (&blank_t
, orig_addr
+ sym_hash
->size
, 0) - ahead
;
9571 contents
= elf_section_data (sec
)->this_hdr
.contents
;
9572 blank_t
= blank_head
;
9573 while (blank_t
->next
)
9575 /* Actually delete the bytes. */
9577 /* If current blank is the last blank overlap with current section,
9578 go to finish process. */
9579 if (sec
->size
<= (blank_t
->next
->offset
))
9582 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
9583 contents
+ blank_t
->offset
+ blank_t
->size
,
9584 blank_t
->next
->offset
- (blank_t
->offset
+ blank_t
->size
));
9586 blank_t
= blank_t
->next
;
9589 if (sec
->size
> (blank_t
->offset
+ blank_t
->size
))
9591 /* There are remaining code between blank and section boundary.
9592 Move the remaining code to appropriate location. */
9593 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
9594 contents
+ blank_t
->offset
+ blank_t
->size
,
9595 sec
->size
- (blank_t
->offset
+ blank_t
->size
));
9596 sec
->size
-= blank_t
->total_size
+ blank_t
->size
;
9599 /* This blank is not entirely included in the section,
9600 reduce the section size by only part of the blank size. */
9601 sec
->size
-= blank_t
->total_size
+ (sec
->size
- blank_t
->offset
);
9605 blank_t
= blank_head
;
9606 blank_head
= blank_head
->next
;
9607 remove_nds32_elf_blank (blank_t
);
9613 /* Get the contents of a section. */
9616 nds32_get_section_contents (bfd
*abfd
, asection
*sec
,
9617 bfd_byte
**contents_p
, bfd_boolean cache
)
9619 /* Get the section contents. */
9620 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
9621 *contents_p
= elf_section_data (sec
)->this_hdr
.contents
;
9624 if (!bfd_malloc_and_get_section (abfd
, sec
, contents_p
))
9627 elf_section_data (sec
)->this_hdr
.contents
= *contents_p
;
9633 /* Get the contents of the internal symbol of abfd. */
9636 nds32_get_local_syms (bfd
*abfd
, asection
*sec ATTRIBUTE_UNUSED
,
9637 Elf_Internal_Sym
**isymbuf_p
)
9639 Elf_Internal_Shdr
*symtab_hdr
;
9640 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9642 /* Read this BFD's local symbols if we haven't done so already. */
9643 if (*isymbuf_p
== NULL
&& symtab_hdr
->sh_info
!= 0)
9645 *isymbuf_p
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
9646 if (*isymbuf_p
== NULL
)
9648 *isymbuf_p
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
9649 symtab_hdr
->sh_info
, 0,
9651 if (*isymbuf_p
== NULL
)
9655 symtab_hdr
->contents
= (bfd_byte
*) (*isymbuf_p
);
9660 /* Range of small data. */
9661 static bfd_vma sdata_range
[2][2];
9662 static bfd_vma
const sdata_init_range
[2] =
9663 { ACCURATE_12BIT_S1
, ACCURATE_19BIT
};
9666 nds32_elf_insn_size (bfd
*abfd ATTRIBUTE_UNUSED
,
9667 bfd_byte
*contents
, bfd_vma addr
)
9669 unsigned long insn
= bfd_getb32 (contents
+ addr
);
9671 if (insn
& 0x80000000)
9677 /* Set the gp relax range. We have to measure the safe range
9678 to do gp relaxation. */
9681 relax_range_measurement (bfd
*abfd
)
9683 asection
*sec_f
, *sec_b
;
9684 /* For upper bound. */
9685 bfd_vma maxpgsz
= get_elf_backend_data (abfd
)->maxpagesize
;
9687 static int decide_relax_range
= 0;
9689 int range_number
= ARRAY_SIZE (sdata_init_range
);
9691 if (decide_relax_range
)
9693 decide_relax_range
= 1;
9695 if (sda_rela_sec
== NULL
)
9697 /* Since there is no data sections, we assume the range is page size. */
9698 for (i
= 0; i
< range_number
; i
++)
9700 sdata_range
[i
][0] = sdata_init_range
[i
] - 0x1000;
9701 sdata_range
[i
][1] = sdata_init_range
[i
] - 0x1000;
9706 /* Get the biggest alignment power after the gp located section. */
9707 sec_f
= sda_rela_sec
->output_section
;
9708 sec_b
= sec_f
->next
;
9710 while (sec_b
!= NULL
)
9712 if ((unsigned)(1 << sec_b
->alignment_power
) > align
)
9713 align
= (1 << sec_b
->alignment_power
);
9714 sec_b
= sec_b
->next
;
9717 /* I guess we can not determine the section before
9718 gp located section, so we assume the align is max page size. */
9719 for (i
= 0; i
< range_number
; i
++)
9721 sdata_range
[i
][1] = sdata_init_range
[i
] - align
;
9722 BFD_ASSERT (sdata_range
[i
][1] <= sdata_init_range
[i
]);
9723 sdata_range
[i
][0] = sdata_init_range
[i
] - maxpgsz
;
9724 BFD_ASSERT (sdata_range
[i
][0] <= sdata_init_range
[i
]);
9728 /* These are macros used to check flags encoded in r_addend.
9729 They are only used by nds32_elf_relax_section (). */
9730 #define GET_SEQ_LEN(addend) ((addend) & 0x000000ff)
9731 #define IS_1ST_CONVERT(addend) ((addend) & 0x80000000)
9732 #define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
9733 #define IS_16BIT_ON(addend) ((addend) & 0x20000000)
9735 static const char * unrecognized_reloc_msg
=
9736 /* xgettext:c-format */
9737 N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64
);
9739 /* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
9742 nds32_elf_relax_longcall1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9743 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9744 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9745 Elf_Internal_Shdr
*symtab_hdr
)
9747 /* There are 3 variations for LONGCALL1
9748 case 4-4-2; 16-bit on, optimize off or optimize for space
9749 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9750 ori ta, ta, lo12(symbol) ; LO12S0
9753 case 4-4-4; 16-bit off, optimize don't care
9754 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9755 ori ta, ta, lo12(symbol) ; LO12S0
9758 case 4-4-4; 16-bit on, optimize for speed
9759 sethi ta, hi20(symbol) ; LONGCALL1/HI20
9760 ori ta, ta, lo12(symbol) ; LO12S0
9762 Check code for -mlong-calls output. */
9764 /* Get the reloc for the address from which the register is
9765 being loaded. This reloc will tell us which function is
9766 actually being called. */
9769 int seq_len
; /* Original length of instruction sequence. */
9771 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
9772 bfd_signed_vma foff
;
9775 irelend
= internal_relocs
+ sec
->reloc_count
;
9776 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9777 laddr
= irel
->r_offset
;
9778 *insn_len
= seq_len
;
9780 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9781 R_NDS32_HI20_RELA
, laddr
);
9782 lo_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9783 R_NDS32_LO12S0_ORI_RELA
,
9786 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9788 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL1",
9789 (uint64_t) irel
->r_offset
);
9793 /* Get the value of the symbol referred to by the reloc. */
9794 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
9796 /* This condition only happened when symbol is undefined. */
9798 || foff
< -CONSERVATIVE_24BIT_S1
9799 || foff
>= CONSERVATIVE_24BIT_S1
)
9802 /* Relax to: jal symbol; 25_PCREL. */
9803 /* For simplicity of coding, we are going to modify the section
9804 contents, the section relocs, and the BFD symbol table. We
9805 must tell the rest of the code not to free up this
9806 information. It would be possible to instead create a table
9807 of changes which have to be made, as is done in coff-mips.c;
9808 that would be more work, but would require less memory when
9809 the linker is run. */
9811 /* Replace the long call with a jal. */
9812 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9813 R_NDS32_25_PCREL_RELA
);
9814 irel
->r_addend
= hi_irelfn
->r_addend
;
9816 /* We don't resolve this here but resolve it in relocate_section. */
9818 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9821 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9823 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9828 insn16
= NDS32_NOP16
;
9829 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9831 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
9832 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9838 #define CONVERT_CONDITION_CALL(insn) (((insn) & 0xffff0000) ^ 0x90000)
9839 /* Relax LONGCALL2 relocation for nds32_elf_relax_section. */
9842 nds32_elf_relax_longcall2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9843 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9844 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9845 Elf_Internal_Shdr
*symtab_hdr
)
9847 /* bltz rt, .L1 ; LONGCALL2
9848 jal symbol ; 25_PCREL
9851 /* Get the reloc for the address from which the register is
9852 being loaded. This reloc will tell us which function is
9853 actually being called. */
9857 Elf_Internal_Rela
*i1_irelfn
, *cond_irelfn
, *irelend
;
9858 bfd_signed_vma foff
;
9860 irelend
= internal_relocs
+ sec
->reloc_count
;
9861 laddr
= irel
->r_offset
;
9863 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9864 R_NDS32_25_PCREL_RELA
, laddr
+ 4);
9866 if (i1_irelfn
== irelend
)
9868 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL2",
9869 (uint64_t) irel
->r_offset
);
9873 insn
= bfd_getb32 (contents
+ laddr
);
9875 /* Get the value of the symbol referred to by the reloc. */
9876 foff
= calculate_offset (abfd
, sec
, i1_irelfn
, isymbuf
, symtab_hdr
);
9879 || foff
< -CONSERVATIVE_16BIT_S1
9880 || foff
>= CONSERVATIVE_16BIT_S1
)
9883 /* Relax to bgezal rt, label ; 17_PCREL
9884 or bltzal rt, label ; 17_PCREL */
9886 /* Convert to complimentary conditional call. */
9887 insn
= CONVERT_CONDITION_CALL (insn
);
9889 /* For simplicity of coding, we are going to modify the section
9890 contents, the section relocs, and the BFD symbol table. We
9891 must tell the rest of the code not to free up this
9892 information. It would be possible to instead create a table
9893 of changes which have to be made, as is done in coff-mips.c;
9894 that would be more work, but would require less memory when
9895 the linker is run. */
9897 /* Clean unnessary relocations. */
9899 ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
), R_NDS32_NONE
);
9901 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9902 R_NDS32_17_PCREL_RELA
, laddr
);
9903 if (cond_irelfn
!= irelend
)
9904 cond_irelfn
->r_info
=
9905 ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
), R_NDS32_NONE
);
9907 /* Replace the long call with a bgezal. */
9908 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
),
9909 R_NDS32_17_PCREL_RELA
);
9910 irel
->r_addend
= i1_irelfn
->r_addend
;
9912 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9918 /* Relax LONGCALL3 relocation for nds32_elf_relax_section. */
9921 nds32_elf_relax_longcall3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9922 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9923 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9924 Elf_Internal_Shdr
*symtab_hdr
)
9926 /* There are 3 variations for LONGCALL3
9927 case 4-4-4-2; 16-bit on, optimize off or optimize for space
9928 bltz rt, $1 ; LONGCALL3
9929 sethi ta, hi20(symbol) ; HI20
9930 ori ta, ta, lo12(symbol) ; LO12S0
9934 case 4-4-4-4; 16-bit off, optimize don't care
9935 bltz rt, $1 ; LONGCALL3
9936 sethi ta, hi20(symbol) ; HI20
9937 ori ta, ta, lo12(symbol) ; LO12S0
9941 case 4-4-4-4; 16-bit on, optimize for speed
9942 bltz rt, $1 ; LONGCALL3
9943 sethi ta, hi20(symbol) ; HI20
9944 ori ta, ta, lo12(symbol) ; LO12S0
9948 /* Get the reloc for the address from which the register is
9949 being loaded. This reloc will tell us which function is
9950 actually being called. */
9953 int seq_len
; /* Original length of instruction sequence. */
9955 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
9956 bfd_signed_vma foff
;
9959 irelend
= internal_relocs
+ sec
->reloc_count
;
9960 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9961 laddr
= irel
->r_offset
;
9962 *insn_len
= seq_len
;
9965 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9966 R_NDS32_HI20_RELA
, laddr
+ 4);
9968 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9969 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 8);
9971 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9973 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL3",
9974 (uint64_t) irel
->r_offset
);
9978 /* Get the value of the symbol referred to by the reloc. */
9979 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
9982 || foff
< -CONSERVATIVE_24BIT_S1
9983 || foff
>= CONSERVATIVE_24BIT_S1
)
9986 insn
= bfd_getb32 (contents
+ laddr
);
9987 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9989 /* Relax to bgezal rt, label ; 17_PCREL
9990 or bltzal rt, label ; 17_PCREL */
9992 /* Convert to complimentary conditional call. */
9993 insn
= CONVERT_CONDITION_CALL (insn
);
9994 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9998 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
10000 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
10001 lo_irelfn
->r_info
=
10002 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10005 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10006 R_NDS32_17_PCREL_RELA
, laddr
);
10007 if (cond_irelfn
!= irelend
)
10009 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10010 R_NDS32_17_PCREL_RELA
);
10011 cond_irelfn
->r_addend
= hi_irelfn
->r_addend
;
10016 insn16
= NDS32_NOP16
;
10017 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10018 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10020 hi_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10024 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
10026 /* Relax to the following instruction sequence
10027 bltz rt, $1 ; LONGCALL2
10028 jal symbol ; 25_PCREL
10032 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
10034 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10035 R_NDS32_25_PCREL_RELA
);
10037 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL2
);
10039 lo_irelfn
->r_info
=
10040 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10044 insn16
= NDS32_NOP16
;
10045 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10046 lo_irelfn
->r_info
=
10047 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
10048 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10055 /* Relax LONGJUMP1 relocation for nds32_elf_relax_section. */
10058 nds32_elf_relax_longjump1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10059 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10060 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10061 Elf_Internal_Shdr
*symtab_hdr
)
10063 /* There are 3 variations for LONGJUMP1
10064 case 4-4-2; 16-bit bit on, optimize off or optimize for space
10065 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10066 ori ta, ta, lo12(symbol) ; LO12S0
10069 case 4-4-4; 16-bit off, optimize don't care
10070 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10071 ori ta, ta, lo12(symbol) ; LO12S0
10074 case 4-4-4; 16-bit on, optimize for speed
10075 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
10076 ori ta, ta, lo12(symbol) ; LO12S0
10079 /* Get the reloc for the address from which the register is
10080 being loaded. This reloc will tell us which function is
10081 actually being called. */
10084 int seq_len
; /* Original length of instruction sequence. */
10085 int insn16_on
; /* 16-bit on/off. */
10087 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
10088 bfd_signed_vma foff
;
10090 unsigned long reloc
;
10092 irelend
= internal_relocs
+ sec
->reloc_count
;
10093 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10094 laddr
= irel
->r_offset
;
10095 *insn_len
= seq_len
;
10096 insn16_on
= IS_16BIT_ON (irel
->r_addend
);
10099 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10100 R_NDS32_HI20_RELA
, laddr
);
10102 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10103 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 4);
10104 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
10106 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP1",
10107 (uint64_t) irel
->r_offset
);
10111 /* Get the value of the symbol referred to by the reloc. */
10112 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
10115 || foff
>= CONSERVATIVE_24BIT_S1
10116 || foff
< -CONSERVATIVE_24BIT_S1
)
10120 && foff
>= -ACCURATE_8BIT_S1
10121 && foff
< ACCURATE_8BIT_S1
10122 && (seq_len
& 0x2))
10125 /* 16-bit on, but not optimized for speed. */
10126 reloc
= R_NDS32_9_PCREL_RELA
;
10128 bfd_putb16 (insn16
, contents
+ irel
->r_offset
);
10131 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10136 reloc
= R_NDS32_25_PCREL_RELA
;
10138 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
10141 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_INSN16
);
10142 irel
->r_addend
= 0;
10145 hi_irelfn
->r_info
=
10146 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
10147 lo_irelfn
->r_info
=
10148 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
10150 if ((seq_len
& 0x2) && ((*insn_len
& 2) == 0))
10152 insn16
= NDS32_NOP16
;
10153 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10154 lo_irelfn
->r_info
=
10155 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10157 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10163 /* Revert condition branch. This function does not check if the input
10164 instruction is condition branch or not. */
10167 nds32_elf_convert_branch (uint16_t insn16
, uint32_t insn
,
10168 uint16_t *re_insn16
, uint32_t *re_insn
)
10170 uint32_t comp_insn
= 0;
10171 uint16_t comp_insn16
= 0;
10175 if (N32_OP6 (insn
) == N32_OP6_BR1
)
10178 comp_insn
= (insn
^ 0x4000) & 0xffffc000;
10179 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
)
10181 /* Insn can be contracted to 16-bit implied r5. */
10183 (comp_insn
& 0x4000) ? INSN_BNES38
: INSN_BEQS38
;
10184 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
10187 else if (N32_OP6 (insn
) == N32_OP6_BR3
)
10189 /* bnec $ta, imm11, label. */
10190 comp_insn
= (insn
^ 0x80000) & 0xffffff00;
10194 comp_insn
= (insn
^ 0x10000) & 0xffffc000;
10195 if (N32_BR2_SUB (insn
) == N32_BR2_BEQZ
10196 || N32_BR2_SUB (insn
) == N32_BR2_BNEZ
)
10198 if (N32_IS_RT3 (insn
))
10200 /* Insn can be contracted to 16-bit. */
10202 (comp_insn
& 0x10000) ? INSN_BNEZ38
: INSN_BEQZ38
;
10203 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
10205 else if (N32_RT5 (insn
) == REG_R15
)
10207 /* Insn can be contracted to 16-bit. */
10209 (comp_insn
& 0x10000) ? INSN_BNES38
: INSN_BEQS38
;
10216 switch ((insn16
& 0xf000) >> 12)
10219 /* beqz38 or bnez38 */
10220 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
10221 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNEZ
: INSN_BEQZ
;
10222 comp_insn
|= ((comp_insn16
& 0x0700) >> 8) << 20;
10226 /* beqs38 or bnes38 */
10227 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
10228 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNE
: INSN_BEQ
;
10229 comp_insn
|= (((comp_insn16
& 0x0700) >> 8) << 20)
10234 /* beqzS8 or bnezS8 */
10235 comp_insn16
= (insn16
^ 0x0100) & 0xff00;
10236 comp_insn
= (comp_insn16
& 0x0100) ? INSN_BNEZ
: INSN_BEQZ
;
10237 comp_insn
|= REG_R15
<< 20;
10244 if (comp_insn
&& re_insn
)
10245 *re_insn
= comp_insn
;
10246 if (comp_insn16
&& re_insn16
)
10247 *re_insn16
= comp_insn16
;
10250 /* Relax LONGJUMP2 relocation for nds32_elf_relax_section. */
10253 nds32_elf_relax_longjump2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10254 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10255 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10256 Elf_Internal_Shdr
*symtab_hdr
)
10258 /* There are 3 variations for LONGJUMP2
10259 case 2-4; 1st insn convertible, 16-bit on,
10260 optimize off or optimize for space
10261 bnes38 rt, ra, $1 ; LONGJUMP2
10265 case 4-4; 1st insn not convertible
10266 bne rt, ra, $1 ; LONGJUMP2
10270 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10271 bne rt, ra, $1 ; LONGJUMP2
10275 /* Get the reloc for the address from which the register is
10276 being loaded. This reloc will tell us which function is
10277 actually being called. */
10280 int seq_len
; /* Original length of instruction sequence. */
10281 Elf_Internal_Rela
*i2_irelfn
, *cond_irelfn
, *irelend
;
10284 bfd_signed_vma foff
;
10285 uint32_t insn
, re_insn
= 0;
10286 uint16_t insn16
, re_insn16
= 0;
10287 unsigned long reloc
, cond_reloc
;
10289 enum elf_nds32_reloc_type checked_types
[] =
10290 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
10292 irelend
= internal_relocs
+ sec
->reloc_count
;
10293 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10294 laddr
= irel
->r_offset
;
10295 *insn_len
= seq_len
;
10296 first_size
= (seq_len
== 6) ? 2 : 4;
10299 find_relocs_at_address_addr (irel
, internal_relocs
,
10300 irelend
, R_NDS32_25_PCREL_RELA
,
10301 laddr
+ first_size
);
10303 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10306 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10307 checked_types
[i
], laddr
);
10308 if (cond_irelfn
!= irelend
)
10312 if (i2_irelfn
== irelend
|| cond_irelfn
== irelend
)
10314 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP2",
10315 (uint64_t) irel
->r_offset
);
10319 /* Get the value of the symbol referred to by the reloc. */
10320 foff
= calculate_offset (abfd
, sec
, i2_irelfn
, isymbuf
, symtab_hdr
);
10322 || foff
< -CONSERVATIVE_16BIT_S1
10323 || foff
>= CONSERVATIVE_16BIT_S1
)
10326 /* Get the all corresponding instructions. */
10327 if (first_size
== 4)
10329 insn
= bfd_getb32 (contents
+ laddr
);
10330 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10334 insn16
= bfd_getb16 (contents
+ laddr
);
10335 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10338 if (re_insn16
&& foff
>= -(ACCURATE_8BIT_S1
- first_size
)
10339 && foff
< ACCURATE_8BIT_S1
- first_size
)
10341 if (first_size
== 4)
10343 /* Don't convert it to 16-bit now, keep this as relaxable for
10344 ``label reloc; INSN16''. */
10346 /* Save comp_insn32 to buffer. */
10347 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10349 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
10350 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
10351 cond_reloc
= R_NDS32_INSN16
;
10355 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
10357 reloc
= R_NDS32_9_PCREL_RELA
;
10358 cond_reloc
= R_NDS32_NONE
;
10361 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
10362 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
10363 && foff
< ACCURATE_14BIT_S1
- first_size
))
10365 /* beqs label ; 15_PCREL */
10366 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10368 reloc
= R_NDS32_15_PCREL_RELA
;
10369 cond_reloc
= R_NDS32_NONE
;
10371 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10372 && foff
>= -CONSERVATIVE_16BIT_S1
10373 && foff
< CONSERVATIVE_16BIT_S1
)
10375 /* beqz label ; 17_PCREL */
10376 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10378 reloc
= R_NDS32_17_PCREL_RELA
;
10379 cond_reloc
= R_NDS32_NONE
;
10384 /* Set all relocations. */
10385 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
), reloc
);
10386 irel
->r_addend
= i2_irelfn
->r_addend
;
10388 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
10390 cond_irelfn
->r_addend
= 0;
10392 if ((seq_len
^ *insn_len
) & 0x2)
10394 insn16
= NDS32_NOP16
;
10395 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ 4);
10396 i2_irelfn
->r_offset
= 4;
10397 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
10399 i2_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10403 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
10408 /* Relax LONGJUMP3 relocation for nds32_elf_relax_section. */
10411 nds32_elf_relax_longjump3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10412 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10413 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10414 Elf_Internal_Shdr
*symtab_hdr
)
10416 /* There are 5 variations for LONGJUMP3
10417 case 1: 2-4-4-2; 1st insn convertible, 16-bit on,
10418 optimize off or optimize for space
10419 bnes38 rt, ra, $1 ; LONGJUMP3
10420 sethi ta, hi20(symbol) ; HI20
10421 ori ta, ta, lo12(symbol) ; LO12S0
10425 case 2: 2-4-4-2; 1st insn convertible, 16-bit on, optimize for speed
10426 bnes38 rt, ra, $1 ; LONGJUMP3
10427 sethi ta, hi20(symbol) ; HI20
10428 ori ta, ta, lo12(symbol) ; LO12S0
10432 case 3: 4-4-4-2; 1st insn not convertible, 16-bit on,
10433 optimize off or optimize for space
10434 bne rt, ra, $1 ; LONGJUMP3
10435 sethi ta, hi20(symbol) ; HI20
10436 ori ta, ta, lo12(symbol) ; LO12S0
10440 case 4: 4-4-4-4; 1st insn don't care, 16-bit off, optimize don't care
10441 16-bit off if no INSN16
10442 bne rt, ra, $1 ; LONGJUMP3
10443 sethi ta, hi20(symbol) ; HI20
10444 ori ta, ta, lo12(symbol) ; LO12S0
10448 case 5: 4-4-4-4; 1st insn not convertible, 16-bit on, optimize for speed
10449 16-bit off if no INSN16
10450 bne rt, ra, $1 ; LONGJUMP3
10451 sethi ta, hi20(symbol) ; HI20
10452 ori ta, ta, lo12(symbol) ; LO12S0
10456 /* Get the reloc for the address from which the register is
10457 being loaded. This reloc will tell us which function is
10458 actually being called. */
10459 enum elf_nds32_reloc_type checked_types
[] =
10460 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
10462 int reloc_off
= 0, cond_removed
= 0, convertible
;
10464 int seq_len
; /* Original length of instruction sequence. */
10465 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
10468 bfd_signed_vma foff
;
10469 uint32_t insn
, re_insn
= 0;
10470 uint16_t insn16
, re_insn16
= 0;
10471 unsigned long reloc
, cond_reloc
;
10473 irelend
= internal_relocs
+ sec
->reloc_count
;
10474 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10475 laddr
= irel
->r_offset
;
10476 *insn_len
= seq_len
;
10478 convertible
= IS_1ST_CONVERT (irel
->r_addend
);
10485 /* Get all needed relocations. */
10487 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10488 R_NDS32_HI20_RELA
, laddr
+ first_size
);
10490 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10491 R_NDS32_LO12S0_ORI_RELA
,
10492 laddr
+ first_size
+ 4);
10494 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10497 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10498 checked_types
[i
], laddr
);
10499 if (cond_irelfn
!= irelend
)
10503 if (hi_irelfn
== irelend
10504 || lo_irelfn
== irelend
10505 || cond_irelfn
== irelend
)
10507 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP3",
10508 (uint64_t) irel
->r_offset
);
10512 /* Get the value of the symbol referred to by the reloc. */
10513 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
);
10516 || foff
< -CONSERVATIVE_24BIT_S1
10517 || foff
>= CONSERVATIVE_24BIT_S1
)
10520 /* Get the all corresponding instructions. */
10521 if (first_size
== 4)
10523 insn
= bfd_getb32 (contents
+ laddr
);
10524 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10528 insn16
= bfd_getb16 (contents
+ laddr
);
10529 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10532 /* For simplicity of coding, we are going to modify the section
10533 contents, the section relocs, and the BFD symbol table. We
10534 must tell the rest of the code not to free up this
10535 information. It would be possible to instead create a table
10536 of changes which have to be made, as is done in coff-mips.c;
10537 that would be more work, but would require less memory when
10538 the linker is run. */
10541 && foff
>= -ACCURATE_8BIT_S1
- first_size
10542 && foff
< ACCURATE_8BIT_S1
- first_size
)
10544 if (!(seq_len
& 0x2))
10546 /* Don't convert it to 16-bit now, keep this as relaxable
10547 for ``label reloc; INSN1a''6. */
10548 /* Save comp_insn32 to buffer. */
10549 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10551 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
10552 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
10553 cond_reloc
= R_NDS32_INSN16
;
10557 /* Not optimize for speed; convert sequence to 16-bit. */
10558 /* Save comp_insn16 to buffer. */
10559 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
10561 reloc
= R_NDS32_9_PCREL_RELA
;
10562 cond_reloc
= R_NDS32_NONE
;
10566 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
10567 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
10568 && foff
< ACCURATE_14BIT_S1
- first_size
))
10570 /* beqs label ; 15_PCREL */
10571 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10573 reloc
= R_NDS32_15_PCREL_RELA
;
10574 cond_reloc
= R_NDS32_NONE
;
10577 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10578 && foff
>= -CONSERVATIVE_16BIT_S1
10579 && foff
< CONSERVATIVE_16BIT_S1
)
10581 /* beqz label ; 17_PCREL */
10582 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
10584 reloc
= R_NDS32_17_PCREL_RELA
;
10585 cond_reloc
= R_NDS32_NONE
;
10588 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
10589 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
10591 /* Relax to one of the following 3 variations
10593 case 2-4; 1st insn convertible, 16-bit on, optimize off or optimize
10595 bnes38 rt, $1 ; LONGJUMP2
10599 case 4-4; 1st insn not convertible, others don't care
10600 bne rt, ra, $1 ; LONGJUMP2
10604 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
10605 bne rt, ra, $1 ; LONGJUMP2
10609 /* Offset for first instruction. */
10611 /* Use j label as second instruction. */
10612 *insn_len
= 4 + first_size
;
10614 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
10615 reloc
= R_NDS32_LONGJUMP2
;
10616 cond_reloc
= R_NDS32_25_PLTREL
;
10621 if (cond_removed
== 1)
10623 /* Set all relocations. */
10624 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
10625 irel
->r_addend
= hi_irelfn
->r_addend
;
10627 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
10629 cond_irelfn
->r_addend
= 0;
10630 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10635 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10636 irel
->r_addend
= irel
->r_addend
;
10637 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
10641 if ((seq_len
^ *insn_len
) & 0x2)
10643 insn16
= NDS32_NOP16
;
10644 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
10645 lo_irelfn
->r_offset
= *insn_len
;
10646 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10648 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10652 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
10657 /* Relax LONGCALL4 relocation for nds32_elf_relax_section. */
10660 nds32_elf_relax_longcall4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10661 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10662 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10663 Elf_Internal_Shdr
*symtab_hdr
)
10665 /* The pattern for LONGCALL4. Support for function cse.
10666 sethi ta, hi20(symbol) ; LONGCALL4/HI20
10667 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10668 jral ta ; PTR_RES/EMPTY/INSN16 */
10672 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *insn_irel
, *em_irel
, *call_irel
;
10673 Elf_Internal_Rela
*irelend
;
10674 bfd_signed_vma foff
;
10676 irelend
= internal_relocs
+ sec
->reloc_count
;
10677 laddr
= irel
->r_offset
;
10679 /* Get the reloc for the address from which the register is
10680 being loaded. This reloc will tell us which function is
10681 actually being called. */
10682 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10683 R_NDS32_HI20_RELA
, laddr
);
10685 if (hi_irel
== irelend
)
10687 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
10688 (uint64_t) irel
->r_offset
);
10692 /* Get the value of the symbol referred to by the reloc. */
10693 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
);
10695 /* This condition only happened when symbol is undefined. */
10697 || foff
< -CONSERVATIVE_24BIT_S1
10698 || foff
>= CONSERVATIVE_24BIT_S1
)
10701 /* Relax to: jal symbol; 25_PCREL. */
10702 /* For simplicity of coding, we are going to modify the section
10703 contents, the section relocs, and the BFD symbol table. We
10704 must tell the rest of the code not to free up this
10705 information. It would be possible to instead create a table
10706 of changes which have to be made, as is done in coff-mips.c;
10707 that would be more work, but would require less memory when
10708 the linker is run. */
10710 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10711 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10712 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10713 R_NDS32_EMPTY
, irel
->r_addend
);
10715 if (ptr_irel
== irelend
|| em_irel
== irelend
)
10717 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
10718 (uint64_t) irel
->r_offset
);
10721 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10722 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10723 if (insn
& 0x80000000)
10726 /* Replace the long call with a jal. */
10727 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
10728 R_NDS32_25_PCREL_RELA
);
10729 ptr_irel
->r_addend
= 1;
10731 /* We don't resolve this here but resolve it in relocate_section. */
10733 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10736 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10738 /* If there is function cse, HI20 can not remove now. */
10739 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10740 R_NDS32_LONGCALL4
, laddr
);
10741 if (call_irel
== irelend
)
10745 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
10748 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10749 R_NDS32_INSN16
, irel
->r_addend
);
10750 if (insn_irel
!= irelend
)
10751 insn_irel
->r_info
=
10752 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10757 /* Relax LONGCALL5 relocation for nds32_elf_relax_section. */
10760 nds32_elf_relax_longcall5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10761 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10762 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10763 Elf_Internal_Shdr
*symtab_hdr
)
10765 /* The pattern for LONGCALL5.
10766 bltz rt, .L1 ; LONGCALL5/17_PCREL
10767 jal symbol ; 25_PCREL
10772 Elf_Internal_Rela
*cond_irel
, *irelend
;
10773 bfd_signed_vma foff
;
10775 irelend
= internal_relocs
+ sec
->reloc_count
;
10776 laddr
= irel
->r_offset
;
10777 insn
= bfd_getb32 (contents
+ laddr
);
10779 /* Get the reloc for the address from which the register is
10780 being loaded. This reloc will tell us which function is
10781 actually being called. */
10783 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10784 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
10785 if (cond_irel
== irelend
)
10787 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL5",
10788 (uint64_t) irel
->r_offset
);
10792 /* Get the value of the symbol referred to by the reloc. */
10793 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
10796 || foff
< -CONSERVATIVE_16BIT_S1
10797 || foff
>= CONSERVATIVE_16BIT_S1
)
10800 /* Relax to bgezal rt, label ; 17_PCREL
10801 or bltzal rt, label ; 17_PCREL. */
10803 /* Convert to complimentary conditional call. */
10804 insn
= CONVERT_CONDITION_CALL (insn
);
10806 /* For simplicity of coding, we are going to modify the section
10807 contents, the section relocs, and the BFD symbol table. We
10808 must tell the rest of the code not to free up this
10809 information. It would be possible to instead create a table
10810 of changes which have to be made, as is done in coff-mips.c;
10811 that would be more work, but would require less memory when
10812 the linker is run. */
10814 /* Modify relocation and contents. */
10815 cond_irel
->r_info
=
10816 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
10818 /* Replace the long call with a bgezal. */
10819 bfd_putb32 (insn
, contents
+ cond_irel
->r_offset
);
10822 /* Clean unnessary relocations. */
10823 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10825 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10826 R_NDS32_17_PCREL_RELA
, laddr
);
10827 cond_irel
->r_info
=
10828 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10833 /* Relax LONGCALL6 relocation for nds32_elf_relax_section. */
10836 nds32_elf_relax_longcall6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10837 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10838 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10839 Elf_Internal_Shdr
*symtab_hdr
)
10841 /* The pattern for LONGCALL6.
10842 bltz rt, .L1 ; LONGCALL6/17_PCREL
10843 sethi ta, hi20(symbol) ; HI20/PTR
10844 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10845 jral ta ; PTR_RES/EMPTY/INSN16
10850 Elf_Internal_Rela
*em_irel
, *cond_irel
, *irelend
;
10851 bfd_signed_vma foff
;
10853 irelend
= internal_relocs
+ sec
->reloc_count
;
10854 laddr
= irel
->r_offset
;
10856 /* Get the reloc for the address from which the register is
10857 being loaded. This reloc will tell us which function is
10858 actually being called. */
10859 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10860 R_NDS32_EMPTY
, irel
->r_addend
);
10862 if (em_irel
== irelend
)
10864 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL6",
10865 (uint64_t) irel
->r_offset
);
10869 /* Get the value of the symbol referred to by the reloc. */
10870 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
);
10873 || foff
< -CONSERVATIVE_24BIT_S1
10874 || foff
>= CONSERVATIVE_24BIT_S1
)
10877 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
10878 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10879 if (insn
& 0x80000000)
10882 insn
= bfd_getb32 (contents
+ laddr
);
10883 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10885 /* Relax to bgezal rt, label ; 17_PCREL
10886 or bltzal rt, label ; 17_PCREL. */
10888 /* Convert to complimentary conditional call. */
10890 insn
= CONVERT_CONDITION_CALL (insn
);
10891 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10894 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
10896 /* Set resolved relocation. */
10898 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10899 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10900 if (cond_irel
== irelend
)
10902 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
10903 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
10906 cond_irel
->r_addend
= 1;
10908 /* Clear relocations. */
10911 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10914 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10915 R_NDS32_17_PCREL_RELA
, laddr
);
10916 if (cond_irel
!= irelend
)
10917 cond_irel
->r_info
=
10918 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10921 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10922 R_NDS32_INSN16
, irel
->r_addend
);
10923 if (cond_irel
!= irelend
)
10924 cond_irel
->r_info
=
10925 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10928 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
10930 /* Relax to the following instruction sequence
10931 bltz rt, .L1 ; LONGCALL2/17_PCREL
10932 jal symbol ; 25_PCREL/PTR_RES
10935 /* Convert instruction. */
10937 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10939 /* Convert relocations. */
10940 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
10941 R_NDS32_25_PCREL_RELA
);
10943 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL5
);
10945 /* Set resolved relocation. */
10947 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10948 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10949 if (cond_irel
== irelend
)
10951 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
10952 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
10955 cond_irel
->r_addend
= 1;
10958 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10959 R_NDS32_INSN16
, irel
->r_addend
);
10960 if (cond_irel
!= irelend
)
10961 cond_irel
->r_info
=
10962 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10967 /* Relax LONGJUMP4 relocation for nds32_elf_relax_section. */
10970 nds32_elf_relax_longjump4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10971 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10972 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10973 Elf_Internal_Shdr
*symtab_hdr
)
10975 /* The pattern for LONGJUMP4.
10976 sethi ta, hi20(symbol) ; LONGJUMP4/HI20
10977 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10978 jr ta ; PTR_RES/INSN16/EMPTY */
10981 int seq_len
; /* Original length of instruction sequence. */
10983 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *em_irel
, *call_irel
, *irelend
;
10984 bfd_signed_vma foff
;
10986 irelend
= internal_relocs
+ sec
->reloc_count
;
10987 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10988 laddr
= irel
->r_offset
;
10989 *insn_len
= seq_len
;
10991 /* Get the reloc for the address from which the register is
10992 being loaded. This reloc will tell us which function is
10993 actually being called. */
10995 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10996 R_NDS32_HI20_RELA
, laddr
);
10998 if (hi_irel
== irelend
)
11000 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
11001 (uint64_t) irel
->r_offset
);
11005 /* Get the value of the symbol referred to by the reloc. */
11006 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
);
11009 || foff
>= CONSERVATIVE_24BIT_S1
11010 || foff
< -CONSERVATIVE_24BIT_S1
)
11013 /* Convert it to "j label", it may be converted to j8 in the final
11014 pass of relaxation. Therefore, we do not consider this currently. */
11015 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11016 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11017 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11018 R_NDS32_EMPTY
, irel
->r_addend
);
11020 if (ptr_irel
== irelend
|| em_irel
== irelend
)
11022 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
11023 (uint64_t) irel
->r_offset
);
11028 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_25_PCREL_RELA
);
11029 ptr_irel
->r_addend
= 1;
11031 /* Write instruction. */
11033 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
11035 /* Clear relocations. */
11036 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11038 /* If there is function cse, HI20 can not remove now. */
11039 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11040 R_NDS32_LONGJUMP4
, laddr
);
11041 if (call_irel
== irelend
)
11045 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
11051 /* Relax LONGJUMP5 relocation for nds32_elf_relax_section. */
11054 nds32_elf_relax_longjump5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11055 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11056 int *seq_len
, bfd_byte
*contents
,
11057 Elf_Internal_Sym
*isymbuf
,
11058 Elf_Internal_Shdr
*symtab_hdr
)
11060 /* There are 2 variations for LONGJUMP5
11061 case 2-4; 1st insn convertible, 16-bit on.
11062 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11063 j label ; 25_PCREL/INSN16
11066 case 4-4; 1st insn not convertible
11067 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11068 j label ; 25_PCREL/INSN16
11072 Elf_Internal_Rela
*cond_irel
, *irelend
;
11074 bfd_signed_vma foff
;
11075 uint32_t insn
, re_insn
= 0;
11076 uint16_t insn16
, re_insn16
= 0;
11077 unsigned long reloc
;
11079 enum elf_nds32_reloc_type checked_types
[] =
11080 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
11081 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
11083 irelend
= internal_relocs
+ sec
->reloc_count
;
11084 laddr
= irel
->r_offset
;
11086 /* Get the reloc for the address from which the register is
11087 being loaded. This reloc will tell us which function is
11088 actually being called. */
11091 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11092 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
11093 if (cond_irel
== irelend
)
11095 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP5",
11096 (uint64_t) irel
->r_offset
);
11100 /* Get the value of the symbol referred to by the reloc. */
11101 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
11104 || foff
< -CONSERVATIVE_16BIT_S1
11105 || foff
>= CONSERVATIVE_16BIT_S1
)
11108 /* Get the all corresponding instructions. */
11109 insn
= bfd_getb32 (contents
+ laddr
);
11110 /* Check instruction size. */
11111 if (insn
& 0x80000000)
11114 insn16
= insn
>> 16;
11115 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
11118 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
11120 if (N32_OP6 (re_insn
) == N32_OP6_BR1
11121 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
11123 /* beqs label ; 15_PCREL. */
11124 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11125 reloc
= R_NDS32_15_PCREL_RELA
;
11127 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
11128 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
11130 /* beqz label ; 17_PCREL. */
11131 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11132 reloc
= R_NDS32_17_PCREL_RELA
;
11134 else if ( N32_OP6 (re_insn
) == N32_OP6_BR3
11135 && foff
>= -CONSERVATIVE_8BIT_S1
&& foff
< CONSERVATIVE_8BIT_S1
)
11137 /* beqc label ; 9_PCREL. */
11138 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11139 reloc
= R_NDS32_WORD_9_PCREL_RELA
;
11144 /* Set all relocations. */
11145 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), reloc
);
11147 /* Clean relocations. */
11148 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11149 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11151 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11152 checked_types
[i
], laddr
);
11153 if (cond_irel
!= irelend
)
11156 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
11158 /* If the branch instruction is 2 byte, it cannot remove
11159 directly. Only convert it to nop16 and remove it after
11160 checking alignment issue. */
11161 insn16
= NDS32_NOP16
;
11162 bfd_putb16 (insn16
, contents
+ laddr
);
11163 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11166 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11175 /* Relax LONGJUMP6 relocation for nds32_elf_relax_section. */
11178 nds32_elf_relax_longjump6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11179 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11180 int *seq_len
, bfd_byte
*contents
,
11181 Elf_Internal_Sym
*isymbuf
,
11182 Elf_Internal_Shdr
*symtab_hdr
)
11184 /* There are 5 variations for LONGJUMP6
11185 case : 2-4-4-4; 1st insn convertible, 16-bit on.
11186 bnes38 rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11187 sethi ta, hi20(symbol) ; HI20/PTR
11188 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11189 jr ta ; PTR_RES/INSN16/EMPTY
11192 case : 4-4-4-4; 1st insn not convertible, 16-bit on.
11193 bne rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
11194 sethi ta, hi20(symbol) ; HI20/PTR
11195 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
11196 jr ta ; PTR_RES/INSN16/EMPTY
11199 enum elf_nds32_reloc_type checked_types
[] =
11200 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
11201 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
11203 int reloc_off
= 0, cond_removed
= 0;
11205 Elf_Internal_Rela
*cond_irel
, *em_irel
, *irelend
, *insn_irel
;
11207 bfd_signed_vma foff
;
11208 uint32_t insn
, re_insn
= 0;
11209 uint16_t insn16
, re_insn16
= 0;
11210 unsigned long reloc
;
11212 irelend
= internal_relocs
+ sec
->reloc_count
;
11213 laddr
= irel
->r_offset
;
11215 /* Get the reloc for the address from which the register is
11216 being loaded. This reloc will tell us which function is
11217 actually being called. */
11218 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11219 R_NDS32_EMPTY
, irel
->r_addend
);
11221 if (em_irel
== irelend
)
11223 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP6",
11224 (uint64_t) irel
->r_offset
);
11228 /* Get the value of the symbol referred to by the reloc. */
11229 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
);
11232 || foff
< -CONSERVATIVE_24BIT_S1
11233 || foff
>= CONSERVATIVE_24BIT_S1
)
11236 insn
= bfd_getb32 (contents
+ laddr
);
11237 /* Check instruction size. */
11238 if (insn
& 0x80000000)
11241 insn16
= insn
>> 16;
11242 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
11245 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
11247 /* For simplicity of coding, we are going to modify the section
11248 contents, the section relocs, and the BFD symbol table. We
11249 must tell the rest of the code not to free up this
11250 information. It would be possible to instead create a table
11251 of changes which have to be made, as is done in coff-mips.c;
11252 that would be more work, but would require less memory when
11253 the linker is run. */
11255 if (N32_OP6 (re_insn
) == N32_OP6_BR1
11256 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
11258 /* beqs label ; 15_PCREL. */
11259 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
11260 reloc
= R_NDS32_15_PCREL_RELA
;
11263 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
11264 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
11266 /* beqz label ; 17_PCREL. */
11267 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
11268 reloc
= R_NDS32_17_PCREL_RELA
;
11271 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
11272 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
11274 /* Relax to one of the following 2 variations
11276 case 2-4; 1st insn convertible, 16-bit on.
11277 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
11278 j label ; 25_PCREL/INSN16
11281 case 4-4; 1st insn not convertible
11282 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
11283 j label ; 25_PCREL/INSN16
11286 /* Use j label as second instruction. */
11288 reloc
= R_NDS32_25_PCREL_RELA
;
11289 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
11294 /* Set all relocations. */
11295 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), reloc
);
11298 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11299 R_NDS32_PTR_RESOLVED
, em_irel
->r_offset
);
11300 cond_irel
->r_addend
= 1;
11302 /* Use INSN16 of first branch instruction to distinguish if keeping
11303 INSN16 of final instruction or not. */
11304 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11305 R_NDS32_INSN16
, irel
->r_offset
);
11306 if (insn_irel
== irelend
)
11308 /* Clean the final INSN16. */
11310 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11311 R_NDS32_INSN16
, em_irel
->r_offset
);
11312 insn_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11316 if (cond_removed
== 1)
11320 /* Clear relocations. */
11321 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11323 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11326 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11327 checked_types
[i
], laddr
);
11328 if (cond_irel
!= irelend
)
11331 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
11333 /* If the branch instruction is 2 byte, it cannot remove
11334 directly. Only convert it to nop16 and remove it after
11335 checking alignment issue. */
11336 insn16
= NDS32_NOP16
;
11337 bfd_putb16 (insn16
, contents
+ laddr
);
11338 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11341 cond_irel
->r_info
=
11342 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
11348 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11349 R_NDS32_LONGJUMP5
);
11355 /* Relax LONGJUMP7 relocation for nds32_elf_relax_section. */
11358 nds32_elf_relax_longjump7 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11359 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11360 int *seq_len
, bfd_byte
*contents
,
11361 Elf_Internal_Sym
*isymbuf
,
11362 Elf_Internal_Shdr
*symtab_hdr
)
11364 /* There are 2 variations for LONGJUMP5
11365 case 2-4; 1st insn convertible, 16-bit on.
11366 movi55 ta, imm11 ; LONGJUMP7/INSN16
11367 beq rt, ta, label ; 15_PCREL
11369 case 4-4; 1st insn not convertible
11370 movi55 ta, imm11 ; LONGJUMP7/INSN16
11371 beq rt, ta, label ; 15_PCREL */
11374 Elf_Internal_Rela
*cond_irel
, *irelend
, *insn_irel
;
11375 bfd_signed_vma foff
;
11376 uint32_t insn
, re_insn
= 0;
11380 irelend
= internal_relocs
+ sec
->reloc_count
;
11381 laddr
= irel
->r_offset
;
11383 /* Get the reloc for the address from which the register is
11384 being loaded. This reloc will tell us which function is
11385 actually being called. */
11388 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11389 R_NDS32_15_PCREL_RELA
, irel
->r_addend
);
11390 if (cond_irel
== irelend
)
11392 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP7",
11393 (uint64_t) irel
->r_offset
);
11397 /* Get the value of the symbol referred to by the reloc. */
11398 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
);
11401 || foff
< -CONSERVATIVE_8BIT_S1
11402 || foff
>= CONSERVATIVE_8BIT_S1
)
11405 /* Get the first instruction for its size. */
11406 insn
= bfd_getb32 (contents
+ laddr
);
11407 if (insn
& 0x80000000)
11410 /* Get the immediate from movi55. */
11411 imm11
= N16_IMM5S (insn
>> 16);
11415 /* Get the immediate from movi. */
11416 imm11
= N32_IMM20S (insn
);
11419 /* Get the branch instruction. */
11420 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
11421 /* Convert instruction to BR3. */
11422 if ((insn
>> 14) & 0x1)
11423 re_insn
= N32_BR3 (BNEC
, N32_RT5 (insn
), imm11
, 0);
11425 re_insn
= N32_BR3 (BEQC
, N32_RT5 (insn
), imm11
, 0);
11427 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
11429 /* Set all relocations. */
11430 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11431 R_NDS32_WORD_9_PCREL_RELA
);
11433 /* Clean relocations. */
11434 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11435 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11436 R_NDS32_INSN16
, irel
->r_offset
);
11437 if (insn_irel
!= irelend
)
11441 /* If the first insntruction is 16bit, convert it to nop16. */
11442 insn16
= NDS32_NOP16
;
11443 bfd_putb16 (insn16
, contents
+ laddr
);
11444 insn_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
11447 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
11455 /* We figure out and reassign the best gp value in nds32_elf_final_sda_base
11456 for each relax round. But the gp may changed dramatically and then cause
11457 the truncated to fit errors for the the converted gp instructions.
11458 Therefore, we must reserve the minimum but safe enough size to prevent it. */
11461 nds32_elf_relax_guard (bfd_vma
*access_addr
, bfd_vma local_sda
, asection
*sec
,
11462 Elf_Internal_Rela
*irel
, bfd_boolean
*again
,
11464 struct elf_nds32_link_hash_table
*table
,
11465 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
11469 static bfd_boolean sec_pass
= FALSE
;
11470 static asection
*first_sec
= NULL
, *sym_sec
;
11471 /* Record the number of instructions which may be removed. */
11472 static int count
= 0, record_count
;
11473 Elf_Internal_Sym
*isym
;
11474 struct elf_link_hash_entry
*h
= NULL
;
11476 unsigned long r_symndx
;
11477 bfd
*abfd
= sec
->owner
;
11478 static bfd_vma record_sda
= 0;
11479 int sda_offset
= 0;
11481 /* Force doing relaxation when hyper-relax is high. */
11482 if (table
->hyper_relax
== 2)
11485 /* Do not relax the load/store patterns for the first
11491 else if (first_sec
== sec
)
11493 record_count
= count
;
11504 /* Generally, _SDA_BASE_ is fixed or smaller. But the large
11505 DATA_SEGMENT_ALIGN size in the linker script may make it
11506 get even bigger. */
11507 if (record_sda
== 0)
11508 record_sda
= local_sda
;
11509 else if (local_sda
> record_sda
)
11510 sda_offset
= local_sda
- record_sda
;
11512 /* Assume the instruction will be removed in the best case. */
11515 /* We record the offset to gp for each symbol, and then check
11516 if it is changed dramatically after relaxing.
11517 (global symbol): elf32_nds32_hash_entry (h)->offset_to_gp
11518 (local symbol) : elf32_nds32_local_gp_offset (abfd)[r_symndx]. */
11519 r_symndx
= ELF32_R_SYM (irel
->r_info
);
11520 if (r_symndx
>= symtab_hdr
->sh_info
)
11522 /* Global symbols. */
11523 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
11524 h
= elf_sym_hashes (abfd
)[indx
];
11525 sym_sec
= h
->root
.u
.def
.section
;
11526 if (NDS32_GUARD_SEC_P (sym_sec
->flags
)
11527 || bfd_is_abs_section (sym_sec
))
11529 /* Forbid doing relaxation when hyper-relax is low. */
11530 if (table
->hyper_relax
== 0)
11533 offset_to_gp
= *access_addr
- local_sda
;
11534 if (elf32_nds32_hash_entry (h
)->offset_to_gp
== 0)
11535 elf32_nds32_hash_entry (h
)->offset_to_gp
= offset_to_gp
;
11536 else if (abs (elf32_nds32_hash_entry (h
)->offset_to_gp
)
11537 < abs (offset_to_gp
) - sda_offset
)
11539 /* This may cause the error, so we reserve the
11540 safe enough size for relaxing. */
11541 if (*access_addr
>= local_sda
)
11542 *access_addr
+= (record_count
* 4);
11544 *access_addr
-= (record_count
* 4);
11551 /* Local symbols. */
11552 if (!elf32_nds32_allocate_local_sym_info (abfd
))
11554 isym
= isymbuf
+ r_symndx
;
11556 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
11557 if (NDS32_GUARD_SEC_P (sym_sec
->flags
))
11559 /* Forbid doing relaxation when hyper-relax is low. */
11560 if (table
->hyper_relax
== 0)
11563 offset_to_gp
= *access_addr
- local_sda
;
11564 if (elf32_nds32_local_gp_offset (abfd
)[r_symndx
] == 0)
11565 elf32_nds32_local_gp_offset (abfd
)[r_symndx
] = offset_to_gp
;
11566 else if (abs (elf32_nds32_local_gp_offset (abfd
)[r_symndx
])
11567 < abs (offset_to_gp
) - sda_offset
)
11569 /* This may cause the error, so we reserve the
11570 safe enough size for relaxing. */
11571 if (*access_addr
>= local_sda
)
11572 *access_addr
+= (record_count
* 4);
11574 *access_addr
-= (record_count
* 4);
11583 #define GET_LOADSTORE_RANGE(addend) (((addend) >> 8) & 0x3f)
11585 /* Relax LOADSTORE relocation for nds32_elf_relax_section. */
11588 nds32_elf_relax_loadstore (struct bfd_link_info
*link_info
, bfd
*abfd
,
11589 asection
*sec
, Elf_Internal_Rela
*irel
,
11590 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11591 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11592 Elf_Internal_Shdr
*symtab_hdr
, int load_store_relax
,
11593 struct elf_nds32_link_hash_table
*table
)
11595 int eliminate_sethi
= 0, range_type
;
11597 bfd_vma local_sda
, laddr
;
11598 int seq_len
; /* Original length of instruction sequence. */
11600 Elf_Internal_Rela
*hi_irelfn
= NULL
, *irelend
;
11601 bfd_vma access_addr
= 0;
11602 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11603 struct elf_link_hash_entry
*h
= NULL
;
11605 enum elf_nds32_reloc_type checked_types
[] =
11606 { R_NDS32_HI20_RELA
, R_NDS32_GOT_HI20
,
11607 R_NDS32_GOTPC_HI20
, R_NDS32_GOTOFF_HI20
,
11608 R_NDS32_PLTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
,
11609 R_NDS32_TLS_LE_HI20
11612 irelend
= internal_relocs
+ sec
->reloc_count
;
11613 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
11614 laddr
= irel
->r_offset
;
11615 *insn_len
= seq_len
;
11617 /* Get the high part relocation. */
11618 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
11620 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11621 checked_types
[i
], laddr
);
11622 if (hi_irelfn
!= irelend
)
11626 if (hi_irelfn
== irelend
)
11628 /* Not R_NDS32_HI20_RELA. */
11630 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LOADSTORE",
11631 (uint64_t) irel
->r_offset
);
11635 range_type
= GET_LOADSTORE_RANGE (irel
->r_addend
);
11636 nds32_elf_final_sda_base (sec
->output_section
->owner
,
11637 link_info
, &local_sda
, FALSE
);
11639 switch (ELF32_R_TYPE (hi_irelfn
->r_info
))
11641 case R_NDS32_HI20_RELA
:
11642 insn
= bfd_getb32 (contents
+ laddr
);
11644 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
11646 if (ELF32_R_SYM (hi_irelfn
->r_info
) >= symtab_hdr
->sh_info
)
11648 indx
= ELF32_R_SYM (hi_irelfn
->r_info
) - symtab_hdr
->sh_info
;
11649 h
= elf_sym_hashes (abfd
)[indx
];
11653 if (range_type
== NDS32_LOADSTORE_IMM
11654 && access_addr
< CONSERVATIVE_20BIT
11655 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
11657 eliminate_sethi
= 1;
11661 if (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0)
11663 eliminate_sethi
= 1;
11666 else if (!nds32_elf_relax_guard (&access_addr
, local_sda
, sec
, hi_irelfn
,
11667 NULL
, FALSE
, table
, isymbuf
, symtab_hdr
))
11670 if (!load_store_relax
)
11673 /* Case for set gp register. */
11674 if (N32_RT5 (insn
) == REG_GP
)
11677 if (range_type
== NDS32_LOADSTORE_FLOAT_S
11678 || range_type
== NDS32_LOADSTORE_FLOAT_D
)
11680 range_l
= sdata_range
[0][0];
11681 range_h
= sdata_range
[0][1];
11685 range_l
= sdata_range
[1][0];
11686 range_h
= sdata_range
[1][1];
11694 /* Delete sethi instruction. */
11695 if (eliminate_sethi
== 1
11696 || (local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11697 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
11699 hi_irelfn
->r_info
=
11700 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
11702 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11710 /* Relax LO12 relocation for nds32_elf_relax_section. */
11713 nds32_elf_relax_lo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
11714 asection
*sec
, Elf_Internal_Rela
*irel
,
11715 Elf_Internal_Rela
*internal_relocs
, bfd_byte
*contents
,
11716 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
,
11717 struct elf_nds32_link_hash_table
*table
)
11720 bfd_vma local_sda
, laddr
;
11721 unsigned long reloc
;
11722 bfd_vma access_addr
;
11723 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11724 Elf_Internal_Rela
*irelfn
= NULL
, *irelend
;
11725 struct elf_link_hash_entry
*h
= NULL
;
11728 /* For SDA base relative relaxation. */
11729 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11730 &local_sda
, FALSE
);
11732 irelend
= internal_relocs
+ sec
->reloc_count
;
11733 laddr
= irel
->r_offset
;
11734 insn
= bfd_getb32 (contents
+ laddr
);
11736 if (!is_sda_access_insn (insn
) && N32_OP6 (insn
) != N32_OP6_ORI
)
11739 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11741 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
11743 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
11744 h
= elf_sym_hashes (abfd
)[indx
];
11748 if (N32_OP6 (insn
) == N32_OP6_ORI
&& access_addr
< CONSERVATIVE_20BIT
11749 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
11751 reloc
= R_NDS32_20_RELA
;
11752 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11753 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
11754 bfd_putb32 (insn
, contents
+ laddr
);
11758 if (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0)
11760 /* Fall through. */
11762 else if (!nds32_elf_relax_guard (&access_addr
, local_sda
, sec
, irel
, NULL
,
11763 FALSE
, table
, isymbuf
, symtab_hdr
))
11766 range_l
= sdata_range
[1][0];
11767 range_h
= sdata_range
[1][1];
11768 switch (ELF32_R_TYPE (irel
->r_info
))
11770 case R_NDS32_LO12S0_RELA
:
11771 reloc
= R_NDS32_SDA19S0_RELA
;
11773 case R_NDS32_LO12S1_RELA
:
11774 reloc
= R_NDS32_SDA18S1_RELA
;
11776 case R_NDS32_LO12S2_RELA
:
11777 reloc
= R_NDS32_SDA17S2_RELA
;
11779 case R_NDS32_LO12S2_DP_RELA
:
11780 range_l
= sdata_range
[0][0];
11781 range_h
= sdata_range
[0][1];
11782 reloc
= R_NDS32_SDA12S2_DP_RELA
;
11784 case R_NDS32_LO12S2_SP_RELA
:
11785 range_l
= sdata_range
[0][0];
11786 range_h
= sdata_range
[0][1];
11787 reloc
= R_NDS32_SDA12S2_SP_RELA
;
11793 /* There are range_h and range_l because linker has to promise
11794 all sections move cross one page together. */
11795 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11796 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
)
11797 || (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) == 0))
11799 if (N32_OP6 (insn
) == N32_OP6_ORI
&& N32_RT5 (insn
) == REG_GP
)
11801 /* Maybe we should add R_NDS32_INSN16 reloc type here
11802 or manually do some optimization. sethi can't be
11803 eliminated when updating $gp so the relative ori
11804 needs to be preserved. */
11807 if (!turn_insn_to_sda_access (insn
, ELF32_R_TYPE (irel
->r_info
),
11810 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11811 bfd_putb32 (insn
, contents
+ laddr
);
11813 irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11815 /* SDA17 must keep INSN16 for converting fp_as_gp. */
11816 if (irelfn
!= irelend
&& reloc
!= R_NDS32_SDA17S2_RELA
)
11818 ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_NDS32_NONE
);
11825 /* Relax PTR relocation for nds32_elf_relax_section. */
11828 nds32_elf_relax_ptr (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11829 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11830 int *seq_len
, bfd_byte
*contents
)
11832 Elf_Internal_Rela
*ptr_irel
, *irelend
, *count_irel
, *re_irel
;
11834 irelend
= internal_relocs
+ sec
->reloc_count
;
11837 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11838 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11840 if (re_irel
== irelend
)
11842 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_PTR",
11843 (uint64_t) irel
->r_offset
);
11847 if (re_irel
->r_addend
!= 1)
11850 /* Pointed target is relaxed and no longer needs this void *,
11851 change the type to NONE. */
11852 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11854 /* Find PTR_COUNT to decide remove it or not. If PTR_COUNT does
11855 not exist, it means only count 1 and remove it directly. */
11856 /* TODO: I hope we can obsolate R_NDS32_COUNT in the future. */
11857 count_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11858 R_NDS32_PTR_COUNT
);
11859 ptr_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11861 if (count_irel
!= irelend
)
11863 if (--count_irel
->r_addend
> 0)
11867 if (ptr_irel
!= irelend
)
11870 /* If the PTR_COUNT is already 0, remove current instruction. */
11871 *seq_len
= nds32_elf_insn_size (abfd
, contents
, irel
->r_offset
);
11876 /* Relax LWC relocation for nds32_elf_relax_section. */
11879 nds32_elf_relax_flsi (struct bfd_link_info
*link_info
, bfd
*abfd
,
11880 asection
*sec
, Elf_Internal_Rela
*irel
,
11881 Elf_Internal_Rela
*internal_relocs
,
11882 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11883 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11886 sethi ra, hi20(symbol) ; HI20/LOADSTORE
11887 ori ra, ra, lo12(symbol) ; LO12S0/PTR/PTR/.../INSN16
11888 flsi fsa, [ra + offset1] ; LSI/PTR_RESOLVED/INSN16
11889 flsi fsb, [ra + offset2] ; LSI/PTR_RESOLVED/INSN16
11893 bfd_vma local_sda
, laddr
;
11894 unsigned long reloc
;
11895 bfd_vma access_addr
, flsi_offset
;
11896 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
11897 Elf_Internal_Rela
*irelend
, *re_irel
;
11898 unsigned int opcode
;
11900 irelend
= internal_relocs
+ sec
->reloc_count
;
11901 laddr
= irel
->r_offset
;
11902 insn
= bfd_getb32 (contents
+ laddr
);
11904 if ((insn
& 0x80000000) || !is_sda_access_insn (insn
))
11907 /* Can not do relaxation for bi format. */
11908 if ((insn
& 0x1000))
11911 /* Only deal with flsi, fssi, fldi, fsdi, so far. */
11912 opcode
= N32_OP6 (insn
);
11913 if ((opcode
== N32_OP6_LWC
) || (opcode
== N32_OP6_SWC
))
11914 reloc
= R_NDS32_SDA12S2_SP_RELA
;
11915 else if ((opcode
== N32_OP6_LDC
) || (opcode
== N32_OP6_SDC
))
11916 reloc
= R_NDS32_SDA12S2_DP_RELA
;
11920 re_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11921 R_NDS32_PTR_RESOLVED
);
11922 if (re_irel
== irelend
)
11924 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LSI",
11925 (uint64_t) irel
->r_offset
);
11929 /* For SDA base relative relaxation. */
11930 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11931 &local_sda
, FALSE
);
11932 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11933 flsi_offset
= (insn
& 0xfff) << 2;
11934 access_addr
+= flsi_offset
;
11935 range_l
= sdata_range
[0][0];
11936 range_h
= sdata_range
[0][1];
11938 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
11939 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
11941 /* Turn flsi instruction into sda access format. */
11942 insn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
11944 /* Add relocation type to flsi. */
11945 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
11946 irel
->r_addend
+= flsi_offset
;
11947 bfd_putb32 (insn
, contents
+ re_irel
->r_offset
);
11949 re_irel
->r_addend
|= 1;
11955 nds32_relax_adjust_label (bfd
*abfd
, asection
*sec
,
11956 Elf_Internal_Rela
*internal_relocs
,
11957 bfd_byte
*contents
,
11958 nds32_elf_blank_t
**relax_blank_list
,
11959 int optimize
, int opt_size
)
11961 /* This code block is used to adjust 4-byte alignment by relax a pair
11962 of instruction a time.
11964 It recognizes three types of relocations.
11965 1. R_NDS32_LABEL - a alignment.
11966 2. R_NDS32_INSN16 - relax a 32-bit instruction to 16-bit.
11967 3. is_16bit_NOP () - remove a 16-bit instruction. */
11969 /* TODO: It seems currently implementation only support 4-byte alignment.
11970 We should handle any-alignment. */
11972 Elf_Internal_Rela
*insn_rel
= NULL
, *label_rel
= NULL
, *irel
;
11973 Elf_Internal_Rela
*tmp_rel
, *tmp2_rel
= NULL
;
11974 Elf_Internal_Rela rel_temp
;
11975 Elf_Internal_Rela
*irelend
;
11979 /* Checking for branch relaxation relies on the relocations to
11980 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
11981 nds32_insertion_sort (internal_relocs
, sec
->reloc_count
,
11982 sizeof (Elf_Internal_Rela
), compar_reloc
);
11984 irelend
= internal_relocs
+ sec
->reloc_count
;
11986 /* Force R_NDS32_LABEL before R_NDS32_INSN16. */
11987 /* FIXME: Can we generate the right order in assembler?
11988 So we don't have to swapping them here. */
11990 for (label_rel
= internal_relocs
, insn_rel
= internal_relocs
;
11991 label_rel
< irelend
; label_rel
++)
11993 if (ELF32_R_TYPE (label_rel
->r_info
) != R_NDS32_LABEL
)
11996 /* Find the first reloc has the same offset with label_rel. */
11997 while (insn_rel
< irelend
&& insn_rel
->r_offset
< label_rel
->r_offset
)
12000 for (;insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
;
12002 /* Check if there were R_NDS32_INSN16 and R_NDS32_LABEL at the same
12004 if (ELF32_R_TYPE (insn_rel
->r_info
) == R_NDS32_INSN16
)
12007 if (insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
12008 && insn_rel
< label_rel
)
12010 /* Swap the two reloc if the R_NDS32_INSN16 is
12011 before R_NDS32_LABEL. */
12012 memcpy (&rel_temp
, insn_rel
, sizeof (Elf_Internal_Rela
));
12013 memcpy (insn_rel
, label_rel
, sizeof (Elf_Internal_Rela
));
12014 memcpy (label_rel
, &rel_temp
, sizeof (Elf_Internal_Rela
));
12020 /* If there were a sequence of R_NDS32_LABEL end up with .align 2
12021 or higher, remove other R_NDS32_LABEL with lower alignment.
12022 If an R_NDS32_INSN16 in between R_NDS32_LABELs must be converted,
12023 then the R_NDS32_LABEL sequence is broke. */
12024 for (tmp_rel
= internal_relocs
; tmp_rel
< irelend
; tmp_rel
++)
12026 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_LABEL
)
12028 if (label_rel
== NULL
)
12030 if (tmp_rel
->r_addend
< 2)
12031 label_rel
= tmp_rel
;
12034 else if (tmp_rel
->r_addend
> 1)
12036 /* Remove all LABEL relocation from label_rel to tmp_rel
12037 including relocations with same offset as tmp_rel. */
12038 for (tmp2_rel
= label_rel
; tmp2_rel
< tmp_rel
; tmp2_rel
++)
12040 if (tmp2_rel
->r_offset
== tmp_rel
->r_offset
)
12043 if (ELF32_R_TYPE (tmp2_rel
->r_info
) == R_NDS32_LABEL
12044 && tmp2_rel
->r_addend
< 2)
12046 ELF32_R_INFO (ELF32_R_SYM (tmp2_rel
->r_info
),
12052 else if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
&& label_rel
)
12054 /* A new INSN16 which can be converted, so clear label_rel. */
12055 if (is_convert_32_to_16 (abfd
, sec
, tmp_rel
, internal_relocs
,
12057 || is_16bit_NOP (abfd
, sec
, tmp_rel
))
12064 /* Optimized for speed and nothing has not been relaxed.
12065 It's time to align labels.
12066 We may convert a 16-bit instruction right before a label to
12067 32-bit, in order to align the label if necessary
12068 all reloc entries has been sorted by r_offset. */
12069 for (irel
= internal_relocs
;
12070 irel
< irelend
&& irel
->r_offset
< sec
->size
; irel
++)
12072 if (ELF32_R_TYPE (irel
->r_info
) != R_NDS32_INSN16
12073 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
)
12076 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_INSN16
)
12078 /* A new INSN16 found, resize the old one. */
12079 if (is_convert_32_to_16
12080 (abfd
, sec
, irel
, internal_relocs
, irelend
, &insn16
)
12081 || is_16bit_NOP (abfd
, sec
, irel
))
12085 /* Previous INSN16 reloc exists, reduce its
12087 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
12090 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
12091 internal_relocs
, irelend
, insn16
);
12093 if (!insert_nds32_elf_blank_recalc_total
12094 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12097 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12099 if (!insert_nds32_elf_blank_recalc_total
12100 (relax_blank_list
, insn_rel
->r_offset
, 2))
12104 ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
), R_NDS32_NONE
);
12106 /* Save the new one for later use. */
12110 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
12113 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
)
12115 /* Search for label. */
12116 int force_relax
= 0;
12118 /* Label on 16-bit instruction or optimization
12119 needless, just reset this reloc. */
12120 insn16
= bfd_getb16 (contents
+ irel
->r_offset
);
12121 if ((irel
->r_addend
& 0x1f) < 2 && (!optimize
|| (insn16
& 0x8000)))
12124 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
12129 irel
->r_offset
- get_nds32_elf_blank_total (relax_blank_list
,
12130 irel
->r_offset
, 1);
12134 /* Check if there is case which can not be aligned. */
12135 if (irel
->r_addend
== 2 && address
& 0x2)
12140 /* Try to align this label. */
12142 if ((irel
->r_addend
& 0x1f) < 2)
12144 /* Check if there is a INSN16 at the same address.
12145 Label_rel always seats before insn_rel after
12148 /* Search for INSN16 at LABEL location. If INSN16 is at
12149 same location and this LABEL alignment is lower than 2,
12150 the INSN16 can be converted to 2-byte. */
12151 for (tmp_rel
= irel
;
12152 tmp_rel
< irelend
&& tmp_rel
->r_offset
== irel
->r_offset
;
12155 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
12156 && (is_convert_32_to_16
12157 (abfd
, sec
, tmp_rel
, internal_relocs
,
12159 || is_16bit_NOP (abfd
, sec
, tmp_rel
)))
12167 if (force_relax
|| irel
->r_addend
== 1 || address
& 0x2)
12169 /* Label not aligned. */
12170 /* Previous reloc exists, reduce its size to 16-bit. */
12171 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
,
12172 internal_relocs
, irelend
, &insn16
))
12174 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
12175 internal_relocs
, irelend
, insn16
);
12177 if (!insert_nds32_elf_blank_recalc_total
12178 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12181 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12183 if (!insert_nds32_elf_blank_recalc_total
12184 (relax_blank_list
, insn_rel
->r_offset
, 2))
12189 /* INSN16 reloc is used. */
12195 sec
->size
- get_nds32_elf_blank_total (relax_blank_list
, sec
->size
, 0);
12196 if (insn_rel
&& (address
& 0x2 || opt_size
))
12198 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
12201 nds32_elf_write_16 (abfd
, contents
, insn_rel
, internal_relocs
,
12203 if (!insert_nds32_elf_blank_recalc_total
12204 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
12206 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
12209 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
12211 if (!insert_nds32_elf_blank_recalc_total
12212 (relax_blank_list
, insn_rel
->r_offset
, 2))
12214 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
12223 nds32_elf_relax_section (bfd
*abfd
, asection
*sec
,
12224 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
12226 nds32_elf_blank_t
*relax_blank_list
= NULL
;
12227 Elf_Internal_Shdr
*symtab_hdr
;
12228 Elf_Internal_Rela
*internal_relocs
;
12229 Elf_Internal_Rela
*irel
;
12230 Elf_Internal_Rela
*irelend
;
12231 Elf_Internal_Sym
*isymbuf
= NULL
;
12232 bfd_byte
*contents
= NULL
;
12233 bfd_boolean result
= TRUE
;
12239 /* Target dependnet option. */
12240 struct elf_nds32_link_hash_table
*table
;
12241 int load_store_relax
;
12243 relax_blank_list
= NULL
;
12247 /* Nothing to do for
12248 * relocatable link or
12249 * non-relocatable section or
12250 * non-code section or
12252 * no reloc entry. */
12253 if (bfd_link_relocatable (link_info
)
12254 || (sec
->flags
& SEC_RELOC
) == 0
12255 || (sec
->flags
& SEC_EXCLUDE
) != 0
12256 || (sec
->flags
& SEC_CODE
) == 0
12258 || sec
->reloc_count
== 0)
12261 /* 09.12.11 Workaround. */
12262 /* We have to adjust align for R_NDS32_LABEL if needed.
12263 The adjust approach only can fix 2-byte align once. */
12264 if (sec
->alignment_power
> 2)
12267 /* Do TLS model conversion once at first. */
12268 nds32_elf_unify_tls_model (abfd
, sec
, contents
, link_info
);
12270 /* The optimization type to do. */
12272 table
= nds32_elf_hash_table (link_info
);
12274 /* Save the first section for abs symbol relaxation.
12275 This is used for checking gp relaxation in the
12276 nds32_elf_relax_loadstore and nds32_elf_relax_lo12. */
12277 nds32_elf_relax_guard (NULL
, 0, sec
, NULL
, again
, TRUE
,
12278 table
, NULL
, NULL
);
12280 /* The begining of general relaxation. */
12282 if (is_SDA_BASE_set
== 0)
12285 is_SDA_BASE_set
= 1;
12286 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
12288 relax_range_measurement (abfd
);
12291 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12292 /* Relocations MUST be kept in memory, because relaxation adjust them. */
12293 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
12294 TRUE
/* keep_memory */);
12295 if (internal_relocs
== NULL
)
12298 irelend
= internal_relocs
+ sec
->reloc_count
;
12299 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
12300 irelend
, R_NDS32_RELAX_ENTRY
);
12302 if (irel
== irelend
)
12305 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
12307 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
)
12310 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG
)
12313 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG
)
12317 load_store_relax
= table
->load_store_relax
;
12319 /* Get symbol table and section content. */
12320 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12321 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12324 /* Do relax loop only when finalize is not done.
12325 Take care of relaxable relocs except INSN16. */
12326 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12328 int seq_len
; /* Original length of instruction sequence. */
12329 int insn_len
= 0; /* Final length of instruction sequence. */
12330 bfd_boolean removed
;
12333 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
12334 && (irel
->r_addend
& 0x1f) >= 2)
12337 /* Relocation Types
12338 R_NDS32_LONGCALL1 53
12339 R_NDS32_LONGCALL2 54
12340 R_NDS32_LONGCALL3 55
12341 R_NDS32_LONGJUMP1 56
12342 R_NDS32_LONGJUMP2 57
12343 R_NDS32_LONGJUMP3 58
12344 R_NDS32_LOADSTORE 59 */
12345 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL1
12346 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LOADSTORE
)
12347 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
12349 /* Relocation Types
12350 R_NDS32_LONGCALL4 107
12351 R_NDS32_LONGCALL5 108
12352 R_NDS32_LONGCALL6 109
12353 R_NDS32_LONGJUMP4 110
12354 R_NDS32_LONGJUMP5 111
12355 R_NDS32_LONGJUMP6 112
12356 R_NDS32_LONGJUMP7 113 */
12357 else if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL4
12358 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LONGJUMP7
)
12361 /* Relocation Types
12362 R_NDS32_LO12S0_RELA 30
12363 R_NDS32_LO12S1_RELA 29
12364 R_NDS32_LO12S2_RELA 28
12365 R_NDS32_LO12S2_SP_RELA 71
12366 R_NDS32_LO12S2_DP_RELA 70
12367 R_NDS32_GOT_LO12 46
12368 R_NDS32_GOTOFF_LO12 50
12369 R_NDS32_PLTREL_LO12 65
12370 R_NDS32_PLT_GOTREL_LO12 67
12371 R_NDS32_17IFC_PCREL_RELA 96
12372 R_NDS32_GOT_SUFF 193
12373 R_NDS32_GOTOFF_SUFF 194
12374 R_NDS32_PLT_GOT_SUFF 195
12375 R_NDS32_MULCALL_SUFF 196
12377 else if ((ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LO12S0_RELA
12378 && ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LO12S2_RELA
)
12379 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_SP_RELA
12380 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_DP_RELA
12381 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
12382 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
12383 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
12384 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLTREL_LO12
12385 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
12386 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_GOT_SUFF
12387 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_PTR
)
12388 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
12389 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LO12
12390 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_ADD
12391 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LS
12392 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LSI
)
12397 insn_len
= seq_len
;
12400 switch (ELF32_R_TYPE (irel
->r_info
))
12402 case R_NDS32_LONGCALL1
:
12403 removed
= nds32_elf_relax_longcall1 (abfd
, sec
, irel
, internal_relocs
,
12404 &insn_len
, contents
, isymbuf
,
12407 case R_NDS32_LONGCALL2
:
12408 removed
= nds32_elf_relax_longcall2 (abfd
, sec
, irel
, internal_relocs
,
12409 &insn_len
, contents
, isymbuf
,
12412 case R_NDS32_LONGCALL3
:
12413 removed
= nds32_elf_relax_longcall3 (abfd
, sec
, irel
, internal_relocs
,
12414 &insn_len
, contents
, isymbuf
,
12417 case R_NDS32_LONGJUMP1
:
12418 removed
= nds32_elf_relax_longjump1 (abfd
, sec
, irel
, internal_relocs
,
12419 &insn_len
, contents
, isymbuf
,
12422 case R_NDS32_LONGJUMP2
:
12423 removed
= nds32_elf_relax_longjump2 (abfd
, sec
, irel
, internal_relocs
,
12424 &insn_len
, contents
, isymbuf
,
12427 case R_NDS32_LONGJUMP3
:
12428 removed
= nds32_elf_relax_longjump3 (abfd
, sec
, irel
, internal_relocs
,
12429 &insn_len
, contents
, isymbuf
,
12432 case R_NDS32_LONGCALL4
:
12433 removed
= nds32_elf_relax_longcall4 (abfd
, sec
, irel
, internal_relocs
,
12434 &insn_len
, contents
, isymbuf
,
12437 case R_NDS32_LONGCALL5
:
12438 removed
= nds32_elf_relax_longcall5 (abfd
, sec
, irel
, internal_relocs
,
12439 &insn_len
, contents
, isymbuf
,
12442 case R_NDS32_LONGCALL6
:
12443 removed
= nds32_elf_relax_longcall6 (abfd
, sec
, irel
, internal_relocs
,
12444 &insn_len
, contents
, isymbuf
,
12447 case R_NDS32_LONGJUMP4
:
12448 removed
= nds32_elf_relax_longjump4 (abfd
, sec
, irel
, internal_relocs
,
12449 &insn_len
, contents
, isymbuf
,
12452 case R_NDS32_LONGJUMP5
:
12453 removed
= nds32_elf_relax_longjump5 (abfd
, sec
, irel
, internal_relocs
,
12454 &insn_len
, &seq_len
, contents
,
12455 isymbuf
, symtab_hdr
);
12457 case R_NDS32_LONGJUMP6
:
12458 removed
= nds32_elf_relax_longjump6 (abfd
, sec
, irel
, internal_relocs
,
12459 &insn_len
, &seq_len
, contents
,
12460 isymbuf
, symtab_hdr
);
12462 case R_NDS32_LONGJUMP7
:
12463 removed
= nds32_elf_relax_longjump7 (abfd
, sec
, irel
, internal_relocs
,
12464 &insn_len
, &seq_len
, contents
,
12465 isymbuf
, symtab_hdr
);
12467 case R_NDS32_LOADSTORE
:
12468 removed
= nds32_elf_relax_loadstore (link_info
, abfd
, sec
, irel
,
12469 internal_relocs
, &insn_len
,
12470 contents
, isymbuf
, symtab_hdr
,
12471 load_store_relax
, table
);
12473 case R_NDS32_LO12S0_RELA
:
12474 case R_NDS32_LO12S1_RELA
:
12475 case R_NDS32_LO12S2_RELA
:
12476 case R_NDS32_LO12S2_DP_RELA
:
12477 case R_NDS32_LO12S2_SP_RELA
:
12478 /* Relax for low part. */
12479 nds32_elf_relax_lo12 (link_info
, abfd
, sec
, irel
, internal_relocs
,
12480 contents
, isymbuf
, symtab_hdr
, table
);
12482 /* It is impossible to delete blank, so just continue. */
12485 removed
= nds32_elf_relax_ptr (abfd
, sec
, irel
, internal_relocs
,
12486 &insn_len
, &seq_len
, contents
);
12489 nds32_elf_relax_flsi (link_info
, abfd
, sec
, irel
, internal_relocs
,
12490 contents
, isymbuf
, symtab_hdr
, again
);
12492 case R_NDS32_GOT_LO12
:
12493 case R_NDS32_GOTOFF_LO12
:
12494 case R_NDS32_PLTREL_LO12
:
12495 case R_NDS32_PLT_GOTREL_LO12
:
12496 case R_NDS32_GOTPC_LO12
:
12497 case R_NDS32_TLS_LE_LO12
:
12498 case R_NDS32_TLS_LE_ADD
:
12499 case R_NDS32_TLS_LE_LS
:
12500 case R_NDS32_PLT_GOT_SUFF
:
12501 case R_NDS32_GOT_SUFF
:
12502 case R_NDS32_GOTOFF_SUFF
:
12508 if (removed
&& seq_len
- insn_len
> 0)
12510 if (!insert_nds32_elf_blank
12511 (&relax_blank_list
, irel
->r_offset
+ insn_len
,
12512 seq_len
- insn_len
))
12518 calc_nds32_blank_total (relax_blank_list
);
12520 if (table
->relax_fp_as_gp
)
12522 if (!nds32_relax_fp_as_gp (link_info
, abfd
, sec
, internal_relocs
,
12528 if (!nds32_fag_remove_unused_fpbase (abfd
, sec
, internal_relocs
,
12536 if (!nds32_relax_adjust_label (abfd
, sec
, internal_relocs
, contents
,
12537 &relax_blank_list
, optimize
, opt_size
))
12541 /* It doesn't matter optimize_for_space_no_align anymore.
12542 If object file is assembled with flag '-Os',
12543 the we don't adjust jump-destination on 4-byte boundary. */
12545 if (relax_blank_list
)
12547 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
12548 relax_blank_list
= NULL
;
12553 /* Closing the section, so we don't relax it anymore. */
12554 bfd_vma sec_size_align
;
12555 Elf_Internal_Rela
*tmp_rel
;
12557 /* Pad to alignment boundary. Only handle current section alignment. */
12558 sec_size_align
= (sec
->size
+ (~((-1U) << sec
->alignment_power
)))
12559 & ((-1U) << sec
->alignment_power
);
12560 if ((sec_size_align
- sec
->size
) & 0x2)
12562 insn16
= NDS32_NOP16
;
12563 bfd_putb16 (insn16
, contents
+ sec
->size
);
12567 while (sec_size_align
!= sec
->size
)
12569 insn
= NDS32_NOP32
;
12570 bfd_putb32 (insn
, contents
+ sec
->size
);
12574 tmp_rel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
12575 irelend
, R_NDS32_RELAX_ENTRY
);
12576 if (tmp_rel
!= irelend
)
12577 tmp_rel
->r_addend
|= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
;
12579 clean_nds32_elf_blank ();
12583 if (internal_relocs
!= NULL
12584 && elf_section_data (sec
)->relocs
!= internal_relocs
)
12585 free (internal_relocs
);
12587 if (contents
!= NULL
12588 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
12591 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) isymbuf
)
12601 static struct bfd_elf_special_section
const nds32_elf_special_sections
[] =
12603 {".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
12604 {".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
12609 nds32_elf_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
12610 struct bfd_link_info
*info
,
12611 void *finfo ATTRIBUTE_UNUSED
,
12612 bfd_boolean (*func
) (void *, const char *,
12613 Elf_Internal_Sym
*,
12615 struct elf_link_hash_entry
*)
12618 FILE *sym_ld_script
= NULL
;
12619 struct elf_nds32_link_hash_table
*table
;
12621 table
= nds32_elf_hash_table (info
);
12622 sym_ld_script
= table
->sym_ld_script
;
12624 if (check_start_export_sym
)
12625 fprintf (sym_ld_script
, "}\n");
12630 static enum elf_reloc_type_class
12631 nds32_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
12632 const asection
*rel_sec ATTRIBUTE_UNUSED
,
12633 const Elf_Internal_Rela
*rela
)
12635 switch ((int) ELF32_R_TYPE (rela
->r_info
))
12637 case R_NDS32_RELATIVE
:
12638 return reloc_class_relative
;
12639 case R_NDS32_JMP_SLOT
:
12640 return reloc_class_plt
;
12642 return reloc_class_copy
;
12644 return reloc_class_normal
;
12648 /* Put target dependent option into info hash table. */
12650 bfd_elf32_nds32_set_target_option (struct bfd_link_info
*link_info
,
12651 int relax_fp_as_gp
,
12652 int eliminate_gc_relocs
,
12653 FILE * sym_ld_script
,
12655 int tls_desc_trampoline
,
12656 int load_store_relax
)
12658 struct elf_nds32_link_hash_table
*table
;
12660 table
= nds32_elf_hash_table (link_info
);
12664 table
->relax_fp_as_gp
= relax_fp_as_gp
;
12665 table
->eliminate_gc_relocs
= eliminate_gc_relocs
;
12666 table
->sym_ld_script
= sym_ld_script
;
12667 table
->hyper_relax
= hyper_relax
;
12668 table
->tls_desc_trampoline
= tls_desc_trampoline
;
12669 table
->load_store_relax
= load_store_relax
;
12673 /* These functions and data-structures are used for fp-as-gp
12676 #define FAG_THRESHOLD 3 /* At least 3 gp-access. */
12677 /* lwi37.fp covers 508 bytes, but there may be 32-byte padding between
12678 the read-only section and read-write section. */
12679 #define FAG_WINDOW (508 - 32)
12681 /* An nds32_fag represent a gp-relative access.
12682 We find best fp-base by using a sliding window
12683 to find a base address which can cover most gp-access. */
12686 struct nds32_fag
*next
; /* NULL-teminated linked list. */
12687 bfd_vma addr
; /* The address of this fag. */
12688 Elf_Internal_Rela
**relas
; /* The relocations associated with this fag.
12689 It is used for applying FP7U2_FLAG. */
12690 int count
; /* How many times this address is referred.
12691 There should be exactly `count' relocations
12693 int relas_capcity
; /* The buffer size of relas.
12694 We use an array instead of linked-list,
12695 and realloc is used to adjust buffer size. */
12699 nds32_fag_init (struct nds32_fag
*head
)
12701 memset (head
, 0, sizeof (struct nds32_fag
));
12705 nds32_fag_verify (struct nds32_fag
*head
)
12707 struct nds32_fag
*iter
;
12708 struct nds32_fag
*prev
;
12714 if (prev
&& prev
->addr
>= iter
->addr
)
12715 puts ("Bug in fp-as-gp insertion.");
12721 /* Insert a fag in ascending order.
12722 If a fag of the same address already exists,
12723 they are chained by relas array. */
12726 nds32_fag_insert (struct nds32_fag
*head
, bfd_vma addr
,
12727 Elf_Internal_Rela
* rel
)
12729 struct nds32_fag
*iter
;
12730 struct nds32_fag
*new_fag
;
12731 const int INIT_RELAS_CAP
= 4;
12734 iter
->next
&& iter
->next
->addr
<= addr
;
12736 /* Find somewhere to insert. */ ;
12738 /* `iter' will be equal to `head' if the list is empty. */
12739 if (iter
!= head
&& iter
->addr
== addr
)
12741 /* The address exists in the list.
12742 Insert `rel' into relocation list, relas. */
12744 /* Check whether relas is big enough. */
12745 if (iter
->count
>= iter
->relas_capcity
)
12747 iter
->relas_capcity
*= 2;
12748 iter
->relas
= bfd_realloc
12749 (iter
->relas
, iter
->relas_capcity
* sizeof (void *));
12751 iter
->relas
[iter
->count
++] = rel
;
12755 /* This is a new address. Create a fag node for it. */
12756 new_fag
= bfd_malloc (sizeof (struct nds32_fag
));
12757 memset (new_fag
, 0, sizeof (*new_fag
));
12758 new_fag
->addr
= addr
;
12759 new_fag
->count
= 1;
12760 new_fag
->next
= iter
->next
;
12761 new_fag
->relas_capcity
= INIT_RELAS_CAP
;
12762 new_fag
->relas
= (Elf_Internal_Rela
**)
12763 bfd_malloc (new_fag
->relas_capcity
* sizeof (void *));
12764 new_fag
->relas
[0] = rel
;
12765 iter
->next
= new_fag
;
12767 nds32_fag_verify (head
);
12771 nds32_fag_free_list (struct nds32_fag
*head
)
12773 struct nds32_fag
*iter
;
12778 struct nds32_fag
*tmp
= iter
;
12786 /* Find the best fp-base address.
12787 The relocation associated with that address is returned,
12788 so we can track the symbol instead of a fixed address.
12790 When relaxation, the address of an datum may change,
12791 because a text section is shrinked, so the data section
12792 moves forward. If the aligments of text and data section
12793 are different, their distance may change too.
12794 Therefore, tracking a fixed address is not appriate. */
12797 nds32_fag_find_base (struct nds32_fag
*head
, struct nds32_fag
**bestpp
)
12799 struct nds32_fag
*base
; /* First fag in the window. */
12800 struct nds32_fag
*last
; /* First fag outside the window. */
12801 int accu
= 0; /* Usage accumulation. */
12802 struct nds32_fag
*best
; /* Best fag. */
12803 int baccu
= 0; /* Best accumulation. */
12805 /* Use first fag for initial, and find the last fag in the window.
12807 In each iteration, we could simply subtract previous fag
12808 and accumulate following fags which are inside the window,
12809 untill we each the end. */
12811 if (head
->next
== NULL
)
12817 /* Initialize base. */
12821 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12823 accu
+= last
->count
;
12827 /* Record the best base in each iteration. */
12830 accu
-= base
->count
;
12832 /* Account fags in window. */
12833 for (/* Nothing. */;
12834 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12836 accu
+= last
->count
;
12838 /* A better fp-base? */
12851 /* Apply R_NDS32_INSN16_FP7U2_FLAG on gp-relative accesses,
12852 so we can convert it fo fp-relative access later.
12853 `best_fag' is the best fp-base. Only those inside the window
12854 of best_fag is applied the flag. */
12857 nds32_fag_mark_relax (struct bfd_link_info
*link_info
,
12858 asection
*sec
, struct nds32_fag
*best_fag
,
12859 Elf_Internal_Rela
*internal_relocs
,
12860 Elf_Internal_Rela
*irelend
)
12862 struct nds32_fag
*ifag
;
12863 bfd_vma best_fpbase
, gp
;
12866 output_bfd
= sec
->output_section
->owner
;
12867 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
12868 best_fpbase
= best_fag
->addr
;
12870 if (best_fpbase
> gp
+ sdata_range
[1][1]
12871 || best_fpbase
< gp
- sdata_range
[1][0])
12874 /* Mark these inside the window R_NDS32_INSN16_FP7U2_FLAG flag,
12875 so we know they can be converted to lwi37.fp. */
12876 for (ifag
= best_fag
;
12877 ifag
&& ifag
->addr
< best_fpbase
+ FAG_WINDOW
; ifag
= ifag
->next
)
12881 for (i
= 0; i
< ifag
->count
; i
++)
12883 Elf_Internal_Rela
*insn16_rel
;
12884 Elf_Internal_Rela
*fag_rel
;
12886 fag_rel
= ifag
->relas
[i
];
12888 /* Only if this is within the WINDOWS, FP7U2_FLAG
12891 insn16_rel
= find_relocs_at_address
12892 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12894 if (insn16_rel
!= irelend
)
12895 insn16_rel
->r_addend
= R_NDS32_INSN16_FP7U2_FLAG
;
12901 /* Reset INSN16 to clean fp as gp. */
12904 nds32_fag_unmark_relax (struct nds32_fag
*fag
,
12905 Elf_Internal_Rela
*internal_relocs
,
12906 Elf_Internal_Rela
*irelend
)
12908 struct nds32_fag
*ifag
;
12910 Elf_Internal_Rela
*insn16_rel
;
12911 Elf_Internal_Rela
*fag_rel
;
12913 for (ifag
= fag
; ifag
; ifag
= ifag
->next
)
12915 for (i
= 0; i
< ifag
->count
; i
++)
12917 fag_rel
= ifag
->relas
[i
];
12919 /* Restore the INSN16 relocation. */
12920 insn16_rel
= find_relocs_at_address
12921 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12923 if (insn16_rel
!= irelend
)
12924 insn16_rel
->r_addend
&= ~R_NDS32_INSN16_FP7U2_FLAG
;
12929 /* This is the main function of fp-as-gp optimization.
12930 It should be called by relax_section. */
12933 nds32_relax_fp_as_gp (struct bfd_link_info
*link_info
,
12934 bfd
*abfd
, asection
*sec
,
12935 Elf_Internal_Rela
*internal_relocs
,
12936 Elf_Internal_Rela
*irelend
,
12937 Elf_Internal_Sym
*isymbuf
)
12939 Elf_Internal_Rela
*begin_rel
= NULL
;
12940 Elf_Internal_Rela
*irel
;
12941 struct nds32_fag fag_head
;
12942 Elf_Internal_Shdr
*symtab_hdr
;
12943 bfd_byte
*contents
;
12944 bfd_boolean ifc_inside
= FALSE
;
12946 /* FIXME: Can we bfd_elf_link_read_relocs for the relocs? */
12948 /* Per-function fp-base selection.
12949 1. Create a list for all the gp-relative access.
12950 2. Base on those gp-relative address,
12951 find a fp-base which can cover most access.
12952 3. Use the fp-base for fp-as-gp relaxation.
12954 NOTE: If fp-as-gp is not worth to do, (e.g., less than 3 times),
12956 1. delete the `la $fp, _FP_BASE_' instruction and
12957 2. not convert lwi.gp to lwi37.fp.
12959 To delete the _FP_BASE_ instruction, we simply apply
12960 R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG flag in the r_addend to disable it.
12962 To suppress the conversion, we simply NOT to apply
12963 R_NDS32_INSN16_FP7U2_FLAG flag. */
12965 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12967 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12968 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12971 /* Check whether it is worth for fp-as-gp optimization,
12972 i.e., at least 3 gp-load.
12974 Set R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG if we should NOT
12975 apply this optimization. */
12977 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12979 /* We recognize R_NDS32_RELAX_REGION_BEGIN/_END for the region.
12980 One we enter the begin of the region, we track all the LW/ST
12981 instructions, so when we leave the region, we try to find
12982 the best fp-base address for those LW/ST instructions. */
12984 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12985 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12987 /* Begin of the region. */
12989 /* xgettext:c-format */
12990 _bfd_error_handler (_("%pB: nested OMIT_FP in %pA"), abfd
, sec
);
12993 nds32_fag_init (&fag_head
);
12994 ifc_inside
= FALSE
;
12996 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12997 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
13000 struct nds32_fag
*best_fag
, *tmp_fag
;
13003 /* End of the region.
13004 Check whether it is worth to do fp-as-gp. */
13006 if (begin_rel
== NULL
)
13008 /* xgettext:c-format */
13009 _bfd_error_handler (_("%pB: unmatched OMIT_FP in %pA"),
13014 accu
= nds32_fag_find_base (&fag_head
, &best_fag
);
13016 /* Clean FP7U2_FLAG because they may set ever. */
13017 tmp_fag
= fag_head
.next
;
13018 nds32_fag_unmark_relax (tmp_fag
, internal_relocs
, irelend
);
13020 /* Check if it is worth, and FP_BASE is near enough to SDA_BASE. */
13021 if (accu
< FAG_THRESHOLD
13022 || !nds32_fag_mark_relax (link_info
, sec
, best_fag
,
13023 internal_relocs
, irelend
))
13025 /* Not worth to do fp-as-gp. */
13026 begin_rel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
13027 begin_rel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
13028 irel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
13029 irel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
13030 nds32_fag_free_list (&fag_head
);
13035 /* R_SYM of R_NDS32_RELAX_REGION_BEGIN is not used by assembler,
13036 so we use it to record the distance to the reloction of best
13038 dist
= best_fag
->relas
[0] - begin_rel
;
13039 BFD_ASSERT (dist
> 0 && dist
< 0xffffff);
13040 /* Use high 16 bits of addend to record the _FP_BASE_ matched
13041 relocation. And get the base value when relocating. */
13042 begin_rel
->r_addend
&= (0x1 << 16) - 1;
13043 begin_rel
->r_addend
|= dist
<< 16;
13045 nds32_fag_free_list (&fag_head
);
13049 if (begin_rel
== NULL
|| ifc_inside
)
13050 /* Skip if we are not in the region of fp-as-gp. */
13053 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S2_RELA
13054 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA17S2_RELA
)
13059 /* A gp-relative access is found. Insert it to the fag-list. */
13061 /* Rt is necessary an RT3, so it can be converted to lwi37.fp. */
13062 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13063 if (!N32_IS_RT3 (insn
))
13066 addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
13067 nds32_fag_insert (&fag_head
, addr
, irel
);
13069 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA_FP7U2_RELA
)
13073 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
13074 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
13076 /* Suppress fp as gp when encounter ifc. */
13084 /* Remove unused `la $fp, _FD_BASE_' instruction. */
13087 nds32_fag_remove_unused_fpbase (bfd
*abfd
, asection
*sec
,
13088 Elf_Internal_Rela
*internal_relocs
,
13089 Elf_Internal_Rela
*irelend
)
13091 Elf_Internal_Rela
*irel
;
13092 Elf_Internal_Shdr
*symtab_hdr
;
13093 bfd_byte
*contents
= NULL
;
13094 nds32_elf_blank_t
*relax_blank_list
= NULL
;
13095 bfd_boolean result
= TRUE
;
13096 bfd_boolean unused_region
= FALSE
;
13099 NOTE: Disable fp-as-gp if we encounter ifcall relocations:
13100 R_NDS32_17IFC_PCREL_RELA
13101 R_NDS32_10IFCU_PCREL_RELA. */
13103 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13104 nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
);
13106 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13108 /* To remove unused fp-base, we simply find the REGION_NOT_OMIT_FP
13109 we marked to in previous pass.
13110 DO NOT scan relocations again, since we've alreadly decided it
13111 and set the flag. */
13112 const char *syname
;
13116 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
13117 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
13118 unused_region
= TRUE
;
13119 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
13120 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
13121 unused_region
= FALSE
;
13123 /* We're not in the region. */
13124 if (!unused_region
)
13127 /* _FP_BASE_ must be a GLOBAL symbol. */
13128 syndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
13129 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
13132 /* The symbol name must be _FP_BASE_. */
13133 syname
= elf_sym_hashes (abfd
)[syndx
]->root
.root
.string
;
13134 if (strcmp (syname
, FP_BASE_NAME
) != 0)
13137 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA19S0_RELA
)
13139 /* addi.gp $fp, -256 */
13140 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13141 if (insn
!= INSN_ADDIGP_TO_FP
)
13144 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S0_RELA
)
13146 /* addi $fp, $gp, -256 */
13147 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13148 if (insn
!= INSN_ADDI_GP_TO_FP
)
13151 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_20_RELA
)
13153 /* movi $fp, FP_BASE */
13154 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13155 if (insn
!= INSN_MOVI_TO_FP
)
13161 /* We got here because a FP_BASE instruction is found. */
13162 if (!insert_nds32_elf_blank_recalc_total
13163 (&relax_blank_list
, irel
->r_offset
, 4))
13168 if (relax_blank_list
)
13170 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
13171 relax_blank_list
= NULL
;
13180 /* This is a version of bfd_generic_get_relocated_section_contents.
13181 We need this variety because relaxation will modify the dwarf
13182 infomation. When there is undefined symbol reference error mesage,
13183 linker need to dump line number where the symbol be used. However
13184 the address is be relaxed, it can not get the original dwarf contents.
13185 The variety only modify function call for reading in the section. */
13188 nds32_elf_get_relocated_section_contents (bfd
*abfd
,
13189 struct bfd_link_info
*link_info
,
13190 struct bfd_link_order
*link_order
,
13192 bfd_boolean relocatable
,
13195 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
13196 asection
*input_section
= link_order
->u
.indirect
.section
;
13198 arelent
**reloc_vector
;
13201 reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
13202 if (reloc_size
< 0)
13205 /* Read in the section. */
13206 if (!nds32_get_section_contents (input_bfd
, input_section
, &data
, FALSE
))
13209 if (reloc_size
== 0)
13212 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
13213 if (reloc_vector
== NULL
)
13216 reloc_count
= bfd_canonicalize_reloc (input_bfd
, input_section
,
13217 reloc_vector
, symbols
);
13218 if (reloc_count
< 0)
13221 if (reloc_count
> 0)
13224 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
13226 char *error_message
= NULL
;
13228 bfd_reloc_status_type r
;
13230 symbol
= *(*parent
)->sym_ptr_ptr
;
13231 if (symbol
->section
&& discarded_section (symbol
->section
))
13234 static reloc_howto_type none_howto
13235 = HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, NULL
,
13236 "unused", FALSE
, 0, 0, FALSE
);
13238 p
= data
+ (*parent
)->address
* bfd_octets_per_byte (input_bfd
);
13239 _bfd_clear_contents ((*parent
)->howto
, input_bfd
, input_section
,
13241 (*parent
)->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
13242 (*parent
)->addend
= 0;
13243 (*parent
)->howto
= &none_howto
;
13247 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
13249 relocatable
? abfd
: NULL
,
13254 asection
*os
= input_section
->output_section
;
13256 /* A partial link, so keep the relocs. */
13257 os
->orelocation
[os
->reloc_count
] = *parent
;
13261 if (r
!= bfd_reloc_ok
)
13265 case bfd_reloc_undefined
:
13266 (*link_info
->callbacks
->undefined_symbol
)
13267 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13268 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
13270 case bfd_reloc_dangerous
:
13271 BFD_ASSERT (error_message
!= NULL
);
13272 (*link_info
->callbacks
->reloc_dangerous
)
13273 (link_info
, error_message
,
13274 input_bfd
, input_section
, (*parent
)->address
);
13276 case bfd_reloc_overflow
:
13277 (*link_info
->callbacks
->reloc_overflow
)
13279 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
13280 (*parent
)->howto
->name
, (*parent
)->addend
,
13281 input_bfd
, input_section
, (*parent
)->address
);
13283 case bfd_reloc_outofrange
:
13285 This error can result when processing some partially
13286 complete binaries. Do not abort, but issue an error
13287 message instead. */
13288 link_info
->callbacks
->einfo
13289 /* xgettext:c-format */
13290 (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
13291 abfd
, input_section
, * parent
);
13302 free (reloc_vector
);
13306 free (reloc_vector
);
13310 /* Check target symbol. */
13313 nds32_elf_is_target_special_symbol (bfd
*abfd ATTRIBUTE_UNUSED
, asymbol
*sym
)
13315 if (!sym
|| !sym
->name
|| sym
->name
[0] != '$')
13320 /* nds32 find maybe function sym. Ignore target special symbol
13321 first, and then go the general function. */
13323 static bfd_size_type
13324 nds32_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
13327 if (nds32_elf_is_target_special_symbol (NULL
, (asymbol
*) sym
))
13330 return _bfd_elf_maybe_function_sym (sym
, sec
, code_off
);
13334 /* Do TLS model conversion. */
13336 typedef struct relax_group_list_t
13338 Elf_Internal_Rela
*relo
;
13339 struct relax_group_list_t
*next
;
13340 struct relax_group_list_t
*next_sibling
;
13342 } relax_group_list_t
;
13345 list_insert (relax_group_list_t
*pHead
, Elf_Internal_Rela
*pElem
);
13348 list_insert_sibling (relax_group_list_t
*pNode
, Elf_Internal_Rela
*pElem
);
13351 dump_chain (relax_group_list_t
*pHead
);
13354 list_insert (relax_group_list_t
*pHead
, Elf_Internal_Rela
*pElem
)
13356 relax_group_list_t
*pNext
= pHead
;
13359 while (pNext
->next
)
13361 if (pNext
->next
->id
> (int) pElem
->r_addend
)
13364 pNext
= pNext
->next
;
13368 relax_group_list_t
*pNew
= bfd_malloc (sizeof (relax_group_list_t
));
13372 relax_group_list_t
*tmp
= pNext
->next
;
13373 pNext
->next
= pNew
;
13375 pNew
->id
= pElem
->r_addend
;
13376 pNew
->relo
= pElem
;
13378 pNew
->next_sibling
= NULL
;
13384 list_insert_sibling (relax_group_list_t
*pNode
, Elf_Internal_Rela
*pElem
)
13386 relax_group_list_t
*pNext
= pNode
;
13389 while (pNext
->next_sibling
)
13391 pNext
= pNext
->next_sibling
;
13395 relax_group_list_t
*pNew
= bfd_malloc (sizeof (relax_group_list_t
));
13399 relax_group_list_t
*tmp
= pNext
->next_sibling
;
13400 pNext
->next_sibling
= pNew
;
13403 pNew
->relo
= pElem
;
13405 pNew
->next_sibling
= tmp
;
13411 dump_chain (relax_group_list_t
*pHead
)
13413 relax_group_list_t
*pNext
= pHead
->next
;
13416 printf("group %d @ 0x%08x", pNext
->id
, (unsigned)pNext
->relo
->r_offset
);
13417 relax_group_list_t
*pNextSib
= pNext
->next_sibling
;
13420 printf(", %d", (unsigned) ELF32_R_TYPE (pNextSib
->relo
->r_info
));
13421 pNextSib
= pNextSib
->next_sibling
;
13423 pNext
= pNext
->next
;
13428 /* Check R_NDS32_RELAX_GROUP of each section.
13429 There might be multiple sections in one object file. */
13432 elf32_nds32_check_relax_group (bfd
*abfd
, asection
*asec
)
13434 elf32_nds32_relax_group_t
*relax_group_ptr
=
13435 elf32_nds32_relax_group_ptr (abfd
);
13437 int min_id
= relax_group_ptr
->min_id
;
13438 int max_id
= relax_group_ptr
->max_id
;
13440 Elf_Internal_Rela
*rel
;
13441 Elf_Internal_Rela
*relend
;
13442 Elf_Internal_Rela
*relocs
;
13443 enum elf_nds32_reloc_type rtype
;
13447 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13448 relocs
= _bfd_elf_link_read_relocs (abfd
, asec
, NULL
, NULL
,
13449 TRUE
/* keep_memory */);
13450 if (relocs
== NULL
)
13453 /* Check R_NDS32_RELAX_GROUP. */
13454 relend
= relocs
+ asec
->reloc_count
;
13455 for (rel
= relocs
; rel
< relend
; rel
++)
13458 rtype
= ELF32_R_TYPE (rel
->r_info
);
13459 if (rtype
!= R_NDS32_RELAX_GROUP
)
13462 id
= rel
->r_addend
;
13465 else if (id
> max_id
)
13471 if ((relocs
!= NULL
) && (elf_section_data (asec
)->relocs
!= relocs
))
13474 if ((min_id
!= relax_group_ptr
->min_id
)
13475 || (max_id
!= relax_group_ptr
->max_id
))
13477 relax_group_ptr
->count
= max_id
- min_id
+ 1;
13478 BFD_ASSERT(min_id
<= relax_group_ptr
->min_id
);
13479 relax_group_ptr
->min_id
= min_id
;
13480 BFD_ASSERT(max_id
>= relax_group_ptr
->max_id
);
13481 relax_group_ptr
->max_id
= max_id
;
13484 return relax_group_ptr
->count
;
13487 /* Reorder RELAX_GROUP ID when command line option '-r' is applied. */
13488 struct section_id_list_t
*relax_group_section_id_list
= NULL
;
13490 struct section_id_list_t
*
13491 elf32_nds32_lookup_section_id (int id
, struct section_id_list_t
**lst_ptr
)
13493 struct section_id_list_t
*result
= NULL
;
13494 struct section_id_list_t
*lst
= *lst_ptr
;
13498 result
= (struct section_id_list_t
*) calloc
13499 (1, sizeof (struct section_id_list_t
));
13500 BFD_ASSERT (result
); /* Feed me. */
13506 struct section_id_list_t
*cur
= lst
;
13507 struct section_id_list_t
*prv
= NULL
;
13508 struct section_id_list_t
*sec
= NULL
;
13521 cur
= NULL
; /* To insert after prv. */
13522 sec
= cur
; /* In case prv == NULL. */
13530 /* Insert after prv. */
13531 result
= (struct section_id_list_t
*) calloc
13532 (1, sizeof (struct section_id_list_t
));
13533 BFD_ASSERT (result
); /* Feed me. */
13537 result
->next
= prv
->next
;
13538 prv
->next
= result
;
13543 result
->next
= sec
;
13552 elf32_nds32_unify_relax_group (bfd
*abfd
, asection
*asec
)
13554 static int next_relax_group_bias
= 0;
13556 elf32_nds32_relax_group_t
*relax_group_ptr
=
13557 elf32_nds32_relax_group_ptr (abfd
);
13559 bfd_boolean result
= TRUE
;
13560 Elf_Internal_Rela
*rel
;
13561 Elf_Internal_Rela
*relend
;
13562 Elf_Internal_Rela
*relocs
= NULL
;
13563 enum elf_nds32_reloc_type rtype
;
13564 struct section_id_list_t
*node
= NULL
;
13569 if (0 == relax_group_ptr
->count
)
13572 /* Check if this section has been handled. */
13573 node
= elf32_nds32_lookup_section_id (asec
->id
, &relax_group_section_id_list
);
13575 break; /* Hit, the section id has handled. */
13577 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13578 relocs
= _bfd_elf_link_read_relocs (abfd
, asec
, NULL
, NULL
,
13579 TRUE
/* keep_memory */);
13580 if (relocs
== NULL
)
13582 BFD_ASSERT (0); /* feed me */
13586 /* Allocate group id bias for this bfd! */
13587 if (0 == relax_group_ptr
->init
)
13589 relax_group_ptr
->bias
= next_relax_group_bias
;
13590 next_relax_group_bias
+= relax_group_ptr
->count
;
13591 relax_group_ptr
->init
= 1;
13594 /* Reorder relax group groups. */
13595 relend
= relocs
+ asec
->reloc_count
;
13596 for (rel
= relocs
; rel
< relend
; rel
++)
13598 rtype
= ELF32_R_TYPE(rel
->r_info
);
13599 if (rtype
!= R_NDS32_RELAX_GROUP
)
13603 rel
->r_addend
+= relax_group_ptr
->bias
;
13604 /* Debugging count. */
13610 if (relocs
!= NULL
&& elf_section_data (asec
)->relocs
!= relocs
)
13617 nds32_elf_unify_tls_model (bfd
*inbfd
, asection
*insec
, bfd_byte
*incontents
,
13618 struct bfd_link_info
*lnkinfo
)
13620 bfd_boolean result
= TRUE
;
13621 Elf_Internal_Rela
*irel
;
13622 Elf_Internal_Rela
*irelend
;
13623 Elf_Internal_Rela
*internal_relocs
;
13624 unsigned long r_symndx
;
13625 enum elf_nds32_reloc_type r_type
;
13627 Elf_Internal_Sym
*local_syms
= NULL
;
13628 bfd_byte
*contents
= NULL
;
13630 relax_group_list_t chain
= { .id
= -1, .next
= NULL
, .next_sibling
= NULL
};
13632 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (inbfd
)->symtab_hdr
;
13633 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
13634 sym_hashes
= elf_sym_hashes (inbfd
);
13636 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
13637 if (!elf_bad_symtab (inbfd
))
13638 sym_hashes_end
-= symtab_hdr
->sh_info
;
13640 /* Reorder RELAX_GROUP when command line option '-r' is applied. */
13641 if (bfd_link_relocatable (lnkinfo
))
13643 elf32_nds32_unify_relax_group (inbfd
, insec
);
13647 /* Relocations MUST be kept in memory, because relaxation adjust them. */
13648 internal_relocs
= _bfd_elf_link_read_relocs (inbfd
, insec
, NULL
, NULL
,
13649 TRUE
/* keep_memory */);
13650 if (internal_relocs
== NULL
)
13653 irelend
= internal_relocs
+ insec
->reloc_count
;
13654 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
13655 irelend
, R_NDS32_RELAX_ENTRY
);
13656 if (irel
== irelend
)
13659 /* Chain/remove groups. */
13660 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13662 r_symndx
= ELF32_R_SYM (irel
->r_info
);
13663 r_type
= ELF32_R_TYPE (irel
->r_info
);
13664 if (r_type
!= R_NDS32_RELAX_GROUP
)
13668 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_NONE
);
13669 /* Chain it now. */
13670 if (!list_insert (&chain
, irel
))
13674 /* Collect group relocations. */
13675 /* Presume relocations are sorted. */
13676 relax_group_list_t
*pNext
= chain
.next
;
13679 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
13681 if (irel
->r_offset
== pNext
->relo
->r_offset
)
13683 /* Ignore Non-TLS relocation types. */
13684 r_type
= ELF32_R_TYPE (irel
->r_info
);
13685 if ((R_NDS32_TLS_LE_HI20
> r_type
)
13686 || (R_NDS32_RELAX_ENTRY
== r_type
))
13689 if (!list_insert_sibling (pNext
, irel
))
13692 else if (irel
->r_offset
> pNext
->relo
->r_offset
)
13694 pNext
= pNext
->next
;
13698 bfd_vma current_offset
= pNext
->relo
->r_offset
;
13699 if (irel
->r_offset
> current_offset
)
13700 irel
= internal_relocs
; /* restart from head */
13702 --irel
; /* Check current irel again. */
13707 /* This shouldn't be reached. */
13711 pNext
= pNext
->next
;
13714 #ifdef DUBUG_VERBOSE
13715 dump_chain(&chain
);
13718 /* Get symbol table and section content. */
13720 contents
= incontents
;
13721 else if (!nds32_get_section_contents (inbfd
, insec
, &contents
, TRUE
)
13722 || !nds32_get_local_syms (inbfd
, insec
, &local_syms
))
13725 char *local_got_tls_type
= elf32_nds32_local_got_tls_type (inbfd
);
13727 /* Convert TLS model each group if necessary. */
13728 pNext
= chain
.next
;
13730 int cur_grp_id
= -1;
13733 enum elf_nds32_tls_type tls_type
, org_tls_type
, eff_tls_type
;
13735 tls_type
= org_tls_type
= eff_tls_type
= 0;
13739 relax_group_list_t
*pNextSig
= pNext
->next_sibling
;
13742 struct elf_link_hash_entry
*h
= NULL
;
13744 irel
= pNextSig
->relo
;
13745 r_symndx
= ELF32_R_SYM(irel
->r_info
);
13746 r_type
= ELF32_R_TYPE(irel
->r_info
);
13748 if (pNext
->id
!= cur_grp_id
)
13750 cur_grp_id
= pNext
->id
;
13751 org_tls_type
= get_tls_type (r_type
, NULL
);
13752 if (r_symndx
>= symtab_hdr
->sh_info
)
13754 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
13755 while (h
->root
.type
== bfd_link_hash_indirect
13756 || h
->root
.type
== bfd_link_hash_warning
)
13757 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
13758 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
13762 tls_type
= local_got_tls_type
13763 ? local_got_tls_type
[r_symndx
]
13767 eff_tls_type
= 1 << (fls (tls_type
) - 1);
13768 sethi_rt
= N32_RT5(bfd_getb32 (contents
+ irel
->r_offset
));
13771 if (eff_tls_type
!= org_tls_type
)
13773 switch (org_tls_type
)
13775 /* DESC to IEGP/IE/LE. */
13777 switch (eff_tls_type
)
13782 case R_NDS32_TLS_DESC_HI20
:
13783 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13784 R_NDS32_TLS_IE_HI20
);
13786 case R_NDS32_TLS_DESC_LO12
:
13787 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13788 R_NDS32_TLS_IE_LO12
);
13790 case R_NDS32_TLS_DESC_ADD
:
13792 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13793 add_rt
= N32_RT5 (insn
);
13794 insn
= N32_TYPE2 (LWI
, add_rt
, sethi_rt
, 0);
13795 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13797 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13800 case R_NDS32_TLS_DESC_FUNC
:
13801 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13802 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13803 R_NDS32_RELAX_REMOVE
);
13805 case R_NDS32_TLS_DESC_CALL
:
13807 uint32_t insn
= N32_ALU1(ADD
, REG_R0
, add_rt
,
13809 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13811 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13814 case R_NDS32_LOADSTORE
:
13816 case R_NDS32_PTR_RESOLVED
:
13818 case R_NDS32_LABEL
:
13828 case R_NDS32_TLS_DESC_HI20
:
13829 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13830 R_NDS32_TLS_IEGP_HI20
);
13832 case R_NDS32_TLS_DESC_LO12
:
13833 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13834 R_NDS32_TLS_IEGP_LO12
);
13836 case R_NDS32_TLS_DESC_ADD
:
13838 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13839 add_rt
= N32_RT5 (insn
);
13840 insn
= N32_MEM(LW
, add_rt
, sethi_rt
, REG_GP
, 0);
13841 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13843 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13846 case R_NDS32_TLS_DESC_FUNC
:
13847 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13848 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13849 R_NDS32_RELAX_REMOVE
);
13851 case R_NDS32_TLS_DESC_CALL
:
13853 uint32_t insn
= N32_ALU1(ADD
, REG_R0
, add_rt
,
13855 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13857 irel
->r_info
= ELF32_R_INFO(r_symndx
, R_NDS32_NONE
);
13860 case R_NDS32_LOADSTORE
:
13862 case R_NDS32_PTR_RESOLVED
:
13864 case R_NDS32_LABEL
:
13874 case R_NDS32_TLS_DESC_HI20
:
13875 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13877 case R_NDS32_TLS_DESC_LO12
:
13878 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13880 case R_NDS32_TLS_DESC_ADD
:
13882 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13884 add_rt
= N32_RT5 (insn
);
13885 insn
= N32_ALU1 (ADD
, REG_R0
, sethi_rt
, REG_TP
);
13886 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13888 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_ADD
);
13891 case R_NDS32_TLS_DESC_FUNC
:
13892 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13893 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13895 case R_NDS32_TLS_DESC_CALL
:
13896 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13897 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13899 case R_NDS32_LOADSTORE
:
13901 case R_NDS32_PTR_RESOLVED
:
13903 case R_NDS32_LABEL
:
13914 /* IEGP to IE/LE. */
13916 switch (eff_tls_type
)
13921 case R_NDS32_TLS_IEGP_HI20
:
13922 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13923 R_NDS32_TLS_IE_HI20
);
13925 case R_NDS32_TLS_IEGP_LO12
:
13926 irel
->r_info
= ELF32_R_INFO(r_symndx
,
13927 R_NDS32_TLS_IE_LO12
);
13929 case R_NDS32_PTR_RESOLVED
:
13931 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13933 add_rt
= N32_RT5 (insn
);
13934 insn
= N32_TYPE2 (LWI
, add_rt
, sethi_rt
, 0);
13935 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13938 case R_NDS32_TLS_IEGP_LW
:
13940 case R_NDS32_LOADSTORE
:
13943 case R_NDS32_LABEL
:
13953 case R_NDS32_TLS_IEGP_HI20
:
13954 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13956 case R_NDS32_TLS_IEGP_LO12
:
13957 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13959 case R_NDS32_TLS_IEGP_LW
:
13960 bfd_putb32 (INSN_NOP
, contents
+ irel
->r_offset
);
13961 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_RELAX_REMOVE
);
13963 case R_NDS32_LOADSTORE
:
13966 case R_NDS32_LABEL
:
13967 case R_NDS32_PTR_RESOLVED
:
13980 switch (eff_tls_type
)
13985 case R_NDS32_TLS_IE_HI20
:
13986 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_HI20
);
13988 case R_NDS32_TLS_IE_LO12S2
:
13990 uint32_t insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13992 add_rt
= N32_RT5 (insn
);
13993 insn
= N32_TYPE2 (ORI
, add_rt
, sethi_rt
, 0);
13994 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
13996 irel
->r_info
= ELF32_R_INFO (r_symndx
, R_NDS32_TLS_LE_LO12
);
13999 case R_NDS32_LOADSTORE
:
14002 case R_NDS32_LABEL
:
14017 pNextSig
= pNextSig
->next_sibling
;
14021 pNext
= pNext
->next
;
14025 if (pNext
->id
!= cur_grp_id
)
14027 pNext
= pNext
->next
;
14036 if (internal_relocs
!= NULL
14037 && elf_section_data (insec
)->relocs
!= internal_relocs
)
14038 free (internal_relocs
);
14040 if (contents
!= NULL
14041 && elf_section_data (insec
)->this_hdr
.contents
!= contents
)
14044 if (local_syms
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
14049 pNext
= chain
.next
;
14050 relax_group_list_t
*pDel
;
14054 pNext
= pNext
->next
;
14066 /* End TLS model conversion. */
14068 #define ELF_ARCH bfd_arch_nds32
14069 #define ELF_MACHINE_CODE EM_NDS32
14070 #define ELF_MAXPAGESIZE 0x1000
14071 #define ELF_TARGET_ID NDS32_ELF_DATA
14073 #define TARGET_BIG_SYM nds32_elf32_be_vec
14074 #define TARGET_BIG_NAME "elf32-nds32be"
14075 #define TARGET_LITTLE_SYM nds32_elf32_le_vec
14076 #define TARGET_LITTLE_NAME "elf32-nds32le"
14078 #define elf_info_to_howto nds32_info_to_howto
14079 #define elf_info_to_howto_rel nds32_info_to_howto_rel
14081 #define bfd_elf32_bfd_link_hash_table_create nds32_elf_link_hash_table_create
14082 #define bfd_elf32_bfd_merge_private_bfd_data nds32_elf_merge_private_bfd_data
14083 #define bfd_elf32_bfd_print_private_bfd_data nds32_elf_print_private_bfd_data
14084 #define bfd_elf32_bfd_relax_section nds32_elf_relax_section
14085 #define bfd_elf32_bfd_set_private_flags nds32_elf_set_private_flags
14087 #define bfd_elf32_mkobject nds32_elf_mkobject
14088 #define elf_backend_action_discarded nds32_elf_action_discarded
14089 #define elf_backend_add_symbol_hook nds32_elf_add_symbol_hook
14090 #define elf_backend_check_relocs nds32_elf_check_relocs
14091 #define elf_backend_adjust_dynamic_symbol nds32_elf_adjust_dynamic_symbol
14092 #define elf_backend_create_dynamic_sections nds32_elf_create_dynamic_sections
14093 #define elf_backend_finish_dynamic_sections nds32_elf_finish_dynamic_sections
14094 #define elf_backend_finish_dynamic_symbol nds32_elf_finish_dynamic_symbol
14095 #define elf_backend_size_dynamic_sections nds32_elf_size_dynamic_sections
14096 #define elf_backend_relocate_section nds32_elf_relocate_section
14097 #define elf_backend_gc_mark_hook nds32_elf_gc_mark_hook
14098 #define elf_backend_grok_prstatus nds32_elf_grok_prstatus
14099 #define elf_backend_grok_psinfo nds32_elf_grok_psinfo
14100 #define elf_backend_reloc_type_class nds32_elf_reloc_type_class
14101 #define elf_backend_copy_indirect_symbol nds32_elf_copy_indirect_symbol
14102 #define elf_backend_link_output_symbol_hook nds32_elf_output_symbol_hook
14103 #define elf_backend_output_arch_syms nds32_elf_output_arch_syms
14104 #define elf_backend_object_p nds32_elf_object_p
14105 #define elf_backend_final_write_processing nds32_elf_final_write_processing
14106 #define elf_backend_special_sections nds32_elf_special_sections
14107 #define bfd_elf32_bfd_get_relocated_section_contents \
14108 nds32_elf_get_relocated_section_contents
14109 #define bfd_elf32_bfd_is_target_special_symbol nds32_elf_is_target_special_symbol
14110 #define elf_backend_maybe_function_sym nds32_elf_maybe_function_sym
14112 #define elf_backend_can_gc_sections 1
14113 #define elf_backend_can_refcount 1
14114 #define elf_backend_want_got_plt 1
14115 #define elf_backend_plt_readonly 1
14116 #define elf_backend_want_plt_sym 0
14117 #define elf_backend_got_header_size 12
14118 #define elf_backend_may_use_rel_p 1
14119 #define elf_backend_default_use_rela_p 1
14120 #define elf_backend_may_use_rela_p 1
14121 #define elf_backend_dtrel_excludes_plt 0
14123 #include "elf32-target.h"
14125 #undef ELF_MAXPAGESIZE
14126 #define ELF_MAXPAGESIZE 0x2000
14128 #undef TARGET_BIG_SYM
14129 #define TARGET_BIG_SYM nds32_elf32_linux_be_vec
14130 #undef TARGET_BIG_NAME
14131 #define TARGET_BIG_NAME "elf32-nds32be-linux"
14132 #undef TARGET_LITTLE_SYM
14133 #define TARGET_LITTLE_SYM nds32_elf32_linux_le_vec
14134 #undef TARGET_LITTLE_NAME
14135 #define TARGET_LITTLE_NAME "elf32-nds32le-linux"
14137 #define elf32_bed elf32_nds32_lin_bed
14139 #include "elf32-target.h"