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 /* The nop opcode we use. */
91 #define NDS32_NOP32 0x40000009
92 #define NDS32_NOP16 0x9200
94 /* The size in bytes of an entry in the procedure linkage table. */
95 #define PLT_ENTRY_SIZE 24
96 #define PLT_HEADER_SIZE 24
98 /* The first entry in a procedure linkage table are reserved,
99 and the initial contents are unimportant (we zero them out).
100 Subsequent entries look like this. */
101 #define PLT0_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(.got+4) */
102 #define PLT0_ENTRY_WORD1 0x58f78000 /* ori r15, r25, LO12(.got+4) */
103 #define PLT0_ENTRY_WORD2 0x05178000 /* lwi r17, [r15+0] */
104 #define PLT0_ENTRY_WORD3 0x04f78001 /* lwi r15, [r15+4] */
105 #define PLT0_ENTRY_WORD4 0x4a003c00 /* jr r15 */
107 /* $ta is change to $r15 (from $r25). */
108 #define PLT0_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[1]@GOT) */
109 #define PLT0_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[1]@GOT) */
110 #define PLT0_PIC_ENTRY_WORD2 0x40f7f400 /* add r15, gp, r15 */
111 #define PLT0_PIC_ENTRY_WORD3 0x05178000 /* lwi r17, [r15+0] */
112 #define PLT0_PIC_ENTRY_WORD4 0x04f78001 /* lwi r15, [r15+4] */
113 #define PLT0_PIC_ENTRY_WORD5 0x4a003c00 /* jr r15 */
115 #define PLT_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(&got[n+3]) */
116 #define PLT_ENTRY_WORD1 0x04f78000 /* lwi r15, r15, LO12(&got[n+3]) */
117 #define PLT_ENTRY_WORD2 0x4a003c00 /* jr r15 */
118 #define PLT_ENTRY_WORD3 0x45000000 /* movi r16, sizeof(RELA) * n */
119 #define PLT_ENTRY_WORD4 0x48000000 /* j .plt0. */
121 #define PLT_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[n+3]@GOT) */
122 #define PLT_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[n+3]@GOT) */
123 #define PLT_PIC_ENTRY_WORD2 0x38febc02 /* lw r15, [gp+r15] */
124 #define PLT_PIC_ENTRY_WORD3 0x4a003c00 /* jr r15 */
125 #define PLT_PIC_ENTRY_WORD4 0x45000000 /* movi r16, sizeof(RELA) * n */
126 #define PLT_PIC_ENTRY_WORD5 0x48000000 /* j .plt0 */
128 /* These are macros used to get the relocation accurate value. */
129 #define ACCURATE_8BIT_S1 (0x100)
130 #define ACCURATE_U9BIT_S1 (0x400)
131 #define ACCURATE_12BIT_S1 (0x2000)
132 #define ACCURATE_14BIT_S1 (0x4000)
133 #define ACCURATE_19BIT (0x40000)
135 /* These are macros used to get the relocation conservative value. */
136 #define CONSERVATIVE_8BIT_S1 (0x100 - 4)
137 #define CONSERVATIVE_14BIT_S1 (0x4000 - 4)
138 #define CONSERVATIVE_16BIT_S1 (0x10000 - 4)
139 #define CONSERVATIVE_24BIT_S1 (0x1000000 - 4)
140 /* These must be more conservative because the address may be in
141 different segment. */
142 #define CONSERVATIVE_15BIT (0x4000 - 0x1000)
143 #define CONSERVATIVE_15BIT_S1 (0x8000 - 0x1000)
144 #define CONSERVATIVE_15BIT_S2 (0x10000 - 0x1000)
145 #define CONSERVATIVE_19BIT (0x40000 - 0x1000)
146 #define CONSERVATIVE_20BIT (0x80000 - 0x1000)
148 /* Size of small data/bss sections, used to calculate SDA_BASE. */
149 static long got_size
= 0;
150 static int is_SDA_BASE_set
= 0;
152 /* Convert ELF-VER in eflags to string for debugging purpose. */
153 static const char *const nds32_elfver_strtab
[] =
160 /* The nds32 linker needs to keep track of the number of relocs that it
161 decides to copy in check_relocs for each symbol. This is so that
162 it can discard PC relative relocs if it doesn't need them when
163 linking with -Bsymbolic. We store the information in a field
164 extending the regular ELF linker hash table. */
166 /* This structure keeps track of the number of PC relative relocs we
167 have copied for a given symbol. */
169 struct elf_nds32_pcrel_relocs_copied
172 struct elf_nds32_pcrel_relocs_copied
*next
;
173 /* A section in dynobj. */
175 /* Number of relocs copied in this section. */
179 /* Nds32 ELF linker hash entry. */
181 struct elf_nds32_link_hash_entry
183 struct elf_link_hash_entry root
;
185 /* Track dynamic relocs copied for this symbol. */
186 struct elf_dyn_relocs
*dyn_relocs
;
188 /* For checking relocation type. */
189 #define GOT_UNKNOWN 0
192 unsigned int tls_type
;
195 /* Get the nds32 ELF linker hash table from a link_info structure. */
197 #define FP_BASE_NAME "_FP_BASE_"
198 static int check_start_export_sym
= 0;
200 /* The offset for executable tls relaxation. */
201 #define TP_OFFSET 0x0
203 struct elf_nds32_obj_tdata
205 struct elf_obj_tdata root
;
207 /* tls_type for each local got entry. */
208 char *local_got_tls_type
;
211 #define elf_nds32_tdata(bfd) \
212 ((struct elf_nds32_obj_tdata *) (bfd)->tdata.any)
214 #define elf32_nds32_local_got_tls_type(bfd) \
215 (elf_nds32_tdata (bfd)->local_got_tls_type)
217 #define elf32_nds32_hash_entry(ent) ((struct elf_nds32_link_hash_entry *)(ent))
220 nds32_elf_mkobject (bfd
*abfd
)
222 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_nds32_obj_tdata
),
226 /* Relocations used for relocation. */
227 static reloc_howto_type nds32_elf_howto_table
[] =
229 /* This reloc does nothing. */
230 HOWTO (R_NDS32_NONE
, /* type */
232 3, /* size (0 = byte, 1 = short, 2 = long) */
234 FALSE
, /* pc_relative */
236 complain_overflow_dont
, /* complain_on_overflow */
237 bfd_elf_generic_reloc
, /* special_function */
238 "R_NDS32_NONE", /* name */
239 FALSE
, /* partial_inplace */
242 FALSE
), /* pcrel_offset */
244 /* A 16 bit absolute relocation. */
245 HOWTO (R_NDS32_16
, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 FALSE
, /* pc_relative */
251 complain_overflow_bitfield
, /* complain_on_overflow */
252 nds32_elf_generic_reloc
, /* special_function */
253 "R_NDS32_16", /* name */
254 FALSE
, /* partial_inplace */
255 0xffff, /* src_mask */
256 0xffff, /* dst_mask */
257 FALSE
), /* pcrel_offset */
259 /* A 32 bit absolute relocation. */
260 HOWTO (R_NDS32_32
, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE
, /* pc_relative */
266 complain_overflow_bitfield
, /* complain_on_overflow */
267 nds32_elf_generic_reloc
, /* special_function */
268 "R_NDS32_32", /* name */
269 FALSE
, /* partial_inplace */
270 0xffffffff, /* src_mask */
271 0xffffffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
274 /* A 20 bit address. */
275 HOWTO (R_NDS32_20
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE
, /* pc_relative */
281 complain_overflow_unsigned
, /* complain_on_overflow */
282 nds32_elf_generic_reloc
, /* special_function */
283 "R_NDS32_20", /* name */
284 FALSE
, /* partial_inplace */
285 0xfffff, /* src_mask */
286 0xfffff, /* dst_mask */
287 FALSE
), /* pcrel_offset */
289 /* An PC Relative 9-bit relocation, shifted by 2.
290 This reloc is complicated because relocations are relative to pc & -4.
291 i.e. branches in the right insn slot use the address of the left insn
293 /* ??? It's not clear whether this should have partial_inplace set or not.
294 Branch relaxing in the assembler can store the addend in the insn,
295 and if bfd_install_relocation gets called the addend may get added
297 HOWTO (R_NDS32_9_PCREL
, /* type */
299 1, /* size (0 = byte, 1 = short, 2 = long) */
301 TRUE
, /* pc_relative */
303 complain_overflow_signed
, /* complain_on_overflow */
304 nds32_elf_9_pcrel_reloc
, /* special_function */
305 "R_NDS32_9_PCREL", /* name */
306 FALSE
, /* partial_inplace */
309 TRUE
), /* pcrel_offset */
311 /* A relative 15 bit relocation, right shifted by 1. */
312 HOWTO (R_NDS32_15_PCREL
, /* type */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
316 TRUE
, /* pc_relative */
318 complain_overflow_signed
, /* complain_on_overflow */
319 bfd_elf_generic_reloc
, /* special_function */
320 "R_NDS32_15_PCREL", /* name */
321 FALSE
, /* partial_inplace */
322 0x3fff, /* src_mask */
323 0x3fff, /* dst_mask */
324 TRUE
), /* pcrel_offset */
326 /* A relative 17 bit relocation, right shifted by 1. */
327 HOWTO (R_NDS32_17_PCREL
, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 TRUE
, /* pc_relative */
333 complain_overflow_signed
, /* complain_on_overflow */
334 bfd_elf_generic_reloc
, /* special_function */
335 "R_NDS32_17_PCREL", /* name */
336 FALSE
, /* partial_inplace */
337 0xffff, /* src_mask */
338 0xffff, /* dst_mask */
339 TRUE
), /* pcrel_offset */
341 /* A relative 25 bit relocation, right shifted by 1. */
342 /* ??? It's not clear whether this should have partial_inplace set or not.
343 Branch relaxing in the assembler can store the addend in the insn,
344 and if bfd_install_relocation gets called the addend may get added
346 HOWTO (R_NDS32_25_PCREL
, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 TRUE
, /* pc_relative */
352 complain_overflow_signed
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_NDS32_25_PCREL", /* name */
355 FALSE
, /* partial_inplace */
356 0xffffff, /* src_mask */
357 0xffffff, /* dst_mask */
358 TRUE
), /* pcrel_offset */
360 /* High 20 bits of address when lower 12 is or'd in. */
361 HOWTO (R_NDS32_HI20
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE
, /* pc_relative */
367 complain_overflow_dont
,/* complain_on_overflow */
368 nds32_elf_hi20_reloc
, /* special_function */
369 "R_NDS32_HI20", /* name */
370 FALSE
, /* partial_inplace */
371 0x000fffff, /* src_mask */
372 0x000fffff, /* dst_mask */
373 FALSE
), /* pcrel_offset */
375 /* Lower 12 bits of address. */
376 HOWTO (R_NDS32_LO12S3
, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE
, /* pc_relative */
382 complain_overflow_dont
,/* complain_on_overflow */
383 nds32_elf_lo12_reloc
, /* special_function */
384 "R_NDS32_LO12S3", /* name */
385 FALSE
, /* partial_inplace */
386 0x000001ff, /* src_mask */
387 0x000001ff, /* dst_mask */
388 FALSE
), /* pcrel_offset */
390 /* Lower 12 bits of address. */
391 HOWTO (R_NDS32_LO12S2
, /* type */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
395 FALSE
, /* pc_relative */
397 complain_overflow_dont
,/* complain_on_overflow */
398 nds32_elf_lo12_reloc
, /* special_function */
399 "R_NDS32_LO12S2", /* name */
400 FALSE
, /* partial_inplace */
401 0x000003ff, /* src_mask */
402 0x000003ff, /* dst_mask */
403 FALSE
), /* pcrel_offset */
405 /* Lower 12 bits of address. */
406 HOWTO (R_NDS32_LO12S1
, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE
, /* pc_relative */
412 complain_overflow_dont
,/* complain_on_overflow */
413 nds32_elf_lo12_reloc
, /* special_function */
414 "R_NDS32_LO12S1", /* name */
415 FALSE
, /* partial_inplace */
416 0x000007ff, /* src_mask */
417 0x000007ff, /* dst_mask */
418 FALSE
), /* pcrel_offset */
420 /* Lower 12 bits of address. */
421 HOWTO (R_NDS32_LO12S0
, /* type */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
425 FALSE
, /* pc_relative */
427 complain_overflow_dont
,/* complain_on_overflow */
428 nds32_elf_lo12_reloc
, /* special_function */
429 "R_NDS32_LO12S0", /* name */
430 FALSE
, /* partial_inplace */
431 0x00000fff, /* src_mask */
432 0x00000fff, /* dst_mask */
433 FALSE
), /* pcrel_offset */
435 /* Small data area 15 bits offset. */
436 HOWTO (R_NDS32_SDA15S3
, /* type */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
440 FALSE
, /* pc_relative */
442 complain_overflow_signed
, /* complain_on_overflow */
443 nds32_elf_sda15_reloc
, /* special_function */
444 "R_NDS32_SDA15S3", /* name */
445 FALSE
, /* partial_inplace */
446 0x00007fff, /* src_mask */
447 0x00007fff, /* dst_mask */
448 FALSE
), /* pcrel_offset */
450 /* Small data area 15 bits offset. */
451 HOWTO (R_NDS32_SDA15S2
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_signed
, /* complain_on_overflow */
458 nds32_elf_sda15_reloc
, /* special_function */
459 "R_NDS32_SDA15S2", /* name */
460 FALSE
, /* partial_inplace */
461 0x00007fff, /* src_mask */
462 0x00007fff, /* dst_mask */
463 FALSE
), /* pcrel_offset */
465 /* Small data area 15 bits offset. */
466 HOWTO (R_NDS32_SDA15S1
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE
, /* pc_relative */
472 complain_overflow_signed
, /* complain_on_overflow */
473 nds32_elf_sda15_reloc
, /* special_function */
474 "R_NDS32_SDA15S1", /* name */
475 FALSE
, /* partial_inplace */
476 0x00007fff, /* src_mask */
477 0x00007fff, /* dst_mask */
478 FALSE
), /* pcrel_offset */
480 /* Small data area 15 bits offset. */
481 HOWTO (R_NDS32_SDA15S0
, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 FALSE
, /* pc_relative */
487 complain_overflow_signed
, /* complain_on_overflow */
488 nds32_elf_sda15_reloc
, /* special_function */
489 "R_NDS32_SDA15S0", /* name */
490 FALSE
, /* partial_inplace */
491 0x00007fff, /* src_mask */
492 0x00007fff, /* dst_mask */
493 FALSE
), /* pcrel_offset */
495 /* GNU extension to record C++ vtable hierarchy */
496 HOWTO (R_NDS32_GNU_VTINHERIT
, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 FALSE
, /* pc_relative */
502 complain_overflow_dont
,/* complain_on_overflow */
503 NULL
, /* special_function */
504 "R_NDS32_GNU_VTINHERIT", /* name */
505 FALSE
, /* partial_inplace */
508 FALSE
), /* pcrel_offset */
510 /* GNU extension to record C++ vtable member usage */
511 HOWTO (R_NDS32_GNU_VTENTRY
, /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE
, /* pc_relative */
517 complain_overflow_dont
,/* complain_on_overflow */
518 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
519 "R_NDS32_GNU_VTENTRY", /* name */
520 FALSE
, /* partial_inplace */
523 FALSE
), /* pcrel_offset */
525 /* A 16 bit absolute relocation. */
526 HOWTO (R_NDS32_16_RELA
, /* type */
528 1, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE
, /* pc_relative */
532 complain_overflow_bitfield
, /* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_NDS32_16_RELA", /* name */
535 FALSE
, /* partial_inplace */
536 0xffff, /* src_mask */
537 0xffff, /* dst_mask */
538 FALSE
), /* pcrel_offset */
540 /* A 32 bit absolute relocation. */
541 HOWTO (R_NDS32_32_RELA
, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 FALSE
, /* pc_relative */
547 complain_overflow_bitfield
, /* complain_on_overflow */
548 bfd_elf_generic_reloc
, /* special_function */
549 "R_NDS32_32_RELA", /* name */
550 FALSE
, /* partial_inplace */
551 0xffffffff, /* src_mask */
552 0xffffffff, /* dst_mask */
553 FALSE
), /* pcrel_offset */
555 /* A 20 bit address. */
556 HOWTO (R_NDS32_20_RELA
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE
, /* pc_relative */
562 complain_overflow_signed
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_NDS32_20_RELA", /* name */
565 FALSE
, /* partial_inplace */
566 0xfffff, /* src_mask */
567 0xfffff, /* dst_mask */
568 FALSE
), /* pcrel_offset */
570 HOWTO (R_NDS32_9_PCREL_RELA
, /* type */
572 1, /* size (0 = byte, 1 = short, 2 = long) */
574 TRUE
, /* pc_relative */
576 complain_overflow_signed
, /* complain_on_overflow */
577 bfd_elf_generic_reloc
, /* special_function */
578 "R_NDS32_9_PCREL_RELA",/* name */
579 FALSE
, /* partial_inplace */
582 TRUE
), /* pcrel_offset */
584 /* A relative 15 bit relocation, right shifted by 1. */
585 HOWTO (R_NDS32_15_PCREL_RELA
, /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 TRUE
, /* pc_relative */
591 complain_overflow_signed
, /* complain_on_overflow */
592 bfd_elf_generic_reloc
, /* special_function */
593 "R_NDS32_15_PCREL_RELA", /* name */
594 FALSE
, /* partial_inplace */
595 0x3fff, /* src_mask */
596 0x3fff, /* dst_mask */
597 TRUE
), /* pcrel_offset */
599 /* A relative 17 bit relocation, right shifted by 1. */
600 HOWTO (R_NDS32_17_PCREL_RELA
, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 TRUE
, /* pc_relative */
606 complain_overflow_signed
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 "R_NDS32_17_PCREL_RELA", /* name */
609 FALSE
, /* partial_inplace */
610 0xffff, /* src_mask */
611 0xffff, /* dst_mask */
612 TRUE
), /* pcrel_offset */
614 /* A relative 25 bit relocation, right shifted by 2. */
615 HOWTO (R_NDS32_25_PCREL_RELA
, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 TRUE
, /* pc_relative */
621 complain_overflow_signed
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_NDS32_25_PCREL_RELA", /* name */
624 FALSE
, /* partial_inplace */
625 0xffffff, /* src_mask */
626 0xffffff, /* dst_mask */
627 TRUE
), /* pcrel_offset */
629 /* High 20 bits of address when lower 16 is or'd in. */
630 HOWTO (R_NDS32_HI20_RELA
, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 FALSE
, /* pc_relative */
636 complain_overflow_dont
,/* complain_on_overflow */
637 bfd_elf_generic_reloc
, /* special_function */
638 "R_NDS32_HI20_RELA", /* name */
639 FALSE
, /* partial_inplace */
640 0x000fffff, /* src_mask */
641 0x000fffff, /* dst_mask */
642 FALSE
), /* pcrel_offset */
644 /* Lower 12 bits of address. */
645 HOWTO (R_NDS32_LO12S3_RELA
, /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 FALSE
, /* pc_relative */
651 complain_overflow_dont
,/* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 "R_NDS32_LO12S3_RELA", /* name */
654 FALSE
, /* partial_inplace */
655 0x000001ff, /* src_mask */
656 0x000001ff, /* dst_mask */
657 FALSE
), /* pcrel_offset */
659 /* Lower 12 bits of address. */
660 HOWTO (R_NDS32_LO12S2_RELA
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_dont
,/* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_NDS32_LO12S2_RELA", /* name */
669 FALSE
, /* partial_inplace */
670 0x000003ff, /* src_mask */
671 0x000003ff, /* dst_mask */
672 FALSE
), /* pcrel_offset */
674 /* Lower 12 bits of address. */
675 HOWTO (R_NDS32_LO12S1_RELA
, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_dont
,/* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_NDS32_LO12S1_RELA", /* name */
684 FALSE
, /* partial_inplace */
685 0x000007ff, /* src_mask */
686 0x000007ff, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* Lower 12 bits of address. */
690 HOWTO (R_NDS32_LO12S0_RELA
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_dont
,/* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_NDS32_LO12S0_RELA", /* name */
699 FALSE
, /* partial_inplace */
700 0x00000fff, /* src_mask */
701 0x00000fff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* Small data area 15 bits offset. */
705 HOWTO (R_NDS32_SDA15S3_RELA
, /* type */
707 2, /* size (0 = byte, 1 = short, 2 = long) */
709 FALSE
, /* pc_relative */
711 complain_overflow_signed
, /* complain_on_overflow */
712 bfd_elf_generic_reloc
, /* special_function */
713 "R_NDS32_SDA15S3_RELA",/* name */
714 FALSE
, /* partial_inplace */
715 0x00007fff, /* src_mask */
716 0x00007fff, /* dst_mask */
717 FALSE
), /* pcrel_offset */
719 /* Small data area 15 bits offset. */
720 HOWTO (R_NDS32_SDA15S2_RELA
, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE
, /* pc_relative */
726 complain_overflow_signed
, /* complain_on_overflow */
727 bfd_elf_generic_reloc
, /* special_function */
728 "R_NDS32_SDA15S2_RELA",/* name */
729 FALSE
, /* partial_inplace */
730 0x00007fff, /* src_mask */
731 0x00007fff, /* dst_mask */
732 FALSE
), /* pcrel_offset */
734 HOWTO (R_NDS32_SDA15S1_RELA
, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 FALSE
, /* pc_relative */
740 complain_overflow_signed
, /* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_NDS32_SDA15S1_RELA",/* name */
743 FALSE
, /* partial_inplace */
744 0x00007fff, /* src_mask */
745 0x00007fff, /* dst_mask */
746 FALSE
), /* pcrel_offset */
748 HOWTO (R_NDS32_SDA15S0_RELA
, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE
, /* pc_relative */
754 complain_overflow_signed
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_NDS32_SDA15S0_RELA",/* name */
757 FALSE
, /* partial_inplace */
758 0x00007fff, /* src_mask */
759 0x00007fff, /* dst_mask */
760 FALSE
), /* pcrel_offset */
762 /* GNU extension to record C++ vtable hierarchy */
763 HOWTO (R_NDS32_RELA_GNU_VTINHERIT
, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE
, /* pc_relative */
769 complain_overflow_dont
,/* complain_on_overflow */
770 NULL
, /* special_function */
771 "R_NDS32_RELA_GNU_VTINHERIT", /* name */
772 FALSE
, /* partial_inplace */
775 FALSE
), /* pcrel_offset */
777 /* GNU extension to record C++ vtable member usage */
778 HOWTO (R_NDS32_RELA_GNU_VTENTRY
, /* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_dont
,/* complain_on_overflow */
785 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
786 "R_NDS32_RELA_GNU_VTENTRY", /* name */
787 FALSE
, /* partial_inplace */
790 FALSE
), /* pcrel_offset */
792 /* Like R_NDS32_20, but referring to the GOT table entry for
794 HOWTO (R_NDS32_GOT20
, /* 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_GOT20", /* name */
803 FALSE
, /* partial_inplace */
804 0xfffff, /* src_mask */
805 0xfffff, /* dst_mask */
806 FALSE
), /* pcrel_offset */
808 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
809 entry for the symbol. */
810 HOWTO (R_NDS32_25_PLTREL
, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 TRUE
, /* pc_relative */
816 complain_overflow_signed
, /* complain_on_overflow */
817 bfd_elf_generic_reloc
, /* special_function */
818 "R_NDS32_25_PLTREL", /* name */
819 FALSE
, /* partial_inplace */
820 0xffffff, /* src_mask */
821 0xffffff, /* dst_mask */
822 TRUE
), /* pcrel_offset */
824 /* This is used only by the dynamic linker. The symbol should exist
825 both in the object being run and in some shared library. The
826 dynamic linker copies the data addressed by the symbol from the
827 shared library into the object, because the object being
828 run has to have the data at some particular address. */
829 HOWTO (R_NDS32_COPY
, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 "R_NDS32_COPY", /* name */
838 FALSE
, /* partial_inplace */
839 0xffffffff, /* src_mask */
840 0xffffffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
843 /* Like R_NDS32_20, but used when setting global offset table
845 HOWTO (R_NDS32_GLOB_DAT
, /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_bitfield
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 "R_NDS32_GLOB_DAT", /* name */
854 FALSE
, /* partial_inplace */
855 0xffffffff, /* src_mask */
856 0xffffffff, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* Marks a procedure linkage table entry for a symbol. */
860 HOWTO (R_NDS32_JMP_SLOT
, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_bitfield
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_NDS32_JMP_SLOT", /* name */
869 FALSE
, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* Used only by the dynamic linker. When the object is run, this
875 longword is set to the load address of the object, plus the
877 HOWTO (R_NDS32_RELATIVE
, /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE
, /* pc_relative */
883 complain_overflow_bitfield
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_NDS32_RELATIVE", /* name */
886 FALSE
, /* partial_inplace */
887 0xffffffff, /* src_mask */
888 0xffffffff, /* dst_mask */
889 FALSE
), /* pcrel_offset */
891 HOWTO (R_NDS32_GOTOFF
, /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE
, /* pc_relative */
897 complain_overflow_signed
, /* complain_on_overflow */
898 bfd_elf_generic_reloc
, /* special_function */
899 "R_NDS32_GOTOFF", /* name */
900 FALSE
, /* partial_inplace */
901 0xfffff, /* src_mask */
902 0xfffff, /* dst_mask */
903 FALSE
), /* pcrel_offset */
905 /* An PC Relative 20-bit relocation used when setting PIC offset
907 HOWTO (R_NDS32_GOTPC20
, /* type */
909 2, /* size (0 = byte, 1 = short, 2 = long) */
911 TRUE
, /* pc_relative */
913 complain_overflow_signed
, /* complain_on_overflow */
914 bfd_elf_generic_reloc
, /* special_function */
915 "R_NDS32_GOTPC20", /* name */
916 FALSE
, /* partial_inplace */
917 0xfffff, /* src_mask */
918 0xfffff, /* dst_mask */
919 TRUE
), /* pcrel_offset */
921 /* Like R_NDS32_HI20, but referring to the GOT table entry for
923 HOWTO (R_NDS32_GOT_HI20
, /* type */
925 2, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE
, /* pc_relative */
929 complain_overflow_dont
,/* complain_on_overflow */
930 bfd_elf_generic_reloc
, /* special_function */
931 "R_NDS32_GOT_HI20", /* name */
932 FALSE
, /* partial_inplace */
933 0x000fffff, /* src_mask */
934 0x000fffff, /* dst_mask */
935 FALSE
), /* pcrel_offset */
936 HOWTO (R_NDS32_GOT_LO12
, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_dont
,/* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 "R_NDS32_GOT_LO12", /* name */
945 FALSE
, /* partial_inplace */
946 0x00000fff, /* src_mask */
947 0x00000fff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* An PC Relative relocation used when setting PIC offset table register.
951 Like R_NDS32_HI20, but referring to the GOT table entry for
953 HOWTO (R_NDS32_GOTPC_HI20
, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE
, /* pc_relative */
959 complain_overflow_dont
,/* complain_on_overflow */
960 bfd_elf_generic_reloc
, /* special_function */
961 "R_NDS32_GOTPC_HI20", /* name */
962 FALSE
, /* partial_inplace */
963 0x000fffff, /* src_mask */
964 0x000fffff, /* dst_mask */
965 TRUE
), /* pcrel_offset */
966 HOWTO (R_NDS32_GOTPC_LO12
, /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE
, /* pc_relative */
972 complain_overflow_dont
, /* complain_on_overflow */
973 bfd_elf_generic_reloc
, /* special_function */
974 "R_NDS32_GOTPC_LO12", /* name */
975 FALSE
, /* partial_inplace */
976 0x00000fff, /* src_mask */
977 0x00000fff, /* dst_mask */
978 TRUE
), /* pcrel_offset */
980 HOWTO (R_NDS32_GOTOFF_HI20
, /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_dont
,/* complain_on_overflow */
987 bfd_elf_generic_reloc
, /* special_function */
988 "R_NDS32_GOTOFF_HI20", /* name */
989 FALSE
, /* partial_inplace */
990 0x000fffff, /* src_mask */
991 0x000fffff, /* dst_mask */
992 FALSE
), /* pcrel_offset */
993 HOWTO (R_NDS32_GOTOFF_LO12
, /* type */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE
, /* pc_relative */
999 complain_overflow_dont
,/* complain_on_overflow */
1000 bfd_elf_generic_reloc
, /* special_function */
1001 "R_NDS32_GOTOFF_LO12", /* name */
1002 FALSE
, /* partial_inplace */
1003 0x00000fff, /* src_mask */
1004 0x00000fff, /* dst_mask */
1005 FALSE
), /* pcrel_offset */
1007 /* Alignment hint for relaxable instruction. This is used with
1008 R_NDS32_LABEL as a pair. Relax this instruction from 4 bytes to 2
1009 in order to make next label aligned on word boundary. */
1010 HOWTO (R_NDS32_INSN16
, /* type */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_dont
,/* complain_on_overflow */
1017 nds32_elf_ignore_reloc
,/* special_function */
1018 "R_NDS32_INSN16", /* name */
1019 FALSE
, /* partial_inplace */
1020 0x00000fff, /* src_mask */
1021 0x00000fff, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* Alignment hint for label. */
1025 HOWTO (R_NDS32_LABEL
, /* type */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_dont
,/* complain_on_overflow */
1032 nds32_elf_ignore_reloc
,/* special_function */
1033 "R_NDS32_LABEL", /* name */
1034 FALSE
, /* partial_inplace */
1035 0xffffffff, /* src_mask */
1036 0xffffffff, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 /* Relax hint for unconditional call sequence */
1040 HOWTO (R_NDS32_LONGCALL1
, /* type */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1044 FALSE
, /* pc_relative */
1046 complain_overflow_dont
,/* complain_on_overflow */
1047 nds32_elf_ignore_reloc
,/* special_function */
1048 "R_NDS32_LONGCALL1", /* name */
1049 FALSE
, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 FALSE
), /* pcrel_offset */
1054 /* Relax hint for conditional call sequence. */
1055 HOWTO (R_NDS32_LONGCALL2
, /* type */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
,/* complain_on_overflow */
1062 nds32_elf_ignore_reloc
,/* special_function */
1063 "R_NDS32_LONGCALL2", /* name */
1064 FALSE
, /* partial_inplace */
1065 0xffffffff, /* src_mask */
1066 0xffffffff, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1069 /* Relax hint for conditional call sequence. */
1070 HOWTO (R_NDS32_LONGCALL3
, /* type */
1072 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 FALSE
, /* pc_relative */
1076 complain_overflow_dont
,/* complain_on_overflow */
1077 nds32_elf_ignore_reloc
,/* special_function */
1078 "R_NDS32_LONGCALL3", /* name */
1079 FALSE
, /* partial_inplace */
1080 0xffffffff, /* src_mask */
1081 0xffffffff, /* dst_mask */
1082 FALSE
), /* pcrel_offset */
1084 /* Relax hint for unconditional branch sequence. */
1085 HOWTO (R_NDS32_LONGJUMP1
, /* type */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE
, /* pc_relative */
1091 complain_overflow_dont
,/* complain_on_overflow */
1092 nds32_elf_ignore_reloc
,/* special_function */
1093 "R_NDS32_LONGJUMP1", /* name */
1094 FALSE
, /* partial_inplace */
1095 0xffffffff, /* src_mask */
1096 0xffffffff, /* dst_mask */
1097 FALSE
), /* pcrel_offset */
1099 /* Relax hint for conditional branch sequence. */
1100 HOWTO (R_NDS32_LONGJUMP2
, /* type */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1104 FALSE
, /* pc_relative */
1106 complain_overflow_dont
,/* complain_on_overflow */
1107 nds32_elf_ignore_reloc
,/* special_function */
1108 "R_NDS32_LONGJUMP2", /* name */
1109 FALSE
, /* partial_inplace */
1110 0xffffffff, /* src_mask */
1111 0xffffffff, /* dst_mask */
1112 FALSE
), /* pcrel_offset */
1114 /* Relax hint for conditional branch sequence. */
1115 HOWTO (R_NDS32_LONGJUMP3
, /* type */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 FALSE
, /* pc_relative */
1121 complain_overflow_dont
,/* complain_on_overflow */
1122 nds32_elf_ignore_reloc
,/* special_function */
1123 "R_NDS32_LONGJUMP3", /* name */
1124 FALSE
, /* partial_inplace */
1125 0xffffffff, /* src_mask */
1126 0xffffffff, /* dst_mask */
1127 FALSE
), /* pcrel_offset */
1129 /* Relax hint for load/store sequence. */
1130 HOWTO (R_NDS32_LOADSTORE
, /* type */
1132 2, /* size (0 = byte, 1 = short, 2 = long) */
1134 FALSE
, /* pc_relative */
1136 complain_overflow_dont
,/* complain_on_overflow */
1137 nds32_elf_ignore_reloc
,/* special_function */
1138 "R_NDS32_LOADSTORE", /* name */
1139 FALSE
, /* partial_inplace */
1140 0xffffffff, /* src_mask */
1141 0xffffffff, /* dst_mask */
1142 FALSE
), /* pcrel_offset */
1144 /* Relax hint for load/store sequence. */
1145 HOWTO (R_NDS32_9_FIXED_RELA
, /* type */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1149 FALSE
, /* pc_relative */
1151 complain_overflow_dont
,/* complain_on_overflow */
1152 nds32_elf_ignore_reloc
,/* special_function */
1153 "R_NDS32_9_FIXED_RELA",/* name */
1154 FALSE
, /* partial_inplace */
1155 0x000000ff, /* src_mask */
1156 0x000000ff, /* dst_mask */
1157 FALSE
), /* pcrel_offset */
1159 /* Relax hint for load/store sequence. */
1160 HOWTO (R_NDS32_15_FIXED_RELA
, /* type */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE
, /* pc_relative */
1166 complain_overflow_dont
,/* complain_on_overflow */
1167 nds32_elf_ignore_reloc
,/* special_function */
1168 "R_NDS32_15_FIXED_RELA", /* name */
1169 FALSE
, /* partial_inplace */
1170 0x00003fff, /* src_mask */
1171 0x00003fff, /* dst_mask */
1172 FALSE
), /* pcrel_offset */
1174 /* Relax hint for load/store sequence. */
1175 HOWTO (R_NDS32_17_FIXED_RELA
, /* type */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE
, /* pc_relative */
1181 complain_overflow_dont
,/* complain_on_overflow */
1182 nds32_elf_ignore_reloc
,/* special_function */
1183 "R_NDS32_17_FIXED_RELA", /* name */
1184 FALSE
, /* partial_inplace */
1185 0x0000ffff, /* src_mask */
1186 0x0000ffff, /* dst_mask */
1187 FALSE
), /* pcrel_offset */
1189 /* Relax hint for load/store sequence. */
1190 HOWTO (R_NDS32_25_FIXED_RELA
, /* type */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE
, /* pc_relative */
1196 complain_overflow_dont
,/* complain_on_overflow */
1197 nds32_elf_ignore_reloc
,/* special_function */
1198 "R_NDS32_25_FIXED_RELA", /* name */
1199 FALSE
, /* partial_inplace */
1200 0x00ffffff, /* src_mask */
1201 0x00ffffff, /* dst_mask */
1202 FALSE
), /* pcrel_offset */
1204 /* High 20 bits of PLT symbol offset relative to PC. */
1205 HOWTO (R_NDS32_PLTREL_HI20
, /* type */
1206 12, /* rightshift */
1207 2, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE
, /* pc_relative */
1211 complain_overflow_dont
,/* complain_on_overflow */
1212 bfd_elf_generic_reloc
, /* special_function */
1213 "R_NDS32_PLTREL_HI20", /* name */
1214 FALSE
, /* partial_inplace */
1215 0x000fffff, /* src_mask */
1216 0x000fffff, /* dst_mask */
1217 FALSE
), /* pcrel_offset */
1219 /* Low 12 bits of PLT symbol offset relative to PC. */
1220 HOWTO (R_NDS32_PLTREL_LO12
, /* type */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE
, /* pc_relative */
1226 complain_overflow_dont
,/* complain_on_overflow */
1227 bfd_elf_generic_reloc
, /* special_function */
1228 "R_NDS32_PLTREL_LO12", /* name */
1229 FALSE
, /* partial_inplace */
1230 0x00000fff, /* src_mask */
1231 0x00000fff, /* dst_mask */
1232 FALSE
), /* pcrel_offset */
1234 /* High 20 bits of PLT symbol offset relative to GOT (GP). */
1235 HOWTO (R_NDS32_PLT_GOTREL_HI20
, /* type */
1236 12, /* rightshift */
1237 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 FALSE
, /* pc_relative */
1241 complain_overflow_dont
,/* complain_on_overflow */
1242 bfd_elf_generic_reloc
, /* special_function */
1243 "R_NDS32_PLT_GOTREL_HI20", /* name */
1244 FALSE
, /* partial_inplace */
1245 0x000fffff, /* src_mask */
1246 0x000fffff, /* dst_mask */
1247 FALSE
), /* pcrel_offset */
1249 /* Low 12 bits of PLT symbol offset relative to GOT (GP). */
1250 HOWTO (R_NDS32_PLT_GOTREL_LO12
, /* type */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE
, /* pc_relative */
1256 complain_overflow_dont
,/* complain_on_overflow */
1257 bfd_elf_generic_reloc
, /* special_function */
1258 "R_NDS32_PLT_GOTREL_LO12", /* name */
1259 FALSE
, /* partial_inplace */
1260 0x00000fff, /* src_mask */
1261 0x00000fff, /* dst_mask */
1262 FALSE
), /* pcrel_offset */
1264 /* Small data area 12 bits offset. */
1265 HOWTO (R_NDS32_SDA12S2_DP_RELA
, /* type */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 FALSE
, /* pc_relative */
1271 complain_overflow_signed
, /* complain_on_overflow */
1272 bfd_elf_generic_reloc
, /* special_function */
1273 "R_NDS32_SDA12S2_DP_RELA", /* name */
1274 FALSE
, /* partial_inplace */
1275 0x00000fff, /* src_mask */
1276 0x00000fff, /* dst_mask */
1277 FALSE
), /* pcrel_offset */
1279 /* Small data area 12 bits offset. */
1280 HOWTO (R_NDS32_SDA12S2_SP_RELA
, /* type */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1284 FALSE
, /* pc_relative */
1286 complain_overflow_signed
, /* complain_on_overflow */
1287 bfd_elf_generic_reloc
, /* special_function */
1288 "R_NDS32_SDA12S2_SP_RELA", /* name */
1289 FALSE
, /* partial_inplace */
1290 0x00000fff, /* src_mask */
1291 0x00000fff, /* dst_mask */
1292 FALSE
), /* pcrel_offset */
1293 /* Lower 12 bits of address. */
1295 HOWTO (R_NDS32_LO12S2_DP_RELA
, /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_dont
,/* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 "R_NDS32_LO12S2_DP_RELA", /* name */
1304 FALSE
, /* partial_inplace */
1305 0x000003ff, /* src_mask */
1306 0x000003ff, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 /* Lower 12 bits of address. */
1310 HOWTO (R_NDS32_LO12S2_SP_RELA
,/* type */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 FALSE
, /* pc_relative */
1316 complain_overflow_dont
,/* complain_on_overflow */
1317 bfd_elf_generic_reloc
, /* special_function */
1318 "R_NDS32_LO12S2_SP_RELA", /* name */
1319 FALSE
, /* partial_inplace */
1320 0x000003ff, /* src_mask */
1321 0x000003ff, /* dst_mask */
1322 FALSE
), /* pcrel_offset */
1323 /* Lower 12 bits of address. Special identity for or case. */
1324 HOWTO (R_NDS32_LO12S0_ORI_RELA
, /* type */
1326 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 FALSE
, /* pc_relative */
1330 complain_overflow_dont
,/* complain_on_overflow */
1331 bfd_elf_generic_reloc
, /* special_function */
1332 "R_NDS32_LO12S0_ORI_RELA", /* name */
1333 FALSE
, /* partial_inplace */
1334 0x00000fff, /* src_mask */
1335 0x00000fff, /* dst_mask */
1336 FALSE
), /* pcrel_offset */
1337 /* Small data area 19 bits offset. */
1338 HOWTO (R_NDS32_SDA16S3_RELA
, /* type */
1340 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE
, /* pc_relative */
1344 complain_overflow_signed
, /* complain_on_overflow */
1345 bfd_elf_generic_reloc
, /* special_function */
1346 "R_NDS32_SDA16S3_RELA",/* name */
1347 FALSE
, /* partial_inplace */
1348 0x0000ffff, /* src_mask */
1349 0x0000ffff, /* dst_mask */
1350 FALSE
), /* pcrel_offset */
1352 /* Small data area 15 bits offset. */
1353 HOWTO (R_NDS32_SDA17S2_RELA
, /* type */
1355 2, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE
, /* pc_relative */
1359 complain_overflow_signed
, /* complain_on_overflow */
1360 bfd_elf_generic_reloc
, /* special_function */
1361 "R_NDS32_SDA17S2_RELA",/* name */
1362 FALSE
, /* partial_inplace */
1363 0x0001ffff, /* src_mask */
1364 0x0001ffff, /* dst_mask */
1365 FALSE
), /* pcrel_offset */
1367 HOWTO (R_NDS32_SDA18S1_RELA
, /* type */
1369 2, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE
, /* pc_relative */
1373 complain_overflow_signed
, /* complain_on_overflow */
1374 bfd_elf_generic_reloc
, /* special_function */
1375 "R_NDS32_SDA18S1_RELA",/* name */
1376 FALSE
, /* partial_inplace */
1377 0x0003ffff, /* src_mask */
1378 0x0003ffff, /* dst_mask */
1379 FALSE
), /* pcrel_offset */
1381 HOWTO (R_NDS32_SDA19S0_RELA
, /* type */
1383 2, /* size (0 = byte, 1 = short, 2 = long) */
1385 FALSE
, /* pc_relative */
1387 complain_overflow_signed
, /* complain_on_overflow */
1388 bfd_elf_generic_reloc
, /* special_function */
1389 "R_NDS32_SDA19S0_RELA",/* name */
1390 FALSE
, /* partial_inplace */
1391 0x0007ffff, /* src_mask */
1392 0x0007ffff, /* dst_mask */
1393 FALSE
), /* pcrel_offset */
1394 HOWTO (R_NDS32_DWARF2_OP1_RELA
, /* type */
1396 0, /* size (0 = byte, 1 = short, 2 = long) */
1398 FALSE
, /* pc_relative */
1400 complain_overflow_dont
,/* complain_on_overflow */
1401 nds32_elf_ignore_reloc
,/* special_function */
1402 "R_NDS32_DWARF2_OP1_RELA", /* name */
1403 FALSE
, /* partial_inplace */
1404 0xff, /* src_mask */
1405 0xff, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1407 HOWTO (R_NDS32_DWARF2_OP2_RELA
, /* type */
1409 1, /* size (0 = byte, 1 = short, 2 = long) */
1411 FALSE
, /* pc_relative */
1413 complain_overflow_dont
,/* complain_on_overflow */
1414 nds32_elf_ignore_reloc
,/* special_function */
1415 "R_NDS32_DWARF2_OP2_RELA", /* name */
1416 FALSE
, /* partial_inplace */
1417 0xffff, /* src_mask */
1418 0xffff, /* dst_mask */
1419 FALSE
), /* pcrel_offset */
1420 HOWTO (R_NDS32_DWARF2_LEB_RELA
, /* type */
1422 2, /* size (0 = byte, 1 = short, 2 = long) */
1424 FALSE
, /* pc_relative */
1426 complain_overflow_dont
,/* complain_on_overflow */
1427 nds32_elf_ignore_reloc
,/* special_function */
1428 "R_NDS32_DWARF2_LEB_RELA", /* name */
1429 FALSE
, /* partial_inplace */
1430 0xffffffff, /* src_mask */
1431 0xffffffff, /* dst_mask */
1432 FALSE
), /* pcrel_offset */
1433 HOWTO (R_NDS32_UPDATE_TA_RELA
,/* type */
1435 1, /* size (0 = byte, 1 = short, 2 = long) */
1437 FALSE
, /* pc_relative */
1439 complain_overflow_dont
,/* complain_on_overflow */
1440 nds32_elf_ignore_reloc
,/* special_function */
1441 "R_NDS32_UPDATE_TA_RELA", /* name */
1442 FALSE
, /* partial_inplace */
1443 0xffff, /* src_mask */
1444 0xffff, /* dst_mask */
1445 FALSE
), /* pcrel_offset */
1446 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
1447 entry for the symbol. */
1448 HOWTO (R_NDS32_9_PLTREL
, /* type */
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 TRUE
, /* pc_relative */
1454 complain_overflow_signed
, /* complain_on_overflow */
1455 bfd_elf_generic_reloc
, /* special_function */
1456 "R_NDS32_9_PLTREL", /* name */
1457 FALSE
, /* partial_inplace */
1458 0xff, /* src_mask */
1459 0xff, /* dst_mask */
1460 TRUE
), /* pcrel_offset */
1461 /* Low 20 bits of PLT symbol offset relative to GOT (GP). */
1462 HOWTO (R_NDS32_PLT_GOTREL_LO20
, /* type */
1464 2, /* size (0 = byte, 1 = short, 2 = long) */
1466 FALSE
, /* pc_relative */
1468 complain_overflow_dont
,/* complain_on_overflow */
1469 bfd_elf_generic_reloc
, /* special_function */
1470 "R_NDS32_PLT_GOTREL_LO20", /* name */
1471 FALSE
, /* partial_inplace */
1472 0x000fffff, /* src_mask */
1473 0x000fffff, /* dst_mask */
1474 FALSE
), /* pcrel_offset */
1475 /* low 15 bits of PLT symbol offset relative to GOT (GP) */
1476 HOWTO (R_NDS32_PLT_GOTREL_LO15
, /* type */
1478 2, /* size (0 = byte, 1 = short, 2 = long) */
1480 FALSE
, /* pc_relative */
1482 complain_overflow_dont
,/* complain_on_overflow */
1483 bfd_elf_generic_reloc
, /* special_function */
1484 "R_NDS32_PLT_GOTREL_LO15", /* name */
1485 FALSE
, /* partial_inplace */
1486 0x00007fff, /* src_mask */
1487 0x00007fff, /* dst_mask */
1488 FALSE
), /* pcrel_offset */
1489 /* Low 19 bits of PLT symbol offset relative to GOT (GP). */
1490 HOWTO (R_NDS32_PLT_GOTREL_LO19
, /* type */
1492 2, /* size (0 = byte, 1 = short, 2 = long) */
1494 FALSE
, /* pc_relative */
1496 complain_overflow_dont
,/* complain_on_overflow */
1497 bfd_elf_generic_reloc
, /* special_function */
1498 "R_NDS32_PLT_GOTREL_LO19", /* name */
1499 FALSE
, /* partial_inplace */
1500 0x0007ffff, /* src_mask */
1501 0x0007ffff, /* dst_mask */
1502 FALSE
), /* pcrel_offset */
1503 HOWTO (R_NDS32_GOT_LO15
, /* type */
1505 2, /* size (0 = byte, 1 = short, 2 = long) */
1507 FALSE
, /* pc_relative */
1509 complain_overflow_dont
,/* complain_on_overflow */
1510 bfd_elf_generic_reloc
, /* special_function */
1511 "R_NDS32_GOT_LO15", /* name */
1512 FALSE
, /* partial_inplace */
1513 0x00007fff, /* src_mask */
1514 0x00007fff, /* dst_mask */
1515 FALSE
), /* pcrel_offset */
1516 HOWTO (R_NDS32_GOT_LO19
, /* type */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 FALSE
, /* pc_relative */
1522 complain_overflow_dont
,/* complain_on_overflow */
1523 bfd_elf_generic_reloc
, /* special_function */
1524 "R_NDS32_GOT_LO19", /* name */
1525 FALSE
, /* partial_inplace */
1526 0x0007ffff, /* src_mask */
1527 0x0007ffff, /* dst_mask */
1528 FALSE
), /* pcrel_offset */
1529 HOWTO (R_NDS32_GOTOFF_LO15
, /* type */
1531 2, /* size (0 = byte, 1 = short, 2 = long) */
1533 FALSE
, /* pc_relative */
1535 complain_overflow_dont
,/* complain_on_overflow */
1536 bfd_elf_generic_reloc
, /* special_function */
1537 "R_NDS32_GOTOFF_LO15", /* name */
1538 FALSE
, /* partial_inplace */
1539 0x00007fff, /* src_mask */
1540 0x00007fff, /* dst_mask */
1541 FALSE
), /* pcrel_offset */
1542 HOWTO (R_NDS32_GOTOFF_LO19
, /* type */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE
, /* pc_relative */
1548 complain_overflow_dont
,/* complain_on_overflow */
1549 bfd_elf_generic_reloc
, /* special_function */
1550 "R_NDS32_GOTOFF_LO19", /* name */
1551 FALSE
, /* partial_inplace */
1552 0x0007ffff, /* src_mask */
1553 0x0007ffff, /* dst_mask */
1554 FALSE
), /* pcrel_offset */
1555 /* GOT 15 bits offset. */
1556 HOWTO (R_NDS32_GOT15S2_RELA
, /* type */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE
, /* pc_relative */
1562 complain_overflow_signed
, /* complain_on_overflow */
1563 bfd_elf_generic_reloc
, /* special_function */
1564 "R_NDS32_GOT15S2_RELA",/* name */
1565 FALSE
, /* partial_inplace */
1566 0x00007fff, /* src_mask */
1567 0x00007fff, /* dst_mask */
1568 FALSE
), /* pcrel_offset */
1569 /* GOT 17 bits offset. */
1570 HOWTO (R_NDS32_GOT17S2_RELA
, /* type */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE
, /* pc_relative */
1576 complain_overflow_signed
, /* complain_on_overflow */
1577 bfd_elf_generic_reloc
, /* special_function */
1578 "R_NDS32_GOT17S2_RELA",/* name */
1579 FALSE
, /* partial_inplace */
1580 0x0001ffff, /* src_mask */
1581 0x0001ffff, /* dst_mask */
1582 FALSE
), /* pcrel_offset */
1583 /* A 5 bit address. */
1584 HOWTO (R_NDS32_5_RELA
, /* type */
1586 1, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE
, /* pc_relative */
1590 complain_overflow_signed
, /* complain_on_overflow */
1591 bfd_elf_generic_reloc
, /* special_function */
1592 "R_NDS32_5_RELA", /* name */
1593 FALSE
, /* partial_inplace */
1594 0x1f, /* src_mask */
1595 0x1f, /* dst_mask */
1596 FALSE
), /* pcrel_offset */
1597 HOWTO (R_NDS32_10_UPCREL_RELA
,/* type */
1599 1, /* size (0 = byte, 1 = short, 2 = long) */
1601 TRUE
, /* pc_relative */
1603 complain_overflow_unsigned
, /* complain_on_overflow */
1604 bfd_elf_generic_reloc
, /* special_function */
1605 "R_NDS32_10_UPCREL_RELA", /* name */
1606 FALSE
, /* partial_inplace */
1607 0x1ff, /* src_mask */
1608 0x1ff, /* dst_mask */
1609 TRUE
), /* pcrel_offset */
1610 HOWTO (R_NDS32_SDA_FP7U2_RELA
,/* type */
1612 1, /* size (0 = byte, 1 = short, 2 = long) */
1614 FALSE
, /* pc_relative */
1616 complain_overflow_unsigned
, /* complain_on_overflow */
1617 bfd_elf_generic_reloc
, /* special_function */
1618 "R_NDS32_SDA_FP7U2_RELA", /* name */
1619 FALSE
, /* partial_inplace */
1620 0x0000007f, /* src_mask */
1621 0x0000007f, /* dst_mask */
1622 FALSE
), /* pcrel_offset */
1623 HOWTO (R_NDS32_WORD_9_PCREL_RELA
, /* type */
1625 2, /* size (0 = byte, 1 = short, 2 = long) */
1627 TRUE
, /* pc_relative */
1629 complain_overflow_signed
, /* complain_on_overflow */
1630 bfd_elf_generic_reloc
, /* special_function */
1631 "R_NDS32_WORD_9_PCREL_RELA", /* name */
1632 FALSE
, /* partial_inplace */
1633 0xff, /* src_mask */
1634 0xff, /* dst_mask */
1635 TRUE
), /* pcrel_offset */
1636 HOWTO (R_NDS32_25_ABS_RELA
, /* type */
1638 2, /* size (0 = byte, 1 = short, 2 = long) */
1640 FALSE
, /* pc_relative */
1642 complain_overflow_dont
,/* complain_on_overflow */
1643 bfd_elf_generic_reloc
, /* special_function */
1644 "R_NDS32_25_ABS_RELA", /* name */
1645 FALSE
, /* partial_inplace */
1646 0xffffff, /* src_mask */
1647 0xffffff, /* dst_mask */
1648 FALSE
), /* pcrel_offset */
1650 /* A relative 17 bit relocation for ifc, right shifted by 1. */
1651 HOWTO (R_NDS32_17IFC_PCREL_RELA
, /* type */
1653 2, /* size (0 = byte, 1 = short, 2 = long) */
1655 TRUE
, /* pc_relative */
1657 complain_overflow_signed
, /* complain_on_overflow */
1658 bfd_elf_generic_reloc
, /* special_function */
1659 "R_NDS32_17IFC_PCREL_RELA", /* name */
1660 FALSE
, /* partial_inplace */
1661 0xffff, /* src_mask */
1662 0xffff, /* dst_mask */
1663 TRUE
), /* pcrel_offset */
1665 /* A relative unsigned 10 bit relocation for ifc, right shifted by 1. */
1666 HOWTO (R_NDS32_10IFCU_PCREL_RELA
, /* type */
1668 1, /* size (0 = byte, 1 = short, 2 = long) */
1670 TRUE
, /* pc_relative */
1672 complain_overflow_unsigned
, /* complain_on_overflow */
1673 bfd_elf_generic_reloc
, /* special_function */
1674 "R_NDS32_10IFCU_PCREL_RELA", /* name */
1675 FALSE
, /* partial_inplace */
1676 0x1ff, /* src_mask */
1677 0x1ff, /* dst_mask */
1678 TRUE
), /* pcrel_offset */
1680 /* Like R_NDS32_HI20, but referring to the TLS entry for the symbol. */
1681 HOWTO (R_NDS32_TLS_LE_HI20
, /* type */
1682 12, /* rightshift */
1683 2, /* size (0 = byte, 1 = short, 2 = long) */
1685 FALSE
, /* pc_relative */
1687 complain_overflow_dont
, /* complain_on_overflow */
1688 bfd_elf_generic_reloc
, /* special_function */
1689 "R_NDS32_TLS_LE_HI20", /* name */
1690 FALSE
, /* partial_inplace */
1691 0x000fffff, /* src_mask */
1692 0x000fffff, /* dst_mask */
1693 FALSE
), /* pcrel_offset */
1694 HOWTO (R_NDS32_TLS_LE_LO12
, /* type */
1696 2, /* size (0 = byte, 1 = short, 2 = long) */
1698 FALSE
, /* pc_relative */
1700 complain_overflow_dont
, /* complain_on_overflow */
1701 bfd_elf_generic_reloc
, /* special_function */
1702 "R_NDS32_TLS_LE_LO12", /* name */
1703 FALSE
, /* partial_inplace */
1704 0x00000fff, /* src_mask */
1705 0x00000fff, /* dst_mask */
1706 FALSE
), /* pcrel_offset */
1708 /* Like R_NDS32_HI20, but referring to the TLS entry for the symbol. */
1709 HOWTO (R_NDS32_TLS_IE_HI20
, /* type */
1710 12, /* rightshift */
1711 2, /* size (0 = byte, 1 = short, 2 = long) */
1713 FALSE
, /* pc_relative */
1715 complain_overflow_dont
, /* complain_on_overflow */
1716 bfd_elf_generic_reloc
, /* special_function */
1717 "R_NDS32_TLS_IE_HI20", /* name */
1718 FALSE
, /* partial_inplace */
1719 0x000fffff, /* src_mask */
1720 0x000fffff, /* dst_mask */
1721 FALSE
), /* pcrel_offset */
1722 HOWTO (R_NDS32_TLS_IE_LO12S2
, /* type */
1724 2, /* size (0 = byte, 1 = short, 2 = long) */
1726 FALSE
, /* pc_relative */
1728 complain_overflow_dont
, /* complain_on_overflow */
1729 bfd_elf_generic_reloc
, /* special_function */
1730 "R_NDS32_TLS_IE_LO12S2", /* name */
1731 FALSE
, /* partial_inplace */
1732 0x000003ff, /* src_mask */
1733 0x000003ff, /* dst_mask */
1734 FALSE
), /* pcrel_offset */
1735 /* Mark a TLS IE entry in GOT. */
1736 HOWTO (R_NDS32_TLS_TPOFF
, /* type */
1738 2, /* size (0 = byte, 1 = short, 2 = long) */
1740 FALSE
, /* pc_relative */
1742 complain_overflow_bitfield
, /* complain_on_overflow */
1743 bfd_elf_generic_reloc
, /* special_function */
1744 "R_NDS32_TLS_TPOFF", /* name */
1745 FALSE
, /* partial_inplace */
1746 0xffffffff, /* src_mask */
1747 0xffffffff, /* dst_mask */
1748 FALSE
), /* pcrel_offset */
1749 /* A 20 bit address. */
1750 HOWTO (R_NDS32_TLS_LE_20
, /* type */
1752 2, /* size (0 = byte, 1 = short, 2 = long) */
1754 FALSE
, /* pc_relative */
1756 complain_overflow_signed
, /* complain_on_overflow */
1757 bfd_elf_generic_reloc
, /* special_function */
1758 "R_NDS32_TLS_LE_20", /* name */
1759 FALSE
, /* partial_inplace */
1760 0xfffff, /* src_mask */
1761 0xfffff, /* dst_mask */
1762 FALSE
), /* pcrel_offset */
1763 HOWTO (R_NDS32_TLS_LE_15S0
, /* type */
1765 2, /* size (0 = byte, 1 = short, 2 = long) */
1767 FALSE
, /* pc_relative */
1769 complain_overflow_signed
, /* complain_on_overflow */
1770 bfd_elf_generic_reloc
, /* special_function */
1771 "R_NDS32_TLS_LE_15S0", /* name */
1772 FALSE
, /* partial_inplace */
1773 0x7fff, /* src_mask */
1774 0x7fff, /* dst_mask */
1775 FALSE
), /* pcrel_offset */
1776 HOWTO (R_NDS32_TLS_LE_15S1
, /* type */
1778 2, /* size (0 = byte, 1 = short, 2 = long) */
1780 FALSE
, /* pc_relative */
1782 complain_overflow_signed
, /* complain_on_overflow */
1783 bfd_elf_generic_reloc
, /* special_function */
1784 "R_NDS32_TLS_LE_15S1", /* name */
1785 FALSE
, /* partial_inplace */
1786 0x7fff, /* src_mask */
1787 0x7fff, /* dst_mask */
1788 FALSE
), /* pcrel_offset */
1789 HOWTO (R_NDS32_TLS_LE_15S2
, /* type */
1791 2, /* size (0 = byte, 1 = short, 2 = long) */
1793 FALSE
, /* pc_relative */
1795 complain_overflow_signed
, /* complain_on_overflow */
1796 bfd_elf_generic_reloc
, /* special_function */
1797 "R_NDS32_TLS_LE_15S2", /* name */
1798 FALSE
, /* partial_inplace */
1799 0x7fff, /* src_mask */
1800 0x7fff, /* dst_mask */
1801 FALSE
), /* pcrel_offset */
1803 /* Relax hint for unconditional call sequence */
1804 HOWTO (R_NDS32_LONGCALL4
, /* type */
1806 2, /* size (0 = byte, 1 = short, 2 = long) */
1808 FALSE
, /* pc_relative */
1810 complain_overflow_dont
, /* complain_on_overflow */
1811 nds32_elf_ignore_reloc
, /* special_function */
1812 "R_NDS32_LONGCALL4", /* name */
1813 FALSE
, /* partial_inplace */
1814 0xffffffff, /* src_mask */
1815 0xffffffff, /* dst_mask */
1816 FALSE
), /* pcrel_offset */
1818 /* Relax hint for conditional call sequence. */
1819 HOWTO (R_NDS32_LONGCALL5
, /* type */
1821 2, /* size (0 = byte, 1 = short, 2 = long) */
1823 FALSE
, /* pc_relative */
1825 complain_overflow_dont
, /* complain_on_overflow */
1826 nds32_elf_ignore_reloc
, /* special_function */
1827 "R_NDS32_LONGCALL5", /* name */
1828 FALSE
, /* partial_inplace */
1829 0xffffffff, /* src_mask */
1830 0xffffffff, /* dst_mask */
1831 FALSE
), /* pcrel_offset */
1833 /* Relax hint for conditional call sequence. */
1834 HOWTO (R_NDS32_LONGCALL6
, /* type */
1836 2, /* size (0 = byte, 1 = short, 2 = long) */
1838 FALSE
, /* pc_relative */
1840 complain_overflow_dont
, /* complain_on_overflow */
1841 nds32_elf_ignore_reloc
, /* special_function */
1842 "R_NDS32_LONGCALL6", /* name */
1843 FALSE
, /* partial_inplace */
1844 0xffffffff, /* src_mask */
1845 0xffffffff, /* dst_mask */
1846 FALSE
), /* pcrel_offset */
1848 /* Relax hint for unconditional branch sequence. */
1849 HOWTO (R_NDS32_LONGJUMP4
, /* type */
1851 2, /* size (0 = byte, 1 = short, 2 = long) */
1853 FALSE
, /* pc_relative */
1855 complain_overflow_dont
, /* complain_on_overflow */
1856 nds32_elf_ignore_reloc
, /* special_function */
1857 "R_NDS32_LONGJUMP4", /* name */
1858 FALSE
, /* partial_inplace */
1859 0xffffffff, /* src_mask */
1860 0xffffffff, /* dst_mask */
1861 FALSE
), /* pcrel_offset */
1863 /* Relax hint for conditional branch sequence. */
1864 HOWTO (R_NDS32_LONGJUMP5
, /* type */
1866 2, /* size (0 = byte, 1 = short, 2 = long) */
1868 FALSE
, /* pc_relative */
1870 complain_overflow_dont
, /* complain_on_overflow */
1871 nds32_elf_ignore_reloc
, /* special_function */
1872 "R_NDS32_LONGJUMP5", /* name */
1873 FALSE
, /* partial_inplace */
1874 0xffffffff, /* src_mask */
1875 0xffffffff, /* dst_mask */
1876 FALSE
), /* pcrel_offset */
1878 /* Relax hint for conditional branch sequence. */
1879 HOWTO (R_NDS32_LONGJUMP6
, /* type */
1881 2, /* size (0 = byte, 1 = short, 2 = long) */
1883 FALSE
, /* pc_relative */
1885 complain_overflow_dont
, /* complain_on_overflow */
1886 nds32_elf_ignore_reloc
, /* special_function */
1887 "R_NDS32_LONGJUMP6", /* name */
1888 FALSE
, /* partial_inplace */
1889 0xffffffff, /* src_mask */
1890 0xffffffff, /* dst_mask */
1891 FALSE
), /* pcrel_offset */
1893 /* Relax hint for conditional branch sequence. */
1894 HOWTO (R_NDS32_LONGJUMP7
, /* type */
1896 2, /* size (0 = byte, 1 = short, 2 = long) */
1898 FALSE
, /* pc_relative */
1900 complain_overflow_dont
, /* complain_on_overflow */
1901 nds32_elf_ignore_reloc
, /* special_function */
1902 "R_NDS32_LONGJUMP7", /* name */
1903 FALSE
, /* partial_inplace */
1904 0xffffffff, /* src_mask */
1905 0xffffffff, /* dst_mask */
1906 FALSE
), /* pcrel_offset */
1909 /* Relocations used for relaxation. */
1910 static reloc_howto_type nds32_elf_relax_howto_table
[] =
1912 HOWTO (R_NDS32_RELAX_ENTRY
, /* type */
1914 2, /* size (0 = byte, 1 = short, 2 = long) */
1916 FALSE
, /* pc_relative */
1918 complain_overflow_dont
,/* complain_on_overflow */
1919 nds32_elf_ignore_reloc
,/* special_function */
1920 "R_NDS32_RELAX_ENTRY", /* name */
1921 FALSE
, /* partial_inplace */
1922 0xffffffff, /* src_mask */
1923 0xffffffff, /* dst_mask */
1924 FALSE
), /* pcrel_offset */
1925 HOWTO (R_NDS32_GOT_SUFF
, /* type */
1927 2, /* size (0 = byte, 1 = short, 2 = long) */
1929 FALSE
, /* pc_relative */
1931 complain_overflow_dont
,/* complain_on_overflow */
1932 nds32_elf_ignore_reloc
,/* special_function */
1933 "R_NDS32_GOT_SUFF", /* name */
1934 FALSE
, /* partial_inplace */
1935 0xffffffff, /* src_mask */
1936 0xffffffff, /* dst_mask */
1937 FALSE
), /* pcrel_offset */
1938 HOWTO (R_NDS32_GOTOFF_SUFF
, /* type */
1940 2, /* size (0 = byte, 1 = short, 2 = long) */
1942 FALSE
, /* pc_relative */
1944 complain_overflow_bitfield
, /* complain_on_overflow */
1945 nds32_elf_ignore_reloc
,/* special_function */
1946 "R_NDS32_GOTOFF_SUFF", /* name */
1947 FALSE
, /* partial_inplace */
1948 0xffffffff, /* src_mask */
1949 0xffffffff, /* dst_mask */
1950 FALSE
), /* pcrel_offset */
1951 HOWTO (R_NDS32_PLT_GOT_SUFF
, /* type */
1953 2, /* size (0 = byte, 1 = short, 2 = long) */
1955 FALSE
, /* pc_relative */
1957 complain_overflow_dont
,/* complain_on_overflow */
1958 nds32_elf_ignore_reloc
,/* special_function */
1959 "R_NDS32_PLT_GOT_SUFF",/* name */
1960 FALSE
, /* partial_inplace */
1961 0xffffffff, /* src_mask */
1962 0xffffffff, /* dst_mask */
1963 FALSE
), /* pcrel_offset */
1964 HOWTO (R_NDS32_MULCALL_SUFF
, /* type */
1966 2, /* size (0 = byte, 1 = short, 2 = long) */
1968 FALSE
, /* pc_relative */
1970 complain_overflow_dont
,/* complain_on_overflow */
1971 nds32_elf_ignore_reloc
,/* special_function */
1972 "R_NDS32_MULCALL_SUFF",/* name */
1973 FALSE
, /* partial_inplace */
1974 0xffffffff, /* src_mask */
1975 0xffffffff, /* dst_mask */
1976 FALSE
), /* pcrel_offset */
1977 HOWTO (R_NDS32_PTR
, /* type */
1979 2, /* size (0 = byte, 1 = short, 2 = long) */
1981 FALSE
, /* pc_relative */
1983 complain_overflow_dont
,/* complain_on_overflow */
1984 nds32_elf_ignore_reloc
,/* special_function */
1985 "R_NDS32_PTR", /* name */
1986 FALSE
, /* partial_inplace */
1987 0xffffffff, /* src_mask */
1988 0xffffffff, /* dst_mask */
1989 FALSE
), /* pcrel_offset */
1990 HOWTO (R_NDS32_PTR_COUNT
, /* type */
1992 2, /* size (0 = byte, 1 = short, 2 = long) */
1994 FALSE
, /* pc_relative */
1996 complain_overflow_dont
,/* complain_on_overflow */
1997 nds32_elf_ignore_reloc
,/* special_function */
1998 "R_NDS32_PTR_COUNT", /* name */
1999 FALSE
, /* partial_inplace */
2000 0xffffffff, /* src_mask */
2001 0xffffffff, /* dst_mask */
2002 FALSE
), /* pcrel_offset */
2003 HOWTO (R_NDS32_PTR_RESOLVED
, /* type */
2005 2, /* size (0 = byte, 1 = short, 2 = long) */
2007 FALSE
, /* pc_relative */
2009 complain_overflow_dont
,/* complain_on_overflow */
2010 nds32_elf_ignore_reloc
,/* special_function */
2011 "R_NDS32_PTR_RESOLVED",/* name */
2012 FALSE
, /* partial_inplace */
2013 0xffffffff, /* src_mask */
2014 0xffffffff, /* dst_mask */
2015 FALSE
), /* pcrel_offset */
2016 HOWTO (R_NDS32_PLTBLOCK
, /* type */
2018 2, /* size (0 = byte, 1 = short, 2 = long) */
2020 FALSE
, /* pc_relative */
2022 complain_overflow_dont
,/* complain_on_overflow */
2023 nds32_elf_ignore_reloc
,/* special_function */
2024 "R_NDS32_PLTBLOCK", /* name */
2025 FALSE
, /* partial_inplace */
2026 0xffffffff, /* src_mask */
2027 0xffffffff, /* dst_mask */
2028 FALSE
), /* pcrel_offset */
2029 HOWTO (R_NDS32_RELAX_REGION_BEGIN
, /* type */
2031 2, /* size (0 = byte, 1 = short, 2 = long) */
2033 FALSE
, /* pc_relative */
2035 complain_overflow_dont
,/* complain_on_overflow */
2036 nds32_elf_ignore_reloc
,/* special_function */
2037 "R_NDS32_RELAX_REGION_BEGIN", /* name */
2038 FALSE
, /* partial_inplace */
2039 0xffffffff, /* src_mask */
2040 0xffffffff, /* dst_mask */
2041 FALSE
), /* pcrel_offset */
2042 HOWTO (R_NDS32_RELAX_REGION_END
, /* type */
2044 2, /* size (0 = byte, 1 = short, 2 = long) */
2046 FALSE
, /* pc_relative */
2048 complain_overflow_dont
,/* complain_on_overflow */
2049 nds32_elf_ignore_reloc
,/* special_function */
2050 "R_NDS32_RELAX_REGION_END", /* name */
2051 FALSE
, /* partial_inplace */
2052 0xffffffff, /* src_mask */
2053 0xffffffff, /* dst_mask */
2054 FALSE
), /* pcrel_offset */
2055 HOWTO (R_NDS32_MINUEND
, /* type */
2057 2, /* size (0 = byte, 1 = short, 2 = long) */
2059 FALSE
, /* pc_relative */
2061 complain_overflow_dont
,/* complain_on_overflow */
2062 nds32_elf_ignore_reloc
,/* special_function */
2063 "R_NDS32_MINUEND", /* name */
2064 FALSE
, /* partial_inplace */
2065 0xffffffff, /* src_mask */
2066 0xffffffff, /* dst_mask */
2067 FALSE
), /* pcrel_offset */
2068 HOWTO (R_NDS32_SUBTRAHEND
, /* type */
2070 2, /* size (0 = byte, 1 = short, 2 = long) */
2072 FALSE
, /* pc_relative */
2074 complain_overflow_dont
,/* complain_on_overflow */
2075 nds32_elf_ignore_reloc
,/* special_function */
2076 "R_NDS32_SUBTRAHEND", /* name */
2077 FALSE
, /* partial_inplace */
2078 0xffffffff, /* src_mask */
2079 0xffffffff, /* dst_mask */
2080 FALSE
), /* pcrel_offset */
2081 HOWTO (R_NDS32_DIFF8
, /* type */
2083 0, /* size (0 = byte, 1 = short, 2 = long) */
2085 FALSE
, /* pc_relative */
2087 complain_overflow_dont
,/* complain_on_overflow */
2088 nds32_elf_ignore_reloc
,/* special_function */
2089 "R_NDS32_DIFF8", /* name */
2090 FALSE
, /* partial_inplace */
2091 0x000000ff, /* src_mask */
2092 0x000000ff, /* dst_mask */
2093 FALSE
), /* pcrel_offset */
2094 HOWTO (R_NDS32_DIFF16
, /* type */
2096 1, /* size (0 = byte, 1 = short, 2 = long) */
2098 FALSE
, /* pc_relative */
2100 complain_overflow_dont
,/* complain_on_overflow */
2101 nds32_elf_ignore_reloc
,/* special_function */
2102 "R_NDS32_DIFF16", /* name */
2103 FALSE
, /* partial_inplace */
2104 0x0000ffff, /* src_mask */
2105 0x0000ffff, /* dst_mask */
2106 FALSE
), /* pcrel_offset */
2107 HOWTO (R_NDS32_DIFF32
, /* type */
2109 2, /* size (0 = byte, 1 = short, 2 = long) */
2111 FALSE
, /* pc_relative */
2113 complain_overflow_dont
,/* complain_on_overflow */
2114 nds32_elf_ignore_reloc
,/* special_function */
2115 "R_NDS32_DIFF32", /* name */
2116 FALSE
, /* partial_inplace */
2117 0xffffffff, /* src_mask */
2118 0xffffffff, /* dst_mask */
2119 FALSE
), /* pcrel_offset */
2120 HOWTO (R_NDS32_DIFF_ULEB128
, /* type */
2122 0, /* size (0 = byte, 1 = short, 2 = long) */
2124 FALSE
, /* pc_relative */
2126 complain_overflow_dont
,/* complain_on_overflow */
2127 nds32_elf_ignore_reloc
,/* special_function */
2128 "R_NDS32_DIFF_ULEB128",/* name */
2129 FALSE
, /* partial_inplace */
2130 0xffffffff, /* src_mask */
2131 0xffffffff, /* dst_mask */
2132 FALSE
), /* pcrel_offset */
2133 HOWTO (R_NDS32_DATA
, /* type */
2135 2, /* size (0 = byte, 1 = short, 2 = long) */
2137 FALSE
, /* pc_relative */
2139 complain_overflow_dont
,/* complain_on_overflow */
2140 nds32_elf_ignore_reloc
,/* special_function */
2141 "R_NDS32_DATA", /* name */
2142 FALSE
, /* partial_inplace */
2143 0xffffffff, /* src_mask */
2144 0xffffffff, /* dst_mask */
2145 FALSE
), /* pcrel_offset */
2146 HOWTO (R_NDS32_TRAN
, /* type */
2148 2, /* size (0 = byte, 1 = short, 2 = long) */
2150 FALSE
, /* pc_relative */
2152 complain_overflow_dont
,/* complain_on_overflow */
2153 nds32_elf_ignore_reloc
,/* special_function */
2154 "R_NDS32_TRAN", /* name */
2155 FALSE
, /* partial_inplace */
2156 0xffffffff, /* src_mask */
2157 0xffffffff, /* dst_mask */
2158 FALSE
), /* pcrel_offset */
2159 HOWTO (R_NDS32_TLS_LE_ADD
, /* type */
2161 2, /* size (0 = byte, 1 = short, 2 = long) */
2163 FALSE
, /* pc_relative */
2165 complain_overflow_dont
, /* complain_on_overflow */
2166 nds32_elf_ignore_reloc
, /* special_function */
2167 "R_NDS32_TLS_LE_ADD", /* name */
2168 FALSE
, /* partial_inplace */
2169 0xffffffff, /* src_mask */
2170 0xffffffff, /* dst_mask */
2171 FALSE
), /* pcrel_offset */
2172 HOWTO (R_NDS32_TLS_LE_LS
, /* type */
2174 2, /* size (0 = byte, 1 = short, 2 = long) */
2176 FALSE
, /* pc_relative */
2178 complain_overflow_dont
, /* complain_on_overflow */
2179 nds32_elf_ignore_reloc
, /* special_function */
2180 "R_NDS32_TLS_LE_LS", /* name */
2181 FALSE
, /* partial_inplace */
2182 0xffffffff, /* src_mask */
2183 0xffffffff, /* dst_mask */
2184 FALSE
), /* pcrel_offset */
2185 HOWTO (R_NDS32_EMPTY
, /* type */
2187 2, /* size (0 = byte, 1 = short, 2 = long) */
2189 FALSE
, /* pc_relative */
2191 complain_overflow_dont
, /* complain_on_overflow */
2192 nds32_elf_ignore_reloc
, /* special_function */
2193 "R_NDS32_EMPTY", /* name */
2194 FALSE
, /* partial_inplace */
2195 0xffffffff, /* src_mask */
2196 0xffffffff, /* dst_mask */
2197 FALSE
), /* pcrel_offset */
2201 /* nds32_insertion_sort sorts an array with nmemb elements of size size.
2202 This prototype is the same as qsort (). */
2205 nds32_insertion_sort (void *base
, size_t nmemb
, size_t size
,
2206 int (*compar
) (const void *lhs
, const void *rhs
))
2208 char *ptr
= (char *) base
;
2210 char *tmp
= xmalloc (size
);
2212 /* If i is less than j, i is inserted before j.
2214 |---- j ----- i --------------|
2219 for (i
= 1; i
< (int) nmemb
; i
++)
2221 for (j
= (i
- 1); j
>= 0; j
--)
2222 if (compar (ptr
+ i
* size
, ptr
+ j
* size
) >= 0)
2228 continue; /* i is in order. */
2230 memcpy (tmp
, ptr
+ i
* size
, size
);
2231 memmove (ptr
+ (j
+ 1) * size
, ptr
+ j
* size
, (i
- j
) * size
);
2232 memcpy (ptr
+ j
* size
, tmp
, size
);
2237 /* Sort relocation by r_offset.
2239 We didn't use qsort () in stdlib, because quick-sort is not a stable sorting
2240 algorithm. Relocations at the same r_offset must keep their order.
2241 For example, RELAX_ENTRY must be the very first relocation entry.
2243 Currently, this function implements insertion-sort.
2245 FIXME: If we already sort them in assembler, why bother sort them
2249 compar_reloc (const void *lhs
, const void *rhs
)
2251 const Elf_Internal_Rela
*l
= (const Elf_Internal_Rela
*) lhs
;
2252 const Elf_Internal_Rela
*r
= (const Elf_Internal_Rela
*) rhs
;
2254 if (l
->r_offset
> r
->r_offset
)
2256 else if (l
->r_offset
== r
->r_offset
)
2262 /* Functions listed below are only used for old relocs.
2263 * nds32_elf_9_pcrel_reloc
2264 * nds32_elf_do_9_pcrel_reloc
2265 * nds32_elf_hi20_reloc
2266 * nds32_elf_relocate_hi20
2267 * nds32_elf_lo12_reloc
2268 * nds32_elf_sda15_reloc
2269 * nds32_elf_generic_reloc
2272 /* Handle the R_NDS32_9_PCREL & R_NDS32_9_PCREL_RELA reloc. */
2274 static bfd_reloc_status_type
2275 nds32_elf_9_pcrel_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2276 void *data
, asection
*input_section
, bfd
*output_bfd
,
2277 char **error_message ATTRIBUTE_UNUSED
)
2279 /* This part is from bfd_elf_generic_reloc. */
2280 if (output_bfd
!= (bfd
*) NULL
2281 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2282 && (!reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
2284 reloc_entry
->address
+= input_section
->output_offset
;
2285 return bfd_reloc_ok
;
2288 if (output_bfd
!= NULL
)
2290 /* FIXME: See bfd_perform_relocation. Is this right? */
2291 return bfd_reloc_continue
;
2294 return nds32_elf_do_9_pcrel_reloc (abfd
, reloc_entry
->howto
,
2296 data
, reloc_entry
->address
,
2299 + symbol
->section
->output_section
->vma
2300 + symbol
->section
->output_offset
),
2301 reloc_entry
->addend
);
2304 /* Utility to actually perform an R_NDS32_9_PCREL reloc. */
2305 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
2307 static bfd_reloc_status_type
2308 nds32_elf_do_9_pcrel_reloc (bfd
*abfd
, reloc_howto_type
*howto
,
2309 asection
*input_section
, bfd_byte
*data
,
2311 asection
*symbol_section ATTRIBUTE_UNUSED
,
2312 bfd_vma symbol_value
, bfd_vma addend
)
2314 bfd_signed_vma relocation
;
2316 bfd_reloc_status_type status
;
2318 /* Sanity check the address (offset in section). */
2319 if (offset
> bfd_get_section_limit (abfd
, input_section
))
2320 return bfd_reloc_outofrange
;
2322 relocation
= symbol_value
+ addend
;
2323 /* Make it pc relative. */
2324 relocation
-= (input_section
->output_section
->vma
2325 + input_section
->output_offset
);
2326 /* These jumps mask off the lower two bits of the current address
2327 before doing pcrel calculations. */
2328 relocation
-= (offset
& -(bfd_vma
) 2);
2330 if (relocation
< -ACCURATE_8BIT_S1
|| relocation
>= ACCURATE_8BIT_S1
)
2331 status
= bfd_reloc_overflow
;
2333 status
= bfd_reloc_ok
;
2335 x
= bfd_getb16 (data
+ offset
);
2337 relocation
>>= howto
->rightshift
;
2338 relocation
<<= howto
->bitpos
;
2339 x
= (x
& ~howto
->dst_mask
)
2340 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
);
2342 bfd_putb16 ((bfd_vma
) x
, data
+ offset
);
2347 /* Handle the R_NDS32_HI20_[SU]LO relocs.
2348 HI20_SLO is for the add3 and load/store with displacement instructions.
2349 HI20 is for the or3 instruction.
2350 For R_NDS32_HI20_SLO, the lower 16 bits are sign extended when added to
2351 the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
2352 we must add one to the high 16 bytes (which will get subtracted off when
2353 the low 16 bits are added).
2354 These relocs have to be done in combination with an R_NDS32_LO12 reloc
2355 because there is a carry from the LO12 to the HI20. Here we just save
2356 the information we need; we do the actual relocation when we see the LO12.
2357 This code is copied from the elf32-mips.c. We also support an arbitrary
2358 number of HI20 relocs to be associated with a single LO12 reloc. The
2359 assembler sorts the relocs to ensure each HI20 immediately precedes its
2360 LO12. However if there are multiple copies, the assembler may not find
2361 the real LO12 so it picks the first one it finds. */
2365 struct nds32_hi20
*next
;
2370 static struct nds32_hi20
*nds32_hi20_list
;
2372 static bfd_reloc_status_type
2373 nds32_elf_hi20_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2374 asymbol
*symbol
, void *data
, asection
*input_section
,
2375 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2377 bfd_reloc_status_type ret
;
2379 struct nds32_hi20
*n
;
2381 /* This part is from bfd_elf_generic_reloc.
2382 If we're relocating, and this an external symbol, we don't want
2383 to change anything. */
2384 if (output_bfd
!= (bfd
*) NULL
2385 && (symbol
->flags
& BSF_SECTION_SYM
) == 0 && reloc_entry
->addend
== 0)
2387 reloc_entry
->address
+= input_section
->output_offset
;
2388 return bfd_reloc_ok
;
2391 /* Sanity check the address (offset in section). */
2392 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2393 return bfd_reloc_outofrange
;
2396 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
2397 ret
= bfd_reloc_undefined
;
2399 if (bfd_is_com_section (symbol
->section
))
2402 relocation
= symbol
->value
;
2404 relocation
+= symbol
->section
->output_section
->vma
;
2405 relocation
+= symbol
->section
->output_offset
;
2406 relocation
+= reloc_entry
->addend
;
2408 /* Save the information, and let LO12 do the actual relocation. */
2409 n
= (struct nds32_hi20
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
2411 return bfd_reloc_outofrange
;
2413 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
2414 n
->addend
= relocation
;
2415 n
->next
= nds32_hi20_list
;
2416 nds32_hi20_list
= n
;
2418 if (output_bfd
!= (bfd
*) NULL
)
2419 reloc_entry
->address
+= input_section
->output_offset
;
2424 /* Handle an NDS32 ELF HI20 reloc. */
2427 nds32_elf_relocate_hi20 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2428 int type ATTRIBUTE_UNUSED
, Elf_Internal_Rela
*relhi
,
2429 Elf_Internal_Rela
*rello
, bfd_byte
*contents
,
2435 insn
= bfd_getb32 (contents
+ relhi
->r_offset
);
2437 addlo
= bfd_getb32 (contents
+ rello
->r_offset
);
2440 addend
+= ((insn
& 0xfffff) << 20) + addlo
;
2442 insn
= (insn
& 0xfff00000) | ((addend
>> 12) & 0xfffff);
2443 bfd_putb32 (insn
, contents
+ relhi
->r_offset
);
2446 /* Do an R_NDS32_LO12 relocation. This is a straightforward 12 bit
2447 inplace relocation; this function exists in order to do the
2448 R_NDS32_HI20_[SU]LO relocation described above. */
2450 static bfd_reloc_status_type
2451 nds32_elf_lo12_reloc (bfd
*input_bfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2452 void *data
, asection
*input_section
, bfd
*output_bfd
,
2453 char **error_message
)
2455 /* This part is from bfd_elf_generic_reloc.
2456 If we're relocating, and this an external symbol, we don't want
2457 to change anything. */
2458 if (output_bfd
!= NULL
&& (symbol
->flags
& BSF_SECTION_SYM
) == 0
2459 && reloc_entry
->addend
== 0)
2461 reloc_entry
->address
+= input_section
->output_offset
;
2462 return bfd_reloc_ok
;
2465 if (nds32_hi20_list
!= NULL
)
2467 struct nds32_hi20
*l
;
2469 l
= nds32_hi20_list
;
2474 unsigned long vallo
;
2475 struct nds32_hi20
*next
;
2477 /* Do the HI20 relocation. Note that we actually don't need
2478 to know anything about the LO12 itself, except where to
2479 find the low 12 bits of the addend needed by the LO12. */
2480 insn
= bfd_getb32 (l
->addr
);
2481 vallo
= bfd_getb32 ((bfd_byte
*) data
+ reloc_entry
->address
);
2483 switch (reloc_entry
->howto
->type
)
2485 case R_NDS32_LO12S3
:
2489 case R_NDS32_LO12S2
:
2493 case R_NDS32_LO12S1
:
2497 case R_NDS32_LO12S0
:
2502 val
= ((insn
& 0xfffff) << 12) + vallo
;
2505 insn
= (insn
& ~(bfd_vma
) 0xfffff) | ((val
>> 12) & 0xfffff);
2506 bfd_putb32 ((bfd_vma
) insn
, l
->addr
);
2513 nds32_hi20_list
= NULL
;
2516 /* Now do the LO12 reloc in the usual way.
2517 ??? It would be nice to call bfd_elf_generic_reloc here,
2518 but we have partial_inplace set. bfd_elf_generic_reloc will
2519 pass the handling back to bfd_install_relocation which will install
2520 a section relative addend which is wrong. */
2521 return nds32_elf_generic_reloc (input_bfd
, reloc_entry
, symbol
, data
,
2522 input_section
, output_bfd
, error_message
);
2525 /* Do generic partial_inplace relocation.
2526 This is a local replacement for bfd_elf_generic_reloc. */
2528 static bfd_reloc_status_type
2529 nds32_elf_generic_reloc (bfd
*input_bfd
, arelent
*reloc_entry
,
2530 asymbol
*symbol
, void *data
, asection
*input_section
,
2531 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2533 bfd_reloc_status_type ret
;
2535 bfd_byte
*inplace_address
;
2537 /* This part is from bfd_elf_generic_reloc.
2538 If we're relocating, and this an external symbol, we don't want
2539 to change anything. */
2540 if (output_bfd
!= NULL
&& (symbol
->flags
& BSF_SECTION_SYM
) == 0
2541 && reloc_entry
->addend
== 0)
2543 reloc_entry
->address
+= input_section
->output_offset
;
2544 return bfd_reloc_ok
;
2547 /* Now do the reloc in the usual way.
2548 ??? It would be nice to call bfd_elf_generic_reloc here,
2549 but we have partial_inplace set. bfd_elf_generic_reloc will
2550 pass the handling back to bfd_install_relocation which will install
2551 a section relative addend which is wrong. */
2553 /* Sanity check the address (offset in section). */
2554 if (reloc_entry
->address
> bfd_get_section_limit (input_bfd
, input_section
))
2555 return bfd_reloc_outofrange
;
2558 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
2559 ret
= bfd_reloc_undefined
;
2561 if (bfd_is_com_section (symbol
->section
) || output_bfd
!= (bfd
*) NULL
)
2564 relocation
= symbol
->value
;
2566 /* Only do this for a final link. */
2567 if (output_bfd
== (bfd
*) NULL
)
2569 relocation
+= symbol
->section
->output_section
->vma
;
2570 relocation
+= symbol
->section
->output_offset
;
2573 relocation
+= reloc_entry
->addend
;
2574 switch (reloc_entry
->howto
->type
)
2576 case R_NDS32_LO12S3
:
2580 case R_NDS32_LO12S2
:
2584 case R_NDS32_LO12S1
:
2588 case R_NDS32_LO12S0
:
2594 inplace_address
= (bfd_byte
*) data
+ reloc_entry
->address
;
2597 x = ((x & ~reloc_entry->howto->dst_mask) | \
2598 (((x & reloc_entry->howto->src_mask) + relocation) & \
2599 reloc_entry->howto->dst_mask))
2601 switch (reloc_entry
->howto
->size
)
2605 short x
= bfd_getb16 (inplace_address
);
2608 bfd_putb16 ((bfd_vma
) x
, inplace_address
);
2613 unsigned long x
= bfd_getb32 (inplace_address
);
2616 bfd_putb32 ((bfd_vma
) x
, inplace_address
);
2623 if (output_bfd
!= (bfd
*) NULL
)
2624 reloc_entry
->address
+= input_section
->output_offset
;
2629 /* Handle the R_NDS32_SDA15 reloc.
2630 This reloc is used to compute the address of objects in the small data area
2631 and to perform loads and stores from that area.
2632 The lower 15 bits are sign extended and added to the register specified
2633 in the instruction, which is assumed to point to _SDA_BASE_.
2635 Since the lower 15 bits offset is left-shifted 0, 1 or 2 bits depending on
2636 the access size, this must be taken care of. */
2638 static bfd_reloc_status_type
2639 nds32_elf_sda15_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2640 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2641 asection
*input_section
, bfd
*output_bfd
,
2642 char **error_message ATTRIBUTE_UNUSED
)
2644 /* This part is from bfd_elf_generic_reloc. */
2645 if (output_bfd
!= (bfd
*) NULL
2646 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2647 && (!reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
2649 reloc_entry
->address
+= input_section
->output_offset
;
2650 return bfd_reloc_ok
;
2653 if (output_bfd
!= NULL
)
2655 /* FIXME: See bfd_perform_relocation. Is this right? */
2656 return bfd_reloc_continue
;
2659 /* FIXME: not sure what to do here yet. But then again, the linker
2660 may never call us. */
2664 /* nds32_elf_ignore_reloc is the special function for
2665 relocation types which don't need to be relocated
2666 like relaxation relocation types.
2667 This function simply return bfd_reloc_ok when it is
2670 static bfd_reloc_status_type
2671 nds32_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2672 asymbol
*symbol ATTRIBUTE_UNUSED
,
2673 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
2674 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2676 if (output_bfd
!= NULL
)
2677 reloc_entry
->address
+= input_section
->output_offset
;
2679 return bfd_reloc_ok
;
2683 /* Map BFD reloc types to NDS32 ELF reloc types. */
2685 struct nds32_reloc_map_entry
2687 bfd_reloc_code_real_type bfd_reloc_val
;
2688 unsigned char elf_reloc_val
;
2691 static const struct nds32_reloc_map_entry nds32_reloc_map
[] =
2693 {BFD_RELOC_NONE
, R_NDS32_NONE
},
2694 {BFD_RELOC_16
, R_NDS32_16_RELA
},
2695 {BFD_RELOC_32
, R_NDS32_32_RELA
},
2696 {BFD_RELOC_NDS32_20
, R_NDS32_20_RELA
},
2697 {BFD_RELOC_NDS32_5
, R_NDS32_5_RELA
},
2698 {BFD_RELOC_NDS32_9_PCREL
, R_NDS32_9_PCREL_RELA
},
2699 {BFD_RELOC_NDS32_WORD_9_PCREL
, R_NDS32_WORD_9_PCREL_RELA
},
2700 {BFD_RELOC_NDS32_15_PCREL
, R_NDS32_15_PCREL_RELA
},
2701 {BFD_RELOC_NDS32_17_PCREL
, R_NDS32_17_PCREL_RELA
},
2702 {BFD_RELOC_NDS32_25_PCREL
, R_NDS32_25_PCREL_RELA
},
2703 {BFD_RELOC_NDS32_10_UPCREL
, R_NDS32_10_UPCREL_RELA
},
2704 {BFD_RELOC_NDS32_HI20
, R_NDS32_HI20_RELA
},
2705 {BFD_RELOC_NDS32_LO12S3
, R_NDS32_LO12S3_RELA
},
2706 {BFD_RELOC_NDS32_LO12S2
, R_NDS32_LO12S2_RELA
},
2707 {BFD_RELOC_NDS32_LO12S1
, R_NDS32_LO12S1_RELA
},
2708 {BFD_RELOC_NDS32_LO12S0
, R_NDS32_LO12S0_RELA
},
2709 {BFD_RELOC_NDS32_LO12S0_ORI
, R_NDS32_LO12S0_ORI_RELA
},
2710 {BFD_RELOC_NDS32_SDA15S3
, R_NDS32_SDA15S3_RELA
},
2711 {BFD_RELOC_NDS32_SDA15S2
, R_NDS32_SDA15S2_RELA
},
2712 {BFD_RELOC_NDS32_SDA15S1
, R_NDS32_SDA15S1_RELA
},
2713 {BFD_RELOC_NDS32_SDA15S0
, R_NDS32_SDA15S0_RELA
},
2714 {BFD_RELOC_VTABLE_INHERIT
, R_NDS32_RELA_GNU_VTINHERIT
},
2715 {BFD_RELOC_VTABLE_ENTRY
, R_NDS32_RELA_GNU_VTENTRY
},
2717 {BFD_RELOC_NDS32_GOT20
, R_NDS32_GOT20
},
2718 {BFD_RELOC_NDS32_9_PLTREL
, R_NDS32_9_PLTREL
},
2719 {BFD_RELOC_NDS32_25_PLTREL
, R_NDS32_25_PLTREL
},
2720 {BFD_RELOC_NDS32_COPY
, R_NDS32_COPY
},
2721 {BFD_RELOC_NDS32_GLOB_DAT
, R_NDS32_GLOB_DAT
},
2722 {BFD_RELOC_NDS32_JMP_SLOT
, R_NDS32_JMP_SLOT
},
2723 {BFD_RELOC_NDS32_RELATIVE
, R_NDS32_RELATIVE
},
2724 {BFD_RELOC_NDS32_GOTOFF
, R_NDS32_GOTOFF
},
2725 {BFD_RELOC_NDS32_GOTPC20
, R_NDS32_GOTPC20
},
2726 {BFD_RELOC_NDS32_GOT_HI20
, R_NDS32_GOT_HI20
},
2727 {BFD_RELOC_NDS32_GOT_LO12
, R_NDS32_GOT_LO12
},
2728 {BFD_RELOC_NDS32_GOT_LO15
, R_NDS32_GOT_LO15
},
2729 {BFD_RELOC_NDS32_GOT_LO19
, R_NDS32_GOT_LO19
},
2730 {BFD_RELOC_NDS32_GOTPC_HI20
, R_NDS32_GOTPC_HI20
},
2731 {BFD_RELOC_NDS32_GOTPC_LO12
, R_NDS32_GOTPC_LO12
},
2732 {BFD_RELOC_NDS32_GOTOFF_HI20
, R_NDS32_GOTOFF_HI20
},
2733 {BFD_RELOC_NDS32_GOTOFF_LO12
, R_NDS32_GOTOFF_LO12
},
2734 {BFD_RELOC_NDS32_GOTOFF_LO15
, R_NDS32_GOTOFF_LO15
},
2735 {BFD_RELOC_NDS32_GOTOFF_LO19
, R_NDS32_GOTOFF_LO19
},
2736 {BFD_RELOC_NDS32_INSN16
, R_NDS32_INSN16
},
2737 {BFD_RELOC_NDS32_LABEL
, R_NDS32_LABEL
},
2738 {BFD_RELOC_NDS32_LONGCALL1
, R_NDS32_LONGCALL1
},
2739 {BFD_RELOC_NDS32_LONGCALL2
, R_NDS32_LONGCALL2
},
2740 {BFD_RELOC_NDS32_LONGCALL3
, R_NDS32_LONGCALL3
},
2741 {BFD_RELOC_NDS32_LONGCALL4
, R_NDS32_LONGCALL4
},
2742 {BFD_RELOC_NDS32_LONGCALL5
, R_NDS32_LONGCALL5
},
2743 {BFD_RELOC_NDS32_LONGCALL6
, R_NDS32_LONGCALL6
},
2744 {BFD_RELOC_NDS32_LONGJUMP1
, R_NDS32_LONGJUMP1
},
2745 {BFD_RELOC_NDS32_LONGJUMP2
, R_NDS32_LONGJUMP2
},
2746 {BFD_RELOC_NDS32_LONGJUMP3
, R_NDS32_LONGJUMP3
},
2747 {BFD_RELOC_NDS32_LONGJUMP4
, R_NDS32_LONGJUMP4
},
2748 {BFD_RELOC_NDS32_LONGJUMP5
, R_NDS32_LONGJUMP5
},
2749 {BFD_RELOC_NDS32_LONGJUMP6
, R_NDS32_LONGJUMP6
},
2750 {BFD_RELOC_NDS32_LONGJUMP7
, R_NDS32_LONGJUMP7
},
2751 {BFD_RELOC_NDS32_LOADSTORE
, R_NDS32_LOADSTORE
},
2752 {BFD_RELOC_NDS32_9_FIXED
, R_NDS32_9_FIXED_RELA
},
2753 {BFD_RELOC_NDS32_15_FIXED
, R_NDS32_15_FIXED_RELA
},
2754 {BFD_RELOC_NDS32_17_FIXED
, R_NDS32_17_FIXED_RELA
},
2755 {BFD_RELOC_NDS32_25_FIXED
, R_NDS32_25_FIXED_RELA
},
2756 {BFD_RELOC_NDS32_PLTREL_HI20
, R_NDS32_PLTREL_HI20
},
2757 {BFD_RELOC_NDS32_PLTREL_LO12
, R_NDS32_PLTREL_LO12
},
2758 {BFD_RELOC_NDS32_PLT_GOTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
},
2759 {BFD_RELOC_NDS32_PLT_GOTREL_LO12
, R_NDS32_PLT_GOTREL_LO12
},
2760 {BFD_RELOC_NDS32_PLT_GOTREL_LO15
, R_NDS32_PLT_GOTREL_LO15
},
2761 {BFD_RELOC_NDS32_PLT_GOTREL_LO19
, R_NDS32_PLT_GOTREL_LO19
},
2762 {BFD_RELOC_NDS32_PLT_GOTREL_LO20
, R_NDS32_PLT_GOTREL_LO20
},
2763 {BFD_RELOC_NDS32_SDA12S2_DP
, R_NDS32_SDA12S2_DP_RELA
},
2764 {BFD_RELOC_NDS32_SDA12S2_SP
, R_NDS32_SDA12S2_SP_RELA
},
2765 {BFD_RELOC_NDS32_LO12S2_DP
, R_NDS32_LO12S2_DP_RELA
},
2766 {BFD_RELOC_NDS32_LO12S2_SP
, R_NDS32_LO12S2_SP_RELA
},
2767 {BFD_RELOC_NDS32_SDA16S3
, R_NDS32_SDA16S3_RELA
},
2768 {BFD_RELOC_NDS32_SDA17S2
, R_NDS32_SDA17S2_RELA
},
2769 {BFD_RELOC_NDS32_SDA18S1
, R_NDS32_SDA18S1_RELA
},
2770 {BFD_RELOC_NDS32_SDA19S0
, R_NDS32_SDA19S0_RELA
},
2771 {BFD_RELOC_NDS32_SDA_FP7U2_RELA
, R_NDS32_SDA_FP7U2_RELA
},
2772 {BFD_RELOC_NDS32_DWARF2_OP1
, R_NDS32_DWARF2_OP1_RELA
},
2773 {BFD_RELOC_NDS32_DWARF2_OP2
, R_NDS32_DWARF2_OP2_RELA
},
2774 {BFD_RELOC_NDS32_DWARF2_LEB
, R_NDS32_DWARF2_LEB_RELA
},
2775 {BFD_RELOC_NDS32_UPDATE_TA
, R_NDS32_UPDATE_TA_RELA
},
2776 {BFD_RELOC_NDS32_GOT_SUFF
, R_NDS32_GOT_SUFF
},
2777 {BFD_RELOC_NDS32_GOTOFF_SUFF
, R_NDS32_GOTOFF_SUFF
},
2778 {BFD_RELOC_NDS32_GOT15S2
, R_NDS32_GOT15S2_RELA
},
2779 {BFD_RELOC_NDS32_GOT17S2
, R_NDS32_GOT17S2_RELA
},
2780 {BFD_RELOC_NDS32_PTR
, R_NDS32_PTR
},
2781 {BFD_RELOC_NDS32_PTR_COUNT
, R_NDS32_PTR_COUNT
},
2782 {BFD_RELOC_NDS32_PLT_GOT_SUFF
, R_NDS32_PLT_GOT_SUFF
},
2783 {BFD_RELOC_NDS32_PTR_RESOLVED
, R_NDS32_PTR_RESOLVED
},
2784 {BFD_RELOC_NDS32_RELAX_ENTRY
, R_NDS32_RELAX_ENTRY
},
2785 {BFD_RELOC_NDS32_MULCALL_SUFF
, R_NDS32_MULCALL_SUFF
},
2786 {BFD_RELOC_NDS32_PLTBLOCK
, R_NDS32_PLTBLOCK
},
2787 {BFD_RELOC_NDS32_RELAX_REGION_BEGIN
, R_NDS32_RELAX_REGION_BEGIN
},
2788 {BFD_RELOC_NDS32_RELAX_REGION_END
, R_NDS32_RELAX_REGION_END
},
2789 {BFD_RELOC_NDS32_MINUEND
, R_NDS32_MINUEND
},
2790 {BFD_RELOC_NDS32_SUBTRAHEND
, R_NDS32_SUBTRAHEND
},
2791 {BFD_RELOC_NDS32_EMPTY
, R_NDS32_EMPTY
},
2793 {BFD_RELOC_NDS32_DIFF8
, R_NDS32_DIFF8
},
2794 {BFD_RELOC_NDS32_DIFF16
, R_NDS32_DIFF16
},
2795 {BFD_RELOC_NDS32_DIFF32
, R_NDS32_DIFF32
},
2796 {BFD_RELOC_NDS32_DIFF_ULEB128
, R_NDS32_DIFF_ULEB128
},
2797 {BFD_RELOC_NDS32_25_ABS
, R_NDS32_25_ABS_RELA
},
2798 {BFD_RELOC_NDS32_DATA
, R_NDS32_DATA
},
2799 {BFD_RELOC_NDS32_TRAN
, R_NDS32_TRAN
},
2800 {BFD_RELOC_NDS32_17IFC_PCREL
, R_NDS32_17IFC_PCREL_RELA
},
2801 {BFD_RELOC_NDS32_10IFCU_PCREL
, R_NDS32_10IFCU_PCREL_RELA
},
2802 {BFD_RELOC_NDS32_TLS_LE_HI20
, R_NDS32_TLS_LE_HI20
},
2803 {BFD_RELOC_NDS32_TLS_LE_LO12
, R_NDS32_TLS_LE_LO12
},
2804 {BFD_RELOC_NDS32_TLS_LE_ADD
, R_NDS32_TLS_LE_ADD
},
2805 {BFD_RELOC_NDS32_TLS_LE_LS
, R_NDS32_TLS_LE_LS
},
2806 {BFD_RELOC_NDS32_TLS_IE_HI20
, R_NDS32_TLS_IE_HI20
},
2807 {BFD_RELOC_NDS32_TLS_IE_LO12S2
, R_NDS32_TLS_IE_LO12S2
},
2808 {BFD_RELOC_NDS32_TLS_TPOFF
, R_NDS32_TLS_TPOFF
},
2809 {BFD_RELOC_NDS32_TLS_LE_20
, R_NDS32_TLS_LE_20
},
2810 {BFD_RELOC_NDS32_TLS_LE_15S0
, R_NDS32_TLS_LE_15S0
},
2811 {BFD_RELOC_NDS32_TLS_LE_15S1
, R_NDS32_TLS_LE_15S1
},
2812 {BFD_RELOC_NDS32_TLS_LE_15S2
, R_NDS32_TLS_LE_15S2
},
2817 static reloc_howto_type
*
2818 bfd_elf32_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2823 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_howto_table
); i
++)
2824 if (nds32_elf_howto_table
[i
].name
!= NULL
2825 && strcasecmp (nds32_elf_howto_table
[i
].name
, r_name
) == 0)
2826 return &nds32_elf_howto_table
[i
];
2828 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_relax_howto_table
); i
++)
2829 if (nds32_elf_relax_howto_table
[i
].name
!= NULL
2830 && strcasecmp (nds32_elf_relax_howto_table
[i
].name
, r_name
) == 0)
2831 return &nds32_elf_relax_howto_table
[i
];
2836 static reloc_howto_type
*
2837 bfd_elf32_bfd_reloc_type_table_lookup (enum elf_nds32_reloc_type code
)
2839 if (code
< R_NDS32_RELAX_ENTRY
)
2841 BFD_ASSERT (code
< ARRAY_SIZE (nds32_elf_howto_table
));
2842 return &nds32_elf_howto_table
[code
];
2846 BFD_ASSERT ((size_t) (code
- R_NDS32_RELAX_ENTRY
)
2847 < ARRAY_SIZE (nds32_elf_relax_howto_table
));
2848 return &nds32_elf_relax_howto_table
[code
- R_NDS32_RELAX_ENTRY
];
2852 static reloc_howto_type
*
2853 bfd_elf32_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2854 bfd_reloc_code_real_type code
)
2858 for (i
= 0; i
< ARRAY_SIZE (nds32_reloc_map
); i
++)
2860 if (nds32_reloc_map
[i
].bfd_reloc_val
== code
)
2861 return bfd_elf32_bfd_reloc_type_table_lookup
2862 (nds32_reloc_map
[i
].elf_reloc_val
);
2868 /* Set the howto pointer for an NDS32 ELF reloc. */
2871 nds32_info_to_howto_rel (bfd
*abfd
, arelent
*cache_ptr
,
2872 Elf_Internal_Rela
*dst
)
2874 enum elf_nds32_reloc_type r_type
;
2876 r_type
= ELF32_R_TYPE (dst
->r_info
);
2877 if (r_type
> R_NDS32_GNU_VTENTRY
)
2879 /* xgettext:c-format */
2880 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2882 bfd_set_error (bfd_error_bad_value
);
2885 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
2890 nds32_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2891 Elf_Internal_Rela
*dst
)
2893 unsigned int r_type
= ELF32_R_TYPE (dst
->r_info
);
2895 if ((r_type
== R_NDS32_NONE
)
2896 || ((r_type
> R_NDS32_GNU_VTENTRY
)
2897 && (r_type
< R_NDS32_max
)))
2899 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
2903 /* xgettext:c-format */
2904 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, r_type
);
2905 bfd_set_error (bfd_error_bad_value
);
2909 /* Support for core dump NOTE sections.
2910 Reference to include/linux/elfcore.h in Linux. */
2913 nds32_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2918 switch (note
->descsz
)
2921 /* Linux/NDS32 32-bit, ABI1 */
2924 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2927 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2935 /* Linux/NDS32 32-bit */
2938 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2941 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2952 /* Make a ".reg" section. */
2953 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2954 size
, note
->descpos
+ offset
);
2958 nds32_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2960 switch (note
->descsz
)
2965 /* __kernel_uid_t, __kernel_gid_t are short on NDS32 platform. */
2966 elf_tdata (abfd
)->core
->program
=
2967 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
2968 elf_tdata (abfd
)->core
->command
=
2969 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
2976 /* Note that for some reason, a spurious space is tacked
2977 onto the end of the args in some (at least one anyway)
2978 implementations, so strip it off if it exists. */
2980 char *command
= elf_tdata (abfd
)->core
->command
;
2981 int n
= strlen (command
);
2983 if (0 < n
&& command
[n
- 1] == ' ')
2984 command
[n
- 1] = '\0';
2990 /* Hook called by the linker routine which adds symbols from an object
2991 file. We must handle the special NDS32 section numbers here.
2992 We also keep watching for whether we need to create the sdata special
2996 nds32_elf_add_symbol_hook (bfd
*abfd
,
2997 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2998 Elf_Internal_Sym
*sym
,
2999 const char **namep ATTRIBUTE_UNUSED
,
3000 flagword
*flagsp ATTRIBUTE_UNUSED
,
3001 asection
**secp
, bfd_vma
*valp
)
3003 switch (sym
->st_shndx
)
3006 /* Common symbols less than the GP size are automatically
3007 treated as SHN_MIPS_SCOMMON symbols. */
3008 if (sym
->st_size
> elf_gp_size (abfd
)
3009 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
)
3012 /* st_value is the alignemnt constraint.
3013 That might be its actual size if it is an array or structure. */
3014 switch (sym
->st_value
)
3017 *secp
= bfd_make_section_old_way (abfd
, ".scommon_b");
3020 *secp
= bfd_make_section_old_way (abfd
, ".scommon_h");
3023 *secp
= bfd_make_section_old_way (abfd
, ".scommon_w");
3026 *secp
= bfd_make_section_old_way (abfd
, ".scommon_d");
3032 (*secp
)->flags
|= SEC_IS_COMMON
;
3033 *valp
= sym
->st_size
;
3041 /* This function can figure out the best location for a base register to access
3042 data relative to this base register
3044 sda_d0: size of first DOUBLE WORD data section
3045 sda_w0: size of first WORD data section
3046 sda_h0: size of first HALF WORD data section
3047 sda_b : size of BYTE data section
3048 sda_hi: size of second HALF WORD data section
3049 sda_w1: size of second WORD data section
3050 sda_d1: size of second DOUBLE WORD data section
3052 offset (always positive) from the beginning of sda_d0 if OK
3053 a negative error value if fail
3055 these 7 sections have to be located back to back if exist
3056 a pass in 0 value for non-existing section */
3058 /* Due to the interpretation of simm15 field of load/store depending on
3059 data accessing size, the organization of base register relative data shall
3060 like the following figure
3061 -------------------------------------------
3062 | DOUBLE WORD sized data (range +/- 128K)
3063 -------------------------------------------
3064 | WORD sized data (range +/- 64K)
3065 -------------------------------------------
3066 | HALF WORD sized data (range +/- 32K)
3067 -------------------------------------------
3068 | BYTE sized data (range +/- 16K)
3069 -------------------------------------------
3070 | HALF WORD sized data (range +/- 32K)
3071 -------------------------------------------
3072 | WORD sized data (range +/- 64K)
3073 -------------------------------------------
3074 | DOUBLE WORD sized data (range +/- 128K)
3075 -------------------------------------------
3076 Its base register shall be set to access these data freely. */
3078 /* We have to figure out the SDA_BASE value, so that we can adjust the
3079 symbol value correctly. We look up the symbol _SDA_BASE_ in the output
3080 BFD. If we can't find it, we're stuck. We cache it in the ELF
3081 target data. We don't need to adjust the symbol value for an
3082 external symbol if we are producing relocatable output. */
3084 static asection
*sda_rela_sec
= NULL
;
3086 #define SDA_SECTION_NUM 10
3088 static bfd_reloc_status_type
3089 nds32_elf_final_sda_base (bfd
*output_bfd
, struct bfd_link_info
*info
,
3090 bfd_vma
*psb
, bfd_boolean add_symbol
)
3093 struct elf_nds32_link_hash_table
*table
;
3094 struct bfd_link_hash_entry
*h
, *h2
;
3095 long unsigned int total
= 0;
3097 h
= bfd_link_hash_lookup (info
->hash
, "_SDA_BASE_", FALSE
, FALSE
, TRUE
);
3098 if (!h
|| (h
->type
!= bfd_link_hash_defined
&& h
->type
!= bfd_link_hash_defweak
))
3100 asection
*first
= NULL
, *final
= NULL
, *temp
;
3102 /* The first section must be 4-byte aligned to promise _SDA_BASE_ being
3103 4 byte-aligned. Therefore, it has to set the first section ".data"
3105 static const char sec_name
[SDA_SECTION_NUM
][10] =
3107 ".data", ".got", ".sdata_d", ".sdata_w", ".sdata_h", ".sdata_b",
3108 ".sbss_b", ".sbss_h", ".sbss_w", ".sbss_d"
3112 if (output_bfd
->sections
== NULL
)
3114 *psb
= elf_gp (output_bfd
);
3115 return bfd_reloc_ok
;
3118 /* Get the first and final section. */
3119 while (i
< sizeof (sec_name
) / sizeof (sec_name
[0]))
3121 temp
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3122 if (temp
&& !first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3124 if (temp
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3127 /* Summarize the sections in order to check if joining .bss. */
3128 if (temp
&& temp
->size
!= 0)
3129 total
+= temp
->size
;
3130 else if (temp
&& temp
->rawsize
!= 0)
3131 total
+= temp
->rawsize
;
3136 /* Check .bss size. */
3137 temp
= bfd_get_section_by_name (output_bfd
, ".bss");
3140 if (temp
->size
!= 0)
3141 total
+= temp
->size
;
3142 else if (temp
->rawsize
!= 0)
3143 total
+= temp
->rawsize
;
3145 if (total
< 0x80000)
3147 if (!first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3149 if ((temp
->size
!= 0 || temp
->rawsize
!= 0))
3156 /* The middle of data region. */
3157 sda_base
= final
->vma
/ 2 + final
->rawsize
/ 2 + first
->vma
/ 2;
3159 /* Find the section sda_base located. */
3161 while (i
< sizeof (sec_name
) / sizeof (sec_name
[0]))
3163 final
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3164 if (final
&& (final
->size
!= 0 || final
->rawsize
!= 0)
3165 && sda_base
>= final
->vma
)
3176 /* There is not any data section in output bfd, and set _SDA_BASE_ in
3177 first output section. */
3178 first
= output_bfd
->sections
;
3179 while (first
&& first
->size
== 0 && first
->rawsize
== 0)
3180 first
= first
->next
;
3183 *psb
= elf_gp (output_bfd
);
3184 return bfd_reloc_ok
;
3186 sda_base
= first
->vma
+ first
->rawsize
;
3189 sda_base
-= first
->vma
;
3190 sda_base
= sda_base
& (~7);
3192 if (!_bfd_generic_link_add_one_symbol
3193 (info
, output_bfd
, "_SDA_BASE_", BSF_GLOBAL
| BSF_WEAK
, first
,
3194 (bfd_vma
) sda_base
, (const char *) NULL
, FALSE
,
3195 get_elf_backend_data (output_bfd
)->collect
, &h
))
3198 sda_rela_sec
= first
;
3200 table
= nds32_elf_hash_table (info
);
3201 relax_fp_as_gp
= table
->relax_fp_as_gp
;
3204 h2
= bfd_link_hash_lookup (info
->hash
, FP_BASE_NAME
,
3205 FALSE
, FALSE
, FALSE
);
3206 /* Define a weak FP_BASE_NAME here to prevent the undefined symbol.
3207 And set FP equal to SDA_BASE to do relaxation for
3208 la $fp, _FP_BASE_. */
3209 if (!_bfd_generic_link_add_one_symbol
3210 (info
, output_bfd
, FP_BASE_NAME
, BSF_GLOBAL
| BSF_WEAK
,
3211 first
, (bfd_vma
) sda_base
, (const char *) NULL
,
3212 FALSE
, get_elf_backend_data (output_bfd
)->collect
, &h2
))
3222 elf_gp (output_bfd
) = (h
->u
.def
.value
3223 + h
->u
.def
.section
->output_section
->vma
3224 + h
->u
.def
.section
->output_offset
);
3228 _bfd_error_handler (_("error: can't find symbol: %s"), "_SDA_BASE_");
3229 return bfd_reloc_dangerous
;
3233 *psb
= h
->u
.def
.value
+ h
->u
.def
.section
->output_section
->vma
3234 + h
->u
.def
.section
->output_offset
;
3235 return bfd_reloc_ok
;
3239 /* Return size of a PLT entry. */
3240 #define elf_nds32_sizeof_plt(info) PLT_ENTRY_SIZE
3243 /* Create an entry in an nds32 ELF linker hash table. */
3245 static struct bfd_hash_entry
*
3246 nds32_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3247 struct bfd_hash_table
*table
,
3250 struct elf_nds32_link_hash_entry
*ret
;
3252 ret
= (struct elf_nds32_link_hash_entry
*) entry
;
3254 /* Allocate the structure if it has not already been allocated by a
3257 ret
= (struct elf_nds32_link_hash_entry
*)
3258 bfd_hash_allocate (table
, sizeof (struct elf_nds32_link_hash_entry
));
3261 return (struct bfd_hash_entry
*) ret
;
3263 /* Call the allocation method of the superclass. */
3264 ret
= (struct elf_nds32_link_hash_entry
*)
3265 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
);
3269 struct elf_nds32_link_hash_entry
*eh
;
3271 eh
= (struct elf_nds32_link_hash_entry
*) ret
;
3272 eh
->dyn_relocs
= NULL
;
3273 eh
->tls_type
= GOT_UNKNOWN
;
3276 return (struct bfd_hash_entry
*) ret
;
3279 /* Create an nds32 ELF linker hash table. */
3281 static struct bfd_link_hash_table
*
3282 nds32_elf_link_hash_table_create (bfd
*abfd
)
3284 struct elf_nds32_link_hash_table
*ret
;
3286 bfd_size_type amt
= sizeof (struct elf_nds32_link_hash_table
);
3288 ret
= (struct elf_nds32_link_hash_table
*) bfd_zmalloc (amt
);
3293 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3294 nds32_elf_link_hash_newfunc
,
3295 sizeof (struct elf_nds32_link_hash_entry
),
3302 return &ret
->root
.root
;
3305 /* Create dynamic sections when linking against a dynamic object. */
3308 nds32_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3310 struct elf_nds32_link_hash_table
*htab
;
3311 flagword flags
, pltflags
;
3312 register asection
*s
;
3313 const struct elf_backend_data
*bed
;
3314 int ptralign
= 2; /* 32-bit */
3316 bed
= get_elf_backend_data (abfd
);
3318 htab
= nds32_elf_hash_table (info
);
3320 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3321 .rel[a].bss sections. */
3323 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3324 | SEC_LINKER_CREATED
);
3327 pltflags
|= SEC_CODE
;
3328 if (bed
->plt_not_loaded
)
3329 pltflags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
3330 if (bed
->plt_readonly
)
3331 pltflags
|= SEC_READONLY
;
3333 s
= bfd_make_section (abfd
, ".plt");
3334 htab
->root
.splt
= s
;
3336 || !bfd_set_section_flags (abfd
, s
, pltflags
)
3337 || !bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3340 if (bed
->want_plt_sym
)
3342 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3344 struct bfd_link_hash_entry
*bh
= NULL
;
3345 struct elf_link_hash_entry
*h
;
3347 if (!(_bfd_generic_link_add_one_symbol
3348 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3349 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3350 get_elf_backend_data (abfd
)->collect
, &bh
)))
3353 h
= (struct elf_link_hash_entry
*) bh
;
3355 h
->type
= STT_OBJECT
;
3357 if (bfd_link_pic (info
) && !bfd_elf_link_record_dynamic_symbol (info
, h
))
3361 s
= bfd_make_section (abfd
,
3362 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3363 htab
->root
.srelplt
= s
;
3365 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3366 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3369 if (htab
->root
.sgot
== NULL
&& !_bfd_elf_create_got_section (abfd
, info
))
3373 const char *secname
;
3378 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3380 secflags
= bfd_get_section_flags (abfd
, sec
);
3381 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3382 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3384 secname
= bfd_get_section_name (abfd
, sec
);
3385 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3386 strcpy (relname
, ".rela");
3387 strcat (relname
, secname
);
3388 if (bfd_get_section_by_name (abfd
, secname
))
3390 s
= bfd_make_section (abfd
, relname
);
3392 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3393 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3398 if (bed
->want_dynbss
)
3400 /* The .dynbss section is a place to put symbols which are defined
3401 by dynamic objects, are referenced by regular objects, and are
3402 not functions. We must allocate space for them in the process
3403 image and use a R_*_COPY reloc to tell the dynamic linker to
3404 initialize them at run time. The linker script puts the .dynbss
3405 section into the .bss section of the final image. */
3406 s
= bfd_make_section (abfd
, ".dynbss");
3409 || !bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
3411 /* The .rel[a].bss section holds copy relocs. This section is not
3412 normally needed. We need to create it here, though, so that the
3413 linker will map it to an output section. We can't just create it
3414 only if we need it, because we will not know whether we need it
3415 until we have seen all the input files, and the first time the
3416 main linker code calls BFD after examining all the input files
3417 (size_dynamic_sections) the input sections have already been
3418 mapped to the output sections. If the section turns out not to
3419 be needed, we can discard it later. We will never need this
3420 section when generating a shared object, since they do not use
3422 if (!bfd_link_pic (info
))
3424 s
= bfd_make_section (abfd
, (bed
->default_use_rela_p
3425 ? ".rela.bss" : ".rel.bss"));
3428 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3429 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3437 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3439 nds32_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3440 struct elf_link_hash_entry
*dir
,
3441 struct elf_link_hash_entry
*ind
)
3443 struct elf_nds32_link_hash_entry
*edir
, *eind
;
3445 edir
= (struct elf_nds32_link_hash_entry
*) dir
;
3446 eind
= (struct elf_nds32_link_hash_entry
*) ind
;
3448 if (eind
->dyn_relocs
!= NULL
)
3450 if (edir
->dyn_relocs
!= NULL
)
3452 struct elf_dyn_relocs
**pp
;
3453 struct elf_dyn_relocs
*p
;
3455 if (ind
->root
.type
== bfd_link_hash_indirect
)
3458 /* Add reloc counts against the weak sym to the strong sym
3459 list. Merge any entries against the same section. */
3460 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
3462 struct elf_dyn_relocs
*q
;
3464 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3465 if (q
->sec
== p
->sec
)
3467 q
->pc_count
+= p
->pc_count
;
3468 q
->count
+= p
->count
;
3475 *pp
= edir
->dyn_relocs
;
3478 edir
->dyn_relocs
= eind
->dyn_relocs
;
3479 eind
->dyn_relocs
= NULL
;
3482 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3485 /* Find dynamic relocs for H that apply to read-only sections. */
3488 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
3490 struct elf_dyn_relocs
*p
;
3492 for (p
= elf32_nds32_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3494 asection
*s
= p
->sec
->output_section
;
3496 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3502 /* Adjust a symbol defined by a dynamic object and referenced by a
3503 regular object. The current definition is in some section of the
3504 dynamic object, but we're not including those sections. We have to
3505 change the definition to something the rest of the link can
3509 nds32_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3510 struct elf_link_hash_entry
*h
)
3512 struct elf_nds32_link_hash_table
*htab
;
3515 unsigned int power_of_two
;
3517 dynobj
= elf_hash_table (info
)->dynobj
;
3519 /* Make sure we know what is going on here. */
3520 BFD_ASSERT (dynobj
!= NULL
3523 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
3526 /* If this is a function, put it in the procedure linkage table. We
3527 will fill in the contents of the procedure linkage table later,
3528 when we know the address of the .got section. */
3529 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
3531 if (!bfd_link_pic (info
)
3534 && h
->root
.type
!= bfd_link_hash_undefweak
3535 && h
->root
.type
!= bfd_link_hash_undefined
)
3537 /* This case can occur if we saw a PLT reloc in an input
3538 file, but the symbol was never referred to by a dynamic
3539 object. In such a case, we don't actually need to build
3540 a procedure linkage table, and we can just do a PCREL
3542 h
->plt
.offset
= (bfd_vma
) - 1;
3549 h
->plt
.offset
= (bfd_vma
) - 1;
3551 /* If this is a weak symbol, and there is a real definition, the
3552 processor independent code will have arranged for us to see the
3553 real definition first, and we can just use the same value. */
3554 if (h
->is_weakalias
)
3556 struct elf_link_hash_entry
*def
= weakdef (h
);
3557 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3558 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3559 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3563 /* This is a reference to a symbol defined by a dynamic object which
3564 is not a function. */
3566 /* If we are creating a shared library, we must presume that the
3567 only references to the symbol are via the global offset table.
3568 For such cases we need not do anything here; the relocations will
3569 be handled correctly by relocate_section. */
3570 if (bfd_link_pic (info
))
3573 /* If there are no references to this symbol that do not use the
3574 GOT, we don't need to generate a copy reloc. */
3575 if (!h
->non_got_ref
)
3578 /* If -z nocopyreloc was given, we won't generate them either. */
3579 if (0 && info
->nocopyreloc
)
3585 /* If we don't find any dynamic relocs in read-only sections, then
3586 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3587 if (0 && !readonly_dynrelocs (h
))
3593 /* We must allocate the symbol in our .dynbss section, which will
3594 become part of the .bss section of the executable. There will be
3595 an entry for this symbol in the .dynsym section. The dynamic
3596 object will contain position independent code, so all references
3597 from the dynamic object to this symbol will go through the global
3598 offset table. The dynamic linker will use the .dynsym entry to
3599 determine the address it must put in the global offset table, so
3600 both the dynamic object and the regular object will refer to the
3601 same memory location for the variable. */
3603 htab
= nds32_elf_hash_table (info
);
3605 BFD_ASSERT (s
!= NULL
);
3607 /* We must generate a R_NDS32_COPY reloc to tell the dynamic linker
3608 to copy the initial value out of the dynamic object and into the
3609 runtime process image. We need to remember the offset into the
3610 .rela.bss section we are going to use. */
3611 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3615 srel
= htab
->srelbss
;
3616 BFD_ASSERT (srel
!= NULL
);
3617 srel
->size
+= sizeof (Elf32_External_Rela
);
3621 /* We need to figure out the alignment required for this symbol. I
3622 have no idea how ELF linkers handle this. */
3623 power_of_two
= bfd_log2 (h
->size
);
3624 if (power_of_two
> 3)
3627 /* Apply the required alignment. */
3628 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3629 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3631 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3635 /* Define the symbol as being at this point in the section. */
3636 h
->root
.u
.def
.section
= s
;
3637 h
->root
.u
.def
.value
= s
->size
;
3639 /* Increment the section size to make room for the symbol. */
3645 /* Allocate space in .plt, .got and associated reloc sections for
3649 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3651 struct bfd_link_info
*info
;
3652 struct elf_nds32_link_hash_table
*htab
;
3653 struct elf_nds32_link_hash_entry
*eh
;
3654 struct elf_dyn_relocs
*p
;
3656 if (h
->root
.type
== bfd_link_hash_indirect
)
3659 if (h
->root
.type
== bfd_link_hash_warning
)
3660 /* When warning symbols are created, they **replace** the "real"
3661 entry in the hash table, thus we never get to see the real
3662 symbol in a hash traversal. So look at it now. */
3663 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3665 info
= (struct bfd_link_info
*) inf
;
3666 htab
= nds32_elf_hash_table (info
);
3668 eh
= (struct elf_nds32_link_hash_entry
*) h
;
3670 if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3672 /* Make sure this symbol is output as a dynamic symbol.
3673 Undefined weak syms won't yet be marked as dynamic. */
3674 if (h
->dynindx
== -1 && !h
->forced_local
)
3676 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3680 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
3682 asection
*s
= htab
->root
.splt
;
3684 /* If this is the first .plt entry, make room for the special
3687 s
->size
+= PLT_ENTRY_SIZE
;
3689 h
->plt
.offset
= s
->size
;
3691 /* If this symbol is not defined in a regular file, and we are
3692 not generating a shared library, then set the symbol to this
3693 location in the .plt. This is required to make function
3694 pointers compare as equal between the normal executable and
3695 the shared library. */
3696 if (!bfd_link_pic (info
) && !h
->def_regular
)
3698 h
->root
.u
.def
.section
= s
;
3699 h
->root
.u
.def
.value
= h
->plt
.offset
;
3702 /* Make room for this entry. */
3703 s
->size
+= PLT_ENTRY_SIZE
;
3705 /* We also need to make an entry in the .got.plt section, which
3706 will be placed in the .got section by the linker script. */
3707 htab
->root
.sgotplt
->size
+= 4;
3709 /* We also need to make an entry in the .rel.plt section. */
3710 htab
->root
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3714 h
->plt
.offset
= (bfd_vma
) - 1;
3720 h
->plt
.offset
= (bfd_vma
) - 1;
3724 if (h
->got
.refcount
> 0)
3728 int tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
3730 /* Make sure this symbol is output as a dynamic symbol.
3731 Undefined weak syms won't yet be marked as dynamic. */
3732 if (h
->dynindx
== -1 && !h
->forced_local
)
3734 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3738 s
= htab
->root
.sgot
;
3739 h
->got
.offset
= s
->size
;
3741 if (tls_type
== GOT_UNKNOWN
)
3743 else if (tls_type
== GOT_NORMAL
3744 || tls_type
== GOT_TLS_IE
)
3745 /* Need a GOT slot. */
3748 dyn
= htab
->root
.dynamic_sections_created
;
3749 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
))
3750 htab
->root
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3753 h
->got
.offset
= (bfd_vma
) - 1;
3755 if (eh
->dyn_relocs
== NULL
)
3758 /* In the shared -Bsymbolic case, discard space allocated for
3759 dynamic pc-relative relocs against symbols which turn out to be
3760 defined in regular objects. For the normal shared case, discard
3761 space for pc-relative relocs that have become local due to symbol
3762 visibility changes. */
3764 if (bfd_link_pic (info
))
3766 if (h
->def_regular
&& (h
->forced_local
|| info
->symbolic
))
3768 struct elf_dyn_relocs
**pp
;
3770 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
3772 p
->count
-= p
->pc_count
;
3783 /* For the non-shared case, discard space for relocs against
3784 symbols which turn out to need copy relocs or are not dynamic. */
3789 || (htab
->root
.dynamic_sections_created
3790 && (h
->root
.type
== bfd_link_hash_undefweak
3791 || h
->root
.type
== bfd_link_hash_undefined
))))
3793 /* Make sure this symbol is output as a dynamic symbol.
3794 Undefined weak syms won't yet be marked as dynamic. */
3795 if (h
->dynindx
== -1 && !h
->forced_local
)
3797 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3801 /* If that succeeded, we know we'll be keeping all the
3803 if (h
->dynindx
!= -1)
3807 eh
->dyn_relocs
= NULL
;
3812 /* Finally, allocate space. */
3813 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3815 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3816 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3822 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
3823 read-only sections. */
3826 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
3830 if (h
->root
.type
== bfd_link_hash_indirect
)
3833 sec
= readonly_dynrelocs (h
);
3836 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
3838 info
->flags
|= DF_TEXTREL
;
3839 info
->callbacks
->minfo
3840 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
3841 sec
->owner
, h
->root
.root
.string
, sec
);
3843 /* Not an error, just cut short the traversal. */
3849 /* Set the sizes of the dynamic sections. */
3852 nds32_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3853 struct bfd_link_info
*info
)
3855 struct elf_nds32_link_hash_table
*htab
;
3861 htab
= nds32_elf_hash_table (info
);
3862 dynobj
= htab
->root
.dynobj
;
3863 BFD_ASSERT (dynobj
!= NULL
);
3865 if (htab
->root
.dynamic_sections_created
)
3867 /* Set the contents of the .interp section to the interpreter. */
3868 if (bfd_link_executable (info
) && !info
->nointerp
)
3870 s
= bfd_get_section_by_name (dynobj
, ".interp");
3871 BFD_ASSERT (s
!= NULL
);
3872 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3873 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3877 /* Set up .got offsets for local syms, and space for local dynamic
3879 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3881 bfd_signed_vma
*local_got
;
3882 bfd_signed_vma
*end_local_got
;
3883 bfd_size_type locsymcount
;
3884 Elf_Internal_Shdr
*symtab_hdr
;
3887 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3890 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3892 struct elf_dyn_relocs
*p
;
3894 for (p
= ((struct elf_dyn_relocs
*)
3895 elf_section_data (s
)->local_dynrel
);
3896 p
!= NULL
; p
= p
->next
)
3898 if (!bfd_is_abs_section (p
->sec
)
3899 && bfd_is_abs_section (p
->sec
->output_section
))
3901 /* Input section has been discarded, either because
3902 it is a copy of a linkonce section or due to
3903 linker script /DISCARD/, so we'll be discarding
3906 else if (p
->count
!= 0)
3908 srel
= elf_section_data (p
->sec
)->sreloc
;
3909 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3910 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3911 info
->flags
|= DF_TEXTREL
;
3916 local_got
= elf_local_got_refcounts (ibfd
);
3920 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3921 locsymcount
= symtab_hdr
->sh_info
;
3922 end_local_got
= local_got
+ locsymcount
;
3923 s
= htab
->root
.sgot
;
3924 srel
= htab
->root
.srelgot
;
3925 for (; local_got
< end_local_got
; ++local_got
)
3929 *local_got
= s
->size
;
3931 if (bfd_link_pic (info
))
3932 srel
->size
+= sizeof (Elf32_External_Rela
);
3935 *local_got
= (bfd_vma
) - 1;
3939 /* Allocate global sym .plt and .got entries, and space for global
3940 sym dynamic relocs. */
3941 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (void *) info
);
3943 /* We now have determined the sizes of the various dynamic sections.
3944 Allocate memory for them. */
3946 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3948 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3951 if (s
== htab
->root
.splt
)
3953 /* Strip this section if we don't need it; see the
3956 else if (s
== htab
->root
.sgot
)
3958 got_size
+= s
->size
;
3960 else if (s
== htab
->root
.sgotplt
)
3962 got_size
+= s
->size
;
3964 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3966 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
3969 /* We use the reloc_count field as a counter if we need
3970 to copy relocs into the output file. */
3975 /* It's not one of our sections, so don't allocate space. */
3981 /* If we don't need this section, strip it from the
3982 output file. This is mostly to handle .rela.bss and
3983 .rela.plt. We must create both sections in
3984 create_dynamic_sections, because they must be created
3985 before the linker maps input sections to output
3986 sections. The linker does that before
3987 adjust_dynamic_symbol is called, and it is that
3988 function which decides whether anything needs to go
3989 into these sections. */
3990 s
->flags
|= SEC_EXCLUDE
;
3994 /* Allocate memory for the section contents. We use bfd_zalloc
3995 here in case unused entries are not reclaimed before the
3996 section's contents are written out. This should not happen,
3997 but this way if it does, we get a R_NDS32_NONE reloc instead
3999 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4000 if (s
->contents
== NULL
)
4005 if (htab
->root
.dynamic_sections_created
)
4007 /* Add some entries to the .dynamic section. We fill in the
4008 values later, in nds32_elf_finish_dynamic_sections, but we
4009 must add the entries now so that we get the correct size for
4010 the .dynamic section. The DT_DEBUG entry is filled in by the
4011 dynamic linker and used by the debugger. */
4012 #define add_dynamic_entry(TAG, VAL) \
4013 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4015 if (!bfd_link_pic (info
))
4017 if (!add_dynamic_entry (DT_DEBUG
, 0))
4021 if (htab
->root
.splt
->size
!= 0)
4023 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4024 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4025 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4026 || !add_dynamic_entry (DT_JMPREL
, 0))
4032 if (!add_dynamic_entry (DT_RELA
, 0)
4033 || !add_dynamic_entry (DT_RELASZ
, 0)
4034 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4037 /* If any dynamic relocs apply to a read-only section,
4038 then we need a DT_TEXTREL entry. */
4039 if ((info
->flags
& DF_TEXTREL
) == 0)
4040 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
,
4043 if ((info
->flags
& DF_TEXTREL
) != 0)
4045 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4050 #undef add_dynamic_entry
4055 static bfd_reloc_status_type
4056 nds32_relocate_contents (reloc_howto_type
*howto
, bfd
*input_bfd
,
4057 bfd_vma relocation
, bfd_byte
*location
)
4061 bfd_reloc_status_type flag
;
4062 unsigned int rightshift
= howto
->rightshift
;
4063 unsigned int bitpos
= howto
->bitpos
;
4065 /* If the size is negative, negate RELOCATION. This isn't very
4067 if (howto
->size
< 0)
4068 relocation
= -relocation
;
4070 /* Get the value we are going to relocate. */
4071 size
= bfd_get_reloc_size (howto
);
4078 return bfd_reloc_ok
;
4080 x
= bfd_getb16 (location
);
4083 x
= bfd_getb32 (location
);
4087 /* Check for overflow. FIXME: We may drop bits during the addition
4088 which we don't check for. We must either check at every single
4089 operation, which would be tedious, or we must do the computations
4090 in a type larger than bfd_vma, which would be inefficient. */
4091 flag
= bfd_reloc_ok
;
4092 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
4094 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
4097 /* Get the values to be added together. For signed and unsigned
4098 relocations, we assume that all values should be truncated to
4099 the size of an address. For bitfields, all the bits matter.
4100 See also bfd_check_overflow. */
4101 fieldmask
= N_ONES (howto
->bitsize
);
4102 signmask
= ~fieldmask
;
4103 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
4104 a
= (relocation
& addrmask
) >> rightshift
;
4105 b
= (x
& howto
->src_mask
& addrmask
) >> bitpos
;
4107 switch (howto
->complain_on_overflow
)
4109 case complain_overflow_signed
:
4110 /* If any sign bits are set, all sign bits must be set.
4111 That is, A must be a valid negative address after
4113 signmask
= ~(fieldmask
>> 1);
4116 case complain_overflow_bitfield
:
4117 /* Much like the signed check, but for a field one bit
4118 wider. We allow a bitfield to represent numbers in the
4119 range -2**n to 2**n-1, where n is the number of bits in the
4120 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
4121 can't overflow, which is exactly what we want. */
4123 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
4124 flag
= bfd_reloc_overflow
;
4126 /* We only need this next bit of code if the sign bit of B
4127 is below the sign bit of A. This would only happen if
4128 SRC_MASK had fewer bits than BITSIZE. Note that if
4129 SRC_MASK has more bits than BITSIZE, we can get into
4130 trouble; we would need to verify that B is in range, as
4131 we do for A above. */
4132 ss
= ((~howto
->src_mask
) >> 1) & howto
->src_mask
;
4135 /* Set all the bits above the sign bit. */
4138 /* Now we can do the addition. */
4141 /* See if the result has the correct sign. Bits above the
4142 sign bit are junk now; ignore them. If the sum is
4143 positive, make sure we did not have all negative inputs;
4144 if the sum is negative, make sure we did not have all
4145 positive inputs. The test below looks only at the sign
4146 bits, and it really just
4147 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
4149 We mask with addrmask here to explicitly allow an address
4150 wrap-around. The Linux kernel relies on it, and it is
4151 the only way to write assembler code which can run when
4152 loaded at a location 0x80000000 away from the location at
4153 which it is linked. */
4154 if (((~(a
^ b
)) & (a
^ sum
)) & signmask
& addrmask
)
4155 flag
= bfd_reloc_overflow
;
4159 case complain_overflow_unsigned
:
4160 /* Checking for an unsigned overflow is relatively easy:
4161 trim the addresses and add, and trim the result as well.
4162 Overflow is normally indicated when the result does not
4163 fit in the field. However, we also need to consider the
4164 case when, e.g., fieldmask is 0x7fffffff or smaller, an
4165 input is 0x80000000, and bfd_vma is only 32 bits; then we
4166 will get sum == 0, but there is an overflow, since the
4167 inputs did not fit in the field. Instead of doing a
4168 separate test, we can check for this by or-ing in the
4169 operands when testing for the sum overflowing its final
4171 sum
= (a
+ b
) & addrmask
;
4172 if ((a
| b
| sum
) & signmask
)
4173 flag
= bfd_reloc_overflow
;
4181 /* Put RELOCATION in the right bits. */
4182 relocation
>>= (bfd_vma
) rightshift
;
4183 relocation
<<= (bfd_vma
) bitpos
;
4185 /* Add RELOCATION to the right bits of X. */
4187 Because the relaxation may generate duplicate relocation at one address,
4188 an addition to immediate in the instruction may cause the relocation added
4190 This bug should be fixed in assembler, but a check is also needed here. */
4191 if (howto
->partial_inplace
)
4192 x
= ((x
& ~howto
->dst_mask
)
4193 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
4195 x
= ((x
& ~howto
->dst_mask
) | ((relocation
) & howto
->dst_mask
));
4198 /* Put the relocated value back in the object file. */
4208 bfd_putb16 (x
, location
);
4211 bfd_putb32 (x
, location
);
4218 static bfd_reloc_status_type
4219 nds32_elf_final_link_relocate (reloc_howto_type
*howto
, bfd
*input_bfd
,
4220 asection
*input_section
, bfd_byte
*contents
,
4221 bfd_vma address
, bfd_vma value
, bfd_vma addend
)
4225 /* Sanity check the address. */
4226 if (address
> bfd_get_section_limit (input_bfd
, input_section
))
4227 return bfd_reloc_outofrange
;
4229 /* This function assumes that we are dealing with a basic relocation
4230 against a symbol. We want to compute the value of the symbol to
4231 relocate to. This is just VALUE, the value of the symbol, plus
4232 ADDEND, any addend associated with the reloc. */
4233 relocation
= value
+ addend
;
4235 /* If the relocation is PC relative, we want to set RELOCATION to
4236 the distance between the symbol (currently in RELOCATION) and the
4237 location we are relocating. Some targets (e.g., i386-aout)
4238 arrange for the contents of the section to be the negative of the
4239 offset of the location within the section; for such targets
4240 pcrel_offset is FALSE. Other targets (e.g., m88kbcs or ELF)
4241 simply leave the contents of the section as zero; for such
4242 targets pcrel_offset is TRUE. If pcrel_offset is FALSE we do not
4243 need to subtract out the offset of the location within the
4244 section (which is just ADDRESS). */
4245 if (howto
->pc_relative
)
4247 relocation
-= (input_section
->output_section
->vma
4248 + input_section
->output_offset
);
4249 if (howto
->pcrel_offset
)
4250 relocation
-= address
;
4253 return nds32_relocate_contents (howto
, input_bfd
, relocation
,
4254 contents
+ address
);
4258 nds32_elf_output_symbol_hook (struct bfd_link_info
*info
,
4260 Elf_Internal_Sym
*elfsym ATTRIBUTE_UNUSED
,
4261 asection
*input_sec
,
4262 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4265 FILE *sym_ld_script
= NULL
;
4266 struct elf_nds32_link_hash_table
*table
;
4268 table
= nds32_elf_hash_table (info
);
4269 sym_ld_script
= table
->sym_ld_script
;
4273 if (!h
|| !name
|| *name
== '\0')
4276 if (input_sec
->flags
& SEC_EXCLUDE
)
4279 if (!check_start_export_sym
)
4281 fprintf (sym_ld_script
, "SECTIONS\n{\n");
4282 check_start_export_sym
= 1;
4285 if (h
->root
.type
== bfd_link_hash_defined
4286 || h
->root
.type
== bfd_link_hash_defweak
)
4288 if (!h
->root
.u
.def
.section
->output_section
)
4291 if (bfd_is_const_section (input_sec
))
4292 source
= input_sec
->name
;
4294 source
= input_sec
->owner
->filename
;
4296 fprintf (sym_ld_script
, "\t%s = 0x%08lx;\t /* %s */\n",
4297 h
->root
.root
.string
,
4298 (long) (h
->root
.u
.def
.value
4299 + h
->root
.u
.def
.section
->output_section
->vma
4300 + h
->root
.u
.def
.section
->output_offset
), source
);
4306 /* Relocate an NDS32/D ELF section.
4307 There is some attempt to make this function usable for many architectures,
4308 both for RELA and REL type relocs, if only to serve as a learning tool.
4310 The RELOCATE_SECTION function is called by the new ELF backend linker
4311 to handle the relocations for a section.
4313 The relocs are always passed as Rela structures; if the section
4314 actually uses Rel structures, the r_addend field will always be
4317 This function is responsible for adjust the section contents as
4318 necessary, and (if using Rela relocs and generating a
4319 relocatable output file) adjusting the reloc addend as
4322 This function does not have to worry about setting the reloc
4323 address or the reloc symbol index.
4325 LOCAL_SYMS is a pointer to the swapped in local symbols.
4327 LOCAL_SECTIONS is an array giving the section in the input file
4328 corresponding to the st_shndx field of each local symbol.
4330 The global hash table entry for the global symbols can be found
4331 via elf_sym_hashes (input_bfd).
4333 When generating relocatable output, this function must handle
4334 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4335 going to be the section symbol corresponding to the output
4336 section, which means that the addend must be adjusted
4340 dtpoff_base (struct bfd_link_info
*info
)
4342 /* If tls_sec is NULL, we should have signalled an error already. */
4343 if (elf_hash_table (info
)->tls_sec
== NULL
)
4345 return elf_hash_table (info
)->tls_sec
->vma
;
4349 nds32_elf_relocate_section (bfd
* output_bfd ATTRIBUTE_UNUSED
,
4350 struct bfd_link_info
* info
,
4352 asection
* input_section
,
4353 bfd_byte
* contents
,
4354 Elf_Internal_Rela
* relocs
,
4355 Elf_Internal_Sym
* local_syms
,
4356 asection
** local_sections
)
4358 Elf_Internal_Shdr
*symtab_hdr
;
4359 struct elf_link_hash_entry
**sym_hashes
;
4360 Elf_Internal_Rela
*rel
, *relend
;
4361 bfd_boolean ret
= TRUE
; /* Assume success. */
4363 bfd_reloc_status_type r
;
4364 const char *errmsg
= NULL
;
4366 struct elf_nds32_link_hash_table
*htab
;
4368 bfd_vma
*local_got_offsets
;
4369 asection
*sgot
, *splt
, *sreloc
;
4370 bfd_vma high_address
;
4371 struct elf_nds32_link_hash_table
*table
;
4372 int eliminate_gc_relocs
;
4373 bfd_vma fpbase_addr
;
4375 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4376 sym_hashes
= elf_sym_hashes (input_bfd
);
4377 htab
= nds32_elf_hash_table (info
);
4378 high_address
= bfd_get_section_limit (input_bfd
, input_section
);
4380 dynobj
= htab
->root
.dynobj
;
4381 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4383 sgot
= htab
->root
.sgot
;
4384 splt
= htab
->root
.splt
;
4388 relend
= relocs
+ input_section
->reloc_count
;
4390 table
= nds32_elf_hash_table (info
);
4391 eliminate_gc_relocs
= table
->eliminate_gc_relocs
;
4392 /* By this time, we can adjust the value of _SDA_BASE_. */
4393 if ((!bfd_link_relocatable (info
)))
4395 is_SDA_BASE_set
= 1;
4396 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, TRUE
);
4397 if (r
!= bfd_reloc_ok
)
4401 /* Use gp as fp to prevent truncated fit. Because in relaxation time
4402 the fp value is set as gp, and it has be reverted for instruction
4404 fpbase_addr
= elf_gp (output_bfd
);
4406 for (rel
= relocs
; rel
< relend
; rel
++)
4408 enum elf_nds32_reloc_type r_type
;
4409 reloc_howto_type
*howto
= NULL
;
4410 unsigned long r_symndx
;
4411 struct elf_link_hash_entry
*h
= NULL
;
4412 Elf_Internal_Sym
*sym
= NULL
;
4416 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
4417 ensure it's zero (we use REL relocs, not RELA). Therefore this
4418 should be assigning zero to `addend', but for clarity we use
4421 bfd_vma addend
= rel
->r_addend
;
4422 bfd_vma offset
= rel
->r_offset
;
4424 r_type
= ELF32_R_TYPE (rel
->r_info
);
4425 if (r_type
>= R_NDS32_max
)
4427 /* xgettext:c-format */
4428 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
4430 bfd_set_error (bfd_error_bad_value
);
4435 if (r_type
== R_NDS32_GNU_VTENTRY
4436 || r_type
== R_NDS32_GNU_VTINHERIT
4437 || r_type
== R_NDS32_NONE
4438 || r_type
== R_NDS32_RELA_GNU_VTENTRY
4439 || r_type
== R_NDS32_RELA_GNU_VTINHERIT
4440 || (r_type
>= R_NDS32_INSN16
&& r_type
<= R_NDS32_25_FIXED_RELA
)
4441 || r_type
== R_NDS32_DATA
4442 || r_type
== R_NDS32_TRAN
4443 || (r_type
>= R_NDS32_LONGCALL4
&& r_type
<= R_NDS32_LONGJUMP7
))
4446 /* If we enter the fp-as-gp region. Resolve the address
4448 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
4449 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
4453 /* Distance to relocation of best fp-base is encoded in R_SYM. */
4454 dist
= rel
->r_addend
>> 16;
4455 fpbase_addr
= calculate_memory_address (input_bfd
, rel
+ dist
,
4456 local_syms
, symtab_hdr
);
4458 else if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_END
4459 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
4461 fpbase_addr
= elf_gp (output_bfd
);
4464 if (((r_type
>= R_NDS32_DWARF2_OP1_RELA
4465 && r_type
<= R_NDS32_DWARF2_LEB_RELA
)
4466 || r_type
>= R_NDS32_RELAX_ENTRY
) && !bfd_link_relocatable (info
))
4469 howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
4470 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4472 /* This is a final link. */
4477 if (r_symndx
< symtab_hdr
->sh_info
)
4480 sym
= local_syms
+ r_symndx
;
4481 sec
= local_sections
[r_symndx
];
4483 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4484 addend
= rel
->r_addend
;
4488 /* External symbol. */
4489 bfd_boolean warned
, ignored
, unresolved_reloc
;
4490 int symndx
= r_symndx
- symtab_hdr
->sh_info
;
4492 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4493 r_symndx
, symtab_hdr
, sym_hashes
, h
, sec
,
4494 relocation
, unresolved_reloc
, warned
,
4497 /* la $fp, _FP_BASE_ is per-function (region).
4498 Handle it specially. */
4499 switch ((int) r_type
)
4501 case R_NDS32_SDA19S0_RELA
:
4502 case R_NDS32_SDA15S0_RELA
:
4503 case R_NDS32_20_RELA
:
4504 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
4507 relocation
= fpbase_addr
;
4514 if (bfd_link_relocatable (info
))
4516 /* This is a relocatable link. We don't have to change
4517 anything, unless the reloc is against a section symbol,
4518 in which case we have to adjust according to where the
4519 section symbol winds up in the output section. */
4520 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4521 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4526 /* Sanity check the address. */
4527 if (offset
> high_address
)
4529 r
= bfd_reloc_outofrange
;
4533 if ((r_type
>= R_NDS32_DWARF2_OP1_RELA
4534 && r_type
<= R_NDS32_DWARF2_LEB_RELA
)
4535 || r_type
>= R_NDS32_RELAX_ENTRY
)
4538 switch ((int) r_type
)
4540 case R_NDS32_GOTOFF
:
4541 /* Relocation is relative to the start of the global offset
4542 table (for ld24 rx, #uimm24), e.g. access at label+addend
4544 ld24 rx. #label@GOTOFF + addend
4546 case R_NDS32_GOTOFF_HI20
:
4547 case R_NDS32_GOTOFF_LO12
:
4548 case R_NDS32_GOTOFF_LO15
:
4549 case R_NDS32_GOTOFF_LO19
:
4550 BFD_ASSERT (sgot
!= NULL
);
4552 relocation
-= elf_gp (output_bfd
);
4555 case R_NDS32_9_PLTREL
:
4556 case R_NDS32_25_PLTREL
:
4557 /* Relocation is to the entry for this symbol in the
4558 procedure linkage table. */
4560 /* The native assembler will generate a 25_PLTREL reloc
4561 for a local symbol if you assemble a call from one
4562 section to another when using -K pic. */
4566 if (h
->forced_local
)
4569 /* We didn't make a PLT entry for this symbol. This
4570 happens when statically linking PIC code, or when
4571 using -Bsymbolic. */
4572 if (h
->plt
.offset
== (bfd_vma
) - 1)
4575 relocation
= (splt
->output_section
->vma
4576 + splt
->output_offset
+ h
->plt
.offset
);
4579 case R_NDS32_PLT_GOTREL_HI20
:
4580 case R_NDS32_PLT_GOTREL_LO12
:
4581 case R_NDS32_PLT_GOTREL_LO15
:
4582 case R_NDS32_PLT_GOTREL_LO19
:
4583 case R_NDS32_PLT_GOTREL_LO20
:
4584 if (h
== NULL
|| h
->forced_local
|| h
->plt
.offset
== (bfd_vma
) - 1)
4586 /* We didn't make a PLT entry for this symbol. This
4587 happens when statically linking PIC code, or when
4588 using -Bsymbolic. */
4589 relocation
-= elf_gp (output_bfd
);
4593 relocation
= (splt
->output_section
->vma
4594 + splt
->output_offset
+ h
->plt
.offset
);
4596 relocation
-= elf_gp (output_bfd
);
4599 case R_NDS32_PLTREL_HI20
:
4600 case R_NDS32_PLTREL_LO12
:
4602 /* Relocation is to the entry for this symbol in the
4603 procedure linkage table. */
4605 /* The native assembler will generate a 25_PLTREL reloc
4606 for a local symbol if you assemble a call from one
4607 section to another when using -K pic. */
4611 if (h
->forced_local
)
4614 if (h
->plt
.offset
== (bfd_vma
) - 1)
4615 /* We didn't make a PLT entry for this symbol. This
4616 happens when statically linking PIC code, or when
4617 using -Bsymbolic. */
4623 relocation
= (splt
->output_section
->vma
4624 + splt
->output_offset
4625 + h
->plt
.offset
+ 4)
4626 - (input_section
->output_section
->vma
4627 + input_section
->output_offset
4632 case R_NDS32_GOTPC20
:
4633 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
4634 ld24 rx,#_GLOBAL_OFFSET_TABLE_ */
4635 relocation
= elf_gp (output_bfd
);
4638 case R_NDS32_GOTPC_HI20
:
4639 case R_NDS32_GOTPC_LO12
:
4641 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
4643 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
4644 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
4647 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
4648 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
4650 relocation
= elf_gp (output_bfd
);
4651 relocation
-= (input_section
->output_section
->vma
4652 + input_section
->output_offset
+ rel
->r_offset
);
4658 case R_NDS32_GOT_HI20
:
4659 case R_NDS32_GOT_LO12
:
4660 case R_NDS32_GOT_LO15
:
4661 case R_NDS32_GOT_LO19
:
4662 /* Relocation is to the entry for this symbol in the global
4664 BFD_ASSERT (sgot
!= NULL
);
4671 off
= h
->got
.offset
;
4672 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4673 dyn
= htab
->root
.dynamic_sections_created
;
4674 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4675 bfd_link_pic (info
),
4677 || (bfd_link_pic (info
)
4680 || h
->forced_local
) && h
->def_regular
))
4682 /* This is actually a static link, or it is a
4683 -Bsymbolic link and the symbol is defined
4684 locally, or the symbol was forced to be local
4685 because of a version file. We must initialize
4686 this entry in the global offset table. Since the
4687 offset must always be a multiple of 4, we use the
4688 least significant bit to record whether we have
4689 initialized it already.
4691 When doing a dynamic link, we create a .rela.got
4692 relocation entry to initialize the value. This
4693 is done in the finish_dynamic_symbol routine. */
4698 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4702 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
4703 - elf_gp (output_bfd
);
4710 BFD_ASSERT (local_got_offsets
!= NULL
4711 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
4713 off
= local_got_offsets
[r_symndx
];
4715 /* The offset must always be a multiple of 4. We use
4716 the least significant bit to record whether we have
4717 already processed this entry. */
4722 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4724 if (bfd_link_pic (info
))
4727 Elf_Internal_Rela outrel
;
4729 /* We need to generate a R_NDS32_RELATIVE reloc
4730 for the dynamic linker. */
4731 srelgot
= htab
->root
.srelgot
;
4732 BFD_ASSERT (srelgot
!= NULL
);
4734 outrel
.r_offset
= (elf_gp (output_bfd
)
4735 + sgot
->output_offset
+ off
);
4736 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
4737 outrel
.r_addend
= relocation
;
4738 loc
= srelgot
->contents
;
4740 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
4741 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4742 ++srelgot
->reloc_count
;
4744 local_got_offsets
[r_symndx
] |= 1;
4746 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
4747 - elf_gp (output_bfd
);
4752 case R_NDS32_16_RELA
:
4753 case R_NDS32_20_RELA
:
4754 case R_NDS32_5_RELA
:
4755 case R_NDS32_32_RELA
:
4756 case R_NDS32_9_PCREL_RELA
:
4757 case R_NDS32_WORD_9_PCREL_RELA
:
4758 case R_NDS32_10_UPCREL_RELA
:
4759 case R_NDS32_15_PCREL_RELA
:
4760 case R_NDS32_17_PCREL_RELA
:
4761 case R_NDS32_25_PCREL_RELA
:
4762 case R_NDS32_HI20_RELA
:
4763 case R_NDS32_LO12S3_RELA
:
4764 case R_NDS32_LO12S2_RELA
:
4765 case R_NDS32_LO12S2_DP_RELA
:
4766 case R_NDS32_LO12S2_SP_RELA
:
4767 case R_NDS32_LO12S1_RELA
:
4768 case R_NDS32_LO12S0_RELA
:
4769 case R_NDS32_LO12S0_ORI_RELA
:
4770 if (bfd_link_pic (info
) && r_symndx
!= 0
4771 && (input_section
->flags
& SEC_ALLOC
) != 0
4772 && (eliminate_gc_relocs
== 0
4773 || (sec
&& (sec
->flags
& SEC_EXCLUDE
) == 0))
4774 && ((r_type
!= R_NDS32_9_PCREL_RELA
4775 && r_type
!= R_NDS32_WORD_9_PCREL_RELA
4776 && r_type
!= R_NDS32_10_UPCREL_RELA
4777 && r_type
!= R_NDS32_15_PCREL_RELA
4778 && r_type
!= R_NDS32_17_PCREL_RELA
4779 && r_type
!= R_NDS32_25_PCREL_RELA
4780 && !(r_type
== R_NDS32_32_RELA
4781 && strcmp (input_section
->name
, ".eh_frame") == 0))
4782 || (h
!= NULL
&& h
->dynindx
!= -1
4783 && (!info
->symbolic
|| !h
->def_regular
))))
4785 Elf_Internal_Rela outrel
;
4786 bfd_boolean skip
, relocate
;
4789 /* When generating a shared object, these relocations
4790 are copied into the output file to be resolved at run
4797 name
= bfd_elf_string_from_elf_section
4798 (input_bfd
, elf_elfheader (input_bfd
)->e_shstrndx
,
4799 elf_section_data (input_section
)->rela
.hdr
->sh_name
);
4803 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4804 && strcmp (bfd_get_section_name (input_bfd
,
4808 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4809 BFD_ASSERT (sreloc
!= NULL
);
4815 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4819 if (outrel
.r_offset
== (bfd_vma
) - 1)
4821 else if (outrel
.r_offset
== (bfd_vma
) - 2)
4822 skip
= TRUE
, relocate
= TRUE
;
4823 outrel
.r_offset
+= (input_section
->output_section
->vma
4824 + input_section
->output_offset
);
4827 memset (&outrel
, 0, sizeof outrel
);
4828 else if (r_type
== R_NDS32_17_PCREL_RELA
4829 || r_type
== R_NDS32_15_PCREL_RELA
4830 || r_type
== R_NDS32_25_PCREL_RELA
)
4832 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4833 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4834 outrel
.r_addend
= rel
->r_addend
;
4838 /* h->dynindx may be -1 if this symbol was marked to
4841 || ((info
->symbolic
|| h
->dynindx
== -1)
4845 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
4846 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4850 BFD_ASSERT (h
->dynindx
!= -1);
4851 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4852 outrel
.r_addend
= rel
->r_addend
;
4856 loc
= sreloc
->contents
;
4857 loc
+= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
4858 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4859 ++sreloc
->reloc_count
;
4861 /* If this reloc is against an external symbol, we do
4862 not want to fiddle with the addend. Otherwise, we
4863 need to include the symbol value so that it becomes
4864 an addend for the dynamic reloc. */
4870 case R_NDS32_25_ABS_RELA
:
4871 if (bfd_link_pic (info
))
4874 (_("%pB: warning: %s unsupported in shared mode"),
4875 input_bfd
, "R_NDS32_25_ABS_RELA");
4880 case R_NDS32_9_PCREL
:
4881 r
= nds32_elf_do_9_pcrel_reloc (input_bfd
, howto
, input_section
,
4883 sec
, relocation
, addend
);
4888 Elf_Internal_Rela
*lorel
;
4890 /* We allow an arbitrary number of HI20 relocs before the
4891 LO12 reloc. This permits gcc to emit the HI and LO relocs
4893 for (lorel
= rel
+ 1;
4895 && ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_HI20
); lorel
++)
4898 && (ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S3
4899 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S2
4900 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S1
4901 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S0
))
4903 nds32_elf_relocate_hi20 (input_bfd
, r_type
, rel
, lorel
,
4904 contents
, relocation
+ addend
);
4908 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4909 contents
, offset
, relocation
,
4915 case R_NDS32_GOT17S2_RELA
:
4916 case R_NDS32_GOT15S2_RELA
:
4920 BFD_ASSERT (sgot
!= NULL
);
4926 off
= h
->got
.offset
;
4927 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4929 dyn
= htab
->root
.dynamic_sections_created
;
4930 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL
4931 (dyn
, bfd_link_pic (info
), h
)
4932 || (bfd_link_pic (info
)
4938 /* This is actually a static link, or it is a
4939 -Bsymbolic link and the symbol is defined
4940 locally, or the symbol was forced to be local
4941 because of a version file. We must initialize
4942 this entry in the global offset table. Since the
4943 offset must always be a multiple of 4, we use the
4944 least significant bit to record whether we have
4945 initialized it already.
4947 When doing a dynamic link, we create a .rela.got
4948 relocation entry to initialize the value. This
4949 is done in the finish_dynamic_symbol routine. */
4954 bfd_put_32 (output_bfd
, relocation
,
4955 sgot
->contents
+ off
);
4964 BFD_ASSERT (local_got_offsets
!= NULL
4965 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
4967 off
= local_got_offsets
[r_symndx
];
4969 /* The offset must always be a multiple of 4. We use
4970 the least significant bit to record whether we have
4971 already processed this entry. */
4976 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4978 if (bfd_link_pic (info
))
4981 Elf_Internal_Rela outrel
;
4983 /* We need to generate a R_NDS32_RELATIVE reloc
4984 for the dynamic linker. */
4985 srelgot
= htab
->root
.srelgot
;
4986 BFD_ASSERT (srelgot
!= NULL
);
4988 outrel
.r_offset
= (elf_gp (output_bfd
)
4989 + sgot
->output_offset
+ off
);
4990 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
4991 outrel
.r_addend
= relocation
;
4992 loc
= srelgot
->contents
;
4994 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
4995 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4996 ++srelgot
->reloc_count
;
4998 local_got_offsets
[r_symndx
] |= 1;
5001 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5002 - elf_gp (output_bfd
);
5004 if (relocation
& align
)
5006 /* Incorrect alignment. */
5008 (_("%pB: warning: unaligned access to GOT entry"), input_bfd
);
5010 r
= bfd_reloc_dangerous
;
5015 case R_NDS32_SDA16S3_RELA
:
5016 case R_NDS32_SDA15S3_RELA
:
5017 case R_NDS32_SDA15S3
:
5021 case R_NDS32_SDA17S2_RELA
:
5022 case R_NDS32_SDA15S2_RELA
:
5023 case R_NDS32_SDA12S2_SP_RELA
:
5024 case R_NDS32_SDA12S2_DP_RELA
:
5025 case R_NDS32_SDA15S2
:
5026 case R_NDS32_SDA_FP7U2_RELA
:
5030 case R_NDS32_SDA18S1_RELA
:
5031 case R_NDS32_SDA15S1_RELA
:
5032 case R_NDS32_SDA15S1
:
5036 case R_NDS32_SDA19S0_RELA
:
5037 case R_NDS32_SDA15S0_RELA
:
5038 case R_NDS32_SDA15S0
:
5042 BFD_ASSERT (sec
!= NULL
);
5044 /* If the symbol is in the abs section, the out_bfd will be null.
5045 This happens when the relocation has a symbol@GOTOFF. */
5046 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, FALSE
);
5047 if (r
!= bfd_reloc_ok
)
5050 (_("%pB: warning: relocate SDA_BASE failed"), input_bfd
);
5055 /* At this point `relocation' contains the object's
5057 if (r_type
== R_NDS32_SDA_FP7U2_RELA
)
5059 relocation
-= fpbase_addr
;
5063 /* Now it contains the offset from _SDA_BASE_. */
5065 /* Make sure alignment is correct. */
5067 if (relocation
& align
)
5069 /* Incorrect alignment. */
5071 /* xgettext:c-format */
5072 (_("%pB(%pA): warning: unaligned small data access"
5074 input_bfd
, input_section
, r_type
);
5081 case R_NDS32_17IFC_PCREL_RELA
:
5082 case R_NDS32_10IFCU_PCREL_RELA
:
5086 case R_NDS32_TLS_LE_HI20
:
5087 case R_NDS32_TLS_LE_LO12
:
5088 case R_NDS32_TLS_LE_20
:
5089 case R_NDS32_TLS_LE_15S0
:
5090 case R_NDS32_TLS_LE_15S1
:
5091 case R_NDS32_TLS_LE_15S2
:
5092 if (elf_hash_table (info
)->tls_sec
!= NULL
)
5093 relocation
-= (elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
);
5095 case R_NDS32_TLS_IE_HI20
:
5096 case R_NDS32_TLS_IE_LO12S2
:
5098 /* Relocation is to the entry for this symbol in the global
5100 unsigned int tls_type
;
5102 Elf_Internal_Rela outrel
;
5107 BFD_ASSERT (sgot
!= NULL
);
5112 off
= h
->got
.offset
;
5113 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5114 dyn
= htab
->root
.dynamic_sections_created
;
5115 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
5116 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
5117 && (!bfd_link_pic (info
)
5118 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
5123 /* Never happen currently. */
5124 BFD_ASSERT (local_got_offsets
!= NULL
5125 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5127 off
= local_got_offsets
[r_symndx
];
5129 tls_type
= elf32_nds32_local_got_tls_type (input_bfd
)[r_symndx
];
5131 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
;
5133 if (r_type
== R_NDS32_TLS_IE_LO12S2
)
5136 /* The offset must always be a multiple of 4. We use
5137 the least significant bit to record whether we have
5138 already processed this entry. */
5143 bfd_boolean need_relocs
= FALSE
;
5144 srelgot
= htab
->root
.srelgot
;
5145 if ((bfd_link_pic (info
) || indx
!= 0)
5147 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5148 || h
->root
.type
!= bfd_link_hash_undefweak
))
5151 BFD_ASSERT (srelgot
!= NULL
);
5153 if (tls_type
& GOT_TLS_IE
)
5157 if (h
->dynindx
== 0)
5158 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5160 outrel
.r_addend
= 0;
5161 outrel
.r_offset
= (sgot
->output_section
->vma
5162 + sgot
->output_offset
5165 ELF32_R_INFO (h
->dynindx
, R_NDS32_TLS_TPOFF
);
5167 loc
= srelgot
->contents
;
5169 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5170 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5171 ++srelgot
->reloc_count
;
5174 bfd_put_32 (output_bfd
, h
->root
.u
.def
.value
- TP_OFFSET
,
5175 sgot
->contents
+ off
);
5181 /* DON'T fall through. */
5184 /* OLD_NDS32_RELOC. */
5186 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5187 contents
, offset
, relocation
, addend
);
5191 switch ((int) r_type
)
5193 case R_NDS32_20_RELA
:
5194 case R_NDS32_5_RELA
:
5195 case R_NDS32_9_PCREL_RELA
:
5196 case R_NDS32_WORD_9_PCREL_RELA
:
5197 case R_NDS32_10_UPCREL_RELA
:
5198 case R_NDS32_15_PCREL_RELA
:
5199 case R_NDS32_17_PCREL_RELA
:
5200 case R_NDS32_25_PCREL_RELA
:
5201 case R_NDS32_25_ABS_RELA
:
5202 case R_NDS32_HI20_RELA
:
5203 case R_NDS32_LO12S3_RELA
:
5204 case R_NDS32_LO12S2_RELA
:
5205 case R_NDS32_LO12S2_DP_RELA
:
5206 case R_NDS32_LO12S2_SP_RELA
:
5207 case R_NDS32_LO12S1_RELA
:
5208 case R_NDS32_LO12S0_RELA
:
5209 case R_NDS32_LO12S0_ORI_RELA
:
5210 case R_NDS32_SDA16S3_RELA
:
5211 case R_NDS32_SDA17S2_RELA
:
5212 case R_NDS32_SDA18S1_RELA
:
5213 case R_NDS32_SDA19S0_RELA
:
5214 case R_NDS32_SDA15S3_RELA
:
5215 case R_NDS32_SDA15S2_RELA
:
5216 case R_NDS32_SDA12S2_DP_RELA
:
5217 case R_NDS32_SDA12S2_SP_RELA
:
5218 case R_NDS32_SDA15S1_RELA
:
5219 case R_NDS32_SDA15S0_RELA
:
5220 case R_NDS32_SDA_FP7U2_RELA
:
5221 case R_NDS32_9_PLTREL
:
5222 case R_NDS32_25_PLTREL
:
5224 case R_NDS32_GOT_HI20
:
5225 case R_NDS32_GOT_LO12
:
5226 case R_NDS32_GOT_LO15
:
5227 case R_NDS32_GOT_LO19
:
5228 case R_NDS32_GOT15S2_RELA
:
5229 case R_NDS32_GOT17S2_RELA
:
5230 case R_NDS32_GOTPC20
:
5231 case R_NDS32_GOTPC_HI20
:
5232 case R_NDS32_GOTPC_LO12
:
5233 case R_NDS32_GOTOFF
:
5234 case R_NDS32_GOTOFF_HI20
:
5235 case R_NDS32_GOTOFF_LO12
:
5236 case R_NDS32_GOTOFF_LO15
:
5237 case R_NDS32_GOTOFF_LO19
:
5238 case R_NDS32_PLTREL_HI20
:
5239 case R_NDS32_PLTREL_LO12
:
5240 case R_NDS32_PLT_GOTREL_HI20
:
5241 case R_NDS32_PLT_GOTREL_LO12
:
5242 case R_NDS32_PLT_GOTREL_LO15
:
5243 case R_NDS32_PLT_GOTREL_LO19
:
5244 case R_NDS32_PLT_GOTREL_LO20
:
5245 case R_NDS32_17IFC_PCREL_RELA
:
5246 case R_NDS32_10IFCU_PCREL_RELA
:
5247 case R_NDS32_TLS_LE_HI20
:
5248 case R_NDS32_TLS_LE_LO12
:
5249 case R_NDS32_TLS_IE_HI20
:
5250 case R_NDS32_TLS_IE_LO12S2
:
5251 case R_NDS32_TLS_LE_20
:
5252 case R_NDS32_TLS_LE_15S0
:
5253 case R_NDS32_TLS_LE_15S1
:
5254 case R_NDS32_TLS_LE_15S2
:
5255 /* Instruction related relocs must handle endian properly. */
5256 /* NOTE: PIC IS NOT HANDLE YET; DO IT LATER. */
5257 r
= nds32_elf_final_link_relocate (howto
, input_bfd
,
5258 input_section
, contents
,
5259 rel
->r_offset
, relocation
,
5264 /* All other relocs can use default handler. */
5265 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5266 contents
, rel
->r_offset
,
5267 relocation
, rel
->r_addend
);
5273 if (r
!= bfd_reloc_ok
)
5275 /* FIXME: This should be generic enough to go in a utility. */
5279 name
= h
->root
.root
.string
;
5282 name
= bfd_elf_string_from_elf_section
5283 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
5284 if (name
== NULL
|| *name
== '\0')
5285 name
= bfd_section_name (input_bfd
, sec
);
5293 case bfd_reloc_overflow
:
5294 (*info
->callbacks
->reloc_overflow
)
5295 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5296 (bfd_vma
) 0, input_bfd
, input_section
, offset
);
5299 case bfd_reloc_undefined
:
5300 (*info
->callbacks
->undefined_symbol
)
5301 (info
, name
, input_bfd
, input_section
, offset
, TRUE
);
5304 case bfd_reloc_outofrange
:
5305 errmsg
= _("internal error: out of range error");
5308 case bfd_reloc_notsupported
:
5309 errmsg
= _("internal error: unsupported relocation error");
5312 case bfd_reloc_dangerous
:
5313 errmsg
= _("internal error: dangerous error");
5317 errmsg
= _("internal error: unknown error");
5321 (*info
->callbacks
->warning
) (info
, errmsg
, name
, input_bfd
,
5322 input_section
, offset
);
5331 /* Finish up dynamic symbol handling. We set the contents of various
5332 dynamic sections here. */
5335 nds32_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
5336 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
)
5338 struct elf_nds32_link_hash_table
*htab
;
5341 htab
= nds32_elf_hash_table (info
);
5343 if (h
->plt
.offset
!= (bfd_vma
) - 1)
5351 bfd_vma local_plt_offset
;
5352 Elf_Internal_Rela rela
;
5354 /* This symbol has an entry in the procedure linkage table. Set
5357 BFD_ASSERT (h
->dynindx
!= -1);
5359 splt
= htab
->root
.splt
;
5360 sgot
= htab
->root
.sgotplt
;
5361 srela
= htab
->root
.srelplt
;
5362 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
5364 /* Get the index in the procedure linkage table which
5365 corresponds to this symbol. This is the index of this symbol
5366 in all the symbols for which we are making plt entries. The
5367 first entry in the procedure linkage table is reserved. */
5368 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
5370 /* Get the offset into the .got table of the entry that
5371 corresponds to this function. Each .got entry is 4 bytes.
5372 The first three are reserved. */
5373 got_offset
= (plt_index
+ 3) * 4;
5375 /* Fill in the entry in the procedure linkage table. */
5376 if (!bfd_link_pic (info
))
5380 insn
= PLT_ENTRY_WORD0
+ (((sgot
->output_section
->vma
5381 + sgot
->output_offset
+ got_offset
) >> 12)
5383 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
5385 insn
= PLT_ENTRY_WORD1
+ (((sgot
->output_section
->vma
5386 + sgot
->output_offset
+ got_offset
) & 0x0fff)
5388 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
5390 insn
= PLT_ENTRY_WORD2
;
5391 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
5393 insn
= PLT_ENTRY_WORD3
+ (plt_index
& 0x7ffff);
5394 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
5396 insn
= PLT_ENTRY_WORD4
5397 + (((unsigned int) ((-(h
->plt
.offset
+ 16)) >> 1)) & 0xffffff);
5398 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
5399 local_plt_offset
= 12;
5403 /* sda_base must be set at this time. */
5407 /* FIXME, sda_base is 65536, it will damage opcode. */
5408 /* insn = PLT_PIC_ENTRY_WORD0 + (((got_offset - sda_base) >> 2) & 0x7fff); */
5409 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ got_offset
5410 - elf_gp (output_bfd
);
5411 insn
= PLT_PIC_ENTRY_WORD0
+ ((offset
>> 12) & 0xfffff);
5412 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
5414 insn
= PLT_PIC_ENTRY_WORD1
+ (offset
& 0xfff);
5415 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
5417 insn
= PLT_PIC_ENTRY_WORD2
;
5418 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
5420 insn
= PLT_PIC_ENTRY_WORD3
;
5421 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
5423 insn
= PLT_PIC_ENTRY_WORD4
+ (plt_index
& 0x7fffff);
5424 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
5426 insn
= PLT_PIC_ENTRY_WORD5
5427 + (((unsigned int) ((-(h
->plt
.offset
+ 20)) >> 1)) & 0xffffff);
5428 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 20);
5430 local_plt_offset
= 16;
5433 /* Fill in the entry in the global offset table,
5434 so it will fall through to the next instruction for the first time. */
5435 bfd_put_32 (output_bfd
,
5436 (splt
->output_section
->vma
+ splt
->output_offset
5437 + h
->plt
.offset
+ local_plt_offset
),
5438 sgot
->contents
+ got_offset
);
5440 /* Fill in the entry in the .rela.plt section. */
5441 rela
.r_offset
= (sgot
->output_section
->vma
5442 + sgot
->output_offset
+ got_offset
);
5443 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_JMP_SLOT
);
5445 loc
= srela
->contents
;
5446 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
5447 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5449 if (!h
->def_regular
)
5451 /* Mark the symbol as undefined, rather than as defined in
5452 the .plt section. Leave the value alone. */
5453 sym
->st_shndx
= SHN_UNDEF
;
5454 if (!h
->ref_regular_nonweak
)
5459 if (h
->got
.offset
!= (bfd_vma
) - 1)
5463 Elf_Internal_Rela rela
;
5465 /* This symbol has an entry in the global offset table.
5468 sgot
= htab
->root
.sgot
;
5469 srela
= htab
->root
.srelgot
;
5470 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
5472 rela
.r_offset
= (sgot
->output_section
->vma
5473 + sgot
->output_offset
+ (h
->got
.offset
& ~1));
5475 /* If this is a -Bsymbolic link, and the symbol is defined
5476 locally, we just want to emit a RELATIVE reloc. Likewise if
5477 the symbol was forced to be local because of a version file.
5478 The entry in the global offset table will already have been
5479 initialized in the relocate_section function. */
5480 if (bfd_link_pic (info
)
5482 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
5484 rela
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5485 rela
.r_addend
= (h
->root
.u
.def
.value
5486 + h
->root
.u
.def
.section
->output_section
->vma
5487 + h
->root
.u
.def
.section
->output_offset
);
5491 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
5492 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5493 sgot
->contents
+ h
->got
.offset
);
5494 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_GLOB_DAT
);
5498 loc
= srela
->contents
;
5499 loc
+= srela
->reloc_count
* sizeof (Elf32_External_Rela
);
5500 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5501 ++srela
->reloc_count
;
5507 Elf_Internal_Rela rela
;
5509 /* This symbols needs a copy reloc. Set it up. */
5511 BFD_ASSERT (h
->dynindx
!= -1
5512 && (h
->root
.type
== bfd_link_hash_defined
5513 || h
->root
.type
== bfd_link_hash_defweak
));
5515 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
, ".rela.bss");
5516 BFD_ASSERT (s
!= NULL
);
5518 rela
.r_offset
= (h
->root
.u
.def
.value
5519 + h
->root
.u
.def
.section
->output_section
->vma
5520 + h
->root
.u
.def
.section
->output_offset
);
5521 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_COPY
);
5524 loc
+= s
->reloc_count
* sizeof (Elf32_External_Rela
);
5525 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5529 /* Mark some specially defined symbols as absolute. */
5530 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5531 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5532 sym
->st_shndx
= SHN_ABS
;
5538 /* Finish up the dynamic sections. */
5541 nds32_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
5543 struct elf_nds32_link_hash_table
*htab
;
5548 htab
= nds32_elf_hash_table (info
);
5549 dynobj
= htab
->root
.dynobj
;
5551 sgot
= htab
->root
.sgotplt
;
5552 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5554 if (htab
->root
.dynamic_sections_created
)
5557 Elf32_External_Dyn
*dyncon
, *dynconend
;
5559 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
5561 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5562 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5564 for (; dyncon
< dynconend
; dyncon
++)
5566 Elf_Internal_Dyn dyn
;
5569 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5577 s
= htab
->root
.sgotplt
;
5580 s
= htab
->root
.srelplt
;
5582 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5583 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5587 s
= htab
->root
.srelplt
;
5588 dyn
.d_un
.d_val
= s
->size
;
5589 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5594 /* Fill in the first entry in the procedure linkage table. */
5595 splt
= htab
->root
.splt
;
5596 if (splt
&& splt
->size
> 0)
5598 if (bfd_link_pic (info
))
5603 /* FIXME, sda_base is 65536, it will damage opcode. */
5604 /* insn = PLT_PIC_ENTRY_WORD0 + (((got_offset - sda_base) >> 2) & 0x7fff); */
5605 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4
5606 - elf_gp (output_bfd
);
5607 insn
= PLT0_PIC_ENTRY_WORD0
| ((offset
>> 12) & 0xfffff);
5608 bfd_putb32 (insn
, splt
->contents
);
5610 /* insn = PLT0_PIC_ENTRY_WORD0 | (((8 - sda_base) >> 2) & 0x7fff) ; */
5611 /* here has a typo? */
5612 insn
= PLT0_PIC_ENTRY_WORD1
| (offset
& 0xfff);
5613 bfd_putb32 (insn
, splt
->contents
+ 4);
5615 insn
= PLT0_PIC_ENTRY_WORD2
;
5616 bfd_putb32 (insn
, splt
->contents
+ 8);
5618 insn
= PLT0_PIC_ENTRY_WORD3
;
5619 bfd_putb32 (insn
, splt
->contents
+ 12);
5621 insn
= PLT0_PIC_ENTRY_WORD4
;
5622 bfd_putb32 (insn
, splt
->contents
+ 16);
5624 insn
= PLT0_PIC_ENTRY_WORD5
;
5625 bfd_putb32 (insn
, splt
->contents
+ 20);
5632 /* addr = .got + 4 */
5633 addr
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4;
5634 insn
= PLT0_ENTRY_WORD0
| ((addr
>> 12) & 0xfffff);
5635 bfd_putb32 (insn
, splt
->contents
);
5637 insn
= PLT0_ENTRY_WORD1
| (addr
& 0x0fff);
5638 bfd_putb32 (insn
, splt
->contents
+ 4);
5640 insn
= PLT0_ENTRY_WORD2
;
5641 bfd_putb32 (insn
, splt
->contents
+ 8);
5643 insn
= PLT0_ENTRY_WORD3
;
5644 bfd_putb32 (insn
, splt
->contents
+ 12);
5646 insn
= PLT0_ENTRY_WORD4
;
5647 bfd_putb32 (insn
, splt
->contents
+ 16);
5650 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
5655 /* Fill in the first three entries in the global offset table. */
5656 if (sgot
&& sgot
->size
> 0)
5659 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5661 bfd_put_32 (output_bfd
,
5662 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5664 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
5665 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
5667 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5674 /* Set the right machine number. */
5677 nds32_elf_object_p (bfd
*abfd
)
5679 static unsigned int cur_arch
= 0;
5681 if (E_N1_ARCH
!= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
))
5683 /* E_N1_ARCH is a wild card, so it is set only when no others exist. */
5684 cur_arch
= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
);
5691 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1
);
5694 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h
);
5696 case E_NDS_ARCH_STAR_V2_0
:
5697 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v2
);
5699 case E_NDS_ARCH_STAR_V3_0
:
5700 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3
);
5702 case E_NDS_ARCH_STAR_V3_M
:
5703 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3m
);
5710 /* Store the machine number in the flags field. */
5713 nds32_elf_final_write_processing (bfd
*abfd
,
5714 bfd_boolean linker ATTRIBUTE_UNUSED
)
5717 static unsigned int cur_mach
= 0;
5719 if (bfd_mach_n1
!= bfd_get_mach (abfd
))
5721 cur_mach
= bfd_get_mach (abfd
);
5727 /* Only happen when object is empty, since the case is abandon. */
5729 val
|= E_NDS_ABI_AABI
;
5730 val
|= E_NDS32_ELF_VER_1_4
;
5735 case bfd_mach_n1h_v2
:
5736 val
= E_NDS_ARCH_STAR_V2_0
;
5738 case bfd_mach_n1h_v3
:
5739 val
= E_NDS_ARCH_STAR_V3_0
;
5741 case bfd_mach_n1h_v3m
:
5742 val
= E_NDS_ARCH_STAR_V3_M
;
5749 elf_elfheader (abfd
)->e_flags
&= ~EF_NDS_ARCH
;
5750 elf_elfheader (abfd
)->e_flags
|= val
;
5753 /* Function to keep NDS32 specific file flags. */
5756 nds32_elf_set_private_flags (bfd
*abfd
, flagword flags
)
5758 BFD_ASSERT (!elf_flags_init (abfd
)
5759 || elf_elfheader (abfd
)->e_flags
== flags
);
5761 elf_elfheader (abfd
)->e_flags
= flags
;
5762 elf_flags_init (abfd
) = TRUE
;
5767 convert_e_flags (unsigned int e_flags
, unsigned int arch
)
5769 if ((e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
)
5771 /* From 0.9 to 1.0. */
5772 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V1_0
;
5774 /* Invert E_NDS32_HAS_NO_MAC_INST. */
5775 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
5776 if (arch
== E_NDS_ARCH_STAR_V1_0
)
5783 /* From 1.0 to 2.0. */
5784 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V2_0
;
5786 /* Clear E_NDS32_HAS_MFUSR_PC_INST. */
5787 e_flags
&= ~E_NDS32_HAS_MFUSR_PC_INST
;
5789 /* Invert E_NDS32_HAS_NO_MAC_INST. */
5790 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
5795 nds32_check_vec_size (bfd
*ibfd
)
5797 static unsigned int nds32_vec_size
= 0;
5799 asection
*sec_t
= NULL
;
5800 bfd_byte
*contents
= NULL
;
5802 sec_t
= bfd_get_section_by_name (ibfd
, ".nds32_e_flags");
5804 if (sec_t
&& sec_t
->size
>= 4)
5806 /* Get vec_size in file. */
5807 unsigned int flag_t
;
5809 nds32_get_section_contents (ibfd
, sec_t
, &contents
, TRUE
);
5810 flag_t
= bfd_get_32 (ibfd
, contents
);
5812 /* The value could only be 4 or 16. */
5814 if (!nds32_vec_size
)
5815 /* Set if not set yet. */
5816 nds32_vec_size
= (flag_t
& 0x3);
5817 else if (nds32_vec_size
!= (flag_t
& 0x3))
5820 /* xgettext:c-format */
5821 (_("%pB: ISR vector size mismatch"
5822 " with previous modules, previous %u-byte, current %u-byte"),
5824 nds32_vec_size
== 1 ? 4 : nds32_vec_size
== 2 ? 16 : 0xffffffff,
5825 (flag_t
& 0x3) == 1 ? 4 : (flag_t
& 0x3) == 2 ? 16 : 0xffffffff);
5829 /* Only keep the first vec_size section. */
5830 sec_t
->flags
|= SEC_EXCLUDE
;
5836 /* Merge backend specific data from an object file to the output
5837 object file when linking. */
5840 nds32_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5842 bfd
*obfd
= info
->output_bfd
;
5845 flagword out_16regs
;
5847 flagword out_no_mac
;
5849 flagword out_version
;
5850 flagword in_version
;
5851 flagword out_fpu_config
;
5852 flagword in_fpu_config
;
5854 /* TODO: Revise to use object-attributes instead. */
5855 if (!nds32_check_vec_size (ibfd
))
5858 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5859 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5862 if (bfd_little_endian (ibfd
) != bfd_little_endian (obfd
))
5865 (_("%pB: warning: endian mismatch with previous modules"), ibfd
);
5867 bfd_set_error (bfd_error_bad_value
);
5871 in_version
= elf_elfheader (ibfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
5872 if (in_version
== E_NDS32_ELF_VER_1_2
)
5875 (_("%pB: warning: older version of object file encountered, "
5876 "please recompile with current tool chain"), ibfd
);
5879 /* We may need to merge V1 and V2 arch object files to V2. */
5880 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5881 != (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
5883 /* Need to convert version. */
5884 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5885 == E_NDS_ARCH_STAR_RESERVED
)
5887 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
5889 else if ((elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
5890 || (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5891 > (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
5893 elf_elfheader (obfd
)->e_flags
=
5894 convert_e_flags (elf_elfheader (obfd
)->e_flags
,
5895 (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
));
5899 elf_elfheader (ibfd
)->e_flags
=
5900 convert_e_flags (elf_elfheader (ibfd
)->e_flags
,
5901 (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
));
5905 /* Extract some flags. */
5906 in_flags
= elf_elfheader (ibfd
)->e_flags
5907 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
5908 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
5910 /* The following flags need special treatment. */
5911 in_16regs
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
5912 in_no_mac
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
5913 in_fpu_config
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
5915 /* Extract some flags. */
5916 out_flags
= elf_elfheader (obfd
)->e_flags
5917 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
5918 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
5920 /* The following flags need special treatment. */
5921 out_16regs
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
5922 out_no_mac
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
5923 out_fpu_config
= elf_elfheader (obfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
5924 out_version
= elf_elfheader (obfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
5925 if (!elf_flags_init (obfd
))
5927 /* If the input is the default architecture then do not
5928 bother setting the flags for the output architecture,
5929 instead allow future merges to do this. If no future
5930 merges ever set these flags then they will retain their
5931 unitialised values, which surprise surprise, correspond
5932 to the default values. */
5933 if (bfd_get_arch_info (ibfd
)->the_default
)
5936 elf_flags_init (obfd
) = TRUE
;
5937 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
5939 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5940 && bfd_get_arch_info (obfd
)->the_default
)
5942 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
5943 bfd_get_mach (ibfd
));
5949 /* Check flag compatibility. */
5950 if ((in_flags
& EF_NDS_ABI
) != (out_flags
& EF_NDS_ABI
))
5953 (_("%pB: error: ABI mismatch with previous modules"), ibfd
);
5955 bfd_set_error (bfd_error_bad_value
);
5959 if ((in_flags
& EF_NDS_ARCH
) != (out_flags
& EF_NDS_ARCH
))
5961 if (((in_flags
& EF_NDS_ARCH
) != E_N1_ARCH
))
5964 (_("%pB: error: instruction set mismatch with previous modules"),
5967 bfd_set_error (bfd_error_bad_value
);
5972 /* When linking with V1.2 and V1.3 objects together the output is V1.2.
5973 and perf ext1 and DIV are mergerd to perf ext1. */
5974 if (in_version
== E_NDS32_ELF_VER_1_2
|| out_version
== E_NDS32_ELF_VER_1_2
)
5976 elf_elfheader (obfd
)->e_flags
=
5977 (in_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
5978 | (out_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
5979 | (((in_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
5980 ? E_NDS32_HAS_EXT_INST
: 0)
5981 | (((out_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
5982 ? E_NDS32_HAS_EXT_INST
: 0)
5983 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
5984 | ((in_version
> out_version
) ? out_version
: in_version
);
5988 if (in_version
!= out_version
)
5990 /* xgettext:c-format */
5991 (_("%pB: warning: incompatible elf-versions %s and %s"),
5992 ibfd
, nds32_elfver_strtab
[out_version
],
5993 nds32_elfver_strtab
[in_version
]);
5995 elf_elfheader (obfd
)->e_flags
= in_flags
| out_flags
5996 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
5997 | (in_fpu_config
> out_fpu_config
? in_fpu_config
: out_fpu_config
)
5998 | (in_version
> out_version
? out_version
: in_version
);
6004 /* Display the flags field. */
6007 nds32_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6009 FILE *file
= (FILE *) ptr
;
6011 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6013 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6015 fprintf (file
, _("private flags = %lx"), elf_elfheader (abfd
)->e_flags
);
6017 switch (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
)
6021 fprintf (file
, _(": n1 instructions"));
6024 fprintf (file
, _(": n1h instructions"));
6034 nds32_elf_action_discarded (asection
*sec
)
6038 (".gcc_except_table", sec
->name
, sizeof (".gcc_except_table") - 1) == 0)
6041 return _bfd_elf_default_action_discarded (sec
);
6045 nds32_elf_gc_mark_hook (asection
*sec
, struct bfd_link_info
*info
,
6046 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
6047 Elf_Internal_Sym
*sym
)
6050 switch (ELF32_R_TYPE (rel
->r_info
))
6052 case R_NDS32_GNU_VTINHERIT
:
6053 case R_NDS32_GNU_VTENTRY
:
6054 case R_NDS32_RELA_GNU_VTINHERIT
:
6055 case R_NDS32_RELA_GNU_VTENTRY
:
6059 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6062 /* Look through the relocs for a section during the first phase.
6063 Since we don't do .gots or .plts, we just need to consider the
6064 virtual table relocs for gc. */
6067 nds32_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6068 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6070 Elf_Internal_Shdr
*symtab_hdr
;
6071 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6072 const Elf_Internal_Rela
*rel
;
6073 const Elf_Internal_Rela
*rel_end
;
6074 struct elf_nds32_link_hash_table
*htab
;
6076 asection
*sreloc
= NULL
;
6078 if (bfd_link_relocatable (info
))
6081 /* Don't do anything special with non-loaded, non-alloced sections.
6082 In particular, any relocs in such sections should not affect GOT
6083 and PLT reference counting (ie. we don't allow them to create GOT
6084 or PLT entries), there's no possibility or desire to optimize TLS
6085 relocs, and there's not much point in propagating relocs to shared
6086 libs that the dynamic linker won't relocate. */
6087 if ((sec
->flags
& SEC_ALLOC
) == 0)
6090 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6091 sym_hashes
= elf_sym_hashes (abfd
);
6093 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6094 if (!elf_bad_symtab (abfd
))
6095 sym_hashes_end
-= symtab_hdr
->sh_info
;
6097 htab
= nds32_elf_hash_table (info
);
6098 dynobj
= htab
->root
.dynobj
;
6100 rel_end
= relocs
+ sec
->reloc_count
;
6101 for (rel
= relocs
; rel
< rel_end
; rel
++)
6103 enum elf_nds32_reloc_type r_type
;
6104 struct elf_link_hash_entry
*h
;
6105 unsigned long r_symndx
;
6106 int tls_type
, old_tls_type
;
6108 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6109 r_type
= ELF32_R_TYPE (rel
->r_info
);
6110 if (r_symndx
< symtab_hdr
->sh_info
)
6114 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6115 while (h
->root
.type
== bfd_link_hash_indirect
6116 || h
->root
.type
== bfd_link_hash_warning
)
6117 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6120 /* Some relocs require a global offset table. We create
6121 got section here, since these relocation need got section
6122 and it is not created yet. */
6123 if (htab
->root
.sgot
== NULL
)
6127 case R_NDS32_GOT_HI20
:
6128 case R_NDS32_GOT_LO12
:
6129 case R_NDS32_GOT_LO15
:
6130 case R_NDS32_GOT_LO19
:
6131 case R_NDS32_GOT17S2_RELA
:
6132 case R_NDS32_GOT15S2_RELA
:
6133 case R_NDS32_GOTOFF
:
6134 case R_NDS32_GOTOFF_HI20
:
6135 case R_NDS32_GOTOFF_LO12
:
6136 case R_NDS32_GOTOFF_LO15
:
6137 case R_NDS32_GOTOFF_LO19
:
6138 case R_NDS32_GOTPC20
:
6139 case R_NDS32_GOTPC_HI20
:
6140 case R_NDS32_GOTPC_LO12
:
6142 case R_NDS32_TLS_IE_HI20
:
6143 case R_NDS32_TLS_IE_LO12S2
:
6145 htab
->root
.dynobj
= dynobj
= abfd
;
6146 if (!_bfd_elf_create_got_section (dynobj
, info
))
6155 switch ((int) r_type
)
6157 case R_NDS32_GOT_HI20
:
6158 case R_NDS32_GOT_LO12
:
6159 case R_NDS32_GOT_LO15
:
6160 case R_NDS32_GOT_LO19
:
6162 case R_NDS32_TLS_IE_HI20
:
6163 case R_NDS32_TLS_IE_LO12S2
:
6166 case R_NDS32_TLS_IE_HI20
:
6167 case R_NDS32_TLS_IE_LO12S2
:
6168 tls_type
= GOT_TLS_IE
;
6171 tls_type
= GOT_NORMAL
;
6176 old_tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
6177 h
->got
.refcount
+= 1;
6181 bfd_signed_vma
*local_got_refcounts
;
6183 /* This is a global offset table entry for a local
6185 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6186 if (local_got_refcounts
== NULL
)
6190 size
= symtab_hdr
->sh_info
;
6191 size
*= sizeof (bfd_signed_vma
);
6192 local_got_refcounts
= (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
6193 if (local_got_refcounts
== NULL
)
6195 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6197 local_got_refcounts
[r_symndx
] += 1;
6198 old_tls_type
= elf32_nds32_local_got_tls_type (abfd
)[r_symndx
];
6201 /* We will already have issued an error message if there
6202 is a TLS/non-TLS mismatch, based on the symbol
6203 type. So just combine any TLS types needed. */
6204 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
6205 && tls_type
!= GOT_NORMAL
)
6206 tls_type
|= old_tls_type
;
6208 if (old_tls_type
!= tls_type
)
6211 elf32_nds32_hash_entry (h
)->tls_type
= tls_type
;
6213 elf32_nds32_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
6216 case R_NDS32_9_PLTREL
:
6217 case R_NDS32_25_PLTREL
:
6218 case R_NDS32_PLTREL_HI20
:
6219 case R_NDS32_PLTREL_LO12
:
6220 case R_NDS32_PLT_GOTREL_HI20
:
6221 case R_NDS32_PLT_GOTREL_LO12
:
6222 case R_NDS32_PLT_GOTREL_LO15
:
6223 case R_NDS32_PLT_GOTREL_LO19
:
6224 case R_NDS32_PLT_GOTREL_LO20
:
6226 /* This symbol requires a procedure linkage table entry. We
6227 actually build the entry in adjust_dynamic_symbol,
6228 because this might be a case of linking PIC code without
6229 linking in any dynamic objects, in which case we don't
6230 need to generate a procedure linkage table after all. */
6232 /* If this is a local symbol, we resolve it directly without
6233 creating a procedure linkage table entry. */
6237 if (h
->forced_local
)
6240 elf32_nds32_hash_entry (h
)->tls_type
= GOT_NORMAL
;
6242 h
->plt
.refcount
+= 1;
6245 case R_NDS32_16_RELA
:
6246 case R_NDS32_20_RELA
:
6247 case R_NDS32_5_RELA
:
6248 case R_NDS32_32_RELA
:
6249 case R_NDS32_HI20_RELA
:
6250 case R_NDS32_LO12S3_RELA
:
6251 case R_NDS32_LO12S2_RELA
:
6252 case R_NDS32_LO12S2_DP_RELA
:
6253 case R_NDS32_LO12S2_SP_RELA
:
6254 case R_NDS32_LO12S1_RELA
:
6255 case R_NDS32_LO12S0_RELA
:
6256 case R_NDS32_LO12S0_ORI_RELA
:
6257 case R_NDS32_SDA16S3_RELA
:
6258 case R_NDS32_SDA17S2_RELA
:
6259 case R_NDS32_SDA18S1_RELA
:
6260 case R_NDS32_SDA19S0_RELA
:
6261 case R_NDS32_SDA15S3_RELA
:
6262 case R_NDS32_SDA15S2_RELA
:
6263 case R_NDS32_SDA12S2_DP_RELA
:
6264 case R_NDS32_SDA12S2_SP_RELA
:
6265 case R_NDS32_SDA15S1_RELA
:
6266 case R_NDS32_SDA15S0_RELA
:
6267 case R_NDS32_SDA_FP7U2_RELA
:
6268 case R_NDS32_15_PCREL_RELA
:
6269 case R_NDS32_17_PCREL_RELA
:
6270 case R_NDS32_25_PCREL_RELA
:
6272 if (h
!= NULL
&& !bfd_link_pic (info
))
6275 h
->plt
.refcount
+= 1;
6278 /* If we are creating a shared library, and this is a reloc against
6279 a global symbol, or a non PC relative reloc against a local
6280 symbol, then we need to copy the reloc into the shared library.
6281 However, if we are linking with -Bsymbolic, we do not need to
6282 copy a reloc against a global symbol which is defined in an
6283 object we are including in the link (i.e., DEF_REGULAR is set).
6284 At this point we have not seen all the input files, so it is
6285 possible that DEF_REGULAR is not set now but will be set later
6286 (it is never cleared). We account for that possibility below by
6287 storing information in the dyn_relocs field of the hash table
6288 entry. A similar situation occurs when creating shared libraries
6289 and symbol visibility changes render the symbol local.
6291 If on the other hand, we are creating an executable, we may need
6292 to keep relocations for symbols satisfied by a dynamic library
6293 if we manage to avoid copy relocs for the symbol. */
6294 if ((bfd_link_pic (info
)
6295 && (sec
->flags
& SEC_ALLOC
) != 0
6296 && ((r_type
!= R_NDS32_25_PCREL_RELA
6297 && r_type
!= R_NDS32_15_PCREL_RELA
6298 && r_type
!= R_NDS32_17_PCREL_RELA
6299 && !(r_type
== R_NDS32_32_RELA
6300 && strcmp (sec
->name
, ".eh_frame") == 0))
6303 || h
->root
.type
== bfd_link_hash_defweak
6304 || !h
->def_regular
))))
6305 || (!bfd_link_pic (info
)
6306 && (sec
->flags
& SEC_ALLOC
) != 0
6308 && (h
->root
.type
== bfd_link_hash_defweak
6309 || !h
->def_regular
)))
6311 struct elf_dyn_relocs
*p
;
6312 struct elf_dyn_relocs
**head
;
6315 htab
->root
.dynobj
= dynobj
= abfd
;
6317 /* When creating a shared object, we must copy these
6318 relocs into the output file. We create a reloc
6319 section in dynobj and make room for the reloc. */
6324 name
= bfd_elf_string_from_elf_section
6325 (abfd
, elf_elfheader (abfd
)->e_shstrndx
,
6326 elf_section_data (sec
)->rela
.hdr
->sh_name
);
6330 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6331 && strcmp (bfd_get_section_name (abfd
, sec
),
6334 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6339 sreloc
= bfd_make_section (dynobj
, name
);
6340 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6341 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6342 if ((sec
->flags
& SEC_ALLOC
) != 0)
6343 flags
|= SEC_ALLOC
| SEC_LOAD
;
6345 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
6346 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
6349 elf_section_type (sreloc
) = SHT_RELA
;
6351 elf_section_data (sec
)->sreloc
= sreloc
;
6354 /* If this is a global symbol, we count the number of
6355 relocations we need for this symbol. */
6357 head
= &((struct elf_nds32_link_hash_entry
*) h
)->dyn_relocs
;
6363 Elf_Internal_Sym
*isym
;
6364 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
6368 /* Track dynamic relocs needed for local syms too. */
6369 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6373 vpp
= &elf_section_data (s
)->local_dynrel
;
6374 head
= (struct elf_dyn_relocs
**) vpp
;
6378 if (p
== NULL
|| p
->sec
!= sec
)
6380 bfd_size_type amt
= sizeof (*p
);
6381 p
= (struct elf_dyn_relocs
*) bfd_alloc (dynobj
, amt
);
6392 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_25_PCREL_RELA
6393 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_15_PCREL_RELA
6394 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_17_PCREL_RELA
)
6399 /* This relocation describes the C++ object vtable hierarchy.
6400 Reconstruct it for later use during GC. */
6401 case R_NDS32_RELA_GNU_VTINHERIT
:
6402 case R_NDS32_GNU_VTINHERIT
:
6403 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6407 /* This relocation describes which C++ vtable entries are actually
6408 used. Record for later use during GC. */
6409 case R_NDS32_GNU_VTENTRY
:
6410 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6413 case R_NDS32_RELA_GNU_VTENTRY
:
6414 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6423 /* Write VAL in uleb128 format to P, returning a pointer to the
6425 This code is copied from elf-attr.c. */
6428 write_uleb128 (bfd_byte
*p
, unsigned int val
)
6443 static bfd_signed_vma
6444 calculate_offset (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
6445 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
,
6446 int *pic_ext_target
)
6448 bfd_signed_vma foff
;
6449 bfd_vma symval
, addend
;
6452 /* Get the value of the symbol referred to by the reloc. */
6453 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6455 Elf_Internal_Sym
*isym
;
6457 /* A local symbol. */
6458 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6460 if (isym
->st_shndx
== SHN_UNDEF
)
6461 sym_sec
= bfd_und_section_ptr
;
6462 else if (isym
->st_shndx
== SHN_ABS
)
6463 sym_sec
= bfd_abs_section_ptr
;
6464 else if (isym
->st_shndx
== SHN_COMMON
)
6465 sym_sec
= bfd_com_section_ptr
;
6467 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6468 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
6469 + sym_sec
->output_offset
;
6474 struct elf_link_hash_entry
*h
;
6477 /* An external symbol. */
6478 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6479 h
= elf_sym_hashes (abfd
)[indx
];
6480 BFD_ASSERT (h
!= NULL
);
6482 if (h
->root
.type
!= bfd_link_hash_defined
6483 && h
->root
.type
!= bfd_link_hash_defweak
)
6484 /* This appears to be a reference to an undefined
6485 symbol. Just ignore it--it will be caught by the
6486 regular reloc processing. */
6488 owner
= h
->root
.u
.def
.section
->owner
;
6489 if (owner
&& (elf_elfheader (owner
)->e_flags
& E_NDS32_HAS_PIC
))
6490 *pic_ext_target
= 1;
6492 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
6494 sym_sec
= h
->root
.u
.def
.section
;
6495 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
,
6496 elf_section_data (sym_sec
)->sec_info
,
6497 h
->root
.u
.def
.value
);
6498 symval
= symval
+ sym_sec
->output_section
->vma
6499 + sym_sec
->output_offset
;
6502 symval
= (h
->root
.u
.def
.value
6503 + h
->root
.u
.def
.section
->output_section
->vma
6504 + h
->root
.u
.def
.section
->output_offset
);
6507 addend
= irel
->r_addend
;
6509 foff
= (symval
+ addend
6510 - (irel
->r_offset
+ sec
->output_section
->vma
+ sec
->output_offset
));
6515 calculate_plt_memory_address (bfd
*abfd
, struct bfd_link_info
*link_info
,
6516 Elf_Internal_Sym
*isymbuf
,
6517 Elf_Internal_Rela
*irel
,
6518 Elf_Internal_Shdr
*symtab_hdr
)
6522 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6524 Elf_Internal_Sym
*isym
;
6526 /* A local symbol. */
6527 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6529 if (isym
->st_shndx
== SHN_UNDEF
)
6530 sym_sec
= bfd_und_section_ptr
;
6531 else if (isym
->st_shndx
== SHN_ABS
)
6532 sym_sec
= bfd_abs_section_ptr
;
6533 else if (isym
->st_shndx
== SHN_COMMON
)
6534 sym_sec
= bfd_com_section_ptr
;
6536 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6537 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
6538 + sym_sec
->output_offset
;
6543 struct elf_link_hash_entry
*h
;
6544 struct elf_nds32_link_hash_table
*htab
;
6547 /* An external symbol. */
6548 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6549 h
= elf_sym_hashes (abfd
)[indx
];
6550 BFD_ASSERT (h
!= NULL
);
6551 htab
= nds32_elf_hash_table (link_info
);
6552 splt
= htab
->root
.splt
;
6554 while (h
->root
.type
== bfd_link_hash_indirect
6555 || h
->root
.type
== bfd_link_hash_warning
)
6556 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6558 if (h
->plt
.offset
== (bfd_vma
) - 1)
6560 if (h
->root
.type
!= bfd_link_hash_defined
6561 && h
->root
.type
!= bfd_link_hash_defweak
)
6562 /* This appears to be a reference to an undefined
6563 * symbol. Just ignore it--it will be caught by the
6564 * regular reloc processing. */
6566 symval
= (h
->root
.u
.def
.value
6567 + h
->root
.u
.def
.section
->output_section
->vma
6568 + h
->root
.u
.def
.section
->output_offset
);
6571 symval
= splt
->output_section
->vma
+ h
->plt
.offset
;
6577 static bfd_signed_vma
6578 calculate_plt_offset (bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
6579 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Rela
*irel
,
6580 Elf_Internal_Shdr
*symtab_hdr
)
6583 if ((foff
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
, irel
,
6587 return foff
- (irel
->r_offset
6588 + sec
->output_section
->vma
+ sec
->output_offset
);
6591 /* Convert a 32-bit instruction to 16-bit one.
6592 INSN is the input 32-bit instruction, INSN16 is the output 16-bit
6593 instruction. If INSN_TYPE is not NULL, it the CGEN instruction
6594 type of INSN16. Return 1 if successful. */
6597 nds32_convert_32_to_16_alu1 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6600 uint16_t insn16
= 0;
6602 unsigned long mach
= bfd_get_mach (abfd
);
6604 if (N32_SH5 (insn
) != 0)
6607 switch (N32_SUB5 (insn
))
6609 case N32_ALU1_ADD_SLLI
:
6610 case N32_ALU1_ADD_SRLI
:
6611 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
6613 insn16
= N16_TYPE333 (ADD333
, N32_RT5 (insn
), N32_RA5 (insn
),
6615 insn_type
= NDS32_INSN_ADD333
;
6617 else if (N32_IS_RT4 (insn
))
6619 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6620 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RB5 (insn
));
6621 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6622 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RA5 (insn
));
6623 insn_type
= NDS32_INSN_ADD45
;
6627 case N32_ALU1_SUB_SLLI
:
6628 case N32_ALU1_SUB_SRLI
:
6629 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
6631 insn16
= N16_TYPE333 (SUB333
, N32_RT5 (insn
), N32_RA5 (insn
),
6633 insn_type
= NDS32_INSN_SUB333
;
6635 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6637 insn16
= N16_TYPE45 (SUB45
, N32_RT54 (insn
), N32_RB5 (insn
));
6638 insn_type
= NDS32_INSN_SUB45
;
6642 case N32_ALU1_AND_SLLI
:
6643 case N32_ALU1_AND_SRLI
:
6644 /* and $rt, $rt, $rb -> and33 for v3, v3m. */
6645 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6646 && N32_IS_RB3 (insn
))
6648 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6649 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RB5 (insn
));
6650 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6651 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RA5 (insn
));
6653 insn_type
= NDS32_INSN_AND33
;
6657 case N32_ALU1_XOR_SLLI
:
6658 case N32_ALU1_XOR_SRLI
:
6659 /* xor $rt, $rt, $rb -> xor33 for v3, v3m. */
6660 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6661 && N32_IS_RB3 (insn
))
6663 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6664 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RB5 (insn
));
6665 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6666 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RA5 (insn
));
6668 insn_type
= NDS32_INSN_XOR33
;
6672 case N32_ALU1_OR_SLLI
:
6673 case N32_ALU1_OR_SRLI
:
6674 /* or $rt, $rt, $rb -> or33 for v3, v3m. */
6675 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6676 && N32_IS_RB3 (insn
))
6678 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6679 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RB5 (insn
));
6680 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6681 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RA5 (insn
));
6683 insn_type
= NDS32_INSN_OR33
;
6687 /* nor $rt, $ra, $ra -> not33 for v3, v3m. */
6688 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RB3 (insn
)
6689 && N32_RA5 (insn
) == N32_RB5 (insn
))
6691 insn16
= N16_MISC33 (NOT33
, N32_RT5 (insn
), N32_RA5 (insn
));
6692 insn_type
= NDS32_INSN_NOT33
;
6696 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6698 insn16
= N16_TYPE45 (SRAI45
, N32_RT54 (insn
), N32_UB5 (insn
));
6699 insn_type
= NDS32_INSN_SRAI45
;
6704 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6706 insn16
= N16_TYPE45 (SRLI45
, N32_RT54 (insn
), N32_UB5 (insn
));
6707 insn_type
= NDS32_INSN_SRLI45
;
6712 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_UB5 (insn
) < 8)
6714 insn16
= N16_TYPE333 (SLLI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6716 insn_type
= NDS32_INSN_SLLI333
;
6721 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6723 insn16
= N16_BFMI333 (ZEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
6724 insn_type
= NDS32_INSN_ZEH33
;
6729 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6731 insn16
= N16_BFMI333 (SEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6732 insn_type
= NDS32_INSN_SEB33
;
6737 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6739 insn16
= N16_BFMI333 (SEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
6740 insn_type
= NDS32_INSN_SEH33
;
6745 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
6748 insn16
= N16_TYPE45 (SLT45
, N32_RA54 (insn
), N32_RB5 (insn
));
6749 insn_type
= NDS32_INSN_SLT45
;
6754 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
6757 insn16
= N16_TYPE45 (SLTS45
, N32_RA54 (insn
), N32_RB5 (insn
));
6758 insn_type
= NDS32_INSN_SLTS45
;
6763 if ((insn16
& 0x8000) == 0)
6769 *pinsn_type
= insn_type
;
6774 nds32_convert_32_to_16_alu2 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6777 uint16_t insn16
= 0;
6779 unsigned long mach
= bfd_get_mach (abfd
);
6781 /* TODO: bset, bclr, btgl, btst. */
6782 if (__GF (insn
, 6, 4) != 0)
6785 switch (N32_IMMU (insn
, 6))
6788 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6789 && N32_IS_RB3 (insn
))
6791 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6792 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RB5 (insn
));
6793 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6794 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RA5 (insn
));
6796 insn_type
= NDS32_INSN_MUL33
;
6800 if ((insn16
& 0x8000) == 0)
6806 *pinsn_type
= insn_type
;
6811 nds32_convert_32_to_16 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6815 uint16_t insn16
= 0;
6817 unsigned long mach
= bfd_get_mach (abfd
);
6819 /* Decode 32-bit instruction. */
6820 if (insn
& 0x80000000)
6822 /* Not 32-bit insn. */
6826 op6
= N32_OP6 (insn
);
6828 /* Convert it to 16-bit instruction. */
6832 if (IS_WITHIN_S (N32_IMM20S (insn
), 5))
6834 insn16
= N16_TYPE55 (MOVI55
, N32_RT5 (insn
), N32_IMM20S (insn
));
6835 insn_type
= NDS32_INSN_MOVI55
;
6837 else if (mach
>= MACH_V3
&& N32_IMM20S (insn
) >= 16
6838 && N32_IMM20S (insn
) < 48 && N32_IS_RT4 (insn
))
6840 insn16
= N16_TYPE45 (MOVPI45
, N32_RT54 (insn
),
6841 N32_IMM20S (insn
) - 16);
6842 insn_type
= NDS32_INSN_MOVPI45
;
6847 if (N32_IMM15S (insn
) == 0)
6849 /* Do not convert `addi $sp, $sp, 0' to `mov55 $sp, $sp',
6850 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
6852 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
6854 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
6855 insn_type
= NDS32_INSN_MOV55
;
6858 else if (N32_IMM15S (insn
) > 0)
6860 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) < 8)
6862 insn16
= N16_TYPE333 (ADDI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6864 insn_type
= NDS32_INSN_ADDI333
;
6866 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
6867 && N32_IMM15S (insn
) < 32)
6869 insn16
= N16_TYPE45 (ADDI45
, N32_RT54 (insn
), N32_IMM15S (insn
));
6870 insn_type
= NDS32_INSN_ADDI45
;
6872 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
6873 && N32_RT5 (insn
) == N32_RA5 (insn
)
6874 && N32_IMM15S (insn
) < 512)
6876 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
6877 insn_type
= NDS32_INSN_ADDI10_SP
;
6879 else if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
6880 && N32_RA5 (insn
) == REG_SP
&& N32_IMM15S (insn
) < 256
6881 && (N32_IMM15S (insn
) % 4 == 0))
6883 insn16
= N16_TYPE36 (ADDRI36_SP
, N32_RT5 (insn
),
6884 N32_IMM15S (insn
) >> 2);
6885 insn_type
= NDS32_INSN_ADDRI36_SP
;
6891 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) > -8)
6893 insn16
= N16_TYPE333 (SUBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6894 0 - N32_IMM15S (insn
));
6895 insn_type
= NDS32_INSN_SUBI333
;
6897 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
6898 && N32_IMM15S (insn
) > -32)
6900 insn16
= N16_TYPE45 (SUBI45
, N32_RT54 (insn
),
6901 0 - N32_IMM15S (insn
));
6902 insn_type
= NDS32_INSN_SUBI45
;
6904 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
6905 && N32_RT5 (insn
) == N32_RA5 (insn
)
6906 && N32_IMM15S (insn
) >= -512)
6908 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
6909 insn_type
= NDS32_INSN_ADDI10_SP
;
6915 if (N32_IMM15S (insn
) == 0)
6917 /* Do not convert `ori $sp, $sp, 0' to `mov55 $sp, $sp',
6918 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
6920 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
6922 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
6923 insn_type
= NDS32_INSN_MOV55
;
6929 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
6930 && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) == 0)
6932 insn16
= N16_MISC33 (NEG33
, N32_RT5 (insn
), N32_RA5 (insn
));
6933 insn_type
= NDS32_INSN_NEG33
;
6938 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6940 if (N32_IMM15U (insn
) == 1)
6942 insn16
= N16_BFMI333 (XLSB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6943 insn_type
= NDS32_INSN_XLSB33
;
6945 else if (N32_IMM15U (insn
) == 0x7ff)
6947 insn16
= N16_BFMI333 (X11B33
, N32_RT5 (insn
), N32_RA5 (insn
));
6948 insn_type
= NDS32_INSN_X11B33
;
6950 else if (N32_IMM15U (insn
) == 0xff)
6952 insn16
= N16_BFMI333 (ZEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6953 insn_type
= NDS32_INSN_ZEB33
;
6955 else if (mach
>= MACH_V3
&& N32_RT5 (insn
) == N32_RA5 (insn
)
6956 && N32_IMM15U (insn
) < 256)
6958 int imm15u
= N32_IMM15U (insn
);
6960 if (__builtin_popcount (imm15u
) == 1)
6963 int imm3u
= __builtin_ctz (imm15u
);
6965 insn16
= N16_BFMI333 (BMSKI33
, N32_RT5 (insn
), imm3u
);
6966 insn_type
= NDS32_INSN_BMSKI33
;
6968 else if (imm15u
!= 0 && __builtin_popcount (imm15u
+ 1) == 1)
6971 int imm3u
= __builtin_ctz (imm15u
+ 1) - 1;
6973 insn16
= N16_BFMI333 (FEXTI33
, N32_RT5 (insn
), imm3u
);
6974 insn_type
= NDS32_INSN_FEXTI33
;
6981 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
6982 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
6984 insn16
= N16_TYPE45 (SLTI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
6985 insn_type
= NDS32_INSN_SLTI45
;
6990 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
6991 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
6993 insn16
= N16_TYPE45 (SLTSI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
6994 insn_type
= NDS32_INSN_SLTSI45
;
6999 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
7001 insn16
= N16_TYPE45 (LWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
7002 insn_type
= NDS32_INSN_LWI450
;
7004 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7005 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7007 insn16
= N16_TYPE333 (LWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7009 insn_type
= NDS32_INSN_LWI333
;
7011 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
7012 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7014 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7015 insn_type
= NDS32_INSN_LWI37
;
7017 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
7018 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7020 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7021 insn_type
= NDS32_INSN_LWI37_SP
;
7023 else if (mach
>= MACH_V2
&& N32_IS_RT4 (insn
) && N32_RA5 (insn
) == REG_R8
7024 && -32 <= N32_IMM15S (insn
) && N32_IMM15S (insn
) < 0)
7026 insn16
= N16_TYPE45 (LWI45_FE
, N32_RT54 (insn
),
7027 N32_IMM15S (insn
) + 32);
7028 insn_type
= NDS32_INSN_LWI45_FE
;
7033 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
7035 insn16
= N16_TYPE45 (SWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
7036 insn_type
= NDS32_INSN_SWI450
;
7038 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7039 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7041 insn16
= N16_TYPE333 (SWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7043 insn_type
= NDS32_INSN_SWI333
;
7045 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
7046 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7048 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7049 insn_type
= NDS32_INSN_SWI37
;
7051 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
7052 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7054 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7055 insn_type
= NDS32_INSN_SWI37_SP
;
7059 case N32_OP6_LWI_BI
:
7060 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7061 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7063 insn16
= N16_TYPE333 (LWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
7065 insn_type
= NDS32_INSN_LWI333_BI
;
7069 case N32_OP6_SWI_BI
:
7070 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7071 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7073 insn16
= N16_TYPE333 (SWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
7075 insn_type
= NDS32_INSN_SWI333_BI
;
7080 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7081 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7083 insn16
= N16_TYPE333 (LHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7085 insn_type
= NDS32_INSN_LHI333
;
7090 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7091 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7093 insn16
= N16_TYPE333 (SHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7095 insn_type
= NDS32_INSN_SHI333
;
7100 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7101 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7103 insn16
= N16_TYPE333 (LBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7105 insn_type
= NDS32_INSN_LBI333
;
7110 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7111 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7113 insn16
= N16_TYPE333 (SBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7115 insn_type
= NDS32_INSN_SBI333
;
7120 return nds32_convert_32_to_16_alu1 (abfd
, insn
, pinsn16
, pinsn_type
);
7123 return nds32_convert_32_to_16_alu2 (abfd
, insn
, pinsn16
, pinsn_type
);
7126 if (!IS_WITHIN_S (N32_IMM14S (insn
), 8))
7129 if ((insn
& N32_BIT (14)) == 0)
7132 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
7133 && N32_RT5 (insn
) != REG_R5
)
7134 insn16
= N16_TYPE38 (BEQS38
, N32_RT5 (insn
), N32_IMM14S (insn
));
7135 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
7136 && N32_RA5 (insn
) != REG_R5
)
7137 insn16
= N16_TYPE38 (BEQS38
, N32_RA5 (insn
), N32_IMM14S (insn
));
7138 insn_type
= NDS32_INSN_BEQS38
;
7144 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
7145 && N32_RT5 (insn
) != REG_R5
)
7146 insn16
= N16_TYPE38 (BNES38
, N32_RT5 (insn
), N32_IMM14S (insn
));
7147 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
7148 && N32_RA5 (insn
) != REG_R5
)
7149 insn16
= N16_TYPE38 (BNES38
, N32_RA5 (insn
), N32_IMM14S (insn
));
7150 insn_type
= NDS32_INSN_BNES38
;
7156 switch (N32_BR2_SUB (insn
))
7159 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7161 insn16
= N16_TYPE38 (BEQZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
7162 insn_type
= NDS32_INSN_BEQZ38
;
7164 else if (N32_RT5 (insn
) == REG_R15
7165 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7167 insn16
= N16_TYPE8 (BEQZS8
, N32_IMM16S (insn
));
7168 insn_type
= NDS32_INSN_BEQZS8
;
7173 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7175 insn16
= N16_TYPE38 (BNEZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
7176 insn_type
= NDS32_INSN_BNEZ38
;
7178 else if (N32_RT5 (insn
) == REG_R15
7179 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7181 insn16
= N16_TYPE8 (BNEZS8
, N32_IMM16S (insn
));
7182 insn_type
= NDS32_INSN_BNEZS8
;
7186 case N32_BR2_IFCALL
:
7187 if (IS_WITHIN_U (N32_IMM16S (insn
), 9))
7189 insn16
= N16_TYPE9 (IFCALL9
, N32_IMM16S (insn
));
7190 insn_type
= NDS32_INSN_IFCALL9
;
7197 if ((insn
& N32_BIT (24)) == 0)
7200 if (IS_WITHIN_S (N32_IMM24S (insn
), 8))
7202 insn16
= N16_TYPE8 (J8
, N32_IMM24S (insn
));
7203 insn_type
= NDS32_INSN_J8
;
7209 if (__GF (insn
, 8, 2) != 0)
7212 switch (N32_IMMU (insn
, 5))
7215 if (N32_JREG_HINT (insn
) == 0)
7218 insn16
= N16_TYPE5 (JR5
, N32_RB5 (insn
));
7219 insn_type
= NDS32_INSN_JR5
;
7221 else if (N32_JREG_HINT (insn
) == 1)
7224 insn16
= N16_TYPE5 (RET5
, N32_RB5 (insn
));
7225 insn_type
= NDS32_INSN_RET5
;
7227 else if (N32_JREG_HINT (insn
) == 3)
7229 /* ifret = mov55 $sp, $sp */
7230 insn16
= N16_TYPE55 (MOV55
, REG_SP
, REG_SP
);
7231 insn_type
= NDS32_INSN_IFRET
;
7236 /* It's convertible when return rt5 is $lp and address
7237 translation is kept. */
7238 if (N32_RT5 (insn
) == REG_LP
&& N32_JREG_HINT (insn
) == 0)
7240 insn16
= N16_TYPE5 (JRAL5
, N32_RB5 (insn
));
7241 insn_type
= NDS32_INSN_JRAL5
;
7248 if (N32_SUB5 (insn
) == N32_MISC_BREAK
&& N32_SWID (insn
) < 32)
7250 /* For v3, swid above 31 are used for ex9.it. */
7251 insn16
= N16_TYPE5 (BREAK16
, N32_SWID (insn
));
7252 insn_type
= NDS32_INSN_BREAK16
;
7257 /* This instruction has no 16-bit variant. */
7262 /* Bit-15 of insn16 should be set for a valid instruction. */
7263 if ((insn16
& 0x8000) == 0)
7269 *pinsn_type
= insn_type
;
7274 special_convert_32_to_16 (unsigned long insn
, uint16_t *pinsn16
,
7275 Elf_Internal_Rela
*reloc
)
7277 uint16_t insn16
= 0;
7279 if ((reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
) == 0
7280 || (ELF32_R_TYPE (reloc
->r_info
) != R_NDS32_INSN16
))
7283 if (!N32_IS_RT3 (insn
))
7286 switch (N32_OP6 (insn
))
7289 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
7290 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7293 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
7294 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7297 if (!IS_WITHIN_U (N32_IMM17S (insn
), 7))
7300 if (__GF (insn
, 17, 3) == 6)
7301 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM17S (insn
));
7302 else if (__GF (insn
, 17, 3) == 7)
7303 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM17S (insn
));
7307 if ((insn16
& 0x8000) == 0)
7314 /* Convert a 16-bit instruction to 32-bit one.
7315 INSN16 it the input and PINSN it the point to output.
7316 Return non-zero on successful. Otherwise 0 is returned. */
7319 nds32_convert_16_to_32 (bfd
*abfd
, uint16_t insn16
, uint32_t *pinsn
)
7321 uint32_t insn
= 0xffffffff;
7322 unsigned long mach
= bfd_get_mach (abfd
);
7324 /* NOTE: push25, pop25 and movd44 do not have 32-bit variants. */
7326 switch (__GF (insn16
, 9, 6))
7328 case 0x4: /* add45 */
7329 insn
= N32_ALU1 (ADD
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7332 case 0x5: /* sub45 */
7333 insn
= N32_ALU1 (SUB
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7336 case 0x6: /* addi45 */
7337 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7338 N16_IMM5U (insn16
));
7340 case 0x7: /* subi45 */
7341 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7342 -N16_IMM5U (insn16
));
7344 case 0x8: /* srai45 */
7345 insn
= N32_ALU1 (SRAI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7346 N16_IMM5U (insn16
));
7348 case 0x9: /* srli45 */
7349 insn
= N32_ALU1 (SRLI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7350 N16_IMM5U (insn16
));
7352 case 0xa: /* slli333 */
7353 insn
= N32_ALU1 (SLLI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7354 N16_IMM3U (insn16
));
7356 case 0xc: /* add333 */
7357 insn
= N32_ALU1 (ADD
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7360 case 0xd: /* sub333 */
7361 insn
= N32_ALU1 (SUB
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7364 case 0xe: /* addi333 */
7365 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7366 N16_IMM3U (insn16
));
7368 case 0xf: /* subi333 */
7369 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7370 -N16_IMM3U (insn16
));
7372 case 0x10: /* lwi333 */
7373 insn
= N32_TYPE2 (LWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7374 N16_IMM3U (insn16
));
7376 case 0x12: /* lhi333 */
7377 insn
= N32_TYPE2 (LHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7378 N16_IMM3U (insn16
));
7380 case 0x13: /* lbi333 */
7381 insn
= N32_TYPE2 (LBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7382 N16_IMM3U (insn16
));
7384 case 0x11: /* lwi333.bi */
7385 insn
= N32_TYPE2 (LWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7386 N16_IMM3U (insn16
));
7388 case 0x14: /* swi333 */
7389 insn
= N32_TYPE2 (SWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7390 N16_IMM3U (insn16
));
7392 case 0x16: /* shi333 */
7393 insn
= N32_TYPE2 (SHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7394 N16_IMM3U (insn16
));
7396 case 0x17: /* sbi333 */
7397 insn
= N32_TYPE2 (SBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7398 N16_IMM3U (insn16
));
7400 case 0x15: /* swi333.bi */
7401 insn
= N32_TYPE2 (SWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7402 N16_IMM3U (insn16
));
7404 case 0x18: /* addri36.sp */
7405 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), REG_SP
,
7406 N16_IMM6U (insn16
) << 2);
7408 case 0x19: /* lwi45.fe */
7409 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), REG_R8
,
7410 (N16_IMM5U (insn16
) - 32));
7412 case 0x1a: /* lwi450 */
7413 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
7415 case 0x1b: /* swi450 */
7416 insn
= N32_TYPE2 (SWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
7419 /* These are r15 implied instructions. */
7420 case 0x30: /* slts45 */
7421 insn
= N32_ALU1 (SLTS
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
7423 case 0x31: /* slt45 */
7424 insn
= N32_ALU1 (SLT
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
7426 case 0x32: /* sltsi45 */
7427 insn
= N32_TYPE2 (SLTSI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
7429 case 0x33: /* slti45 */
7430 insn
= N32_TYPE2 (SLTI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
7432 case 0x34: /* beqzs8, bnezs8 */
7433 if (insn16
& N32_BIT (8))
7434 insn
= N32_BR2 (BNEZ
, REG_TA
, N16_IMM8S (insn16
));
7436 insn
= N32_BR2 (BEQZ
, REG_TA
, N16_IMM8S (insn16
));
7439 case 0x35: /* break16, ex9.it */
7440 /* Only consider range of v3 break16. */
7441 insn
= N32_TYPE0 (MISC
, (N16_IMM5U (insn16
) << 5) | N32_MISC_BREAK
);
7444 case 0x3c: /* ifcall9 */
7445 insn
= N32_BR2 (IFCALL
, 0, N16_IMM9U (insn16
));
7447 case 0x3d: /* movpi45 */
7448 insn
= N32_TYPE1 (MOVI
, N16_RT4 (insn16
), N16_IMM5U (insn16
) + 16);
7451 case 0x3f: /* MISC33 */
7452 switch (insn16
& 0x7)
7455 insn
= N32_TYPE2 (SUBRI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7458 insn
= N32_ALU1 (NOR
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7462 insn
= N32_ALU2 (MUL
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7466 insn
= N32_ALU1 (XOR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7470 insn
= N32_ALU1 (AND
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7474 insn
= N32_ALU1 (OR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7481 switch (insn16
& 0x7)
7484 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0xff);
7487 insn
= N32_ALU1 (ZEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7490 insn
= N32_ALU1 (SEB
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7493 insn
= N32_ALU1 (SEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7495 case 4: /* xlsb33 */
7496 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 1);
7498 case 5: /* x11b33 */
7499 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0x7ff);
7501 case 6: /* bmski33 */
7502 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7503 1 << __GF (insn16
, 3, 3));
7505 case 7: /* fexti33 */
7506 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7507 (1 << (__GF (insn16
, 3, 3) + 1)) - 1);
7513 switch (__GF (insn16
, 10, 5))
7515 case 0x0: /* mov55 or ifret16 */
7516 if (mach
>= MACH_V3
&& N16_RT5 (insn16
) == REG_SP
7517 && N16_RT5 (insn16
) == N16_RA5 (insn16
))
7518 insn
= N32_JREG (JR
, 0, 0, 0, 3);
7520 insn
= N32_TYPE2 (ADDI
, N16_RT5 (insn16
), N16_RA5 (insn16
), 0);
7522 case 0x1: /* movi55 */
7523 insn
= N32_TYPE1 (MOVI
, N16_RT5 (insn16
), N16_IMM5S (insn16
));
7525 case 0x1b: /* addi10s (V2) */
7526 insn
= N32_TYPE2 (ADDI
, REG_SP
, REG_SP
, N16_IMM10S (insn16
));
7530 switch (__GF (insn16
, 11, 4))
7532 case 0x7: /* lwi37.fp/swi37.fp */
7533 if (insn16
& N32_BIT (7)) /* swi37.fp */
7534 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
7536 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
7538 case 0x8: /* beqz38 */
7539 insn
= N32_BR2 (BEQZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
7541 case 0x9: /* bnez38 */
7542 insn
= N32_BR2 (BNEZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
7544 case 0xa: /* beqs38/j8, implied r5 */
7545 if (N16_RT38 (insn16
) == 5)
7546 insn
= N32_JI (J
, N16_IMM8S (insn16
));
7548 insn
= N32_BR1 (BEQ
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
7550 case 0xb: /* bnes38 and others */
7551 if (N16_RT38 (insn16
) == 5)
7553 switch (__GF (insn16
, 5, 3))
7556 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 0);
7559 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 1);
7562 insn
= N32_JREG (JRAL
, REG_LP
, N16_RA5 (insn16
), 0, 0);
7564 case 2: /* ex9.it imm5 */
7565 /* ex9.it had no 32-bit variantl. */
7567 case 5: /* add5.pc */
7568 /* add5.pc had no 32-bit variantl. */
7573 insn
= N32_BR1 (BNE
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
7575 case 0xe: /* lwi37/swi37 */
7576 if (insn16
& (1 << 7)) /* swi37.sp */
7577 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
7579 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
7584 if (insn
& 0x80000000)
7593 is_sda_access_insn (unsigned long insn
)
7595 switch (N32_OP6 (insn
))
7616 static unsigned long
7617 turn_insn_to_sda_access (uint32_t insn
, bfd_signed_vma type
, uint32_t *pinsn
)
7623 case R_NDS32_GOT_LO12
:
7624 case R_NDS32_GOTOFF_LO12
:
7625 case R_NDS32_PLTREL_LO12
:
7626 case R_NDS32_PLT_GOTREL_LO12
:
7627 case R_NDS32_LO12S0_RELA
:
7628 switch (N32_OP6 (insn
))
7632 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
7636 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
7640 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
7644 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
7649 case R_NDS32_LO12S1_RELA
:
7650 switch (N32_OP6 (insn
))
7654 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
7658 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
7662 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
7667 case R_NDS32_LO12S2_RELA
:
7668 switch (N32_OP6 (insn
))
7672 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
7676 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
7681 case R_NDS32_LO12S2_DP_RELA
:
7682 case R_NDS32_LO12S2_SP_RELA
:
7683 oinsn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
7693 /* Linker hasn't found the correct merge section for non-section symbol
7694 in relax time, this work is left to the function elf_link_input_bfd().
7695 So for non-section symbol, _bfd_merged_section_offset is also needed
7696 to find the correct symbol address. */
7699 nds32_elf_rela_local_sym (bfd
*abfd
, Elf_Internal_Sym
*sym
,
7700 asection
**psec
, Elf_Internal_Rela
*rel
)
7702 asection
*sec
= *psec
;
7705 relocation
= (sec
->output_section
->vma
7706 + sec
->output_offset
+ sym
->st_value
);
7707 if ((sec
->flags
& SEC_MERGE
) && sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
7709 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7711 _bfd_merged_section_offset (abfd
, psec
,
7712 elf_section_data (sec
)->sec_info
,
7713 sym
->st_value
+ rel
->r_addend
);
7716 _bfd_merged_section_offset (abfd
, psec
,
7717 elf_section_data (sec
)->sec_info
,
7718 sym
->st_value
) + rel
->r_addend
;
7722 /* If we have changed the section, and our original section is
7723 marked with SEC_EXCLUDE, it means that the original
7724 SEC_MERGE section has been completely subsumed in some
7725 other SEC_MERGE section. In this case, we need to leave
7726 some info around for --emit-relocs. */
7727 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
7728 sec
->kept_section
= *psec
;
7731 rel
->r_addend
-= relocation
;
7732 rel
->r_addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
7738 calculate_memory_address (bfd
*abfd
, Elf_Internal_Rela
*irel
,
7739 Elf_Internal_Sym
*isymbuf
,
7740 Elf_Internal_Shdr
*symtab_hdr
)
7742 bfd_signed_vma foff
;
7743 bfd_vma symval
, addend
;
7744 Elf_Internal_Rela irel_fn
;
7745 Elf_Internal_Sym
*isym
;
7748 /* Get the value of the symbol referred to by the reloc. */
7749 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
7751 /* A local symbol. */
7752 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
7754 if (isym
->st_shndx
== SHN_UNDEF
)
7755 sym_sec
= bfd_und_section_ptr
;
7756 else if (isym
->st_shndx
== SHN_ABS
)
7757 sym_sec
= bfd_abs_section_ptr
;
7758 else if (isym
->st_shndx
== SHN_COMMON
)
7759 sym_sec
= bfd_com_section_ptr
;
7761 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7762 memcpy (&irel_fn
, irel
, sizeof (Elf_Internal_Rela
));
7763 symval
= nds32_elf_rela_local_sym (abfd
, isym
, &sym_sec
, &irel_fn
);
7764 addend
= irel_fn
.r_addend
;
7769 struct elf_link_hash_entry
*h
;
7771 /* An external symbol. */
7772 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7773 h
= elf_sym_hashes (abfd
)[indx
];
7774 BFD_ASSERT (h
!= NULL
);
7776 while (h
->root
.type
== bfd_link_hash_indirect
7777 || h
->root
.type
== bfd_link_hash_warning
)
7778 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7780 if (h
->root
.type
!= bfd_link_hash_defined
7781 && h
->root
.type
!= bfd_link_hash_defweak
)
7782 /* This appears to be a reference to an undefined
7783 symbol. Just ignore it--it will be caught by the
7784 regular reloc processing. */
7787 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
7789 sym_sec
= h
->root
.u
.def
.section
;
7790 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
, elf_section_data
7791 (sym_sec
)->sec_info
, h
->root
.u
.def
.value
);
7792 symval
= symval
+ sym_sec
->output_section
->vma
7793 + sym_sec
->output_offset
;
7796 symval
= (h
->root
.u
.def
.value
7797 + h
->root
.u
.def
.section
->output_section
->vma
7798 + h
->root
.u
.def
.section
->output_offset
);
7799 addend
= irel
->r_addend
;
7802 foff
= symval
+ addend
;
7808 calculate_got_memory_address (bfd
*abfd
, struct bfd_link_info
*link_info
,
7809 Elf_Internal_Rela
*irel
,
7810 Elf_Internal_Shdr
*symtab_hdr
)
7813 bfd_vma
*local_got_offsets
;
7814 /* Get the value of the symbol referred to by the reloc. */
7815 struct elf_link_hash_entry
*h
;
7816 struct elf_nds32_link_hash_table
*htab
= nds32_elf_hash_table (link_info
);
7818 /* An external symbol. */
7819 symndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7820 h
= elf_sym_hashes (abfd
)[symndx
];
7821 while (h
->root
.type
== bfd_link_hash_indirect
7822 || h
->root
.type
== bfd_link_hash_warning
)
7823 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7827 BFD_ASSERT (h
!= NULL
);
7828 return (htab
->root
.sgot
->output_section
->vma
7829 + htab
->root
.sgot
->output_offset
7834 local_got_offsets
= elf_local_got_offsets (abfd
);
7835 BFD_ASSERT (local_got_offsets
!= NULL
);
7836 return (htab
->root
.sgot
->output_section
->vma
7837 + htab
->root
.sgot
->output_offset
7838 + local_got_offsets
[ELF32_R_SYM (irel
->r_info
)]);
7841 /* The _GLOBAL_OFFSET_TABLE_ may be undefweak(or should be?). */
7842 /* The check of h->root.type is passed. */
7846 is_16bit_NOP (bfd
*abfd ATTRIBUTE_UNUSED
,
7847 asection
*sec
, Elf_Internal_Rela
*rel
)
7850 unsigned short insn16
;
7852 if (!(rel
->r_addend
& R_NDS32_INSN16_CONVERT_FLAG
))
7854 contents
= elf_section_data (sec
)->this_hdr
.contents
;
7855 insn16
= bfd_getb16 (contents
+ rel
->r_offset
);
7856 if (insn16
== NDS32_NOP16
)
7861 /* It checks whether the instruction could be converted to
7862 16-bit form and returns the converted one.
7864 `internal_relocs' is supposed to be sorted. */
7867 is_convert_32_to_16 (bfd
*abfd
, asection
*sec
,
7868 Elf_Internal_Rela
*reloc
,
7869 Elf_Internal_Rela
*internal_relocs
,
7870 Elf_Internal_Rela
*irelend
,
7873 #define NORMAL_32_TO_16 (1 << 0)
7874 #define SPECIAL_32_TO_16 (1 << 1)
7875 bfd_byte
*contents
= NULL
;
7879 Elf_Internal_Rela
*pc_rel
;
7880 int pic_ext_target
= 0;
7881 Elf_Internal_Shdr
*symtab_hdr
;
7882 Elf_Internal_Sym
*isymbuf
= NULL
;
7886 if (reloc
->r_offset
+ 4 > sec
->size
)
7889 offset
= reloc
->r_offset
;
7891 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
7893 insn
= bfd_getb32 (contents
+ offset
);
7895 if (nds32_convert_32_to_16 (abfd
, insn
, insn16
, NULL
))
7896 convert_type
= NORMAL_32_TO_16
;
7897 else if (special_convert_32_to_16 (insn
, insn16
, reloc
))
7898 convert_type
= SPECIAL_32_TO_16
;
7902 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7903 if (!nds32_get_local_syms (abfd
, sec
, &isymbuf
))
7906 /* Find the first relocation of the same relocation-type,
7907 so we iteratie them forward. */
7909 while ((pc_rel
- 1) >= internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
7912 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
7914 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
7915 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
7916 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
7917 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
7919 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
,
7921 if (off
>= ACCURATE_8BIT_S1
|| off
< -ACCURATE_8BIT_S1
7926 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
7928 /* movi => movi55 */
7929 mem_addr
= calculate_memory_address (abfd
, pc_rel
, isymbuf
,
7931 /* mem_addr is unsigned, but the value should
7932 be between [-16, 15]. */
7933 if ((mem_addr
+ 0x10) >> 5)
7937 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_20
)
7938 || (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_LO12
))
7940 /* It never happen movi to movi55 for R_NDS32_TLS_LE_20,
7941 because it can be relaxed to addi for TLS_LE_ADD. */
7944 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
7945 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
7946 && (reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
)
7947 && convert_type
== SPECIAL_32_TO_16
)
7950 We've selected a best fp-base for this access, so we can
7951 always resolve it anyway. Do nothing. */
7954 else if ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_NONE
7955 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_RELA_GNU_VTINHERIT
))
7956 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_RELA_GNU_VTENTRY
)
7957 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_INSN16
))
7958 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_LOADSTORE
)
7959 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_DWARF2_OP1_RELA
)))
7961 /* Prevent unresolved addi instruction translate
7962 to addi45 or addi333. */
7965 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
7967 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
,
7969 if (off
>= ACCURATE_U9BIT_S1
|| off
<= 0)
7979 nds32_elf_write_16 (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*contents
,
7980 Elf_Internal_Rela
*reloc
,
7981 Elf_Internal_Rela
*internal_relocs
,
7982 Elf_Internal_Rela
*irelend
,
7983 unsigned short insn16
)
7985 Elf_Internal_Rela
*pc_rel
;
7988 offset
= reloc
->r_offset
;
7989 bfd_putb16 (insn16
, contents
+ offset
);
7990 /* Find the first relocation of the same relocation-type,
7991 so we iteratie them forward. */
7993 while ((pc_rel
- 1) > internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
7996 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
7998 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
7999 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8000 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
)
8003 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PCREL_RELA
);
8005 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
8007 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PLTREL
);
8008 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
8010 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_5_RELA
);
8011 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
8012 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
8014 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_SDA_FP7U2_RELA
);
8015 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
8017 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_10IFCU_PCREL_RELA
);
8021 /* Find a relocation of type specified by `reloc_type'
8022 of the same r_offset with reloc.
8023 If not found, return irelend.
8025 Assuming relocations are sorted by r_offset,
8026 we find the relocation from `reloc' backward untill relocs,
8027 or find it from `reloc' forward untill irelend. */
8029 static Elf_Internal_Rela
*
8030 find_relocs_at_address (Elf_Internal_Rela
*reloc
,
8031 Elf_Internal_Rela
*relocs
,
8032 Elf_Internal_Rela
*irelend
,
8033 enum elf_nds32_reloc_type reloc_type
)
8035 Elf_Internal_Rela
*rel_t
;
8037 /* Find backward. */
8039 rel_t
>= relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
8041 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8044 /* We didn't find it backward. Try find it forward. */
8046 rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
8048 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8054 /* Find a relocation of specified type and offset.
8055 `reloc' is just a refence point to find a relocation at specified offset.
8056 If not found, return irelend.
8058 Assuming relocations are sorted by r_offset,
8059 we find the relocation from `reloc' backward untill relocs,
8060 or find it from `reloc' forward untill irelend. */
8062 static Elf_Internal_Rela
*
8063 find_relocs_at_address_addr (Elf_Internal_Rela
*reloc
,
8064 Elf_Internal_Rela
*relocs
,
8065 Elf_Internal_Rela
*irelend
,
8066 enum elf_nds32_reloc_type reloc_type
,
8069 Elf_Internal_Rela
*rel_t
= NULL
;
8071 /* First, we try to find a relocation of offset `offset_p',
8072 and then we use find_relocs_at_address to find specific type. */
8074 if (reloc
->r_offset
> offset_p
)
8076 /* Find backward. */
8078 rel_t
>= relocs
&& rel_t
->r_offset
> offset_p
; rel_t
--)
8081 else if (reloc
->r_offset
< offset_p
)
8085 rel_t
< irelend
&& rel_t
->r_offset
< offset_p
; rel_t
++)
8092 if (rel_t
< relocs
|| rel_t
== irelend
|| rel_t
->r_offset
!= offset_p
)
8095 return find_relocs_at_address (rel_t
, relocs
, irelend
, reloc_type
);
8099 nds32_elf_check_dup_relocs (Elf_Internal_Rela
*reloc
,
8100 Elf_Internal_Rela
*internal_relocs
,
8101 Elf_Internal_Rela
*irelend
,
8102 unsigned char reloc_type
)
8104 Elf_Internal_Rela
*rel_t
;
8107 rel_t
>= internal_relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
8109 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8111 if (ELF32_R_SYM (rel_t
->r_info
) == ELF32_R_SYM (reloc
->r_info
)
8112 && rel_t
->r_addend
== reloc
->r_addend
)
8117 for (rel_t
= reloc
; rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
8119 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8121 if (ELF32_R_SYM (rel_t
->r_info
) == ELF32_R_SYM (reloc
->r_info
)
8122 && rel_t
->r_addend
== reloc
->r_addend
)
8130 typedef struct nds32_elf_blank nds32_elf_blank_t
;
8131 struct nds32_elf_blank
8133 /* Where the blank begins. */
8135 /* The size of the blank. */
8137 /* The accumulative size before this blank. */
8139 nds32_elf_blank_t
*next
;
8140 nds32_elf_blank_t
*prev
;
8143 static nds32_elf_blank_t
*blank_free_list
= NULL
;
8145 static nds32_elf_blank_t
*
8146 create_nds32_elf_blank (bfd_vma offset_p
, bfd_vma size_p
)
8148 nds32_elf_blank_t
*blank_t
;
8150 if (blank_free_list
)
8152 blank_t
= blank_free_list
;
8153 blank_free_list
= blank_free_list
->next
;
8156 blank_t
= bfd_malloc (sizeof (nds32_elf_blank_t
));
8158 if (blank_t
== NULL
)
8161 blank_t
->offset
= offset_p
;
8162 blank_t
->size
= size_p
;
8163 blank_t
->total_size
= 0;
8164 blank_t
->next
= NULL
;
8165 blank_t
->prev
= NULL
;
8171 remove_nds32_elf_blank (nds32_elf_blank_t
*blank_p
)
8173 if (blank_free_list
)
8175 blank_free_list
->prev
= blank_p
;
8176 blank_p
->next
= blank_free_list
;
8179 blank_p
->next
= NULL
;
8181 blank_p
->prev
= NULL
;
8182 blank_free_list
= blank_p
;
8186 clean_nds32_elf_blank (void)
8188 nds32_elf_blank_t
*blank_t
;
8190 while (blank_free_list
)
8192 blank_t
= blank_free_list
;
8193 blank_free_list
= blank_free_list
->next
;
8198 static nds32_elf_blank_t
*
8199 search_nds32_elf_blank (nds32_elf_blank_t
*blank_p
, bfd_vma addr
)
8201 nds32_elf_blank_t
*blank_t
;
8207 while (blank_t
&& addr
< blank_t
->offset
)
8208 blank_t
= blank_t
->prev
;
8209 while (blank_t
&& blank_t
->next
&& addr
>= blank_t
->next
->offset
)
8210 blank_t
= blank_t
->next
;
8216 get_nds32_elf_blank_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
8219 nds32_elf_blank_t
*blank_t
;
8221 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
8228 if (addr
< blank_t
->offset
+ blank_t
->size
)
8229 return blank_t
->total_size
+ (addr
- blank_t
->offset
);
8231 return blank_t
->total_size
+ blank_t
->size
;
8235 insert_nds32_elf_blank (nds32_elf_blank_t
**blank_p
, bfd_vma addr
, bfd_vma len
)
8237 nds32_elf_blank_t
*blank_t
, *blank_t2
;
8241 *blank_p
= create_nds32_elf_blank (addr
, len
);
8242 return *blank_p
? TRUE
: FALSE
;
8245 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
8247 if (blank_t
== NULL
)
8249 blank_t
= create_nds32_elf_blank (addr
, len
);
8252 while ((*blank_p
)->prev
!= NULL
)
8253 *blank_p
= (*blank_p
)->prev
;
8254 blank_t
->next
= *blank_p
;
8255 (*blank_p
)->prev
= blank_t
;
8256 (*blank_p
) = blank_t
;
8260 if (addr
< blank_t
->offset
+ blank_t
->size
)
8262 if (addr
> blank_t
->offset
+ blank_t
->size
)
8263 blank_t
->size
= addr
- blank_t
->offset
;
8267 blank_t2
= create_nds32_elf_blank (addr
, len
);
8272 blank_t
->next
->prev
= blank_t2
;
8273 blank_t2
->next
= blank_t
->next
;
8275 blank_t2
->prev
= blank_t
;
8276 blank_t
->next
= blank_t2
;
8277 *blank_p
= blank_t2
;
8284 insert_nds32_elf_blank_recalc_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
8287 nds32_elf_blank_t
*blank_t
;
8289 if (!insert_nds32_elf_blank (blank_p
, addr
, len
))
8296 blank_t
->total_size
= 0;
8297 blank_t
= blank_t
->next
;
8302 blank_t
->total_size
= blank_t
->prev
->total_size
+ blank_t
->prev
->size
;
8303 blank_t
= blank_t
->next
;
8310 calc_nds32_blank_total (nds32_elf_blank_t
*blank_p
)
8312 nds32_elf_blank_t
*blank_t
;
8313 bfd_vma total_size
= 0;
8319 while (blank_t
->prev
)
8320 blank_t
= blank_t
->prev
;
8323 blank_t
->total_size
= total_size
;
8324 total_size
+= blank_t
->size
;
8325 blank_t
= blank_t
->next
;
8330 nds32_elf_relax_delete_blanks (bfd
*abfd
, asection
*sec
,
8331 nds32_elf_blank_t
*blank_p
)
8333 Elf_Internal_Shdr
*symtab_hdr
; /* Symbol table header of this bfd. */
8334 Elf_Internal_Sym
*isym
= NULL
; /* Symbol table of this bfd. */
8335 Elf_Internal_Sym
*isymend
; /* Symbol entry iterator. */
8336 unsigned int sec_shndx
; /* The section the be relaxed. */
8337 bfd_byte
*contents
; /* Contents data of iterating section. */
8338 Elf_Internal_Rela
*internal_relocs
;
8339 Elf_Internal_Rela
*irel
;
8340 Elf_Internal_Rela
*irelend
;
8341 struct elf_link_hash_entry
**sym_hashes
;
8342 struct elf_link_hash_entry
**end_hashes
;
8343 unsigned int symcount
;
8345 nds32_elf_blank_t
*blank_t
;
8346 nds32_elf_blank_t
*blank_t2
;
8347 nds32_elf_blank_t
*blank_head
;
8349 blank_head
= blank_t
= blank_p
;
8350 while (blank_head
->prev
!= NULL
)
8351 blank_head
= blank_head
->prev
;
8352 while (blank_t
->next
!= NULL
)
8353 blank_t
= blank_t
->next
;
8355 if (blank_t
->offset
+ blank_t
->size
<= sec
->size
)
8357 blank_t
->next
= create_nds32_elf_blank (sec
->size
+ 4, 0);
8358 blank_t
->next
->prev
= blank_t
;
8360 if (blank_head
->offset
> 0)
8362 blank_head
->prev
= create_nds32_elf_blank (0, 0);
8363 blank_head
->prev
->next
= blank_head
;
8364 blank_head
= blank_head
->prev
;
8367 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
8369 /* The deletion must stop at the next ALIGN reloc for an alignment
8370 power larger than the number of bytes we are deleting. */
8372 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8373 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
8378 isym
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8379 symtab_hdr
->sh_info
, 0, NULL
, NULL
, NULL
);
8380 symtab_hdr
->contents
= (bfd_byte
*) isym
;
8383 if (isym
== NULL
|| symtab_hdr
->sh_info
== 0)
8386 blank_t
= blank_head
;
8387 calc_nds32_blank_total (blank_head
);
8389 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
8391 /* Adjust all the relocs. */
8393 /* Relocations MUST be kept in memory, because relaxation adjust them. */
8394 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sect
, NULL
, NULL
,
8395 TRUE
/* keep_memory */);
8396 irelend
= internal_relocs
+ sect
->reloc_count
;
8398 blank_t
= blank_head
;
8399 blank_t2
= blank_head
;
8401 if (!(sect
->flags
& SEC_RELOC
))
8404 nds32_get_section_contents (abfd
, sect
, &contents
, TRUE
);
8406 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
8410 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_DIFF8
8411 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_DIFF32
8412 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
8414 unsigned long val
= 0;
8416 long before
, between
;
8419 switch (ELF32_R_TYPE (irel
->r_info
))
8422 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
8424 case R_NDS32_DIFF16
:
8425 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
8427 case R_NDS32_DIFF32
:
8428 val
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8429 /* Get the signed bit and mask for the high part. The
8430 gcc will alarm when right shift 32-bit since the
8431 type size of long may be 32-bit. */
8432 mask
= 0 - (val
>> 31);
8434 offset
= (val
| (mask
- 0xffffffff));
8443 0 |encoded in location|
8444 |------------|-------------------|---------
8446 -- before ---| *****************
8447 --------------------- between ---|
8449 We only care how much data are relax between DIFF,
8452 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
8453 between
= get_nds32_elf_blank_total (&blank_t
,
8454 irel
->r_addend
+ offset
, 0);
8455 if (between
== before
)
8456 goto done_adjust_diff
;
8458 switch (ELF32_R_TYPE (irel
->r_info
))
8461 bfd_put_8 (abfd
, offset
- (between
- before
),
8462 contents
+ irel
->r_offset
);
8464 case R_NDS32_DIFF16
:
8465 bfd_put_16 (abfd
, offset
- (between
- before
),
8466 contents
+ irel
->r_offset
);
8468 case R_NDS32_DIFF32
:
8469 bfd_put_32 (abfd
, offset
- (between
- before
),
8470 contents
+ irel
->r_offset
);
8474 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_DIFF_ULEB128
8475 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
8478 unsigned int len
= 0;
8479 unsigned long before
, between
;
8482 val
= _bfd_read_unsigned_leb128 (abfd
, contents
+ irel
->r_offset
,
8485 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
8486 between
= get_nds32_elf_blank_total (&blank_t
,
8487 irel
->r_addend
+ val
, 0);
8488 if (between
== before
)
8489 goto done_adjust_diff
;
8491 p
= contents
+ irel
->r_offset
;
8493 memset (p
, 0x80, len
);
8495 p
= write_uleb128 (p
, val
- (between
- before
)) - 1;
8503 raddr
= irel
->r_offset
;
8504 irel
->r_offset
-= get_nds32_elf_blank_total (&blank_t2
,
8507 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
8509 if (blank_t2
&& blank_t2
->next
8510 && (blank_t2
->offset
> raddr
8511 || blank_t2
->next
->offset
<= raddr
))
8513 (_("%pB: error: search_nds32_elf_blank reports wrong node"),
8516 /* Mark reloc in deleted portion as NONE.
8517 For some relocs like R_NDS32_LABEL that doesn't modify the
8518 content in the section. R_NDS32_LABEL doesn't belong to the
8519 instruction in the section, so we should preserve it. */
8520 if (raddr
>= blank_t2
->offset
8521 && raddr
< blank_t2
->offset
+ blank_t2
->size
8522 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
8523 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_BEGIN
8524 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_END
8525 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
8526 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_SUBTRAHEND
8527 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_MINUEND
)
8529 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
8535 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
8536 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
8537 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
8540 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
8541 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
8542 && ELF_ST_TYPE (isym
[ELF32_R_SYM (irel
->r_info
)].st_info
) == STT_SECTION
)
8544 if (irel
->r_addend
<= sec
->size
)
8546 get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 1);
8551 /* Adjust the local symbols defined in this section. */
8552 blank_t
= blank_head
;
8553 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
8555 if (isym
->st_shndx
== sec_shndx
)
8557 if (isym
->st_value
<= sec
->size
)
8560 bfd_vma orig_addr
= isym
->st_value
;
8562 ahead
= get_nds32_elf_blank_total (&blank_t
, isym
->st_value
, 1);
8563 isym
->st_value
-= ahead
;
8565 /* Adjust function size. */
8566 if (ELF32_ST_TYPE (isym
->st_info
) == STT_FUNC
8567 && isym
->st_size
> 0)
8569 get_nds32_elf_blank_total
8570 (&blank_t
, orig_addr
+ isym
->st_size
, 0) - ahead
;
8575 /* Now adjust the global symbols defined in this section. */
8576 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
8577 - symtab_hdr
->sh_info
);
8578 sym_hashes
= elf_sym_hashes (abfd
);
8579 end_hashes
= sym_hashes
+ symcount
;
8580 blank_t
= blank_head
;
8581 for (; sym_hashes
< end_hashes
; sym_hashes
++)
8583 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
8585 if ((sym_hash
->root
.type
== bfd_link_hash_defined
8586 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
8587 && sym_hash
->root
.u
.def
.section
== sec
)
8589 if (sym_hash
->root
.u
.def
.value
<= sec
->size
)
8592 bfd_vma orig_addr
= sym_hash
->root
.u
.def
.value
;
8594 ahead
= get_nds32_elf_blank_total (&blank_t
, sym_hash
->root
.u
.def
.value
, 1);
8595 sym_hash
->root
.u
.def
.value
-= ahead
;
8597 /* Adjust function size. */
8598 if (sym_hash
->type
== STT_FUNC
)
8600 get_nds32_elf_blank_total
8601 (&blank_t
, orig_addr
+ sym_hash
->size
, 0) - ahead
;
8607 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8608 blank_t
= blank_head
;
8609 while (blank_t
->next
)
8611 /* Actually delete the bytes. */
8613 /* If current blank is the last blank overlap with current section,
8614 go to finish process. */
8615 if (sec
->size
<= (blank_t
->next
->offset
))
8618 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
8619 contents
+ blank_t
->offset
+ blank_t
->size
,
8620 blank_t
->next
->offset
- (blank_t
->offset
+ blank_t
->size
));
8622 blank_t
= blank_t
->next
;
8625 if (sec
->size
> (blank_t
->offset
+ blank_t
->size
))
8627 /* There are remaining code between blank and section boundary.
8628 Move the remaining code to appropriate location. */
8629 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
8630 contents
+ blank_t
->offset
+ blank_t
->size
,
8631 sec
->size
- (blank_t
->offset
+ blank_t
->size
));
8632 sec
->size
-= blank_t
->total_size
+ blank_t
->size
;
8635 /* This blank is not entirely included in the section,
8636 reduce the section size by only part of the blank size. */
8637 sec
->size
-= blank_t
->total_size
+ (sec
->size
- blank_t
->offset
);
8641 blank_t
= blank_head
;
8642 blank_head
= blank_head
->next
;
8643 remove_nds32_elf_blank (blank_t
);
8649 /* Get the contents of a section. */
8652 nds32_get_section_contents (bfd
*abfd
, asection
*sec
,
8653 bfd_byte
**contents_p
, bfd_boolean cache
)
8655 /* Get the section contents. */
8656 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8657 *contents_p
= elf_section_data (sec
)->this_hdr
.contents
;
8660 if (!bfd_malloc_and_get_section (abfd
, sec
, contents_p
))
8663 elf_section_data (sec
)->this_hdr
.contents
= *contents_p
;
8669 /* Get the contents of the internal symbol of abfd. */
8672 nds32_get_local_syms (bfd
*abfd
, asection
*sec ATTRIBUTE_UNUSED
,
8673 Elf_Internal_Sym
**isymbuf_p
)
8675 Elf_Internal_Shdr
*symtab_hdr
;
8676 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8678 /* Read this BFD's local symbols if we haven't done so already. */
8679 if (*isymbuf_p
== NULL
&& symtab_hdr
->sh_info
!= 0)
8681 *isymbuf_p
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8682 if (*isymbuf_p
== NULL
)
8684 *isymbuf_p
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8685 symtab_hdr
->sh_info
, 0,
8687 if (*isymbuf_p
== NULL
)
8691 symtab_hdr
->contents
= (bfd_byte
*) (*isymbuf_p
);
8696 /* Range of small data. */
8697 static bfd_vma sdata_range
[2][2];
8698 static bfd_vma
const sdata_init_range
[2] =
8699 { ACCURATE_12BIT_S1
, ACCURATE_19BIT
};
8702 nds32_elf_insn_size (bfd
*abfd ATTRIBUTE_UNUSED
,
8703 bfd_byte
*contents
, bfd_vma addr
)
8705 unsigned long insn
= bfd_getb32 (contents
+ addr
);
8707 if (insn
& 0x80000000)
8713 /* Set the gp relax range. We have to measure the safe range
8714 to do gp relaxation. */
8717 relax_range_measurement (bfd
*abfd
)
8719 asection
*sec_f
, *sec_b
;
8720 /* For upper bound. */
8721 bfd_vma maxpgsz
= get_elf_backend_data (abfd
)->maxpagesize
;
8723 static int decide_relax_range
= 0;
8725 int range_number
= sizeof (sdata_init_range
) / sizeof (sdata_init_range
[0]);
8727 if (decide_relax_range
)
8729 decide_relax_range
= 1;
8731 if (sda_rela_sec
== NULL
)
8733 /* Since there is no data sections, we assume the range is page size. */
8734 for (i
= 0; i
< range_number
; i
++)
8736 sdata_range
[i
][0] = sdata_init_range
[i
] - 0x1000;
8737 sdata_range
[i
][1] = sdata_init_range
[i
] - 0x1000;
8742 /* Get the biggest alignment power after the gp located section. */
8743 sec_f
= sda_rela_sec
->output_section
;
8744 sec_b
= sec_f
->next
;
8746 while (sec_b
!= NULL
)
8748 if ((unsigned)(1 << sec_b
->alignment_power
) > align
)
8749 align
= (1 << sec_b
->alignment_power
);
8750 sec_b
= sec_b
->next
;
8753 /* I guess we can not determine the section before
8754 gp located section, so we assume the align is max page size. */
8755 for (i
= 0; i
< range_number
; i
++)
8757 sdata_range
[i
][1] = sdata_init_range
[i
] - align
;
8758 BFD_ASSERT (sdata_range
[i
][1] <= sdata_init_range
[i
]);
8759 sdata_range
[i
][0] = sdata_init_range
[i
] - maxpgsz
;
8760 BFD_ASSERT (sdata_range
[i
][0] <= sdata_init_range
[i
]);
8764 /* These are macros used to check flags encoded in r_addend.
8765 They are only used by nds32_elf_relax_section (). */
8766 #define GET_SEQ_LEN(addend) ((addend) & 0x000000ff)
8767 #define IS_1ST_CONVERT(addend) ((addend) & 0x80000000)
8768 #define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
8769 #define IS_16BIT_ON(addend) ((addend) & 0x20000000)
8771 static const char * unrecognized_reloc_msg
=
8772 /* xgettext:c-format */
8773 N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64
);
8775 /* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
8778 nds32_elf_relax_longcall1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
8779 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
8780 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
8781 Elf_Internal_Shdr
*symtab_hdr
)
8783 /* There are 3 variations for LONGCALL1
8784 case 4-4-2; 16-bit on, optimize off or optimize for space
8785 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8786 ori ta, ta, lo12(symbol) ; LO12S0
8789 case 4-4-4; 16-bit off, optimize don't care
8790 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8791 ori ta, ta, lo12(symbol) ; LO12S0
8794 case 4-4-4; 16-bit on, optimize for speed
8795 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8796 ori ta, ta, lo12(symbol) ; LO12S0
8798 Check code for -mlong-calls output. */
8800 /* Get the reloc for the address from which the register is
8801 being loaded. This reloc will tell us which function is
8802 actually being called. */
8805 int seq_len
; /* Original length of instruction sequence. */
8807 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
8808 int pic_ext_target
= 0;
8809 bfd_signed_vma foff
;
8812 irelend
= internal_relocs
+ sec
->reloc_count
;
8813 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
8814 laddr
= irel
->r_offset
;
8815 *insn_len
= seq_len
;
8817 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8818 R_NDS32_HI20_RELA
, laddr
);
8819 lo_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8820 R_NDS32_LO12S0_ORI_RELA
,
8823 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
8825 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL1",
8826 (uint64_t) irel
->r_offset
);
8830 /* Get the value of the symbol referred to by the reloc. */
8831 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
8834 /* This condition only happened when symbol is undefined. */
8835 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
8836 || foff
>= CONSERVATIVE_24BIT_S1
)
8839 /* Relax to: jal symbol; 25_PCREL */
8840 /* For simplicity of coding, we are going to modify the section
8841 contents, the section relocs, and the BFD symbol table. We
8842 must tell the rest of the code not to free up this
8843 information. It would be possible to instead create a table
8844 of changes which have to be made, as is done in coff-mips.c;
8845 that would be more work, but would require less memory when
8846 the linker is run. */
8848 /* Replace the long call with a jal. */
8849 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
8850 R_NDS32_25_PCREL_RELA
);
8851 irel
->r_addend
= hi_irelfn
->r_addend
;
8853 /* We don't resolve this here but resolve it in relocate_section. */
8855 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
8858 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
8860 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
8865 insn16
= NDS32_NOP16
;
8866 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
8868 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
8869 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
8875 #define CONVERT_CONDITION_CALL(insn) (((insn) & 0xffff0000) ^ 0x90000)
8876 /* Relax LONGCALL2 relocation for nds32_elf_relax_section. */
8879 nds32_elf_relax_longcall2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
8880 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
8881 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
8882 Elf_Internal_Shdr
*symtab_hdr
)
8884 /* bltz rt, .L1 ; LONGCALL2
8885 jal symbol ; 25_PCREL
8888 /* Get the reloc for the address from which the register is
8889 being loaded. This reloc will tell us which function is
8890 actually being called. */
8894 Elf_Internal_Rela
*i1_irelfn
, *cond_irelfn
, *irelend
;
8895 int pic_ext_target
= 0;
8896 bfd_signed_vma foff
;
8898 irelend
= internal_relocs
+ sec
->reloc_count
;
8899 laddr
= irel
->r_offset
;
8901 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8902 R_NDS32_25_PCREL_RELA
, laddr
+ 4);
8904 if (i1_irelfn
== irelend
)
8906 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL2",
8907 (uint64_t) irel
->r_offset
);
8911 insn
= bfd_getb32 (contents
+ laddr
);
8913 /* Get the value of the symbol referred to by the reloc. */
8914 foff
= calculate_offset (abfd
, sec
, i1_irelfn
, isymbuf
, symtab_hdr
,
8917 if (foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
8918 || foff
>= CONSERVATIVE_16BIT_S1
)
8921 /* Relax to bgezal rt, label ; 17_PCREL
8922 or bltzal rt, label ; 17_PCREL */
8924 /* Convert to complimentary conditional call. */
8925 insn
= CONVERT_CONDITION_CALL (insn
);
8927 /* For simplicity of coding, we are going to modify the section
8928 contents, the section relocs, and the BFD symbol table. We
8929 must tell the rest of the code not to free up this
8930 information. It would be possible to instead create a table
8931 of changes which have to be made, as is done in coff-mips.c;
8932 that would be more work, but would require less memory when
8933 the linker is run. */
8935 /* Clean unnessary relocations. */
8937 ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
), R_NDS32_NONE
);
8939 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8940 R_NDS32_17_PCREL_RELA
, laddr
);
8941 if (cond_irelfn
!= irelend
)
8942 cond_irelfn
->r_info
=
8943 ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
), R_NDS32_NONE
);
8945 /* Replace the long call with a bgezal. */
8946 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
),
8947 R_NDS32_17_PCREL_RELA
);
8948 irel
->r_addend
= i1_irelfn
->r_addend
;
8950 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
8956 /* Relax LONGCALL3 relocation for nds32_elf_relax_section. */
8959 nds32_elf_relax_longcall3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
8960 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
8961 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
8962 Elf_Internal_Shdr
*symtab_hdr
)
8964 /* There are 3 variations for LONGCALL3
8965 case 4-4-4-2; 16-bit on, optimize off or optimize for space
8966 bltz rt, $1 ; LONGCALL3
8967 sethi ta, hi20(symbol) ; HI20
8968 ori ta, ta, lo12(symbol) ; LO12S0
8972 case 4-4-4-4; 16-bit off, optimize don't care
8973 bltz rt, $1 ; LONGCALL3
8974 sethi ta, hi20(symbol) ; HI20
8975 ori ta, ta, lo12(symbol) ; LO12S0
8979 case 4-4-4-4; 16-bit on, optimize for speed
8980 bltz rt, $1 ; LONGCALL3
8981 sethi ta, hi20(symbol) ; HI20
8982 ori ta, ta, lo12(symbol) ; LO12S0
8986 /* Get the reloc for the address from which the register is
8987 being loaded. This reloc will tell us which function is
8988 actually being called. */
8991 int seq_len
; /* Original length of instruction sequence. */
8993 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
8994 int pic_ext_target
= 0;
8995 bfd_signed_vma foff
;
8998 irelend
= internal_relocs
+ sec
->reloc_count
;
8999 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9000 laddr
= irel
->r_offset
;
9001 *insn_len
= seq_len
;
9004 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9005 R_NDS32_HI20_RELA
, laddr
+ 4);
9007 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9008 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 8);
9010 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9012 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL3",
9013 (uint64_t) irel
->r_offset
);
9017 /* Get the value of the symbol referred to by the reloc. */
9018 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9021 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9022 || foff
>= CONSERVATIVE_24BIT_S1
)
9025 insn
= bfd_getb32 (contents
+ laddr
);
9026 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9028 /* Relax to bgezal rt, label ; 17_PCREL
9029 or bltzal rt, label ; 17_PCREL */
9031 /* Convert to complimentary conditional call. */
9032 insn
= CONVERT_CONDITION_CALL (insn
);
9033 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9037 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9039 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9041 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9044 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9045 R_NDS32_17_PCREL_RELA
, laddr
);
9046 if (cond_irelfn
!= irelend
)
9048 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9049 R_NDS32_17_PCREL_RELA
);
9050 cond_irelfn
->r_addend
= hi_irelfn
->r_addend
;
9055 insn16
= NDS32_NOP16
;
9056 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9057 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9059 hi_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9063 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
9065 /* Relax to the following instruction sequence
9066 bltz rt, $1 ; LONGCALL2
9067 jal symbol ; 25_PCREL
9071 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
9073 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9074 R_NDS32_25_PCREL_RELA
);
9076 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL2
);
9079 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9083 insn16
= NDS32_NOP16
;
9084 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9086 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
9087 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9094 /* Relax LONGJUMP1 relocation for nds32_elf_relax_section. */
9097 nds32_elf_relax_longjump1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9098 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9099 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9100 Elf_Internal_Shdr
*symtab_hdr
)
9102 /* There are 3 variations for LONGJUMP1
9103 case 4-4-2; 16-bit bit on, optimize off or optimize for space
9104 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9105 ori ta, ta, lo12(symbol) ; LO12S0
9108 case 4-4-4; 16-bit off, optimize don't care
9109 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9110 ori ta, ta, lo12(symbol) ; LO12S0
9113 case 4-4-4; 16-bit on, optimize for speed
9114 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9115 ori ta, ta, lo12(symbol) ; LO12S0
9118 /* Get the reloc for the address from which the register is
9119 being loaded. This reloc will tell us which function is
9120 actually being called. */
9123 int seq_len
; /* Original length of instruction sequence. */
9124 int insn16_on
; /* 16-bit on/off. */
9126 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
9127 int pic_ext_target
= 0;
9128 bfd_signed_vma foff
;
9130 unsigned long reloc
;
9132 irelend
= internal_relocs
+ sec
->reloc_count
;
9133 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9134 laddr
= irel
->r_offset
;
9135 *insn_len
= seq_len
;
9136 insn16_on
= IS_16BIT_ON (irel
->r_addend
);
9139 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9140 R_NDS32_HI20_RELA
, laddr
);
9142 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9143 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 4);
9144 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9146 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP1",
9147 (uint64_t) irel
->r_offset
);
9151 /* Get the value of the symbol referred to by the reloc. */
9152 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9155 if (pic_ext_target
|| foff
== 0 || foff
>= CONSERVATIVE_24BIT_S1
9156 || foff
< -CONSERVATIVE_24BIT_S1
)
9159 if (insn16_on
&& foff
>= -ACCURATE_8BIT_S1
9160 && foff
< ACCURATE_8BIT_S1
&& (seq_len
& 0x2))
9163 /* 16-bit on, but not optimized for speed. */
9164 reloc
= R_NDS32_9_PCREL_RELA
;
9166 bfd_putb16 (insn16
, contents
+ irel
->r_offset
);
9169 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9174 reloc
= R_NDS32_25_PCREL_RELA
;
9176 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9179 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_INSN16
);
9184 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
9186 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9188 if ((seq_len
& 0x2) && ((*insn_len
& 2) == 0))
9190 insn16
= NDS32_NOP16
;
9191 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9193 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9195 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9201 /* Revert condition branch. This function does not check if the input
9202 instruction is condition branch or not. */
9205 nds32_elf_convert_branch (uint16_t insn16
, uint32_t insn
,
9206 uint16_t *re_insn16
, uint32_t *re_insn
)
9208 uint32_t comp_insn
= 0;
9209 uint16_t comp_insn16
= 0;
9213 if (N32_OP6 (insn
) == N32_OP6_BR1
)
9216 comp_insn
= (insn
^ 0x4000) & 0xffffc000;
9217 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
)
9219 /* Insn can be contracted to 16-bit implied r5. */
9221 (comp_insn
& 0x4000) ? INSN_BNES38
: INSN_BEQS38
;
9222 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
9225 else if (N32_OP6 (insn
) == N32_OP6_BR3
)
9227 /* bnec $ta, imm11, label. */
9228 comp_insn
= (insn
^ 0x80000) & 0xffffff00;
9232 comp_insn
= (insn
^ 0x10000) & 0xffffc000;
9233 if (N32_BR2_SUB (insn
) == N32_BR2_BEQZ
9234 || N32_BR2_SUB (insn
) == N32_BR2_BNEZ
)
9236 if (N32_IS_RT3 (insn
))
9238 /* Insn can be contracted to 16-bit. */
9240 (comp_insn
& 0x10000) ? INSN_BNEZ38
: INSN_BEQZ38
;
9241 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
9243 else if (N32_RT5 (insn
) == REG_R15
)
9245 /* Insn can be contracted to 16-bit. */
9247 (comp_insn
& 0x10000) ? INSN_BNES38
: INSN_BEQS38
;
9254 switch ((insn16
& 0xf000) >> 12)
9257 /* beqz38 or bnez38 */
9258 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
9259 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNEZ
: INSN_BEQZ
;
9260 comp_insn
|= ((comp_insn16
& 0x0700) >> 8) << 20;
9264 /* beqs38 or bnes38 */
9265 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
9266 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNE
: INSN_BEQ
;
9267 comp_insn
|= (((comp_insn16
& 0x0700) >> 8) << 20)
9272 /* beqzS8 or bnezS8 */
9273 comp_insn16
= (insn16
^ 0x0100) & 0xff00;
9274 comp_insn
= (comp_insn16
& 0x0100) ? INSN_BNEZ
: INSN_BEQZ
;
9275 comp_insn
|= REG_R15
<< 20;
9282 if (comp_insn
&& re_insn
)
9283 *re_insn
= comp_insn
;
9284 if (comp_insn16
&& re_insn16
)
9285 *re_insn16
= comp_insn16
;
9288 /* Relax LONGJUMP2 relocation for nds32_elf_relax_section. */
9291 nds32_elf_relax_longjump2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9292 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9293 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9294 Elf_Internal_Shdr
*symtab_hdr
)
9296 /* There are 3 variations for LONGJUMP2
9297 case 2-4; 1st insn convertible, 16-bit on,
9298 optimize off or optimize for space
9299 bnes38 rt, ra, $1 ; LONGJUMP2
9303 case 4-4; 1st insn not convertible
9304 bne rt, ra, $1 ; LONGJUMP2
9308 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
9309 bne rt, ra, $1 ; LONGJUMP2
9313 /* Get the reloc for the address from which the register is
9314 being loaded. This reloc will tell us which function is
9315 actually being called. */
9318 int seq_len
; /* Original length of instruction sequence. */
9319 Elf_Internal_Rela
*i2_irelfn
, *cond_irelfn
, *irelend
;
9320 int pic_ext_target
= 0, first_size
;
9322 bfd_signed_vma foff
;
9323 uint32_t insn
, re_insn
= 0;
9324 uint16_t insn16
, re_insn16
= 0;
9325 unsigned long reloc
, cond_reloc
;
9327 enum elf_nds32_reloc_type checked_types
[] =
9328 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
9330 irelend
= internal_relocs
+ sec
->reloc_count
;
9331 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9332 laddr
= irel
->r_offset
;
9333 *insn_len
= seq_len
;
9334 first_size
= (seq_len
== 6) ? 2 : 4;
9337 find_relocs_at_address_addr (irel
, internal_relocs
,
9338 irelend
, R_NDS32_25_PCREL_RELA
,
9339 laddr
+ first_size
);
9341 for (i
= 0; i
< sizeof (checked_types
) / sizeof(checked_types
[0]); i
++)
9344 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9345 checked_types
[i
], laddr
);
9346 if (cond_irelfn
!= irelend
)
9350 if (i2_irelfn
== irelend
|| cond_irelfn
== irelend
)
9352 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP2",
9353 (uint64_t) irel
->r_offset
);
9357 /* Get the value of the symbol referred to by the reloc. */
9359 calculate_offset (abfd
, sec
, i2_irelfn
, isymbuf
, symtab_hdr
,
9361 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
9362 || foff
>= CONSERVATIVE_16BIT_S1
)
9365 /* Get the all corresponding instructions. */
9366 if (first_size
== 4)
9368 insn
= bfd_getb32 (contents
+ laddr
);
9369 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
9373 insn16
= bfd_getb16 (contents
+ laddr
);
9374 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
9377 if (re_insn16
&& foff
>= -(ACCURATE_8BIT_S1
- first_size
)
9378 && foff
< ACCURATE_8BIT_S1
- first_size
)
9380 if (first_size
== 4)
9382 /* Don't convert it to 16-bit now, keep this as relaxable for
9383 ``label reloc; INSN16''. */
9385 /* Save comp_insn32 to buffer. */
9386 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9388 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
9389 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
9390 cond_reloc
= R_NDS32_INSN16
;
9394 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
9396 reloc
= R_NDS32_9_PCREL_RELA
;
9397 cond_reloc
= R_NDS32_NONE
;
9400 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
9401 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
9402 && foff
< ACCURATE_14BIT_S1
- first_size
))
9404 /* beqs label ; 15_PCREL */
9405 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9407 reloc
= R_NDS32_15_PCREL_RELA
;
9408 cond_reloc
= R_NDS32_NONE
;
9410 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
9411 && foff
>= -CONSERVATIVE_16BIT_S1
9412 && foff
< CONSERVATIVE_16BIT_S1
)
9414 /* beqz label ; 17_PCREL */
9415 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9417 reloc
= R_NDS32_17_PCREL_RELA
;
9418 cond_reloc
= R_NDS32_NONE
;
9423 /* Set all relocations. */
9424 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
), reloc
);
9425 irel
->r_addend
= i2_irelfn
->r_addend
;
9427 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
9429 cond_irelfn
->r_addend
= 0;
9431 if ((seq_len
^ *insn_len
) & 0x2)
9433 insn16
= NDS32_NOP16
;
9434 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ 4);
9435 i2_irelfn
->r_offset
= 4;
9436 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
9438 i2_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9442 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
9447 /* Relax LONGJUMP3 relocation for nds32_elf_relax_section. */
9450 nds32_elf_relax_longjump3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9451 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9452 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9453 Elf_Internal_Shdr
*symtab_hdr
)
9455 /* There are 5 variations for LONGJUMP3
9456 case 1: 2-4-4-2; 1st insn convertible, 16-bit on,
9457 optimize off or optimize for space
9458 bnes38 rt, ra, $1 ; LONGJUMP3
9459 sethi ta, hi20(symbol) ; HI20
9460 ori ta, ta, lo12(symbol) ; LO12S0
9464 case 2: 2-4-4-2; 1st insn convertible, 16-bit on, optimize for speed
9465 bnes38 rt, ra, $1 ; LONGJUMP3
9466 sethi ta, hi20(symbol) ; HI20
9467 ori ta, ta, lo12(symbol) ; LO12S0
9471 case 3: 4-4-4-2; 1st insn not convertible, 16-bit on,
9472 optimize off or optimize for space
9473 bne rt, ra, $1 ; LONGJUMP3
9474 sethi ta, hi20(symbol) ; HI20
9475 ori ta, ta, lo12(symbol) ; LO12S0
9479 case 4: 4-4-4-4; 1st insn don't care, 16-bit off, optimize don't care
9480 16-bit off if no INSN16
9481 bne rt, ra, $1 ; LONGJUMP3
9482 sethi ta, hi20(symbol) ; HI20
9483 ori ta, ta, lo12(symbol) ; LO12S0
9487 case 5: 4-4-4-4; 1st insn not convertible, 16-bit on, optimize for speed
9488 16-bit off if no INSN16
9489 bne rt, ra, $1 ; LONGJUMP3
9490 sethi ta, hi20(symbol) ; HI20
9491 ori ta, ta, lo12(symbol) ; LO12S0
9495 /* Get the reloc for the address from which the register is
9496 being loaded. This reloc will tell us which function is
9497 actually being called. */
9498 enum elf_nds32_reloc_type checked_types
[] =
9499 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
9501 int reloc_off
= 0, cond_removed
= 0, convertible
;
9503 int seq_len
; /* Original length of instruction sequence. */
9504 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
9505 int pic_ext_target
= 0, first_size
;
9507 bfd_signed_vma foff
;
9508 uint32_t insn
, re_insn
= 0;
9509 uint16_t insn16
, re_insn16
= 0;
9510 unsigned long reloc
, cond_reloc
;
9512 irelend
= internal_relocs
+ sec
->reloc_count
;
9513 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9514 laddr
= irel
->r_offset
;
9515 *insn_len
= seq_len
;
9517 convertible
= IS_1ST_CONVERT (irel
->r_addend
);
9524 /* Get all needed relocations. */
9526 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9527 R_NDS32_HI20_RELA
, laddr
+ first_size
);
9529 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9530 R_NDS32_LO12S0_ORI_RELA
,
9531 laddr
+ first_size
+ 4);
9533 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
9536 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9537 checked_types
[i
], laddr
);
9538 if (cond_irelfn
!= irelend
)
9542 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
|| cond_irelfn
== irelend
)
9544 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP3",
9545 (uint64_t) irel
->r_offset
);
9549 /* Get the value of the symbol referred to by the reloc. */
9550 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9553 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9554 || foff
>= CONSERVATIVE_24BIT_S1
)
9557 /* Get the all corresponding instructions. */
9558 if (first_size
== 4)
9560 insn
= bfd_getb32 (contents
+ laddr
);
9561 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
9565 insn16
= bfd_getb16 (contents
+ laddr
);
9566 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
9569 /* For simplicity of coding, we are going to modify the section
9570 contents, the section relocs, and the BFD symbol table. We
9571 must tell the rest of the code not to free up this
9572 information. It would be possible to instead create a table
9573 of changes which have to be made, as is done in coff-mips.c;
9574 that would be more work, but would require less memory when
9575 the linker is run. */
9577 if (re_insn16
&& foff
>= -ACCURATE_8BIT_S1
- first_size
9578 && foff
< ACCURATE_8BIT_S1
- first_size
)
9580 if (!(seq_len
& 0x2))
9582 /* Don't convert it to 16-bit now, keep this as relaxable
9583 for ``label reloc; INSN1a''6. */
9584 /* Save comp_insn32 to buffer. */
9585 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9587 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
9588 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
9589 cond_reloc
= R_NDS32_INSN16
;
9593 /* Not optimize for speed; convert sequence to 16-bit. */
9594 /* Save comp_insn16 to buffer. */
9595 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
9597 reloc
= R_NDS32_9_PCREL_RELA
;
9598 cond_reloc
= R_NDS32_NONE
;
9602 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
9603 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
9604 && foff
< ACCURATE_14BIT_S1
- first_size
))
9606 /* beqs label ; 15_PCREL */
9607 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9609 reloc
= R_NDS32_15_PCREL_RELA
;
9610 cond_reloc
= R_NDS32_NONE
;
9613 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
9614 && foff
>= -CONSERVATIVE_16BIT_S1
9615 && foff
< CONSERVATIVE_16BIT_S1
)
9617 /* beqz label ; 17_PCREL */
9618 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9620 reloc
= R_NDS32_17_PCREL_RELA
;
9621 cond_reloc
= R_NDS32_NONE
;
9624 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
9625 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
9627 /* Relax to one of the following 3 variations
9629 case 2-4; 1st insn convertible, 16-bit on, optimize off or optimize
9631 bnes38 rt, $1 ; LONGJUMP2
9635 case 4-4; 1st insn not convertible, others don't care
9636 bne rt, ra, $1 ; LONGJUMP2
9640 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
9641 bne rt, ra, $1 ; LONGJUMP2
9645 /* Offset for first instruction. */
9647 /* Use j label as second instruction. */
9648 *insn_len
= 4 + first_size
;
9650 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
9651 reloc
= R_NDS32_LONGJUMP2
;
9652 cond_reloc
= R_NDS32_25_PLTREL
;
9657 if (cond_removed
== 1)
9659 /* Set all relocations. */
9660 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
9661 irel
->r_addend
= hi_irelfn
->r_addend
;
9663 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
9665 cond_irelfn
->r_addend
= 0;
9666 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9671 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
9672 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9676 if ((seq_len
^ *insn_len
) & 0x2)
9678 insn16
= NDS32_NOP16
;
9679 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9680 lo_irelfn
->r_offset
= *insn_len
;
9681 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9683 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9687 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9692 /* Relax LONGCALL4 relocation for nds32_elf_relax_section. */
9695 nds32_elf_relax_longcall4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9696 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9697 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9698 Elf_Internal_Shdr
*symtab_hdr
)
9700 /* The pattern for LONGCALL4. Support for function cse.
9701 sethi ta, hi20(symbol) ; LONGCALL4/HI20
9702 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
9703 jral ta ; PTR_RES/EMPTY/INSN16 */
9707 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *insn_irel
, *em_irel
, *call_irel
;
9708 Elf_Internal_Rela
*irelend
;
9709 int pic_ext_target
= 0;
9710 bfd_signed_vma foff
;
9712 irelend
= internal_relocs
+ sec
->reloc_count
;
9713 laddr
= irel
->r_offset
;
9715 /* Get the reloc for the address from which the register is
9716 being loaded. This reloc will tell us which function is
9717 actually being called. */
9718 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9719 R_NDS32_HI20_RELA
, laddr
);
9721 if (hi_irel
== irelend
)
9723 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
9724 (uint64_t) irel
->r_offset
);
9728 /* Get the value of the symbol referred to by the reloc. */
9729 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
,
9732 /* This condition only happened when symbol is undefined. */
9733 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9734 || foff
>= CONSERVATIVE_24BIT_S1
)
9737 /* Relax to: jal symbol; 25_PCREL */
9738 /* For simplicity of coding, we are going to modify the section
9739 contents, the section relocs, and the BFD symbol table. We
9740 must tell the rest of the code not to free up this
9741 information. It would be possible to instead create a table
9742 of changes which have to be made, as is done in coff-mips.c;
9743 that would be more work, but would require less memory when
9744 the linker is run. */
9746 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9747 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
9748 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9749 R_NDS32_EMPTY
, irel
->r_addend
);
9751 if (ptr_irel
== irelend
|| em_irel
== irelend
)
9753 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
9754 (uint64_t) irel
->r_offset
);
9757 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
9758 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
9759 if (insn
& 0x80000000)
9762 /* Replace the long call with a jal. */
9763 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
9764 R_NDS32_25_PCREL_RELA
);
9765 ptr_irel
->r_addend
= 1;
9767 /* We don't resolve this here but resolve it in relocate_section. */
9769 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
9772 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9774 /* If there is function cse, HI20 can not remove now. */
9775 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9776 R_NDS32_LONGCALL4
, laddr
);
9777 if (call_irel
== irelend
)
9781 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
9784 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9785 R_NDS32_INSN16
, irel
->r_addend
);
9786 if (insn_irel
!= irelend
)
9788 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9793 /* Relax LONGCALL5 relocation for nds32_elf_relax_section. */
9796 nds32_elf_relax_longcall5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9797 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9798 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9799 Elf_Internal_Shdr
*symtab_hdr
)
9801 /* The pattern for LONGCALL5.
9802 bltz rt, .L1 ; LONGCALL5/17_PCREL
9803 jal symbol ; 25_PCREL
9808 Elf_Internal_Rela
*cond_irel
, *irelend
;
9809 int pic_ext_target
= 0;
9810 bfd_signed_vma foff
;
9812 irelend
= internal_relocs
+ sec
->reloc_count
;
9813 laddr
= irel
->r_offset
;
9814 insn
= bfd_getb32 (contents
+ laddr
);
9816 /* Get the reloc for the address from which the register is
9817 being loaded. This reloc will tell us which function is
9818 actually being called. */
9820 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9821 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
9822 if (cond_irel
== irelend
)
9824 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL5",
9825 (uint64_t) irel
->r_offset
);
9829 /* Get the value of the symbol referred to by the reloc. */
9830 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
9833 if (foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
9834 || foff
>= CONSERVATIVE_16BIT_S1
)
9837 /* Relax to bgezal rt, label ; 17_PCREL
9838 or bltzal rt, label ; 17_PCREL */
9840 /* Convert to complimentary conditional call. */
9841 insn
= CONVERT_CONDITION_CALL (insn
);
9843 /* For simplicity of coding, we are going to modify the section
9844 contents, the section relocs, and the BFD symbol table. We
9845 must tell the rest of the code not to free up this
9846 information. It would be possible to instead create a table
9847 of changes which have to be made, as is done in coff-mips.c;
9848 that would be more work, but would require less memory when
9849 the linker is run. */
9851 /* Modify relocation and contents. */
9853 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
9855 /* Replace the long call with a bgezal. */
9856 bfd_putb32 (insn
, contents
+ cond_irel
->r_offset
);
9859 /* Clean unnessary relocations. */
9860 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9862 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9863 R_NDS32_17_PCREL_RELA
, laddr
);
9865 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
9870 /* Relax LONGCALL6 relocation for nds32_elf_relax_section. */
9873 nds32_elf_relax_longcall6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9874 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9875 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9876 Elf_Internal_Shdr
*symtab_hdr
)
9878 /* The pattern for LONGCALL6.
9879 bltz rt, .L1 ; LONGCALL6/17_PCREL
9880 sethi ta, hi20(symbol) ; HI20/PTR
9881 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
9882 jral ta ; PTR_RES/EMPTY/INSN16
9887 Elf_Internal_Rela
*em_irel
, *cond_irel
, *irelend
;
9888 int pic_ext_target
= 0;
9889 bfd_signed_vma foff
;
9891 irelend
= internal_relocs
+ sec
->reloc_count
;
9892 laddr
= irel
->r_offset
;
9894 /* Get the reloc for the address from which the register is
9895 being loaded. This reloc will tell us which function is
9896 actually being called. */
9897 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9898 R_NDS32_EMPTY
, irel
->r_addend
);
9900 if (em_irel
== irelend
)
9902 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL6",
9903 (uint64_t) irel
->r_offset
);
9907 /* Get the value of the symbol referred to by the reloc. */
9908 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
,
9911 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9912 || foff
>= CONSERVATIVE_24BIT_S1
)
9915 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
9916 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
9917 if (insn
& 0x80000000)
9920 insn
= bfd_getb32 (contents
+ laddr
);
9921 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9923 /* Relax to bgezal rt, label ; 17_PCREL
9924 or bltzal rt, label ; 17_PCREL */
9926 /* Convert to complimentary conditional call. */
9928 insn
= CONVERT_CONDITION_CALL (insn
);
9929 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
9932 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
9934 /* Set resolved relocation. */
9936 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9937 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
9938 if (cond_irel
== irelend
)
9940 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
9941 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
9944 cond_irel
->r_addend
= 1;
9946 /* Clear relocations. */
9949 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9952 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9953 R_NDS32_17_PCREL_RELA
, laddr
);
9954 if (cond_irel
!= irelend
)
9956 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
9959 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9960 R_NDS32_INSN16
, irel
->r_addend
);
9961 if (cond_irel
!= irelend
)
9963 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
9966 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
9968 /* Relax to the following instruction sequence
9969 bltz rt, .L1 ; LONGCALL2/17_PCREL
9970 jal symbol ; 25_PCREL/PTR_RES
9973 /* Convert instruction. */
9975 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
9977 /* Convert relocations. */
9978 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
9979 R_NDS32_25_PCREL_RELA
);
9981 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL5
);
9983 /* Set resolved relocation. */
9985 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9986 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
9987 if (cond_irel
== irelend
)
9989 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
9990 "R_NDS32_LONGCALL6", (uint64_t) irel
->r_offset
);
9993 cond_irel
->r_addend
= 1;
9996 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9997 R_NDS32_INSN16
, irel
->r_addend
);
9998 if (cond_irel
!= irelend
)
10000 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10005 /* Relax LONGJUMP4 relocation for nds32_elf_relax_section. */
10008 nds32_elf_relax_longjump4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10009 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10010 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10011 Elf_Internal_Shdr
*symtab_hdr
)
10013 /* The pattern for LONGJUMP4.
10014 sethi ta, hi20(symbol) ; LONGJUMP4/HI20
10015 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10016 jr ta ; PTR_RES/INSN16/EMPTY */
10019 int seq_len
; /* Original length of instruction sequence. */
10021 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *em_irel
, *call_irel
, *irelend
;
10022 int pic_ext_target
= 0;
10023 bfd_signed_vma foff
;
10025 irelend
= internal_relocs
+ sec
->reloc_count
;
10026 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10027 laddr
= irel
->r_offset
;
10028 *insn_len
= seq_len
;
10030 /* Get the reloc for the address from which the register is
10031 being loaded. This reloc will tell us which function is
10032 actually being called. */
10034 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10035 R_NDS32_HI20_RELA
, laddr
);
10037 if (hi_irel
== irelend
)
10039 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
10040 (uint64_t) irel
->r_offset
);
10044 /* Get the value of the symbol referred to by the reloc. */
10045 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
,
10048 if (pic_ext_target
|| foff
== 0 || foff
>= CONSERVATIVE_24BIT_S1
10049 || foff
< -CONSERVATIVE_24BIT_S1
)
10052 /* Convert it to "j label", it may be converted to j8 in the final
10053 pass of relaxation. Therefore, we do not consider this currently. */
10054 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10055 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10056 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10057 R_NDS32_EMPTY
, irel
->r_addend
);
10059 if (ptr_irel
== irelend
|| em_irel
== irelend
)
10061 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
10062 (uint64_t) irel
->r_offset
);
10067 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_25_PCREL_RELA
);
10068 ptr_irel
->r_addend
= 1;
10070 /* Write instruction. */
10072 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10074 /* Clear relocations. */
10075 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10077 /* If there is function cse, HI20 can not remove now. */
10078 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10079 R_NDS32_LONGJUMP4
, laddr
);
10080 if (call_irel
== irelend
)
10084 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
10090 /* Relax LONGJUMP5 relocation for nds32_elf_relax_section. */
10093 nds32_elf_relax_longjump5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10094 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10095 int *seq_len
, bfd_byte
*contents
,
10096 Elf_Internal_Sym
*isymbuf
,
10097 Elf_Internal_Shdr
*symtab_hdr
)
10099 /* There are 2 variations for LONGJUMP5
10100 case 2-4; 1st insn convertible, 16-bit on.
10101 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
10102 j label ; 25_PCREL/INSN16
10105 case 4-4; 1st insn not convertible
10106 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
10107 j label ; 25_PCREL/INSN16
10111 Elf_Internal_Rela
*cond_irel
, *irelend
;
10112 int pic_ext_target
= 0;
10114 bfd_signed_vma foff
;
10115 uint32_t insn
, re_insn
= 0;
10116 uint16_t insn16
, re_insn16
= 0;
10117 unsigned long reloc
;
10119 enum elf_nds32_reloc_type checked_types
[] =
10120 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
10121 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
10123 irelend
= internal_relocs
+ sec
->reloc_count
;
10124 laddr
= irel
->r_offset
;
10126 /* Get the reloc for the address from which the register is
10127 being loaded. This reloc will tell us which function is
10128 actually being called. */
10131 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10132 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
10133 if (cond_irel
== irelend
)
10135 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP5",
10136 (uint64_t) irel
->r_offset
);
10140 /* Get the value of the symbol referred to by the reloc. */
10141 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
10144 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
10145 || foff
>= CONSERVATIVE_16BIT_S1
)
10148 /* Get the all corresponding instructions. */
10149 insn
= bfd_getb32 (contents
+ laddr
);
10150 /* Check instruction size. */
10151 if (insn
& 0x80000000)
10154 insn16
= insn
>> 16;
10155 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10158 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10160 if (N32_OP6 (re_insn
) == N32_OP6_BR1
10161 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
10163 /* beqs label ; 15_PCREL. */
10164 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10165 reloc
= R_NDS32_15_PCREL_RELA
;
10167 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10168 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10170 /* beqz label ; 17_PCREL. */
10171 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10172 reloc
= R_NDS32_17_PCREL_RELA
;
10174 else if ( N32_OP6 (re_insn
) == N32_OP6_BR3
10175 && foff
>= -CONSERVATIVE_8BIT_S1
&& foff
< CONSERVATIVE_8BIT_S1
)
10177 /* beqc label ; 9_PCREL. */
10178 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10179 reloc
= R_NDS32_WORD_9_PCREL_RELA
;
10184 /* Set all relocations. */
10185 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), reloc
);
10187 /* Clean relocations. */
10188 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10189 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
10191 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10192 checked_types
[i
], laddr
);
10193 if (cond_irel
!= irelend
)
10196 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
10198 /* If the branch instruction is 2 byte, it cannot remove
10199 directly. Only convert it to nop16 and remove it after
10200 checking alignment issue. */
10201 insn16
= NDS32_NOP16
;
10202 bfd_putb16 (insn16
, contents
+ laddr
);
10203 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10206 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10215 /* Relax LONGJUMP6 relocation for nds32_elf_relax_section. */
10218 nds32_elf_relax_longjump6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10219 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10220 int *seq_len
, bfd_byte
*contents
,
10221 Elf_Internal_Sym
*isymbuf
,
10222 Elf_Internal_Shdr
*symtab_hdr
)
10224 /* There are 5 variations for LONGJUMP6
10225 case : 2-4-4-4; 1st insn convertible, 16-bit on.
10226 bnes38 rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
10227 sethi ta, hi20(symbol) ; HI20/PTR
10228 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10229 jr ta ; PTR_RES/INSN16/EMPTY
10232 case : 4-4-4-4; 1st insn not convertible, 16-bit on.
10233 bne rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
10234 sethi ta, hi20(symbol) ; HI20/PTR
10235 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10236 jr ta ; PTR_RES/INSN16/EMPTY
10239 enum elf_nds32_reloc_type checked_types
[] =
10240 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
10241 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
10243 int reloc_off
= 0, cond_removed
= 0;
10245 Elf_Internal_Rela
*cond_irel
, *em_irel
, *irelend
, *insn_irel
;
10246 int pic_ext_target
= 0;
10248 bfd_signed_vma foff
;
10249 uint32_t insn
, re_insn
= 0;
10250 uint16_t insn16
, re_insn16
= 0;
10251 unsigned long reloc
;
10253 irelend
= internal_relocs
+ sec
->reloc_count
;
10254 laddr
= irel
->r_offset
;
10256 /* Get the reloc for the address from which the register is
10257 being loaded. This reloc will tell us which function is
10258 actually being called. */
10259 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10260 R_NDS32_EMPTY
, irel
->r_addend
);
10262 if (em_irel
== irelend
)
10264 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP6",
10265 (uint64_t) irel
->r_offset
);
10269 /* Get the value of the symbol referred to by the reloc. */
10270 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
,
10273 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
10274 || foff
>= CONSERVATIVE_24BIT_S1
)
10277 insn
= bfd_getb32 (contents
+ laddr
);
10278 /* Check instruction size. */
10279 if (insn
& 0x80000000)
10282 insn16
= insn
>> 16;
10283 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10286 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10288 /* For simplicity of coding, we are going to modify the section
10289 contents, the section relocs, and the BFD symbol table. We
10290 must tell the rest of the code not to free up this
10291 information. It would be possible to instead create a table
10292 of changes which have to be made, as is done in coff-mips.c;
10293 that would be more work, but would require less memory when
10294 the linker is run. */
10296 if (N32_OP6 (re_insn
) == N32_OP6_BR1
10297 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
10299 /* beqs label ; 15_PCREL */
10300 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
10301 reloc
= R_NDS32_15_PCREL_RELA
;
10304 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10305 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10307 /* beqz label ; 17_PCREL */
10308 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
10309 reloc
= R_NDS32_17_PCREL_RELA
;
10312 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
10313 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
10315 /* Relax to one of the following 2 variations
10317 case 2-4; 1st insn convertible, 16-bit on.
10318 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
10319 j label ; 25_PCREL/INSN16
10322 case 4-4; 1st insn not convertible
10323 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
10324 j label ; 25_PCREL/INSN16
10327 /* Use j label as second instruction. */
10329 reloc
= R_NDS32_25_PCREL_RELA
;
10330 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10335 /* Set all relocations. */
10336 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), reloc
);
10339 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10340 R_NDS32_PTR_RESOLVED
, em_irel
->r_offset
);
10341 cond_irel
->r_addend
= 1;
10343 /* Use INSN16 of first branch instruction to distinguish if keeping
10344 INSN16 of final instruction or not. */
10345 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10346 R_NDS32_INSN16
, irel
->r_offset
);
10347 if (insn_irel
== irelend
)
10349 /* Clean the final INSN16. */
10351 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10352 R_NDS32_INSN16
, em_irel
->r_offset
);
10353 insn_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10357 if (cond_removed
== 1)
10361 /* Clear relocations. */
10362 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10364 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
10367 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10368 checked_types
[i
], laddr
);
10369 if (cond_irel
!= irelend
)
10372 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
10374 /* If the branch instruction is 2 byte, it cannot remove
10375 directly. Only convert it to nop16 and remove it after
10376 checking alignment issue. */
10377 insn16
= NDS32_NOP16
;
10378 bfd_putb16 (insn16
, contents
+ laddr
);
10379 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10382 cond_irel
->r_info
=
10383 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10389 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
10390 R_NDS32_LONGJUMP5
);
10396 /* Relax LONGJUMP7 relocation for nds32_elf_relax_section. */
10399 nds32_elf_relax_longjump7 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10400 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10401 int *seq_len
, bfd_byte
*contents
,
10402 Elf_Internal_Sym
*isymbuf
,
10403 Elf_Internal_Shdr
*symtab_hdr
)
10405 /* There are 2 variations for LONGJUMP5
10406 case 2-4; 1st insn convertible, 16-bit on.
10407 movi55 ta, imm11 ; LONGJUMP7/INSN16
10408 beq rt, ta, label ; 15_PCREL
10410 case 4-4; 1st insn not convertible
10411 movi55 ta, imm11 ; LONGJUMP7/INSN16
10412 beq rt, ta, label ; 15_PCREL */
10415 Elf_Internal_Rela
*cond_irel
, *irelend
, *insn_irel
;
10416 int pic_ext_target
= 0;
10417 bfd_signed_vma foff
;
10418 uint32_t insn
, re_insn
= 0;
10422 irelend
= internal_relocs
+ sec
->reloc_count
;
10423 laddr
= irel
->r_offset
;
10425 /* Get the reloc for the address from which the register is
10426 being loaded. This reloc will tell us which function is
10427 actually being called. */
10430 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10431 R_NDS32_15_PCREL_RELA
, irel
->r_addend
);
10432 if (cond_irel
== irelend
)
10434 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP7",
10435 (uint64_t) irel
->r_offset
);
10439 /* Get the value of the symbol referred to by the reloc. */
10440 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
10443 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_8BIT_S1
10444 || foff
>= CONSERVATIVE_8BIT_S1
)
10447 /* Get the first instruction for its size. */
10448 insn
= bfd_getb32 (contents
+ laddr
);
10449 if (insn
& 0x80000000)
10452 /* Get the immediate from movi55. */
10453 imm11
= N16_IMM5S (insn
>> 16);
10457 /* Get the immediate from movi. */
10458 imm11
= N32_IMM20S (insn
);
10461 /* Get the branch instruction. */
10462 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10463 /* Convert instruction to BR3. */
10464 if ((insn
>> 14) & 0x1)
10465 re_insn
= N32_BR3 (BNEC
, N32_RT5 (insn
), imm11
, 0);
10467 re_insn
= N32_BR3 (BEQC
, N32_RT5 (insn
), imm11
, 0);
10469 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10471 /* Set all relocations. */
10472 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10473 R_NDS32_WORD_9_PCREL_RELA
);
10475 /* Clean relocations. */
10476 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10477 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10478 R_NDS32_INSN16
, irel
->r_offset
);
10479 if (insn_irel
!= irelend
)
10483 /* If the first insntruction is 16bit, convert it to nop16. */
10484 insn16
= NDS32_NOP16
;
10485 bfd_putb16 (insn16
, contents
+ laddr
);
10486 insn_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10489 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10497 #define GET_LOADSTORE_RANGE(addend) (((addend) >> 8) & 0x3f)
10499 /* Relax LOADSTORE relocation for nds32_elf_relax_section. */
10502 nds32_elf_relax_loadstore (struct bfd_link_info
*link_info
, bfd
*abfd
,
10503 asection
*sec
, Elf_Internal_Rela
*irel
,
10504 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10505 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10506 Elf_Internal_Shdr
*symtab_hdr
, int load_store_relax
)
10508 int eliminate_sethi
= 0, range_type
;
10510 bfd_vma local_sda
, laddr
;
10511 int seq_len
; /* Original length of instruction sequence. */
10513 Elf_Internal_Rela
*hi_irelfn
= NULL
, *irelend
;
10514 bfd_vma access_addr
= 0;
10515 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
10516 enum elf_nds32_reloc_type checked_types
[] =
10517 { R_NDS32_HI20_RELA
, R_NDS32_GOT_HI20
,
10518 R_NDS32_GOTPC_HI20
, R_NDS32_GOTOFF_HI20
,
10519 R_NDS32_PLTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
,
10520 R_NDS32_TLS_LE_HI20
10523 irelend
= internal_relocs
+ sec
->reloc_count
;
10524 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10525 laddr
= irel
->r_offset
;
10526 *insn_len
= seq_len
;
10528 /* Get the high part relocation. */
10529 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10531 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10532 checked_types
[i
], laddr
);
10533 if (hi_irelfn
!= irelend
)
10537 if (hi_irelfn
== irelend
)
10539 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LOADSTORE",
10540 (uint64_t) irel
->r_offset
);
10544 range_type
= GET_LOADSTORE_RANGE (irel
->r_addend
);
10545 nds32_elf_final_sda_base (sec
->output_section
->owner
,
10546 link_info
, &local_sda
, FALSE
);
10548 switch (ELF32_R_TYPE (hi_irelfn
->r_info
))
10550 case R_NDS32_HI20_RELA
:
10551 insn
= bfd_getb32 (contents
+ laddr
);
10553 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10555 if (range_type
== NDS32_LOADSTORE_IMM
)
10557 struct elf_link_hash_entry
*h
= NULL
;
10560 if (ELF32_R_SYM (hi_irelfn
->r_info
) >= symtab_hdr
->sh_info
)
10562 indx
= ELF32_R_SYM (hi_irelfn
->r_info
) - symtab_hdr
->sh_info
;
10563 h
= elf_sym_hashes (abfd
)[indx
];
10566 if ((access_addr
< CONSERVATIVE_20BIT
)
10567 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
10569 eliminate_sethi
= 1;
10573 /* This is avoid to relax symbol address which is fixed
10574 relocations. Ex: _stack. */
10575 if (h
&& bfd_is_abs_section (h
->root
.u
.def
.section
))
10579 if (!load_store_relax
)
10582 /* Case for set gp register. */
10583 if (N32_RT5 (insn
) == REG_GP
)
10586 if (range_type
== NDS32_LOADSTORE_FLOAT_S
10587 || range_type
== NDS32_LOADSTORE_FLOAT_D
)
10589 range_l
= sdata_range
[0][0];
10590 range_h
= sdata_range
[0][1];
10594 range_l
= sdata_range
[1][0];
10595 range_h
= sdata_range
[1][1];
10599 case R_NDS32_GOT_HI20
:
10601 calculate_got_memory_address (abfd
, link_info
, hi_irelfn
, symtab_hdr
);
10603 /* If this symbol is not in .got, the return value will be -1.
10604 Since the gp value is set to SDA_BASE but not GLOBAL_OFFSET_TABLE,
10605 a negative offset is allowed. */
10606 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10607 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10608 eliminate_sethi
= 1;
10611 case R_NDS32_PLT_GOTREL_HI20
:
10612 access_addr
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
,
10613 hi_irelfn
, symtab_hdr
);
10615 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10616 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10617 eliminate_sethi
= 1;
10620 case R_NDS32_GOTOFF_HI20
:
10622 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10624 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10625 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10626 eliminate_sethi
= 1;
10629 case R_NDS32_GOTPC_HI20
:
10630 /* The access_addr must consider r_addend of hi_irel. */
10631 access_addr
= sec
->output_section
->vma
+ sec
->output_offset
10632 + irel
->r_offset
+ hi_irelfn
->r_addend
;
10634 if ((bfd_signed_vma
) (local_sda
- access_addr
) < CONSERVATIVE_20BIT
10635 && (bfd_signed_vma
) (local_sda
- access_addr
) >= -CONSERVATIVE_20BIT
)
10636 eliminate_sethi
= 1;
10639 case R_NDS32_TLS_LE_HI20
:
10641 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10642 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10643 access_addr
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10644 if ((range_type
== NDS32_LOADSTORE_IMM
)
10645 && (bfd_signed_vma
) (access_addr
) < CONSERVATIVE_20BIT
10646 && (bfd_signed_vma
) (access_addr
) >= -CONSERVATIVE_20BIT
)
10647 eliminate_sethi
= 1;
10654 /* Delete sethi instruction. */
10655 if (eliminate_sethi
== 1
10656 || (local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
10657 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
10659 hi_irelfn
->r_info
=
10660 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
10662 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10668 /* Relax LO12 relocation for nds32_elf_relax_section. */
10671 nds32_elf_relax_lo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10672 asection
*sec
, Elf_Internal_Rela
*irel
,
10673 Elf_Internal_Rela
*internal_relocs
, bfd_byte
*contents
,
10674 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
10677 bfd_vma local_sda
, laddr
;
10678 unsigned long reloc
;
10679 bfd_vma access_addr
;
10680 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
10681 Elf_Internal_Rela
*irelfn
= NULL
, *irelend
;
10682 struct elf_link_hash_entry
*h
= NULL
;
10685 /* For SDA base relative relaxation. */
10686 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
10687 &local_sda
, FALSE
);
10689 irelend
= internal_relocs
+ sec
->reloc_count
;
10690 laddr
= irel
->r_offset
;
10691 insn
= bfd_getb32 (contents
+ laddr
);
10693 if (!is_sda_access_insn (insn
) && N32_OP6 (insn
) != N32_OP6_ORI
)
10696 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10698 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
10700 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
10701 h
= elf_sym_hashes (abfd
)[indx
];
10704 if (N32_OP6 (insn
) == N32_OP6_ORI
&& access_addr
< CONSERVATIVE_20BIT
10705 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
10707 reloc
= R_NDS32_20_RELA
;
10708 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10709 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10710 bfd_putb32 (insn
, contents
+ laddr
);
10712 /* This is avoid to relax symbol address which is fixed
10713 relocations. Ex: _stack. */
10714 else if (N32_OP6 (insn
) == N32_OP6_ORI
10715 && h
&& bfd_is_abs_section (h
->root
.u
.def
.section
))
10719 range_l
= sdata_range
[1][0];
10720 range_h
= sdata_range
[1][1];
10721 switch (ELF32_R_TYPE (irel
->r_info
))
10723 case R_NDS32_LO12S0_RELA
:
10724 reloc
= R_NDS32_SDA19S0_RELA
;
10726 case R_NDS32_LO12S1_RELA
:
10727 reloc
= R_NDS32_SDA18S1_RELA
;
10729 case R_NDS32_LO12S2_RELA
:
10730 reloc
= R_NDS32_SDA17S2_RELA
;
10732 case R_NDS32_LO12S2_DP_RELA
:
10733 range_l
= sdata_range
[0][0];
10734 range_h
= sdata_range
[0][1];
10735 reloc
= R_NDS32_SDA12S2_DP_RELA
;
10737 case R_NDS32_LO12S2_SP_RELA
:
10738 range_l
= sdata_range
[0][0];
10739 range_h
= sdata_range
[0][1];
10740 reloc
= R_NDS32_SDA12S2_SP_RELA
;
10746 /* There are range_h and range_l because linker has to promise
10747 all sections move cross one page together. */
10748 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
10749 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
10751 if (N32_OP6 (insn
) == N32_OP6_ORI
&& N32_RT5 (insn
) == REG_GP
)
10753 /* Maybe we should add R_NDS32_INSN16 reloc type here
10754 or manually do some optimization. sethi can't be
10755 eliminated when updating $gp so the relative ori
10756 needs to be preserved. */
10759 if (!turn_insn_to_sda_access (insn
, ELF32_R_TYPE (irel
->r_info
),
10762 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10763 bfd_putb32 (insn
, contents
+ laddr
);
10765 irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10767 /* SDA17 must keep INSN16 for converting fp_as_gp. */
10768 if (irelfn
!= irelend
&& reloc
!= R_NDS32_SDA17S2_RELA
)
10770 ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_NDS32_NONE
);
10777 /* Relax low part of PIC instruction pattern. */
10780 nds32_elf_relax_piclo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10781 asection
*sec
, Elf_Internal_Rela
*irel
,
10782 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10783 Elf_Internal_Shdr
*symtab_hdr
)
10786 bfd_vma local_sda
, laddr
;
10787 bfd_signed_vma foff
;
10788 unsigned long reloc
;
10790 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
10791 &local_sda
, FALSE
);
10792 laddr
= irel
->r_offset
;
10793 insn
= bfd_getb32 (contents
+ laddr
);
10795 if (N32_OP6 (insn
) != N32_OP6_ORI
)
10798 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
)
10800 foff
= calculate_got_memory_address (abfd
, link_info
, irel
,
10801 symtab_hdr
) - local_sda
;
10802 reloc
= R_NDS32_GOT20
;
10804 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
)
10806 foff
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
, irel
,
10807 symtab_hdr
) - local_sda
;
10808 reloc
= R_NDS32_PLT_GOTREL_LO20
;
10810 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
)
10812 foff
= calculate_memory_address (abfd
, irel
, isymbuf
,
10813 symtab_hdr
) - local_sda
;
10814 reloc
= R_NDS32_GOTOFF
;
10816 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
)
10818 foff
= local_sda
- sec
->output_section
->vma
+ sec
->output_offset
10819 + irel
->r_offset
+ irel
->r_addend
;
10820 reloc
= R_NDS32_GOTPC20
;
10825 if ((foff
< CONSERVATIVE_20BIT
) && (foff
>= -CONSERVATIVE_20BIT
))
10827 /* Turn into MOVI. */
10828 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10829 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10830 bfd_putb32 (insn
, contents
+ laddr
);
10834 /* Relax low part of LE TLS instruction pattern. */
10837 nds32_elf_relax_letlslo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10838 Elf_Internal_Rela
*irel
,
10839 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10840 Elf_Internal_Shdr
*symtab_hdr
)
10844 bfd_signed_vma foff
;
10845 unsigned long reloc
;
10847 laddr
= irel
->r_offset
;
10848 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10849 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10850 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10851 insn
= bfd_getb32 (contents
+ laddr
);
10853 if ( (bfd_signed_vma
) (foff
) < CONSERVATIVE_20BIT
10854 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_20BIT
)
10856 /* Pattern sethi-ori transform to movi. */
10857 reloc
= R_NDS32_TLS_LE_20
;
10858 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10859 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10860 bfd_putb32 (insn
, contents
+ laddr
);
10864 /* Relax LE TLS calculate address instruction pattern. */
10867 nds32_elf_relax_letlsadd (struct bfd_link_info
*link_info
, bfd
*abfd
,
10868 asection
*sec
, Elf_Internal_Rela
*irel
,
10869 Elf_Internal_Rela
*internal_relocs
,
10870 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10871 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
10873 /* Local TLS non-pic
10874 sethi ta, hi20(symbol@tpoff) ; TLS_LE_HI20
10875 ori ta, ta, lo12(symbol@tpoff) ; TLS_LE_LO12
10876 add ra, ta, tp ; TLS_LE_ADD */
10880 bfd_signed_vma foff
;
10881 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
10883 irelend
= internal_relocs
+ sec
->reloc_count
;
10884 laddr
= irel
->r_offset
;
10885 insn
= bfd_getb32 (contents
+ laddr
);
10886 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10887 R_NDS32_PTR_RESOLVED
);
10888 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10889 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10890 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10892 /* The range is +/-16k. */
10893 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT
10894 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT
)
10896 /* Transform add to addi. */
10897 insn
= N32_TYPE2 (ADDI
, N32_RT5 (insn
), N32_RB5 (insn
), 0);
10899 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S0
);
10901 bfd_putb32 (insn
, contents
+ laddr
);
10902 if (i1_irelfn
!= irelend
)
10904 i1_irelfn
->r_addend
|= 1;
10910 /* Relax LE TLS load store instruction pattern. */
10913 nds32_elf_relax_letlsls (struct bfd_link_info
*link_info
, bfd
*abfd
,
10914 asection
*sec
, Elf_Internal_Rela
*irel
,
10915 Elf_Internal_Rela
*internal_relocs
,
10916 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10917 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
10922 bfd_signed_vma foff
;
10923 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
10926 irelend
= internal_relocs
+ sec
->reloc_count
;
10927 laddr
= irel
->r_offset
;
10928 insn
= bfd_getb32 (contents
+ laddr
);
10929 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10930 R_NDS32_PTR_RESOLVED
);
10931 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10932 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10933 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10935 switch ((N32_OP6 (insn
) << 8) | (insn
& 0xff))
10937 case (N32_OP6_MEM
<< 8) | N32_MEM_LB
:
10938 case (N32_OP6_MEM
<< 8) | N32_MEM_SB
:
10939 case (N32_OP6_MEM
<< 8) | N32_MEM_LBS
:
10940 /* The range is +/-16k. */
10941 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT
10942 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT
)
10945 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
10947 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S0
);
10951 /* Fall through. */
10952 case (N32_OP6_MEM
<< 8) | N32_MEM_LH
:
10953 case (N32_OP6_MEM
<< 8) | N32_MEM_SH
:
10954 case (N32_OP6_MEM
<< 8) | N32_MEM_LHS
:
10955 /* The range is +/-32k. */
10956 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT_S1
10957 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT_S1
)
10960 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
10962 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S1
);
10966 /* Fall through. */
10967 case (N32_OP6_MEM
<< 8) | N32_MEM_LW
:
10968 case (N32_OP6_MEM
<< 8) | N32_MEM_SW
:
10969 /* The range is +/-64k. */
10970 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT_S2
10971 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT_S2
)
10974 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
10976 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S2
);
10980 /* Fall through. */
10987 bfd_putb32 (insn
, contents
+ laddr
);
10988 if (i1_irelfn
!= irelend
)
10990 i1_irelfn
->r_addend
|= 1;
10996 /* Relax PTR relocation for nds32_elf_relax_section. */
10999 nds32_elf_relax_ptr (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11000 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11001 int *seq_len
, bfd_byte
*contents
)
11003 Elf_Internal_Rela
*ptr_irel
, *irelend
, *count_irel
, *re_irel
;
11005 irelend
= internal_relocs
+ sec
->reloc_count
;
11008 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11009 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11011 if (re_irel
== irelend
)
11013 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_PTR",
11014 (uint64_t) irel
->r_offset
);
11018 if (re_irel
->r_addend
!= 1)
11021 /* Pointed target is relaxed and no longer needs this void *,
11022 change the type to NONE. */
11023 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11025 /* Find PTR_COUNT to decide remove it or not. If PTR_COUNT does
11026 not exist, it means only count 1 and remove it directly. */
11027 /* TODO: I hope we can obsolate R_NDS32_COUNT in the future. */
11028 count_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11029 R_NDS32_PTR_COUNT
);
11030 ptr_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11032 if (count_irel
!= irelend
)
11034 if (--count_irel
->r_addend
> 0)
11038 if (ptr_irel
!= irelend
)
11041 /* If the PTR_COUNT is already 0, remove current instruction. */
11042 *seq_len
= nds32_elf_insn_size (abfd
, contents
, irel
->r_offset
);
11047 /* Relax PLT_GOT_SUFF relocation for nds32_elf_relax_section. */
11050 nds32_elf_relax_pltgot_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11051 asection
*sec
, Elf_Internal_Rela
*irel
,
11052 Elf_Internal_Rela
*internal_relocs
,
11053 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11054 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11057 bfd_signed_vma foff
;
11058 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
11059 bfd_vma local_sda
, laddr
;
11061 irelend
= internal_relocs
+ sec
->reloc_count
;
11062 laddr
= irel
->r_offset
;
11063 insn
= bfd_getb32 (contents
+ laddr
);
11065 /* FIXME: It's a little trouble to turn JRAL5 to JAL since
11066 we need additional space. It might be help if we could
11067 borrow some space from instructions to be eliminated
11068 such as sethi, ori, add. */
11069 if (insn
& 0x80000000)
11072 if (nds32_elf_check_dup_relocs
11073 (irel
, internal_relocs
, irelend
, R_NDS32_PLT_GOT_SUFF
))
11077 find_relocs_at_address (irel
, internal_relocs
, irelend
,
11078 R_NDS32_PTR_RESOLVED
);
11081 The boundary should be reduced since the .plt section hasn't
11082 been created and the address of specific entry is still unknown
11083 Maybe the range between the function call and the begin of the
11084 .text section can be used to decide if the .plt is in the range
11085 of function call. */
11087 if (N32_OP6 (insn
) == N32_OP6_ALU1
11088 && N32_SUB5 (insn
) == N32_ALU1_ADD
)
11090 /* Get the value of the symbol referred to by the reloc. */
11091 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11092 &local_sda
, FALSE
);
11093 foff
= (bfd_signed_vma
) (calculate_plt_memory_address
11094 (abfd
, link_info
, isymbuf
, irel
,
11095 symtab_hdr
) - local_sda
);
11096 /* This condition only happened when symbol is undefined. */
11100 if (foff
< -CONSERVATIVE_19BIT
|| foff
>= CONSERVATIVE_19BIT
)
11102 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11103 R_NDS32_PLT_GOTREL_LO19
);
11105 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
11107 else if (N32_OP6 (insn
) == N32_OP6_JREG
11108 && N32_SUB5 (insn
) == N32_JREG_JRAL
)
11110 /* Get the value of the symbol referred to by the reloc. */
11112 calculate_plt_offset (abfd
, sec
, link_info
, isymbuf
, irel
, symtab_hdr
);
11113 /* This condition only happened when symbol is undefined. */
11116 if (foff
< -CONSERVATIVE_24BIT_S1
|| foff
>= CONSERVATIVE_24BIT_S1
)
11118 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_25_PLTREL
);
11124 bfd_putb32 (insn
, contents
+ laddr
);
11125 if (i1_irelfn
!= irelend
)
11127 i1_irelfn
->r_addend
|= 1;
11132 /* Relax GOT_SUFF relocation for nds32_elf_relax_section. */
11135 nds32_elf_relax_got_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11136 asection
*sec
, Elf_Internal_Rela
*irel
,
11137 Elf_Internal_Rela
*internal_relocs
,
11138 bfd_byte
*contents
, Elf_Internal_Shdr
*symtab_hdr
,
11139 bfd_boolean
*again
)
11142 bfd_signed_vma foff
;
11143 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
11144 bfd_vma local_sda
, laddr
;
11146 irelend
= internal_relocs
+ sec
->reloc_count
;
11147 laddr
= irel
->r_offset
;
11148 insn
= bfd_getb32 (contents
+ laddr
);
11149 if (insn
& 0x80000000)
11152 if (nds32_elf_check_dup_relocs
11153 (irel
, internal_relocs
, irelend
, R_NDS32_GOT_SUFF
))
11156 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11157 R_NDS32_PTR_RESOLVED
);
11159 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11160 &local_sda
, FALSE
);
11161 foff
= calculate_got_memory_address (abfd
, link_info
, irel
,
11162 symtab_hdr
) - local_sda
;
11164 if (foff
< CONSERVATIVE_19BIT
&& foff
>= -CONSERVATIVE_19BIT
)
11166 /* Turn LW to LWI.GP. Change relocation type to R_NDS32_GOT_REL. */
11167 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
11169 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_GOT17S2_RELA
);
11170 bfd_putb32 (insn
, contents
+ laddr
);
11171 if (i1_irelfn
!= irelend
)
11173 i1_irelfn
->r_addend
|= 1;
11179 /* Relax PLT_GOT_SUFF relocation for nds32_elf_relax_section. */
11182 nds32_elf_relax_gotoff_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11183 asection
*sec
, Elf_Internal_Rela
*irel
,
11184 Elf_Internal_Rela
*internal_relocs
,
11185 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11186 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11188 int opc_insn_gotoff
;
11190 bfd_signed_vma foff
;
11191 Elf_Internal_Rela
*i1_irelfn
, *i2_irelfn
, *irelend
;
11192 bfd_vma local_sda
, laddr
;
11194 irelend
= internal_relocs
+ sec
->reloc_count
;
11195 laddr
= irel
->r_offset
;
11196 insn
= bfd_getb32 (contents
+ laddr
);
11198 if (insn
& 0x80000000)
11201 if (nds32_elf_check_dup_relocs
11202 (irel
, internal_relocs
, irelend
, R_NDS32_GOTOFF_SUFF
))
11205 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11206 R_NDS32_PTR_RESOLVED
);
11207 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11208 &local_sda
, FALSE
);
11209 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11210 foff
= foff
- local_sda
;
11212 if (foff
>= CONSERVATIVE_19BIT
|| foff
< -CONSERVATIVE_19BIT
)
11215 /* Concatenate opcode and sub-opcode for switch case.
11216 It may be MEM or ALU1. */
11217 opc_insn_gotoff
= (N32_OP6 (insn
) << 8) | (insn
& 0xff);
11218 switch (opc_insn_gotoff
)
11220 case (N32_OP6_MEM
<< 8) | N32_MEM_LW
:
11221 /* 4-byte aligned. */
11222 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
11224 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA17S2_RELA
);
11226 case (N32_OP6_MEM
<< 8) | N32_MEM_SW
:
11227 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
11229 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA17S2_RELA
);
11231 case (N32_OP6_MEM
<< 8) | N32_MEM_LH
:
11232 /* 2-byte aligned. */
11233 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
11235 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11237 case (N32_OP6_MEM
<< 8) | N32_MEM_LHS
:
11238 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
11240 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11242 case (N32_OP6_MEM
<< 8) | N32_MEM_SH
:
11243 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
11245 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11247 case (N32_OP6_MEM
<< 8) | N32_MEM_LB
:
11248 /* 1-byte aligned. */
11249 insn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
11251 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11253 case (N32_OP6_MEM
<< 8) | N32_MEM_LBS
:
11254 insn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
11256 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11258 case (N32_OP6_MEM
<< 8) | N32_MEM_SB
:
11259 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
11261 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11263 case (N32_OP6_ALU1
<< 8) | N32_ALU1_ADD
:
11264 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
11266 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11272 bfd_putb32 (insn
, contents
+ laddr
);
11273 if (i1_irelfn
!= irelend
)
11275 i1_irelfn
->r_addend
|= 1;
11278 if ((i2_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11279 R_NDS32_INSN16
)) != irelend
)
11280 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11285 nds32_relax_adjust_label (bfd
*abfd
, asection
*sec
,
11286 Elf_Internal_Rela
*internal_relocs
,
11287 bfd_byte
*contents
,
11288 nds32_elf_blank_t
**relax_blank_list
,
11289 int optimize
, int opt_size
)
11291 /* This code block is used to adjust 4-byte alignment by relax a pair
11292 of instruction a time.
11294 It recognizes three types of relocations.
11295 1. R_NDS32_LABEL - a alignment.
11296 2. R_NDS32_INSN16 - relax a 32-bit instruction to 16-bit.
11297 3. is_16bit_NOP () - remove a 16-bit instruction. */
11299 /* TODO: It seems currently implementation only support 4-byte alignment.
11300 We should handle any-alignment. */
11302 Elf_Internal_Rela
*insn_rel
= NULL
, *label_rel
= NULL
, *irel
;
11303 Elf_Internal_Rela
*tmp_rel
, *tmp2_rel
= NULL
;
11304 Elf_Internal_Rela rel_temp
;
11305 Elf_Internal_Rela
*irelend
;
11309 /* Checking for branch relaxation relies on the relocations to
11310 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
11311 nds32_insertion_sort (internal_relocs
, sec
->reloc_count
,
11312 sizeof (Elf_Internal_Rela
), compar_reloc
);
11314 irelend
= internal_relocs
+ sec
->reloc_count
;
11316 /* Force R_NDS32_LABEL before R_NDS32_INSN16. */
11317 /* FIXME: Can we generate the right order in assembler?
11318 So we don't have to swapping them here. */
11320 for (label_rel
= internal_relocs
, insn_rel
= internal_relocs
;
11321 label_rel
< irelend
; label_rel
++)
11323 if (ELF32_R_TYPE (label_rel
->r_info
) != R_NDS32_LABEL
)
11326 /* Find the first reloc has the same offset with label_rel. */
11327 while (insn_rel
< irelend
&& insn_rel
->r_offset
< label_rel
->r_offset
)
11330 for (;insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
;
11332 /* Check if there were R_NDS32_INSN16 and R_NDS32_LABEL at the same
11334 if (ELF32_R_TYPE (insn_rel
->r_info
) == R_NDS32_INSN16
)
11337 if (insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
11338 && insn_rel
< label_rel
)
11340 /* Swap the two reloc if the R_NDS32_INSN16 is
11341 before R_NDS32_LABEL. */
11342 memcpy (&rel_temp
, insn_rel
, sizeof (Elf_Internal_Rela
));
11343 memcpy (insn_rel
, label_rel
, sizeof (Elf_Internal_Rela
));
11344 memcpy (label_rel
, &rel_temp
, sizeof (Elf_Internal_Rela
));
11350 /* If there were a sequence of R_NDS32_LABEL end up with .align 2
11351 or higher, remove other R_NDS32_LABEL with lower alignment.
11352 If an R_NDS32_INSN16 in between R_NDS32_LABELs must be converted,
11353 then the R_NDS32_LABEL sequence is broke. */
11354 for (tmp_rel
= internal_relocs
; tmp_rel
< irelend
; tmp_rel
++)
11356 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_LABEL
)
11358 if (label_rel
== NULL
)
11360 if (tmp_rel
->r_addend
< 2)
11361 label_rel
= tmp_rel
;
11364 else if (tmp_rel
->r_addend
> 1)
11366 /* Remove all LABEL relocation from label_rel to tmp_rel
11367 including relocations with same offset as tmp_rel. */
11368 for (tmp2_rel
= label_rel
; tmp2_rel
< tmp_rel
11369 || tmp2_rel
->r_offset
== tmp_rel
->r_offset
; tmp2_rel
++)
11371 if (ELF32_R_TYPE (tmp2_rel
->r_info
) == R_NDS32_LABEL
11372 && tmp2_rel
->r_addend
< 2)
11374 ELF32_R_INFO (ELF32_R_SYM (tmp2_rel
->r_info
),
11380 else if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
&& label_rel
)
11382 /* A new INSN16 which can be converted, so clear label_rel. */
11383 if (is_convert_32_to_16 (abfd
, sec
, tmp_rel
, internal_relocs
,
11385 || is_16bit_NOP (abfd
, sec
, tmp_rel
))
11392 /* Optimized for speed and nothing has not been relaxed.
11393 It's time to align labels.
11394 We may convert a 16-bit instruction right before a label to
11395 32-bit, in order to align the label if necessary
11396 all reloc entries has been sorted by r_offset. */
11397 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
11399 if (ELF32_R_TYPE (irel
->r_info
) != R_NDS32_INSN16
11400 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
)
11403 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_INSN16
)
11405 /* A new INSN16 found, resize the old one. */
11406 if (is_convert_32_to_16
11407 (abfd
, sec
, irel
, internal_relocs
, irelend
, &insn16
)
11408 || is_16bit_NOP (abfd
, sec
, irel
))
11412 /* Previous INSN16 reloc exists, reduce its
11414 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
11417 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
11418 internal_relocs
, irelend
, insn16
);
11420 if (!insert_nds32_elf_blank_recalc_total
11421 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11424 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11426 if (!insert_nds32_elf_blank_recalc_total
11427 (relax_blank_list
, insn_rel
->r_offset
, 2))
11431 ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
), R_NDS32_NONE
);
11433 /* Save the new one for later use. */
11437 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11440 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
)
11442 /* Search for label. */
11443 int force_relax
= 0;
11445 /* Label on 16-bit instruction or optimization
11446 needless, just reset this reloc. */
11447 insn16
= bfd_getb16 (contents
+ irel
->r_offset
);
11448 if ((irel
->r_addend
& 0x1f) < 2 && (!optimize
|| (insn16
& 0x8000)))
11451 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11456 irel
->r_offset
- get_nds32_elf_blank_total (relax_blank_list
,
11457 irel
->r_offset
, 1);
11461 /* Check if there is case which can not be aligned. */
11462 if (irel
->r_addend
== 2 && address
& 0x2)
11467 /* Try to align this label. */
11469 if ((irel
->r_addend
& 0x1f) < 2)
11471 /* Check if there is a INSN16 at the same address.
11472 Label_rel always seats before insn_rel after
11475 /* Search for INSN16 at LABEL location. If INSN16 is at
11476 same location and this LABEL alignment is lower than 2,
11477 the INSN16 can be converted to 2-byte. */
11478 for (tmp_rel
= irel
;
11479 tmp_rel
< irelend
&& tmp_rel
->r_offset
== irel
->r_offset
;
11482 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
11483 && (is_convert_32_to_16
11484 (abfd
, sec
, tmp_rel
, internal_relocs
,
11486 || is_16bit_NOP (abfd
, sec
, tmp_rel
)))
11494 if (force_relax
|| irel
->r_addend
== 1 || address
& 0x2)
11496 /* Label not aligned. */
11497 /* Previous reloc exists, reduce its size to 16-bit. */
11498 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
,
11499 internal_relocs
, irelend
, &insn16
))
11501 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
11502 internal_relocs
, irelend
, insn16
);
11504 if (!insert_nds32_elf_blank_recalc_total
11505 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11508 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11510 if (!insert_nds32_elf_blank_recalc_total
11511 (relax_blank_list
, insn_rel
->r_offset
, 2))
11516 /* INSN16 reloc is used. */
11522 sec
->size
- get_nds32_elf_blank_total (relax_blank_list
, sec
->size
, 0);
11523 if (insn_rel
&& (address
& 0x2 || opt_size
))
11525 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
11528 nds32_elf_write_16 (abfd
, contents
, insn_rel
, internal_relocs
,
11530 if (!insert_nds32_elf_blank_recalc_total
11531 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11533 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
11536 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11538 if (!insert_nds32_elf_blank_recalc_total
11539 (relax_blank_list
, insn_rel
->r_offset
, 2))
11541 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
11550 nds32_elf_relax_section (bfd
*abfd
, asection
*sec
,
11551 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
11553 nds32_elf_blank_t
*relax_blank_list
= NULL
;
11554 Elf_Internal_Shdr
*symtab_hdr
;
11555 Elf_Internal_Rela
*internal_relocs
;
11556 Elf_Internal_Rela
*irel
;
11557 Elf_Internal_Rela
*irelend
;
11558 Elf_Internal_Sym
*isymbuf
= NULL
;
11559 bfd_byte
*contents
= NULL
;
11560 bfd_boolean result
= TRUE
;
11566 /* Target dependnet option. */
11567 struct elf_nds32_link_hash_table
*table
;
11568 int load_store_relax
;
11570 relax_blank_list
= NULL
;
11574 /* Nothing to do for
11575 * relocatable link or
11576 * non-relocatable section or
11577 * non-code section or
11579 * no reloc entry. */
11580 if (bfd_link_relocatable (link_info
)
11581 || (sec
->flags
& SEC_RELOC
) == 0
11582 || (sec
->flags
& SEC_EXCLUDE
) != 0
11583 || (sec
->flags
& SEC_CODE
) == 0
11587 /* 09.12.11 Workaround. */
11588 /* We have to adjust align for R_NDS32_LABEL if needed.
11589 The adjust approach only can fix 2-byte align once. */
11590 if (sec
->alignment_power
> 2)
11593 /* The optimization type to do. */
11595 table
= nds32_elf_hash_table (link_info
);
11597 /* The begining of general relaxation. */
11599 if (is_SDA_BASE_set
== 0)
11602 is_SDA_BASE_set
= 1;
11603 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11605 relax_range_measurement (abfd
);
11608 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11609 /* Relocations MUST be kept in memory, because relaxation adjust them. */
11610 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
11611 TRUE
/* keep_memory */);
11612 if (internal_relocs
== NULL
)
11615 irelend
= internal_relocs
+ sec
->reloc_count
;
11616 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
11617 irelend
, R_NDS32_RELAX_ENTRY
);
11619 if (irel
== irelend
)
11622 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
11624 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
)
11627 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG
)
11630 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG
)
11634 load_store_relax
= table
->load_store_relax
;
11636 /* Get symbol table and section content. */
11637 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
11638 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
11641 /* Do relax loop only when finalize is not done.
11642 Take care of relaxable relocs except INSN16. */
11643 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
11645 int seq_len
; /* Original length of instruction sequence. */
11646 int insn_len
= 0; /* Final length of instruction sequence. */
11647 bfd_boolean removed
;
11650 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
11651 && (irel
->r_addend
& 0x1f) >= 2)
11654 /* Relocation Types
11655 R_NDS32_LONGCALL1 53
11656 R_NDS32_LONGCALL2 54
11657 R_NDS32_LONGCALL3 55
11658 R_NDS32_LONGJUMP1 56
11659 R_NDS32_LONGJUMP2 57
11660 R_NDS32_LONGJUMP3 58
11661 R_NDS32_LOADSTORE 59 */
11662 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL1
11663 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LOADSTORE
)
11664 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
11666 /* Relocation Types
11667 R_NDS32_LONGCALL4 107
11668 R_NDS32_LONGCALL5 108
11669 R_NDS32_LONGCALL6 109
11670 R_NDS32_LONGJUMP4 110
11671 R_NDS32_LONGJUMP5 111
11672 R_NDS32_LONGJUMP6 112
11673 R_NDS32_LONGJUMP7 113 */
11674 else if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL4
11675 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LONGJUMP7
)
11678 /* Relocation Types
11679 R_NDS32_LO12S0_RELA 30
11680 R_NDS32_LO12S1_RELA 29
11681 R_NDS32_LO12S2_RELA 28
11682 R_NDS32_LO12S2_SP_RELA 71
11683 R_NDS32_LO12S2_DP_RELA 70
11684 R_NDS32_GOT_LO12 46
11685 R_NDS32_GOTOFF_LO12 50
11686 R_NDS32_PLTREL_LO12 65
11687 R_NDS32_PLT_GOTREL_LO12 67
11688 R_NDS32_17IFC_PCREL_RELA 96
11689 R_NDS32_GOT_SUFF 193
11690 R_NDS32_GOTOFF_SUFF 194
11691 R_NDS32_PLT_GOT_SUFF 195
11692 R_NDS32_MULCALL_SUFF 196
11694 else if ((ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LO12S0_RELA
11695 && ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LO12S2_RELA
)
11696 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_SP_RELA
11697 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_DP_RELA
11698 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
11699 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
11700 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
11701 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLTREL_LO12
11702 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
11703 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_GOT_SUFF
11704 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_PTR
)
11705 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
11706 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LO12
11707 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_ADD
11708 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LS
)
11713 insn_len
= seq_len
;
11716 switch (ELF32_R_TYPE (irel
->r_info
))
11718 case R_NDS32_LONGCALL1
:
11719 removed
= nds32_elf_relax_longcall1 (abfd
, sec
, irel
, internal_relocs
,
11720 &insn_len
, contents
, isymbuf
,
11723 case R_NDS32_LONGCALL2
:
11724 removed
= nds32_elf_relax_longcall2 (abfd
, sec
, irel
, internal_relocs
,
11725 &insn_len
, contents
, isymbuf
,
11728 case R_NDS32_LONGCALL3
:
11729 removed
= nds32_elf_relax_longcall3 (abfd
, sec
, irel
, internal_relocs
,
11730 &insn_len
, contents
, isymbuf
,
11733 case R_NDS32_LONGJUMP1
:
11734 removed
= nds32_elf_relax_longjump1 (abfd
, sec
, irel
, internal_relocs
,
11735 &insn_len
, contents
, isymbuf
,
11738 case R_NDS32_LONGJUMP2
:
11739 removed
= nds32_elf_relax_longjump2 (abfd
, sec
, irel
, internal_relocs
,
11740 &insn_len
, contents
, isymbuf
,
11743 case R_NDS32_LONGJUMP3
:
11744 removed
= nds32_elf_relax_longjump3 (abfd
, sec
, irel
, internal_relocs
,
11745 &insn_len
, contents
, isymbuf
,
11748 case R_NDS32_LONGCALL4
:
11749 removed
= nds32_elf_relax_longcall4 (abfd
, sec
, irel
, internal_relocs
,
11750 &insn_len
, contents
, isymbuf
,
11753 case R_NDS32_LONGCALL5
:
11754 removed
= nds32_elf_relax_longcall5 (abfd
, sec
, irel
, internal_relocs
,
11755 &insn_len
, contents
, isymbuf
,
11758 case R_NDS32_LONGCALL6
:
11759 removed
= nds32_elf_relax_longcall6 (abfd
, sec
, irel
, internal_relocs
,
11760 &insn_len
, contents
, isymbuf
,
11763 case R_NDS32_LONGJUMP4
:
11764 removed
= nds32_elf_relax_longjump4 (abfd
, sec
, irel
, internal_relocs
,
11765 &insn_len
, contents
, isymbuf
,
11768 case R_NDS32_LONGJUMP5
:
11769 removed
= nds32_elf_relax_longjump5 (abfd
, sec
, irel
, internal_relocs
,
11770 &insn_len
, &seq_len
, contents
,
11771 isymbuf
, symtab_hdr
);
11773 case R_NDS32_LONGJUMP6
:
11774 removed
= nds32_elf_relax_longjump6 (abfd
, sec
, irel
, internal_relocs
,
11775 &insn_len
, &seq_len
, contents
,
11776 isymbuf
, symtab_hdr
);
11778 case R_NDS32_LONGJUMP7
:
11779 removed
= nds32_elf_relax_longjump7 (abfd
, sec
, irel
, internal_relocs
,
11780 &insn_len
, &seq_len
, contents
,
11781 isymbuf
, symtab_hdr
);
11783 case R_NDS32_LOADSTORE
:
11784 removed
= nds32_elf_relax_loadstore (link_info
, abfd
, sec
, irel
,
11785 internal_relocs
, &insn_len
,
11786 contents
, isymbuf
, symtab_hdr
,
11789 case R_NDS32_LO12S0_RELA
:
11790 case R_NDS32_LO12S1_RELA
:
11791 case R_NDS32_LO12S2_DP_RELA
:
11792 case R_NDS32_LO12S2_SP_RELA
:
11793 case R_NDS32_LO12S2_RELA
:
11794 /* Relax for low part. */
11795 nds32_elf_relax_lo12 (link_info
, abfd
, sec
, irel
, internal_relocs
,
11796 contents
, isymbuf
, symtab_hdr
);
11798 /* It is impossible to delete blank, so just continue. */
11800 case R_NDS32_GOT_LO12
:
11801 case R_NDS32_GOTOFF_LO12
:
11802 case R_NDS32_PLTREL_LO12
:
11803 case R_NDS32_PLT_GOTREL_LO12
:
11804 case R_NDS32_GOTPC_LO12
:
11805 /* Relax for PIC gp-relative low part. */
11806 nds32_elf_relax_piclo12 (link_info
, abfd
, sec
, irel
, contents
,
11807 isymbuf
, symtab_hdr
);
11809 /* It is impossible to delete blank, so just continue. */
11811 case R_NDS32_TLS_LE_LO12
:
11812 /* Relax for LE TLS low part. */
11813 nds32_elf_relax_letlslo12 (link_info
, abfd
, irel
, contents
,
11814 isymbuf
, symtab_hdr
);
11816 /* It is impossible to delete blank, so just continue. */
11818 case R_NDS32_TLS_LE_ADD
:
11819 nds32_elf_relax_letlsadd (link_info
, abfd
, sec
, irel
, internal_relocs
,
11820 contents
, isymbuf
, symtab_hdr
, again
);
11821 /* It is impossible to delete blank, so just continue. */
11823 case R_NDS32_TLS_LE_LS
:
11824 nds32_elf_relax_letlsls (link_info
, abfd
, sec
, irel
, internal_relocs
,
11825 contents
, isymbuf
, symtab_hdr
, again
);
11828 removed
= nds32_elf_relax_ptr (abfd
, sec
, irel
, internal_relocs
,
11829 &insn_len
, &seq_len
, contents
);
11831 case R_NDS32_PLT_GOT_SUFF
:
11832 nds32_elf_relax_pltgot_suff (link_info
, abfd
, sec
, irel
,
11833 internal_relocs
, contents
,
11834 isymbuf
, symtab_hdr
, again
);
11835 /* It is impossible to delete blank, so just continue. */
11837 case R_NDS32_GOT_SUFF
:
11838 nds32_elf_relax_got_suff (link_info
, abfd
, sec
, irel
,
11839 internal_relocs
, contents
,
11840 symtab_hdr
, again
);
11841 /* It is impossible to delete blank, so just continue. */
11843 case R_NDS32_GOTOFF_SUFF
:
11844 nds32_elf_relax_gotoff_suff (link_info
, abfd
, sec
, irel
,
11845 internal_relocs
, contents
,
11846 isymbuf
, symtab_hdr
, again
);
11847 /* It is impossible to delete blank, so just continue. */
11853 if (removed
&& seq_len
- insn_len
> 0)
11855 if (!insert_nds32_elf_blank
11856 (&relax_blank_list
, irel
->r_offset
+ insn_len
,
11857 seq_len
- insn_len
))
11863 calc_nds32_blank_total (relax_blank_list
);
11865 if (table
->relax_fp_as_gp
)
11867 if (!nds32_relax_fp_as_gp (link_info
, abfd
, sec
, internal_relocs
,
11873 if (!nds32_fag_remove_unused_fpbase (abfd
, sec
, internal_relocs
,
11881 if (!nds32_relax_adjust_label (abfd
, sec
, internal_relocs
, contents
,
11882 &relax_blank_list
, optimize
, opt_size
))
11886 /* It doesn't matter optimize_for_space_no_align anymore.
11887 If object file is assembled with flag '-Os',
11888 the we don't adjust jump-destination on 4-byte boundary. */
11890 if (relax_blank_list
)
11892 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
11893 relax_blank_list
= NULL
;
11898 /* Closing the section, so we don't relax it anymore. */
11899 bfd_vma sec_size_align
;
11900 Elf_Internal_Rela
*tmp_rel
;
11902 /* Pad to alignment boundary. Only handle current section alignment. */
11903 sec_size_align
= (sec
->size
+ (~((-1U) << sec
->alignment_power
)))
11904 & ((-1U) << sec
->alignment_power
);
11905 if ((sec_size_align
- sec
->size
) & 0x2)
11907 insn16
= NDS32_NOP16
;
11908 bfd_putb16 (insn16
, contents
+ sec
->size
);
11912 while (sec_size_align
!= sec
->size
)
11914 insn
= NDS32_NOP32
;
11915 bfd_putb32 (insn
, contents
+ sec
->size
);
11919 tmp_rel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
11920 irelend
, R_NDS32_RELAX_ENTRY
);
11921 if (tmp_rel
!= irelend
)
11922 tmp_rel
->r_addend
|= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
;
11924 clean_nds32_elf_blank ();
11928 if (internal_relocs
!= NULL
11929 && elf_section_data (sec
)->relocs
!= internal_relocs
)
11930 free (internal_relocs
);
11932 if (contents
!= NULL
11933 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
11936 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) isymbuf
)
11946 static struct bfd_elf_special_section
const nds32_elf_special_sections
[] =
11948 {".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
11949 {".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
11954 nds32_elf_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
11955 struct bfd_link_info
*info
,
11956 void *finfo ATTRIBUTE_UNUSED
,
11957 bfd_boolean (*func
) (void *, const char *,
11958 Elf_Internal_Sym
*,
11960 struct elf_link_hash_entry
*)
11963 FILE *sym_ld_script
= NULL
;
11964 struct elf_nds32_link_hash_table
*table
;
11966 table
= nds32_elf_hash_table (info
);
11967 sym_ld_script
= table
->sym_ld_script
;
11969 if (check_start_export_sym
)
11970 fprintf (sym_ld_script
, "}\n");
11975 static enum elf_reloc_type_class
11976 nds32_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
11977 const asection
*rel_sec ATTRIBUTE_UNUSED
,
11978 const Elf_Internal_Rela
*rela
)
11980 switch ((int) ELF32_R_TYPE (rela
->r_info
))
11982 case R_NDS32_RELATIVE
:
11983 return reloc_class_relative
;
11984 case R_NDS32_JMP_SLOT
:
11985 return reloc_class_plt
;
11987 return reloc_class_copy
;
11989 return reloc_class_normal
;
11993 /* Put target dependent option into info hash table. */
11995 bfd_elf32_nds32_set_target_option (struct bfd_link_info
*link_info
,
11996 int relax_fp_as_gp
,
11997 int eliminate_gc_relocs
,
11998 FILE * sym_ld_script
, int load_store_relax
,
11999 int target_optimize
, int relax_status
,
12000 int relax_round
, FILE * ex9_export_file
,
12001 FILE * ex9_import_file
,
12002 int update_ex9_table
, int ex9_limit
,
12003 bfd_boolean ex9_loop_aware
,
12004 bfd_boolean ifc_loop_aware
)
12006 struct elf_nds32_link_hash_table
*table
;
12008 table
= nds32_elf_hash_table (link_info
);
12012 table
->relax_fp_as_gp
= relax_fp_as_gp
;
12013 table
->eliminate_gc_relocs
= eliminate_gc_relocs
;
12014 table
->sym_ld_script
= sym_ld_script
;
12015 table
->load_store_relax
= load_store_relax
;
12016 table
->target_optimize
= target_optimize
;
12017 table
->relax_status
= relax_status
;
12018 table
->relax_round
= relax_round
;
12019 table
->ex9_export_file
= ex9_export_file
;
12020 table
->ex9_import_file
= ex9_import_file
;
12021 table
->update_ex9_table
= update_ex9_table
;
12022 table
->ex9_limit
= ex9_limit
;
12023 table
->ex9_loop_aware
= ex9_loop_aware
;
12024 table
->ifc_loop_aware
= ifc_loop_aware
;
12027 /* These functions and data-structures are used for fp-as-gp
12030 #define FAG_THRESHOLD 3 /* At least 3 gp-access. */
12031 /* lwi37.fp covers 508 bytes, but there may be 32-byte padding between
12032 the read-only section and read-write section. */
12033 #define FAG_WINDOW (508 - 32)
12035 /* An nds32_fag represent a gp-relative access.
12036 We find best fp-base by using a sliding window
12037 to find a base address which can cover most gp-access. */
12040 struct nds32_fag
*next
; /* NULL-teminated linked list. */
12041 bfd_vma addr
; /* The address of this fag. */
12042 Elf_Internal_Rela
**relas
; /* The relocations associated with this fag.
12043 It is used for applying FP7U2_FLAG. */
12044 int count
; /* How many times this address is referred.
12045 There should be exactly `count' relocations
12047 int relas_capcity
; /* The buffer size of relas.
12048 We use an array instead of linked-list,
12049 and realloc is used to adjust buffer size. */
12053 nds32_fag_init (struct nds32_fag
*head
)
12055 memset (head
, 0, sizeof (struct nds32_fag
));
12059 nds32_fag_verify (struct nds32_fag
*head
)
12061 struct nds32_fag
*iter
;
12062 struct nds32_fag
*prev
;
12068 if (prev
&& prev
->addr
>= iter
->addr
)
12069 puts ("Bug in fp-as-gp insertion.");
12075 /* Insert a fag in ascending order.
12076 If a fag of the same address already exists,
12077 they are chained by relas array. */
12080 nds32_fag_insert (struct nds32_fag
*head
, bfd_vma addr
,
12081 Elf_Internal_Rela
* rel
)
12083 struct nds32_fag
*iter
;
12084 struct nds32_fag
*new_fag
;
12085 const int INIT_RELAS_CAP
= 4;
12088 iter
->next
&& iter
->next
->addr
<= addr
;
12090 /* Find somewhere to insert. */ ;
12092 /* `iter' will be equal to `head' if the list is empty. */
12093 if (iter
!= head
&& iter
->addr
== addr
)
12095 /* The address exists in the list.
12096 Insert `rel' into relocation list, relas. */
12098 /* Check whether relas is big enough. */
12099 if (iter
->count
>= iter
->relas_capcity
)
12101 iter
->relas_capcity
*= 2;
12102 iter
->relas
= bfd_realloc
12103 (iter
->relas
, iter
->relas_capcity
* sizeof (void *));
12105 iter
->relas
[iter
->count
++] = rel
;
12109 /* This is a new address. Create a fag node for it. */
12110 new_fag
= bfd_malloc (sizeof (struct nds32_fag
));
12111 memset (new_fag
, 0, sizeof (*new_fag
));
12112 new_fag
->addr
= addr
;
12113 new_fag
->count
= 1;
12114 new_fag
->next
= iter
->next
;
12115 new_fag
->relas_capcity
= INIT_RELAS_CAP
;
12116 new_fag
->relas
= (Elf_Internal_Rela
**)
12117 bfd_malloc (new_fag
->relas_capcity
* sizeof (void *));
12118 new_fag
->relas
[0] = rel
;
12119 iter
->next
= new_fag
;
12121 nds32_fag_verify (head
);
12125 nds32_fag_free_list (struct nds32_fag
*head
)
12127 struct nds32_fag
*iter
;
12132 struct nds32_fag
*tmp
= iter
;
12140 /* Find the best fp-base address.
12141 The relocation associated with that address is returned,
12142 so we can track the symbol instead of a fixed address.
12144 When relaxation, the address of an datum may change,
12145 because a text section is shrinked, so the data section
12146 moves forward. If the aligments of text and data section
12147 are different, their distance may change too.
12148 Therefore, tracking a fixed address is not appriate. */
12151 nds32_fag_find_base (struct nds32_fag
*head
, struct nds32_fag
**bestpp
)
12153 struct nds32_fag
*base
; /* First fag in the window. */
12154 struct nds32_fag
*last
; /* First fag outside the window. */
12155 int accu
= 0; /* Usage accumulation. */
12156 struct nds32_fag
*best
; /* Best fag. */
12157 int baccu
= 0; /* Best accumulation. */
12159 /* Use first fag for initial, and find the last fag in the window.
12161 In each iteration, we could simply subtract previous fag
12162 and accumulate following fags which are inside the window,
12163 untill we each the end. */
12165 if (head
->next
== NULL
)
12171 /* Initialize base. */
12175 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12177 accu
+= last
->count
;
12181 /* Record the best base in each iteration. */
12184 accu
-= base
->count
;
12186 /* Account fags in window. */
12187 for (/* Nothing. */;
12188 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12190 accu
+= last
->count
;
12192 /* A better fp-base? */
12205 /* Apply R_NDS32_INSN16_FP7U2_FLAG on gp-relative accesses,
12206 so we can convert it fo fp-relative access later.
12207 `best_fag' is the best fp-base. Only those inside the window
12208 of best_fag is applied the flag. */
12211 nds32_fag_mark_relax (struct bfd_link_info
*link_info
,
12212 bfd
*abfd
, struct nds32_fag
*best_fag
,
12213 Elf_Internal_Rela
*internal_relocs
,
12214 Elf_Internal_Rela
*irelend
)
12216 struct nds32_fag
*ifag
;
12217 bfd_vma best_fpbase
, gp
;
12220 output_bfd
= abfd
->sections
->output_section
->owner
;
12221 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
12222 best_fpbase
= best_fag
->addr
;
12224 if (best_fpbase
> gp
+ sdata_range
[1][1]
12225 || best_fpbase
< gp
- sdata_range
[1][0])
12228 /* Mark these inside the window R_NDS32_INSN16_FP7U2_FLAG flag,
12229 so we know they can be converted to lwi37.fp. */
12230 for (ifag
= best_fag
;
12231 ifag
&& ifag
->addr
< best_fpbase
+ FAG_WINDOW
; ifag
= ifag
->next
)
12235 for (i
= 0; i
< ifag
->count
; i
++)
12237 Elf_Internal_Rela
*insn16_rel
;
12238 Elf_Internal_Rela
*fag_rel
;
12240 fag_rel
= ifag
->relas
[i
];
12242 /* Only if this is within the WINDOWS, FP7U2_FLAG
12245 insn16_rel
= find_relocs_at_address
12246 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12248 if (insn16_rel
!= irelend
)
12249 insn16_rel
->r_addend
= R_NDS32_INSN16_FP7U2_FLAG
;
12255 /* Reset INSN16 to clean fp as gp. */
12258 nds32_fag_unmark_relax (struct nds32_fag
*fag
,
12259 Elf_Internal_Rela
*internal_relocs
,
12260 Elf_Internal_Rela
*irelend
)
12262 struct nds32_fag
*ifag
;
12264 Elf_Internal_Rela
*insn16_rel
;
12265 Elf_Internal_Rela
*fag_rel
;
12267 for (ifag
= fag
; ifag
; ifag
= ifag
->next
)
12269 for (i
= 0; i
< ifag
->count
; i
++)
12271 fag_rel
= ifag
->relas
[i
];
12273 /* Restore the INSN16 relocation. */
12274 insn16_rel
= find_relocs_at_address
12275 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12277 if (insn16_rel
!= irelend
)
12278 insn16_rel
->r_addend
&= ~R_NDS32_INSN16_FP7U2_FLAG
;
12283 /* This is the main function of fp-as-gp optimization.
12284 It should be called by relax_section. */
12287 nds32_relax_fp_as_gp (struct bfd_link_info
*link_info
,
12288 bfd
*abfd
, asection
*sec
,
12289 Elf_Internal_Rela
*internal_relocs
,
12290 Elf_Internal_Rela
*irelend
,
12291 Elf_Internal_Sym
*isymbuf
)
12293 Elf_Internal_Rela
*begin_rel
= NULL
;
12294 Elf_Internal_Rela
*irel
;
12295 struct nds32_fag fag_head
;
12296 Elf_Internal_Shdr
*symtab_hdr
;
12297 bfd_byte
*contents
;
12298 bfd_boolean ifc_inside
= FALSE
;
12300 /* FIXME: Can we bfd_elf_link_read_relocs for the relocs? */
12302 /* Per-function fp-base selection.
12303 1. Create a list for all the gp-relative access.
12304 2. Base on those gp-relative address,
12305 find a fp-base which can cover most access.
12306 3. Use the fp-base for fp-as-gp relaxation.
12308 NOTE: If fp-as-gp is not worth to do, (e.g., less than 3 times),
12310 1. delete the `la $fp, _FP_BASE_' instruction and
12311 2. not convert lwi.gp to lwi37.fp.
12313 To delete the _FP_BASE_ instruction, we simply apply
12314 R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG flag in the r_addend to disable it.
12316 To suppress the conversion, we simply NOT to apply
12317 R_NDS32_INSN16_FP7U2_FLAG flag. */
12319 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12321 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12322 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12325 /* Check whether it is worth for fp-as-gp optimization,
12326 i.e., at least 3 gp-load.
12328 Set R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG if we should NOT
12329 apply this optimization. */
12331 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12333 /* We recognize R_NDS32_RELAX_REGION_BEGIN/_END for the region.
12334 One we enter the begin of the region, we track all the LW/ST
12335 instructions, so when we leave the region, we try to find
12336 the best fp-base address for those LW/ST instructions. */
12338 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12339 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12341 /* Begin of the region. */
12343 /* xgettext:c-format */
12344 _bfd_error_handler (_("%pB: nested OMIT_FP in %pA"), abfd
, sec
);
12347 nds32_fag_init (&fag_head
);
12348 ifc_inside
= FALSE
;
12350 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12351 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12354 struct nds32_fag
*best_fag
, *tmp_fag
;
12357 /* End of the region.
12358 Check whether it is worth to do fp-as-gp. */
12360 if (begin_rel
== NULL
)
12362 /* xgettext:c-format */
12363 _bfd_error_handler (_("%pB: unmatched OMIT_FP in %pA"),
12368 accu
= nds32_fag_find_base (&fag_head
, &best_fag
);
12370 /* Clean FP7U2_FLAG because they may set ever. */
12371 tmp_fag
= fag_head
.next
;
12372 nds32_fag_unmark_relax (tmp_fag
, internal_relocs
, irelend
);
12374 /* Check if it is worth, and FP_BASE is near enough to SDA_BASE. */
12375 if (accu
< FAG_THRESHOLD
12376 || !nds32_fag_mark_relax (link_info
, abfd
, best_fag
,
12377 internal_relocs
, irelend
))
12379 /* Not worth to do fp-as-gp. */
12380 begin_rel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
12381 begin_rel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
12382 irel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
12383 irel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
12384 nds32_fag_free_list (&fag_head
);
12389 /* R_SYM of R_NDS32_RELAX_REGION_BEGIN is not used by assembler,
12390 so we use it to record the distance to the reloction of best
12392 dist
= best_fag
->relas
[0] - begin_rel
;
12393 BFD_ASSERT (dist
> 0 && dist
< 0xffffff);
12394 /* Use high 16 bits of addend to record the _FP_BASE_ matched
12395 relocation. And get the base value when relocating. */
12396 begin_rel
->r_addend
&= (0x1 << 16) - 1;
12397 begin_rel
->r_addend
|= dist
<< 16;
12399 nds32_fag_free_list (&fag_head
);
12403 if (begin_rel
== NULL
|| ifc_inside
)
12404 /* Skip if we are not in the region of fp-as-gp. */
12407 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S2_RELA
12408 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA17S2_RELA
)
12413 /* A gp-relative access is found. Insert it to the fag-list. */
12415 /* Rt is necessary an RT3, so it can be converted to lwi37.fp. */
12416 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12417 if (!N32_IS_RT3 (insn
))
12420 addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
12421 nds32_fag_insert (&fag_head
, addr
, irel
);
12423 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA_FP7U2_RELA
)
12427 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
12428 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
12430 /* Suppress fp as gp when encounter ifc. */
12438 /* Remove unused `la $fp, _FD_BASE_' instruction. */
12441 nds32_fag_remove_unused_fpbase (bfd
*abfd
, asection
*sec
,
12442 Elf_Internal_Rela
*internal_relocs
,
12443 Elf_Internal_Rela
*irelend
)
12445 Elf_Internal_Rela
*irel
;
12446 Elf_Internal_Shdr
*symtab_hdr
;
12447 bfd_byte
*contents
= NULL
;
12448 nds32_elf_blank_t
*relax_blank_list
= NULL
;
12449 bfd_boolean result
= TRUE
;
12450 bfd_boolean unused_region
= FALSE
;
12453 NOTE: Disable fp-as-gp if we encounter ifcall relocations.
12454 * R_NDS32_17IFC_PCREL_RELA
12455 * R_NDS32_10IFCU_PCREL_RELA
12460 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12461 nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
);
12463 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12465 /* To remove unused fp-base, we simply find the REGION_NOT_OMIT_FP
12466 we marked to in previous pass.
12467 DO NOT scan relocations again, since we've alreadly decided it
12468 and set the flag. */
12469 const char *syname
;
12473 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12474 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
12475 unused_region
= TRUE
;
12476 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12477 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
12478 unused_region
= FALSE
;
12480 /* We're not in the region. */
12481 if (!unused_region
)
12484 /* _FP_BASE_ must be a GLOBAL symbol. */
12485 syndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
12486 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
12489 /* The symbol name must be _FP_BASE_. */
12490 syname
= elf_sym_hashes (abfd
)[syndx
]->root
.root
.string
;
12491 if (strcmp (syname
, FP_BASE_NAME
) != 0)
12494 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA19S0_RELA
)
12496 /* addi.gp $fp, -256 */
12497 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12498 if (insn
!= INSN_ADDIGP_TO_FP
)
12501 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S0_RELA
)
12503 /* addi $fp, $gp, -256 */
12504 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12505 if (insn
!= INSN_ADDI_GP_TO_FP
)
12508 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_20_RELA
)
12510 /* movi $fp, FP_BASE */
12511 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12512 if (insn
!= INSN_MOVI_TO_FP
)
12518 /* We got here because a FP_BASE instruction is found. */
12519 if (!insert_nds32_elf_blank_recalc_total
12520 (&relax_blank_list
, irel
->r_offset
, 4))
12525 if (relax_blank_list
)
12527 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
12528 relax_blank_list
= NULL
;
12537 /* This is a version of bfd_generic_get_relocated_section_contents.
12538 We need this variety because relaxation will modify the dwarf
12539 infomation. When there is undefined symbol reference error mesage,
12540 linker need to dump line number where the symbol be used. However
12541 the address is be relaxed, it can not get the original dwarf contents.
12542 The variety only modify function call for reading in the section. */
12545 nds32_elf_get_relocated_section_contents (bfd
*abfd
,
12546 struct bfd_link_info
*link_info
,
12547 struct bfd_link_order
*link_order
,
12549 bfd_boolean relocatable
,
12552 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
12553 asection
*input_section
= link_order
->u
.indirect
.section
;
12555 arelent
**reloc_vector
;
12558 reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
12559 if (reloc_size
< 0)
12562 /* Read in the section. */
12563 if (!nds32_get_section_contents (input_bfd
, input_section
, &data
, FALSE
))
12566 if (reloc_size
== 0)
12569 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
12570 if (reloc_vector
== NULL
)
12573 reloc_count
= bfd_canonicalize_reloc (input_bfd
, input_section
,
12574 reloc_vector
, symbols
);
12575 if (reloc_count
< 0)
12578 if (reloc_count
> 0)
12581 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
12583 char *error_message
= NULL
;
12585 bfd_reloc_status_type r
;
12587 symbol
= *(*parent
)->sym_ptr_ptr
;
12588 if (symbol
->section
&& discarded_section (symbol
->section
))
12591 static reloc_howto_type none_howto
12592 = HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, NULL
,
12593 "unused", FALSE
, 0, 0, FALSE
);
12595 p
= data
+ (*parent
)->address
* bfd_octets_per_byte (input_bfd
);
12596 _bfd_clear_contents ((*parent
)->howto
, input_bfd
, input_section
,
12598 (*parent
)->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
12599 (*parent
)->addend
= 0;
12600 (*parent
)->howto
= &none_howto
;
12604 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
12606 relocatable
? abfd
: NULL
,
12611 asection
*os
= input_section
->output_section
;
12613 /* A partial link, so keep the relocs. */
12614 os
->orelocation
[os
->reloc_count
] = *parent
;
12618 if (r
!= bfd_reloc_ok
)
12622 case bfd_reloc_undefined
:
12623 (*link_info
->callbacks
->undefined_symbol
)
12624 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12625 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
12627 case bfd_reloc_dangerous
:
12628 BFD_ASSERT (error_message
!= NULL
);
12629 (*link_info
->callbacks
->reloc_dangerous
)
12630 (link_info
, error_message
,
12631 input_bfd
, input_section
, (*parent
)->address
);
12633 case bfd_reloc_overflow
:
12634 (*link_info
->callbacks
->reloc_overflow
)
12636 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12637 (*parent
)->howto
->name
, (*parent
)->addend
,
12638 input_bfd
, input_section
, (*parent
)->address
);
12640 case bfd_reloc_outofrange
:
12642 This error can result when processing some partially
12643 complete binaries. Do not abort, but issue an error
12644 message instead. */
12645 link_info
->callbacks
->einfo
12646 /* xgettext:c-format */
12647 (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
12648 abfd
, input_section
, * parent
);
12659 free (reloc_vector
);
12663 free (reloc_vector
);
12668 #define ELF_ARCH bfd_arch_nds32
12669 #define ELF_MACHINE_CODE EM_NDS32
12670 #define ELF_MAXPAGESIZE 0x1000
12671 #define ELF_TARGET_ID NDS32_ELF_DATA
12673 #define TARGET_BIG_SYM nds32_elf32_be_vec
12674 #define TARGET_BIG_NAME "elf32-nds32be"
12675 #define TARGET_LITTLE_SYM nds32_elf32_le_vec
12676 #define TARGET_LITTLE_NAME "elf32-nds32le"
12678 #define elf_info_to_howto nds32_info_to_howto
12679 #define elf_info_to_howto_rel nds32_info_to_howto_rel
12681 #define bfd_elf32_bfd_link_hash_table_create nds32_elf_link_hash_table_create
12682 #define bfd_elf32_bfd_merge_private_bfd_data nds32_elf_merge_private_bfd_data
12683 #define bfd_elf32_bfd_print_private_bfd_data nds32_elf_print_private_bfd_data
12684 #define bfd_elf32_bfd_relax_section nds32_elf_relax_section
12685 #define bfd_elf32_bfd_set_private_flags nds32_elf_set_private_flags
12687 #define bfd_elf32_mkobject nds32_elf_mkobject
12688 #define elf_backend_action_discarded nds32_elf_action_discarded
12689 #define elf_backend_add_symbol_hook nds32_elf_add_symbol_hook
12690 #define elf_backend_check_relocs nds32_elf_check_relocs
12691 #define elf_backend_adjust_dynamic_symbol nds32_elf_adjust_dynamic_symbol
12692 #define elf_backend_create_dynamic_sections nds32_elf_create_dynamic_sections
12693 #define elf_backend_finish_dynamic_sections nds32_elf_finish_dynamic_sections
12694 #define elf_backend_finish_dynamic_symbol nds32_elf_finish_dynamic_symbol
12695 #define elf_backend_size_dynamic_sections nds32_elf_size_dynamic_sections
12696 #define elf_backend_relocate_section nds32_elf_relocate_section
12697 #define elf_backend_gc_mark_hook nds32_elf_gc_mark_hook
12698 #define elf_backend_grok_prstatus nds32_elf_grok_prstatus
12699 #define elf_backend_grok_psinfo nds32_elf_grok_psinfo
12700 #define elf_backend_reloc_type_class nds32_elf_reloc_type_class
12701 #define elf_backend_copy_indirect_symbol nds32_elf_copy_indirect_symbol
12702 #define elf_backend_link_output_symbol_hook nds32_elf_output_symbol_hook
12703 #define elf_backend_output_arch_syms nds32_elf_output_arch_syms
12704 #define elf_backend_object_p nds32_elf_object_p
12705 #define elf_backend_final_write_processing nds32_elf_final_write_processing
12706 #define elf_backend_special_sections nds32_elf_special_sections
12707 #define bfd_elf32_bfd_get_relocated_section_contents \
12708 nds32_elf_get_relocated_section_contents
12710 #define elf_backend_can_gc_sections 1
12711 #define elf_backend_can_refcount 1
12712 #define elf_backend_want_got_plt 1
12713 #define elf_backend_plt_readonly 1
12714 #define elf_backend_want_plt_sym 0
12715 #define elf_backend_got_header_size 12
12716 #define elf_backend_may_use_rel_p 1
12717 #define elf_backend_default_use_rela_p 1
12718 #define elf_backend_may_use_rela_p 1
12719 #define elf_backend_dtrel_excludes_plt 1
12721 #include "elf32-target.h"
12723 #undef ELF_MAXPAGESIZE
12724 #define ELF_MAXPAGESIZE 0x2000
12726 #undef TARGET_BIG_SYM
12727 #define TARGET_BIG_SYM nds32_elf32_linux_be_vec
12728 #undef TARGET_BIG_NAME
12729 #define TARGET_BIG_NAME "elf32-nds32be-linux"
12730 #undef TARGET_LITTLE_SYM
12731 #define TARGET_LITTLE_SYM nds32_elf32_linux_le_vec
12732 #undef TARGET_LITTLE_NAME
12733 #define TARGET_LITTLE_NAME "elf32-nds32le-linux"
12735 #define elf32_bed elf32_nds32_lin_bed
12737 #include "elf32-target.h"