1 /* NDS32-specific support for 32-bit ELF.
2 Copyright (C) 2012-2017 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 bfd_boolean nds32_elf_ex9_build_hash_table
66 (bfd
*, asection
*, struct bfd_link_info
*);
67 static bfd_boolean
nds32_elf_ex9_itb_base (struct bfd_link_info
*);
68 static void nds32_elf_ex9_import_table (struct bfd_link_info
*);
69 static void nds32_elf_ex9_finish (struct bfd_link_info
*);
70 static void nds32_elf_ex9_reloc_jmp (struct bfd_link_info
*);
71 static void nds32_elf_get_insn_with_reg
72 (Elf_Internal_Rela
*, uint32_t, uint32_t *);
73 static int nds32_get_local_syms (bfd
*, asection
*ATTRIBUTE_UNUSED
,
75 static bfd_boolean nds32_elf_ex9_replace_instruction
76 (struct bfd_link_info
*, bfd
*, asection
*);
77 static bfd_boolean
nds32_elf_ifc_calc (struct bfd_link_info
*, bfd
*,
79 static bfd_boolean
nds32_elf_ifc_finish (struct bfd_link_info
*);
80 static bfd_boolean
nds32_elf_ifc_replace (struct bfd_link_info
*);
81 static bfd_boolean
nds32_elf_ifc_reloc (void);
82 static bfd_boolean nds32_relax_fp_as_gp
83 (struct bfd_link_info
*link_info
, bfd
*abfd
, asection
*sec
,
84 Elf_Internal_Rela
*internal_relocs
, Elf_Internal_Rela
*irelend
,
85 Elf_Internal_Sym
*isymbuf
);
86 static bfd_boolean nds32_fag_remove_unused_fpbase
87 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*internal_relocs
,
88 Elf_Internal_Rela
*irelend
);
92 MACH_V1
= bfd_mach_n1h
,
93 MACH_V2
= bfd_mach_n1h_v2
,
94 MACH_V3
= bfd_mach_n1h_v3
,
95 MACH_V3M
= bfd_mach_n1h_v3m
98 #define MIN(a, b) ((a) > (b) ? (b) : (a))
99 #define MAX(a, b) ((a) > (b) ? (a) : (b))
101 /* The name of the dynamic interpreter. This is put in the .interp
103 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
105 /* The nop opcode we use. */
106 #define NDS32_NOP32 0x40000009
107 #define NDS32_NOP16 0x9200
109 /* The size in bytes of an entry in the procedure linkage table. */
110 #define PLT_ENTRY_SIZE 24
111 #define PLT_HEADER_SIZE 24
113 /* The first entry in a procedure linkage table are reserved,
114 and the initial contents are unimportant (we zero them out).
115 Subsequent entries look like this. */
116 #define PLT0_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(.got+4) */
117 #define PLT0_ENTRY_WORD1 0x58f78000 /* ori r15, r25, LO12(.got+4) */
118 #define PLT0_ENTRY_WORD2 0x05178000 /* lwi r17, [r15+0] */
119 #define PLT0_ENTRY_WORD3 0x04f78001 /* lwi r15, [r15+4] */
120 #define PLT0_ENTRY_WORD4 0x4a003c00 /* jr r15 */
122 /* $ta is change to $r15 (from $r25). */
123 #define PLT0_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[1]@GOT) */
124 #define PLT0_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[1]@GOT) */
125 #define PLT0_PIC_ENTRY_WORD2 0x40f7f400 /* add r15, gp, r15 */
126 #define PLT0_PIC_ENTRY_WORD3 0x05178000 /* lwi r17, [r15+0] */
127 #define PLT0_PIC_ENTRY_WORD4 0x04f78001 /* lwi r15, [r15+4] */
128 #define PLT0_PIC_ENTRY_WORD5 0x4a003c00 /* jr r15 */
130 #define PLT_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(&got[n+3]) */
131 #define PLT_ENTRY_WORD1 0x04f78000 /* lwi r15, r15, LO12(&got[n+3]) */
132 #define PLT_ENTRY_WORD2 0x4a003c00 /* jr r15 */
133 #define PLT_ENTRY_WORD3 0x45000000 /* movi r16, sizeof(RELA) * n */
134 #define PLT_ENTRY_WORD4 0x48000000 /* j .plt0. */
136 #define PLT_PIC_ENTRY_WORD0 0x46f00000 /* sethi r15, HI20(got[n+3]@GOT) */
137 #define PLT_PIC_ENTRY_WORD1 0x58f78000 /* ori r15, r15, LO12(got[n+3]@GOT) */
138 #define PLT_PIC_ENTRY_WORD2 0x38febc02 /* lw r15, [gp+r15] */
139 #define PLT_PIC_ENTRY_WORD3 0x4a003c00 /* jr r15 */
140 #define PLT_PIC_ENTRY_WORD4 0x45000000 /* movi r16, sizeof(RELA) * n */
141 #define PLT_PIC_ENTRY_WORD5 0x48000000 /* j .plt0 */
143 /* These are macros used to get the relocation accurate value. */
144 #define ACCURATE_8BIT_S1 (0x100)
145 #define ACCURATE_U9BIT_S1 (0x400)
146 #define ACCURATE_12BIT_S1 (0x2000)
147 #define ACCURATE_14BIT_S1 (0x4000)
148 #define ACCURATE_19BIT (0x40000)
150 /* These are macros used to get the relocation conservative value. */
151 #define CONSERVATIVE_8BIT_S1 (0x100 - 4)
152 #define CONSERVATIVE_14BIT_S1 (0x4000 - 4)
153 #define CONSERVATIVE_16BIT_S1 (0x10000 - 4)
154 #define CONSERVATIVE_24BIT_S1 (0x1000000 - 4)
155 /* These must be more conservative because the address may be in
156 different segment. */
157 #define CONSERVATIVE_15BIT (0x4000 - 0x1000)
158 #define CONSERVATIVE_15BIT_S1 (0x8000 - 0x1000)
159 #define CONSERVATIVE_15BIT_S2 (0x10000 - 0x1000)
160 #define CONSERVATIVE_19BIT (0x40000 - 0x1000)
161 #define CONSERVATIVE_20BIT (0x80000 - 0x1000)
163 /* Size of small data/bss sections, used to calculate SDA_BASE. */
164 static long got_size
= 0;
165 static int is_SDA_BASE_set
= 0;
166 static int is_ITB_BASE_set
= 0;
168 /* Convert ELF-VER in eflags to string for debugging purpose. */
169 static const char *const nds32_elfver_strtab
[] =
176 /* The nds32 linker needs to keep track of the number of relocs that it
177 decides to copy in check_relocs for each symbol. This is so that
178 it can discard PC relative relocs if it doesn't need them when
179 linking with -Bsymbolic. We store the information in a field
180 extending the regular ELF linker hash table. */
182 /* This structure keeps track of the number of PC relative relocs we
183 have copied for a given symbol. */
185 struct elf_nds32_pcrel_relocs_copied
188 struct elf_nds32_pcrel_relocs_copied
*next
;
189 /* A section in dynobj. */
191 /* Number of relocs copied in this section. */
195 /* The sh linker needs to keep track of the number of relocs that it
196 decides to copy as dynamic relocs in check_relocs for each symbol.
197 This is so that it can later discard them if they are found to be
198 unnecessary. We store the information in a field extending the
199 regular ELF linker hash table. */
201 struct elf_nds32_dyn_relocs
203 struct elf_nds32_dyn_relocs
*next
;
205 /* The input section of the reloc. */
208 /* Total number of relocs copied for the input section. */
211 /* Number of pc-relative relocs copied for the input section. */
212 bfd_size_type pc_count
;
215 /* Nds32 ELF linker hash entry. */
217 struct elf_nds32_link_hash_entry
219 struct elf_link_hash_entry root
;
221 /* Track dynamic relocs copied for this symbol. */
222 struct elf_nds32_dyn_relocs
*dyn_relocs
;
224 /* For checking relocation type. */
225 #define GOT_UNKNOWN 0
228 unsigned int tls_type
;
231 /* Get the nds32 ELF linker hash table from a link_info structure. */
233 #define FP_BASE_NAME "_FP_BASE_"
234 static int check_start_export_sym
= 0;
235 static size_t ex9_relax_size
= 0; /* Save ex9 predicted reducing size. */
237 /* The offset for executable tls relaxation. */
238 #define TP_OFFSET 0x0
240 struct elf_nds32_obj_tdata
242 struct elf_obj_tdata root
;
244 /* tls_type for each local got entry. */
245 char *local_got_tls_type
;
248 #define elf_nds32_tdata(bfd) \
249 ((struct elf_nds32_obj_tdata *) (bfd)->tdata.any)
251 #define elf32_nds32_local_got_tls_type(bfd) \
252 (elf_nds32_tdata (bfd)->local_got_tls_type)
254 #define elf32_nds32_hash_entry(ent) ((struct elf_nds32_link_hash_entry *)(ent))
257 nds32_elf_mkobject (bfd
*abfd
)
259 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_nds32_obj_tdata
),
263 /* Relocations used for relocation. */
264 static reloc_howto_type nds32_elf_howto_table
[] =
266 /* This reloc does nothing. */
267 HOWTO (R_NDS32_NONE
, /* type */
269 3, /* size (0 = byte, 1 = short, 2 = long) */
271 FALSE
, /* pc_relative */
273 complain_overflow_dont
, /* complain_on_overflow */
274 bfd_elf_generic_reloc
, /* special_function */
275 "R_NDS32_NONE", /* name */
276 FALSE
, /* partial_inplace */
279 FALSE
), /* pcrel_offset */
281 /* A 16 bit absolute relocation. */
282 HOWTO (R_NDS32_16
, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_bitfield
, /* complain_on_overflow */
289 nds32_elf_generic_reloc
, /* special_function */
290 "R_NDS32_16", /* name */
291 FALSE
, /* partial_inplace */
292 0xffff, /* src_mask */
293 0xffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 /* A 32 bit absolute relocation. */
297 HOWTO (R_NDS32_32
, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE
, /* pc_relative */
303 complain_overflow_bitfield
, /* complain_on_overflow */
304 nds32_elf_generic_reloc
, /* special_function */
305 "R_NDS32_32", /* name */
306 FALSE
, /* partial_inplace */
307 0xffffffff, /* src_mask */
308 0xffffffff, /* dst_mask */
309 FALSE
), /* pcrel_offset */
311 /* A 20 bit address. */
312 HOWTO (R_NDS32_20
, /* type */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
316 FALSE
, /* pc_relative */
318 complain_overflow_unsigned
, /* complain_on_overflow */
319 nds32_elf_generic_reloc
, /* special_function */
320 "R_NDS32_20", /* name */
321 FALSE
, /* partial_inplace */
322 0xfffff, /* src_mask */
323 0xfffff, /* dst_mask */
324 FALSE
), /* pcrel_offset */
326 /* An PC Relative 9-bit relocation, shifted by 2.
327 This reloc is complicated because relocations are relative to pc & -4.
328 i.e. branches in the right insn slot use the address of the left insn
330 /* ??? It's not clear whether this should have partial_inplace set or not.
331 Branch relaxing in the assembler can store the addend in the insn,
332 and if bfd_install_relocation gets called the addend may get added
334 HOWTO (R_NDS32_9_PCREL
, /* type */
336 1, /* size (0 = byte, 1 = short, 2 = long) */
338 TRUE
, /* pc_relative */
340 complain_overflow_signed
, /* complain_on_overflow */
341 nds32_elf_9_pcrel_reloc
, /* special_function */
342 "R_NDS32_9_PCREL", /* name */
343 FALSE
, /* partial_inplace */
346 TRUE
), /* pcrel_offset */
348 /* A relative 15 bit relocation, right shifted by 1. */
349 HOWTO (R_NDS32_15_PCREL
, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 TRUE
, /* pc_relative */
355 complain_overflow_signed
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_NDS32_15_PCREL", /* name */
358 FALSE
, /* partial_inplace */
359 0x3fff, /* src_mask */
360 0x3fff, /* dst_mask */
361 TRUE
), /* pcrel_offset */
363 /* A relative 17 bit relocation, right shifted by 1. */
364 HOWTO (R_NDS32_17_PCREL
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 TRUE
, /* pc_relative */
370 complain_overflow_signed
, /* complain_on_overflow */
371 bfd_elf_generic_reloc
, /* special_function */
372 "R_NDS32_17_PCREL", /* name */
373 FALSE
, /* partial_inplace */
374 0xffff, /* src_mask */
375 0xffff, /* dst_mask */
376 TRUE
), /* pcrel_offset */
378 /* A relative 25 bit relocation, right shifted by 1. */
379 /* ??? It's not clear whether this should have partial_inplace set or not.
380 Branch relaxing in the assembler can store the addend in the insn,
381 and if bfd_install_relocation gets called the addend may get added
383 HOWTO (R_NDS32_25_PCREL
, /* type */
385 2, /* size (0 = byte, 1 = short, 2 = long) */
387 TRUE
, /* pc_relative */
389 complain_overflow_signed
, /* complain_on_overflow */
390 bfd_elf_generic_reloc
, /* special_function */
391 "R_NDS32_25_PCREL", /* name */
392 FALSE
, /* partial_inplace */
393 0xffffff, /* src_mask */
394 0xffffff, /* dst_mask */
395 TRUE
), /* pcrel_offset */
397 /* High 20 bits of address when lower 12 is or'd in. */
398 HOWTO (R_NDS32_HI20
, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE
, /* pc_relative */
404 complain_overflow_dont
,/* complain_on_overflow */
405 nds32_elf_hi20_reloc
, /* special_function */
406 "R_NDS32_HI20", /* name */
407 FALSE
, /* partial_inplace */
408 0x000fffff, /* src_mask */
409 0x000fffff, /* dst_mask */
410 FALSE
), /* pcrel_offset */
412 /* Lower 12 bits of address. */
413 HOWTO (R_NDS32_LO12S3
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 FALSE
, /* pc_relative */
419 complain_overflow_dont
,/* complain_on_overflow */
420 nds32_elf_lo12_reloc
, /* special_function */
421 "R_NDS32_LO12S3", /* name */
422 FALSE
, /* partial_inplace */
423 0x000001ff, /* src_mask */
424 0x000001ff, /* dst_mask */
425 FALSE
), /* pcrel_offset */
427 /* Lower 12 bits of address. */
428 HOWTO (R_NDS32_LO12S2
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE
, /* pc_relative */
434 complain_overflow_dont
,/* complain_on_overflow */
435 nds32_elf_lo12_reloc
, /* special_function */
436 "R_NDS32_LO12S2", /* name */
437 FALSE
, /* partial_inplace */
438 0x000003ff, /* src_mask */
439 0x000003ff, /* dst_mask */
440 FALSE
), /* pcrel_offset */
442 /* Lower 12 bits of address. */
443 HOWTO (R_NDS32_LO12S1
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE
, /* pc_relative */
449 complain_overflow_dont
,/* complain_on_overflow */
450 nds32_elf_lo12_reloc
, /* special_function */
451 "R_NDS32_LO12S1", /* name */
452 FALSE
, /* partial_inplace */
453 0x000007ff, /* src_mask */
454 0x000007ff, /* dst_mask */
455 FALSE
), /* pcrel_offset */
457 /* Lower 12 bits of address. */
458 HOWTO (R_NDS32_LO12S0
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 FALSE
, /* pc_relative */
464 complain_overflow_dont
,/* complain_on_overflow */
465 nds32_elf_lo12_reloc
, /* special_function */
466 "R_NDS32_LO12S0", /* name */
467 FALSE
, /* partial_inplace */
468 0x00000fff, /* src_mask */
469 0x00000fff, /* dst_mask */
470 FALSE
), /* pcrel_offset */
472 /* Small data area 15 bits offset. */
473 HOWTO (R_NDS32_SDA15S3
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 FALSE
, /* pc_relative */
479 complain_overflow_signed
, /* complain_on_overflow */
480 nds32_elf_sda15_reloc
, /* special_function */
481 "R_NDS32_SDA15S3", /* name */
482 FALSE
, /* partial_inplace */
483 0x00007fff, /* src_mask */
484 0x00007fff, /* dst_mask */
485 FALSE
), /* pcrel_offset */
487 /* Small data area 15 bits offset. */
488 HOWTO (R_NDS32_SDA15S2
, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 FALSE
, /* pc_relative */
494 complain_overflow_signed
, /* complain_on_overflow */
495 nds32_elf_sda15_reloc
, /* special_function */
496 "R_NDS32_SDA15S2", /* name */
497 FALSE
, /* partial_inplace */
498 0x00007fff, /* src_mask */
499 0x00007fff, /* dst_mask */
500 FALSE
), /* pcrel_offset */
502 /* Small data area 15 bits offset. */
503 HOWTO (R_NDS32_SDA15S1
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_signed
, /* complain_on_overflow */
510 nds32_elf_sda15_reloc
, /* special_function */
511 "R_NDS32_SDA15S1", /* name */
512 FALSE
, /* partial_inplace */
513 0x00007fff, /* src_mask */
514 0x00007fff, /* dst_mask */
515 FALSE
), /* pcrel_offset */
517 /* Small data area 15 bits offset. */
518 HOWTO (R_NDS32_SDA15S0
, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 FALSE
, /* pc_relative */
524 complain_overflow_signed
, /* complain_on_overflow */
525 nds32_elf_sda15_reloc
, /* special_function */
526 "R_NDS32_SDA15S0", /* name */
527 FALSE
, /* partial_inplace */
528 0x00007fff, /* src_mask */
529 0x00007fff, /* dst_mask */
530 FALSE
), /* pcrel_offset */
532 /* GNU extension to record C++ vtable hierarchy */
533 HOWTO (R_NDS32_GNU_VTINHERIT
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 FALSE
, /* pc_relative */
539 complain_overflow_dont
,/* complain_on_overflow */
540 NULL
, /* special_function */
541 "R_NDS32_GNU_VTINHERIT", /* name */
542 FALSE
, /* partial_inplace */
545 FALSE
), /* pcrel_offset */
547 /* GNU extension to record C++ vtable member usage */
548 HOWTO (R_NDS32_GNU_VTENTRY
, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 FALSE
, /* pc_relative */
554 complain_overflow_dont
,/* complain_on_overflow */
555 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
556 "R_NDS32_GNU_VTENTRY", /* name */
557 FALSE
, /* partial_inplace */
560 FALSE
), /* pcrel_offset */
562 /* A 16 bit absolute relocation. */
563 HOWTO (R_NDS32_16_RELA
, /* type */
565 1, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_bitfield
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_NDS32_16_RELA", /* name */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* A 32 bit absolute relocation. */
578 HOWTO (R_NDS32_32_RELA
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_bitfield
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_NDS32_32_RELA", /* name */
587 FALSE
, /* partial_inplace */
588 0xffffffff, /* src_mask */
589 0xffffffff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 /* A 20 bit address. */
593 HOWTO (R_NDS32_20_RELA
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_NDS32_20_RELA", /* name */
602 FALSE
, /* partial_inplace */
603 0xfffff, /* src_mask */
604 0xfffff, /* dst_mask */
605 FALSE
), /* pcrel_offset */
607 HOWTO (R_NDS32_9_PCREL_RELA
, /* type */
609 1, /* size (0 = byte, 1 = short, 2 = long) */
611 TRUE
, /* pc_relative */
613 complain_overflow_signed
, /* complain_on_overflow */
614 bfd_elf_generic_reloc
, /* special_function */
615 "R_NDS32_9_PCREL_RELA",/* name */
616 FALSE
, /* partial_inplace */
619 TRUE
), /* pcrel_offset */
621 /* A relative 15 bit relocation, right shifted by 1. */
622 HOWTO (R_NDS32_15_PCREL_RELA
, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 TRUE
, /* pc_relative */
628 complain_overflow_signed
, /* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_NDS32_15_PCREL_RELA", /* name */
631 FALSE
, /* partial_inplace */
632 0x3fff, /* src_mask */
633 0x3fff, /* dst_mask */
634 TRUE
), /* pcrel_offset */
636 /* A relative 17 bit relocation, right shifted by 1. */
637 HOWTO (R_NDS32_17_PCREL_RELA
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 TRUE
, /* pc_relative */
643 complain_overflow_signed
, /* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_NDS32_17_PCREL_RELA", /* name */
646 FALSE
, /* partial_inplace */
647 0xffff, /* src_mask */
648 0xffff, /* dst_mask */
649 TRUE
), /* pcrel_offset */
651 /* A relative 25 bit relocation, right shifted by 2. */
652 HOWTO (R_NDS32_25_PCREL_RELA
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 TRUE
, /* pc_relative */
658 complain_overflow_signed
, /* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_NDS32_25_PCREL_RELA", /* name */
661 FALSE
, /* partial_inplace */
662 0xffffff, /* src_mask */
663 0xffffff, /* dst_mask */
664 TRUE
), /* pcrel_offset */
666 /* High 20 bits of address when lower 16 is or'd in. */
667 HOWTO (R_NDS32_HI20_RELA
, /* type */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
671 FALSE
, /* pc_relative */
673 complain_overflow_dont
,/* complain_on_overflow */
674 bfd_elf_generic_reloc
, /* special_function */
675 "R_NDS32_HI20_RELA", /* name */
676 FALSE
, /* partial_inplace */
677 0x000fffff, /* src_mask */
678 0x000fffff, /* dst_mask */
679 FALSE
), /* pcrel_offset */
681 /* Lower 12 bits of address. */
682 HOWTO (R_NDS32_LO12S3_RELA
, /* type */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE
, /* pc_relative */
688 complain_overflow_dont
,/* complain_on_overflow */
689 bfd_elf_generic_reloc
, /* special_function */
690 "R_NDS32_LO12S3_RELA", /* name */
691 FALSE
, /* partial_inplace */
692 0x000001ff, /* src_mask */
693 0x000001ff, /* dst_mask */
694 FALSE
), /* pcrel_offset */
696 /* Lower 12 bits of address. */
697 HOWTO (R_NDS32_LO12S2_RELA
, /* type */
699 2, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE
, /* pc_relative */
703 complain_overflow_dont
,/* complain_on_overflow */
704 bfd_elf_generic_reloc
, /* special_function */
705 "R_NDS32_LO12S2_RELA", /* name */
706 FALSE
, /* partial_inplace */
707 0x000003ff, /* src_mask */
708 0x000003ff, /* dst_mask */
709 FALSE
), /* pcrel_offset */
711 /* Lower 12 bits of address. */
712 HOWTO (R_NDS32_LO12S1_RELA
, /* type */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE
, /* pc_relative */
718 complain_overflow_dont
,/* complain_on_overflow */
719 bfd_elf_generic_reloc
, /* special_function */
720 "R_NDS32_LO12S1_RELA", /* name */
721 FALSE
, /* partial_inplace */
722 0x000007ff, /* src_mask */
723 0x000007ff, /* dst_mask */
724 FALSE
), /* pcrel_offset */
726 /* Lower 12 bits of address. */
727 HOWTO (R_NDS32_LO12S0_RELA
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_dont
,/* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_NDS32_LO12S0_RELA", /* name */
736 FALSE
, /* partial_inplace */
737 0x00000fff, /* src_mask */
738 0x00000fff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 /* Small data area 15 bits offset. */
742 HOWTO (R_NDS32_SDA15S3_RELA
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE
, /* pc_relative */
748 complain_overflow_signed
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_NDS32_SDA15S3_RELA",/* name */
751 FALSE
, /* partial_inplace */
752 0x00007fff, /* src_mask */
753 0x00007fff, /* dst_mask */
754 FALSE
), /* pcrel_offset */
756 /* Small data area 15 bits offset. */
757 HOWTO (R_NDS32_SDA15S2_RELA
, /* type */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_signed
, /* complain_on_overflow */
764 bfd_elf_generic_reloc
, /* special_function */
765 "R_NDS32_SDA15S2_RELA",/* name */
766 FALSE
, /* partial_inplace */
767 0x00007fff, /* src_mask */
768 0x00007fff, /* dst_mask */
769 FALSE
), /* pcrel_offset */
771 HOWTO (R_NDS32_SDA15S1_RELA
, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE
, /* pc_relative */
777 complain_overflow_signed
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* special_function */
779 "R_NDS32_SDA15S1_RELA",/* name */
780 FALSE
, /* partial_inplace */
781 0x00007fff, /* src_mask */
782 0x00007fff, /* dst_mask */
783 FALSE
), /* pcrel_offset */
785 HOWTO (R_NDS32_SDA15S0_RELA
, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_signed
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 "R_NDS32_SDA15S0_RELA",/* name */
794 FALSE
, /* partial_inplace */
795 0x00007fff, /* src_mask */
796 0x00007fff, /* dst_mask */
797 FALSE
), /* pcrel_offset */
799 /* GNU extension to record C++ vtable hierarchy */
800 HOWTO (R_NDS32_RELA_GNU_VTINHERIT
, /* type */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE
, /* pc_relative */
806 complain_overflow_dont
,/* complain_on_overflow */
807 NULL
, /* special_function */
808 "R_NDS32_RELA_GNU_VTINHERIT", /* name */
809 FALSE
, /* partial_inplace */
812 FALSE
), /* pcrel_offset */
814 /* GNU extension to record C++ vtable member usage */
815 HOWTO (R_NDS32_RELA_GNU_VTENTRY
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE
, /* pc_relative */
821 complain_overflow_dont
,/* complain_on_overflow */
822 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
823 "R_NDS32_RELA_GNU_VTENTRY", /* name */
824 FALSE
, /* partial_inplace */
827 FALSE
), /* pcrel_offset */
829 /* Like R_NDS32_20, but referring to the GOT table entry for
831 HOWTO (R_NDS32_GOT20
, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 FALSE
, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_NDS32_GOT20", /* name */
840 FALSE
, /* partial_inplace */
841 0xfffff, /* src_mask */
842 0xfffff, /* dst_mask */
843 FALSE
), /* pcrel_offset */
845 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
846 entry for the symbol. */
847 HOWTO (R_NDS32_25_PLTREL
, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 TRUE
, /* pc_relative */
853 complain_overflow_signed
, /* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 "R_NDS32_25_PLTREL", /* name */
856 FALSE
, /* partial_inplace */
857 0xffffff, /* src_mask */
858 0xffffff, /* dst_mask */
859 TRUE
), /* pcrel_offset */
861 /* This is used only by the dynamic linker. The symbol should exist
862 both in the object being run and in some shared library. The
863 dynamic linker copies the data addressed by the symbol from the
864 shared library into the object, because the object being
865 run has to have the data at some particular address. */
866 HOWTO (R_NDS32_COPY
, /* type */
868 2, /* size (0 = byte, 1 = short, 2 = long) */
870 FALSE
, /* pc_relative */
872 complain_overflow_bitfield
, /* complain_on_overflow */
873 bfd_elf_generic_reloc
, /* special_function */
874 "R_NDS32_COPY", /* name */
875 FALSE
, /* partial_inplace */
876 0xffffffff, /* src_mask */
877 0xffffffff, /* dst_mask */
878 FALSE
), /* pcrel_offset */
880 /* Like R_NDS32_20, but used when setting global offset table
882 HOWTO (R_NDS32_GLOB_DAT
, /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_bitfield
, /* complain_on_overflow */
889 bfd_elf_generic_reloc
, /* special_function */
890 "R_NDS32_GLOB_DAT", /* name */
891 FALSE
, /* partial_inplace */
892 0xffffffff, /* src_mask */
893 0xffffffff, /* dst_mask */
894 FALSE
), /* pcrel_offset */
896 /* Marks a procedure linkage table entry for a symbol. */
897 HOWTO (R_NDS32_JMP_SLOT
, /* type */
899 2, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE
, /* pc_relative */
903 complain_overflow_bitfield
, /* complain_on_overflow */
904 bfd_elf_generic_reloc
, /* special_function */
905 "R_NDS32_JMP_SLOT", /* name */
906 FALSE
, /* partial_inplace */
907 0xffffffff, /* src_mask */
908 0xffffffff, /* dst_mask */
909 FALSE
), /* pcrel_offset */
911 /* Used only by the dynamic linker. When the object is run, this
912 longword is set to the load address of the object, plus the
914 HOWTO (R_NDS32_RELATIVE
, /* type */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
918 FALSE
, /* pc_relative */
920 complain_overflow_bitfield
, /* complain_on_overflow */
921 bfd_elf_generic_reloc
, /* special_function */
922 "R_NDS32_RELATIVE", /* name */
923 FALSE
, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 FALSE
), /* pcrel_offset */
928 HOWTO (R_NDS32_GOTOFF
, /* type */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE
, /* pc_relative */
934 complain_overflow_signed
, /* complain_on_overflow */
935 bfd_elf_generic_reloc
, /* special_function */
936 "R_NDS32_GOTOFF", /* name */
937 FALSE
, /* partial_inplace */
938 0xfffff, /* src_mask */
939 0xfffff, /* dst_mask */
940 FALSE
), /* pcrel_offset */
942 /* An PC Relative 20-bit relocation used when setting PIC offset
944 HOWTO (R_NDS32_GOTPC20
, /* type */
946 2, /* size (0 = byte, 1 = short, 2 = long) */
948 TRUE
, /* pc_relative */
950 complain_overflow_signed
, /* complain_on_overflow */
951 bfd_elf_generic_reloc
, /* special_function */
952 "R_NDS32_GOTPC20", /* name */
953 FALSE
, /* partial_inplace */
954 0xfffff, /* src_mask */
955 0xfffff, /* dst_mask */
956 TRUE
), /* pcrel_offset */
958 /* Like R_NDS32_HI20, but referring to the GOT table entry for
960 HOWTO (R_NDS32_GOT_HI20
, /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
,/* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 "R_NDS32_GOT_HI20", /* name */
969 FALSE
, /* partial_inplace */
970 0x000fffff, /* src_mask */
971 0x000fffff, /* dst_mask */
972 FALSE
), /* pcrel_offset */
973 HOWTO (R_NDS32_GOT_LO12
, /* type */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE
, /* pc_relative */
979 complain_overflow_dont
,/* complain_on_overflow */
980 bfd_elf_generic_reloc
, /* special_function */
981 "R_NDS32_GOT_LO12", /* name */
982 FALSE
, /* partial_inplace */
983 0x00000fff, /* src_mask */
984 0x00000fff, /* dst_mask */
985 FALSE
), /* pcrel_offset */
987 /* An PC Relative relocation used when setting PIC offset table register.
988 Like R_NDS32_HI20, but referring to the GOT table entry for
990 HOWTO (R_NDS32_GOTPC_HI20
, /* type */
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE
, /* pc_relative */
996 complain_overflow_dont
,/* complain_on_overflow */
997 bfd_elf_generic_reloc
, /* special_function */
998 "R_NDS32_GOTPC_HI20", /* name */
999 FALSE
, /* partial_inplace */
1000 0x000fffff, /* src_mask */
1001 0x000fffff, /* dst_mask */
1002 TRUE
), /* pcrel_offset */
1003 HOWTO (R_NDS32_GOTPC_LO12
, /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE
, /* pc_relative */
1009 complain_overflow_dont
, /* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_NDS32_GOTPC_LO12", /* name */
1012 FALSE
, /* partial_inplace */
1013 0x00000fff, /* src_mask */
1014 0x00000fff, /* dst_mask */
1015 TRUE
), /* pcrel_offset */
1017 HOWTO (R_NDS32_GOTOFF_HI20
, /* type */
1018 12, /* rightshift */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
,/* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_NDS32_GOTOFF_HI20", /* name */
1026 FALSE
, /* partial_inplace */
1027 0x000fffff, /* src_mask */
1028 0x000fffff, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1030 HOWTO (R_NDS32_GOTOFF_LO12
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 FALSE
, /* pc_relative */
1036 complain_overflow_dont
,/* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_NDS32_GOTOFF_LO12", /* name */
1039 FALSE
, /* partial_inplace */
1040 0x00000fff, /* src_mask */
1041 0x00000fff, /* dst_mask */
1042 FALSE
), /* pcrel_offset */
1044 /* Alignment hint for relaxable instruction. This is used with
1045 R_NDS32_LABEL as a pair. Relax this instruction from 4 bytes to 2
1046 in order to make next label aligned on word boundary. */
1047 HOWTO (R_NDS32_INSN16
, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE
, /* pc_relative */
1053 complain_overflow_dont
,/* complain_on_overflow */
1054 nds32_elf_ignore_reloc
,/* special_function */
1055 "R_NDS32_INSN16", /* name */
1056 FALSE
, /* partial_inplace */
1057 0x00000fff, /* src_mask */
1058 0x00000fff, /* dst_mask */
1059 FALSE
), /* pcrel_offset */
1061 /* Alignment hint for label. */
1062 HOWTO (R_NDS32_LABEL
, /* type */
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE
, /* pc_relative */
1068 complain_overflow_dont
,/* complain_on_overflow */
1069 nds32_elf_ignore_reloc
,/* special_function */
1070 "R_NDS32_LABEL", /* name */
1071 FALSE
, /* partial_inplace */
1072 0xffffffff, /* src_mask */
1073 0xffffffff, /* dst_mask */
1074 FALSE
), /* pcrel_offset */
1076 /* Relax hint for unconditional call sequence */
1077 HOWTO (R_NDS32_LONGCALL1
, /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE
, /* pc_relative */
1083 complain_overflow_dont
,/* complain_on_overflow */
1084 nds32_elf_ignore_reloc
,/* special_function */
1085 "R_NDS32_LONGCALL1", /* name */
1086 FALSE
, /* partial_inplace */
1087 0xffffffff, /* src_mask */
1088 0xffffffff, /* dst_mask */
1089 FALSE
), /* pcrel_offset */
1091 /* Relax hint for conditional call sequence. */
1092 HOWTO (R_NDS32_LONGCALL2
, /* type */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_dont
,/* complain_on_overflow */
1099 nds32_elf_ignore_reloc
,/* special_function */
1100 "R_NDS32_LONGCALL2", /* name */
1101 FALSE
, /* partial_inplace */
1102 0xffffffff, /* src_mask */
1103 0xffffffff, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 /* Relax hint for conditional call sequence. */
1107 HOWTO (R_NDS32_LONGCALL3
, /* type */
1109 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 FALSE
, /* pc_relative */
1113 complain_overflow_dont
,/* complain_on_overflow */
1114 nds32_elf_ignore_reloc
,/* special_function */
1115 "R_NDS32_LONGCALL3", /* name */
1116 FALSE
, /* partial_inplace */
1117 0xffffffff, /* src_mask */
1118 0xffffffff, /* dst_mask */
1119 FALSE
), /* pcrel_offset */
1121 /* Relax hint for unconditional branch sequence. */
1122 HOWTO (R_NDS32_LONGJUMP1
, /* type */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 FALSE
, /* pc_relative */
1128 complain_overflow_dont
,/* complain_on_overflow */
1129 nds32_elf_ignore_reloc
,/* special_function */
1130 "R_NDS32_LONGJUMP1", /* name */
1131 FALSE
, /* partial_inplace */
1132 0xffffffff, /* src_mask */
1133 0xffffffff, /* dst_mask */
1134 FALSE
), /* pcrel_offset */
1136 /* Relax hint for conditional branch sequence. */
1137 HOWTO (R_NDS32_LONGJUMP2
, /* type */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE
, /* pc_relative */
1143 complain_overflow_dont
,/* complain_on_overflow */
1144 nds32_elf_ignore_reloc
,/* special_function */
1145 "R_NDS32_LONGJUMP2", /* name */
1146 FALSE
, /* partial_inplace */
1147 0xffffffff, /* src_mask */
1148 0xffffffff, /* dst_mask */
1149 FALSE
), /* pcrel_offset */
1151 /* Relax hint for conditional branch sequence. */
1152 HOWTO (R_NDS32_LONGJUMP3
, /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE
, /* pc_relative */
1158 complain_overflow_dont
,/* complain_on_overflow */
1159 nds32_elf_ignore_reloc
,/* special_function */
1160 "R_NDS32_LONGJUMP3", /* name */
1161 FALSE
, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 FALSE
), /* pcrel_offset */
1166 /* Relax hint for load/store sequence. */
1167 HOWTO (R_NDS32_LOADSTORE
, /* type */
1169 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE
, /* pc_relative */
1173 complain_overflow_dont
,/* complain_on_overflow */
1174 nds32_elf_ignore_reloc
,/* special_function */
1175 "R_NDS32_LOADSTORE", /* name */
1176 FALSE
, /* partial_inplace */
1177 0xffffffff, /* src_mask */
1178 0xffffffff, /* dst_mask */
1179 FALSE
), /* pcrel_offset */
1181 /* Relax hint for load/store sequence. */
1182 HOWTO (R_NDS32_9_FIXED_RELA
, /* type */
1184 1, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE
, /* pc_relative */
1188 complain_overflow_dont
,/* complain_on_overflow */
1189 nds32_elf_ignore_reloc
,/* special_function */
1190 "R_NDS32_9_FIXED_RELA",/* name */
1191 FALSE
, /* partial_inplace */
1192 0x000000ff, /* src_mask */
1193 0x000000ff, /* dst_mask */
1194 FALSE
), /* pcrel_offset */
1196 /* Relax hint for load/store sequence. */
1197 HOWTO (R_NDS32_15_FIXED_RELA
, /* type */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE
, /* pc_relative */
1203 complain_overflow_dont
,/* complain_on_overflow */
1204 nds32_elf_ignore_reloc
,/* special_function */
1205 "R_NDS32_15_FIXED_RELA", /* name */
1206 FALSE
, /* partial_inplace */
1207 0x00003fff, /* src_mask */
1208 0x00003fff, /* dst_mask */
1209 FALSE
), /* pcrel_offset */
1211 /* Relax hint for load/store sequence. */
1212 HOWTO (R_NDS32_17_FIXED_RELA
, /* type */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_dont
,/* complain_on_overflow */
1219 nds32_elf_ignore_reloc
,/* special_function */
1220 "R_NDS32_17_FIXED_RELA", /* name */
1221 FALSE
, /* partial_inplace */
1222 0x0000ffff, /* src_mask */
1223 0x0000ffff, /* dst_mask */
1224 FALSE
), /* pcrel_offset */
1226 /* Relax hint for load/store sequence. */
1227 HOWTO (R_NDS32_25_FIXED_RELA
, /* type */
1229 2, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE
, /* pc_relative */
1233 complain_overflow_dont
,/* complain_on_overflow */
1234 nds32_elf_ignore_reloc
,/* special_function */
1235 "R_NDS32_25_FIXED_RELA", /* name */
1236 FALSE
, /* partial_inplace */
1237 0x00ffffff, /* src_mask */
1238 0x00ffffff, /* dst_mask */
1239 FALSE
), /* pcrel_offset */
1241 /* High 20 bits of PLT symbol offset relative to PC. */
1242 HOWTO (R_NDS32_PLTREL_HI20
, /* type */
1243 12, /* rightshift */
1244 2, /* size (0 = byte, 1 = short, 2 = long) */
1246 FALSE
, /* pc_relative */
1248 complain_overflow_dont
,/* complain_on_overflow */
1249 bfd_elf_generic_reloc
, /* special_function */
1250 "R_NDS32_PLTREL_HI20", /* name */
1251 FALSE
, /* partial_inplace */
1252 0x000fffff, /* src_mask */
1253 0x000fffff, /* dst_mask */
1254 FALSE
), /* pcrel_offset */
1256 /* Low 12 bits of PLT symbol offset relative to PC. */
1257 HOWTO (R_NDS32_PLTREL_LO12
, /* type */
1259 2, /* size (0 = byte, 1 = short, 2 = long) */
1261 FALSE
, /* pc_relative */
1263 complain_overflow_dont
,/* complain_on_overflow */
1264 bfd_elf_generic_reloc
, /* special_function */
1265 "R_NDS32_PLTREL_LO12", /* name */
1266 FALSE
, /* partial_inplace */
1267 0x00000fff, /* src_mask */
1268 0x00000fff, /* dst_mask */
1269 FALSE
), /* pcrel_offset */
1271 /* High 20 bits of PLT symbol offset relative to GOT (GP). */
1272 HOWTO (R_NDS32_PLT_GOTREL_HI20
, /* type */
1273 12, /* rightshift */
1274 2, /* size (0 = byte, 1 = short, 2 = long) */
1276 FALSE
, /* pc_relative */
1278 complain_overflow_dont
,/* complain_on_overflow */
1279 bfd_elf_generic_reloc
, /* special_function */
1280 "R_NDS32_PLT_GOTREL_HI20", /* name */
1281 FALSE
, /* partial_inplace */
1282 0x000fffff, /* src_mask */
1283 0x000fffff, /* dst_mask */
1284 FALSE
), /* pcrel_offset */
1286 /* Low 12 bits of PLT symbol offset relative to GOT (GP). */
1287 HOWTO (R_NDS32_PLT_GOTREL_LO12
, /* type */
1289 2, /* size (0 = byte, 1 = short, 2 = long) */
1291 FALSE
, /* pc_relative */
1293 complain_overflow_dont
,/* complain_on_overflow */
1294 bfd_elf_generic_reloc
, /* special_function */
1295 "R_NDS32_PLT_GOTREL_LO12", /* name */
1296 FALSE
, /* partial_inplace */
1297 0x00000fff, /* src_mask */
1298 0x00000fff, /* dst_mask */
1299 FALSE
), /* pcrel_offset */
1301 /* Small data area 12 bits offset. */
1302 HOWTO (R_NDS32_SDA12S2_DP_RELA
, /* type */
1304 2, /* size (0 = byte, 1 = short, 2 = long) */
1306 FALSE
, /* pc_relative */
1308 complain_overflow_signed
, /* complain_on_overflow */
1309 bfd_elf_generic_reloc
, /* special_function */
1310 "R_NDS32_SDA12S2_DP_RELA", /* name */
1311 FALSE
, /* partial_inplace */
1312 0x00000fff, /* src_mask */
1313 0x00000fff, /* dst_mask */
1314 FALSE
), /* pcrel_offset */
1316 /* Small data area 12 bits offset. */
1317 HOWTO (R_NDS32_SDA12S2_SP_RELA
, /* type */
1319 2, /* size (0 = byte, 1 = short, 2 = long) */
1321 FALSE
, /* pc_relative */
1323 complain_overflow_signed
, /* complain_on_overflow */
1324 bfd_elf_generic_reloc
, /* special_function */
1325 "R_NDS32_SDA12S2_SP_RELA", /* name */
1326 FALSE
, /* partial_inplace */
1327 0x00000fff, /* src_mask */
1328 0x00000fff, /* dst_mask */
1329 FALSE
), /* pcrel_offset */
1330 /* Lower 12 bits of address. */
1332 HOWTO (R_NDS32_LO12S2_DP_RELA
, /* type */
1334 2, /* size (0 = byte, 1 = short, 2 = long) */
1336 FALSE
, /* pc_relative */
1338 complain_overflow_dont
,/* complain_on_overflow */
1339 bfd_elf_generic_reloc
, /* special_function */
1340 "R_NDS32_LO12S2_DP_RELA", /* name */
1341 FALSE
, /* partial_inplace */
1342 0x000003ff, /* src_mask */
1343 0x000003ff, /* dst_mask */
1344 FALSE
), /* pcrel_offset */
1346 /* Lower 12 bits of address. */
1347 HOWTO (R_NDS32_LO12S2_SP_RELA
,/* type */
1349 2, /* size (0 = byte, 1 = short, 2 = long) */
1351 FALSE
, /* pc_relative */
1353 complain_overflow_dont
,/* complain_on_overflow */
1354 bfd_elf_generic_reloc
, /* special_function */
1355 "R_NDS32_LO12S2_SP_RELA", /* name */
1356 FALSE
, /* partial_inplace */
1357 0x000003ff, /* src_mask */
1358 0x000003ff, /* dst_mask */
1359 FALSE
), /* pcrel_offset */
1360 /* Lower 12 bits of address. Special identity for or case. */
1361 HOWTO (R_NDS32_LO12S0_ORI_RELA
, /* type */
1363 2, /* size (0 = byte, 1 = short, 2 = long) */
1365 FALSE
, /* pc_relative */
1367 complain_overflow_dont
,/* complain_on_overflow */
1368 bfd_elf_generic_reloc
, /* special_function */
1369 "R_NDS32_LO12S0_ORI_RELA", /* name */
1370 FALSE
, /* partial_inplace */
1371 0x00000fff, /* src_mask */
1372 0x00000fff, /* dst_mask */
1373 FALSE
), /* pcrel_offset */
1374 /* Small data area 19 bits offset. */
1375 HOWTO (R_NDS32_SDA16S3_RELA
, /* type */
1377 2, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_signed
, /* complain_on_overflow */
1382 bfd_elf_generic_reloc
, /* special_function */
1383 "R_NDS32_SDA16S3_RELA",/* name */
1384 FALSE
, /* partial_inplace */
1385 0x0000ffff, /* src_mask */
1386 0x0000ffff, /* dst_mask */
1387 FALSE
), /* pcrel_offset */
1389 /* Small data area 15 bits offset. */
1390 HOWTO (R_NDS32_SDA17S2_RELA
, /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE
, /* pc_relative */
1396 complain_overflow_signed
, /* complain_on_overflow */
1397 bfd_elf_generic_reloc
, /* special_function */
1398 "R_NDS32_SDA17S2_RELA",/* name */
1399 FALSE
, /* partial_inplace */
1400 0x0001ffff, /* src_mask */
1401 0x0001ffff, /* dst_mask */
1402 FALSE
), /* pcrel_offset */
1404 HOWTO (R_NDS32_SDA18S1_RELA
, /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE
, /* pc_relative */
1410 complain_overflow_signed
, /* complain_on_overflow */
1411 bfd_elf_generic_reloc
, /* special_function */
1412 "R_NDS32_SDA18S1_RELA",/* name */
1413 FALSE
, /* partial_inplace */
1414 0x0003ffff, /* src_mask */
1415 0x0003ffff, /* dst_mask */
1416 FALSE
), /* pcrel_offset */
1418 HOWTO (R_NDS32_SDA19S0_RELA
, /* type */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE
, /* pc_relative */
1424 complain_overflow_signed
, /* complain_on_overflow */
1425 bfd_elf_generic_reloc
, /* special_function */
1426 "R_NDS32_SDA19S0_RELA",/* name */
1427 FALSE
, /* partial_inplace */
1428 0x0007ffff, /* src_mask */
1429 0x0007ffff, /* dst_mask */
1430 FALSE
), /* pcrel_offset */
1431 HOWTO (R_NDS32_DWARF2_OP1_RELA
, /* type */
1433 0, /* size (0 = byte, 1 = short, 2 = long) */
1435 FALSE
, /* pc_relative */
1437 complain_overflow_dont
,/* complain_on_overflow */
1438 nds32_elf_ignore_reloc
,/* special_function */
1439 "R_NDS32_DWARF2_OP1_RELA", /* name */
1440 FALSE
, /* partial_inplace */
1441 0xff, /* src_mask */
1442 0xff, /* dst_mask */
1443 FALSE
), /* pcrel_offset */
1444 HOWTO (R_NDS32_DWARF2_OP2_RELA
, /* type */
1446 1, /* size (0 = byte, 1 = short, 2 = long) */
1448 FALSE
, /* pc_relative */
1450 complain_overflow_dont
,/* complain_on_overflow */
1451 nds32_elf_ignore_reloc
,/* special_function */
1452 "R_NDS32_DWARF2_OP2_RELA", /* name */
1453 FALSE
, /* partial_inplace */
1454 0xffff, /* src_mask */
1455 0xffff, /* dst_mask */
1456 FALSE
), /* pcrel_offset */
1457 HOWTO (R_NDS32_DWARF2_LEB_RELA
, /* type */
1459 2, /* size (0 = byte, 1 = short, 2 = long) */
1461 FALSE
, /* pc_relative */
1463 complain_overflow_dont
,/* complain_on_overflow */
1464 nds32_elf_ignore_reloc
,/* special_function */
1465 "R_NDS32_DWARF2_LEB_RELA", /* name */
1466 FALSE
, /* partial_inplace */
1467 0xffffffff, /* src_mask */
1468 0xffffffff, /* dst_mask */
1469 FALSE
), /* pcrel_offset */
1470 HOWTO (R_NDS32_UPDATE_TA_RELA
,/* type */
1472 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE
, /* pc_relative */
1476 complain_overflow_dont
,/* complain_on_overflow */
1477 nds32_elf_ignore_reloc
,/* special_function */
1478 "R_NDS32_UPDATE_TA_RELA", /* name */
1479 FALSE
, /* partial_inplace */
1480 0xffff, /* src_mask */
1481 0xffff, /* dst_mask */
1482 FALSE
), /* pcrel_offset */
1483 /* Like R_NDS32_PCREL, but referring to the procedure linkage table
1484 entry for the symbol. */
1485 HOWTO (R_NDS32_9_PLTREL
, /* type */
1487 1, /* size (0 = byte, 1 = short, 2 = long) */
1489 TRUE
, /* pc_relative */
1491 complain_overflow_signed
, /* complain_on_overflow */
1492 bfd_elf_generic_reloc
, /* special_function */
1493 "R_NDS32_9_PLTREL", /* name */
1494 FALSE
, /* partial_inplace */
1495 0xff, /* src_mask */
1496 0xff, /* dst_mask */
1497 TRUE
), /* pcrel_offset */
1498 /* Low 20 bits of PLT symbol offset relative to GOT (GP). */
1499 HOWTO (R_NDS32_PLT_GOTREL_LO20
, /* type */
1501 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_dont
,/* complain_on_overflow */
1506 bfd_elf_generic_reloc
, /* special_function */
1507 "R_NDS32_PLT_GOTREL_LO20", /* name */
1508 FALSE
, /* partial_inplace */
1509 0x000fffff, /* src_mask */
1510 0x000fffff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1512 /* low 15 bits of PLT symbol offset relative to GOT (GP) */
1513 HOWTO (R_NDS32_PLT_GOTREL_LO15
, /* type */
1515 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 FALSE
, /* pc_relative */
1519 complain_overflow_dont
,/* complain_on_overflow */
1520 bfd_elf_generic_reloc
, /* special_function */
1521 "R_NDS32_PLT_GOTREL_LO15", /* name */
1522 FALSE
, /* partial_inplace */
1523 0x00007fff, /* src_mask */
1524 0x00007fff, /* dst_mask */
1525 FALSE
), /* pcrel_offset */
1526 /* Low 19 bits of PLT symbol offset relative to GOT (GP). */
1527 HOWTO (R_NDS32_PLT_GOTREL_LO19
, /* type */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 FALSE
, /* pc_relative */
1533 complain_overflow_dont
,/* complain_on_overflow */
1534 bfd_elf_generic_reloc
, /* special_function */
1535 "R_NDS32_PLT_GOTREL_LO19", /* name */
1536 FALSE
, /* partial_inplace */
1537 0x0007ffff, /* src_mask */
1538 0x0007ffff, /* dst_mask */
1539 FALSE
), /* pcrel_offset */
1540 HOWTO (R_NDS32_GOT_LO15
, /* type */
1542 2, /* size (0 = byte, 1 = short, 2 = long) */
1544 FALSE
, /* pc_relative */
1546 complain_overflow_dont
,/* complain_on_overflow */
1547 bfd_elf_generic_reloc
, /* special_function */
1548 "R_NDS32_GOT_LO15", /* name */
1549 FALSE
, /* partial_inplace */
1550 0x00007fff, /* src_mask */
1551 0x00007fff, /* dst_mask */
1552 FALSE
), /* pcrel_offset */
1553 HOWTO (R_NDS32_GOT_LO19
, /* type */
1555 2, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE
, /* pc_relative */
1559 complain_overflow_dont
,/* complain_on_overflow */
1560 bfd_elf_generic_reloc
, /* special_function */
1561 "R_NDS32_GOT_LO19", /* name */
1562 FALSE
, /* partial_inplace */
1563 0x0007ffff, /* src_mask */
1564 0x0007ffff, /* dst_mask */
1565 FALSE
), /* pcrel_offset */
1566 HOWTO (R_NDS32_GOTOFF_LO15
, /* type */
1568 2, /* size (0 = byte, 1 = short, 2 = long) */
1570 FALSE
, /* pc_relative */
1572 complain_overflow_dont
,/* complain_on_overflow */
1573 bfd_elf_generic_reloc
, /* special_function */
1574 "R_NDS32_GOTOFF_LO15", /* name */
1575 FALSE
, /* partial_inplace */
1576 0x00007fff, /* src_mask */
1577 0x00007fff, /* dst_mask */
1578 FALSE
), /* pcrel_offset */
1579 HOWTO (R_NDS32_GOTOFF_LO19
, /* type */
1581 2, /* size (0 = byte, 1 = short, 2 = long) */
1583 FALSE
, /* pc_relative */
1585 complain_overflow_dont
,/* complain_on_overflow */
1586 bfd_elf_generic_reloc
, /* special_function */
1587 "R_NDS32_GOTOFF_LO19", /* name */
1588 FALSE
, /* partial_inplace */
1589 0x0007ffff, /* src_mask */
1590 0x0007ffff, /* dst_mask */
1591 FALSE
), /* pcrel_offset */
1592 /* GOT 15 bits offset. */
1593 HOWTO (R_NDS32_GOT15S2_RELA
, /* type */
1595 2, /* size (0 = byte, 1 = short, 2 = long) */
1597 FALSE
, /* pc_relative */
1599 complain_overflow_signed
, /* complain_on_overflow */
1600 bfd_elf_generic_reloc
, /* special_function */
1601 "R_NDS32_GOT15S2_RELA",/* name */
1602 FALSE
, /* partial_inplace */
1603 0x00007fff, /* src_mask */
1604 0x00007fff, /* dst_mask */
1605 FALSE
), /* pcrel_offset */
1606 /* GOT 17 bits offset. */
1607 HOWTO (R_NDS32_GOT17S2_RELA
, /* type */
1609 2, /* size (0 = byte, 1 = short, 2 = long) */
1611 FALSE
, /* pc_relative */
1613 complain_overflow_signed
, /* complain_on_overflow */
1614 bfd_elf_generic_reloc
, /* special_function */
1615 "R_NDS32_GOT17S2_RELA",/* name */
1616 FALSE
, /* partial_inplace */
1617 0x0001ffff, /* src_mask */
1618 0x0001ffff, /* dst_mask */
1619 FALSE
), /* pcrel_offset */
1620 /* A 5 bit address. */
1621 HOWTO (R_NDS32_5_RELA
, /* type */
1623 1, /* size (0 = byte, 1 = short, 2 = long) */
1625 FALSE
, /* pc_relative */
1627 complain_overflow_signed
, /* complain_on_overflow */
1628 bfd_elf_generic_reloc
, /* special_function */
1629 "R_NDS32_5_RELA", /* name */
1630 FALSE
, /* partial_inplace */
1631 0x1f, /* src_mask */
1632 0x1f, /* dst_mask */
1633 FALSE
), /* pcrel_offset */
1634 HOWTO (R_NDS32_10_UPCREL_RELA
,/* type */
1636 1, /* size (0 = byte, 1 = short, 2 = long) */
1638 TRUE
, /* pc_relative */
1640 complain_overflow_unsigned
, /* complain_on_overflow */
1641 bfd_elf_generic_reloc
, /* special_function */
1642 "R_NDS32_10_UPCREL_RELA", /* name */
1643 FALSE
, /* partial_inplace */
1644 0x1ff, /* src_mask */
1645 0x1ff, /* dst_mask */
1646 TRUE
), /* pcrel_offset */
1647 HOWTO (R_NDS32_SDA_FP7U2_RELA
,/* type */
1649 1, /* size (0 = byte, 1 = short, 2 = long) */
1651 FALSE
, /* pc_relative */
1653 complain_overflow_unsigned
, /* complain_on_overflow */
1654 bfd_elf_generic_reloc
, /* special_function */
1655 "R_NDS32_SDA_FP7U2_RELA", /* name */
1656 FALSE
, /* partial_inplace */
1657 0x0000007f, /* src_mask */
1658 0x0000007f, /* dst_mask */
1659 FALSE
), /* pcrel_offset */
1660 HOWTO (R_NDS32_WORD_9_PCREL_RELA
, /* type */
1662 2, /* size (0 = byte, 1 = short, 2 = long) */
1664 TRUE
, /* pc_relative */
1666 complain_overflow_signed
, /* complain_on_overflow */
1667 bfd_elf_generic_reloc
, /* special_function */
1668 "R_NDS32_WORD_9_PCREL_RELA", /* name */
1669 FALSE
, /* partial_inplace */
1670 0xff, /* src_mask */
1671 0xff, /* dst_mask */
1672 TRUE
), /* pcrel_offset */
1673 HOWTO (R_NDS32_25_ABS_RELA
, /* type */
1675 2, /* size (0 = byte, 1 = short, 2 = long) */
1677 FALSE
, /* pc_relative */
1679 complain_overflow_dont
,/* complain_on_overflow */
1680 bfd_elf_generic_reloc
, /* special_function */
1681 "R_NDS32_25_ABS_RELA", /* name */
1682 FALSE
, /* partial_inplace */
1683 0xffffff, /* src_mask */
1684 0xffffff, /* dst_mask */
1685 FALSE
), /* pcrel_offset */
1687 /* A relative 17 bit relocation for ifc, right shifted by 1. */
1688 HOWTO (R_NDS32_17IFC_PCREL_RELA
, /* type */
1690 2, /* size (0 = byte, 1 = short, 2 = long) */
1692 TRUE
, /* pc_relative */
1694 complain_overflow_signed
, /* complain_on_overflow */
1695 bfd_elf_generic_reloc
, /* special_function */
1696 "R_NDS32_17IFC_PCREL_RELA", /* name */
1697 FALSE
, /* partial_inplace */
1698 0xffff, /* src_mask */
1699 0xffff, /* dst_mask */
1700 TRUE
), /* pcrel_offset */
1702 /* A relative unsigned 10 bit relocation for ifc, right shifted by 1. */
1703 HOWTO (R_NDS32_10IFCU_PCREL_RELA
, /* type */
1705 1, /* size (0 = byte, 1 = short, 2 = long) */
1707 TRUE
, /* pc_relative */
1709 complain_overflow_unsigned
, /* complain_on_overflow */
1710 bfd_elf_generic_reloc
, /* special_function */
1711 "R_NDS32_10IFCU_PCREL_RELA", /* name */
1712 FALSE
, /* partial_inplace */
1713 0x1ff, /* src_mask */
1714 0x1ff, /* dst_mask */
1715 TRUE
), /* pcrel_offset */
1717 /* Like R_NDS32_HI20, but referring to the TLS entry for the symbol. */
1718 HOWTO (R_NDS32_TLS_LE_HI20
, /* type */
1719 12, /* rightshift */
1720 2, /* size (0 = byte, 1 = short, 2 = long) */
1722 FALSE
, /* pc_relative */
1724 complain_overflow_dont
, /* complain_on_overflow */
1725 bfd_elf_generic_reloc
, /* special_function */
1726 "R_NDS32_TLS_LE_HI20", /* name */
1727 FALSE
, /* partial_inplace */
1728 0x000fffff, /* src_mask */
1729 0x000fffff, /* dst_mask */
1730 FALSE
), /* pcrel_offset */
1731 HOWTO (R_NDS32_TLS_LE_LO12
, /* type */
1733 2, /* size (0 = byte, 1 = short, 2 = long) */
1735 FALSE
, /* pc_relative */
1737 complain_overflow_dont
, /* complain_on_overflow */
1738 bfd_elf_generic_reloc
, /* special_function */
1739 "R_NDS32_TLS_LE_LO12", /* name */
1740 FALSE
, /* partial_inplace */
1741 0x00000fff, /* src_mask */
1742 0x00000fff, /* dst_mask */
1743 FALSE
), /* pcrel_offset */
1745 /* Like R_NDS32_HI20, but referring to the TLS entry for the symbol. */
1746 HOWTO (R_NDS32_TLS_IE_HI20
, /* type */
1747 12, /* rightshift */
1748 2, /* size (0 = byte, 1 = short, 2 = long) */
1750 FALSE
, /* pc_relative */
1752 complain_overflow_dont
, /* complain_on_overflow */
1753 bfd_elf_generic_reloc
, /* special_function */
1754 "R_NDS32_TLS_IE_HI20", /* name */
1755 FALSE
, /* partial_inplace */
1756 0x000fffff, /* src_mask */
1757 0x000fffff, /* dst_mask */
1758 FALSE
), /* pcrel_offset */
1759 HOWTO (R_NDS32_TLS_IE_LO12S2
, /* type */
1761 2, /* size (0 = byte, 1 = short, 2 = long) */
1763 FALSE
, /* pc_relative */
1765 complain_overflow_dont
, /* complain_on_overflow */
1766 bfd_elf_generic_reloc
, /* special_function */
1767 "R_NDS32_TLS_IE_LO12S2", /* name */
1768 FALSE
, /* partial_inplace */
1769 0x000003ff, /* src_mask */
1770 0x000003ff, /* dst_mask */
1771 FALSE
), /* pcrel_offset */
1772 /* Mark a TLS IE entry in GOT. */
1773 HOWTO (R_NDS32_TLS_TPOFF
, /* type */
1775 2, /* size (0 = byte, 1 = short, 2 = long) */
1777 FALSE
, /* pc_relative */
1779 complain_overflow_bitfield
, /* complain_on_overflow */
1780 bfd_elf_generic_reloc
, /* special_function */
1781 "R_NDS32_TLS_TPOFF", /* name */
1782 FALSE
, /* partial_inplace */
1783 0xffffffff, /* src_mask */
1784 0xffffffff, /* dst_mask */
1785 FALSE
), /* pcrel_offset */
1786 /* A 20 bit address. */
1787 HOWTO (R_NDS32_TLS_LE_20
, /* type */
1789 2, /* size (0 = byte, 1 = short, 2 = long) */
1791 FALSE
, /* pc_relative */
1793 complain_overflow_signed
, /* complain_on_overflow */
1794 bfd_elf_generic_reloc
, /* special_function */
1795 "R_NDS32_TLS_LE_20", /* name */
1796 FALSE
, /* partial_inplace */
1797 0xfffff, /* src_mask */
1798 0xfffff, /* dst_mask */
1799 FALSE
), /* pcrel_offset */
1800 HOWTO (R_NDS32_TLS_LE_15S0
, /* type */
1802 2, /* size (0 = byte, 1 = short, 2 = long) */
1804 FALSE
, /* pc_relative */
1806 complain_overflow_signed
, /* complain_on_overflow */
1807 bfd_elf_generic_reloc
, /* special_function */
1808 "R_NDS32_TLS_LE_15S0", /* name */
1809 FALSE
, /* partial_inplace */
1810 0x7fff, /* src_mask */
1811 0x7fff, /* dst_mask */
1812 FALSE
), /* pcrel_offset */
1813 HOWTO (R_NDS32_TLS_LE_15S1
, /* type */
1815 2, /* size (0 = byte, 1 = short, 2 = long) */
1817 FALSE
, /* pc_relative */
1819 complain_overflow_signed
, /* complain_on_overflow */
1820 bfd_elf_generic_reloc
, /* special_function */
1821 "R_NDS32_TLS_LE_15S1", /* name */
1822 FALSE
, /* partial_inplace */
1823 0x7fff, /* src_mask */
1824 0x7fff, /* dst_mask */
1825 FALSE
), /* pcrel_offset */
1826 HOWTO (R_NDS32_TLS_LE_15S2
, /* type */
1828 2, /* size (0 = byte, 1 = short, 2 = long) */
1830 FALSE
, /* pc_relative */
1832 complain_overflow_signed
, /* complain_on_overflow */
1833 bfd_elf_generic_reloc
, /* special_function */
1834 "R_NDS32_TLS_LE_15S2", /* name */
1835 FALSE
, /* partial_inplace */
1836 0x7fff, /* src_mask */
1837 0x7fff, /* dst_mask */
1838 FALSE
), /* pcrel_offset */
1840 /* Relax hint for unconditional call sequence */
1841 HOWTO (R_NDS32_LONGCALL4
, /* type */
1843 2, /* size (0 = byte, 1 = short, 2 = long) */
1845 FALSE
, /* pc_relative */
1847 complain_overflow_dont
, /* complain_on_overflow */
1848 nds32_elf_ignore_reloc
, /* special_function */
1849 "R_NDS32_LONGCALL4", /* name */
1850 FALSE
, /* partial_inplace */
1851 0xffffffff, /* src_mask */
1852 0xffffffff, /* dst_mask */
1853 FALSE
), /* pcrel_offset */
1855 /* Relax hint for conditional call sequence. */
1856 HOWTO (R_NDS32_LONGCALL5
, /* type */
1858 2, /* size (0 = byte, 1 = short, 2 = long) */
1860 FALSE
, /* pc_relative */
1862 complain_overflow_dont
, /* complain_on_overflow */
1863 nds32_elf_ignore_reloc
, /* special_function */
1864 "R_NDS32_LONGCALL5", /* name */
1865 FALSE
, /* partial_inplace */
1866 0xffffffff, /* src_mask */
1867 0xffffffff, /* dst_mask */
1868 FALSE
), /* pcrel_offset */
1870 /* Relax hint for conditional call sequence. */
1871 HOWTO (R_NDS32_LONGCALL6
, /* type */
1873 2, /* size (0 = byte, 1 = short, 2 = long) */
1875 FALSE
, /* pc_relative */
1877 complain_overflow_dont
, /* complain_on_overflow */
1878 nds32_elf_ignore_reloc
, /* special_function */
1879 "R_NDS32_LONGCALL6", /* name */
1880 FALSE
, /* partial_inplace */
1881 0xffffffff, /* src_mask */
1882 0xffffffff, /* dst_mask */
1883 FALSE
), /* pcrel_offset */
1885 /* Relax hint for unconditional branch sequence. */
1886 HOWTO (R_NDS32_LONGJUMP4
, /* type */
1888 2, /* size (0 = byte, 1 = short, 2 = long) */
1890 FALSE
, /* pc_relative */
1892 complain_overflow_dont
, /* complain_on_overflow */
1893 nds32_elf_ignore_reloc
, /* special_function */
1894 "R_NDS32_LONGJUMP4", /* name */
1895 FALSE
, /* partial_inplace */
1896 0xffffffff, /* src_mask */
1897 0xffffffff, /* dst_mask */
1898 FALSE
), /* pcrel_offset */
1900 /* Relax hint for conditional branch sequence. */
1901 HOWTO (R_NDS32_LONGJUMP5
, /* type */
1903 2, /* size (0 = byte, 1 = short, 2 = long) */
1905 FALSE
, /* pc_relative */
1907 complain_overflow_dont
, /* complain_on_overflow */
1908 nds32_elf_ignore_reloc
, /* special_function */
1909 "R_NDS32_LONGJUMP5", /* name */
1910 FALSE
, /* partial_inplace */
1911 0xffffffff, /* src_mask */
1912 0xffffffff, /* dst_mask */
1913 FALSE
), /* pcrel_offset */
1915 /* Relax hint for conditional branch sequence. */
1916 HOWTO (R_NDS32_LONGJUMP6
, /* type */
1918 2, /* size (0 = byte, 1 = short, 2 = long) */
1920 FALSE
, /* pc_relative */
1922 complain_overflow_dont
, /* complain_on_overflow */
1923 nds32_elf_ignore_reloc
, /* special_function */
1924 "R_NDS32_LONGJUMP6", /* name */
1925 FALSE
, /* partial_inplace */
1926 0xffffffff, /* src_mask */
1927 0xffffffff, /* dst_mask */
1928 FALSE
), /* pcrel_offset */
1930 /* Relax hint for conditional branch sequence. */
1931 HOWTO (R_NDS32_LONGJUMP7
, /* type */
1933 2, /* size (0 = byte, 1 = short, 2 = long) */
1935 FALSE
, /* pc_relative */
1937 complain_overflow_dont
, /* complain_on_overflow */
1938 nds32_elf_ignore_reloc
, /* special_function */
1939 "R_NDS32_LONGJUMP7", /* name */
1940 FALSE
, /* partial_inplace */
1941 0xffffffff, /* src_mask */
1942 0xffffffff, /* dst_mask */
1943 FALSE
), /* pcrel_offset */
1946 /* Relocations used for relaxation. */
1947 static reloc_howto_type nds32_elf_relax_howto_table
[] =
1949 HOWTO (R_NDS32_RELAX_ENTRY
, /* type */
1951 2, /* size (0 = byte, 1 = short, 2 = long) */
1953 FALSE
, /* pc_relative */
1955 complain_overflow_dont
,/* complain_on_overflow */
1956 nds32_elf_ignore_reloc
,/* special_function */
1957 "R_NDS32_RELAX_ENTRY", /* name */
1958 FALSE
, /* partial_inplace */
1959 0xffffffff, /* src_mask */
1960 0xffffffff, /* dst_mask */
1961 FALSE
), /* pcrel_offset */
1962 HOWTO (R_NDS32_GOT_SUFF
, /* type */
1964 2, /* size (0 = byte, 1 = short, 2 = long) */
1966 FALSE
, /* pc_relative */
1968 complain_overflow_dont
,/* complain_on_overflow */
1969 nds32_elf_ignore_reloc
,/* special_function */
1970 "R_NDS32_GOT_SUFF", /* name */
1971 FALSE
, /* partial_inplace */
1972 0xffffffff, /* src_mask */
1973 0xffffffff, /* dst_mask */
1974 FALSE
), /* pcrel_offset */
1975 HOWTO (R_NDS32_GOTOFF_SUFF
, /* type */
1977 2, /* size (0 = byte, 1 = short, 2 = long) */
1979 FALSE
, /* pc_relative */
1981 complain_overflow_bitfield
, /* complain_on_overflow */
1982 nds32_elf_ignore_reloc
,/* special_function */
1983 "R_NDS32_GOTOFF_SUFF", /* name */
1984 FALSE
, /* partial_inplace */
1985 0xffffffff, /* src_mask */
1986 0xffffffff, /* dst_mask */
1987 FALSE
), /* pcrel_offset */
1988 HOWTO (R_NDS32_PLT_GOT_SUFF
, /* type */
1990 2, /* size (0 = byte, 1 = short, 2 = long) */
1992 FALSE
, /* pc_relative */
1994 complain_overflow_dont
,/* complain_on_overflow */
1995 nds32_elf_ignore_reloc
,/* special_function */
1996 "R_NDS32_PLT_GOT_SUFF",/* name */
1997 FALSE
, /* partial_inplace */
1998 0xffffffff, /* src_mask */
1999 0xffffffff, /* dst_mask */
2000 FALSE
), /* pcrel_offset */
2001 HOWTO (R_NDS32_MULCALL_SUFF
, /* type */
2003 2, /* size (0 = byte, 1 = short, 2 = long) */
2005 FALSE
, /* pc_relative */
2007 complain_overflow_dont
,/* complain_on_overflow */
2008 nds32_elf_ignore_reloc
,/* special_function */
2009 "R_NDS32_MULCALL_SUFF",/* name */
2010 FALSE
, /* partial_inplace */
2011 0xffffffff, /* src_mask */
2012 0xffffffff, /* dst_mask */
2013 FALSE
), /* pcrel_offset */
2014 HOWTO (R_NDS32_PTR
, /* type */
2016 2, /* size (0 = byte, 1 = short, 2 = long) */
2018 FALSE
, /* pc_relative */
2020 complain_overflow_dont
,/* complain_on_overflow */
2021 nds32_elf_ignore_reloc
,/* special_function */
2022 "R_NDS32_PTR", /* name */
2023 FALSE
, /* partial_inplace */
2024 0xffffffff, /* src_mask */
2025 0xffffffff, /* dst_mask */
2026 FALSE
), /* pcrel_offset */
2027 HOWTO (R_NDS32_PTR_COUNT
, /* type */
2029 2, /* size (0 = byte, 1 = short, 2 = long) */
2031 FALSE
, /* pc_relative */
2033 complain_overflow_dont
,/* complain_on_overflow */
2034 nds32_elf_ignore_reloc
,/* special_function */
2035 "R_NDS32_PTR_COUNT", /* name */
2036 FALSE
, /* partial_inplace */
2037 0xffffffff, /* src_mask */
2038 0xffffffff, /* dst_mask */
2039 FALSE
), /* pcrel_offset */
2040 HOWTO (R_NDS32_PTR_RESOLVED
, /* type */
2042 2, /* size (0 = byte, 1 = short, 2 = long) */
2044 FALSE
, /* pc_relative */
2046 complain_overflow_dont
,/* complain_on_overflow */
2047 nds32_elf_ignore_reloc
,/* special_function */
2048 "R_NDS32_PTR_RESOLVED",/* name */
2049 FALSE
, /* partial_inplace */
2050 0xffffffff, /* src_mask */
2051 0xffffffff, /* dst_mask */
2052 FALSE
), /* pcrel_offset */
2053 HOWTO (R_NDS32_PLTBLOCK
, /* type */
2055 2, /* size (0 = byte, 1 = short, 2 = long) */
2057 FALSE
, /* pc_relative */
2059 complain_overflow_dont
,/* complain_on_overflow */
2060 nds32_elf_ignore_reloc
,/* special_function */
2061 "R_NDS32_PLTBLOCK", /* name */
2062 FALSE
, /* partial_inplace */
2063 0xffffffff, /* src_mask */
2064 0xffffffff, /* dst_mask */
2065 FALSE
), /* pcrel_offset */
2066 HOWTO (R_NDS32_RELAX_REGION_BEGIN
, /* type */
2068 2, /* size (0 = byte, 1 = short, 2 = long) */
2070 FALSE
, /* pc_relative */
2072 complain_overflow_dont
,/* complain_on_overflow */
2073 nds32_elf_ignore_reloc
,/* special_function */
2074 "R_NDS32_RELAX_REGION_BEGIN", /* name */
2075 FALSE
, /* partial_inplace */
2076 0xffffffff, /* src_mask */
2077 0xffffffff, /* dst_mask */
2078 FALSE
), /* pcrel_offset */
2079 HOWTO (R_NDS32_RELAX_REGION_END
, /* type */
2081 2, /* size (0 = byte, 1 = short, 2 = long) */
2083 FALSE
, /* pc_relative */
2085 complain_overflow_dont
,/* complain_on_overflow */
2086 nds32_elf_ignore_reloc
,/* special_function */
2087 "R_NDS32_RELAX_REGION_END", /* name */
2088 FALSE
, /* partial_inplace */
2089 0xffffffff, /* src_mask */
2090 0xffffffff, /* dst_mask */
2091 FALSE
), /* pcrel_offset */
2092 HOWTO (R_NDS32_MINUEND
, /* type */
2094 2, /* size (0 = byte, 1 = short, 2 = long) */
2096 FALSE
, /* pc_relative */
2098 complain_overflow_dont
,/* complain_on_overflow */
2099 nds32_elf_ignore_reloc
,/* special_function */
2100 "R_NDS32_MINUEND", /* name */
2101 FALSE
, /* partial_inplace */
2102 0xffffffff, /* src_mask */
2103 0xffffffff, /* dst_mask */
2104 FALSE
), /* pcrel_offset */
2105 HOWTO (R_NDS32_SUBTRAHEND
, /* type */
2107 2, /* size (0 = byte, 1 = short, 2 = long) */
2109 FALSE
, /* pc_relative */
2111 complain_overflow_dont
,/* complain_on_overflow */
2112 nds32_elf_ignore_reloc
,/* special_function */
2113 "R_NDS32_SUBTRAHEND", /* name */
2114 FALSE
, /* partial_inplace */
2115 0xffffffff, /* src_mask */
2116 0xffffffff, /* dst_mask */
2117 FALSE
), /* pcrel_offset */
2118 HOWTO (R_NDS32_DIFF8
, /* type */
2120 0, /* size (0 = byte, 1 = short, 2 = long) */
2122 FALSE
, /* pc_relative */
2124 complain_overflow_dont
,/* complain_on_overflow */
2125 nds32_elf_ignore_reloc
,/* special_function */
2126 "R_NDS32_DIFF8", /* name */
2127 FALSE
, /* partial_inplace */
2128 0x000000ff, /* src_mask */
2129 0x000000ff, /* dst_mask */
2130 FALSE
), /* pcrel_offset */
2131 HOWTO (R_NDS32_DIFF16
, /* type */
2133 1, /* size (0 = byte, 1 = short, 2 = long) */
2135 FALSE
, /* pc_relative */
2137 complain_overflow_dont
,/* complain_on_overflow */
2138 nds32_elf_ignore_reloc
,/* special_function */
2139 "R_NDS32_DIFF16", /* name */
2140 FALSE
, /* partial_inplace */
2141 0x0000ffff, /* src_mask */
2142 0x0000ffff, /* dst_mask */
2143 FALSE
), /* pcrel_offset */
2144 HOWTO (R_NDS32_DIFF32
, /* type */
2146 2, /* size (0 = byte, 1 = short, 2 = long) */
2148 FALSE
, /* pc_relative */
2150 complain_overflow_dont
,/* complain_on_overflow */
2151 nds32_elf_ignore_reloc
,/* special_function */
2152 "R_NDS32_DIFF32", /* name */
2153 FALSE
, /* partial_inplace */
2154 0xffffffff, /* src_mask */
2155 0xffffffff, /* dst_mask */
2156 FALSE
), /* pcrel_offset */
2157 HOWTO (R_NDS32_DIFF_ULEB128
, /* type */
2159 0, /* size (0 = byte, 1 = short, 2 = long) */
2161 FALSE
, /* pc_relative */
2163 complain_overflow_dont
,/* complain_on_overflow */
2164 nds32_elf_ignore_reloc
,/* special_function */
2165 "R_NDS32_DIFF_ULEB128",/* name */
2166 FALSE
, /* partial_inplace */
2167 0xffffffff, /* src_mask */
2168 0xffffffff, /* dst_mask */
2169 FALSE
), /* pcrel_offset */
2170 HOWTO (R_NDS32_DATA
, /* type */
2172 2, /* size (0 = byte, 1 = short, 2 = long) */
2174 FALSE
, /* pc_relative */
2176 complain_overflow_dont
,/* complain_on_overflow */
2177 nds32_elf_ignore_reloc
,/* special_function */
2178 "R_NDS32_DATA", /* name */
2179 FALSE
, /* partial_inplace */
2180 0xffffffff, /* src_mask */
2181 0xffffffff, /* dst_mask */
2182 FALSE
), /* pcrel_offset */
2183 HOWTO (R_NDS32_TRAN
, /* type */
2185 2, /* size (0 = byte, 1 = short, 2 = long) */
2187 FALSE
, /* pc_relative */
2189 complain_overflow_dont
,/* complain_on_overflow */
2190 nds32_elf_ignore_reloc
,/* special_function */
2191 "R_NDS32_TRAN", /* name */
2192 FALSE
, /* partial_inplace */
2193 0xffffffff, /* src_mask */
2194 0xffffffff, /* dst_mask */
2195 FALSE
), /* pcrel_offset */
2196 HOWTO (R_NDS32_TLS_LE_ADD
, /* type */
2198 2, /* size (0 = byte, 1 = short, 2 = long) */
2200 FALSE
, /* pc_relative */
2202 complain_overflow_dont
, /* complain_on_overflow */
2203 nds32_elf_ignore_reloc
, /* special_function */
2204 "R_NDS32_TLS_LE_ADD", /* name */
2205 FALSE
, /* partial_inplace */
2206 0xffffffff, /* src_mask */
2207 0xffffffff, /* dst_mask */
2208 FALSE
), /* pcrel_offset */
2209 HOWTO (R_NDS32_TLS_LE_LS
, /* type */
2211 2, /* size (0 = byte, 1 = short, 2 = long) */
2213 FALSE
, /* pc_relative */
2215 complain_overflow_dont
, /* complain_on_overflow */
2216 nds32_elf_ignore_reloc
, /* special_function */
2217 "R_NDS32_TLS_LE_LS", /* name */
2218 FALSE
, /* partial_inplace */
2219 0xffffffff, /* src_mask */
2220 0xffffffff, /* dst_mask */
2221 FALSE
), /* pcrel_offset */
2222 HOWTO (R_NDS32_EMPTY
, /* type */
2224 2, /* size (0 = byte, 1 = short, 2 = long) */
2226 FALSE
, /* pc_relative */
2228 complain_overflow_dont
, /* complain_on_overflow */
2229 nds32_elf_ignore_reloc
, /* special_function */
2230 "R_NDS32_EMPTY", /* name */
2231 FALSE
, /* partial_inplace */
2232 0xffffffff, /* src_mask */
2233 0xffffffff, /* dst_mask */
2234 FALSE
), /* pcrel_offset */
2238 /* nds32_insertion_sort sorts an array with nmemb elements of size size.
2239 This prototype is the same as qsort (). */
2242 nds32_insertion_sort (void *base
, size_t nmemb
, size_t size
,
2243 int (*compar
) (const void *lhs
, const void *rhs
))
2245 char *ptr
= (char *) base
;
2247 char *tmp
= xmalloc (size
);
2249 /* If i is less than j, i is inserted before j.
2251 |---- j ----- i --------------|
2256 for (i
= 1; i
< (int) nmemb
; i
++)
2258 for (j
= (i
- 1); j
>= 0; j
--)
2259 if (compar (ptr
+ i
* size
, ptr
+ j
* size
) >= 0)
2265 continue; /* i is in order. */
2267 memcpy (tmp
, ptr
+ i
* size
, size
);
2268 memmove (ptr
+ (j
+ 1) * size
, ptr
+ j
* size
, (i
- j
) * size
);
2269 memcpy (ptr
+ j
* size
, tmp
, size
);
2274 /* Sort relocation by r_offset.
2276 We didn't use qsort () in stdlib, because quick-sort is not a stable sorting
2277 algorithm. Relocations at the same r_offset must keep their order.
2278 For example, RELAX_ENTRY must be the very first relocation entry.
2280 Currently, this function implements insertion-sort.
2282 FIXME: If we already sort them in assembler, why bother sort them
2286 compar_reloc (const void *lhs
, const void *rhs
)
2288 const Elf_Internal_Rela
*l
= (const Elf_Internal_Rela
*) lhs
;
2289 const Elf_Internal_Rela
*r
= (const Elf_Internal_Rela
*) rhs
;
2291 if (l
->r_offset
> r
->r_offset
)
2293 else if (l
->r_offset
== r
->r_offset
)
2299 /* Functions listed below are only used for old relocs.
2300 * nds32_elf_9_pcrel_reloc
2301 * nds32_elf_do_9_pcrel_reloc
2302 * nds32_elf_hi20_reloc
2303 * nds32_elf_relocate_hi20
2304 * nds32_elf_lo12_reloc
2305 * nds32_elf_sda15_reloc
2306 * nds32_elf_generic_reloc
2309 /* Handle the R_NDS32_9_PCREL & R_NDS32_9_PCREL_RELA reloc. */
2311 static bfd_reloc_status_type
2312 nds32_elf_9_pcrel_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2313 void *data
, asection
*input_section
, bfd
*output_bfd
,
2314 char **error_message ATTRIBUTE_UNUSED
)
2316 /* This part is from bfd_elf_generic_reloc. */
2317 if (output_bfd
!= (bfd
*) NULL
2318 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2319 && (!reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
2321 reloc_entry
->address
+= input_section
->output_offset
;
2322 return bfd_reloc_ok
;
2325 if (output_bfd
!= NULL
)
2327 /* FIXME: See bfd_perform_relocation. Is this right? */
2328 return bfd_reloc_continue
;
2331 return nds32_elf_do_9_pcrel_reloc (abfd
, reloc_entry
->howto
,
2333 data
, reloc_entry
->address
,
2336 + symbol
->section
->output_section
->vma
2337 + symbol
->section
->output_offset
),
2338 reloc_entry
->addend
);
2341 /* Utility to actually perform an R_NDS32_9_PCREL reloc. */
2342 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
2344 static bfd_reloc_status_type
2345 nds32_elf_do_9_pcrel_reloc (bfd
*abfd
, reloc_howto_type
*howto
,
2346 asection
*input_section
, bfd_byte
*data
,
2348 asection
*symbol_section ATTRIBUTE_UNUSED
,
2349 bfd_vma symbol_value
, bfd_vma addend
)
2351 bfd_signed_vma relocation
;
2353 bfd_reloc_status_type status
;
2355 /* Sanity check the address (offset in section). */
2356 if (offset
> bfd_get_section_limit (abfd
, input_section
))
2357 return bfd_reloc_outofrange
;
2359 relocation
= symbol_value
+ addend
;
2360 /* Make it pc relative. */
2361 relocation
-= (input_section
->output_section
->vma
2362 + input_section
->output_offset
);
2363 /* These jumps mask off the lower two bits of the current address
2364 before doing pcrel calculations. */
2365 relocation
-= (offset
& -(bfd_vma
) 2);
2367 if (relocation
< -ACCURATE_8BIT_S1
|| relocation
>= ACCURATE_8BIT_S1
)
2368 status
= bfd_reloc_overflow
;
2370 status
= bfd_reloc_ok
;
2372 x
= bfd_getb16 (data
+ offset
);
2374 relocation
>>= howto
->rightshift
;
2375 relocation
<<= howto
->bitpos
;
2376 x
= (x
& ~howto
->dst_mask
)
2377 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
);
2379 bfd_putb16 ((bfd_vma
) x
, data
+ offset
);
2384 /* Handle the R_NDS32_HI20_[SU]LO relocs.
2385 HI20_SLO is for the add3 and load/store with displacement instructions.
2386 HI20 is for the or3 instruction.
2387 For R_NDS32_HI20_SLO, the lower 16 bits are sign extended when added to
2388 the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
2389 we must add one to the high 16 bytes (which will get subtracted off when
2390 the low 16 bits are added).
2391 These relocs have to be done in combination with an R_NDS32_LO12 reloc
2392 because there is a carry from the LO12 to the HI20. Here we just save
2393 the information we need; we do the actual relocation when we see the LO12.
2394 This code is copied from the elf32-mips.c. We also support an arbitrary
2395 number of HI20 relocs to be associated with a single LO12 reloc. The
2396 assembler sorts the relocs to ensure each HI20 immediately precedes its
2397 LO12. However if there are multiple copies, the assembler may not find
2398 the real LO12 so it picks the first one it finds. */
2402 struct nds32_hi20
*next
;
2407 static struct nds32_hi20
*nds32_hi20_list
;
2409 static bfd_reloc_status_type
2410 nds32_elf_hi20_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2411 asymbol
*symbol
, void *data
, asection
*input_section
,
2412 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2414 bfd_reloc_status_type ret
;
2416 struct nds32_hi20
*n
;
2418 /* This part is from bfd_elf_generic_reloc.
2419 If we're relocating, and this an external symbol, we don't want
2420 to change anything. */
2421 if (output_bfd
!= (bfd
*) NULL
2422 && (symbol
->flags
& BSF_SECTION_SYM
) == 0 && reloc_entry
->addend
== 0)
2424 reloc_entry
->address
+= input_section
->output_offset
;
2425 return bfd_reloc_ok
;
2428 /* Sanity check the address (offset in section). */
2429 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2430 return bfd_reloc_outofrange
;
2433 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
2434 ret
= bfd_reloc_undefined
;
2436 if (bfd_is_com_section (symbol
->section
))
2439 relocation
= symbol
->value
;
2441 relocation
+= symbol
->section
->output_section
->vma
;
2442 relocation
+= symbol
->section
->output_offset
;
2443 relocation
+= reloc_entry
->addend
;
2445 /* Save the information, and let LO12 do the actual relocation. */
2446 n
= (struct nds32_hi20
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
2448 return bfd_reloc_outofrange
;
2450 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
2451 n
->addend
= relocation
;
2452 n
->next
= nds32_hi20_list
;
2453 nds32_hi20_list
= n
;
2455 if (output_bfd
!= (bfd
*) NULL
)
2456 reloc_entry
->address
+= input_section
->output_offset
;
2461 /* Handle an NDS32 ELF HI20 reloc. */
2464 nds32_elf_relocate_hi20 (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2465 int type ATTRIBUTE_UNUSED
, Elf_Internal_Rela
*relhi
,
2466 Elf_Internal_Rela
*rello
, bfd_byte
*contents
,
2472 insn
= bfd_getb32 (contents
+ relhi
->r_offset
);
2474 addlo
= bfd_getb32 (contents
+ rello
->r_offset
);
2477 addend
+= ((insn
& 0xfffff) << 20) + addlo
;
2479 insn
= (insn
& 0xfff00000) | ((addend
>> 12) & 0xfffff);
2480 bfd_putb32 (insn
, contents
+ relhi
->r_offset
);
2483 /* Do an R_NDS32_LO12 relocation. This is a straightforward 12 bit
2484 inplace relocation; this function exists in order to do the
2485 R_NDS32_HI20_[SU]LO relocation described above. */
2487 static bfd_reloc_status_type
2488 nds32_elf_lo12_reloc (bfd
*input_bfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2489 void *data
, asection
*input_section
, bfd
*output_bfd
,
2490 char **error_message
)
2492 /* This part is from bfd_elf_generic_reloc.
2493 If we're relocating, and this an external symbol, we don't want
2494 to change anything. */
2495 if (output_bfd
!= NULL
&& (symbol
->flags
& BSF_SECTION_SYM
) == 0
2496 && reloc_entry
->addend
== 0)
2498 reloc_entry
->address
+= input_section
->output_offset
;
2499 return bfd_reloc_ok
;
2502 if (nds32_hi20_list
!= NULL
)
2504 struct nds32_hi20
*l
;
2506 l
= nds32_hi20_list
;
2511 unsigned long vallo
;
2512 struct nds32_hi20
*next
;
2514 /* Do the HI20 relocation. Note that we actually don't need
2515 to know anything about the LO12 itself, except where to
2516 find the low 12 bits of the addend needed by the LO12. */
2517 insn
= bfd_getb32 (l
->addr
);
2518 vallo
= bfd_getb32 ((bfd_byte
*) data
+ reloc_entry
->address
);
2520 switch (reloc_entry
->howto
->type
)
2522 case R_NDS32_LO12S3
:
2526 case R_NDS32_LO12S2
:
2530 case R_NDS32_LO12S1
:
2534 case R_NDS32_LO12S0
:
2539 val
= ((insn
& 0xfffff) << 12) + vallo
;
2542 insn
= (insn
& ~(bfd_vma
) 0xfffff) | ((val
>> 12) & 0xfffff);
2543 bfd_putb32 ((bfd_vma
) insn
, l
->addr
);
2550 nds32_hi20_list
= NULL
;
2553 /* Now do the LO12 reloc in the usual way.
2554 ??? It would be nice to call bfd_elf_generic_reloc here,
2555 but we have partial_inplace set. bfd_elf_generic_reloc will
2556 pass the handling back to bfd_install_relocation which will install
2557 a section relative addend which is wrong. */
2558 return nds32_elf_generic_reloc (input_bfd
, reloc_entry
, symbol
, data
,
2559 input_section
, output_bfd
, error_message
);
2562 /* Do generic partial_inplace relocation.
2563 This is a local replacement for bfd_elf_generic_reloc. */
2565 static bfd_reloc_status_type
2566 nds32_elf_generic_reloc (bfd
*input_bfd
, arelent
*reloc_entry
,
2567 asymbol
*symbol
, void *data
, asection
*input_section
,
2568 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2570 bfd_reloc_status_type ret
;
2572 bfd_byte
*inplace_address
;
2574 /* This part is from bfd_elf_generic_reloc.
2575 If we're relocating, and this an external symbol, we don't want
2576 to change anything. */
2577 if (output_bfd
!= NULL
&& (symbol
->flags
& BSF_SECTION_SYM
) == 0
2578 && reloc_entry
->addend
== 0)
2580 reloc_entry
->address
+= input_section
->output_offset
;
2581 return bfd_reloc_ok
;
2584 /* Now do the reloc in the usual way.
2585 ??? It would be nice to call bfd_elf_generic_reloc here,
2586 but we have partial_inplace set. bfd_elf_generic_reloc will
2587 pass the handling back to bfd_install_relocation which will install
2588 a section relative addend which is wrong. */
2590 /* Sanity check the address (offset in section). */
2591 if (reloc_entry
->address
> bfd_get_section_limit (input_bfd
, input_section
))
2592 return bfd_reloc_outofrange
;
2595 if (bfd_is_und_section (symbol
->section
) && output_bfd
== (bfd
*) NULL
)
2596 ret
= bfd_reloc_undefined
;
2598 if (bfd_is_com_section (symbol
->section
) || output_bfd
!= (bfd
*) NULL
)
2601 relocation
= symbol
->value
;
2603 /* Only do this for a final link. */
2604 if (output_bfd
== (bfd
*) NULL
)
2606 relocation
+= symbol
->section
->output_section
->vma
;
2607 relocation
+= symbol
->section
->output_offset
;
2610 relocation
+= reloc_entry
->addend
;
2611 switch (reloc_entry
->howto
->type
)
2613 case R_NDS32_LO12S3
:
2617 case R_NDS32_LO12S2
:
2621 case R_NDS32_LO12S1
:
2625 case R_NDS32_LO12S0
:
2631 inplace_address
= (bfd_byte
*) data
+ reloc_entry
->address
;
2634 x = ((x & ~reloc_entry->howto->dst_mask) | \
2635 (((x & reloc_entry->howto->src_mask) + relocation) & \
2636 reloc_entry->howto->dst_mask))
2638 switch (reloc_entry
->howto
->size
)
2642 short x
= bfd_getb16 (inplace_address
);
2645 bfd_putb16 ((bfd_vma
) x
, inplace_address
);
2650 unsigned long x
= bfd_getb32 (inplace_address
);
2653 bfd_putb32 ((bfd_vma
) x
, inplace_address
);
2660 if (output_bfd
!= (bfd
*) NULL
)
2661 reloc_entry
->address
+= input_section
->output_offset
;
2666 /* Handle the R_NDS32_SDA15 reloc.
2667 This reloc is used to compute the address of objects in the small data area
2668 and to perform loads and stores from that area.
2669 The lower 15 bits are sign extended and added to the register specified
2670 in the instruction, which is assumed to point to _SDA_BASE_.
2672 Since the lower 15 bits offset is left-shifted 0, 1 or 2 bits depending on
2673 the access size, this must be taken care of. */
2675 static bfd_reloc_status_type
2676 nds32_elf_sda15_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2677 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2678 asection
*input_section
, bfd
*output_bfd
,
2679 char **error_message ATTRIBUTE_UNUSED
)
2681 /* This part is from bfd_elf_generic_reloc. */
2682 if (output_bfd
!= (bfd
*) NULL
2683 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
2684 && (!reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
2686 reloc_entry
->address
+= input_section
->output_offset
;
2687 return bfd_reloc_ok
;
2690 if (output_bfd
!= NULL
)
2692 /* FIXME: See bfd_perform_relocation. Is this right? */
2693 return bfd_reloc_continue
;
2696 /* FIXME: not sure what to do here yet. But then again, the linker
2697 may never call us. */
2701 /* nds32_elf_ignore_reloc is the special function for
2702 relocation types which don't need to be relocated
2703 like relaxation relocation types.
2704 This function simply return bfd_reloc_ok when it is
2707 static bfd_reloc_status_type
2708 nds32_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2709 asymbol
*symbol ATTRIBUTE_UNUSED
,
2710 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
2711 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
2713 if (output_bfd
!= NULL
)
2714 reloc_entry
->address
+= input_section
->output_offset
;
2716 return bfd_reloc_ok
;
2720 /* Map BFD reloc types to NDS32 ELF reloc types. */
2722 struct nds32_reloc_map_entry
2724 bfd_reloc_code_real_type bfd_reloc_val
;
2725 unsigned char elf_reloc_val
;
2728 static const struct nds32_reloc_map_entry nds32_reloc_map
[] =
2730 {BFD_RELOC_NONE
, R_NDS32_NONE
},
2731 {BFD_RELOC_16
, R_NDS32_16_RELA
},
2732 {BFD_RELOC_32
, R_NDS32_32_RELA
},
2733 {BFD_RELOC_NDS32_20
, R_NDS32_20_RELA
},
2734 {BFD_RELOC_NDS32_5
, R_NDS32_5_RELA
},
2735 {BFD_RELOC_NDS32_9_PCREL
, R_NDS32_9_PCREL_RELA
},
2736 {BFD_RELOC_NDS32_WORD_9_PCREL
, R_NDS32_WORD_9_PCREL_RELA
},
2737 {BFD_RELOC_NDS32_15_PCREL
, R_NDS32_15_PCREL_RELA
},
2738 {BFD_RELOC_NDS32_17_PCREL
, R_NDS32_17_PCREL_RELA
},
2739 {BFD_RELOC_NDS32_25_PCREL
, R_NDS32_25_PCREL_RELA
},
2740 {BFD_RELOC_NDS32_10_UPCREL
, R_NDS32_10_UPCREL_RELA
},
2741 {BFD_RELOC_NDS32_HI20
, R_NDS32_HI20_RELA
},
2742 {BFD_RELOC_NDS32_LO12S3
, R_NDS32_LO12S3_RELA
},
2743 {BFD_RELOC_NDS32_LO12S2
, R_NDS32_LO12S2_RELA
},
2744 {BFD_RELOC_NDS32_LO12S1
, R_NDS32_LO12S1_RELA
},
2745 {BFD_RELOC_NDS32_LO12S0
, R_NDS32_LO12S0_RELA
},
2746 {BFD_RELOC_NDS32_LO12S0_ORI
, R_NDS32_LO12S0_ORI_RELA
},
2747 {BFD_RELOC_NDS32_SDA15S3
, R_NDS32_SDA15S3_RELA
},
2748 {BFD_RELOC_NDS32_SDA15S2
, R_NDS32_SDA15S2_RELA
},
2749 {BFD_RELOC_NDS32_SDA15S1
, R_NDS32_SDA15S1_RELA
},
2750 {BFD_RELOC_NDS32_SDA15S0
, R_NDS32_SDA15S0_RELA
},
2751 {BFD_RELOC_VTABLE_INHERIT
, R_NDS32_RELA_GNU_VTINHERIT
},
2752 {BFD_RELOC_VTABLE_ENTRY
, R_NDS32_RELA_GNU_VTENTRY
},
2754 {BFD_RELOC_NDS32_GOT20
, R_NDS32_GOT20
},
2755 {BFD_RELOC_NDS32_9_PLTREL
, R_NDS32_9_PLTREL
},
2756 {BFD_RELOC_NDS32_25_PLTREL
, R_NDS32_25_PLTREL
},
2757 {BFD_RELOC_NDS32_COPY
, R_NDS32_COPY
},
2758 {BFD_RELOC_NDS32_GLOB_DAT
, R_NDS32_GLOB_DAT
},
2759 {BFD_RELOC_NDS32_JMP_SLOT
, R_NDS32_JMP_SLOT
},
2760 {BFD_RELOC_NDS32_RELATIVE
, R_NDS32_RELATIVE
},
2761 {BFD_RELOC_NDS32_GOTOFF
, R_NDS32_GOTOFF
},
2762 {BFD_RELOC_NDS32_GOTPC20
, R_NDS32_GOTPC20
},
2763 {BFD_RELOC_NDS32_GOT_HI20
, R_NDS32_GOT_HI20
},
2764 {BFD_RELOC_NDS32_GOT_LO12
, R_NDS32_GOT_LO12
},
2765 {BFD_RELOC_NDS32_GOT_LO15
, R_NDS32_GOT_LO15
},
2766 {BFD_RELOC_NDS32_GOT_LO19
, R_NDS32_GOT_LO19
},
2767 {BFD_RELOC_NDS32_GOTPC_HI20
, R_NDS32_GOTPC_HI20
},
2768 {BFD_RELOC_NDS32_GOTPC_LO12
, R_NDS32_GOTPC_LO12
},
2769 {BFD_RELOC_NDS32_GOTOFF_HI20
, R_NDS32_GOTOFF_HI20
},
2770 {BFD_RELOC_NDS32_GOTOFF_LO12
, R_NDS32_GOTOFF_LO12
},
2771 {BFD_RELOC_NDS32_GOTOFF_LO15
, R_NDS32_GOTOFF_LO15
},
2772 {BFD_RELOC_NDS32_GOTOFF_LO19
, R_NDS32_GOTOFF_LO19
},
2773 {BFD_RELOC_NDS32_INSN16
, R_NDS32_INSN16
},
2774 {BFD_RELOC_NDS32_LABEL
, R_NDS32_LABEL
},
2775 {BFD_RELOC_NDS32_LONGCALL1
, R_NDS32_LONGCALL1
},
2776 {BFD_RELOC_NDS32_LONGCALL2
, R_NDS32_LONGCALL2
},
2777 {BFD_RELOC_NDS32_LONGCALL3
, R_NDS32_LONGCALL3
},
2778 {BFD_RELOC_NDS32_LONGCALL4
, R_NDS32_LONGCALL4
},
2779 {BFD_RELOC_NDS32_LONGCALL5
, R_NDS32_LONGCALL5
},
2780 {BFD_RELOC_NDS32_LONGCALL6
, R_NDS32_LONGCALL6
},
2781 {BFD_RELOC_NDS32_LONGJUMP1
, R_NDS32_LONGJUMP1
},
2782 {BFD_RELOC_NDS32_LONGJUMP2
, R_NDS32_LONGJUMP2
},
2783 {BFD_RELOC_NDS32_LONGJUMP3
, R_NDS32_LONGJUMP3
},
2784 {BFD_RELOC_NDS32_LONGJUMP4
, R_NDS32_LONGJUMP4
},
2785 {BFD_RELOC_NDS32_LONGJUMP5
, R_NDS32_LONGJUMP5
},
2786 {BFD_RELOC_NDS32_LONGJUMP6
, R_NDS32_LONGJUMP6
},
2787 {BFD_RELOC_NDS32_LONGJUMP7
, R_NDS32_LONGJUMP7
},
2788 {BFD_RELOC_NDS32_LOADSTORE
, R_NDS32_LOADSTORE
},
2789 {BFD_RELOC_NDS32_9_FIXED
, R_NDS32_9_FIXED_RELA
},
2790 {BFD_RELOC_NDS32_15_FIXED
, R_NDS32_15_FIXED_RELA
},
2791 {BFD_RELOC_NDS32_17_FIXED
, R_NDS32_17_FIXED_RELA
},
2792 {BFD_RELOC_NDS32_25_FIXED
, R_NDS32_25_FIXED_RELA
},
2793 {BFD_RELOC_NDS32_PLTREL_HI20
, R_NDS32_PLTREL_HI20
},
2794 {BFD_RELOC_NDS32_PLTREL_LO12
, R_NDS32_PLTREL_LO12
},
2795 {BFD_RELOC_NDS32_PLT_GOTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
},
2796 {BFD_RELOC_NDS32_PLT_GOTREL_LO12
, R_NDS32_PLT_GOTREL_LO12
},
2797 {BFD_RELOC_NDS32_PLT_GOTREL_LO15
, R_NDS32_PLT_GOTREL_LO15
},
2798 {BFD_RELOC_NDS32_PLT_GOTREL_LO19
, R_NDS32_PLT_GOTREL_LO19
},
2799 {BFD_RELOC_NDS32_PLT_GOTREL_LO20
, R_NDS32_PLT_GOTREL_LO20
},
2800 {BFD_RELOC_NDS32_SDA12S2_DP
, R_NDS32_SDA12S2_DP_RELA
},
2801 {BFD_RELOC_NDS32_SDA12S2_SP
, R_NDS32_SDA12S2_SP_RELA
},
2802 {BFD_RELOC_NDS32_LO12S2_DP
, R_NDS32_LO12S2_DP_RELA
},
2803 {BFD_RELOC_NDS32_LO12S2_SP
, R_NDS32_LO12S2_SP_RELA
},
2804 {BFD_RELOC_NDS32_SDA16S3
, R_NDS32_SDA16S3_RELA
},
2805 {BFD_RELOC_NDS32_SDA17S2
, R_NDS32_SDA17S2_RELA
},
2806 {BFD_RELOC_NDS32_SDA18S1
, R_NDS32_SDA18S1_RELA
},
2807 {BFD_RELOC_NDS32_SDA19S0
, R_NDS32_SDA19S0_RELA
},
2808 {BFD_RELOC_NDS32_SDA_FP7U2_RELA
, R_NDS32_SDA_FP7U2_RELA
},
2809 {BFD_RELOC_NDS32_DWARF2_OP1
, R_NDS32_DWARF2_OP1_RELA
},
2810 {BFD_RELOC_NDS32_DWARF2_OP2
, R_NDS32_DWARF2_OP2_RELA
},
2811 {BFD_RELOC_NDS32_DWARF2_LEB
, R_NDS32_DWARF2_LEB_RELA
},
2812 {BFD_RELOC_NDS32_UPDATE_TA
, R_NDS32_UPDATE_TA_RELA
},
2813 {BFD_RELOC_NDS32_GOT_SUFF
, R_NDS32_GOT_SUFF
},
2814 {BFD_RELOC_NDS32_GOTOFF_SUFF
, R_NDS32_GOTOFF_SUFF
},
2815 {BFD_RELOC_NDS32_GOT15S2
, R_NDS32_GOT15S2_RELA
},
2816 {BFD_RELOC_NDS32_GOT17S2
, R_NDS32_GOT17S2_RELA
},
2817 {BFD_RELOC_NDS32_PTR
, R_NDS32_PTR
},
2818 {BFD_RELOC_NDS32_PTR_COUNT
, R_NDS32_PTR_COUNT
},
2819 {BFD_RELOC_NDS32_PLT_GOT_SUFF
, R_NDS32_PLT_GOT_SUFF
},
2820 {BFD_RELOC_NDS32_PTR_RESOLVED
, R_NDS32_PTR_RESOLVED
},
2821 {BFD_RELOC_NDS32_RELAX_ENTRY
, R_NDS32_RELAX_ENTRY
},
2822 {BFD_RELOC_NDS32_MULCALL_SUFF
, R_NDS32_MULCALL_SUFF
},
2823 {BFD_RELOC_NDS32_PLTBLOCK
, R_NDS32_PLTBLOCK
},
2824 {BFD_RELOC_NDS32_RELAX_REGION_BEGIN
, R_NDS32_RELAX_REGION_BEGIN
},
2825 {BFD_RELOC_NDS32_RELAX_REGION_END
, R_NDS32_RELAX_REGION_END
},
2826 {BFD_RELOC_NDS32_MINUEND
, R_NDS32_MINUEND
},
2827 {BFD_RELOC_NDS32_SUBTRAHEND
, R_NDS32_SUBTRAHEND
},
2828 {BFD_RELOC_NDS32_EMPTY
, R_NDS32_EMPTY
},
2830 {BFD_RELOC_NDS32_DIFF8
, R_NDS32_DIFF8
},
2831 {BFD_RELOC_NDS32_DIFF16
, R_NDS32_DIFF16
},
2832 {BFD_RELOC_NDS32_DIFF32
, R_NDS32_DIFF32
},
2833 {BFD_RELOC_NDS32_DIFF_ULEB128
, R_NDS32_DIFF_ULEB128
},
2834 {BFD_RELOC_NDS32_25_ABS
, R_NDS32_25_ABS_RELA
},
2835 {BFD_RELOC_NDS32_DATA
, R_NDS32_DATA
},
2836 {BFD_RELOC_NDS32_TRAN
, R_NDS32_TRAN
},
2837 {BFD_RELOC_NDS32_17IFC_PCREL
, R_NDS32_17IFC_PCREL_RELA
},
2838 {BFD_RELOC_NDS32_10IFCU_PCREL
, R_NDS32_10IFCU_PCREL_RELA
},
2839 {BFD_RELOC_NDS32_TLS_LE_HI20
, R_NDS32_TLS_LE_HI20
},
2840 {BFD_RELOC_NDS32_TLS_LE_LO12
, R_NDS32_TLS_LE_LO12
},
2841 {BFD_RELOC_NDS32_TLS_LE_ADD
, R_NDS32_TLS_LE_ADD
},
2842 {BFD_RELOC_NDS32_TLS_LE_LS
, R_NDS32_TLS_LE_LS
},
2843 {BFD_RELOC_NDS32_TLS_IE_HI20
, R_NDS32_TLS_IE_HI20
},
2844 {BFD_RELOC_NDS32_TLS_IE_LO12S2
, R_NDS32_TLS_IE_LO12S2
},
2845 {BFD_RELOC_NDS32_TLS_TPOFF
, R_NDS32_TLS_TPOFF
},
2846 {BFD_RELOC_NDS32_TLS_LE_20
, R_NDS32_TLS_LE_20
},
2847 {BFD_RELOC_NDS32_TLS_LE_15S0
, R_NDS32_TLS_LE_15S0
},
2848 {BFD_RELOC_NDS32_TLS_LE_15S1
, R_NDS32_TLS_LE_15S1
},
2849 {BFD_RELOC_NDS32_TLS_LE_15S2
, R_NDS32_TLS_LE_15S2
},
2854 static reloc_howto_type
*
2855 bfd_elf32_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2860 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_howto_table
); i
++)
2861 if (nds32_elf_howto_table
[i
].name
!= NULL
2862 && strcasecmp (nds32_elf_howto_table
[i
].name
, r_name
) == 0)
2863 return &nds32_elf_howto_table
[i
];
2865 for (i
= 0; i
< ARRAY_SIZE (nds32_elf_relax_howto_table
); i
++)
2866 if (nds32_elf_relax_howto_table
[i
].name
!= NULL
2867 && strcasecmp (nds32_elf_relax_howto_table
[i
].name
, r_name
) == 0)
2868 return &nds32_elf_relax_howto_table
[i
];
2873 static reloc_howto_type
*
2874 bfd_elf32_bfd_reloc_type_table_lookup (enum elf_nds32_reloc_type code
)
2876 if (code
< R_NDS32_RELAX_ENTRY
)
2878 BFD_ASSERT (code
< ARRAY_SIZE (nds32_elf_howto_table
));
2879 return &nds32_elf_howto_table
[code
];
2883 BFD_ASSERT ((size_t) (code
- R_NDS32_RELAX_ENTRY
)
2884 < ARRAY_SIZE (nds32_elf_relax_howto_table
));
2885 return &nds32_elf_relax_howto_table
[code
- R_NDS32_RELAX_ENTRY
];
2889 static reloc_howto_type
*
2890 bfd_elf32_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2891 bfd_reloc_code_real_type code
)
2895 for (i
= 0; i
< ARRAY_SIZE (nds32_reloc_map
); i
++)
2897 if (nds32_reloc_map
[i
].bfd_reloc_val
== code
)
2898 return bfd_elf32_bfd_reloc_type_table_lookup
2899 (nds32_reloc_map
[i
].elf_reloc_val
);
2905 /* Set the howto pointer for an NDS32 ELF reloc. */
2908 nds32_info_to_howto_rel (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2909 Elf_Internal_Rela
*dst
)
2911 enum elf_nds32_reloc_type r_type
;
2913 r_type
= ELF32_R_TYPE (dst
->r_info
);
2914 if (r_type
> R_NDS32_GNU_VTENTRY
)
2916 /* xgettext:c-format */
2917 _bfd_error_handler (_("%B: invalid NDS32 reloc number: %d"), abfd
, r_type
);
2920 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
2924 nds32_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2925 Elf_Internal_Rela
*dst
)
2927 BFD_ASSERT ((ELF32_R_TYPE (dst
->r_info
) == R_NDS32_NONE
)
2928 || ((ELF32_R_TYPE (dst
->r_info
) > R_NDS32_GNU_VTENTRY
)
2929 && (ELF32_R_TYPE (dst
->r_info
) < R_NDS32_max
)));
2930 cache_ptr
->howto
= bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (dst
->r_info
));
2933 /* Support for core dump NOTE sections.
2934 Reference to include/linux/elfcore.h in Linux. */
2937 nds32_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2942 switch (note
->descsz
)
2945 /* Linux/NDS32 32-bit, ABI1 */
2948 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2951 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2959 /* Linux/NDS32 32-bit */
2962 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2965 elf_tdata (abfd
)->core
->pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2976 /* Make a ".reg" section. */
2977 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2978 size
, note
->descpos
+ offset
);
2982 nds32_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2984 switch (note
->descsz
)
2989 /* __kernel_uid_t, __kernel_gid_t are short on NDS32 platform. */
2990 elf_tdata (abfd
)->core
->program
=
2991 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
2992 elf_tdata (abfd
)->core
->command
=
2993 _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
3000 /* Note that for some reason, a spurious space is tacked
3001 onto the end of the args in some (at least one anyway)
3002 implementations, so strip it off if it exists. */
3004 char *command
= elf_tdata (abfd
)->core
->command
;
3005 int n
= strlen (command
);
3007 if (0 < n
&& command
[n
- 1] == ' ')
3008 command
[n
- 1] = '\0';
3014 /* Hook called by the linker routine which adds symbols from an object
3015 file. We must handle the special NDS32 section numbers here.
3016 We also keep watching for whether we need to create the sdata special
3020 nds32_elf_add_symbol_hook (bfd
*abfd
,
3021 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3022 Elf_Internal_Sym
*sym
,
3023 const char **namep ATTRIBUTE_UNUSED
,
3024 flagword
*flagsp ATTRIBUTE_UNUSED
,
3025 asection
**secp
, bfd_vma
*valp
)
3027 switch (sym
->st_shndx
)
3030 /* Common symbols less than the GP size are automatically
3031 treated as SHN_MIPS_SCOMMON symbols. */
3032 if (sym
->st_size
> elf_gp_size (abfd
)
3033 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
)
3036 /* st_value is the alignemnt constraint.
3037 That might be its actual size if it is an array or structure. */
3038 switch (sym
->st_value
)
3041 *secp
= bfd_make_section_old_way (abfd
, ".scommon_b");
3044 *secp
= bfd_make_section_old_way (abfd
, ".scommon_h");
3047 *secp
= bfd_make_section_old_way (abfd
, ".scommon_w");
3050 *secp
= bfd_make_section_old_way (abfd
, ".scommon_d");
3056 (*secp
)->flags
|= SEC_IS_COMMON
;
3057 *valp
= sym
->st_size
;
3065 /* This function can figure out the best location for a base register to access
3066 data relative to this base register
3068 sda_d0: size of first DOUBLE WORD data section
3069 sda_w0: size of first WORD data section
3070 sda_h0: size of first HALF WORD data section
3071 sda_b : size of BYTE data section
3072 sda_hi: size of second HALF WORD data section
3073 sda_w1: size of second WORD data section
3074 sda_d1: size of second DOUBLE WORD data section
3076 offset (always positive) from the beginning of sda_d0 if OK
3077 a negative error value if fail
3079 these 7 sections have to be located back to back if exist
3080 a pass in 0 value for non-existing section */
3082 /* Due to the interpretation of simm15 field of load/store depending on
3083 data accessing size, the organization of base register relative data shall
3084 like the following figure
3085 -------------------------------------------
3086 | DOUBLE WORD sized data (range +/- 128K)
3087 -------------------------------------------
3088 | WORD sized data (range +/- 64K)
3089 -------------------------------------------
3090 | HALF WORD sized data (range +/- 32K)
3091 -------------------------------------------
3092 | BYTE sized data (range +/- 16K)
3093 -------------------------------------------
3094 | HALF WORD sized data (range +/- 32K)
3095 -------------------------------------------
3096 | WORD sized data (range +/- 64K)
3097 -------------------------------------------
3098 | DOUBLE WORD sized data (range +/- 128K)
3099 -------------------------------------------
3100 Its base register shall be set to access these data freely. */
3102 /* We have to figure out the SDA_BASE value, so that we can adjust the
3103 symbol value correctly. We look up the symbol _SDA_BASE_ in the output
3104 BFD. If we can't find it, we're stuck. We cache it in the ELF
3105 target data. We don't need to adjust the symbol value for an
3106 external symbol if we are producing relocatable output. */
3108 static asection
*sda_rela_sec
= NULL
;
3110 #define SDA_SECTION_NUM 10
3112 static bfd_reloc_status_type
3113 nds32_elf_final_sda_base (bfd
*output_bfd
, struct bfd_link_info
*info
,
3114 bfd_vma
*psb
, bfd_boolean add_symbol
)
3117 struct elf_nds32_link_hash_table
*table
;
3118 struct bfd_link_hash_entry
*h
, *h2
;
3119 long unsigned int total
= 0;
3121 h
= bfd_link_hash_lookup (info
->hash
, "_SDA_BASE_", FALSE
, FALSE
, TRUE
);
3122 if (!h
|| (h
->type
!= bfd_link_hash_defined
&& h
->type
!= bfd_link_hash_defweak
))
3124 asection
*first
= NULL
, *final
= NULL
, *temp
;
3126 /* The first section must be 4-byte aligned to promise _SDA_BASE_ being
3127 4 byte-aligned. Therefore, it has to set the first section ".data"
3129 static const char sec_name
[SDA_SECTION_NUM
][10] =
3131 ".data", ".got", ".sdata_d", ".sdata_w", ".sdata_h", ".sdata_b",
3132 ".sbss_b", ".sbss_h", ".sbss_w", ".sbss_d"
3136 if (output_bfd
->sections
== NULL
)
3138 *psb
= elf_gp (output_bfd
);
3139 return bfd_reloc_ok
;
3142 /* Get the first and final section. */
3143 while (i
< sizeof (sec_name
) / sizeof (sec_name
[0]))
3145 temp
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3146 if (temp
&& !first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3148 if (temp
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3151 /* Summarize the sections in order to check if joining .bss. */
3152 if (temp
&& temp
->size
!= 0)
3153 total
+= temp
->size
;
3154 else if (temp
&& temp
->rawsize
!= 0)
3155 total
+= temp
->rawsize
;
3160 /* Check .bss size. */
3161 temp
= bfd_get_section_by_name (output_bfd
, ".bss");
3164 if (temp
->size
!= 0)
3165 total
+= temp
->size
;
3166 else if (temp
->rawsize
!= 0)
3167 total
+= temp
->rawsize
;
3169 if (total
< 0x80000)
3171 if (!first
&& (temp
->size
!= 0 || temp
->rawsize
!= 0))
3173 if ((temp
->size
!= 0 || temp
->rawsize
!= 0))
3180 /* The middle of data region. */
3181 sda_base
= final
->vma
/ 2 + final
->rawsize
/ 2 + first
->vma
/ 2;
3183 /* Find the section sda_base located. */
3185 while (i
< sizeof (sec_name
) / sizeof (sec_name
[0]))
3187 final
= bfd_get_section_by_name (output_bfd
, sec_name
[i
]);
3188 if (final
&& (final
->size
!= 0 || final
->rawsize
!= 0)
3189 && sda_base
>= final
->vma
)
3200 /* There is not any data section in output bfd, and set _SDA_BASE_ in
3201 first output section. */
3202 first
= output_bfd
->sections
;
3203 while (first
&& first
->size
== 0 && first
->rawsize
== 0)
3204 first
= first
->next
;
3207 *psb
= elf_gp (output_bfd
);
3208 return bfd_reloc_ok
;
3210 sda_base
= first
->vma
+ first
->rawsize
;
3213 sda_base
-= first
->vma
;
3214 sda_base
= sda_base
& (~7);
3216 if (!_bfd_generic_link_add_one_symbol
3217 (info
, output_bfd
, "_SDA_BASE_", BSF_GLOBAL
| BSF_WEAK
, first
,
3218 (bfd_vma
) sda_base
, (const char *) NULL
, FALSE
,
3219 get_elf_backend_data (output_bfd
)->collect
, &h
))
3222 sda_rela_sec
= first
;
3224 table
= nds32_elf_hash_table (info
);
3225 relax_fp_as_gp
= table
->relax_fp_as_gp
;
3228 h2
= bfd_link_hash_lookup (info
->hash
, FP_BASE_NAME
,
3229 FALSE
, FALSE
, FALSE
);
3230 /* Define a weak FP_BASE_NAME here to prevent the undefined symbol.
3231 And set FP equal to SDA_BASE to do relaxation for
3232 la $fp, _FP_BASE_. */
3233 if (!_bfd_generic_link_add_one_symbol
3234 (info
, output_bfd
, FP_BASE_NAME
, BSF_GLOBAL
| BSF_WEAK
,
3235 first
, (bfd_vma
) sda_base
, (const char *) NULL
,
3236 FALSE
, get_elf_backend_data (output_bfd
)->collect
, &h2
))
3246 elf_gp (output_bfd
) = (h
->u
.def
.value
3247 + h
->u
.def
.section
->output_section
->vma
3248 + h
->u
.def
.section
->output_offset
);
3252 _bfd_error_handler (_("error: Can't find symbol: _SDA_BASE_."));
3253 return bfd_reloc_dangerous
;
3257 *psb
= h
->u
.def
.value
+ h
->u
.def
.section
->output_section
->vma
3258 + h
->u
.def
.section
->output_offset
;
3259 return bfd_reloc_ok
;
3263 /* Return size of a PLT entry. */
3264 #define elf_nds32_sizeof_plt(info) PLT_ENTRY_SIZE
3267 /* Create an entry in an nds32 ELF linker hash table. */
3269 static struct bfd_hash_entry
*
3270 nds32_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3271 struct bfd_hash_table
*table
,
3274 struct elf_nds32_link_hash_entry
*ret
;
3276 ret
= (struct elf_nds32_link_hash_entry
*) entry
;
3278 /* Allocate the structure if it has not already been allocated by a
3281 ret
= (struct elf_nds32_link_hash_entry
*)
3282 bfd_hash_allocate (table
, sizeof (struct elf_nds32_link_hash_entry
));
3285 return (struct bfd_hash_entry
*) ret
;
3287 /* Call the allocation method of the superclass. */
3288 ret
= (struct elf_nds32_link_hash_entry
*)
3289 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
);
3293 struct elf_nds32_link_hash_entry
*eh
;
3295 eh
= (struct elf_nds32_link_hash_entry
*) ret
;
3296 eh
->dyn_relocs
= NULL
;
3297 eh
->tls_type
= GOT_UNKNOWN
;
3300 return (struct bfd_hash_entry
*) ret
;
3303 /* Create an nds32 ELF linker hash table. */
3305 static struct bfd_link_hash_table
*
3306 nds32_elf_link_hash_table_create (bfd
*abfd
)
3308 struct elf_nds32_link_hash_table
*ret
;
3310 bfd_size_type amt
= sizeof (struct elf_nds32_link_hash_table
);
3312 ret
= (struct elf_nds32_link_hash_table
*) bfd_zmalloc (amt
);
3317 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3318 nds32_elf_link_hash_newfunc
,
3319 sizeof (struct elf_nds32_link_hash_entry
),
3326 return &ret
->root
.root
;
3329 /* Create dynamic sections when linking against a dynamic object. */
3332 nds32_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3334 struct elf_nds32_link_hash_table
*htab
;
3335 flagword flags
, pltflags
;
3336 register asection
*s
;
3337 const struct elf_backend_data
*bed
;
3338 int ptralign
= 2; /* 32-bit */
3340 bed
= get_elf_backend_data (abfd
);
3342 htab
= nds32_elf_hash_table (info
);
3344 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3345 .rel[a].bss sections. */
3347 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3348 | SEC_LINKER_CREATED
);
3351 pltflags
|= SEC_CODE
;
3352 if (bed
->plt_not_loaded
)
3353 pltflags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
3354 if (bed
->plt_readonly
)
3355 pltflags
|= SEC_READONLY
;
3357 s
= bfd_make_section (abfd
, ".plt");
3358 htab
->root
.splt
= s
;
3360 || !bfd_set_section_flags (abfd
, s
, pltflags
)
3361 || !bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3364 if (bed
->want_plt_sym
)
3366 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3368 struct bfd_link_hash_entry
*bh
= NULL
;
3369 struct elf_link_hash_entry
*h
;
3371 if (!(_bfd_generic_link_add_one_symbol
3372 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3373 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3374 get_elf_backend_data (abfd
)->collect
, &bh
)))
3377 h
= (struct elf_link_hash_entry
*) bh
;
3379 h
->type
= STT_OBJECT
;
3381 if (bfd_link_pic (info
) && !bfd_elf_link_record_dynamic_symbol (info
, h
))
3385 s
= bfd_make_section (abfd
,
3386 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3387 htab
->root
.srelplt
= s
;
3389 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3390 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3393 if (htab
->root
.sgot
== NULL
&& !_bfd_elf_create_got_section (abfd
, info
))
3397 const char *secname
;
3402 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3404 secflags
= bfd_get_section_flags (abfd
, sec
);
3405 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3406 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3408 secname
= bfd_get_section_name (abfd
, sec
);
3409 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3410 strcpy (relname
, ".rela");
3411 strcat (relname
, secname
);
3412 if (bfd_get_section_by_name (abfd
, secname
))
3414 s
= bfd_make_section (abfd
, relname
);
3416 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3417 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3422 if (bed
->want_dynbss
)
3424 /* The .dynbss section is a place to put symbols which are defined
3425 by dynamic objects, are referenced by regular objects, and are
3426 not functions. We must allocate space for them in the process
3427 image and use a R_*_COPY reloc to tell the dynamic linker to
3428 initialize them at run time. The linker script puts the .dynbss
3429 section into the .bss section of the final image. */
3430 s
= bfd_make_section (abfd
, ".dynbss");
3433 || !bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
3435 /* The .rel[a].bss section holds copy relocs. This section is not
3436 normally needed. We need to create it here, though, so that the
3437 linker will map it to an output section. We can't just create it
3438 only if we need it, because we will not know whether we need it
3439 until we have seen all the input files, and the first time the
3440 main linker code calls BFD after examining all the input files
3441 (size_dynamic_sections) the input sections have already been
3442 mapped to the output sections. If the section turns out not to
3443 be needed, we can discard it later. We will never need this
3444 section when generating a shared object, since they do not use
3446 if (!bfd_link_pic (info
))
3448 s
= bfd_make_section (abfd
, (bed
->default_use_rela_p
3449 ? ".rela.bss" : ".rel.bss"));
3452 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3453 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
3461 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3463 nds32_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3464 struct elf_link_hash_entry
*dir
,
3465 struct elf_link_hash_entry
*ind
)
3467 struct elf_nds32_link_hash_entry
*edir
, *eind
;
3469 edir
= (struct elf_nds32_link_hash_entry
*) dir
;
3470 eind
= (struct elf_nds32_link_hash_entry
*) ind
;
3472 if (eind
->dyn_relocs
!= NULL
)
3474 if (edir
->dyn_relocs
!= NULL
)
3476 struct elf_nds32_dyn_relocs
**pp
;
3477 struct elf_nds32_dyn_relocs
*p
;
3479 if (ind
->root
.type
== bfd_link_hash_indirect
)
3482 /* Add reloc counts against the weak sym to the strong sym
3483 list. Merge any entries against the same section. */
3484 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
;)
3486 struct elf_nds32_dyn_relocs
*q
;
3488 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3489 if (q
->sec
== p
->sec
)
3491 q
->pc_count
+= p
->pc_count
;
3492 q
->count
+= p
->count
;
3499 *pp
= edir
->dyn_relocs
;
3502 edir
->dyn_relocs
= eind
->dyn_relocs
;
3503 eind
->dyn_relocs
= NULL
;
3506 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3509 /* Find dynamic relocs for H that apply to read-only sections. */
3512 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
3514 struct elf_nds32_dyn_relocs
*p
;
3516 for (p
= elf32_nds32_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3518 asection
*s
= p
->sec
->output_section
;
3520 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3526 /* Adjust a symbol defined by a dynamic object and referenced by a
3527 regular object. The current definition is in some section of the
3528 dynamic object, but we're not including those sections. We have to
3529 change the definition to something the rest of the link can
3533 nds32_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3534 struct elf_link_hash_entry
*h
)
3536 struct elf_nds32_link_hash_table
*htab
;
3537 struct elf_nds32_link_hash_entry
*eh
;
3538 struct elf_nds32_dyn_relocs
*p
;
3541 unsigned int power_of_two
;
3543 dynobj
= elf_hash_table (info
)->dynobj
;
3545 /* Make sure we know what is going on here. */
3546 BFD_ASSERT (dynobj
!= NULL
3549 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
3552 /* If this is a function, put it in the procedure linkage table. We
3553 will fill in the contents of the procedure linkage table later,
3554 when we know the address of the .got section. */
3555 if (h
->type
== STT_FUNC
|| h
->needs_plt
)
3557 if (!bfd_link_pic (info
)
3560 && h
->root
.type
!= bfd_link_hash_undefweak
3561 && h
->root
.type
!= bfd_link_hash_undefined
)
3563 /* This case can occur if we saw a PLT reloc in an input
3564 file, but the symbol was never referred to by a dynamic
3565 object. In such a case, we don't actually need to build
3566 a procedure linkage table, and we can just do a PCREL
3568 h
->plt
.offset
= (bfd_vma
) - 1;
3575 h
->plt
.offset
= (bfd_vma
) - 1;
3577 /* If this is a weak symbol, and there is a real definition, the
3578 processor independent code will have arranged for us to see the
3579 real definition first, and we can just use the same value. */
3580 if (h
->is_weakalias
)
3582 struct elf_link_hash_entry
*def
= weakdef (h
);
3583 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3584 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3585 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3589 /* This is a reference to a symbol defined by a dynamic object which
3590 is not a function. */
3592 /* If we are creating a shared library, we must presume that the
3593 only references to the symbol are via the global offset table.
3594 For such cases we need not do anything here; the relocations will
3595 be handled correctly by relocate_section. */
3596 if (bfd_link_pic (info
))
3599 /* If there are no references to this symbol that do not use the
3600 GOT, we don't need to generate a copy reloc. */
3601 if (!h
->non_got_ref
)
3604 /* If -z nocopyreloc was given, we won't generate them either. */
3605 if (info
->nocopyreloc
)
3611 eh
= (struct elf_nds32_link_hash_entry
*) h
;
3612 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3614 s
= p
->sec
->output_section
;
3615 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3619 /* If we didn't find any dynamic relocs in sections which needs the
3620 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3628 /* We must allocate the symbol in our .dynbss section, which will
3629 become part of the .bss section of the executable. There will be
3630 an entry for this symbol in the .dynsym section. The dynamic
3631 object will contain position independent code, so all references
3632 from the dynamic object to this symbol will go through the global
3633 offset table. The dynamic linker will use the .dynsym entry to
3634 determine the address it must put in the global offset table, so
3635 both the dynamic object and the regular object will refer to the
3636 same memory location for the variable. */
3638 htab
= nds32_elf_hash_table (info
);
3640 BFD_ASSERT (s
!= NULL
);
3642 /* We must generate a R_NDS32_COPY reloc to tell the dynamic linker
3643 to copy the initial value out of the dynamic object and into the
3644 runtime process image. We need to remember the offset into the
3645 .rela.bss section we are going to use. */
3646 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3650 srel
= htab
->srelbss
;
3651 BFD_ASSERT (srel
!= NULL
);
3652 srel
->size
+= sizeof (Elf32_External_Rela
);
3656 /* We need to figure out the alignment required for this symbol. I
3657 have no idea how ELF linkers handle this. */
3658 power_of_two
= bfd_log2 (h
->size
);
3659 if (power_of_two
> 3)
3662 /* Apply the required alignment. */
3663 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3664 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3666 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3670 /* Define the symbol as being at this point in the section. */
3671 h
->root
.u
.def
.section
= s
;
3672 h
->root
.u
.def
.value
= s
->size
;
3674 /* Increment the section size to make room for the symbol. */
3680 /* Allocate space in .plt, .got and associated reloc sections for
3684 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3686 struct bfd_link_info
*info
;
3687 struct elf_nds32_link_hash_table
*htab
;
3688 struct elf_nds32_link_hash_entry
*eh
;
3689 struct elf_nds32_dyn_relocs
*p
;
3691 if (h
->root
.type
== bfd_link_hash_indirect
)
3694 if (h
->root
.type
== bfd_link_hash_warning
)
3695 /* When warning symbols are created, they **replace** the "real"
3696 entry in the hash table, thus we never get to see the real
3697 symbol in a hash traversal. So look at it now. */
3698 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3700 info
= (struct bfd_link_info
*) inf
;
3701 htab
= nds32_elf_hash_table (info
);
3703 eh
= (struct elf_nds32_link_hash_entry
*) h
;
3705 if (htab
->root
.dynamic_sections_created
&& h
->plt
.refcount
> 0)
3707 /* Make sure this symbol is output as a dynamic symbol.
3708 Undefined weak syms won't yet be marked as dynamic. */
3709 if (h
->dynindx
== -1 && !h
->forced_local
)
3711 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3715 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
3717 asection
*s
= htab
->root
.splt
;
3719 /* If this is the first .plt entry, make room for the special
3722 s
->size
+= PLT_ENTRY_SIZE
;
3724 h
->plt
.offset
= s
->size
;
3726 /* If this symbol is not defined in a regular file, and we are
3727 not generating a shared library, then set the symbol to this
3728 location in the .plt. This is required to make function
3729 pointers compare as equal between the normal executable and
3730 the shared library. */
3731 if (!bfd_link_pic (info
) && !h
->def_regular
)
3733 h
->root
.u
.def
.section
= s
;
3734 h
->root
.u
.def
.value
= h
->plt
.offset
;
3737 /* Make room for this entry. */
3738 s
->size
+= PLT_ENTRY_SIZE
;
3740 /* We also need to make an entry in the .got.plt section, which
3741 will be placed in the .got section by the linker script. */
3742 htab
->root
.sgotplt
->size
+= 4;
3744 /* We also need to make an entry in the .rel.plt section. */
3745 htab
->root
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
3749 h
->plt
.offset
= (bfd_vma
) - 1;
3755 h
->plt
.offset
= (bfd_vma
) - 1;
3759 if (h
->got
.refcount
> 0)
3763 int tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
3765 /* Make sure this symbol is output as a dynamic symbol.
3766 Undefined weak syms won't yet be marked as dynamic. */
3767 if (h
->dynindx
== -1 && !h
->forced_local
)
3769 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3773 s
= htab
->root
.sgot
;
3774 h
->got
.offset
= s
->size
;
3776 if (tls_type
== GOT_UNKNOWN
)
3778 else if (tls_type
== GOT_NORMAL
3779 || tls_type
== GOT_TLS_IE
)
3780 /* Need a GOT slot. */
3783 dyn
= htab
->root
.dynamic_sections_created
;
3784 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
))
3785 htab
->root
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
3788 h
->got
.offset
= (bfd_vma
) - 1;
3790 if (eh
->dyn_relocs
== NULL
)
3793 /* In the shared -Bsymbolic case, discard space allocated for
3794 dynamic pc-relative relocs against symbols which turn out to be
3795 defined in regular objects. For the normal shared case, discard
3796 space for pc-relative relocs that have become local due to symbol
3797 visibility changes. */
3799 if (bfd_link_pic (info
))
3801 if (h
->def_regular
&& (h
->forced_local
|| info
->symbolic
))
3803 struct elf_nds32_dyn_relocs
**pp
;
3805 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
;)
3807 p
->count
-= p
->pc_count
;
3818 /* For the non-shared case, discard space for relocs against
3819 symbols which turn out to need copy relocs or are not dynamic. */
3824 || (htab
->root
.dynamic_sections_created
3825 && (h
->root
.type
== bfd_link_hash_undefweak
3826 || h
->root
.type
== bfd_link_hash_undefined
))))
3828 /* Make sure this symbol is output as a dynamic symbol.
3829 Undefined weak syms won't yet be marked as dynamic. */
3830 if (h
->dynindx
== -1 && !h
->forced_local
)
3832 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3836 /* If that succeeded, we know we'll be keeping all the
3838 if (h
->dynindx
!= -1)
3842 eh
->dyn_relocs
= NULL
;
3847 /* Finally, allocate space. */
3848 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3850 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3851 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3857 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
3858 read-only sections. */
3861 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
3865 if (h
->root
.type
== bfd_link_hash_indirect
)
3868 sec
= readonly_dynrelocs (h
);
3871 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
3873 info
->flags
|= DF_TEXTREL
;
3874 info
->callbacks
->minfo
3875 (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
3876 sec
->owner
, h
->root
.root
.string
, sec
);
3878 /* Not an error, just cut short the traversal. */
3884 /* Set the sizes of the dynamic sections. */
3887 nds32_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3888 struct bfd_link_info
*info
)
3890 struct elf_nds32_link_hash_table
*htab
;
3896 htab
= nds32_elf_hash_table (info
);
3897 dynobj
= htab
->root
.dynobj
;
3898 BFD_ASSERT (dynobj
!= NULL
);
3900 if (htab
->root
.dynamic_sections_created
)
3902 /* Set the contents of the .interp section to the interpreter. */
3903 if (bfd_link_executable (info
) && !info
->nointerp
)
3905 s
= bfd_get_section_by_name (dynobj
, ".interp");
3906 BFD_ASSERT (s
!= NULL
);
3907 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3908 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3912 /* Set up .got offsets for local syms, and space for local dynamic
3914 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
3916 bfd_signed_vma
*local_got
;
3917 bfd_signed_vma
*end_local_got
;
3918 bfd_size_type locsymcount
;
3919 Elf_Internal_Shdr
*symtab_hdr
;
3922 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3925 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3927 struct elf_nds32_dyn_relocs
*p
;
3929 for (p
= ((struct elf_nds32_dyn_relocs
*)
3930 elf_section_data (s
)->local_dynrel
);
3931 p
!= NULL
; p
= p
->next
)
3933 if (!bfd_is_abs_section (p
->sec
)
3934 && bfd_is_abs_section (p
->sec
->output_section
))
3936 /* Input section has been discarded, either because
3937 it is a copy of a linkonce section or due to
3938 linker script /DISCARD/, so we'll be discarding
3941 else if (p
->count
!= 0)
3943 srel
= elf_section_data (p
->sec
)->sreloc
;
3944 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3945 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3946 info
->flags
|= DF_TEXTREL
;
3951 local_got
= elf_local_got_refcounts (ibfd
);
3955 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3956 locsymcount
= symtab_hdr
->sh_info
;
3957 end_local_got
= local_got
+ locsymcount
;
3958 s
= htab
->root
.sgot
;
3959 srel
= htab
->root
.srelgot
;
3960 for (; local_got
< end_local_got
; ++local_got
)
3964 *local_got
= s
->size
;
3966 if (bfd_link_pic (info
))
3967 srel
->size
+= sizeof (Elf32_External_Rela
);
3970 *local_got
= (bfd_vma
) - 1;
3974 /* Allocate global sym .plt and .got entries, and space for global
3975 sym dynamic relocs. */
3976 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (void *) info
);
3978 /* We now have determined the sizes of the various dynamic sections.
3979 Allocate memory for them. */
3981 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3983 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3986 if (s
== htab
->root
.splt
)
3988 /* Strip this section if we don't need it; see the
3991 else if (s
== htab
->root
.sgot
)
3993 got_size
+= s
->size
;
3995 else if (s
== htab
->root
.sgotplt
)
3997 got_size
+= s
->size
;
3999 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4001 if (s
->size
!= 0 && s
!= htab
->root
.srelplt
)
4004 /* We use the reloc_count field as a counter if we need
4005 to copy relocs into the output file. */
4010 /* It's not one of our sections, so don't allocate space. */
4016 /* If we don't need this section, strip it from the
4017 output file. This is mostly to handle .rela.bss and
4018 .rela.plt. We must create both sections in
4019 create_dynamic_sections, because they must be created
4020 before the linker maps input sections to output
4021 sections. The linker does that before
4022 adjust_dynamic_symbol is called, and it is that
4023 function which decides whether anything needs to go
4024 into these sections. */
4025 s
->flags
|= SEC_EXCLUDE
;
4029 /* Allocate memory for the section contents. We use bfd_zalloc
4030 here in case unused entries are not reclaimed before the
4031 section's contents are written out. This should not happen,
4032 but this way if it does, we get a R_NDS32_NONE reloc instead
4034 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4035 if (s
->contents
== NULL
)
4040 if (htab
->root
.dynamic_sections_created
)
4042 /* Add some entries to the .dynamic section. We fill in the
4043 values later, in nds32_elf_finish_dynamic_sections, but we
4044 must add the entries now so that we get the correct size for
4045 the .dynamic section. The DT_DEBUG entry is filled in by the
4046 dynamic linker and used by the debugger. */
4047 #define add_dynamic_entry(TAG, VAL) \
4048 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4050 if (!bfd_link_pic (info
))
4052 if (!add_dynamic_entry (DT_DEBUG
, 0))
4056 if (htab
->root
.splt
->size
!= 0)
4058 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4059 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4060 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4061 || !add_dynamic_entry (DT_JMPREL
, 0))
4067 if (!add_dynamic_entry (DT_RELA
, 0)
4068 || !add_dynamic_entry (DT_RELASZ
, 0)
4069 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4072 /* If any dynamic relocs apply to a read-only section,
4073 then we need a DT_TEXTREL entry. */
4074 if ((info
->flags
& DF_TEXTREL
) == 0)
4075 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
,
4078 if ((info
->flags
& DF_TEXTREL
) != 0)
4080 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4085 #undef add_dynamic_entry
4090 static bfd_reloc_status_type
4091 nds32_relocate_contents (reloc_howto_type
*howto
, bfd
*input_bfd
,
4092 bfd_vma relocation
, bfd_byte
*location
)
4096 bfd_reloc_status_type flag
;
4097 unsigned int rightshift
= howto
->rightshift
;
4098 unsigned int bitpos
= howto
->bitpos
;
4100 /* If the size is negative, negate RELOCATION. This isn't very
4102 if (howto
->size
< 0)
4103 relocation
= -relocation
;
4105 /* Get the value we are going to relocate. */
4106 size
= bfd_get_reloc_size (howto
);
4113 return bfd_reloc_ok
;
4115 x
= bfd_getb16 (location
);
4118 x
= bfd_getb32 (location
);
4122 /* Check for overflow. FIXME: We may drop bits during the addition
4123 which we don't check for. We must either check at every single
4124 operation, which would be tedious, or we must do the computations
4125 in a type larger than bfd_vma, which would be inefficient. */
4126 flag
= bfd_reloc_ok
;
4127 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
4129 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
4132 /* Get the values to be added together. For signed and unsigned
4133 relocations, we assume that all values should be truncated to
4134 the size of an address. For bitfields, all the bits matter.
4135 See also bfd_check_overflow. */
4136 fieldmask
= N_ONES (howto
->bitsize
);
4137 signmask
= ~fieldmask
;
4138 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
4139 a
= (relocation
& addrmask
) >> rightshift
;
4140 b
= (x
& howto
->src_mask
& addrmask
) >> bitpos
;
4142 switch (howto
->complain_on_overflow
)
4144 case complain_overflow_signed
:
4145 /* If any sign bits are set, all sign bits must be set.
4146 That is, A must be a valid negative address after
4148 signmask
= ~(fieldmask
>> 1);
4151 case complain_overflow_bitfield
:
4152 /* Much like the signed check, but for a field one bit
4153 wider. We allow a bitfield to represent numbers in the
4154 range -2**n to 2**n-1, where n is the number of bits in the
4155 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
4156 can't overflow, which is exactly what we want. */
4158 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
4159 flag
= bfd_reloc_overflow
;
4161 /* We only need this next bit of code if the sign bit of B
4162 is below the sign bit of A. This would only happen if
4163 SRC_MASK had fewer bits than BITSIZE. Note that if
4164 SRC_MASK has more bits than BITSIZE, we can get into
4165 trouble; we would need to verify that B is in range, as
4166 we do for A above. */
4167 ss
= ((~howto
->src_mask
) >> 1) & howto
->src_mask
;
4170 /* Set all the bits above the sign bit. */
4173 /* Now we can do the addition. */
4176 /* See if the result has the correct sign. Bits above the
4177 sign bit are junk now; ignore them. If the sum is
4178 positive, make sure we did not have all negative inputs;
4179 if the sum is negative, make sure we did not have all
4180 positive inputs. The test below looks only at the sign
4181 bits, and it really just
4182 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
4184 We mask with addrmask here to explicitly allow an address
4185 wrap-around. The Linux kernel relies on it, and it is
4186 the only way to write assembler code which can run when
4187 loaded at a location 0x80000000 away from the location at
4188 which it is linked. */
4189 if (((~(a
^ b
)) & (a
^ sum
)) & signmask
& addrmask
)
4190 flag
= bfd_reloc_overflow
;
4194 case complain_overflow_unsigned
:
4195 /* Checking for an unsigned overflow is relatively easy:
4196 trim the addresses and add, and trim the result as well.
4197 Overflow is normally indicated when the result does not
4198 fit in the field. However, we also need to consider the
4199 case when, e.g., fieldmask is 0x7fffffff or smaller, an
4200 input is 0x80000000, and bfd_vma is only 32 bits; then we
4201 will get sum == 0, but there is an overflow, since the
4202 inputs did not fit in the field. Instead of doing a
4203 separate test, we can check for this by or-ing in the
4204 operands when testing for the sum overflowing its final
4206 sum
= (a
+ b
) & addrmask
;
4207 if ((a
| b
| sum
) & signmask
)
4208 flag
= bfd_reloc_overflow
;
4216 /* Put RELOCATION in the right bits. */
4217 relocation
>>= (bfd_vma
) rightshift
;
4218 relocation
<<= (bfd_vma
) bitpos
;
4220 /* Add RELOCATION to the right bits of X. */
4222 Because the relaxation may generate duplicate relocation at one address,
4223 an addition to immediate in the instruction may cause the relocation added
4225 This bug should be fixed in assembler, but a check is also needed here. */
4226 if (howto
->partial_inplace
)
4227 x
= ((x
& ~howto
->dst_mask
)
4228 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
4230 x
= ((x
& ~howto
->dst_mask
) | ((relocation
) & howto
->dst_mask
));
4233 /* Put the relocated value back in the object file. */
4243 bfd_putb16 (x
, location
);
4246 bfd_putb32 (x
, location
);
4253 static bfd_reloc_status_type
4254 nds32_elf_final_link_relocate (reloc_howto_type
*howto
, bfd
*input_bfd
,
4255 asection
*input_section
, bfd_byte
*contents
,
4256 bfd_vma address
, bfd_vma value
, bfd_vma addend
)
4260 /* Sanity check the address. */
4261 if (address
> bfd_get_section_limit (input_bfd
, input_section
))
4262 return bfd_reloc_outofrange
;
4264 /* This function assumes that we are dealing with a basic relocation
4265 against a symbol. We want to compute the value of the symbol to
4266 relocate to. This is just VALUE, the value of the symbol, plus
4267 ADDEND, any addend associated with the reloc. */
4268 relocation
= value
+ addend
;
4270 /* If the relocation is PC relative, we want to set RELOCATION to
4271 the distance between the symbol (currently in RELOCATION) and the
4272 location we are relocating. Some targets (e.g., i386-aout)
4273 arrange for the contents of the section to be the negative of the
4274 offset of the location within the section; for such targets
4275 pcrel_offset is FALSE. Other targets (e.g., m88kbcs or ELF)
4276 simply leave the contents of the section as zero; for such
4277 targets pcrel_offset is TRUE. If pcrel_offset is FALSE we do not
4278 need to subtract out the offset of the location within the
4279 section (which is just ADDRESS). */
4280 if (howto
->pc_relative
)
4282 relocation
-= (input_section
->output_section
->vma
4283 + input_section
->output_offset
);
4284 if (howto
->pcrel_offset
)
4285 relocation
-= address
;
4288 return nds32_relocate_contents (howto
, input_bfd
, relocation
,
4289 contents
+ address
);
4293 nds32_elf_output_symbol_hook (struct bfd_link_info
*info
,
4295 Elf_Internal_Sym
*elfsym ATTRIBUTE_UNUSED
,
4296 asection
*input_sec
,
4297 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4300 FILE *sym_ld_script
= NULL
;
4301 struct elf_nds32_link_hash_table
*table
;
4303 table
= nds32_elf_hash_table (info
);
4304 sym_ld_script
= table
->sym_ld_script
;
4308 if (!h
|| !name
|| *name
== '\0')
4311 if (input_sec
->flags
& SEC_EXCLUDE
)
4314 if (!check_start_export_sym
)
4316 fprintf (sym_ld_script
, "SECTIONS\n{\n");
4317 check_start_export_sym
= 1;
4320 if (h
->root
.type
== bfd_link_hash_defined
4321 || h
->root
.type
== bfd_link_hash_defweak
)
4323 if (!h
->root
.u
.def
.section
->output_section
)
4326 if (bfd_is_const_section (input_sec
))
4327 source
= input_sec
->name
;
4329 source
= input_sec
->owner
->filename
;
4331 fprintf (sym_ld_script
, "\t%s = 0x%08lx;\t /* %s */\n",
4332 h
->root
.root
.string
,
4333 (long) (h
->root
.u
.def
.value
4334 + h
->root
.u
.def
.section
->output_section
->vma
4335 + h
->root
.u
.def
.section
->output_offset
), source
);
4341 /* Relocate an NDS32/D ELF section.
4342 There is some attempt to make this function usable for many architectures,
4343 both for RELA and REL type relocs, if only to serve as a learning tool.
4345 The RELOCATE_SECTION function is called by the new ELF backend linker
4346 to handle the relocations for a section.
4348 The relocs are always passed as Rela structures; if the section
4349 actually uses Rel structures, the r_addend field will always be
4352 This function is responsible for adjust the section contents as
4353 necessary, and (if using Rela relocs and generating a
4354 relocatable output file) adjusting the reloc addend as
4357 This function does not have to worry about setting the reloc
4358 address or the reloc symbol index.
4360 LOCAL_SYMS is a pointer to the swapped in local symbols.
4362 LOCAL_SECTIONS is an array giving the section in the input file
4363 corresponding to the st_shndx field of each local symbol.
4365 The global hash table entry for the global symbols can be found
4366 via elf_sym_hashes (input_bfd).
4368 When generating relocatable output, this function must handle
4369 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4370 going to be the section symbol corresponding to the output
4371 section, which means that the addend must be adjusted
4375 dtpoff_base (struct bfd_link_info
*info
)
4377 /* If tls_sec is NULL, we should have signalled an error already. */
4378 if (elf_hash_table (info
)->tls_sec
== NULL
)
4380 return elf_hash_table (info
)->tls_sec
->vma
;
4384 nds32_elf_relocate_section (bfd
* output_bfd ATTRIBUTE_UNUSED
,
4385 struct bfd_link_info
* info
,
4387 asection
* input_section
,
4388 bfd_byte
* contents
,
4389 Elf_Internal_Rela
* relocs
,
4390 Elf_Internal_Sym
* local_syms
,
4391 asection
** local_sections
)
4393 Elf_Internal_Shdr
*symtab_hdr
;
4394 struct elf_link_hash_entry
**sym_hashes
;
4395 Elf_Internal_Rela
*rel
, *relend
;
4396 bfd_boolean ret
= TRUE
; /* Assume success. */
4398 bfd_reloc_status_type r
;
4399 const char *errmsg
= NULL
;
4401 struct elf_nds32_link_hash_table
*htab
;
4403 bfd_vma
*local_got_offsets
;
4404 asection
*sgot
, *splt
, *sreloc
;
4405 bfd_vma high_address
;
4406 struct elf_nds32_link_hash_table
*table
;
4407 int eliminate_gc_relocs
;
4408 bfd_vma fpbase_addr
;
4410 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4411 sym_hashes
= elf_sym_hashes (input_bfd
);
4412 htab
= nds32_elf_hash_table (info
);
4413 high_address
= bfd_get_section_limit (input_bfd
, input_section
);
4415 dynobj
= htab
->root
.dynobj
;
4416 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4418 sgot
= htab
->root
.sgot
;
4419 splt
= htab
->root
.splt
;
4423 relend
= relocs
+ input_section
->reloc_count
;
4425 table
= nds32_elf_hash_table (info
);
4426 eliminate_gc_relocs
= table
->eliminate_gc_relocs
;
4427 /* By this time, we can adjust the value of _SDA_BASE_. */
4428 if ((!bfd_link_relocatable (info
)))
4430 is_SDA_BASE_set
= 1;
4431 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, TRUE
);
4432 if (r
!= bfd_reloc_ok
)
4436 if (is_ITB_BASE_set
== 0)
4438 /* Set the _ITB_BASE_. */
4439 if (!nds32_elf_ex9_itb_base (info
))
4441 _bfd_error_handler (_("%B: error: Cannot set _ITB_BASE_"),
4443 bfd_set_error (bfd_error_bad_value
);
4447 if (table
->target_optimize
& NDS32_RELAX_JUMP_IFC_ON
)
4448 if (!nds32_elf_ifc_reloc ())
4449 _bfd_error_handler (_("error: IFC relocation error."));
4451 /* Relocation for .ex9.itable. */
4452 if (table
->target_optimize
& NDS32_RELAX_EX9_ON
4453 || (table
->ex9_import_file
&& table
->update_ex9_table
))
4454 nds32_elf_ex9_reloc_jmp (info
);
4456 /* Use gp as fp to prevent truncated fit. Because in relaxation time
4457 the fp value is set as gp, and it has be reverted for instruction
4459 fpbase_addr
= elf_gp (output_bfd
);
4461 for (rel
= relocs
; rel
< relend
; rel
++)
4463 enum elf_nds32_reloc_type r_type
;
4464 reloc_howto_type
*howto
= NULL
;
4465 unsigned long r_symndx
;
4466 struct elf_link_hash_entry
*h
= NULL
;
4467 Elf_Internal_Sym
*sym
= NULL
;
4471 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
4472 ensure it's zero (we use REL relocs, not RELA). Therefore this
4473 should be assigning zero to `addend', but for clarity we use
4476 bfd_vma addend
= rel
->r_addend
;
4477 bfd_vma offset
= rel
->r_offset
;
4479 r_type
= ELF32_R_TYPE (rel
->r_info
);
4480 if (r_type
>= R_NDS32_max
)
4482 /* xgettext:c-format */
4483 _bfd_error_handler (_("%B: error: unknown relocation type %d."),
4485 bfd_set_error (bfd_error_bad_value
);
4490 if (r_type
== R_NDS32_GNU_VTENTRY
4491 || r_type
== R_NDS32_GNU_VTINHERIT
4492 || r_type
== R_NDS32_NONE
4493 || r_type
== R_NDS32_RELA_GNU_VTENTRY
4494 || r_type
== R_NDS32_RELA_GNU_VTINHERIT
4495 || (r_type
>= R_NDS32_INSN16
&& r_type
<= R_NDS32_25_FIXED_RELA
)
4496 || r_type
== R_NDS32_DATA
4497 || r_type
== R_NDS32_TRAN
4498 || (r_type
>= R_NDS32_LONGCALL4
&& r_type
<= R_NDS32_LONGJUMP7
))
4501 /* If we enter the fp-as-gp region. Resolve the address
4503 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
4504 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
4508 /* Distance to relocation of best fp-base is encoded in R_SYM. */
4509 dist
= rel
->r_addend
>> 16;
4510 fpbase_addr
= calculate_memory_address (input_bfd
, rel
+ dist
,
4511 local_syms
, symtab_hdr
);
4513 else if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_RELAX_REGION_END
4514 && (rel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
4516 fpbase_addr
= elf_gp (output_bfd
);
4519 if (((r_type
>= R_NDS32_DWARF2_OP1_RELA
4520 && r_type
<= R_NDS32_DWARF2_LEB_RELA
)
4521 || r_type
>= R_NDS32_RELAX_ENTRY
) && !bfd_link_relocatable (info
))
4524 howto
= bfd_elf32_bfd_reloc_type_table_lookup (r_type
);
4525 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4527 /* This is a final link. */
4532 if (r_symndx
< symtab_hdr
->sh_info
)
4535 sym
= local_syms
+ r_symndx
;
4536 sec
= local_sections
[r_symndx
];
4538 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4539 addend
= rel
->r_addend
;
4543 /* External symbol. */
4544 bfd_boolean warned
, ignored
, unresolved_reloc
;
4545 int symndx
= r_symndx
- symtab_hdr
->sh_info
;
4547 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4548 r_symndx
, symtab_hdr
, sym_hashes
, h
, sec
,
4549 relocation
, unresolved_reloc
, warned
,
4552 /* la $fp, _FP_BASE_ is per-function (region).
4553 Handle it specially. */
4554 switch ((int) r_type
)
4556 case R_NDS32_SDA19S0_RELA
:
4557 case R_NDS32_SDA15S0_RELA
:
4558 case R_NDS32_20_RELA
:
4559 if (strcmp (elf_sym_hashes (input_bfd
)[symndx
]->root
.root
.string
,
4562 relocation
= fpbase_addr
;
4569 if (bfd_link_relocatable (info
))
4571 /* This is a relocatable link. We don't have to change
4572 anything, unless the reloc is against a section symbol,
4573 in which case we have to adjust according to where the
4574 section symbol winds up in the output section. */
4575 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4576 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4581 /* Sanity check the address. */
4582 if (offset
> high_address
)
4584 r
= bfd_reloc_outofrange
;
4588 if ((r_type
>= R_NDS32_DWARF2_OP1_RELA
4589 && r_type
<= R_NDS32_DWARF2_LEB_RELA
)
4590 || r_type
>= R_NDS32_RELAX_ENTRY
)
4593 switch ((int) r_type
)
4595 case R_NDS32_GOTOFF
:
4596 /* Relocation is relative to the start of the global offset
4597 table (for ld24 rx, #uimm24), e.g. access at label+addend
4599 ld24 rx. #label@GOTOFF + addend
4601 case R_NDS32_GOTOFF_HI20
:
4602 case R_NDS32_GOTOFF_LO12
:
4603 case R_NDS32_GOTOFF_LO15
:
4604 case R_NDS32_GOTOFF_LO19
:
4605 BFD_ASSERT (sgot
!= NULL
);
4607 relocation
-= elf_gp (output_bfd
);
4610 case R_NDS32_9_PLTREL
:
4611 case R_NDS32_25_PLTREL
:
4612 /* Relocation is to the entry for this symbol in the
4613 procedure linkage table. */
4615 /* The native assembler will generate a 25_PLTREL reloc
4616 for a local symbol if you assemble a call from one
4617 section to another when using -K pic. */
4621 if (h
->forced_local
)
4624 /* We didn't make a PLT entry for this symbol. This
4625 happens when statically linking PIC code, or when
4626 using -Bsymbolic. */
4627 if (h
->plt
.offset
== (bfd_vma
) - 1)
4630 relocation
= (splt
->output_section
->vma
4631 + splt
->output_offset
+ h
->plt
.offset
);
4634 case R_NDS32_PLT_GOTREL_HI20
:
4635 case R_NDS32_PLT_GOTREL_LO12
:
4636 case R_NDS32_PLT_GOTREL_LO15
:
4637 case R_NDS32_PLT_GOTREL_LO19
:
4638 case R_NDS32_PLT_GOTREL_LO20
:
4639 if (h
== NULL
|| h
->forced_local
|| h
->plt
.offset
== (bfd_vma
) - 1)
4641 /* We didn't make a PLT entry for this symbol. This
4642 happens when statically linking PIC code, or when
4643 using -Bsymbolic. */
4644 relocation
-= elf_gp (output_bfd
);
4648 relocation
= (splt
->output_section
->vma
4649 + splt
->output_offset
+ h
->plt
.offset
);
4651 relocation
-= elf_gp (output_bfd
);
4654 case R_NDS32_PLTREL_HI20
:
4655 case R_NDS32_PLTREL_LO12
:
4657 /* Relocation is to the entry for this symbol in the
4658 procedure linkage table. */
4660 /* The native assembler will generate a 25_PLTREL reloc
4661 for a local symbol if you assemble a call from one
4662 section to another when using -K pic. */
4666 if (h
->forced_local
)
4669 if (h
->plt
.offset
== (bfd_vma
) - 1)
4670 /* We didn't make a PLT entry for this symbol. This
4671 happens when statically linking PIC code, or when
4672 using -Bsymbolic. */
4678 relocation
= (splt
->output_section
->vma
4679 + splt
->output_offset
4680 + h
->plt
.offset
+ 4)
4681 - (input_section
->output_section
->vma
4682 + input_section
->output_offset
4687 case R_NDS32_GOTPC20
:
4688 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
4689 ld24 rx,#_GLOBAL_OFFSET_TABLE_ */
4690 relocation
= elf_gp (output_bfd
);
4693 case R_NDS32_GOTPC_HI20
:
4694 case R_NDS32_GOTPC_LO12
:
4696 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
4698 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
4699 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
4702 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
4703 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
4705 relocation
= elf_gp (output_bfd
);
4706 relocation
-= (input_section
->output_section
->vma
4707 + input_section
->output_offset
+ rel
->r_offset
);
4713 case R_NDS32_GOT_HI20
:
4714 case R_NDS32_GOT_LO12
:
4715 case R_NDS32_GOT_LO15
:
4716 case R_NDS32_GOT_LO19
:
4717 /* Relocation is to the entry for this symbol in the global
4719 BFD_ASSERT (sgot
!= NULL
);
4726 off
= h
->got
.offset
;
4727 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4728 dyn
= htab
->root
.dynamic_sections_created
;
4729 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4730 bfd_link_pic (info
),
4732 || (bfd_link_pic (info
)
4735 || h
->forced_local
) && h
->def_regular
))
4737 /* This is actually a static link, or it is a
4738 -Bsymbolic link and the symbol is defined
4739 locally, or the symbol was forced to be local
4740 because of a version file. We must initialize
4741 this entry in the global offset table. Since the
4742 offset must always be a multiple of 4, we use the
4743 least significant bit to record whether we have
4744 initialized it already.
4746 When doing a dynamic link, we create a .rela.got
4747 relocation entry to initialize the value. This
4748 is done in the finish_dynamic_symbol routine. */
4753 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4757 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
4758 - elf_gp (output_bfd
);
4765 BFD_ASSERT (local_got_offsets
!= NULL
4766 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
4768 off
= local_got_offsets
[r_symndx
];
4770 /* The offset must always be a multiple of 4. We use
4771 the least significant bit to record whether we have
4772 already processed this entry. */
4777 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4779 if (bfd_link_pic (info
))
4782 Elf_Internal_Rela outrel
;
4784 /* We need to generate a R_NDS32_RELATIVE reloc
4785 for the dynamic linker. */
4786 srelgot
= htab
->root
.srelgot
;
4787 BFD_ASSERT (srelgot
!= NULL
);
4789 outrel
.r_offset
= (elf_gp (output_bfd
)
4790 + sgot
->output_offset
+ off
);
4791 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
4792 outrel
.r_addend
= relocation
;
4793 loc
= srelgot
->contents
;
4795 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
4796 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4797 ++srelgot
->reloc_count
;
4799 local_got_offsets
[r_symndx
] |= 1;
4801 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
4802 - elf_gp (output_bfd
);
4807 case R_NDS32_16_RELA
:
4808 case R_NDS32_20_RELA
:
4809 case R_NDS32_5_RELA
:
4810 case R_NDS32_32_RELA
:
4811 case R_NDS32_9_PCREL_RELA
:
4812 case R_NDS32_WORD_9_PCREL_RELA
:
4813 case R_NDS32_10_UPCREL_RELA
:
4814 case R_NDS32_15_PCREL_RELA
:
4815 case R_NDS32_17_PCREL_RELA
:
4816 case R_NDS32_25_PCREL_RELA
:
4817 case R_NDS32_HI20_RELA
:
4818 case R_NDS32_LO12S3_RELA
:
4819 case R_NDS32_LO12S2_RELA
:
4820 case R_NDS32_LO12S2_DP_RELA
:
4821 case R_NDS32_LO12S2_SP_RELA
:
4822 case R_NDS32_LO12S1_RELA
:
4823 case R_NDS32_LO12S0_RELA
:
4824 case R_NDS32_LO12S0_ORI_RELA
:
4825 if (bfd_link_pic (info
) && r_symndx
!= 0
4826 && (input_section
->flags
& SEC_ALLOC
) != 0
4827 && (eliminate_gc_relocs
== 0
4828 || (sec
&& (sec
->flags
& SEC_EXCLUDE
) == 0))
4829 && ((r_type
!= R_NDS32_9_PCREL_RELA
4830 && r_type
!= R_NDS32_WORD_9_PCREL_RELA
4831 && r_type
!= R_NDS32_10_UPCREL_RELA
4832 && r_type
!= R_NDS32_15_PCREL_RELA
4833 && r_type
!= R_NDS32_17_PCREL_RELA
4834 && r_type
!= R_NDS32_25_PCREL_RELA
4835 && !(r_type
== R_NDS32_32_RELA
4836 && strcmp (input_section
->name
, ".eh_frame") == 0))
4837 || (h
!= NULL
&& h
->dynindx
!= -1
4838 && (!info
->symbolic
|| !h
->def_regular
))))
4840 Elf_Internal_Rela outrel
;
4841 bfd_boolean skip
, relocate
;
4844 /* When generating a shared object, these relocations
4845 are copied into the output file to be resolved at run
4852 name
= bfd_elf_string_from_elf_section
4853 (input_bfd
, elf_elfheader (input_bfd
)->e_shstrndx
,
4854 elf_section_data (input_section
)->rela
.hdr
->sh_name
);
4858 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4859 && strcmp (bfd_get_section_name (input_bfd
,
4863 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4864 BFD_ASSERT (sreloc
!= NULL
);
4870 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
4874 if (outrel
.r_offset
== (bfd_vma
) - 1)
4876 else if (outrel
.r_offset
== (bfd_vma
) - 2)
4877 skip
= TRUE
, relocate
= TRUE
;
4878 outrel
.r_offset
+= (input_section
->output_section
->vma
4879 + input_section
->output_offset
);
4882 memset (&outrel
, 0, sizeof outrel
);
4883 else if (r_type
== R_NDS32_17_PCREL_RELA
4884 || r_type
== R_NDS32_15_PCREL_RELA
4885 || r_type
== R_NDS32_25_PCREL_RELA
)
4887 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4888 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4889 outrel
.r_addend
= rel
->r_addend
;
4893 /* h->dynindx may be -1 if this symbol was marked to
4896 || ((info
->symbolic
|| h
->dynindx
== -1)
4900 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
4901 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4905 BFD_ASSERT (h
->dynindx
!= -1);
4906 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4907 outrel
.r_addend
= rel
->r_addend
;
4911 loc
= sreloc
->contents
;
4912 loc
+= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
4913 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4914 ++sreloc
->reloc_count
;
4916 /* If this reloc is against an external symbol, we do
4917 not want to fiddle with the addend. Otherwise, we
4918 need to include the symbol value so that it becomes
4919 an addend for the dynamic reloc. */
4925 case R_NDS32_25_ABS_RELA
:
4926 if (bfd_link_pic (info
))
4929 (_("%B: warning: cannot deal R_NDS32_25_ABS_RELA in shared "
4930 "mode."), input_bfd
);
4935 case R_NDS32_9_PCREL
:
4936 r
= nds32_elf_do_9_pcrel_reloc (input_bfd
, howto
, input_section
,
4938 sec
, relocation
, addend
);
4943 Elf_Internal_Rela
*lorel
;
4945 /* We allow an arbitrary number of HI20 relocs before the
4946 LO12 reloc. This permits gcc to emit the HI and LO relocs
4948 for (lorel
= rel
+ 1;
4950 && ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_HI20
); lorel
++)
4953 && (ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S3
4954 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S2
4955 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S1
4956 || ELF32_R_TYPE (lorel
->r_info
) == R_NDS32_LO12S0
))
4958 nds32_elf_relocate_hi20 (input_bfd
, r_type
, rel
, lorel
,
4959 contents
, relocation
+ addend
);
4963 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4964 contents
, offset
, relocation
,
4970 case R_NDS32_GOT17S2_RELA
:
4971 case R_NDS32_GOT15S2_RELA
:
4975 BFD_ASSERT (sgot
!= NULL
);
4981 off
= h
->got
.offset
;
4982 BFD_ASSERT (off
!= (bfd_vma
) - 1);
4984 dyn
= htab
->root
.dynamic_sections_created
;
4985 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL
4986 (dyn
, bfd_link_pic (info
), h
)
4987 || (bfd_link_pic (info
)
4993 /* This is actually a static link, or it is a
4994 -Bsymbolic link and the symbol is defined
4995 locally, or the symbol was forced to be local
4996 because of a version file. We must initialize
4997 this entry in the global offset table. Since the
4998 offset must always be a multiple of 4, we use the
4999 least significant bit to record whether we have
5000 initialized it already.
5002 When doing a dynamic link, we create a .rela.got
5003 relocation entry to initialize the value. This
5004 is done in the finish_dynamic_symbol routine. */
5009 bfd_put_32 (output_bfd
, relocation
,
5010 sgot
->contents
+ off
);
5019 BFD_ASSERT (local_got_offsets
!= NULL
5020 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5022 off
= local_got_offsets
[r_symndx
];
5024 /* The offset must always be a multiple of 4. We use
5025 the least significant bit to record whether we have
5026 already processed this entry. */
5031 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5033 if (bfd_link_pic (info
))
5036 Elf_Internal_Rela outrel
;
5038 /* We need to generate a R_NDS32_RELATIVE reloc
5039 for the dynamic linker. */
5040 srelgot
= htab
->root
.srelgot
;
5041 BFD_ASSERT (srelgot
!= NULL
);
5043 outrel
.r_offset
= (elf_gp (output_bfd
)
5044 + sgot
->output_offset
+ off
);
5045 outrel
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5046 outrel
.r_addend
= relocation
;
5047 loc
= srelgot
->contents
;
5049 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5050 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5051 ++srelgot
->reloc_count
;
5053 local_got_offsets
[r_symndx
] |= 1;
5056 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
5057 - elf_gp (output_bfd
);
5059 if (relocation
& align
)
5061 /* Incorrect alignment. */
5063 (_("%B: warning: unaligned access to GOT entry."), input_bfd
);
5065 r
= bfd_reloc_dangerous
;
5070 case R_NDS32_SDA16S3_RELA
:
5071 case R_NDS32_SDA15S3_RELA
:
5072 case R_NDS32_SDA15S3
:
5076 case R_NDS32_SDA17S2_RELA
:
5077 case R_NDS32_SDA15S2_RELA
:
5078 case R_NDS32_SDA12S2_SP_RELA
:
5079 case R_NDS32_SDA12S2_DP_RELA
:
5080 case R_NDS32_SDA15S2
:
5081 case R_NDS32_SDA_FP7U2_RELA
:
5085 case R_NDS32_SDA18S1_RELA
:
5086 case R_NDS32_SDA15S1_RELA
:
5087 case R_NDS32_SDA15S1
:
5091 case R_NDS32_SDA19S0_RELA
:
5092 case R_NDS32_SDA15S0_RELA
:
5093 case R_NDS32_SDA15S0
:
5097 BFD_ASSERT (sec
!= NULL
);
5099 /* If the symbol is in the abs section, the out_bfd will be null.
5100 This happens when the relocation has a symbol@GOTOFF. */
5101 r
= nds32_elf_final_sda_base (output_bfd
, info
, &gp
, FALSE
);
5102 if (r
!= bfd_reloc_ok
)
5105 (_("%B: warning: relocate SDA_BASE failed."), input_bfd
);
5110 /* At this point `relocation' contains the object's
5112 if (r_type
== R_NDS32_SDA_FP7U2_RELA
)
5114 relocation
-= fpbase_addr
;
5118 /* Now it contains the offset from _SDA_BASE_. */
5120 /* Make sure alignment is correct. */
5122 if (relocation
& align
)
5124 /* Incorrect alignment. */
5126 /* xgettext:c-format */
5127 (_("%B(%A): warning: unaligned small data access of type %d."),
5128 input_bfd
, input_section
, r_type
);
5135 case R_NDS32_17IFC_PCREL_RELA
:
5136 case R_NDS32_10IFCU_PCREL_RELA
:
5140 case R_NDS32_TLS_LE_HI20
:
5141 case R_NDS32_TLS_LE_LO12
:
5142 case R_NDS32_TLS_LE_20
:
5143 case R_NDS32_TLS_LE_15S0
:
5144 case R_NDS32_TLS_LE_15S1
:
5145 case R_NDS32_TLS_LE_15S2
:
5146 if (elf_hash_table (info
)->tls_sec
!= NULL
)
5147 relocation
-= (elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
);
5149 case R_NDS32_TLS_IE_HI20
:
5150 case R_NDS32_TLS_IE_LO12S2
:
5152 /* Relocation is to the entry for this symbol in the global
5154 unsigned int tls_type
;
5156 Elf_Internal_Rela outrel
;
5161 BFD_ASSERT (sgot
!= NULL
);
5166 off
= h
->got
.offset
;
5167 BFD_ASSERT (off
!= (bfd_vma
) - 1);
5168 dyn
= htab
->root
.dynamic_sections_created
;
5169 tls_type
= ((struct elf_nds32_link_hash_entry
*) h
)->tls_type
;
5170 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
5171 && (!bfd_link_pic (info
)
5172 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
5177 /* Never happen currently. */
5178 BFD_ASSERT (local_got_offsets
!= NULL
5179 && local_got_offsets
[r_symndx
] != (bfd_vma
) - 1);
5181 off
= local_got_offsets
[r_symndx
];
5183 tls_type
= elf32_nds32_local_got_tls_type (input_bfd
)[r_symndx
];
5185 relocation
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
;
5187 if (r_type
== R_NDS32_TLS_IE_LO12S2
)
5190 /* The offset must always be a multiple of 4. We use
5191 the least significant bit to record whether we have
5192 already processed this entry. */
5197 bfd_boolean need_relocs
= FALSE
;
5198 srelgot
= htab
->root
.srelgot
;
5199 if ((bfd_link_pic (info
) || indx
!= 0)
5201 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5202 || h
->root
.type
!= bfd_link_hash_undefweak
))
5205 BFD_ASSERT (srelgot
!= NULL
);
5207 if (tls_type
& GOT_TLS_IE
)
5211 if (h
->dynindx
== 0)
5212 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5214 outrel
.r_addend
= 0;
5215 outrel
.r_offset
= (sgot
->output_section
->vma
5216 + sgot
->output_offset
5219 ELF32_R_INFO (h
->dynindx
, R_NDS32_TLS_TPOFF
);
5221 loc
= srelgot
->contents
;
5223 srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
5224 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5225 ++srelgot
->reloc_count
;
5228 bfd_put_32 (output_bfd
, h
->root
.u
.def
.value
- TP_OFFSET
,
5229 sgot
->contents
+ off
);
5235 /* DON'T fall through. */
5238 /* OLD_NDS32_RELOC. */
5240 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5241 contents
, offset
, relocation
, addend
);
5245 switch ((int) r_type
)
5247 case R_NDS32_20_RELA
:
5248 case R_NDS32_5_RELA
:
5249 case R_NDS32_9_PCREL_RELA
:
5250 case R_NDS32_WORD_9_PCREL_RELA
:
5251 case R_NDS32_10_UPCREL_RELA
:
5252 case R_NDS32_15_PCREL_RELA
:
5253 case R_NDS32_17_PCREL_RELA
:
5254 case R_NDS32_25_PCREL_RELA
:
5255 case R_NDS32_25_ABS_RELA
:
5256 case R_NDS32_HI20_RELA
:
5257 case R_NDS32_LO12S3_RELA
:
5258 case R_NDS32_LO12S2_RELA
:
5259 case R_NDS32_LO12S2_DP_RELA
:
5260 case R_NDS32_LO12S2_SP_RELA
:
5261 case R_NDS32_LO12S1_RELA
:
5262 case R_NDS32_LO12S0_RELA
:
5263 case R_NDS32_LO12S0_ORI_RELA
:
5264 case R_NDS32_SDA16S3_RELA
:
5265 case R_NDS32_SDA17S2_RELA
:
5266 case R_NDS32_SDA18S1_RELA
:
5267 case R_NDS32_SDA19S0_RELA
:
5268 case R_NDS32_SDA15S3_RELA
:
5269 case R_NDS32_SDA15S2_RELA
:
5270 case R_NDS32_SDA12S2_DP_RELA
:
5271 case R_NDS32_SDA12S2_SP_RELA
:
5272 case R_NDS32_SDA15S1_RELA
:
5273 case R_NDS32_SDA15S0_RELA
:
5274 case R_NDS32_SDA_FP7U2_RELA
:
5275 case R_NDS32_9_PLTREL
:
5276 case R_NDS32_25_PLTREL
:
5278 case R_NDS32_GOT_HI20
:
5279 case R_NDS32_GOT_LO12
:
5280 case R_NDS32_GOT_LO15
:
5281 case R_NDS32_GOT_LO19
:
5282 case R_NDS32_GOT15S2_RELA
:
5283 case R_NDS32_GOT17S2_RELA
:
5284 case R_NDS32_GOTPC20
:
5285 case R_NDS32_GOTPC_HI20
:
5286 case R_NDS32_GOTPC_LO12
:
5287 case R_NDS32_GOTOFF
:
5288 case R_NDS32_GOTOFF_HI20
:
5289 case R_NDS32_GOTOFF_LO12
:
5290 case R_NDS32_GOTOFF_LO15
:
5291 case R_NDS32_GOTOFF_LO19
:
5292 case R_NDS32_PLTREL_HI20
:
5293 case R_NDS32_PLTREL_LO12
:
5294 case R_NDS32_PLT_GOTREL_HI20
:
5295 case R_NDS32_PLT_GOTREL_LO12
:
5296 case R_NDS32_PLT_GOTREL_LO15
:
5297 case R_NDS32_PLT_GOTREL_LO19
:
5298 case R_NDS32_PLT_GOTREL_LO20
:
5299 case R_NDS32_17IFC_PCREL_RELA
:
5300 case R_NDS32_10IFCU_PCREL_RELA
:
5301 case R_NDS32_TLS_LE_HI20
:
5302 case R_NDS32_TLS_LE_LO12
:
5303 case R_NDS32_TLS_IE_HI20
:
5304 case R_NDS32_TLS_IE_LO12S2
:
5305 case R_NDS32_TLS_LE_20
:
5306 case R_NDS32_TLS_LE_15S0
:
5307 case R_NDS32_TLS_LE_15S1
:
5308 case R_NDS32_TLS_LE_15S2
:
5309 /* Instruction related relocs must handle endian properly. */
5310 /* NOTE: PIC IS NOT HANDLE YET; DO IT LATER. */
5311 r
= nds32_elf_final_link_relocate (howto
, input_bfd
,
5312 input_section
, contents
,
5313 rel
->r_offset
, relocation
,
5318 /* All other relocs can use default handler. */
5319 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5320 contents
, rel
->r_offset
,
5321 relocation
, rel
->r_addend
);
5327 if (r
!= bfd_reloc_ok
)
5329 /* FIXME: This should be generic enough to go in a utility. */
5333 name
= h
->root
.root
.string
;
5336 name
= bfd_elf_string_from_elf_section
5337 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
5338 if (name
== NULL
|| *name
== '\0')
5339 name
= bfd_section_name (input_bfd
, sec
);
5347 case bfd_reloc_overflow
:
5348 (*info
->callbacks
->reloc_overflow
)
5349 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5350 (bfd_vma
) 0, input_bfd
, input_section
, offset
);
5353 case bfd_reloc_undefined
:
5354 (*info
->callbacks
->undefined_symbol
)
5355 (info
, name
, input_bfd
, input_section
, offset
, TRUE
);
5358 case bfd_reloc_outofrange
:
5359 errmsg
= _("internal error: out of range error");
5362 case bfd_reloc_notsupported
:
5363 errmsg
= _("internal error: unsupported relocation error");
5366 case bfd_reloc_dangerous
:
5367 errmsg
= _("internal error: dangerous error");
5371 errmsg
= _("internal error: unknown error");
5375 (*info
->callbacks
->warning
) (info
, errmsg
, name
, input_bfd
,
5376 input_section
, offset
);
5385 /* Finish up dynamic symbol handling. We set the contents of various
5386 dynamic sections here. */
5389 nds32_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
5390 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
)
5392 struct elf_nds32_link_hash_table
*htab
;
5395 htab
= nds32_elf_hash_table (info
);
5397 if (h
->plt
.offset
!= (bfd_vma
) - 1)
5405 bfd_vma local_plt_offset
;
5406 Elf_Internal_Rela rela
;
5408 /* This symbol has an entry in the procedure linkage table. Set
5411 BFD_ASSERT (h
->dynindx
!= -1);
5413 splt
= htab
->root
.splt
;
5414 sgot
= htab
->root
.sgotplt
;
5415 srela
= htab
->root
.srelplt
;
5416 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
5418 /* Get the index in the procedure linkage table which
5419 corresponds to this symbol. This is the index of this symbol
5420 in all the symbols for which we are making plt entries. The
5421 first entry in the procedure linkage table is reserved. */
5422 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
5424 /* Get the offset into the .got table of the entry that
5425 corresponds to this function. Each .got entry is 4 bytes.
5426 The first three are reserved. */
5427 got_offset
= (plt_index
+ 3) * 4;
5429 /* Fill in the entry in the procedure linkage table. */
5430 if (!bfd_link_pic (info
))
5434 insn
= PLT_ENTRY_WORD0
+ (((sgot
->output_section
->vma
5435 + sgot
->output_offset
+ got_offset
) >> 12)
5437 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
5439 insn
= PLT_ENTRY_WORD1
+ (((sgot
->output_section
->vma
5440 + sgot
->output_offset
+ got_offset
) & 0x0fff)
5442 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
5444 insn
= PLT_ENTRY_WORD2
;
5445 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
5447 insn
= PLT_ENTRY_WORD3
+ (plt_index
& 0x7ffff);
5448 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
5450 insn
= PLT_ENTRY_WORD4
5451 + (((unsigned int) ((-(h
->plt
.offset
+ 16)) >> 1)) & 0xffffff);
5452 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
5453 local_plt_offset
= 12;
5457 /* sda_base must be set at this time. */
5461 /* FIXME, sda_base is 65536, it will damage opcode. */
5462 /* insn = PLT_PIC_ENTRY_WORD0 + (((got_offset - sda_base) >> 2) & 0x7fff); */
5463 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ got_offset
5464 - elf_gp (output_bfd
);
5465 insn
= PLT_PIC_ENTRY_WORD0
+ ((offset
>> 12) & 0xfffff);
5466 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
);
5468 insn
= PLT_PIC_ENTRY_WORD1
+ (offset
& 0xfff);
5469 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 4);
5471 insn
= PLT_PIC_ENTRY_WORD2
;
5472 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 8);
5474 insn
= PLT_PIC_ENTRY_WORD3
;
5475 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 12);
5477 insn
= PLT_PIC_ENTRY_WORD4
+ (plt_index
& 0x7fffff);
5478 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 16);
5480 insn
= PLT_PIC_ENTRY_WORD5
5481 + (((unsigned int) ((-(h
->plt
.offset
+ 20)) >> 1)) & 0xffffff);
5482 bfd_putb32 (insn
, splt
->contents
+ h
->plt
.offset
+ 20);
5484 local_plt_offset
= 16;
5487 /* Fill in the entry in the global offset table,
5488 so it will fall through to the next instruction for the first time. */
5489 bfd_put_32 (output_bfd
,
5490 (splt
->output_section
->vma
+ splt
->output_offset
5491 + h
->plt
.offset
+ local_plt_offset
),
5492 sgot
->contents
+ got_offset
);
5494 /* Fill in the entry in the .rela.plt section. */
5495 rela
.r_offset
= (sgot
->output_section
->vma
5496 + sgot
->output_offset
+ got_offset
);
5497 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_JMP_SLOT
);
5499 loc
= srela
->contents
;
5500 loc
+= plt_index
* sizeof (Elf32_External_Rela
);
5501 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5503 if (!h
->def_regular
)
5505 /* Mark the symbol as undefined, rather than as defined in
5506 the .plt section. Leave the value alone. */
5507 sym
->st_shndx
= SHN_UNDEF
;
5508 if (!h
->ref_regular_nonweak
)
5513 if (h
->got
.offset
!= (bfd_vma
) - 1)
5517 Elf_Internal_Rela rela
;
5519 /* This symbol has an entry in the global offset table.
5522 sgot
= htab
->root
.sgot
;
5523 srela
= htab
->root
.srelgot
;
5524 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
5526 rela
.r_offset
= (sgot
->output_section
->vma
5527 + sgot
->output_offset
+ (h
->got
.offset
& ~1));
5529 /* If this is a -Bsymbolic link, and the symbol is defined
5530 locally, we just want to emit a RELATIVE reloc. Likewise if
5531 the symbol was forced to be local because of a version file.
5532 The entry in the global offset table will already have been
5533 initialized in the relocate_section function. */
5534 if (bfd_link_pic (info
)
5536 || h
->dynindx
== -1 || h
->forced_local
) && h
->def_regular
)
5538 rela
.r_info
= ELF32_R_INFO (0, R_NDS32_RELATIVE
);
5539 rela
.r_addend
= (h
->root
.u
.def
.value
5540 + h
->root
.u
.def
.section
->output_section
->vma
5541 + h
->root
.u
.def
.section
->output_offset
);
5545 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
5546 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
5547 sgot
->contents
+ h
->got
.offset
);
5548 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_GLOB_DAT
);
5552 loc
= srela
->contents
;
5553 loc
+= srela
->reloc_count
* sizeof (Elf32_External_Rela
);
5554 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5555 ++srela
->reloc_count
;
5561 Elf_Internal_Rela rela
;
5563 /* This symbols needs a copy reloc. Set it up. */
5565 BFD_ASSERT (h
->dynindx
!= -1
5566 && (h
->root
.type
== bfd_link_hash_defined
5567 || h
->root
.type
== bfd_link_hash_defweak
));
5569 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
, ".rela.bss");
5570 BFD_ASSERT (s
!= NULL
);
5572 rela
.r_offset
= (h
->root
.u
.def
.value
5573 + h
->root
.u
.def
.section
->output_section
->vma
5574 + h
->root
.u
.def
.section
->output_offset
);
5575 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_NDS32_COPY
);
5578 loc
+= s
->reloc_count
* sizeof (Elf32_External_Rela
);
5579 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5583 /* Mark some specially defined symbols as absolute. */
5584 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5585 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5586 sym
->st_shndx
= SHN_ABS
;
5592 /* Finish up the dynamic sections. */
5595 nds32_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
5597 struct elf_nds32_link_hash_table
*htab
;
5602 htab
= nds32_elf_hash_table (info
);
5603 dynobj
= htab
->root
.dynobj
;
5605 sgot
= htab
->root
.sgotplt
;
5606 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5608 if (htab
->root
.dynamic_sections_created
)
5611 Elf32_External_Dyn
*dyncon
, *dynconend
;
5613 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
5615 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5616 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5618 for (; dyncon
< dynconend
; dyncon
++)
5620 Elf_Internal_Dyn dyn
;
5623 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5631 s
= htab
->root
.sgotplt
;
5634 s
= htab
->root
.srelplt
;
5636 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
5637 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5641 s
= htab
->root
.srelplt
;
5642 dyn
.d_un
.d_val
= s
->size
;
5643 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5648 /* Fill in the first entry in the procedure linkage table. */
5649 splt
= htab
->root
.splt
;
5650 if (splt
&& splt
->size
> 0)
5652 if (bfd_link_pic (info
))
5657 /* FIXME, sda_base is 65536, it will damage opcode. */
5658 /* insn = PLT_PIC_ENTRY_WORD0 + (((got_offset - sda_base) >> 2) & 0x7fff); */
5659 offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4
5660 - elf_gp (output_bfd
);
5661 insn
= PLT0_PIC_ENTRY_WORD0
| ((offset
>> 12) & 0xfffff);
5662 bfd_putb32 (insn
, splt
->contents
);
5664 /* insn = PLT0_PIC_ENTRY_WORD0 | (((8 - sda_base) >> 2) & 0x7fff) ; */
5665 /* here has a typo? */
5666 insn
= PLT0_PIC_ENTRY_WORD1
| (offset
& 0xfff);
5667 bfd_putb32 (insn
, splt
->contents
+ 4);
5669 insn
= PLT0_PIC_ENTRY_WORD2
;
5670 bfd_putb32 (insn
, splt
->contents
+ 8);
5672 insn
= PLT0_PIC_ENTRY_WORD3
;
5673 bfd_putb32 (insn
, splt
->contents
+ 12);
5675 insn
= PLT0_PIC_ENTRY_WORD4
;
5676 bfd_putb32 (insn
, splt
->contents
+ 16);
5678 insn
= PLT0_PIC_ENTRY_WORD5
;
5679 bfd_putb32 (insn
, splt
->contents
+ 20);
5686 /* addr = .got + 4 */
5687 addr
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4;
5688 insn
= PLT0_ENTRY_WORD0
| ((addr
>> 12) & 0xfffff);
5689 bfd_putb32 (insn
, splt
->contents
);
5691 insn
= PLT0_ENTRY_WORD1
| (addr
& 0x0fff);
5692 bfd_putb32 (insn
, splt
->contents
+ 4);
5694 insn
= PLT0_ENTRY_WORD2
;
5695 bfd_putb32 (insn
, splt
->contents
+ 8);
5697 insn
= PLT0_ENTRY_WORD3
;
5698 bfd_putb32 (insn
, splt
->contents
+ 12);
5700 insn
= PLT0_ENTRY_WORD4
;
5701 bfd_putb32 (insn
, splt
->contents
+ 16);
5704 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
5709 /* Fill in the first three entries in the global offset table. */
5710 if (sgot
&& sgot
->size
> 0)
5713 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5715 bfd_put_32 (output_bfd
,
5716 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5718 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
5719 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
5721 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5728 /* Set the right machine number. */
5731 nds32_elf_object_p (bfd
*abfd
)
5733 static unsigned int cur_arch
= 0;
5735 if (E_N1_ARCH
!= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
))
5737 /* E_N1_ARCH is a wild card, so it is set only when no others exist. */
5738 cur_arch
= (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
);
5745 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1
);
5748 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h
);
5750 case E_NDS_ARCH_STAR_V2_0
:
5751 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v2
);
5753 case E_NDS_ARCH_STAR_V3_0
:
5754 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3
);
5756 case E_NDS_ARCH_STAR_V3_M
:
5757 bfd_default_set_arch_mach (abfd
, bfd_arch_nds32
, bfd_mach_n1h_v3m
);
5764 /* Store the machine number in the flags field. */
5767 nds32_elf_final_write_processing (bfd
*abfd
,
5768 bfd_boolean linker ATTRIBUTE_UNUSED
)
5771 static unsigned int cur_mach
= 0;
5773 if (bfd_mach_n1
!= bfd_get_mach (abfd
))
5775 cur_mach
= bfd_get_mach (abfd
);
5781 /* Only happen when object is empty, since the case is abandon. */
5783 val
|= E_NDS_ABI_AABI
;
5784 val
|= E_NDS32_ELF_VER_1_4
;
5789 case bfd_mach_n1h_v2
:
5790 val
= E_NDS_ARCH_STAR_V2_0
;
5792 case bfd_mach_n1h_v3
:
5793 val
= E_NDS_ARCH_STAR_V3_0
;
5795 case bfd_mach_n1h_v3m
:
5796 val
= E_NDS_ARCH_STAR_V3_M
;
5803 elf_elfheader (abfd
)->e_flags
&= ~EF_NDS_ARCH
;
5804 elf_elfheader (abfd
)->e_flags
|= val
;
5807 /* Function to keep NDS32 specific file flags. */
5810 nds32_elf_set_private_flags (bfd
*abfd
, flagword flags
)
5812 BFD_ASSERT (!elf_flags_init (abfd
)
5813 || elf_elfheader (abfd
)->e_flags
== flags
);
5815 elf_elfheader (abfd
)->e_flags
= flags
;
5816 elf_flags_init (abfd
) = TRUE
;
5821 convert_e_flags (unsigned int e_flags
, unsigned int arch
)
5823 if ((e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
)
5825 /* From 0.9 to 1.0. */
5826 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V1_0
;
5828 /* Invert E_NDS32_HAS_NO_MAC_INST. */
5829 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
5830 if (arch
== E_NDS_ARCH_STAR_V1_0
)
5837 /* From 1.0 to 2.0. */
5838 e_flags
= (e_flags
& (~EF_NDS_ARCH
)) | E_NDS_ARCH_STAR_V2_0
;
5840 /* Clear E_NDS32_HAS_MFUSR_PC_INST. */
5841 e_flags
&= ~E_NDS32_HAS_MFUSR_PC_INST
;
5843 /* Invert E_NDS32_HAS_NO_MAC_INST. */
5844 e_flags
^= E_NDS32_HAS_NO_MAC_INST
;
5849 nds32_check_vec_size (bfd
*ibfd
)
5851 static unsigned int nds32_vec_size
= 0;
5853 asection
*sec_t
= NULL
;
5854 bfd_byte
*contents
= NULL
;
5856 sec_t
= bfd_get_section_by_name (ibfd
, ".nds32_e_flags");
5858 if (sec_t
&& sec_t
->size
>= 4)
5860 /* Get vec_size in file. */
5861 unsigned int flag_t
;
5863 nds32_get_section_contents (ibfd
, sec_t
, &contents
, TRUE
);
5864 flag_t
= bfd_get_32 (ibfd
, contents
);
5866 /* The value could only be 4 or 16. */
5868 if (!nds32_vec_size
)
5869 /* Set if not set yet. */
5870 nds32_vec_size
= (flag_t
& 0x3);
5871 else if (nds32_vec_size
!= (flag_t
& 0x3))
5874 /* xgettext:c-format */
5875 (_("%B: ISR vector size mismatch"
5876 " with previous modules, previous %u-byte, current %u-byte"),
5878 nds32_vec_size
== 1 ? 4 : nds32_vec_size
== 2 ? 16 : 0xffffffff,
5879 (flag_t
& 0x3) == 1 ? 4 : (flag_t
& 0x3) == 2 ? 16 : 0xffffffff);
5883 /* Only keep the first vec_size section. */
5884 sec_t
->flags
|= SEC_EXCLUDE
;
5890 /* Merge backend specific data from an object file to the output
5891 object file when linking. */
5894 nds32_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5896 bfd
*obfd
= info
->output_bfd
;
5899 flagword out_16regs
;
5901 flagword out_no_mac
;
5903 flagword out_version
;
5904 flagword in_version
;
5905 flagword out_fpu_config
;
5906 flagword in_fpu_config
;
5908 /* TODO: Revise to use object-attributes instead. */
5909 if (!nds32_check_vec_size (ibfd
))
5912 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5913 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5916 if (bfd_little_endian (ibfd
) != bfd_little_endian (obfd
))
5919 (_("%B: warning: Endian mismatch with previous modules."), ibfd
);
5921 bfd_set_error (bfd_error_bad_value
);
5925 in_version
= elf_elfheader (ibfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
5926 if (in_version
== E_NDS32_ELF_VER_1_2
)
5929 (_("%B: warning: Older version of object file encountered, "
5930 "Please recompile with current tool chain."), ibfd
);
5933 /* We may need to merge V1 and V2 arch object files to V2. */
5934 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5935 != (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
5937 /* Need to convert version. */
5938 if ((elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5939 == E_NDS_ARCH_STAR_RESERVED
)
5941 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
5943 else if ((elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
) == E_NDS_ARCH_STAR_V0_9
5944 || (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
)
5945 > (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
))
5947 elf_elfheader (obfd
)->e_flags
=
5948 convert_e_flags (elf_elfheader (obfd
)->e_flags
,
5949 (elf_elfheader (ibfd
)->e_flags
& EF_NDS_ARCH
));
5953 elf_elfheader (ibfd
)->e_flags
=
5954 convert_e_flags (elf_elfheader (ibfd
)->e_flags
,
5955 (elf_elfheader (obfd
)->e_flags
& EF_NDS_ARCH
));
5959 /* Extract some flags. */
5960 in_flags
= elf_elfheader (ibfd
)->e_flags
5961 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
5962 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
5964 /* The following flags need special treatment. */
5965 in_16regs
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
5966 in_no_mac
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
5967 in_fpu_config
= elf_elfheader (ibfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
5969 /* Extract some flags. */
5970 out_flags
= elf_elfheader (obfd
)->e_flags
5971 & (~(E_NDS32_HAS_REDUCED_REGS
| EF_NDS32_ELF_VERSION
5972 | E_NDS32_HAS_NO_MAC_INST
| E_NDS32_FPU_REG_CONF
));
5974 /* The following flags need special treatment. */
5975 out_16regs
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_REDUCED_REGS
;
5976 out_no_mac
= elf_elfheader (obfd
)->e_flags
& E_NDS32_HAS_NO_MAC_INST
;
5977 out_fpu_config
= elf_elfheader (obfd
)->e_flags
& E_NDS32_FPU_REG_CONF
;
5978 out_version
= elf_elfheader (obfd
)->e_flags
& EF_NDS32_ELF_VERSION
;
5979 if (!elf_flags_init (obfd
))
5981 /* If the input is the default architecture then do not
5982 bother setting the flags for the output architecture,
5983 instead allow future merges to do this. If no future
5984 merges ever set these flags then they will retain their
5985 unitialised values, which surprise surprise, correspond
5986 to the default values. */
5987 if (bfd_get_arch_info (ibfd
)->the_default
)
5990 elf_flags_init (obfd
) = TRUE
;
5991 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
5993 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5994 && bfd_get_arch_info (obfd
)->the_default
)
5996 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
5997 bfd_get_mach (ibfd
));
6003 /* Check flag compatibility. */
6004 if ((in_flags
& EF_NDS_ABI
) != (out_flags
& EF_NDS_ABI
))
6007 (_("%B: error: ABI mismatch with previous modules."), ibfd
);
6009 bfd_set_error (bfd_error_bad_value
);
6013 if ((in_flags
& EF_NDS_ARCH
) != (out_flags
& EF_NDS_ARCH
))
6015 if (((in_flags
& EF_NDS_ARCH
) != E_N1_ARCH
))
6018 (_("%B: error: Instruction set mismatch with previous modules."), ibfd
);
6020 bfd_set_error (bfd_error_bad_value
);
6025 /* When linking with V1.2 and V1.3 objects together the output is V1.2.
6026 and perf ext1 and DIV are mergerd to perf ext1. */
6027 if (in_version
== E_NDS32_ELF_VER_1_2
|| out_version
== E_NDS32_ELF_VER_1_2
)
6029 elf_elfheader (obfd
)->e_flags
=
6030 (in_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6031 | (out_flags
& (~(E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6032 | (((in_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6033 ? E_NDS32_HAS_EXT_INST
: 0)
6034 | (((out_flags
& (E_NDS32_HAS_EXT_INST
| E_NDS32_HAS_DIV_INST
)))
6035 ? E_NDS32_HAS_EXT_INST
: 0)
6036 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6037 | ((in_version
> out_version
) ? out_version
: in_version
);
6041 if (in_version
!= out_version
)
6043 /* xgettext:c-format */
6044 (_("%B: warning: Incompatible elf-versions %s and %s."),
6045 ibfd
, nds32_elfver_strtab
[out_version
],
6046 nds32_elfver_strtab
[in_version
]);
6048 elf_elfheader (obfd
)->e_flags
= in_flags
| out_flags
6049 | (in_16regs
& out_16regs
) | (in_no_mac
& out_no_mac
)
6050 | (in_fpu_config
> out_fpu_config
? in_fpu_config
: out_fpu_config
)
6051 | (in_version
> out_version
? out_version
: in_version
);
6057 /* Display the flags field. */
6060 nds32_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6062 FILE *file
= (FILE *) ptr
;
6064 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6066 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6068 fprintf (file
, _("private flags = %lx"), elf_elfheader (abfd
)->e_flags
);
6070 switch (elf_elfheader (abfd
)->e_flags
& EF_NDS_ARCH
)
6074 fprintf (file
, _(": n1 instructions"));
6077 fprintf (file
, _(": n1h instructions"));
6087 nds32_elf_action_discarded (asection
*sec
)
6091 (".gcc_except_table", sec
->name
, sizeof (".gcc_except_table") - 1) == 0)
6094 return _bfd_elf_default_action_discarded (sec
);
6098 nds32_elf_gc_mark_hook (asection
*sec
, struct bfd_link_info
*info
,
6099 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
6100 Elf_Internal_Sym
*sym
)
6103 switch (ELF32_R_TYPE (rel
->r_info
))
6105 case R_NDS32_GNU_VTINHERIT
:
6106 case R_NDS32_GNU_VTENTRY
:
6107 case R_NDS32_RELA_GNU_VTINHERIT
:
6108 case R_NDS32_RELA_GNU_VTENTRY
:
6112 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6115 /* Look through the relocs for a section during the first phase.
6116 Since we don't do .gots or .plts, we just need to consider the
6117 virtual table relocs for gc. */
6120 nds32_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6121 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6123 Elf_Internal_Shdr
*symtab_hdr
;
6124 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6125 const Elf_Internal_Rela
*rel
;
6126 const Elf_Internal_Rela
*rel_end
;
6127 struct elf_nds32_link_hash_table
*htab
;
6129 asection
*sreloc
= NULL
;
6131 if (bfd_link_relocatable (info
))
6134 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6135 sym_hashes
= elf_sym_hashes (abfd
);
6137 sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6138 if (!elf_bad_symtab (abfd
))
6139 sym_hashes_end
-= symtab_hdr
->sh_info
;
6141 htab
= nds32_elf_hash_table (info
);
6142 dynobj
= htab
->root
.dynobj
;
6144 rel_end
= relocs
+ sec
->reloc_count
;
6145 for (rel
= relocs
; rel
< rel_end
; rel
++)
6147 enum elf_nds32_reloc_type r_type
;
6148 struct elf_link_hash_entry
*h
;
6149 unsigned long r_symndx
;
6150 int tls_type
, old_tls_type
;
6152 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6153 r_type
= ELF32_R_TYPE (rel
->r_info
);
6154 if (r_symndx
< symtab_hdr
->sh_info
)
6158 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6159 while (h
->root
.type
== bfd_link_hash_indirect
6160 || h
->root
.type
== bfd_link_hash_warning
)
6161 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6164 /* Some relocs require a global offset table. We create
6165 got section here, since these relocation need got section
6166 and it is not created yet. */
6167 if (htab
->root
.sgot
== NULL
)
6171 case R_NDS32_GOT_HI20
:
6172 case R_NDS32_GOT_LO12
:
6173 case R_NDS32_GOT_LO15
:
6174 case R_NDS32_GOT_LO19
:
6175 case R_NDS32_GOT17S2_RELA
:
6176 case R_NDS32_GOT15S2_RELA
:
6177 case R_NDS32_GOTOFF
:
6178 case R_NDS32_GOTOFF_HI20
:
6179 case R_NDS32_GOTOFF_LO12
:
6180 case R_NDS32_GOTOFF_LO15
:
6181 case R_NDS32_GOTOFF_LO19
:
6182 case R_NDS32_GOTPC20
:
6183 case R_NDS32_GOTPC_HI20
:
6184 case R_NDS32_GOTPC_LO12
:
6186 case R_NDS32_TLS_IE_HI20
:
6187 case R_NDS32_TLS_IE_LO12S2
:
6189 htab
->root
.dynobj
= dynobj
= abfd
;
6190 if (!_bfd_elf_create_got_section (dynobj
, info
))
6199 switch ((int) r_type
)
6201 case R_NDS32_GOT_HI20
:
6202 case R_NDS32_GOT_LO12
:
6203 case R_NDS32_GOT_LO15
:
6204 case R_NDS32_GOT_LO19
:
6206 case R_NDS32_TLS_IE_HI20
:
6207 case R_NDS32_TLS_IE_LO12S2
:
6210 case R_NDS32_TLS_IE_HI20
:
6211 case R_NDS32_TLS_IE_LO12S2
:
6212 tls_type
= GOT_TLS_IE
;
6215 tls_type
= GOT_NORMAL
;
6220 old_tls_type
= elf32_nds32_hash_entry (h
)->tls_type
;
6221 h
->got
.refcount
+= 1;
6225 bfd_signed_vma
*local_got_refcounts
;
6227 /* This is a global offset table entry for a local
6229 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6230 if (local_got_refcounts
== NULL
)
6234 size
= symtab_hdr
->sh_info
;
6235 size
*= sizeof (bfd_signed_vma
);
6236 local_got_refcounts
= (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
6237 if (local_got_refcounts
== NULL
)
6239 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6241 local_got_refcounts
[r_symndx
] += 1;
6242 old_tls_type
= elf32_nds32_local_got_tls_type (abfd
)[r_symndx
];
6245 /* We will already have issued an error message if there
6246 is a TLS/non-TLS mismatch, based on the symbol
6247 type. So just combine any TLS types needed. */
6248 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
6249 && tls_type
!= GOT_NORMAL
)
6250 tls_type
|= old_tls_type
;
6252 if (old_tls_type
!= tls_type
)
6255 elf32_nds32_hash_entry (h
)->tls_type
= tls_type
;
6257 elf32_nds32_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
6260 case R_NDS32_9_PLTREL
:
6261 case R_NDS32_25_PLTREL
:
6262 case R_NDS32_PLTREL_HI20
:
6263 case R_NDS32_PLTREL_LO12
:
6264 case R_NDS32_PLT_GOTREL_HI20
:
6265 case R_NDS32_PLT_GOTREL_LO12
:
6266 case R_NDS32_PLT_GOTREL_LO15
:
6267 case R_NDS32_PLT_GOTREL_LO19
:
6268 case R_NDS32_PLT_GOTREL_LO20
:
6270 /* This symbol requires a procedure linkage table entry. We
6271 actually build the entry in adjust_dynamic_symbol,
6272 because this might be a case of linking PIC code without
6273 linking in any dynamic objects, in which case we don't
6274 need to generate a procedure linkage table after all. */
6276 /* If this is a local symbol, we resolve it directly without
6277 creating a procedure linkage table entry. */
6281 if (h
->forced_local
)
6284 elf32_nds32_hash_entry (h
)->tls_type
= GOT_NORMAL
;
6286 h
->plt
.refcount
+= 1;
6289 case R_NDS32_16_RELA
:
6290 case R_NDS32_20_RELA
:
6291 case R_NDS32_5_RELA
:
6292 case R_NDS32_32_RELA
:
6293 case R_NDS32_HI20_RELA
:
6294 case R_NDS32_LO12S3_RELA
:
6295 case R_NDS32_LO12S2_RELA
:
6296 case R_NDS32_LO12S2_DP_RELA
:
6297 case R_NDS32_LO12S2_SP_RELA
:
6298 case R_NDS32_LO12S1_RELA
:
6299 case R_NDS32_LO12S0_RELA
:
6300 case R_NDS32_LO12S0_ORI_RELA
:
6301 case R_NDS32_SDA16S3_RELA
:
6302 case R_NDS32_SDA17S2_RELA
:
6303 case R_NDS32_SDA18S1_RELA
:
6304 case R_NDS32_SDA19S0_RELA
:
6305 case R_NDS32_SDA15S3_RELA
:
6306 case R_NDS32_SDA15S2_RELA
:
6307 case R_NDS32_SDA12S2_DP_RELA
:
6308 case R_NDS32_SDA12S2_SP_RELA
:
6309 case R_NDS32_SDA15S1_RELA
:
6310 case R_NDS32_SDA15S0_RELA
:
6311 case R_NDS32_SDA_FP7U2_RELA
:
6312 case R_NDS32_15_PCREL_RELA
:
6313 case R_NDS32_17_PCREL_RELA
:
6314 case R_NDS32_25_PCREL_RELA
:
6316 if (h
!= NULL
&& !bfd_link_pic (info
))
6319 h
->plt
.refcount
+= 1;
6322 /* If we are creating a shared library, and this is a reloc against
6323 a global symbol, or a non PC relative reloc against a local
6324 symbol, then we need to copy the reloc into the shared library.
6325 However, if we are linking with -Bsymbolic, we do not need to
6326 copy a reloc against a global symbol which is defined in an
6327 object we are including in the link (i.e., DEF_REGULAR is set).
6328 At this point we have not seen all the input files, so it is
6329 possible that DEF_REGULAR is not set now but will be set later
6330 (it is never cleared). We account for that possibility below by
6331 storing information in the dyn_relocs field of the hash table
6332 entry. A similar situation occurs when creating shared libraries
6333 and symbol visibility changes render the symbol local.
6335 If on the other hand, we are creating an executable, we may need
6336 to keep relocations for symbols satisfied by a dynamic library
6337 if we manage to avoid copy relocs for the symbol. */
6338 if ((bfd_link_pic (info
)
6339 && (sec
->flags
& SEC_ALLOC
) != 0
6340 && ((r_type
!= R_NDS32_25_PCREL_RELA
6341 && r_type
!= R_NDS32_15_PCREL_RELA
6342 && r_type
!= R_NDS32_17_PCREL_RELA
6343 && !(r_type
== R_NDS32_32_RELA
6344 && strcmp (sec
->name
, ".eh_frame") == 0))
6347 || h
->root
.type
== bfd_link_hash_defweak
6348 || !h
->def_regular
))))
6349 || (!bfd_link_pic (info
)
6350 && (sec
->flags
& SEC_ALLOC
) != 0
6352 && (h
->root
.type
== bfd_link_hash_defweak
6353 || !h
->def_regular
)))
6355 struct elf_nds32_dyn_relocs
*p
;
6356 struct elf_nds32_dyn_relocs
**head
;
6359 htab
->root
.dynobj
= dynobj
= abfd
;
6361 /* When creating a shared object, we must copy these
6362 relocs into the output file. We create a reloc
6363 section in dynobj and make room for the reloc. */
6368 name
= bfd_elf_string_from_elf_section
6369 (abfd
, elf_elfheader (abfd
)->e_shstrndx
,
6370 elf_section_data (sec
)->rela
.hdr
->sh_name
);
6374 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6375 && strcmp (bfd_get_section_name (abfd
, sec
),
6378 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6383 sreloc
= bfd_make_section (dynobj
, name
);
6384 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6385 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6386 if ((sec
->flags
& SEC_ALLOC
) != 0)
6387 flags
|= SEC_ALLOC
| SEC_LOAD
;
6389 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
6390 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
6393 elf_section_type (sreloc
) = SHT_RELA
;
6395 elf_section_data (sec
)->sreloc
= sreloc
;
6398 /* If this is a global symbol, we count the number of
6399 relocations we need for this symbol. */
6401 head
= &((struct elf_nds32_link_hash_entry
*) h
)->dyn_relocs
;
6407 Elf_Internal_Sym
*isym
;
6408 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, abfd
, r_symndx
);
6412 /* Track dynamic relocs needed for local syms too. */
6413 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6417 vpp
= &elf_section_data (s
)->local_dynrel
;
6418 head
= (struct elf_nds32_dyn_relocs
**) vpp
;
6422 if (p
== NULL
|| p
->sec
!= sec
)
6424 bfd_size_type amt
= sizeof (*p
);
6425 p
= (struct elf_nds32_dyn_relocs
*) bfd_alloc (dynobj
, amt
);
6436 if (ELF32_R_TYPE (rel
->r_info
) == R_NDS32_25_PCREL_RELA
6437 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_15_PCREL_RELA
6438 || ELF32_R_TYPE (rel
->r_info
) == R_NDS32_17_PCREL_RELA
)
6443 /* This relocation describes the C++ object vtable hierarchy.
6444 Reconstruct it for later use during GC. */
6445 case R_NDS32_RELA_GNU_VTINHERIT
:
6446 case R_NDS32_GNU_VTINHERIT
:
6447 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6451 /* This relocation describes which C++ vtable entries are actually
6452 used. Record for later use during GC. */
6453 case R_NDS32_GNU_VTENTRY
:
6454 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6457 case R_NDS32_RELA_GNU_VTENTRY
:
6458 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6467 /* Write VAL in uleb128 format to P, returning a pointer to the
6469 This code is copied from elf-attr.c. */
6472 write_uleb128 (bfd_byte
*p
, unsigned int val
)
6487 static bfd_signed_vma
6488 calculate_offset (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
6489 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
,
6490 int *pic_ext_target
)
6492 bfd_signed_vma foff
;
6493 bfd_vma symval
, addend
;
6496 /* Get the value of the symbol referred to by the reloc. */
6497 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6499 Elf_Internal_Sym
*isym
;
6501 /* A local symbol. */
6502 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6504 if (isym
->st_shndx
== SHN_UNDEF
)
6505 sym_sec
= bfd_und_section_ptr
;
6506 else if (isym
->st_shndx
== SHN_ABS
)
6507 sym_sec
= bfd_abs_section_ptr
;
6508 else if (isym
->st_shndx
== SHN_COMMON
)
6509 sym_sec
= bfd_com_section_ptr
;
6511 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6512 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
6513 + sym_sec
->output_offset
;
6518 struct elf_link_hash_entry
*h
;
6521 /* An external symbol. */
6522 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6523 h
= elf_sym_hashes (abfd
)[indx
];
6524 BFD_ASSERT (h
!= NULL
);
6526 if (h
->root
.type
!= bfd_link_hash_defined
6527 && h
->root
.type
!= bfd_link_hash_defweak
)
6528 /* This appears to be a reference to an undefined
6529 symbol. Just ignore it--it will be caught by the
6530 regular reloc processing. */
6532 owner
= h
->root
.u
.def
.section
->owner
;
6533 if (owner
&& (elf_elfheader (owner
)->e_flags
& E_NDS32_HAS_PIC
))
6534 *pic_ext_target
= 1;
6536 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
6538 sym_sec
= h
->root
.u
.def
.section
;
6539 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
,
6540 elf_section_data (sym_sec
)->sec_info
,
6541 h
->root
.u
.def
.value
);
6542 symval
= symval
+ sym_sec
->output_section
->vma
6543 + sym_sec
->output_offset
;
6546 symval
= (h
->root
.u
.def
.value
6547 + h
->root
.u
.def
.section
->output_section
->vma
6548 + h
->root
.u
.def
.section
->output_offset
);
6551 addend
= irel
->r_addend
;
6553 foff
= (symval
+ addend
6554 - (irel
->r_offset
+ sec
->output_section
->vma
+ sec
->output_offset
));
6559 calculate_plt_memory_address (bfd
*abfd
, struct bfd_link_info
*link_info
,
6560 Elf_Internal_Sym
*isymbuf
,
6561 Elf_Internal_Rela
*irel
,
6562 Elf_Internal_Shdr
*symtab_hdr
)
6566 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6568 Elf_Internal_Sym
*isym
;
6570 /* A local symbol. */
6571 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6573 if (isym
->st_shndx
== SHN_UNDEF
)
6574 sym_sec
= bfd_und_section_ptr
;
6575 else if (isym
->st_shndx
== SHN_ABS
)
6576 sym_sec
= bfd_abs_section_ptr
;
6577 else if (isym
->st_shndx
== SHN_COMMON
)
6578 sym_sec
= bfd_com_section_ptr
;
6580 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6581 symval
= isym
->st_value
+ sym_sec
->output_section
->vma
6582 + sym_sec
->output_offset
;
6587 struct elf_link_hash_entry
*h
;
6588 struct elf_nds32_link_hash_table
*htab
;
6591 /* An external symbol. */
6592 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6593 h
= elf_sym_hashes (abfd
)[indx
];
6594 BFD_ASSERT (h
!= NULL
);
6595 htab
= nds32_elf_hash_table (link_info
);
6596 splt
= htab
->root
.splt
;
6598 while (h
->root
.type
== bfd_link_hash_indirect
6599 || h
->root
.type
== bfd_link_hash_warning
)
6600 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6602 if (h
->plt
.offset
== (bfd_vma
) - 1)
6604 if (h
->root
.type
!= bfd_link_hash_defined
6605 && h
->root
.type
!= bfd_link_hash_defweak
)
6606 /* This appears to be a reference to an undefined
6607 * symbol. Just ignore it--it will be caught by the
6608 * regular reloc processing. */
6610 symval
= (h
->root
.u
.def
.value
6611 + h
->root
.u
.def
.section
->output_section
->vma
6612 + h
->root
.u
.def
.section
->output_offset
);
6615 symval
= splt
->output_section
->vma
+ h
->plt
.offset
;
6621 static bfd_signed_vma
6622 calculate_plt_offset (bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
6623 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Rela
*irel
,
6624 Elf_Internal_Shdr
*symtab_hdr
)
6627 if ((foff
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
, irel
,
6631 return foff
- (irel
->r_offset
6632 + sec
->output_section
->vma
+ sec
->output_offset
);
6635 /* Convert a 32-bit instruction to 16-bit one.
6636 INSN is the input 32-bit instruction, INSN16 is the output 16-bit
6637 instruction. If INSN_TYPE is not NULL, it the CGEN instruction
6638 type of INSN16. Return 1 if successful. */
6641 nds32_convert_32_to_16_alu1 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6644 uint16_t insn16
= 0;
6646 unsigned long mach
= bfd_get_mach (abfd
);
6648 if (N32_SH5 (insn
) != 0)
6651 switch (N32_SUB5 (insn
))
6653 case N32_ALU1_ADD_SLLI
:
6654 case N32_ALU1_ADD_SRLI
:
6655 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
6657 insn16
= N16_TYPE333 (ADD333
, N32_RT5 (insn
), N32_RA5 (insn
),
6659 insn_type
= NDS32_INSN_ADD333
;
6661 else if (N32_IS_RT4 (insn
))
6663 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6664 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RB5 (insn
));
6665 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6666 insn16
= N16_TYPE45 (ADD45
, N32_RT54 (insn
), N32_RA5 (insn
));
6667 insn_type
= NDS32_INSN_ADD45
;
6671 case N32_ALU1_SUB_SLLI
:
6672 case N32_ALU1_SUB_SRLI
:
6673 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IS_RB3 (insn
))
6675 insn16
= N16_TYPE333 (SUB333
, N32_RT5 (insn
), N32_RA5 (insn
),
6677 insn_type
= NDS32_INSN_SUB333
;
6679 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6681 insn16
= N16_TYPE45 (SUB45
, N32_RT54 (insn
), N32_RB5 (insn
));
6682 insn_type
= NDS32_INSN_SUB45
;
6686 case N32_ALU1_AND_SLLI
:
6687 case N32_ALU1_AND_SRLI
:
6688 /* and $rt, $rt, $rb -> and33 for v3, v3m. */
6689 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6690 && N32_IS_RB3 (insn
))
6692 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6693 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RB5 (insn
));
6694 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6695 insn16
= N16_MISC33 (AND33
, N32_RT5 (insn
), N32_RA5 (insn
));
6697 insn_type
= NDS32_INSN_AND33
;
6701 case N32_ALU1_XOR_SLLI
:
6702 case N32_ALU1_XOR_SRLI
:
6703 /* xor $rt, $rt, $rb -> xor33 for v3, v3m. */
6704 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6705 && N32_IS_RB3 (insn
))
6707 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6708 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RB5 (insn
));
6709 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6710 insn16
= N16_MISC33 (XOR33
, N32_RT5 (insn
), N32_RA5 (insn
));
6712 insn_type
= NDS32_INSN_XOR33
;
6716 case N32_ALU1_OR_SLLI
:
6717 case N32_ALU1_OR_SRLI
:
6718 /* or $rt, $rt, $rb -> or33 for v3, v3m. */
6719 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6720 && N32_IS_RB3 (insn
))
6722 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6723 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RB5 (insn
));
6724 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6725 insn16
= N16_MISC33 (OR33
, N32_RT5 (insn
), N32_RA5 (insn
));
6727 insn_type
= NDS32_INSN_OR33
;
6731 /* nor $rt, $ra, $ra -> not33 for v3, v3m. */
6732 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RB3 (insn
)
6733 && N32_RA5 (insn
) == N32_RB5 (insn
))
6735 insn16
= N16_MISC33 (NOT33
, N32_RT5 (insn
), N32_RA5 (insn
));
6736 insn_type
= NDS32_INSN_NOT33
;
6740 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6742 insn16
= N16_TYPE45 (SRAI45
, N32_RT54 (insn
), N32_UB5 (insn
));
6743 insn_type
= NDS32_INSN_SRAI45
;
6748 if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
))
6750 insn16
= N16_TYPE45 (SRLI45
, N32_RT54 (insn
), N32_UB5 (insn
));
6751 insn_type
= NDS32_INSN_SRLI45
;
6756 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_UB5 (insn
) < 8)
6758 insn16
= N16_TYPE333 (SLLI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6760 insn_type
= NDS32_INSN_SLLI333
;
6765 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6767 insn16
= N16_BFMI333 (ZEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
6768 insn_type
= NDS32_INSN_ZEH33
;
6773 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6775 insn16
= N16_BFMI333 (SEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6776 insn_type
= NDS32_INSN_SEB33
;
6781 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6783 insn16
= N16_BFMI333 (SEH33
, N32_RT5 (insn
), N32_RA5 (insn
));
6784 insn_type
= NDS32_INSN_SEH33
;
6789 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
6792 insn16
= N16_TYPE45 (SLT45
, N32_RA54 (insn
), N32_RB5 (insn
));
6793 insn_type
= NDS32_INSN_SLT45
;
6798 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
))
6801 insn16
= N16_TYPE45 (SLTS45
, N32_RA54 (insn
), N32_RB5 (insn
));
6802 insn_type
= NDS32_INSN_SLTS45
;
6807 if ((insn16
& 0x8000) == 0)
6813 *pinsn_type
= insn_type
;
6818 nds32_convert_32_to_16_alu2 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6821 uint16_t insn16
= 0;
6823 unsigned long mach
= bfd_get_mach (abfd
);
6825 /* TODO: bset, bclr, btgl, btst. */
6826 if (__GF (insn
, 6, 4) != 0)
6829 switch (N32_IMMU (insn
, 6))
6832 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
6833 && N32_IS_RB3 (insn
))
6835 if (N32_RT5 (insn
) == N32_RA5 (insn
))
6836 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RB5 (insn
));
6837 else if (N32_RT5 (insn
) == N32_RB5 (insn
))
6838 insn16
= N16_MISC33 (MUL33
, N32_RT5 (insn
), N32_RA5 (insn
));
6840 insn_type
= NDS32_INSN_MUL33
;
6844 if ((insn16
& 0x8000) == 0)
6850 *pinsn_type
= insn_type
;
6855 nds32_convert_32_to_16 (bfd
*abfd
, uint32_t insn
, uint16_t *pinsn16
,
6859 uint16_t insn16
= 0;
6861 unsigned long mach
= bfd_get_mach (abfd
);
6863 /* Decode 32-bit instruction. */
6864 if (insn
& 0x80000000)
6866 /* Not 32-bit insn. */
6870 op6
= N32_OP6 (insn
);
6872 /* Convert it to 16-bit instruction. */
6876 if (IS_WITHIN_S (N32_IMM20S (insn
), 5))
6878 insn16
= N16_TYPE55 (MOVI55
, N32_RT5 (insn
), N32_IMM20S (insn
));
6879 insn_type
= NDS32_INSN_MOVI55
;
6881 else if (mach
>= MACH_V3
&& N32_IMM20S (insn
) >= 16
6882 && N32_IMM20S (insn
) < 48 && N32_IS_RT4 (insn
))
6884 insn16
= N16_TYPE45 (MOVPI45
, N32_RT54 (insn
),
6885 N32_IMM20S (insn
) - 16);
6886 insn_type
= NDS32_INSN_MOVPI45
;
6891 if (N32_IMM15S (insn
) == 0)
6893 /* Do not convert `addi $sp, $sp, 0' to `mov55 $sp, $sp',
6894 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
6896 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
6898 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
6899 insn_type
= NDS32_INSN_MOV55
;
6902 else if (N32_IMM15S (insn
) > 0)
6904 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) < 8)
6906 insn16
= N16_TYPE333 (ADDI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6908 insn_type
= NDS32_INSN_ADDI333
;
6910 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
6911 && N32_IMM15S (insn
) < 32)
6913 insn16
= N16_TYPE45 (ADDI45
, N32_RT54 (insn
), N32_IMM15S (insn
));
6914 insn_type
= NDS32_INSN_ADDI45
;
6916 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
6917 && N32_RT5 (insn
) == N32_RA5 (insn
)
6918 && N32_IMM15S (insn
) < 512)
6920 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
6921 insn_type
= NDS32_INSN_ADDI10_SP
;
6923 else if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
6924 && N32_RA5 (insn
) == REG_SP
&& N32_IMM15S (insn
) < 256
6925 && (N32_IMM15S (insn
) % 4 == 0))
6927 insn16
= N16_TYPE36 (ADDRI36_SP
, N32_RT5 (insn
),
6928 N32_IMM15S (insn
) >> 2);
6929 insn_type
= NDS32_INSN_ADDRI36_SP
;
6935 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) > -8)
6937 insn16
= N16_TYPE333 (SUBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
6938 0 - N32_IMM15S (insn
));
6939 insn_type
= NDS32_INSN_SUBI333
;
6941 else if (N32_IS_RT4 (insn
) && N32_RT5 (insn
) == N32_RA5 (insn
)
6942 && N32_IMM15S (insn
) > -32)
6944 insn16
= N16_TYPE45 (SUBI45
, N32_RT54 (insn
),
6945 0 - N32_IMM15S (insn
));
6946 insn_type
= NDS32_INSN_SUBI45
;
6948 else if (mach
>= MACH_V2
&& N32_RT5 (insn
) == REG_SP
6949 && N32_RT5 (insn
) == N32_RA5 (insn
)
6950 && N32_IMM15S (insn
) >= -512)
6952 insn16
= N16_TYPE10 (ADDI10S
, N32_IMM15S (insn
));
6953 insn_type
= NDS32_INSN_ADDI10_SP
;
6959 if (N32_IMM15S (insn
) == 0)
6961 /* Do not convert `ori $sp, $sp, 0' to `mov55 $sp, $sp',
6962 because `mov55 $sp, $sp' is ifret16 in V3 ISA. */
6964 || N32_RT5 (insn
) != REG_SP
|| N32_RA5 (insn
) != REG_SP
)
6966 insn16
= N16_TYPE55 (MOV55
, N32_RT5 (insn
), N32_RA5 (insn
));
6967 insn_type
= NDS32_INSN_MOV55
;
6973 if (mach
>= MACH_V3
&& N32_IS_RT3 (insn
)
6974 && N32_IS_RA3 (insn
) && N32_IMM15S (insn
) == 0)
6976 insn16
= N16_MISC33 (NEG33
, N32_RT5 (insn
), N32_RA5 (insn
));
6977 insn_type
= NDS32_INSN_NEG33
;
6982 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
))
6984 if (N32_IMM15U (insn
) == 1)
6986 insn16
= N16_BFMI333 (XLSB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6987 insn_type
= NDS32_INSN_XLSB33
;
6989 else if (N32_IMM15U (insn
) == 0x7ff)
6991 insn16
= N16_BFMI333 (X11B33
, N32_RT5 (insn
), N32_RA5 (insn
));
6992 insn_type
= NDS32_INSN_X11B33
;
6994 else if (N32_IMM15U (insn
) == 0xff)
6996 insn16
= N16_BFMI333 (ZEB33
, N32_RT5 (insn
), N32_RA5 (insn
));
6997 insn_type
= NDS32_INSN_ZEB33
;
6999 else if (mach
>= MACH_V3
&& N32_RT5 (insn
) == N32_RA5 (insn
)
7000 && N32_IMM15U (insn
) < 256)
7002 int imm15u
= N32_IMM15U (insn
);
7004 if (__builtin_popcount (imm15u
) == 1)
7007 int imm3u
= __builtin_ctz (imm15u
);
7009 insn16
= N16_BFMI333 (BMSKI33
, N32_RT5 (insn
), imm3u
);
7010 insn_type
= NDS32_INSN_BMSKI33
;
7012 else if (imm15u
!= 0 && __builtin_popcount (imm15u
+ 1) == 1)
7015 int imm3u
= __builtin_ctz (imm15u
+ 1) - 1;
7017 insn16
= N16_BFMI333 (FEXTI33
, N32_RT5 (insn
), imm3u
);
7018 insn_type
= NDS32_INSN_FEXTI33
;
7025 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
7026 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
7028 insn16
= N16_TYPE45 (SLTI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
7029 insn_type
= NDS32_INSN_SLTI45
;
7034 if (N32_RT5 (insn
) == REG_R15
&& N32_IS_RA4 (insn
)
7035 && IS_WITHIN_U (N32_IMM15S (insn
), 5))
7037 insn16
= N16_TYPE45 (SLTSI45
, N32_RA54 (insn
), N32_IMM15S (insn
));
7038 insn_type
= NDS32_INSN_SLTSI45
;
7043 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
7045 insn16
= N16_TYPE45 (LWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
7046 insn_type
= NDS32_INSN_LWI450
;
7048 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7049 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7051 insn16
= N16_TYPE333 (LWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7053 insn_type
= NDS32_INSN_LWI333
;
7055 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
7056 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7058 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7059 insn_type
= NDS32_INSN_LWI37
;
7061 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
7062 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7064 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7065 insn_type
= NDS32_INSN_LWI37_SP
;
7067 else if (mach
>= MACH_V2
&& N32_IS_RT4 (insn
) && N32_RA5 (insn
) == REG_R8
7068 && -32 <= N32_IMM15S (insn
) && N32_IMM15S (insn
) < 0)
7070 insn16
= N16_TYPE45 (LWI45_FE
, N32_RT54 (insn
),
7071 N32_IMM15S (insn
) + 32);
7072 insn_type
= NDS32_INSN_LWI45_FE
;
7077 if (N32_IS_RT4 (insn
) && N32_IMM15S (insn
) == 0)
7079 insn16
= N16_TYPE45 (SWI450
, N32_RT54 (insn
), N32_RA5 (insn
));
7080 insn_type
= NDS32_INSN_SWI450
;
7082 else if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7083 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7085 insn16
= N16_TYPE333 (SWI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7087 insn_type
= NDS32_INSN_SWI333
;
7089 else if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_FP
7090 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7092 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7093 insn_type
= NDS32_INSN_SWI37
;
7095 else if (mach
>= MACH_V2
&& N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_SP
7096 && IS_WITHIN_U (N32_IMM15S (insn
), 7))
7098 insn16
= N16_TYPE37 (XWI37SP
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7099 insn_type
= NDS32_INSN_SWI37_SP
;
7103 case N32_OP6_LWI_BI
:
7104 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7105 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7107 insn16
= N16_TYPE333 (LWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
7109 insn_type
= NDS32_INSN_LWI333_BI
;
7113 case N32_OP6_SWI_BI
:
7114 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7115 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7117 insn16
= N16_TYPE333 (SWI333_BI
, N32_RT5 (insn
), N32_RA5 (insn
),
7119 insn_type
= NDS32_INSN_SWI333_BI
;
7124 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7125 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7127 insn16
= N16_TYPE333 (LHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7129 insn_type
= NDS32_INSN_LHI333
;
7134 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7135 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7137 insn16
= N16_TYPE333 (SHI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7139 insn_type
= NDS32_INSN_SHI333
;
7144 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7145 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7147 insn16
= N16_TYPE333 (LBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7149 insn_type
= NDS32_INSN_LBI333
;
7154 if (N32_IS_RT3 (insn
) && N32_IS_RA3 (insn
)
7155 && IS_WITHIN_U (N32_IMM15S (insn
), 3))
7157 insn16
= N16_TYPE333 (SBI333
, N32_RT5 (insn
), N32_RA5 (insn
),
7159 insn_type
= NDS32_INSN_SBI333
;
7164 return nds32_convert_32_to_16_alu1 (abfd
, insn
, pinsn16
, pinsn_type
);
7167 return nds32_convert_32_to_16_alu2 (abfd
, insn
, pinsn16
, pinsn_type
);
7170 if (!IS_WITHIN_S (N32_IMM14S (insn
), 8))
7173 if ((insn
& N32_BIT (14)) == 0)
7176 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
7177 && N32_RT5 (insn
) != REG_R5
)
7178 insn16
= N16_TYPE38 (BEQS38
, N32_RT5 (insn
), N32_IMM14S (insn
));
7179 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
7180 && N32_RA5 (insn
) != REG_R5
)
7181 insn16
= N16_TYPE38 (BEQS38
, N32_RA5 (insn
), N32_IMM14S (insn
));
7182 insn_type
= NDS32_INSN_BEQS38
;
7188 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
7189 && N32_RT5 (insn
) != REG_R5
)
7190 insn16
= N16_TYPE38 (BNES38
, N32_RT5 (insn
), N32_IMM14S (insn
));
7191 else if (N32_IS_RA3 (insn
) && N32_RT5 (insn
) == REG_R5
7192 && N32_RA5 (insn
) != REG_R5
)
7193 insn16
= N16_TYPE38 (BNES38
, N32_RA5 (insn
), N32_IMM14S (insn
));
7194 insn_type
= NDS32_INSN_BNES38
;
7200 switch (N32_BR2_SUB (insn
))
7203 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7205 insn16
= N16_TYPE38 (BEQZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
7206 insn_type
= NDS32_INSN_BEQZ38
;
7208 else if (N32_RT5 (insn
) == REG_R15
7209 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7211 insn16
= N16_TYPE8 (BEQZS8
, N32_IMM16S (insn
));
7212 insn_type
= NDS32_INSN_BEQZS8
;
7217 if (N32_IS_RT3 (insn
) && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7219 insn16
= N16_TYPE38 (BNEZ38
, N32_RT5 (insn
), N32_IMM16S (insn
));
7220 insn_type
= NDS32_INSN_BNEZ38
;
7222 else if (N32_RT5 (insn
) == REG_R15
7223 && IS_WITHIN_S (N32_IMM16S (insn
), 8))
7225 insn16
= N16_TYPE8 (BNEZS8
, N32_IMM16S (insn
));
7226 insn_type
= NDS32_INSN_BNEZS8
;
7230 case N32_BR2_IFCALL
:
7231 if (IS_WITHIN_U (N32_IMM16S (insn
), 9))
7233 insn16
= N16_TYPE9 (IFCALL9
, N32_IMM16S (insn
));
7234 insn_type
= NDS32_INSN_IFCALL9
;
7241 if ((insn
& N32_BIT (24)) == 0)
7244 if (IS_WITHIN_S (N32_IMM24S (insn
), 8))
7246 insn16
= N16_TYPE8 (J8
, N32_IMM24S (insn
));
7247 insn_type
= NDS32_INSN_J8
;
7253 if (__GF (insn
, 8, 2) != 0)
7256 switch (N32_IMMU (insn
, 5))
7259 if (N32_JREG_HINT (insn
) == 0)
7262 insn16
= N16_TYPE5 (JR5
, N32_RB5 (insn
));
7263 insn_type
= NDS32_INSN_JR5
;
7265 else if (N32_JREG_HINT (insn
) == 1)
7268 insn16
= N16_TYPE5 (RET5
, N32_RB5 (insn
));
7269 insn_type
= NDS32_INSN_RET5
;
7271 else if (N32_JREG_HINT (insn
) == 3)
7273 /* ifret = mov55 $sp, $sp */
7274 insn16
= N16_TYPE55 (MOV55
, REG_SP
, REG_SP
);
7275 insn_type
= NDS32_INSN_IFRET
;
7280 /* It's convertible when return rt5 is $lp and address
7281 translation is kept. */
7282 if (N32_RT5 (insn
) == REG_LP
&& N32_JREG_HINT (insn
) == 0)
7284 insn16
= N16_TYPE5 (JRAL5
, N32_RB5 (insn
));
7285 insn_type
= NDS32_INSN_JRAL5
;
7292 if (N32_SUB5 (insn
) == N32_MISC_BREAK
&& N32_SWID (insn
) < 32)
7294 /* For v3, swid above 31 are used for ex9.it. */
7295 insn16
= N16_TYPE5 (BREAK16
, N32_SWID (insn
));
7296 insn_type
= NDS32_INSN_BREAK16
;
7301 /* This instruction has no 16-bit variant. */
7306 /* Bit-15 of insn16 should be set for a valid instruction. */
7307 if ((insn16
& 0x8000) == 0)
7313 *pinsn_type
= insn_type
;
7318 special_convert_32_to_16 (unsigned long insn
, uint16_t *pinsn16
,
7319 Elf_Internal_Rela
*reloc
)
7321 uint16_t insn16
= 0;
7323 if ((reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
) == 0
7324 || (ELF32_R_TYPE (reloc
->r_info
) != R_NDS32_INSN16
))
7327 if (!N32_IS_RT3 (insn
))
7330 switch (N32_OP6 (insn
))
7333 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
7334 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM15S (insn
));
7337 if (N32_RA5 (insn
) == REG_GP
&& IS_WITHIN_U (N32_IMM15S (insn
), 7))
7338 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM15S (insn
));
7341 if (!IS_WITHIN_U (N32_IMM17S (insn
), 7))
7344 if (__GF (insn
, 17, 3) == 6)
7345 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 0, N32_IMM17S (insn
));
7346 else if (__GF (insn
, 17, 3) == 7)
7347 insn16
= N16_TYPE37 (XWI37
, N32_RT5 (insn
), 1, N32_IMM17S (insn
));
7351 if ((insn16
& 0x8000) == 0)
7358 /* Convert a 16-bit instruction to 32-bit one.
7359 INSN16 it the input and PINSN it the point to output.
7360 Return non-zero on successful. Otherwise 0 is returned. */
7363 nds32_convert_16_to_32 (bfd
*abfd
, uint16_t insn16
, uint32_t *pinsn
)
7365 uint32_t insn
= 0xffffffff;
7366 unsigned long mach
= bfd_get_mach (abfd
);
7368 /* NOTE: push25, pop25 and movd44 do not have 32-bit variants. */
7370 switch (__GF (insn16
, 9, 6))
7372 case 0x4: /* add45 */
7373 insn
= N32_ALU1 (ADD
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7376 case 0x5: /* sub45 */
7377 insn
= N32_ALU1 (SUB
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7380 case 0x6: /* addi45 */
7381 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7382 N16_IMM5U (insn16
));
7384 case 0x7: /* subi45 */
7385 insn
= N32_TYPE2 (ADDI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7386 -N16_IMM5U (insn16
));
7388 case 0x8: /* srai45 */
7389 insn
= N32_ALU1 (SRAI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7390 N16_IMM5U (insn16
));
7392 case 0x9: /* srli45 */
7393 insn
= N32_ALU1 (SRLI
, N16_RT4 (insn16
), N16_RT4 (insn16
),
7394 N16_IMM5U (insn16
));
7396 case 0xa: /* slli333 */
7397 insn
= N32_ALU1 (SLLI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7398 N16_IMM3U (insn16
));
7400 case 0xc: /* add333 */
7401 insn
= N32_ALU1 (ADD
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7404 case 0xd: /* sub333 */
7405 insn
= N32_ALU1 (SUB
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7408 case 0xe: /* addi333 */
7409 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7410 N16_IMM3U (insn16
));
7412 case 0xf: /* subi333 */
7413 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7414 -N16_IMM3U (insn16
));
7416 case 0x10: /* lwi333 */
7417 insn
= N32_TYPE2 (LWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7418 N16_IMM3U (insn16
));
7420 case 0x12: /* lhi333 */
7421 insn
= N32_TYPE2 (LHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7422 N16_IMM3U (insn16
));
7424 case 0x13: /* lbi333 */
7425 insn
= N32_TYPE2 (LBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7426 N16_IMM3U (insn16
));
7428 case 0x11: /* lwi333.bi */
7429 insn
= N32_TYPE2 (LWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7430 N16_IMM3U (insn16
));
7432 case 0x14: /* swi333 */
7433 insn
= N32_TYPE2 (SWI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7434 N16_IMM3U (insn16
));
7436 case 0x16: /* shi333 */
7437 insn
= N32_TYPE2 (SHI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7438 N16_IMM3U (insn16
));
7440 case 0x17: /* sbi333 */
7441 insn
= N32_TYPE2 (SBI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7442 N16_IMM3U (insn16
));
7444 case 0x15: /* swi333.bi */
7445 insn
= N32_TYPE2 (SWI_BI
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7446 N16_IMM3U (insn16
));
7448 case 0x18: /* addri36.sp */
7449 insn
= N32_TYPE2 (ADDI
, N16_RT3 (insn16
), REG_SP
,
7450 N16_IMM6U (insn16
) << 2);
7452 case 0x19: /* lwi45.fe */
7453 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), REG_R8
,
7454 (N16_IMM5U (insn16
) - 32));
7456 case 0x1a: /* lwi450 */
7457 insn
= N32_TYPE2 (LWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
7459 case 0x1b: /* swi450 */
7460 insn
= N32_TYPE2 (SWI
, N16_RT4 (insn16
), N16_RA5 (insn16
), 0);
7463 /* These are r15 implied instructions. */
7464 case 0x30: /* slts45 */
7465 insn
= N32_ALU1 (SLTS
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
7467 case 0x31: /* slt45 */
7468 insn
= N32_ALU1 (SLT
, REG_TA
, N16_RT4 (insn16
), N16_RA5 (insn16
));
7470 case 0x32: /* sltsi45 */
7471 insn
= N32_TYPE2 (SLTSI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
7473 case 0x33: /* slti45 */
7474 insn
= N32_TYPE2 (SLTI
, REG_TA
, N16_RT4 (insn16
), N16_IMM5U (insn16
));
7476 case 0x34: /* beqzs8, bnezs8 */
7477 if (insn16
& N32_BIT (8))
7478 insn
= N32_BR2 (BNEZ
, REG_TA
, N16_IMM8S (insn16
));
7480 insn
= N32_BR2 (BEQZ
, REG_TA
, N16_IMM8S (insn16
));
7483 case 0x35: /* break16, ex9.it */
7484 /* Only consider range of v3 break16. */
7485 insn
= N32_TYPE0 (MISC
, (N16_IMM5U (insn16
) << 5) | N32_MISC_BREAK
);
7488 case 0x3c: /* ifcall9 */
7489 insn
= N32_BR2 (IFCALL
, 0, N16_IMM9U (insn16
));
7491 case 0x3d: /* movpi45 */
7492 insn
= N32_TYPE1 (MOVI
, N16_RT4 (insn16
), N16_IMM5U (insn16
) + 16);
7495 case 0x3f: /* MISC33 */
7496 switch (insn16
& 0x7)
7499 insn
= N32_TYPE2 (SUBRI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7502 insn
= N32_ALU1 (NOR
, N16_RT3 (insn16
), N16_RA3 (insn16
),
7506 insn
= N32_ALU2 (MUL
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7510 insn
= N32_ALU1 (XOR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7514 insn
= N32_ALU1 (AND
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7518 insn
= N32_ALU1 (OR
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7525 switch (insn16
& 0x7)
7528 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0xff);
7531 insn
= N32_ALU1 (ZEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7534 insn
= N32_ALU1 (SEB
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7537 insn
= N32_ALU1 (SEH
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0);
7539 case 4: /* xlsb33 */
7540 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 1);
7542 case 5: /* x11b33 */
7543 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RA3 (insn16
), 0x7ff);
7545 case 6: /* bmski33 */
7546 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7547 1 << __GF (insn16
, 3, 3));
7549 case 7: /* fexti33 */
7550 insn
= N32_TYPE2 (ANDI
, N16_RT3 (insn16
), N16_RT3 (insn16
),
7551 (1 << (__GF (insn16
, 3, 3) + 1)) - 1);
7557 switch (__GF (insn16
, 10, 5))
7559 case 0x0: /* mov55 or ifret16 */
7560 if (mach
>= MACH_V3
&& N16_RT5 (insn16
) == REG_SP
7561 && N16_RT5 (insn16
) == N16_RA5 (insn16
))
7562 insn
= N32_JREG (JR
, 0, 0, 0, 3);
7564 insn
= N32_TYPE2 (ADDI
, N16_RT5 (insn16
), N16_RA5 (insn16
), 0);
7566 case 0x1: /* movi55 */
7567 insn
= N32_TYPE1 (MOVI
, N16_RT5 (insn16
), N16_IMM5S (insn16
));
7569 case 0x1b: /* addi10s (V2) */
7570 insn
= N32_TYPE2 (ADDI
, REG_SP
, REG_SP
, N16_IMM10S (insn16
));
7574 switch (__GF (insn16
, 11, 4))
7576 case 0x7: /* lwi37.fp/swi37.fp */
7577 if (insn16
& N32_BIT (7)) /* swi37.fp */
7578 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
7580 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_FP
, N16_IMM7U (insn16
));
7582 case 0x8: /* beqz38 */
7583 insn
= N32_BR2 (BEQZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
7585 case 0x9: /* bnez38 */
7586 insn
= N32_BR2 (BNEZ
, N16_RT38 (insn16
), N16_IMM8S (insn16
));
7588 case 0xa: /* beqs38/j8, implied r5 */
7589 if (N16_RT38 (insn16
) == 5)
7590 insn
= N32_JI (J
, N16_IMM8S (insn16
));
7592 insn
= N32_BR1 (BEQ
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
7594 case 0xb: /* bnes38 and others */
7595 if (N16_RT38 (insn16
) == 5)
7597 switch (__GF (insn16
, 5, 3))
7600 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 0);
7603 insn
= N32_JREG (JR
, 0, N16_RA5 (insn16
), 0, 1);
7606 insn
= N32_JREG (JRAL
, REG_LP
, N16_RA5 (insn16
), 0, 0);
7608 case 2: /* ex9.it imm5 */
7609 /* ex9.it had no 32-bit variantl. */
7611 case 5: /* add5.pc */
7612 /* add5.pc had no 32-bit variantl. */
7617 insn
= N32_BR1 (BNE
, N16_RT38 (insn16
), REG_R5
, N16_IMM8S (insn16
));
7619 case 0xe: /* lwi37/swi37 */
7620 if (insn16
& (1 << 7)) /* swi37.sp */
7621 insn
= N32_TYPE2 (SWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
7623 insn
= N32_TYPE2 (LWI
, N16_RT38 (insn16
), REG_SP
, N16_IMM7U (insn16
));
7628 if (insn
& 0x80000000)
7637 is_sda_access_insn (unsigned long insn
)
7639 switch (N32_OP6 (insn
))
7660 static unsigned long
7661 turn_insn_to_sda_access (uint32_t insn
, bfd_signed_vma type
, uint32_t *pinsn
)
7667 case R_NDS32_GOT_LO12
:
7668 case R_NDS32_GOTOFF_LO12
:
7669 case R_NDS32_PLTREL_LO12
:
7670 case R_NDS32_PLT_GOTREL_LO12
:
7671 case R_NDS32_LO12S0_RELA
:
7672 switch (N32_OP6 (insn
))
7676 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
7680 oinsn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
7684 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
7688 oinsn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
7693 case R_NDS32_LO12S1_RELA
:
7694 switch (N32_OP6 (insn
))
7698 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
7702 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
7706 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
7711 case R_NDS32_LO12S2_RELA
:
7712 switch (N32_OP6 (insn
))
7716 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
7720 oinsn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
7725 case R_NDS32_LO12S2_DP_RELA
:
7726 case R_NDS32_LO12S2_SP_RELA
:
7727 oinsn
= (insn
& 0x7ff07000) | (REG_GP
<< 15);
7737 /* Linker hasn't found the correct merge section for non-section symbol
7738 in relax time, this work is left to the function elf_link_input_bfd().
7739 So for non-section symbol, _bfd_merged_section_offset is also needed
7740 to find the correct symbol address. */
7743 nds32_elf_rela_local_sym (bfd
*abfd
, Elf_Internal_Sym
*sym
,
7744 asection
**psec
, Elf_Internal_Rela
*rel
)
7746 asection
*sec
= *psec
;
7749 relocation
= (sec
->output_section
->vma
7750 + sec
->output_offset
+ sym
->st_value
);
7751 if ((sec
->flags
& SEC_MERGE
) && sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
7753 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7755 _bfd_merged_section_offset (abfd
, psec
,
7756 elf_section_data (sec
)->sec_info
,
7757 sym
->st_value
+ rel
->r_addend
);
7760 _bfd_merged_section_offset (abfd
, psec
,
7761 elf_section_data (sec
)->sec_info
,
7762 sym
->st_value
) + rel
->r_addend
;
7766 /* If we have changed the section, and our original section is
7767 marked with SEC_EXCLUDE, it means that the original
7768 SEC_MERGE section has been completely subsumed in some
7769 other SEC_MERGE section. In this case, we need to leave
7770 some info around for --emit-relocs. */
7771 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
7772 sec
->kept_section
= *psec
;
7775 rel
->r_addend
-= relocation
;
7776 rel
->r_addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
7782 calculate_memory_address (bfd
*abfd
, Elf_Internal_Rela
*irel
,
7783 Elf_Internal_Sym
*isymbuf
,
7784 Elf_Internal_Shdr
*symtab_hdr
)
7786 bfd_signed_vma foff
;
7787 bfd_vma symval
, addend
;
7788 Elf_Internal_Rela irel_fn
;
7789 Elf_Internal_Sym
*isym
;
7792 /* Get the value of the symbol referred to by the reloc. */
7793 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
7795 /* A local symbol. */
7796 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
7798 if (isym
->st_shndx
== SHN_UNDEF
)
7799 sym_sec
= bfd_und_section_ptr
;
7800 else if (isym
->st_shndx
== SHN_ABS
)
7801 sym_sec
= bfd_abs_section_ptr
;
7802 else if (isym
->st_shndx
== SHN_COMMON
)
7803 sym_sec
= bfd_com_section_ptr
;
7805 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7806 memcpy (&irel_fn
, irel
, sizeof (Elf_Internal_Rela
));
7807 symval
= nds32_elf_rela_local_sym (abfd
, isym
, &sym_sec
, &irel_fn
);
7808 addend
= irel_fn
.r_addend
;
7813 struct elf_link_hash_entry
*h
;
7815 /* An external symbol. */
7816 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7817 h
= elf_sym_hashes (abfd
)[indx
];
7818 BFD_ASSERT (h
!= NULL
);
7820 while (h
->root
.type
== bfd_link_hash_indirect
7821 || h
->root
.type
== bfd_link_hash_warning
)
7822 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7824 if (h
->root
.type
!= bfd_link_hash_defined
7825 && h
->root
.type
!= bfd_link_hash_defweak
)
7826 /* This appears to be a reference to an undefined
7827 symbol. Just ignore it--it will be caught by the
7828 regular reloc processing. */
7831 if (h
->root
.u
.def
.section
->flags
& SEC_MERGE
)
7833 sym_sec
= h
->root
.u
.def
.section
;
7834 symval
= _bfd_merged_section_offset (abfd
, &sym_sec
, elf_section_data
7835 (sym_sec
)->sec_info
, h
->root
.u
.def
.value
);
7836 symval
= symval
+ sym_sec
->output_section
->vma
7837 + sym_sec
->output_offset
;
7840 symval
= (h
->root
.u
.def
.value
7841 + h
->root
.u
.def
.section
->output_section
->vma
7842 + h
->root
.u
.def
.section
->output_offset
);
7843 addend
= irel
->r_addend
;
7846 foff
= symval
+ addend
;
7852 calculate_got_memory_address (bfd
*abfd
, struct bfd_link_info
*link_info
,
7853 Elf_Internal_Rela
*irel
,
7854 Elf_Internal_Shdr
*symtab_hdr
)
7857 bfd_vma
*local_got_offsets
;
7858 /* Get the value of the symbol referred to by the reloc. */
7859 struct elf_link_hash_entry
*h
;
7860 struct elf_nds32_link_hash_table
*htab
= nds32_elf_hash_table (link_info
);
7862 /* An external symbol. */
7863 symndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
7864 h
= elf_sym_hashes (abfd
)[symndx
];
7865 while (h
->root
.type
== bfd_link_hash_indirect
7866 || h
->root
.type
== bfd_link_hash_warning
)
7867 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7871 BFD_ASSERT (h
!= NULL
);
7872 return (htab
->root
.sgot
->output_section
->vma
7873 + htab
->root
.sgot
->output_offset
7878 local_got_offsets
= elf_local_got_offsets (abfd
);
7879 BFD_ASSERT (local_got_offsets
!= NULL
);
7880 return (htab
->root
.sgot
->output_section
->vma
7881 + htab
->root
.sgot
->output_offset
7882 + local_got_offsets
[ELF32_R_SYM (irel
->r_info
)]);
7885 /* The _GLOBAL_OFFSET_TABLE_ may be undefweak(or should be?). */
7886 /* The check of h->root.type is passed. */
7890 is_16bit_NOP (bfd
*abfd ATTRIBUTE_UNUSED
,
7891 asection
*sec
, Elf_Internal_Rela
*rel
)
7894 unsigned short insn16
;
7896 if (!(rel
->r_addend
& R_NDS32_INSN16_CONVERT_FLAG
))
7898 contents
= elf_section_data (sec
)->this_hdr
.contents
;
7899 insn16
= bfd_getb16 (contents
+ rel
->r_offset
);
7900 if (insn16
== NDS32_NOP16
)
7905 /* It checks whether the instruction could be converted to
7906 16-bit form and returns the converted one.
7908 `internal_relocs' is supposed to be sorted. */
7911 is_convert_32_to_16 (bfd
*abfd
, asection
*sec
,
7912 Elf_Internal_Rela
*reloc
,
7913 Elf_Internal_Rela
*internal_relocs
,
7914 Elf_Internal_Rela
*irelend
,
7917 #define NORMAL_32_TO_16 (1 << 0)
7918 #define SPECIAL_32_TO_16 (1 << 1)
7919 bfd_byte
*contents
= NULL
;
7923 Elf_Internal_Rela
*pc_rel
;
7924 int pic_ext_target
= 0;
7925 Elf_Internal_Shdr
*symtab_hdr
;
7926 Elf_Internal_Sym
*isymbuf
= NULL
;
7930 if (reloc
->r_offset
+ 4 > sec
->size
)
7933 offset
= reloc
->r_offset
;
7935 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
7937 insn
= bfd_getb32 (contents
+ offset
);
7939 if (nds32_convert_32_to_16 (abfd
, insn
, insn16
, NULL
))
7940 convert_type
= NORMAL_32_TO_16
;
7941 else if (special_convert_32_to_16 (insn
, insn16
, reloc
))
7942 convert_type
= SPECIAL_32_TO_16
;
7946 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7947 if (!nds32_get_local_syms (abfd
, sec
, &isymbuf
))
7950 /* Find the first relocation of the same relocation-type,
7951 so we iteratie them forward. */
7953 while ((pc_rel
- 1) >= internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
7956 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
7958 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
7959 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
7960 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
7961 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
7963 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
,
7965 if (off
>= ACCURATE_8BIT_S1
|| off
< -ACCURATE_8BIT_S1
7970 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
7972 /* movi => movi55 */
7973 mem_addr
= calculate_memory_address (abfd
, pc_rel
, isymbuf
,
7975 /* mem_addr is unsigned, but the value should
7976 be between [-16, 15]. */
7977 if ((mem_addr
+ 0x10) >> 5)
7981 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_20
)
7982 || (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_TLS_LE_LO12
))
7984 /* It never happen movi to movi55 for R_NDS32_TLS_LE_20,
7985 because it can be relaxed to addi for TLS_LE_ADD. */
7988 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
7989 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
7990 && (reloc
->r_addend
& R_NDS32_INSN16_FP7U2_FLAG
)
7991 && convert_type
== SPECIAL_32_TO_16
)
7994 We've selected a best fp-base for this access, so we can
7995 always resolve it anyway. Do nothing. */
7998 else if ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_NONE
7999 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_RELA_GNU_VTINHERIT
))
8000 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_RELA_GNU_VTENTRY
)
8001 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_INSN16
))
8002 || ((ELF32_R_TYPE (pc_rel
->r_info
) > R_NDS32_LOADSTORE
)
8003 && (ELF32_R_TYPE (pc_rel
->r_info
) < R_NDS32_DWARF2_OP1_RELA
)))
8005 /* Prevent unresolved addi instruction translate
8006 to addi45 or addi333. */
8009 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
8011 off
= calculate_offset (abfd
, sec
, pc_rel
, isymbuf
, symtab_hdr
,
8013 if (off
>= ACCURATE_U9BIT_S1
|| off
<= 0)
8023 nds32_elf_write_16 (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_byte
*contents
,
8024 Elf_Internal_Rela
*reloc
,
8025 Elf_Internal_Rela
*internal_relocs
,
8026 Elf_Internal_Rela
*irelend
,
8027 unsigned short insn16
)
8029 Elf_Internal_Rela
*pc_rel
;
8032 offset
= reloc
->r_offset
;
8033 bfd_putb16 (insn16
, contents
+ offset
);
8034 /* Find the first relocation of the same relocation-type,
8035 so we iteratie them forward. */
8037 while ((pc_rel
- 1) > internal_relocs
&& pc_rel
[-1].r_offset
== offset
)
8040 for (; pc_rel
< irelend
&& pc_rel
->r_offset
== offset
; pc_rel
++)
8042 if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_15_PCREL_RELA
8043 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17_PCREL_RELA
8044 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PCREL_RELA
)
8047 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PCREL_RELA
);
8049 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_25_PLTREL
)
8051 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_9_PLTREL
);
8052 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_20_RELA
)
8054 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_5_RELA
);
8055 else if (ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA15S2_RELA
8056 || ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_SDA17S2_RELA
)
8058 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_SDA_FP7U2_RELA
);
8059 else if ((ELF32_R_TYPE (pc_rel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
))
8061 ELF32_R_INFO (ELF32_R_SYM (pc_rel
->r_info
), R_NDS32_10IFCU_PCREL_RELA
);
8065 /* Find a relocation of type specified by `reloc_type'
8066 of the same r_offset with reloc.
8067 If not found, return irelend.
8069 Assuming relocations are sorted by r_offset,
8070 we find the relocation from `reloc' backward untill relocs,
8071 or find it from `reloc' forward untill irelend. */
8073 static Elf_Internal_Rela
*
8074 find_relocs_at_address (Elf_Internal_Rela
*reloc
,
8075 Elf_Internal_Rela
*relocs
,
8076 Elf_Internal_Rela
*irelend
,
8077 enum elf_nds32_reloc_type reloc_type
)
8079 Elf_Internal_Rela
*rel_t
;
8081 /* Find backward. */
8083 rel_t
>= relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
8085 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8088 /* We didn't find it backward. Try find it forward. */
8090 rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
8092 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8098 /* Find a relocation of specified type and offset.
8099 `reloc' is just a refence point to find a relocation at specified offset.
8100 If not found, return irelend.
8102 Assuming relocations are sorted by r_offset,
8103 we find the relocation from `reloc' backward untill relocs,
8104 or find it from `reloc' forward untill irelend. */
8106 static Elf_Internal_Rela
*
8107 find_relocs_at_address_addr (Elf_Internal_Rela
*reloc
,
8108 Elf_Internal_Rela
*relocs
,
8109 Elf_Internal_Rela
*irelend
,
8110 enum elf_nds32_reloc_type reloc_type
,
8113 Elf_Internal_Rela
*rel_t
= NULL
;
8115 /* First, we try to find a relocation of offset `offset_p',
8116 and then we use find_relocs_at_address to find specific type. */
8118 if (reloc
->r_offset
> offset_p
)
8120 /* Find backward. */
8122 rel_t
>= relocs
&& rel_t
->r_offset
> offset_p
; rel_t
--)
8125 else if (reloc
->r_offset
< offset_p
)
8129 rel_t
< irelend
&& rel_t
->r_offset
< offset_p
; rel_t
++)
8136 if (rel_t
< relocs
|| rel_t
== irelend
|| rel_t
->r_offset
!= offset_p
)
8139 return find_relocs_at_address (rel_t
, relocs
, irelend
, reloc_type
);
8143 nds32_elf_check_dup_relocs (Elf_Internal_Rela
*reloc
,
8144 Elf_Internal_Rela
*internal_relocs
,
8145 Elf_Internal_Rela
*irelend
,
8146 unsigned char reloc_type
)
8148 Elf_Internal_Rela
*rel_t
;
8151 rel_t
>= internal_relocs
&& rel_t
->r_offset
== reloc
->r_offset
;
8153 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8155 if (ELF32_R_SYM (rel_t
->r_info
) == ELF32_R_SYM (reloc
->r_info
)
8156 && rel_t
->r_addend
== reloc
->r_addend
)
8161 for (rel_t
= reloc
; rel_t
< irelend
&& rel_t
->r_offset
== reloc
->r_offset
;
8163 if (ELF32_R_TYPE (rel_t
->r_info
) == reloc_type
)
8165 if (ELF32_R_SYM (rel_t
->r_info
) == ELF32_R_SYM (reloc
->r_info
)
8166 && rel_t
->r_addend
== reloc
->r_addend
)
8174 typedef struct nds32_elf_blank nds32_elf_blank_t
;
8175 struct nds32_elf_blank
8177 /* Where the blank begins. */
8179 /* The size of the blank. */
8181 /* The accumulative size before this blank. */
8183 nds32_elf_blank_t
*next
;
8184 nds32_elf_blank_t
*prev
;
8187 static nds32_elf_blank_t
*blank_free_list
= NULL
;
8189 static nds32_elf_blank_t
*
8190 create_nds32_elf_blank (bfd_vma offset_p
, bfd_vma size_p
)
8192 nds32_elf_blank_t
*blank_t
;
8194 if (blank_free_list
)
8196 blank_t
= blank_free_list
;
8197 blank_free_list
= blank_free_list
->next
;
8200 blank_t
= bfd_malloc (sizeof (nds32_elf_blank_t
));
8202 if (blank_t
== NULL
)
8205 blank_t
->offset
= offset_p
;
8206 blank_t
->size
= size_p
;
8207 blank_t
->total_size
= 0;
8208 blank_t
->next
= NULL
;
8209 blank_t
->prev
= NULL
;
8215 remove_nds32_elf_blank (nds32_elf_blank_t
*blank_p
)
8217 if (blank_free_list
)
8219 blank_free_list
->prev
= blank_p
;
8220 blank_p
->next
= blank_free_list
;
8223 blank_p
->next
= NULL
;
8225 blank_p
->prev
= NULL
;
8226 blank_free_list
= blank_p
;
8230 clean_nds32_elf_blank (void)
8232 nds32_elf_blank_t
*blank_t
;
8234 while (blank_free_list
)
8236 blank_t
= blank_free_list
;
8237 blank_free_list
= blank_free_list
->next
;
8242 static nds32_elf_blank_t
*
8243 search_nds32_elf_blank (nds32_elf_blank_t
*blank_p
, bfd_vma addr
)
8245 nds32_elf_blank_t
*blank_t
;
8251 while (blank_t
&& addr
< blank_t
->offset
)
8252 blank_t
= blank_t
->prev
;
8253 while (blank_t
&& blank_t
->next
&& addr
>= blank_t
->next
->offset
)
8254 blank_t
= blank_t
->next
;
8260 get_nds32_elf_blank_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
8263 nds32_elf_blank_t
*blank_t
;
8265 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
8272 if (addr
< blank_t
->offset
+ blank_t
->size
)
8273 return blank_t
->total_size
+ (addr
- blank_t
->offset
);
8275 return blank_t
->total_size
+ blank_t
->size
;
8279 insert_nds32_elf_blank (nds32_elf_blank_t
**blank_p
, bfd_vma addr
, bfd_vma len
)
8281 nds32_elf_blank_t
*blank_t
, *blank_t2
;
8285 *blank_p
= create_nds32_elf_blank (addr
, len
);
8286 return *blank_p
? TRUE
: FALSE
;
8289 blank_t
= search_nds32_elf_blank (*blank_p
, addr
);
8291 if (blank_t
== NULL
)
8293 blank_t
= create_nds32_elf_blank (addr
, len
);
8296 while ((*blank_p
)->prev
!= NULL
)
8297 *blank_p
= (*blank_p
)->prev
;
8298 blank_t
->next
= *blank_p
;
8299 (*blank_p
)->prev
= blank_t
;
8300 (*blank_p
) = blank_t
;
8304 if (addr
< blank_t
->offset
+ blank_t
->size
)
8306 if (addr
> blank_t
->offset
+ blank_t
->size
)
8307 blank_t
->size
= addr
- blank_t
->offset
;
8311 blank_t2
= create_nds32_elf_blank (addr
, len
);
8316 blank_t
->next
->prev
= blank_t2
;
8317 blank_t2
->next
= blank_t
->next
;
8319 blank_t2
->prev
= blank_t
;
8320 blank_t
->next
= blank_t2
;
8321 *blank_p
= blank_t2
;
8328 insert_nds32_elf_blank_recalc_total (nds32_elf_blank_t
**blank_p
, bfd_vma addr
,
8331 nds32_elf_blank_t
*blank_t
;
8333 if (!insert_nds32_elf_blank (blank_p
, addr
, len
))
8340 blank_t
->total_size
= 0;
8341 blank_t
= blank_t
->next
;
8346 blank_t
->total_size
= blank_t
->prev
->total_size
+ blank_t
->prev
->size
;
8347 blank_t
= blank_t
->next
;
8354 calc_nds32_blank_total (nds32_elf_blank_t
*blank_p
)
8356 nds32_elf_blank_t
*blank_t
;
8357 bfd_vma total_size
= 0;
8363 while (blank_t
->prev
)
8364 blank_t
= blank_t
->prev
;
8367 blank_t
->total_size
= total_size
;
8368 total_size
+= blank_t
->size
;
8369 blank_t
= blank_t
->next
;
8374 nds32_elf_relax_delete_blanks (bfd
*abfd
, asection
*sec
,
8375 nds32_elf_blank_t
*blank_p
)
8377 Elf_Internal_Shdr
*symtab_hdr
; /* Symbol table header of this bfd. */
8378 Elf_Internal_Sym
*isym
= NULL
; /* Symbol table of this bfd. */
8379 Elf_Internal_Sym
*isymend
; /* Symbol entry iterator. */
8380 unsigned int sec_shndx
; /* The section the be relaxed. */
8381 bfd_byte
*contents
; /* Contents data of iterating section. */
8382 Elf_Internal_Rela
*internal_relocs
;
8383 Elf_Internal_Rela
*irel
;
8384 Elf_Internal_Rela
*irelend
;
8385 struct elf_link_hash_entry
**sym_hashes
;
8386 struct elf_link_hash_entry
**end_hashes
;
8387 unsigned int symcount
;
8389 nds32_elf_blank_t
*blank_t
;
8390 nds32_elf_blank_t
*blank_t2
;
8391 nds32_elf_blank_t
*blank_head
;
8393 blank_head
= blank_t
= blank_p
;
8394 while (blank_head
->prev
!= NULL
)
8395 blank_head
= blank_head
->prev
;
8396 while (blank_t
->next
!= NULL
)
8397 blank_t
= blank_t
->next
;
8399 if (blank_t
->offset
+ blank_t
->size
<= sec
->size
)
8401 blank_t
->next
= create_nds32_elf_blank (sec
->size
+ 4, 0);
8402 blank_t
->next
->prev
= blank_t
;
8404 if (blank_head
->offset
> 0)
8406 blank_head
->prev
= create_nds32_elf_blank (0, 0);
8407 blank_head
->prev
->next
= blank_head
;
8408 blank_head
= blank_head
->prev
;
8411 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
8413 /* The deletion must stop at the next ALIGN reloc for an alignment
8414 power larger than the number of bytes we are deleting. */
8416 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8417 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
8422 isym
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8423 symtab_hdr
->sh_info
, 0, NULL
, NULL
, NULL
);
8424 symtab_hdr
->contents
= (bfd_byte
*) isym
;
8427 if (isym
== NULL
|| symtab_hdr
->sh_info
== 0)
8430 blank_t
= blank_head
;
8431 calc_nds32_blank_total (blank_head
);
8433 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
8435 /* Adjust all the relocs. */
8437 /* Relocations MUST be kept in memory, because relaxation adjust them. */
8438 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sect
, NULL
, NULL
,
8439 TRUE
/* keep_memory */);
8440 irelend
= internal_relocs
+ sect
->reloc_count
;
8442 blank_t
= blank_head
;
8443 blank_t2
= blank_head
;
8445 if (!(sect
->flags
& SEC_RELOC
))
8448 nds32_get_section_contents (abfd
, sect
, &contents
, TRUE
);
8450 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
8454 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_DIFF8
8455 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_DIFF32
8456 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
8458 unsigned long val
= 0;
8460 long before
, between
;
8463 switch (ELF32_R_TYPE (irel
->r_info
))
8466 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
8468 case R_NDS32_DIFF16
:
8469 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
8471 case R_NDS32_DIFF32
:
8472 val
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8473 /* Get the signed bit and mask for the high part. The
8474 gcc will alarm when right shift 32-bit since the
8475 type size of long may be 32-bit. */
8476 mask
= 0 - (val
>> 31);
8478 offset
= (val
| (mask
- 0xffffffff));
8487 0 |encoded in location|
8488 |------------|-------------------|---------
8490 -- before ---| *****************
8491 --------------------- between ---|
8493 We only care how much data are relax between DIFF,
8496 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
8497 between
= get_nds32_elf_blank_total (&blank_t
,
8498 irel
->r_addend
+ offset
, 0);
8499 if (between
== before
)
8500 goto done_adjust_diff
;
8502 switch (ELF32_R_TYPE (irel
->r_info
))
8505 bfd_put_8 (abfd
, offset
- (between
- before
),
8506 contents
+ irel
->r_offset
);
8508 case R_NDS32_DIFF16
:
8509 bfd_put_16 (abfd
, offset
- (between
- before
),
8510 contents
+ irel
->r_offset
);
8512 case R_NDS32_DIFF32
:
8513 bfd_put_32 (abfd
, offset
- (between
- before
),
8514 contents
+ irel
->r_offset
);
8518 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_DIFF_ULEB128
8519 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
)
8522 unsigned int len
= 0;
8523 unsigned long before
, between
;
8526 val
= _bfd_read_unsigned_leb128 (abfd
, contents
+ irel
->r_offset
,
8529 before
= get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 0);
8530 between
= get_nds32_elf_blank_total (&blank_t
,
8531 irel
->r_addend
+ val
, 0);
8532 if (between
== before
)
8533 goto done_adjust_diff
;
8535 p
= contents
+ irel
->r_offset
;
8537 memset (p
, 0x80, len
);
8539 p
= write_uleb128 (p
, val
- (between
- before
)) - 1;
8547 raddr
= irel
->r_offset
;
8548 irel
->r_offset
-= get_nds32_elf_blank_total (&blank_t2
,
8551 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
8553 if (blank_t2
&& blank_t2
->next
8554 && (blank_t2
->offset
> raddr
8555 || blank_t2
->next
->offset
<= raddr
))
8557 (_("%B: Error: search_nds32_elf_blank reports wrong node\n"), abfd
);
8559 /* Mark reloc in deleted portion as NONE.
8560 For some relocs like R_NDS32_LABEL that doesn't modify the
8561 content in the section. R_NDS32_LABEL doesn't belong to the
8562 instruction in the section, so we should preserve it. */
8563 if (raddr
>= blank_t2
->offset
8564 && raddr
< blank_t2
->offset
+ blank_t2
->size
8565 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
8566 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_BEGIN
8567 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_END
8568 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
8569 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_SUBTRAHEND
8570 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_MINUEND
)
8572 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
8578 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
8579 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
8580 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
8583 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
8584 && isym
[ELF32_R_SYM (irel
->r_info
)].st_shndx
== sec_shndx
8585 && ELF_ST_TYPE (isym
[ELF32_R_SYM (irel
->r_info
)].st_info
) == STT_SECTION
)
8587 if (irel
->r_addend
<= sec
->size
)
8589 get_nds32_elf_blank_total (&blank_t
, irel
->r_addend
, 1);
8594 /* Adjust the local symbols defined in this section. */
8595 blank_t
= blank_head
;
8596 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
8598 if (isym
->st_shndx
== sec_shndx
)
8600 if (isym
->st_value
<= sec
->size
)
8603 bfd_vma orig_addr
= isym
->st_value
;
8605 ahead
= get_nds32_elf_blank_total (&blank_t
, isym
->st_value
, 1);
8606 isym
->st_value
-= ahead
;
8608 /* Adjust function size. */
8609 if (ELF32_ST_TYPE (isym
->st_info
) == STT_FUNC
8610 && isym
->st_size
> 0)
8612 get_nds32_elf_blank_total
8613 (&blank_t
, orig_addr
+ isym
->st_size
, 0) - ahead
;
8618 /* Now adjust the global symbols defined in this section. */
8619 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
8620 - symtab_hdr
->sh_info
);
8621 sym_hashes
= elf_sym_hashes (abfd
);
8622 end_hashes
= sym_hashes
+ symcount
;
8623 blank_t
= blank_head
;
8624 for (; sym_hashes
< end_hashes
; sym_hashes
++)
8626 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
8628 if ((sym_hash
->root
.type
== bfd_link_hash_defined
8629 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
8630 && sym_hash
->root
.u
.def
.section
== sec
)
8632 if (sym_hash
->root
.u
.def
.value
<= sec
->size
)
8635 bfd_vma orig_addr
= sym_hash
->root
.u
.def
.value
;
8637 ahead
= get_nds32_elf_blank_total (&blank_t
, sym_hash
->root
.u
.def
.value
, 1);
8638 sym_hash
->root
.u
.def
.value
-= ahead
;
8640 /* Adjust function size. */
8641 if (sym_hash
->type
== STT_FUNC
)
8643 get_nds32_elf_blank_total
8644 (&blank_t
, orig_addr
+ sym_hash
->size
, 0) - ahead
;
8650 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8651 blank_t
= blank_head
;
8652 while (blank_t
->next
)
8654 /* Actually delete the bytes. */
8656 /* If current blank is the last blank overlap with current section,
8657 go to finish process. */
8658 if (sec
->size
<= (blank_t
->next
->offset
))
8661 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
8662 contents
+ blank_t
->offset
+ blank_t
->size
,
8663 blank_t
->next
->offset
- (blank_t
->offset
+ blank_t
->size
));
8665 blank_t
= blank_t
->next
;
8668 if (sec
->size
> (blank_t
->offset
+ blank_t
->size
))
8670 /* There are remaining code between blank and section boundary.
8671 Move the remaining code to appropriate location. */
8672 memmove (contents
+ blank_t
->offset
- blank_t
->total_size
,
8673 contents
+ blank_t
->offset
+ blank_t
->size
,
8674 sec
->size
- (blank_t
->offset
+ blank_t
->size
));
8675 sec
->size
-= blank_t
->total_size
+ blank_t
->size
;
8678 /* This blank is not entirely included in the section,
8679 reduce the section size by only part of the blank size. */
8680 sec
->size
-= blank_t
->total_size
+ (sec
->size
- blank_t
->offset
);
8684 blank_t
= blank_head
;
8685 blank_head
= blank_head
->next
;
8686 remove_nds32_elf_blank (blank_t
);
8692 /* Get the contents of a section. */
8695 nds32_get_section_contents (bfd
*abfd
, asection
*sec
,
8696 bfd_byte
**contents_p
, bfd_boolean cache
)
8698 /* Get the section contents. */
8699 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8700 *contents_p
= elf_section_data (sec
)->this_hdr
.contents
;
8703 if (!bfd_malloc_and_get_section (abfd
, sec
, contents_p
))
8706 elf_section_data (sec
)->this_hdr
.contents
= *contents_p
;
8712 /* Get the contents of the internal symbol of abfd. */
8715 nds32_get_local_syms (bfd
*abfd
, asection
*sec ATTRIBUTE_UNUSED
,
8716 Elf_Internal_Sym
**isymbuf_p
)
8718 Elf_Internal_Shdr
*symtab_hdr
;
8719 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
8721 /* Read this BFD's local symbols if we haven't done so already. */
8722 if (*isymbuf_p
== NULL
&& symtab_hdr
->sh_info
!= 0)
8724 *isymbuf_p
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8725 if (*isymbuf_p
== NULL
)
8727 *isymbuf_p
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8728 symtab_hdr
->sh_info
, 0,
8730 if (*isymbuf_p
== NULL
)
8734 symtab_hdr
->contents
= (bfd_byte
*) (*isymbuf_p
);
8739 /* Range of small data. */
8740 static bfd_vma sdata_range
[2][2];
8741 static bfd_vma
const sdata_init_range
[2] =
8742 { ACCURATE_12BIT_S1
, ACCURATE_19BIT
};
8745 nds32_elf_insn_size (bfd
*abfd ATTRIBUTE_UNUSED
,
8746 bfd_byte
*contents
, bfd_vma addr
)
8748 unsigned long insn
= bfd_getb32 (contents
+ addr
);
8750 if (insn
& 0x80000000)
8756 /* Set the gp relax range. We have to measure the safe range
8757 to do gp relaxation. */
8760 relax_range_measurement (bfd
*abfd
)
8762 asection
*sec_f
, *sec_b
;
8763 /* For upper bound. */
8764 bfd_vma maxpgsz
= get_elf_backend_data (abfd
)->maxpagesize
;
8766 static int decide_relax_range
= 0;
8768 int range_number
= sizeof (sdata_init_range
) / sizeof (sdata_init_range
[0]);
8770 if (decide_relax_range
)
8772 decide_relax_range
= 1;
8774 if (sda_rela_sec
== NULL
)
8776 /* Since there is no data sections, we assume the range is page size. */
8777 for (i
= 0; i
< range_number
; i
++)
8779 sdata_range
[i
][0] = sdata_init_range
[i
] - 0x1000;
8780 sdata_range
[i
][1] = sdata_init_range
[i
] - 0x1000;
8785 /* Get the biggest alignment power after the gp located section. */
8786 sec_f
= sda_rela_sec
->output_section
;
8787 sec_b
= sec_f
->next
;
8789 while (sec_b
!= NULL
)
8791 if ((unsigned)(1 << sec_b
->alignment_power
) > align
)
8792 align
= (1 << sec_b
->alignment_power
);
8793 sec_b
= sec_b
->next
;
8796 /* I guess we can not determine the section before
8797 gp located section, so we assume the align is max page size. */
8798 for (i
= 0; i
< range_number
; i
++)
8800 sdata_range
[i
][1] = sdata_init_range
[i
] - align
;
8801 BFD_ASSERT (sdata_range
[i
][1] <= sdata_init_range
[i
]);
8802 sdata_range
[i
][0] = sdata_init_range
[i
] - maxpgsz
;
8803 BFD_ASSERT (sdata_range
[i
][0] <= sdata_init_range
[i
]);
8807 /* These are macros used to check flags encoded in r_addend.
8808 They are only used by nds32_elf_relax_section (). */
8809 #define GET_SEQ_LEN(addend) ((addend) & 0x000000ff)
8810 #define IS_1ST_CONVERT(addend) ((addend) & 0x80000000)
8811 #define IS_OPTIMIZE(addend) ((addend) & 0x40000000)
8812 #define IS_16BIT_ON(addend) ((addend) & 0x20000000)
8814 static const char * unrecognized_reloc_msg
=
8815 /* xgettext:c-format */
8816 N_("%B: warning: %s points to unrecognized reloc at %#Lx");
8818 /* Relax LONGCALL1 relocation for nds32_elf_relax_section. */
8821 nds32_elf_relax_longcall1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
8822 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
8823 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
8824 Elf_Internal_Shdr
*symtab_hdr
)
8826 /* There are 3 variations for LONGCALL1
8827 case 4-4-2; 16-bit on, optimize off or optimize for space
8828 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8829 ori ta, ta, lo12(symbol) ; LO12S0
8832 case 4-4-4; 16-bit off, optimize don't care
8833 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8834 ori ta, ta, lo12(symbol) ; LO12S0
8837 case 4-4-4; 16-bit on, optimize for speed
8838 sethi ta, hi20(symbol) ; LONGCALL1/HI20
8839 ori ta, ta, lo12(symbol) ; LO12S0
8841 Check code for -mlong-calls output. */
8843 /* Get the reloc for the address from which the register is
8844 being loaded. This reloc will tell us which function is
8845 actually being called. */
8848 int seq_len
; /* Original length of instruction sequence. */
8850 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
8851 int pic_ext_target
= 0;
8852 bfd_signed_vma foff
;
8855 irelend
= internal_relocs
+ sec
->reloc_count
;
8856 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
8857 laddr
= irel
->r_offset
;
8858 *insn_len
= seq_len
;
8860 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8861 R_NDS32_HI20_RELA
, laddr
);
8862 lo_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8863 R_NDS32_LO12S0_ORI_RELA
,
8866 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
8868 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL1",
8873 /* Get the value of the symbol referred to by the reloc. */
8874 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
8877 /* This condition only happened when symbol is undefined. */
8878 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
8879 || foff
>= CONSERVATIVE_24BIT_S1
)
8882 /* Relax to: jal symbol; 25_PCREL */
8883 /* For simplicity of coding, we are going to modify the section
8884 contents, the section relocs, and the BFD symbol table. We
8885 must tell the rest of the code not to free up this
8886 information. It would be possible to instead create a table
8887 of changes which have to be made, as is done in coff-mips.c;
8888 that would be more work, but would require less memory when
8889 the linker is run. */
8891 /* Replace the long call with a jal. */
8892 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
8893 R_NDS32_25_PCREL_RELA
);
8894 irel
->r_addend
= hi_irelfn
->r_addend
;
8896 /* We don't resolve this here but resolve it in relocate_section. */
8898 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
8901 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
8903 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
8908 insn16
= NDS32_NOP16
;
8909 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
8911 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
8912 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
8918 #define CONVERT_CONDITION_CALL(insn) (((insn) & 0xffff0000) ^ 0x90000)
8919 /* Relax LONGCALL2 relocation for nds32_elf_relax_section. */
8922 nds32_elf_relax_longcall2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
8923 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
8924 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
8925 Elf_Internal_Shdr
*symtab_hdr
)
8927 /* bltz rt, .L1 ; LONGCALL2
8928 jal symbol ; 25_PCREL
8931 /* Get the reloc for the address from which the register is
8932 being loaded. This reloc will tell us which function is
8933 actually being called. */
8937 Elf_Internal_Rela
*i1_irelfn
, *cond_irelfn
, *irelend
;
8938 int pic_ext_target
= 0;
8939 bfd_signed_vma foff
;
8941 irelend
= internal_relocs
+ sec
->reloc_count
;
8942 laddr
= irel
->r_offset
;
8944 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8945 R_NDS32_25_PCREL_RELA
, laddr
+ 4);
8947 if (i1_irelfn
== irelend
)
8949 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL2",
8954 insn
= bfd_getb32 (contents
+ laddr
);
8956 /* Get the value of the symbol referred to by the reloc. */
8957 foff
= calculate_offset (abfd
, sec
, i1_irelfn
, isymbuf
, symtab_hdr
,
8960 if (foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
8961 || foff
>= CONSERVATIVE_16BIT_S1
)
8964 /* Relax to bgezal rt, label ; 17_PCREL
8965 or bltzal rt, label ; 17_PCREL */
8967 /* Convert to complimentary conditional call. */
8968 insn
= CONVERT_CONDITION_CALL (insn
);
8970 /* For simplicity of coding, we are going to modify the section
8971 contents, the section relocs, and the BFD symbol table. We
8972 must tell the rest of the code not to free up this
8973 information. It would be possible to instead create a table
8974 of changes which have to be made, as is done in coff-mips.c;
8975 that would be more work, but would require less memory when
8976 the linker is run. */
8978 /* Clean unnessary relocations. */
8980 ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
), R_NDS32_NONE
);
8982 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
8983 R_NDS32_17_PCREL_RELA
, laddr
);
8984 if (cond_irelfn
!= irelend
)
8985 cond_irelfn
->r_info
=
8986 ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
), R_NDS32_NONE
);
8988 /* Replace the long call with a bgezal. */
8989 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i1_irelfn
->r_info
),
8990 R_NDS32_17_PCREL_RELA
);
8991 irel
->r_addend
= i1_irelfn
->r_addend
;
8993 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
8999 /* Relax LONGCALL3 relocation for nds32_elf_relax_section. */
9002 nds32_elf_relax_longcall3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9003 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9004 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9005 Elf_Internal_Shdr
*symtab_hdr
)
9007 /* There are 3 variations for LONGCALL3
9008 case 4-4-4-2; 16-bit on, optimize off or optimize for space
9009 bltz rt, $1 ; LONGCALL3
9010 sethi ta, hi20(symbol) ; HI20
9011 ori ta, ta, lo12(symbol) ; LO12S0
9015 case 4-4-4-4; 16-bit off, optimize don't care
9016 bltz rt, $1 ; LONGCALL3
9017 sethi ta, hi20(symbol) ; HI20
9018 ori ta, ta, lo12(symbol) ; LO12S0
9022 case 4-4-4-4; 16-bit on, optimize for speed
9023 bltz rt, $1 ; LONGCALL3
9024 sethi ta, hi20(symbol) ; HI20
9025 ori ta, ta, lo12(symbol) ; LO12S0
9029 /* Get the reloc for the address from which the register is
9030 being loaded. This reloc will tell us which function is
9031 actually being called. */
9034 int seq_len
; /* Original length of instruction sequence. */
9036 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
9037 int pic_ext_target
= 0;
9038 bfd_signed_vma foff
;
9041 irelend
= internal_relocs
+ sec
->reloc_count
;
9042 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9043 laddr
= irel
->r_offset
;
9044 *insn_len
= seq_len
;
9047 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9048 R_NDS32_HI20_RELA
, laddr
+ 4);
9050 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9051 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 8);
9053 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9055 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL3",
9060 /* Get the value of the symbol referred to by the reloc. */
9061 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9064 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9065 || foff
>= CONSERVATIVE_24BIT_S1
)
9068 insn
= bfd_getb32 (contents
+ laddr
);
9069 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9071 /* Relax to bgezal rt, label ; 17_PCREL
9072 or bltzal rt, label ; 17_PCREL */
9074 /* Convert to complimentary conditional call. */
9075 insn
= CONVERT_CONDITION_CALL (insn
);
9076 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9080 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9082 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
9084 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9087 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9088 R_NDS32_17_PCREL_RELA
, laddr
);
9089 if (cond_irelfn
!= irelend
)
9091 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9092 R_NDS32_17_PCREL_RELA
);
9093 cond_irelfn
->r_addend
= hi_irelfn
->r_addend
;
9098 insn16
= NDS32_NOP16
;
9099 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9100 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9102 hi_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9106 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
9108 /* Relax to the following instruction sequence
9109 bltz rt, $1 ; LONGCALL2
9110 jal symbol ; 25_PCREL
9114 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
9116 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9117 R_NDS32_25_PCREL_RELA
);
9119 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL2
);
9122 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9126 insn16
= NDS32_NOP16
;
9127 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9129 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_INSN16
);
9130 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9137 /* Relax LONGJUMP1 relocation for nds32_elf_relax_section. */
9140 nds32_elf_relax_longjump1 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9141 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9142 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9143 Elf_Internal_Shdr
*symtab_hdr
)
9145 /* There are 3 variations for LONGJUMP1
9146 case 4-4-2; 16-bit bit on, optimize off or optimize for space
9147 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9148 ori ta, ta, lo12(symbol) ; LO12S0
9151 case 4-4-4; 16-bit off, optimize don't care
9152 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9153 ori ta, ta, lo12(symbol) ; LO12S0
9156 case 4-4-4; 16-bit on, optimize for speed
9157 sethi ta, hi20(symbol) ; LONGJUMP1/HI20
9158 ori ta, ta, lo12(symbol) ; LO12S0
9161 /* Get the reloc for the address from which the register is
9162 being loaded. This reloc will tell us which function is
9163 actually being called. */
9166 int seq_len
; /* Original length of instruction sequence. */
9167 int insn16_on
; /* 16-bit on/off. */
9169 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *irelend
;
9170 int pic_ext_target
= 0;
9171 bfd_signed_vma foff
;
9173 unsigned long reloc
;
9175 irelend
= internal_relocs
+ sec
->reloc_count
;
9176 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9177 laddr
= irel
->r_offset
;
9178 *insn_len
= seq_len
;
9179 insn16_on
= IS_16BIT_ON (irel
->r_addend
);
9182 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9183 R_NDS32_HI20_RELA
, laddr
);
9185 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9186 R_NDS32_LO12S0_ORI_RELA
, laddr
+ 4);
9187 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
)
9189 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP1",
9194 /* Get the value of the symbol referred to by the reloc. */
9195 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9198 if (pic_ext_target
|| foff
== 0 || foff
>= CONSERVATIVE_24BIT_S1
9199 || foff
< -CONSERVATIVE_24BIT_S1
)
9202 if (insn16_on
&& foff
>= -ACCURATE_8BIT_S1
9203 && foff
< ACCURATE_8BIT_S1
&& (seq_len
& 0x2))
9206 /* 16-bit on, but not optimized for speed. */
9207 reloc
= R_NDS32_9_PCREL_RELA
;
9209 bfd_putb16 (insn16
, contents
+ irel
->r_offset
);
9212 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9217 reloc
= R_NDS32_25_PCREL_RELA
;
9219 bfd_putb32 (insn
, contents
+ irel
->r_offset
);
9222 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_INSN16
);
9227 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
9229 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
), R_NDS32_NONE
);
9231 if ((seq_len
& 0x2) && ((*insn_len
& 2) == 0))
9233 insn16
= NDS32_NOP16
;
9234 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9236 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9238 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9244 /* Revert condition branch. This function does not check if the input
9245 instruction is condition branch or not. */
9248 nds32_elf_convert_branch (uint16_t insn16
, uint32_t insn
,
9249 uint16_t *re_insn16
, uint32_t *re_insn
)
9251 uint32_t comp_insn
= 0;
9252 uint16_t comp_insn16
= 0;
9256 if (N32_OP6 (insn
) == N32_OP6_BR1
)
9259 comp_insn
= (insn
^ 0x4000) & 0xffffc000;
9260 if (N32_IS_RT3 (insn
) && N32_RA5 (insn
) == REG_R5
)
9262 /* Insn can be contracted to 16-bit implied r5. */
9264 (comp_insn
& 0x4000) ? INSN_BNES38
: INSN_BEQS38
;
9265 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
9268 else if (N32_OP6 (insn
) == N32_OP6_BR3
)
9270 /* bnec $ta, imm11, label. */
9271 comp_insn
= (insn
^ 0x80000) & 0xffffff00;
9275 comp_insn
= (insn
^ 0x10000) & 0xffffc000;
9276 if (N32_BR2_SUB (insn
) == N32_BR2_BEQZ
9277 || N32_BR2_SUB (insn
) == N32_BR2_BNEZ
)
9279 if (N32_IS_RT3 (insn
))
9281 /* Insn can be contracted to 16-bit. */
9283 (comp_insn
& 0x10000) ? INSN_BNEZ38
: INSN_BEQZ38
;
9284 comp_insn16
|= (N32_RT5 (insn
) & 0x7) << 8;
9286 else if (N32_RT5 (insn
) == REG_R15
)
9288 /* Insn can be contracted to 16-bit. */
9290 (comp_insn
& 0x10000) ? INSN_BNES38
: INSN_BEQS38
;
9297 switch ((insn16
& 0xf000) >> 12)
9300 /* beqz38 or bnez38 */
9301 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
9302 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNEZ
: INSN_BEQZ
;
9303 comp_insn
|= ((comp_insn16
& 0x0700) >> 8) << 20;
9307 /* beqs38 or bnes38 */
9308 comp_insn16
= (insn16
^ 0x0800) & 0xff00;
9309 comp_insn
= (comp_insn16
& 0x0800) ? INSN_BNE
: INSN_BEQ
;
9310 comp_insn
|= (((comp_insn16
& 0x0700) >> 8) << 20)
9315 /* beqzS8 or bnezS8 */
9316 comp_insn16
= (insn16
^ 0x0100) & 0xff00;
9317 comp_insn
= (comp_insn16
& 0x0100) ? INSN_BNEZ
: INSN_BEQZ
;
9318 comp_insn
|= REG_R15
<< 20;
9325 if (comp_insn
&& re_insn
)
9326 *re_insn
= comp_insn
;
9327 if (comp_insn16
&& re_insn16
)
9328 *re_insn16
= comp_insn16
;
9331 /* Relax LONGJUMP2 relocation for nds32_elf_relax_section. */
9334 nds32_elf_relax_longjump2 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9335 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9336 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9337 Elf_Internal_Shdr
*symtab_hdr
)
9339 /* There are 3 variations for LONGJUMP2
9340 case 2-4; 1st insn convertible, 16-bit on,
9341 optimize off or optimize for space
9342 bnes38 rt, ra, $1 ; LONGJUMP2
9346 case 4-4; 1st insn not convertible
9347 bne rt, ra, $1 ; LONGJUMP2
9351 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
9352 bne rt, ra, $1 ; LONGJUMP2
9356 /* Get the reloc for the address from which the register is
9357 being loaded. This reloc will tell us which function is
9358 actually being called. */
9361 int seq_len
; /* Original length of instruction sequence. */
9362 Elf_Internal_Rela
*i2_irelfn
, *cond_irelfn
, *irelend
;
9363 int pic_ext_target
= 0, first_size
;
9365 bfd_signed_vma foff
;
9366 uint32_t insn
, re_insn
= 0;
9367 uint16_t insn16
, re_insn16
= 0;
9368 unsigned long reloc
, cond_reloc
;
9370 enum elf_nds32_reloc_type checked_types
[] =
9371 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
9373 irelend
= internal_relocs
+ sec
->reloc_count
;
9374 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9375 laddr
= irel
->r_offset
;
9376 *insn_len
= seq_len
;
9377 first_size
= (seq_len
== 6) ? 2 : 4;
9380 find_relocs_at_address_addr (irel
, internal_relocs
,
9381 irelend
, R_NDS32_25_PCREL_RELA
,
9382 laddr
+ first_size
);
9384 for (i
= 0; i
< sizeof (checked_types
) / sizeof(checked_types
[0]); i
++)
9387 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9388 checked_types
[i
], laddr
);
9389 if (cond_irelfn
!= irelend
)
9393 if (i2_irelfn
== irelend
|| cond_irelfn
== irelend
)
9395 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP2",
9400 /* Get the value of the symbol referred to by the reloc. */
9402 calculate_offset (abfd
, sec
, i2_irelfn
, isymbuf
, symtab_hdr
,
9404 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
9405 || foff
>= CONSERVATIVE_16BIT_S1
)
9408 /* Get the all corresponding instructions. */
9409 if (first_size
== 4)
9411 insn
= bfd_getb32 (contents
+ laddr
);
9412 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
9416 insn16
= bfd_getb16 (contents
+ laddr
);
9417 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
9420 if (re_insn16
&& foff
>= -(ACCURATE_8BIT_S1
- first_size
)
9421 && foff
< ACCURATE_8BIT_S1
- first_size
)
9423 if (first_size
== 4)
9425 /* Don't convert it to 16-bit now, keep this as relaxable for
9426 ``label reloc; INSN16''. */
9428 /* Save comp_insn32 to buffer. */
9429 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9431 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
9432 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
9433 cond_reloc
= R_NDS32_INSN16
;
9437 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
9439 reloc
= R_NDS32_9_PCREL_RELA
;
9440 cond_reloc
= R_NDS32_NONE
;
9443 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
9444 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
9445 && foff
< ACCURATE_14BIT_S1
- first_size
))
9447 /* beqs label ; 15_PCREL */
9448 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9450 reloc
= R_NDS32_15_PCREL_RELA
;
9451 cond_reloc
= R_NDS32_NONE
;
9453 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
9454 && foff
>= -CONSERVATIVE_16BIT_S1
9455 && foff
< CONSERVATIVE_16BIT_S1
)
9457 /* beqz label ; 17_PCREL */
9458 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9460 reloc
= R_NDS32_17_PCREL_RELA
;
9461 cond_reloc
= R_NDS32_NONE
;
9466 /* Set all relocations. */
9467 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
), reloc
);
9468 irel
->r_addend
= i2_irelfn
->r_addend
;
9470 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
9472 cond_irelfn
->r_addend
= 0;
9474 if ((seq_len
^ *insn_len
) & 0x2)
9476 insn16
= NDS32_NOP16
;
9477 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ 4);
9478 i2_irelfn
->r_offset
= 4;
9479 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
9481 i2_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9485 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (i2_irelfn
->r_info
),
9490 /* Relax LONGJUMP3 relocation for nds32_elf_relax_section. */
9493 nds32_elf_relax_longjump3 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9494 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9495 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9496 Elf_Internal_Shdr
*symtab_hdr
)
9498 /* There are 5 variations for LONGJUMP3
9499 case 1: 2-4-4-2; 1st insn convertible, 16-bit on,
9500 optimize off or optimize for space
9501 bnes38 rt, ra, $1 ; LONGJUMP3
9502 sethi ta, hi20(symbol) ; HI20
9503 ori ta, ta, lo12(symbol) ; LO12S0
9507 case 2: 2-4-4-2; 1st insn convertible, 16-bit on, optimize for speed
9508 bnes38 rt, ra, $1 ; LONGJUMP3
9509 sethi ta, hi20(symbol) ; HI20
9510 ori ta, ta, lo12(symbol) ; LO12S0
9514 case 3: 4-4-4-2; 1st insn not convertible, 16-bit on,
9515 optimize off or optimize for space
9516 bne rt, ra, $1 ; LONGJUMP3
9517 sethi ta, hi20(symbol) ; HI20
9518 ori ta, ta, lo12(symbol) ; LO12S0
9522 case 4: 4-4-4-4; 1st insn don't care, 16-bit off, optimize don't care
9523 16-bit off if no INSN16
9524 bne rt, ra, $1 ; LONGJUMP3
9525 sethi ta, hi20(symbol) ; HI20
9526 ori ta, ta, lo12(symbol) ; LO12S0
9530 case 5: 4-4-4-4; 1st insn not convertible, 16-bit on, optimize for speed
9531 16-bit off if no INSN16
9532 bne rt, ra, $1 ; LONGJUMP3
9533 sethi ta, hi20(symbol) ; HI20
9534 ori ta, ta, lo12(symbol) ; LO12S0
9538 /* Get the reloc for the address from which the register is
9539 being loaded. This reloc will tell us which function is
9540 actually being called. */
9541 enum elf_nds32_reloc_type checked_types
[] =
9542 { R_NDS32_15_PCREL_RELA
, R_NDS32_9_PCREL_RELA
};
9544 int reloc_off
= 0, cond_removed
= 0, convertible
;
9546 int seq_len
; /* Original length of instruction sequence. */
9547 Elf_Internal_Rela
*hi_irelfn
, *lo_irelfn
, *cond_irelfn
, *irelend
;
9548 int pic_ext_target
= 0, first_size
;
9550 bfd_signed_vma foff
;
9551 uint32_t insn
, re_insn
= 0;
9552 uint16_t insn16
, re_insn16
= 0;
9553 unsigned long reloc
, cond_reloc
;
9555 irelend
= internal_relocs
+ sec
->reloc_count
;
9556 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
9557 laddr
= irel
->r_offset
;
9558 *insn_len
= seq_len
;
9560 convertible
= IS_1ST_CONVERT (irel
->r_addend
);
9567 /* Get all needed relocations. */
9569 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9570 R_NDS32_HI20_RELA
, laddr
+ first_size
);
9572 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9573 R_NDS32_LO12S0_ORI_RELA
,
9574 laddr
+ first_size
+ 4);
9576 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
9579 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9580 checked_types
[i
], laddr
);
9581 if (cond_irelfn
!= irelend
)
9585 if (hi_irelfn
== irelend
|| lo_irelfn
== irelend
|| cond_irelfn
== irelend
)
9587 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP3",
9592 /* Get the value of the symbol referred to by the reloc. */
9593 foff
= calculate_offset (abfd
, sec
, hi_irelfn
, isymbuf
, symtab_hdr
,
9596 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9597 || foff
>= CONSERVATIVE_24BIT_S1
)
9600 /* Get the all corresponding instructions. */
9601 if (first_size
== 4)
9603 insn
= bfd_getb32 (contents
+ laddr
);
9604 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
9608 insn16
= bfd_getb16 (contents
+ laddr
);
9609 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
9612 /* For simplicity of coding, we are going to modify the section
9613 contents, the section relocs, and the BFD symbol table. We
9614 must tell the rest of the code not to free up this
9615 information. It would be possible to instead create a table
9616 of changes which have to be made, as is done in coff-mips.c;
9617 that would be more work, but would require less memory when
9618 the linker is run. */
9620 if (re_insn16
&& foff
>= -ACCURATE_8BIT_S1
- first_size
9621 && foff
< ACCURATE_8BIT_S1
- first_size
)
9623 if (!(seq_len
& 0x2))
9625 /* Don't convert it to 16-bit now, keep this as relaxable
9626 for ``label reloc; INSN1a''6. */
9627 /* Save comp_insn32 to buffer. */
9628 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9630 reloc
= (N32_OP6 (re_insn
) == N32_OP6_BR1
) ?
9631 R_NDS32_15_PCREL_RELA
: R_NDS32_17_PCREL_RELA
;
9632 cond_reloc
= R_NDS32_INSN16
;
9636 /* Not optimize for speed; convert sequence to 16-bit. */
9637 /* Save comp_insn16 to buffer. */
9638 bfd_putb16 (re_insn16
, contents
+ irel
->r_offset
);
9640 reloc
= R_NDS32_9_PCREL_RELA
;
9641 cond_reloc
= R_NDS32_NONE
;
9645 else if (N32_OP6 (re_insn
) == N32_OP6_BR1
9646 && (foff
>= -(ACCURATE_14BIT_S1
- first_size
)
9647 && foff
< ACCURATE_14BIT_S1
- first_size
))
9649 /* beqs label ; 15_PCREL */
9650 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9652 reloc
= R_NDS32_15_PCREL_RELA
;
9653 cond_reloc
= R_NDS32_NONE
;
9656 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
9657 && foff
>= -CONSERVATIVE_16BIT_S1
9658 && foff
< CONSERVATIVE_16BIT_S1
)
9660 /* beqz label ; 17_PCREL */
9661 bfd_putb32 (re_insn
, contents
+ irel
->r_offset
);
9663 reloc
= R_NDS32_17_PCREL_RELA
;
9664 cond_reloc
= R_NDS32_NONE
;
9667 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
9668 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
9670 /* Relax to one of the following 3 variations
9672 case 2-4; 1st insn convertible, 16-bit on, optimize off or optimize
9674 bnes38 rt, $1 ; LONGJUMP2
9678 case 4-4; 1st insn not convertible, others don't care
9679 bne rt, ra, $1 ; LONGJUMP2
9683 case 4-4; 1st insn convertible, 16-bit on, optimize for speed
9684 bne rt, ra, $1 ; LONGJUMP2
9688 /* Offset for first instruction. */
9690 /* Use j label as second instruction. */
9691 *insn_len
= 4 + first_size
;
9693 bfd_putb32 (insn
, contents
+ hi_irelfn
->r_offset
);
9694 reloc
= R_NDS32_LONGJUMP2
;
9695 cond_reloc
= R_NDS32_25_PLTREL
;
9700 if (cond_removed
== 1)
9702 /* Set all relocations. */
9703 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), reloc
);
9704 irel
->r_addend
= hi_irelfn
->r_addend
;
9706 cond_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irelfn
->r_info
),
9708 cond_irelfn
->r_addend
= 0;
9709 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9714 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
9715 irel
->r_addend
= irel
->r_addend
;
9716 hi_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
),
9720 if ((seq_len
^ *insn_len
) & 0x2)
9722 insn16
= NDS32_NOP16
;
9723 bfd_putb16 (insn16
, contents
+ irel
->r_offset
+ *insn_len
);
9724 lo_irelfn
->r_offset
= *insn_len
;
9725 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9727 lo_irelfn
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
9731 lo_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (lo_irelfn
->r_info
),
9736 /* Relax LONGCALL4 relocation for nds32_elf_relax_section. */
9739 nds32_elf_relax_longcall4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9740 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9741 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9742 Elf_Internal_Shdr
*symtab_hdr
)
9744 /* The pattern for LONGCALL4. Support for function cse.
9745 sethi ta, hi20(symbol) ; LONGCALL4/HI20
9746 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
9747 jral ta ; PTR_RES/EMPTY/INSN16 */
9751 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *insn_irel
, *em_irel
, *call_irel
;
9752 Elf_Internal_Rela
*irelend
;
9753 int pic_ext_target
= 0;
9754 bfd_signed_vma foff
;
9756 irelend
= internal_relocs
+ sec
->reloc_count
;
9757 laddr
= irel
->r_offset
;
9759 /* Get the reloc for the address from which the register is
9760 being loaded. This reloc will tell us which function is
9761 actually being called. */
9762 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9763 R_NDS32_HI20_RELA
, laddr
);
9765 if (hi_irel
== irelend
)
9767 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
9772 /* Get the value of the symbol referred to by the reloc. */
9773 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
,
9776 /* This condition only happened when symbol is undefined. */
9777 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9778 || foff
>= CONSERVATIVE_24BIT_S1
)
9781 /* Relax to: jal symbol; 25_PCREL */
9782 /* For simplicity of coding, we are going to modify the section
9783 contents, the section relocs, and the BFD symbol table. We
9784 must tell the rest of the code not to free up this
9785 information. It would be possible to instead create a table
9786 of changes which have to be made, as is done in coff-mips.c;
9787 that would be more work, but would require less memory when
9788 the linker is run. */
9790 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9791 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
9792 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9793 R_NDS32_EMPTY
, irel
->r_addend
);
9795 if (ptr_irel
== irelend
|| em_irel
== irelend
)
9797 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL4",
9801 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
9802 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
9803 if (insn
& 0x80000000)
9806 /* Replace the long call with a jal. */
9807 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
9808 R_NDS32_25_PCREL_RELA
);
9809 ptr_irel
->r_addend
= 1;
9811 /* We don't resolve this here but resolve it in relocate_section. */
9813 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
9816 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9818 /* If there is function cse, HI20 can not remove now. */
9819 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9820 R_NDS32_LONGCALL4
, laddr
);
9821 if (call_irel
== irelend
)
9825 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
9828 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9829 R_NDS32_INSN16
, irel
->r_addend
);
9830 if (insn_irel
!= irelend
)
9832 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9837 /* Relax LONGCALL5 relocation for nds32_elf_relax_section. */
9840 nds32_elf_relax_longcall5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9841 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9842 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9843 Elf_Internal_Shdr
*symtab_hdr
)
9845 /* The pattern for LONGCALL5.
9846 bltz rt, .L1 ; LONGCALL5/17_PCREL
9847 jal symbol ; 25_PCREL
9852 Elf_Internal_Rela
*cond_irel
, *irelend
;
9853 int pic_ext_target
= 0;
9854 bfd_signed_vma foff
;
9856 irelend
= internal_relocs
+ sec
->reloc_count
;
9857 laddr
= irel
->r_offset
;
9858 insn
= bfd_getb32 (contents
+ laddr
);
9860 /* Get the reloc for the address from which the register is
9861 being loaded. This reloc will tell us which function is
9862 actually being called. */
9864 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9865 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
9866 if (cond_irel
== irelend
)
9868 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL5",
9873 /* Get the value of the symbol referred to by the reloc. */
9874 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
9877 if (foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
9878 || foff
>= CONSERVATIVE_16BIT_S1
)
9881 /* Relax to bgezal rt, label ; 17_PCREL
9882 or bltzal rt, label ; 17_PCREL */
9884 /* Convert to complimentary conditional call. */
9885 insn
= CONVERT_CONDITION_CALL (insn
);
9887 /* For simplicity of coding, we are going to modify the section
9888 contents, the section relocs, and the BFD symbol table. We
9889 must tell the rest of the code not to free up this
9890 information. It would be possible to instead create a table
9891 of changes which have to be made, as is done in coff-mips.c;
9892 that would be more work, but would require less memory when
9893 the linker is run. */
9895 /* Modify relocation and contents. */
9897 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
9899 /* Replace the long call with a bgezal. */
9900 bfd_putb32 (insn
, contents
+ cond_irel
->r_offset
);
9903 /* Clean unnessary relocations. */
9904 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9906 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9907 R_NDS32_17_PCREL_RELA
, laddr
);
9909 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
9914 /* Relax LONGCALL6 relocation for nds32_elf_relax_section. */
9917 nds32_elf_relax_longcall6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
9918 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
9919 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
9920 Elf_Internal_Shdr
*symtab_hdr
)
9922 /* The pattern for LONGCALL6.
9923 bltz rt, .L1 ; LONGCALL6/17_PCREL
9924 sethi ta, hi20(symbol) ; HI20/PTR
9925 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
9926 jral ta ; PTR_RES/EMPTY/INSN16
9931 Elf_Internal_Rela
*em_irel
, *cond_irel
, *irelend
;
9932 int pic_ext_target
= 0;
9933 bfd_signed_vma foff
;
9935 irelend
= internal_relocs
+ sec
->reloc_count
;
9936 laddr
= irel
->r_offset
;
9938 /* Get the reloc for the address from which the register is
9939 being loaded. This reloc will tell us which function is
9940 actually being called. */
9941 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9942 R_NDS32_EMPTY
, irel
->r_addend
);
9944 if (em_irel
== irelend
)
9946 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGCALL6",
9951 /* Get the value of the symbol referred to by the reloc. */
9952 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
,
9955 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
9956 || foff
>= CONSERVATIVE_24BIT_S1
)
9959 /* Check these is enough space to insert jal in R_NDS32_EMPTY. */
9960 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
9961 if (insn
& 0x80000000)
9964 insn
= bfd_getb32 (contents
+ laddr
);
9965 if (foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
9967 /* Relax to bgezal rt, label ; 17_PCREL
9968 or bltzal rt, label ; 17_PCREL */
9970 /* Convert to complimentary conditional call. */
9972 insn
= CONVERT_CONDITION_CALL (insn
);
9973 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
9976 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_17_PCREL_RELA
);
9978 /* Set resolved relocation. */
9980 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9981 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
9982 if (cond_irel
== irelend
)
9984 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
9985 "R_NDS32_LONGCALL6", irel
->r_offset
);
9988 cond_irel
->r_addend
= 1;
9990 /* Clear relocations. */
9993 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
9996 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
9997 R_NDS32_17_PCREL_RELA
, laddr
);
9998 if (cond_irel
!= irelend
)
10000 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10003 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10004 R_NDS32_INSN16
, irel
->r_addend
);
10005 if (cond_irel
!= irelend
)
10006 cond_irel
->r_info
=
10007 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10010 else if (foff
>= -CONSERVATIVE_24BIT_S1
&& foff
< CONSERVATIVE_24BIT_S1
)
10012 /* Relax to the following instruction sequence
10013 bltz rt, .L1 ; LONGCALL2/17_PCREL
10014 jal symbol ; 25_PCREL/PTR_RES
10017 /* Convert instruction. */
10019 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10021 /* Convert relocations. */
10022 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
),
10023 R_NDS32_25_PCREL_RELA
);
10025 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_LONGCALL5
);
10027 /* Set resolved relocation. */
10029 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10030 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10031 if (cond_irel
== irelend
)
10033 _bfd_error_handler (unrecognized_reloc_msg
, abfd
,
10034 "R_NDS32_LONGCALL6", irel
->r_offset
);
10037 cond_irel
->r_addend
= 1;
10040 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10041 R_NDS32_INSN16
, irel
->r_addend
);
10042 if (cond_irel
!= irelend
)
10043 cond_irel
->r_info
=
10044 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10049 /* Relax LONGJUMP4 relocation for nds32_elf_relax_section. */
10052 nds32_elf_relax_longjump4 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10053 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10054 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10055 Elf_Internal_Shdr
*symtab_hdr
)
10057 /* The pattern for LONGJUMP4.
10058 sethi ta, hi20(symbol) ; LONGJUMP4/HI20
10059 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10060 jr ta ; PTR_RES/INSN16/EMPTY */
10063 int seq_len
; /* Original length of instruction sequence. */
10065 Elf_Internal_Rela
*hi_irel
, *ptr_irel
, *em_irel
, *call_irel
, *irelend
;
10066 int pic_ext_target
= 0;
10067 bfd_signed_vma foff
;
10069 irelend
= internal_relocs
+ sec
->reloc_count
;
10070 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10071 laddr
= irel
->r_offset
;
10072 *insn_len
= seq_len
;
10074 /* Get the reloc for the address from which the register is
10075 being loaded. This reloc will tell us which function is
10076 actually being called. */
10078 hi_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10079 R_NDS32_HI20_RELA
, laddr
);
10081 if (hi_irel
== irelend
)
10083 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
10088 /* Get the value of the symbol referred to by the reloc. */
10089 foff
= calculate_offset (abfd
, sec
, hi_irel
, isymbuf
, symtab_hdr
,
10092 if (pic_ext_target
|| foff
== 0 || foff
>= CONSERVATIVE_24BIT_S1
10093 || foff
< -CONSERVATIVE_24BIT_S1
)
10096 /* Convert it to "j label", it may be converted to j8 in the final
10097 pass of relaxation. Therefore, we do not consider this currently. */
10098 ptr_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10099 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
10100 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10101 R_NDS32_EMPTY
, irel
->r_addend
);
10103 if (ptr_irel
== irelend
|| em_irel
== irelend
)
10105 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP4",
10111 ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), R_NDS32_25_PCREL_RELA
);
10112 ptr_irel
->r_addend
= 1;
10114 /* Write instruction. */
10116 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10118 /* Clear relocations. */
10119 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10121 /* If there is function cse, HI20 can not remove now. */
10122 call_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10123 R_NDS32_LONGJUMP4
, laddr
);
10124 if (call_irel
== irelend
)
10128 ELF32_R_INFO (ELF32_R_SYM (hi_irel
->r_info
), R_NDS32_NONE
);
10134 /* Relax LONGJUMP5 relocation for nds32_elf_relax_section. */
10137 nds32_elf_relax_longjump5 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10138 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10139 int *seq_len
, bfd_byte
*contents
,
10140 Elf_Internal_Sym
*isymbuf
,
10141 Elf_Internal_Shdr
*symtab_hdr
)
10143 /* There are 2 variations for LONGJUMP5
10144 case 2-4; 1st insn convertible, 16-bit on.
10145 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
10146 j label ; 25_PCREL/INSN16
10149 case 4-4; 1st insn not convertible
10150 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
10151 j label ; 25_PCREL/INSN16
10155 Elf_Internal_Rela
*cond_irel
, *irelend
;
10156 int pic_ext_target
= 0;
10158 bfd_signed_vma foff
;
10159 uint32_t insn
, re_insn
= 0;
10160 uint16_t insn16
, re_insn16
= 0;
10161 unsigned long reloc
;
10163 enum elf_nds32_reloc_type checked_types
[] =
10164 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
10165 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
10167 irelend
= internal_relocs
+ sec
->reloc_count
;
10168 laddr
= irel
->r_offset
;
10170 /* Get the reloc for the address from which the register is
10171 being loaded. This reloc will tell us which function is
10172 actually being called. */
10175 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10176 R_NDS32_25_PCREL_RELA
, irel
->r_addend
);
10177 if (cond_irel
== irelend
)
10179 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP5",
10184 /* Get the value of the symbol referred to by the reloc. */
10185 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
10188 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_16BIT_S1
10189 || foff
>= CONSERVATIVE_16BIT_S1
)
10192 /* Get the all corresponding instructions. */
10193 insn
= bfd_getb32 (contents
+ laddr
);
10194 /* Check instruction size. */
10195 if (insn
& 0x80000000)
10198 insn16
= insn
>> 16;
10199 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10202 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10204 if (N32_OP6 (re_insn
) == N32_OP6_BR1
10205 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
10207 /* beqs label ; 15_PCREL. */
10208 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10209 reloc
= R_NDS32_15_PCREL_RELA
;
10211 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10212 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10214 /* beqz label ; 17_PCREL. */
10215 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10216 reloc
= R_NDS32_17_PCREL_RELA
;
10218 else if ( N32_OP6 (re_insn
) == N32_OP6_BR3
10219 && foff
>= -CONSERVATIVE_8BIT_S1
&& foff
< CONSERVATIVE_8BIT_S1
)
10221 /* beqc label ; 9_PCREL. */
10222 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10223 reloc
= R_NDS32_WORD_9_PCREL_RELA
;
10228 /* Set all relocations. */
10229 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), reloc
);
10231 /* Clean relocations. */
10232 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10233 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
10235 cond_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10236 checked_types
[i
], laddr
);
10237 if (cond_irel
!= irelend
)
10240 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
10242 /* If the branch instruction is 2 byte, it cannot remove
10243 directly. Only convert it to nop16 and remove it after
10244 checking alignment issue. */
10245 insn16
= NDS32_NOP16
;
10246 bfd_putb16 (insn16
, contents
+ laddr
);
10247 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10250 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10259 /* Relax LONGJUMP6 relocation for nds32_elf_relax_section. */
10262 nds32_elf_relax_longjump6 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10263 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10264 int *seq_len
, bfd_byte
*contents
,
10265 Elf_Internal_Sym
*isymbuf
,
10266 Elf_Internal_Shdr
*symtab_hdr
)
10268 /* There are 5 variations for LONGJUMP6
10269 case : 2-4-4-4; 1st insn convertible, 16-bit on.
10270 bnes38 rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
10271 sethi ta, hi20(symbol) ; HI20/PTR
10272 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10273 jr ta ; PTR_RES/INSN16/EMPTY
10276 case : 4-4-4-4; 1st insn not convertible, 16-bit on.
10277 bne rt, ra, .L1 ; LONGJUMP6/15_PCREL/INSN16
10278 sethi ta, hi20(symbol) ; HI20/PTR
10279 ori ta, ta, lo12(symbol) ; LO12S0_ORI/PTR
10280 jr ta ; PTR_RES/INSN16/EMPTY
10283 enum elf_nds32_reloc_type checked_types
[] =
10284 { R_NDS32_17_PCREL_RELA
, R_NDS32_15_PCREL_RELA
,
10285 R_NDS32_9_PCREL_RELA
, R_NDS32_INSN16
};
10287 int reloc_off
= 0, cond_removed
= 0;
10289 Elf_Internal_Rela
*cond_irel
, *em_irel
, *irelend
, *insn_irel
;
10290 int pic_ext_target
= 0;
10292 bfd_signed_vma foff
;
10293 uint32_t insn
, re_insn
= 0;
10294 uint16_t insn16
, re_insn16
= 0;
10295 unsigned long reloc
;
10297 irelend
= internal_relocs
+ sec
->reloc_count
;
10298 laddr
= irel
->r_offset
;
10300 /* Get the reloc for the address from which the register is
10301 being loaded. This reloc will tell us which function is
10302 actually being called. */
10303 em_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10304 R_NDS32_EMPTY
, irel
->r_addend
);
10306 if (em_irel
== irelend
)
10308 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP6",
10313 /* Get the value of the symbol referred to by the reloc. */
10314 foff
= calculate_offset (abfd
, sec
, em_irel
, isymbuf
, symtab_hdr
,
10317 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_24BIT_S1
10318 || foff
>= CONSERVATIVE_24BIT_S1
)
10321 insn
= bfd_getb32 (contents
+ laddr
);
10322 /* Check instruction size. */
10323 if (insn
& 0x80000000)
10326 insn16
= insn
>> 16;
10327 nds32_elf_convert_branch (insn16
, 0, &re_insn16
, &re_insn
);
10330 nds32_elf_convert_branch (0, insn
, &re_insn16
, &re_insn
);
10332 /* For simplicity of coding, we are going to modify the section
10333 contents, the section relocs, and the BFD symbol table. We
10334 must tell the rest of the code not to free up this
10335 information. It would be possible to instead create a table
10336 of changes which have to be made, as is done in coff-mips.c;
10337 that would be more work, but would require less memory when
10338 the linker is run. */
10340 if (N32_OP6 (re_insn
) == N32_OP6_BR1
10341 && (foff
>= -CONSERVATIVE_14BIT_S1
&& foff
< CONSERVATIVE_14BIT_S1
))
10343 /* beqs label ; 15_PCREL */
10344 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
10345 reloc
= R_NDS32_15_PCREL_RELA
;
10348 else if (N32_OP6 (re_insn
) == N32_OP6_BR2
10349 && foff
>= -CONSERVATIVE_16BIT_S1
&& foff
< CONSERVATIVE_16BIT_S1
)
10351 /* beqz label ; 17_PCREL */
10352 bfd_putb32 (re_insn
, contents
+ em_irel
->r_offset
);
10353 reloc
= R_NDS32_17_PCREL_RELA
;
10356 else if (foff
>= -CONSERVATIVE_24BIT_S1
- reloc_off
10357 && foff
< CONSERVATIVE_24BIT_S1
- reloc_off
)
10359 /* Relax to one of the following 2 variations
10361 case 2-4; 1st insn convertible, 16-bit on.
10362 bnes38 rt, ra, .L1 ; LONGJUMP5/9_PCREL/INSN16
10363 j label ; 25_PCREL/INSN16
10366 case 4-4; 1st insn not convertible
10367 bne rt, ra, .L1 ; LONGJUMP5/15_PCREL/INSN16
10368 j label ; 25_PCREL/INSN16
10371 /* Use j label as second instruction. */
10373 reloc
= R_NDS32_25_PCREL_RELA
;
10374 bfd_putb32 (insn
, contents
+ em_irel
->r_offset
);
10379 /* Set all relocations. */
10380 em_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (em_irel
->r_info
), reloc
);
10383 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10384 R_NDS32_PTR_RESOLVED
, em_irel
->r_offset
);
10385 cond_irel
->r_addend
= 1;
10387 /* Use INSN16 of first branch instruction to distinguish if keeping
10388 INSN16 of final instruction or not. */
10389 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10390 R_NDS32_INSN16
, irel
->r_offset
);
10391 if (insn_irel
== irelend
)
10393 /* Clean the final INSN16. */
10395 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10396 R_NDS32_INSN16
, em_irel
->r_offset
);
10397 insn_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10401 if (cond_removed
== 1)
10405 /* Clear relocations. */
10406 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10408 for (i
= 0; i
< sizeof (checked_types
) / sizeof (checked_types
[0]); i
++)
10411 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10412 checked_types
[i
], laddr
);
10413 if (cond_irel
!= irelend
)
10416 && (ELF32_R_TYPE (cond_irel
->r_info
) == R_NDS32_INSN16
))
10418 /* If the branch instruction is 2 byte, it cannot remove
10419 directly. Only convert it to nop16 and remove it after
10420 checking alignment issue. */
10421 insn16
= NDS32_NOP16
;
10422 bfd_putb16 (insn16
, contents
+ laddr
);
10423 cond_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10426 cond_irel
->r_info
=
10427 ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
), R_NDS32_NONE
);
10433 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
10434 R_NDS32_LONGJUMP5
);
10440 /* Relax LONGJUMP7 relocation for nds32_elf_relax_section. */
10443 nds32_elf_relax_longjump7 (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
10444 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10445 int *seq_len
, bfd_byte
*contents
,
10446 Elf_Internal_Sym
*isymbuf
,
10447 Elf_Internal_Shdr
*symtab_hdr
)
10449 /* There are 2 variations for LONGJUMP5
10450 case 2-4; 1st insn convertible, 16-bit on.
10451 movi55 ta, imm11 ; LONGJUMP7/INSN16
10452 beq rt, ta, label ; 15_PCREL
10454 case 4-4; 1st insn not convertible
10455 movi55 ta, imm11 ; LONGJUMP7/INSN16
10456 beq rt, ta, label ; 15_PCREL */
10459 Elf_Internal_Rela
*cond_irel
, *irelend
, *insn_irel
;
10460 int pic_ext_target
= 0;
10461 bfd_signed_vma foff
;
10462 uint32_t insn
, re_insn
= 0;
10466 irelend
= internal_relocs
+ sec
->reloc_count
;
10467 laddr
= irel
->r_offset
;
10469 /* Get the reloc for the address from which the register is
10470 being loaded. This reloc will tell us which function is
10471 actually being called. */
10474 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10475 R_NDS32_15_PCREL_RELA
, irel
->r_addend
);
10476 if (cond_irel
== irelend
)
10478 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LONGJUMP7",
10483 /* Get the value of the symbol referred to by the reloc. */
10484 foff
= calculate_offset (abfd
, sec
, cond_irel
, isymbuf
, symtab_hdr
,
10487 if (pic_ext_target
|| foff
== 0 || foff
< -CONSERVATIVE_8BIT_S1
10488 || foff
>= CONSERVATIVE_8BIT_S1
)
10491 /* Get the first instruction for its size. */
10492 insn
= bfd_getb32 (contents
+ laddr
);
10493 if (insn
& 0x80000000)
10496 /* Get the immediate from movi55. */
10497 imm11
= N16_IMM5S (insn
>> 16);
10501 /* Get the immediate from movi. */
10502 imm11
= N32_IMM20S (insn
);
10505 /* Get the branch instruction. */
10506 insn
= bfd_getb32 (contents
+ irel
->r_addend
);
10507 /* Convert instruction to BR3. */
10508 if ((insn
>> 14) & 0x1)
10509 re_insn
= N32_BR3 (BNEC
, N32_RT5 (insn
), imm11
, 0);
10511 re_insn
= N32_BR3 (BEQC
, N32_RT5 (insn
), imm11
, 0);
10513 bfd_putb32 (re_insn
, contents
+ cond_irel
->r_offset
);
10515 /* Set all relocations. */
10516 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10517 R_NDS32_WORD_9_PCREL_RELA
);
10519 /* Clean relocations. */
10520 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10521 insn_irel
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10522 R_NDS32_INSN16
, irel
->r_offset
);
10523 if (insn_irel
!= irelend
)
10527 /* If the first insntruction is 16bit, convert it to nop16. */
10528 insn16
= NDS32_NOP16
;
10529 bfd_putb16 (insn16
, contents
+ laddr
);
10530 insn_irel
->r_addend
= R_NDS32_INSN16_CONVERT_FLAG
;
10533 cond_irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (cond_irel
->r_info
),
10541 #define GET_LOADSTORE_RANGE(addend) (((addend) >> 8) & 0x3f)
10543 /* Relax LOADSTORE relocation for nds32_elf_relax_section. */
10546 nds32_elf_relax_loadstore (struct bfd_link_info
*link_info
, bfd
*abfd
,
10547 asection
*sec
, Elf_Internal_Rela
*irel
,
10548 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
10549 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10550 Elf_Internal_Shdr
*symtab_hdr
, int load_store_relax
)
10552 int eliminate_sethi
= 0, range_type
;
10554 bfd_vma local_sda
, laddr
;
10555 int seq_len
; /* Original length of instruction sequence. */
10557 Elf_Internal_Rela
*hi_irelfn
= NULL
, *irelend
;
10558 bfd_vma access_addr
= 0;
10559 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
10560 enum elf_nds32_reloc_type checked_types
[] =
10561 { R_NDS32_HI20_RELA
, R_NDS32_GOT_HI20
,
10562 R_NDS32_GOTPC_HI20
, R_NDS32_GOTOFF_HI20
,
10563 R_NDS32_PLTREL_HI20
, R_NDS32_PLT_GOTREL_HI20
,
10564 R_NDS32_TLS_LE_HI20
10567 irelend
= internal_relocs
+ sec
->reloc_count
;
10568 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
10569 laddr
= irel
->r_offset
;
10570 *insn_len
= seq_len
;
10572 /* Get the high part relocation. */
10573 for (i
= 0; i
< ARRAY_SIZE (checked_types
); i
++)
10575 hi_irelfn
= find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
10576 checked_types
[i
], laddr
);
10577 if (hi_irelfn
!= irelend
)
10581 if (hi_irelfn
== irelend
)
10583 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_LOADSTORE",
10588 range_type
= GET_LOADSTORE_RANGE (irel
->r_addend
);
10589 nds32_elf_final_sda_base (sec
->output_section
->owner
,
10590 link_info
, &local_sda
, FALSE
);
10592 switch (ELF32_R_TYPE (hi_irelfn
->r_info
))
10594 case R_NDS32_HI20_RELA
:
10595 insn
= bfd_getb32 (contents
+ laddr
);
10597 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10599 if (range_type
== NDS32_LOADSTORE_IMM
)
10601 struct elf_link_hash_entry
*h
= NULL
;
10604 if (ELF32_R_SYM (hi_irelfn
->r_info
) >= symtab_hdr
->sh_info
)
10606 indx
= ELF32_R_SYM (hi_irelfn
->r_info
) - symtab_hdr
->sh_info
;
10607 h
= elf_sym_hashes (abfd
)[indx
];
10610 if ((access_addr
< CONSERVATIVE_20BIT
)
10611 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
10613 eliminate_sethi
= 1;
10617 /* This is avoid to relax symbol address which is fixed
10618 relocations. Ex: _stack. */
10619 if (h
&& bfd_is_abs_section (h
->root
.u
.def
.section
))
10623 if (!load_store_relax
)
10626 /* Case for set gp register. */
10627 if (N32_RT5 (insn
) == REG_GP
)
10630 if (range_type
== NDS32_LOADSTORE_FLOAT_S
10631 || range_type
== NDS32_LOADSTORE_FLOAT_S
)
10633 range_l
= sdata_range
[0][0];
10634 range_h
= sdata_range
[0][1];
10638 range_l
= sdata_range
[1][0];
10639 range_h
= sdata_range
[1][1];
10643 case R_NDS32_GOT_HI20
:
10645 calculate_got_memory_address (abfd
, link_info
, hi_irelfn
, symtab_hdr
);
10647 /* If this symbol is not in .got, the return value will be -1.
10648 Since the gp value is set to SDA_BASE but not GLOBAL_OFFSET_TABLE,
10649 a negative offset is allowed. */
10650 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10651 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10652 eliminate_sethi
= 1;
10655 case R_NDS32_PLT_GOTREL_HI20
:
10656 access_addr
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
,
10657 hi_irelfn
, symtab_hdr
);
10659 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10660 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10661 eliminate_sethi
= 1;
10664 case R_NDS32_GOTOFF_HI20
:
10666 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10668 if ((bfd_signed_vma
) (access_addr
- local_sda
) < CONSERVATIVE_20BIT
10669 && (bfd_signed_vma
) (access_addr
- local_sda
) >= -CONSERVATIVE_20BIT
)
10670 eliminate_sethi
= 1;
10673 case R_NDS32_GOTPC_HI20
:
10674 /* The access_addr must consider r_addend of hi_irel. */
10675 access_addr
= sec
->output_section
->vma
+ sec
->output_offset
10676 + irel
->r_offset
+ hi_irelfn
->r_addend
;
10678 if ((bfd_signed_vma
) (local_sda
- access_addr
) < CONSERVATIVE_20BIT
10679 && (bfd_signed_vma
) (local_sda
- access_addr
) >= -CONSERVATIVE_20BIT
)
10680 eliminate_sethi
= 1;
10683 case R_NDS32_TLS_LE_HI20
:
10685 calculate_memory_address (abfd
, hi_irelfn
, isymbuf
, symtab_hdr
);
10686 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10687 access_addr
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10688 if ((range_type
== NDS32_LOADSTORE_IMM
)
10689 && (bfd_signed_vma
) (access_addr
) < CONSERVATIVE_20BIT
10690 && (bfd_signed_vma
) (access_addr
) >= -CONSERVATIVE_20BIT
)
10691 eliminate_sethi
= 1;
10698 /* Delete sethi instruction. */
10699 if (eliminate_sethi
== 1
10700 || (local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
10701 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
10703 hi_irelfn
->r_info
=
10704 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn
->r_info
), R_NDS32_NONE
);
10706 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
10712 /* Relax LO12 relocation for nds32_elf_relax_section. */
10715 nds32_elf_relax_lo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10716 asection
*sec
, Elf_Internal_Rela
*irel
,
10717 Elf_Internal_Rela
*internal_relocs
, bfd_byte
*contents
,
10718 Elf_Internal_Sym
*isymbuf
, Elf_Internal_Shdr
*symtab_hdr
)
10721 bfd_vma local_sda
, laddr
;
10722 unsigned long reloc
;
10723 bfd_vma access_addr
;
10724 bfd_vma range_l
= 0, range_h
= 0; /* Upper/lower bound. */
10725 Elf_Internal_Rela
*irelfn
= NULL
, *irelend
;
10726 struct elf_link_hash_entry
*h
= NULL
;
10729 /* For SDA base relative relaxation. */
10730 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
10731 &local_sda
, FALSE
);
10733 irelend
= internal_relocs
+ sec
->reloc_count
;
10734 laddr
= irel
->r_offset
;
10735 insn
= bfd_getb32 (contents
+ laddr
);
10737 if (!is_sda_access_insn (insn
) && N32_OP6 (insn
) != N32_OP6_ORI
)
10740 access_addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10742 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
10744 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
10745 h
= elf_sym_hashes (abfd
)[indx
];
10748 if (N32_OP6 (insn
) == N32_OP6_ORI
&& access_addr
< CONSERVATIVE_20BIT
10749 && (!h
|| (h
&& strcmp (h
->root
.root
.string
, FP_BASE_NAME
) != 0)))
10751 reloc
= R_NDS32_20_RELA
;
10752 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10753 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10754 bfd_putb32 (insn
, contents
+ laddr
);
10756 /* This is avoid to relax symbol address which is fixed
10757 relocations. Ex: _stack. */
10758 else if (N32_OP6 (insn
) == N32_OP6_ORI
10759 && h
&& bfd_is_abs_section (h
->root
.u
.def
.section
))
10763 range_l
= sdata_range
[1][0];
10764 range_h
= sdata_range
[1][1];
10765 switch (ELF32_R_TYPE (irel
->r_info
))
10767 case R_NDS32_LO12S0_RELA
:
10768 reloc
= R_NDS32_SDA19S0_RELA
;
10770 case R_NDS32_LO12S1_RELA
:
10771 reloc
= R_NDS32_SDA18S1_RELA
;
10773 case R_NDS32_LO12S2_RELA
:
10774 reloc
= R_NDS32_SDA17S2_RELA
;
10776 case R_NDS32_LO12S2_DP_RELA
:
10777 range_l
= sdata_range
[0][0];
10778 range_h
= sdata_range
[0][1];
10779 reloc
= R_NDS32_SDA12S2_DP_RELA
;
10781 case R_NDS32_LO12S2_SP_RELA
:
10782 range_l
= sdata_range
[0][0];
10783 range_h
= sdata_range
[0][1];
10784 reloc
= R_NDS32_SDA12S2_SP_RELA
;
10790 /* There are range_h and range_l because linker has to promise
10791 all sections move cross one page together. */
10792 if ((local_sda
<= access_addr
&& (access_addr
- local_sda
) < range_h
)
10793 || (local_sda
> access_addr
&& (local_sda
- access_addr
) <= range_l
))
10795 if (N32_OP6 (insn
) == N32_OP6_ORI
&& N32_RT5 (insn
) == REG_GP
)
10797 /* Maybe we should add R_NDS32_INSN16 reloc type here
10798 or manually do some optimization. sethi can't be
10799 eliminated when updating $gp so the relative ori
10800 needs to be preserved. */
10803 if (!turn_insn_to_sda_access (insn
, ELF32_R_TYPE (irel
->r_info
),
10806 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10807 bfd_putb32 (insn
, contents
+ laddr
);
10809 irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10811 /* SDA17 must keep INSN16 for converting fp_as_gp. */
10812 if (irelfn
!= irelend
&& reloc
!= R_NDS32_SDA17S2_RELA
)
10814 ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_NDS32_NONE
);
10821 /* Relax low part of PIC instruction pattern. */
10824 nds32_elf_relax_piclo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10825 asection
*sec
, Elf_Internal_Rela
*irel
,
10826 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10827 Elf_Internal_Shdr
*symtab_hdr
)
10830 bfd_vma local_sda
, laddr
;
10831 bfd_signed_vma foff
;
10832 unsigned long reloc
;
10834 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
10835 &local_sda
, FALSE
);
10836 laddr
= irel
->r_offset
;
10837 insn
= bfd_getb32 (contents
+ laddr
);
10839 if (N32_OP6 (insn
) != N32_OP6_ORI
)
10842 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
)
10844 foff
= calculate_got_memory_address (abfd
, link_info
, irel
,
10845 symtab_hdr
) - local_sda
;
10846 reloc
= R_NDS32_GOT20
;
10848 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
)
10850 foff
= calculate_plt_memory_address (abfd
, link_info
, isymbuf
, irel
,
10851 symtab_hdr
) - local_sda
;
10852 reloc
= R_NDS32_PLT_GOTREL_LO20
;
10854 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
)
10856 foff
= calculate_memory_address (abfd
, irel
, isymbuf
,
10857 symtab_hdr
) - local_sda
;
10858 reloc
= R_NDS32_GOTOFF
;
10860 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
)
10862 foff
= local_sda
- sec
->output_section
->vma
+ sec
->output_offset
10863 + irel
->r_offset
+ irel
->r_addend
;
10864 reloc
= R_NDS32_GOTPC20
;
10869 if ((foff
< CONSERVATIVE_20BIT
) && (foff
>= -CONSERVATIVE_20BIT
))
10871 /* Turn into MOVI. */
10872 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10873 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10874 bfd_putb32 (insn
, contents
+ laddr
);
10878 /* Relax low part of LE TLS instruction pattern. */
10881 nds32_elf_relax_letlslo12 (struct bfd_link_info
*link_info
, bfd
*abfd
,
10882 Elf_Internal_Rela
*irel
,
10883 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10884 Elf_Internal_Shdr
*symtab_hdr
)
10888 bfd_signed_vma foff
;
10889 unsigned long reloc
;
10891 laddr
= irel
->r_offset
;
10892 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10893 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10894 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10895 insn
= bfd_getb32 (contents
+ laddr
);
10897 if ( (bfd_signed_vma
) (foff
) < CONSERVATIVE_20BIT
10898 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_20BIT
)
10900 /* Pattern sethi-ori transform to movi. */
10901 reloc
= R_NDS32_TLS_LE_20
;
10902 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), reloc
);
10903 insn
= N32_TYPE1 (MOVI
, N32_RT5 (insn
), 0);
10904 bfd_putb32 (insn
, contents
+ laddr
);
10908 /* Relax LE TLS calculate address instruction pattern. */
10911 nds32_elf_relax_letlsadd (struct bfd_link_info
*link_info
, bfd
*abfd
,
10912 asection
*sec
, Elf_Internal_Rela
*irel
,
10913 Elf_Internal_Rela
*internal_relocs
,
10914 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10915 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
10917 /* Local TLS non-pic
10918 sethi ta, hi20(symbol@tpoff) ; TLS_LE_HI20
10919 ori ta, ta, lo12(symbol@tpoff) ; TLS_LE_LO12
10920 add ra, ta, tp ; TLS_LE_ADD */
10924 bfd_signed_vma foff
;
10925 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
10927 irelend
= internal_relocs
+ sec
->reloc_count
;
10928 laddr
= irel
->r_offset
;
10929 insn
= bfd_getb32 (contents
+ laddr
);
10930 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10931 R_NDS32_PTR_RESOLVED
);
10932 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10933 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10934 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10936 /* The range is +/-16k. */
10937 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT
10938 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT
)
10940 /* Transform add to addi. */
10941 insn
= N32_TYPE2 (ADDI
, N32_RT5 (insn
), N32_RB5 (insn
), 0);
10943 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S0
);
10945 bfd_putb32 (insn
, contents
+ laddr
);
10946 if (i1_irelfn
!= irelend
)
10948 i1_irelfn
->r_addend
|= 1;
10954 /* Relax LE TLS load store instruction pattern. */
10957 nds32_elf_relax_letlsls (struct bfd_link_info
*link_info
, bfd
*abfd
,
10958 asection
*sec
, Elf_Internal_Rela
*irel
,
10959 Elf_Internal_Rela
*internal_relocs
,
10960 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
10961 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
10966 bfd_signed_vma foff
;
10967 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
10970 irelend
= internal_relocs
+ sec
->reloc_count
;
10971 laddr
= irel
->r_offset
;
10972 insn
= bfd_getb32 (contents
+ laddr
);
10973 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
10974 R_NDS32_PTR_RESOLVED
);
10975 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
10976 BFD_ASSERT (elf_hash_table (link_info
)->tls_sec
!= NULL
);
10977 foff
-= (elf_hash_table (link_info
)->tls_sec
->vma
+ TP_OFFSET
);
10979 switch ((N32_OP6 (insn
) << 8) | (insn
& 0xff))
10981 case (N32_OP6_MEM
<< 8) | N32_MEM_LB
:
10982 case (N32_OP6_MEM
<< 8) | N32_MEM_SB
:
10983 case (N32_OP6_MEM
<< 8) | N32_MEM_LBS
:
10984 /* The range is +/-16k. */
10985 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT
10986 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT
)
10989 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
10991 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S0
);
10995 /* Fall through. */
10996 case (N32_OP6_MEM
<< 8) | N32_MEM_LH
:
10997 case (N32_OP6_MEM
<< 8) | N32_MEM_SH
:
10998 case (N32_OP6_MEM
<< 8) | N32_MEM_LHS
:
10999 /* The range is +/-32k. */
11000 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT_S1
11001 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT_S1
)
11004 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
11006 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S1
);
11010 /* Fall through. */
11011 case (N32_OP6_MEM
<< 8) | N32_MEM_LW
:
11012 case (N32_OP6_MEM
<< 8) | N32_MEM_SW
:
11013 /* The range is +/-64k. */
11014 if ((bfd_signed_vma
) (foff
) < CONSERVATIVE_15BIT_S2
11015 && (bfd_signed_vma
) (foff
) >= -CONSERVATIVE_15BIT_S2
)
11018 ((insn
& 0xff) << 25) | (insn
& 0x1f00000) | ((insn
& 0x7c00) << 5);
11020 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_TLS_LE_15S2
);
11024 /* Fall through. */
11031 bfd_putb32 (insn
, contents
+ laddr
);
11032 if (i1_irelfn
!= irelend
)
11034 i1_irelfn
->r_addend
|= 1;
11040 /* Relax PTR relocation for nds32_elf_relax_section. */
11043 nds32_elf_relax_ptr (bfd
*abfd
, asection
*sec
, Elf_Internal_Rela
*irel
,
11044 Elf_Internal_Rela
*internal_relocs
, int *insn_len
,
11045 int *seq_len
, bfd_byte
*contents
)
11047 Elf_Internal_Rela
*ptr_irel
, *irelend
, *count_irel
, *re_irel
;
11049 irelend
= internal_relocs
+ sec
->reloc_count
;
11052 find_relocs_at_address_addr (irel
, internal_relocs
, irelend
,
11053 R_NDS32_PTR_RESOLVED
, irel
->r_addend
);
11055 if (re_irel
== irelend
)
11057 _bfd_error_handler (unrecognized_reloc_msg
, abfd
, "R_NDS32_PTR",
11062 if (re_irel
->r_addend
!= 1)
11065 /* Pointed target is relaxed and no longer needs this void *,
11066 change the type to NONE. */
11067 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11069 /* Find PTR_COUNT to decide remove it or not. If PTR_COUNT does
11070 not exist, it means only count 1 and remove it directly. */
11071 /* TODO: I hope we can obsolate R_NDS32_COUNT in the future. */
11072 count_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11073 R_NDS32_PTR_COUNT
);
11074 ptr_irel
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11076 if (count_irel
!= irelend
)
11078 if (--count_irel
->r_addend
> 0)
11082 if (ptr_irel
!= irelend
)
11085 /* If the PTR_COUNT is already 0, remove current instruction. */
11086 *seq_len
= nds32_elf_insn_size (abfd
, contents
, irel
->r_offset
);
11091 /* Relax PLT_GOT_SUFF relocation for nds32_elf_relax_section. */
11094 nds32_elf_relax_pltgot_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11095 asection
*sec
, Elf_Internal_Rela
*irel
,
11096 Elf_Internal_Rela
*internal_relocs
,
11097 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11098 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11101 bfd_signed_vma foff
;
11102 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
11103 bfd_vma local_sda
, laddr
;
11105 irelend
= internal_relocs
+ sec
->reloc_count
;
11106 laddr
= irel
->r_offset
;
11107 insn
= bfd_getb32 (contents
+ laddr
);
11109 /* FIXME: It's a little trouble to turn JRAL5 to JAL since
11110 we need additional space. It might be help if we could
11111 borrow some space from instructions to be eliminated
11112 such as sethi, ori, add. */
11113 if (insn
& 0x80000000)
11116 if (nds32_elf_check_dup_relocs
11117 (irel
, internal_relocs
, irelend
, R_NDS32_PLT_GOT_SUFF
))
11121 find_relocs_at_address (irel
, internal_relocs
, irelend
,
11122 R_NDS32_PTR_RESOLVED
);
11125 The boundary should be reduced since the .plt section hasn't
11126 been created and the address of specific entry is still unknown
11127 Maybe the range between the function call and the begin of the
11128 .text section can be used to decide if the .plt is in the range
11129 of function call. */
11131 if (N32_OP6 (insn
) == N32_OP6_ALU1
11132 && N32_SUB5 (insn
) == N32_ALU1_ADD
)
11134 /* Get the value of the symbol referred to by the reloc. */
11135 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11136 &local_sda
, FALSE
);
11137 foff
= (bfd_signed_vma
) (calculate_plt_memory_address
11138 (abfd
, link_info
, isymbuf
, irel
,
11139 symtab_hdr
) - local_sda
);
11140 /* This condition only happened when symbol is undefined. */
11144 if (foff
< -CONSERVATIVE_19BIT
|| foff
>= CONSERVATIVE_19BIT
)
11146 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11147 R_NDS32_PLT_GOTREL_LO19
);
11149 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
11151 else if (N32_OP6 (insn
) == N32_OP6_JREG
11152 && N32_SUB5 (insn
) == N32_JREG_JRAL
)
11154 /* Get the value of the symbol referred to by the reloc. */
11156 calculate_plt_offset (abfd
, sec
, link_info
, isymbuf
, irel
, symtab_hdr
);
11157 /* This condition only happened when symbol is undefined. */
11160 if (foff
< -CONSERVATIVE_24BIT_S1
|| foff
>= CONSERVATIVE_24BIT_S1
)
11162 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_25_PLTREL
);
11168 bfd_putb32 (insn
, contents
+ laddr
);
11169 if (i1_irelfn
!= irelend
)
11171 i1_irelfn
->r_addend
|= 1;
11176 /* Relax GOT_SUFF relocation for nds32_elf_relax_section. */
11179 nds32_elf_relax_got_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11180 asection
*sec
, Elf_Internal_Rela
*irel
,
11181 Elf_Internal_Rela
*internal_relocs
,
11182 bfd_byte
*contents
, Elf_Internal_Shdr
*symtab_hdr
,
11183 bfd_boolean
*again
)
11186 bfd_signed_vma foff
;
11187 Elf_Internal_Rela
*i1_irelfn
, *irelend
;
11188 bfd_vma local_sda
, laddr
;
11190 irelend
= internal_relocs
+ sec
->reloc_count
;
11191 laddr
= irel
->r_offset
;
11192 insn
= bfd_getb32 (contents
+ laddr
);
11193 if (insn
& 0x80000000)
11196 if (nds32_elf_check_dup_relocs
11197 (irel
, internal_relocs
, irelend
, R_NDS32_GOT_SUFF
))
11200 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11201 R_NDS32_PTR_RESOLVED
);
11203 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11204 &local_sda
, FALSE
);
11205 foff
= calculate_got_memory_address (abfd
, link_info
, irel
,
11206 symtab_hdr
) - local_sda
;
11208 if (foff
< CONSERVATIVE_19BIT
&& foff
>= -CONSERVATIVE_19BIT
)
11210 /* Turn LW to LWI.GP. Change relocation type to R_NDS32_GOT_REL. */
11211 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
11213 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_GOT17S2_RELA
);
11214 bfd_putb32 (insn
, contents
+ laddr
);
11215 if (i1_irelfn
!= irelend
)
11217 i1_irelfn
->r_addend
|= 1;
11223 /* Relax PLT_GOT_SUFF relocation for nds32_elf_relax_section. */
11226 nds32_elf_relax_gotoff_suff (struct bfd_link_info
*link_info
, bfd
*abfd
,
11227 asection
*sec
, Elf_Internal_Rela
*irel
,
11228 Elf_Internal_Rela
*internal_relocs
,
11229 bfd_byte
*contents
, Elf_Internal_Sym
*isymbuf
,
11230 Elf_Internal_Shdr
*symtab_hdr
, bfd_boolean
*again
)
11232 int opc_insn_gotoff
;
11234 bfd_signed_vma foff
;
11235 Elf_Internal_Rela
*i1_irelfn
, *i2_irelfn
, *irelend
;
11236 bfd_vma local_sda
, laddr
;
11238 irelend
= internal_relocs
+ sec
->reloc_count
;
11239 laddr
= irel
->r_offset
;
11240 insn
= bfd_getb32 (contents
+ laddr
);
11242 if (insn
& 0x80000000)
11245 if (nds32_elf_check_dup_relocs
11246 (irel
, internal_relocs
, irelend
, R_NDS32_GOTOFF_SUFF
))
11249 i1_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11250 R_NDS32_PTR_RESOLVED
);
11251 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11252 &local_sda
, FALSE
);
11253 foff
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
11254 foff
= foff
- local_sda
;
11256 if (foff
>= CONSERVATIVE_19BIT
|| foff
< -CONSERVATIVE_19BIT
)
11259 /* Concatenate opcode and sub-opcode for switch case.
11260 It may be MEM or ALU1. */
11261 opc_insn_gotoff
= (N32_OP6 (insn
) << 8) | (insn
& 0xff);
11262 switch (opc_insn_gotoff
)
11264 case (N32_OP6_MEM
<< 8) | N32_MEM_LW
:
11265 /* 4-byte aligned. */
11266 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (6, 17, 3));
11268 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA17S2_RELA
);
11270 case (N32_OP6_MEM
<< 8) | N32_MEM_SW
:
11271 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), __MF (7, 17, 3));
11273 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA17S2_RELA
);
11275 case (N32_OP6_MEM
<< 8) | N32_MEM_LH
:
11276 /* 2-byte aligned. */
11277 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), 0);
11279 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11281 case (N32_OP6_MEM
<< 8) | N32_MEM_LHS
:
11282 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (18));
11284 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11286 case (N32_OP6_MEM
<< 8) | N32_MEM_SH
:
11287 insn
= N32_TYPE1 (HWGP
, N32_RT5 (insn
), N32_BIT (19));
11289 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA18S1_RELA
);
11291 case (N32_OP6_MEM
<< 8) | N32_MEM_LB
:
11292 /* 1-byte aligned. */
11293 insn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), 0);
11295 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11297 case (N32_OP6_MEM
<< 8) | N32_MEM_LBS
:
11298 insn
= N32_TYPE1 (LBGP
, N32_RT5 (insn
), N32_BIT (19));
11300 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11302 case (N32_OP6_MEM
<< 8) | N32_MEM_SB
:
11303 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), 0);
11305 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11307 case (N32_OP6_ALU1
<< 8) | N32_ALU1_ADD
:
11308 insn
= N32_TYPE1 (SBGP
, N32_RT5 (insn
), N32_BIT (19));
11310 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_SDA19S0_RELA
);
11316 bfd_putb32 (insn
, contents
+ laddr
);
11317 if (i1_irelfn
!= irelend
)
11319 i1_irelfn
->r_addend
|= 1;
11322 if ((i2_irelfn
= find_relocs_at_address (irel
, internal_relocs
, irelend
,
11323 R_NDS32_INSN16
)) != irelend
)
11324 i2_irelfn
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11329 nds32_relax_adjust_label (bfd
*abfd
, asection
*sec
,
11330 Elf_Internal_Rela
*internal_relocs
,
11331 bfd_byte
*contents
,
11332 nds32_elf_blank_t
**relax_blank_list
,
11333 int optimize
, int opt_size
)
11335 /* This code block is used to adjust 4-byte alignment by relax a pair
11336 of instruction a time.
11338 It recognizes three types of relocations.
11339 1. R_NDS32_LABEL - a alignment.
11340 2. R_NDS32_INSN16 - relax a 32-bit instruction to 16-bit.
11341 3. is_16bit_NOP () - remove a 16-bit instruction. */
11343 /* TODO: It seems currently implementation only support 4-byte alignment.
11344 We should handle any-alignment. */
11346 Elf_Internal_Rela
*insn_rel
= NULL
, *label_rel
= NULL
, *irel
;
11347 Elf_Internal_Rela
*tmp_rel
, *tmp2_rel
= NULL
;
11348 Elf_Internal_Rela rel_temp
;
11349 Elf_Internal_Rela
*irelend
;
11353 /* Checking for branch relaxation relies on the relocations to
11354 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
11355 nds32_insertion_sort (internal_relocs
, sec
->reloc_count
,
11356 sizeof (Elf_Internal_Rela
), compar_reloc
);
11358 irelend
= internal_relocs
+ sec
->reloc_count
;
11360 /* Force R_NDS32_LABEL before R_NDS32_INSN16. */
11361 /* FIXME: Can we generate the right order in assembler?
11362 So we don't have to swapping them here. */
11364 for (label_rel
= internal_relocs
, insn_rel
= internal_relocs
;
11365 label_rel
< irelend
; label_rel
++)
11367 if (ELF32_R_TYPE (label_rel
->r_info
) != R_NDS32_LABEL
)
11370 /* Find the first reloc has the same offset with label_rel. */
11371 while (insn_rel
< irelend
&& insn_rel
->r_offset
< label_rel
->r_offset
)
11374 for (;insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
;
11376 /* Check if there were R_NDS32_INSN16 and R_NDS32_LABEL at the same
11378 if (ELF32_R_TYPE (insn_rel
->r_info
) == R_NDS32_INSN16
)
11381 if (insn_rel
< irelend
&& insn_rel
->r_offset
== label_rel
->r_offset
11382 && insn_rel
< label_rel
)
11384 /* Swap the two reloc if the R_NDS32_INSN16 is
11385 before R_NDS32_LABEL. */
11386 memcpy (&rel_temp
, insn_rel
, sizeof (Elf_Internal_Rela
));
11387 memcpy (insn_rel
, label_rel
, sizeof (Elf_Internal_Rela
));
11388 memcpy (label_rel
, &rel_temp
, sizeof (Elf_Internal_Rela
));
11394 /* If there were a sequence of R_NDS32_LABEL end up with .align 2
11395 or higher, remove other R_NDS32_LABEL with lower alignment.
11396 If an R_NDS32_INSN16 in between R_NDS32_LABELs must be converted,
11397 then the R_NDS32_LABEL sequence is broke. */
11398 for (tmp_rel
= internal_relocs
; tmp_rel
< irelend
; tmp_rel
++)
11400 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_LABEL
)
11402 if (label_rel
== NULL
)
11404 if (tmp_rel
->r_addend
< 2)
11405 label_rel
= tmp_rel
;
11408 else if (tmp_rel
->r_addend
> 1)
11410 /* Remove all LABEL relocation from label_rel to tmp_rel
11411 including relocations with same offset as tmp_rel. */
11412 for (tmp2_rel
= label_rel
; tmp2_rel
< tmp_rel
11413 || tmp2_rel
->r_offset
== tmp_rel
->r_offset
; tmp2_rel
++)
11415 if (ELF32_R_TYPE (tmp2_rel
->r_info
) == R_NDS32_LABEL
11416 && tmp2_rel
->r_addend
< 2)
11418 ELF32_R_INFO (ELF32_R_SYM (tmp2_rel
->r_info
),
11424 else if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
&& label_rel
)
11426 /* A new INSN16 which can be converted, so clear label_rel. */
11427 if (is_convert_32_to_16 (abfd
, sec
, tmp_rel
, internal_relocs
,
11429 || is_16bit_NOP (abfd
, sec
, tmp_rel
))
11436 /* Optimized for speed and nothing has not been relaxed.
11437 It's time to align labels.
11438 We may convert a 16-bit instruction right before a label to
11439 32-bit, in order to align the label if necessary
11440 all reloc entries has been sorted by r_offset. */
11441 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
11443 if (ELF32_R_TYPE (irel
->r_info
) != R_NDS32_INSN16
11444 && ELF32_R_TYPE (irel
->r_info
) != R_NDS32_LABEL
)
11447 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_INSN16
)
11449 /* A new INSN16 found, resize the old one. */
11450 if (is_convert_32_to_16
11451 (abfd
, sec
, irel
, internal_relocs
, irelend
, &insn16
)
11452 || is_16bit_NOP (abfd
, sec
, irel
))
11456 /* Previous INSN16 reloc exists, reduce its
11458 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
11461 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
11462 internal_relocs
, irelend
, insn16
);
11464 if (!insert_nds32_elf_blank_recalc_total
11465 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11468 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11470 if (!insert_nds32_elf_blank_recalc_total
11471 (relax_blank_list
, insn_rel
->r_offset
, 2))
11475 ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
), R_NDS32_NONE
);
11477 /* Save the new one for later use. */
11481 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
11484 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
)
11486 /* Search for label. */
11487 int force_relax
= 0;
11489 /* Label on 16-bit instruction or optimization
11490 needless, just reset this reloc. */
11491 insn16
= bfd_getb16 (contents
+ irel
->r_offset
);
11492 if ((irel
->r_addend
& 0x1f) < 2 && (!optimize
|| (insn16
& 0x8000)))
11495 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
), R_NDS32_NONE
);
11500 irel
->r_offset
- get_nds32_elf_blank_total (relax_blank_list
,
11501 irel
->r_offset
, 1);
11505 /* Check if there is case which can not be aligned. */
11506 if (irel
->r_addend
== 2 && address
& 0x2)
11511 /* Try to align this label. */
11513 if ((irel
->r_addend
& 0x1f) < 2)
11515 /* Check if there is a INSN16 at the same address.
11516 Label_rel always seats before insn_rel after
11519 /* Search for INSN16 at LABEL location. If INSN16 is at
11520 same location and this LABEL alignment is lower than 2,
11521 the INSN16 can be converted to 2-byte. */
11522 for (tmp_rel
= irel
;
11523 tmp_rel
< irelend
&& tmp_rel
->r_offset
== irel
->r_offset
;
11526 if (ELF32_R_TYPE (tmp_rel
->r_info
) == R_NDS32_INSN16
11527 && (is_convert_32_to_16
11528 (abfd
, sec
, tmp_rel
, internal_relocs
,
11530 || is_16bit_NOP (abfd
, sec
, tmp_rel
)))
11538 if (force_relax
|| irel
->r_addend
== 1 || address
& 0x2)
11540 /* Label not aligned. */
11541 /* Previous reloc exists, reduce its size to 16-bit. */
11542 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
,
11543 internal_relocs
, irelend
, &insn16
))
11545 nds32_elf_write_16 (abfd
, contents
, insn_rel
,
11546 internal_relocs
, irelend
, insn16
);
11548 if (!insert_nds32_elf_blank_recalc_total
11549 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11552 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11554 if (!insert_nds32_elf_blank_recalc_total
11555 (relax_blank_list
, insn_rel
->r_offset
, 2))
11560 /* INSN16 reloc is used. */
11566 sec
->size
- get_nds32_elf_blank_total (relax_blank_list
, sec
->size
, 0);
11567 if (insn_rel
&& (address
& 0x2 || opt_size
))
11569 if (is_convert_32_to_16 (abfd
, sec
, insn_rel
, internal_relocs
,
11572 nds32_elf_write_16 (abfd
, contents
, insn_rel
, internal_relocs
,
11574 if (!insert_nds32_elf_blank_recalc_total
11575 (relax_blank_list
, insn_rel
->r_offset
+ 2, 2))
11577 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
11580 else if (is_16bit_NOP (abfd
, sec
, insn_rel
))
11582 if (!insert_nds32_elf_blank_recalc_total
11583 (relax_blank_list
, insn_rel
->r_offset
, 2))
11585 insn_rel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (insn_rel
->r_info
),
11593 /* Pick relaxation round. */
11596 nds32_elf_pick_relax (bfd_boolean init
, asection
*sec
, bfd_boolean
*again
,
11597 struct elf_nds32_link_hash_table
*table
,
11598 struct bfd_link_info
*link_info
)
11600 static asection
*final_sec
, *first_sec
= NULL
;
11601 static bfd_boolean normal_again
= FALSE
;
11602 static bfd_boolean set
= FALSE
;
11603 static bfd_boolean first
= TRUE
;
11604 int round_table
[] = {
11605 NDS32_RELAX_NORMAL_ROUND
,
11606 NDS32_RELAX_JUMP_IFC_ROUND
,
11607 NDS32_RELAX_EX9_BUILD_ROUND
,
11608 NDS32_RELAX_EX9_REPLACE_ROUND
,
11610 static int pass
= 0;
11611 static int relax_round
;
11613 /* The new round. */
11614 if (init
&& first_sec
== sec
)
11617 normal_again
= FALSE
;
11622 /* Run an empty run to get the final section. */
11623 relax_round
= NDS32_RELAX_EMPTY_ROUND
;
11625 /* It has to enter relax again because we can
11626 not make sure what the final turn is. */
11635 /* Not reenter yet. */
11637 return relax_round
;
11640 relax_round
= round_table
[pass
];
11642 if (!init
&& relax_round
== NDS32_RELAX_NORMAL_ROUND
&& *again
)
11643 normal_again
= TRUE
;
11645 if (!init
&& final_sec
== sec
)
11647 switch (relax_round
)
11649 case NDS32_RELAX_NORMAL_ROUND
:
11652 /* Normal relaxation done. */
11653 if (table
->target_optimize
& NDS32_RELAX_JUMP_IFC_ON
)
11658 else if (table
->target_optimize
& NDS32_RELAX_EX9_ON
)
11660 pass
+= 2; /* NDS32_RELAX_EX9_BUILD_ROUND */
11663 else if (table
->ex9_import_file
)
11665 /* Import ex9 table. */
11666 if (table
->update_ex9_table
)
11667 pass
+= 2; /* NDS32_RELAX_EX9_BUILD_ROUND */
11669 pass
+= 3; /* NDS32_RELAX_EX9_REPLACE_ROUND */
11670 nds32_elf_ex9_import_table (link_info
);
11675 case NDS32_RELAX_JUMP_IFC_ROUND
:
11676 if (!nds32_elf_ifc_finish (link_info
))
11677 _bfd_error_handler (_("error: Jump IFC Fail."));
11678 if (table
->target_optimize
& NDS32_RELAX_EX9_ON
)
11684 case NDS32_RELAX_EX9_BUILD_ROUND
:
11685 nds32_elf_ex9_finish (link_info
);
11689 case NDS32_RELAX_EX9_REPLACE_ROUND
:
11690 if (table
->target_optimize
& NDS32_RELAX_JUMP_IFC_ON
)
11692 /* Do jump IFC optimization again. */
11693 if (!nds32_elf_ifc_finish (link_info
))
11694 _bfd_error_handler (_("error: Jump IFC Fail."));
11702 return relax_round
;
11706 nds32_elf_relax_section (bfd
*abfd
, asection
*sec
,
11707 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
11709 nds32_elf_blank_t
*relax_blank_list
= NULL
;
11710 Elf_Internal_Shdr
*symtab_hdr
;
11711 Elf_Internal_Rela
*internal_relocs
;
11712 Elf_Internal_Rela
*irel
;
11713 Elf_Internal_Rela
*irelend
;
11714 Elf_Internal_Sym
*isymbuf
= NULL
;
11715 bfd_byte
*contents
= NULL
;
11716 bfd_boolean result
= TRUE
;
11722 /* Target dependnet option. */
11723 struct elf_nds32_link_hash_table
*table
;
11724 int load_store_relax
;
11727 relax_blank_list
= NULL
;
11731 /* Nothing to do for
11732 * relocatable link or
11733 * non-relocatable section or
11734 * non-code section or
11736 * no reloc entry. */
11737 if (bfd_link_relocatable (link_info
)
11738 || (sec
->flags
& SEC_RELOC
) == 0
11739 || (sec
->flags
& SEC_EXCLUDE
) != 0
11740 || (sec
->flags
& SEC_CODE
) == 0
11744 /* 09.12.11 Workaround. */
11745 /* We have to adjust align for R_NDS32_LABEL if needed.
11746 The adjust approach only can fix 2-byte align once. */
11747 if (sec
->alignment_power
> 2)
11750 /* The optimization type to do. */
11752 table
= nds32_elf_hash_table (link_info
);
11753 relax_round
= nds32_elf_pick_relax (TRUE
, sec
, again
, table
, link_info
);
11754 switch (relax_round
)
11756 case NDS32_RELAX_JUMP_IFC_ROUND
:
11757 /* Here is the entrance of ifc jump relaxation. */
11758 if (!nds32_elf_ifc_calc (link_info
, abfd
, sec
))
11760 nds32_elf_pick_relax (FALSE
, sec
, again
, table
, link_info
);
11763 case NDS32_RELAX_EX9_BUILD_ROUND
:
11764 /* Here is the entrance of ex9 relaxation. There are two pass of
11765 ex9 relaxation. The one is to traverse all instructions and build
11766 the hash table. The other one is to compare instructions and replace
11768 if (!nds32_elf_ex9_build_hash_table (abfd
, sec
, link_info
))
11770 nds32_elf_pick_relax (FALSE
, sec
, again
, table
, link_info
);
11773 case NDS32_RELAX_EX9_REPLACE_ROUND
:
11774 if (!nds32_elf_ex9_replace_instruction (link_info
, abfd
, sec
))
11778 case NDS32_RELAX_EMPTY_ROUND
:
11779 nds32_elf_pick_relax (FALSE
, sec
, again
, table
, link_info
);
11782 case NDS32_RELAX_NORMAL_ROUND
:
11784 if (sec
->reloc_count
== 0)
11789 /* The begining of general relaxation. */
11791 if (is_SDA_BASE_set
== 0)
11794 is_SDA_BASE_set
= 1;
11795 nds32_elf_final_sda_base (sec
->output_section
->owner
, link_info
,
11797 relax_range_measurement (abfd
);
11800 if (is_ITB_BASE_set
== 0)
11802 /* Set the _ITB_BASE_. */
11803 if (!nds32_elf_ex9_itb_base (link_info
))
11805 _bfd_error_handler (_("%B: error: Cannot set _ITB_BASE_"), abfd
);
11806 bfd_set_error (bfd_error_bad_value
);
11810 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11811 /* Relocations MUST be kept in memory, because relaxation adjust them. */
11812 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
11813 TRUE
/* keep_memory */);
11814 if (internal_relocs
== NULL
)
11817 irelend
= internal_relocs
+ sec
->reloc_count
;
11818 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
11819 irelend
, R_NDS32_RELAX_ENTRY
);
11821 if (irel
== irelend
)
11824 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
)
11826 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
)
11828 nds32_elf_pick_relax (FALSE
, sec
, again
, table
, link_info
);
11832 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG
)
11835 if (irel
->r_addend
& R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG
)
11839 load_store_relax
= table
->load_store_relax
;
11841 /* Get symbol table and section content. */
11842 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
11843 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
11846 /* Do relax loop only when finalize is not done.
11847 Take care of relaxable relocs except INSN16. */
11848 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
11850 int seq_len
; /* Original length of instruction sequence. */
11851 int insn_len
= 0; /* Final length of instruction sequence. */
11852 bfd_boolean removed
;
11855 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
11856 && (irel
->r_addend
& 0x1f) >= 2)
11859 /* Relocation Types
11860 R_NDS32_LONGCALL1 53
11861 R_NDS32_LONGCALL2 54
11862 R_NDS32_LONGCALL3 55
11863 R_NDS32_LONGJUMP1 56
11864 R_NDS32_LONGJUMP2 57
11865 R_NDS32_LONGJUMP3 58
11866 R_NDS32_LOADSTORE 59 */
11867 if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL1
11868 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LOADSTORE
)
11869 seq_len
= GET_SEQ_LEN (irel
->r_addend
);
11871 /* Relocation Types
11872 R_NDS32_LONGCALL4 107
11873 R_NDS32_LONGCALL5 108
11874 R_NDS32_LONGCALL6 109
11875 R_NDS32_LONGJUMP4 110
11876 R_NDS32_LONGJUMP5 111
11877 R_NDS32_LONGJUMP6 112
11878 R_NDS32_LONGJUMP7 113 */
11879 else if (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LONGCALL4
11880 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LONGJUMP7
)
11883 /* Relocation Types
11884 R_NDS32_LO12S0_RELA 30
11885 R_NDS32_LO12S1_RELA 29
11886 R_NDS32_LO12S2_RELA 28
11887 R_NDS32_LO12S2_SP_RELA 71
11888 R_NDS32_LO12S2_DP_RELA 70
11889 R_NDS32_GOT_LO12 46
11890 R_NDS32_GOTOFF_LO12 50
11891 R_NDS32_PLTREL_LO12 65
11892 R_NDS32_PLT_GOTREL_LO12 67
11893 R_NDS32_17IFC_PCREL_RELA 96
11894 R_NDS32_GOT_SUFF 193
11895 R_NDS32_GOTOFF_SUFF 194
11896 R_NDS32_PLT_GOT_SUFF 195
11897 R_NDS32_MULCALL_SUFF 196
11899 else if ((ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_LO12S0_RELA
11900 && ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_LO12S2_RELA
)
11901 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_SP_RELA
11902 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_DP_RELA
11903 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOT_LO12
11904 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTOFF_LO12
11905 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_GOTPC_LO12
11906 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLTREL_LO12
11907 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_PLT_GOTREL_LO12
11908 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_GOT_SUFF
11909 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_PTR
)
11910 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
11911 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LO12
11912 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_ADD
11913 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_TLS_LE_LS
)
11918 insn_len
= seq_len
;
11921 switch (ELF32_R_TYPE (irel
->r_info
))
11923 case R_NDS32_LONGCALL1
:
11924 removed
= nds32_elf_relax_longcall1 (abfd
, sec
, irel
, internal_relocs
,
11925 &insn_len
, contents
, isymbuf
,
11928 case R_NDS32_LONGCALL2
:
11929 removed
= nds32_elf_relax_longcall2 (abfd
, sec
, irel
, internal_relocs
,
11930 &insn_len
, contents
, isymbuf
,
11933 case R_NDS32_LONGCALL3
:
11934 removed
= nds32_elf_relax_longcall3 (abfd
, sec
, irel
, internal_relocs
,
11935 &insn_len
, contents
, isymbuf
,
11938 case R_NDS32_LONGJUMP1
:
11939 removed
= nds32_elf_relax_longjump1 (abfd
, sec
, irel
, internal_relocs
,
11940 &insn_len
, contents
, isymbuf
,
11943 case R_NDS32_LONGJUMP2
:
11944 removed
= nds32_elf_relax_longjump2 (abfd
, sec
, irel
, internal_relocs
,
11945 &insn_len
, contents
, isymbuf
,
11948 case R_NDS32_LONGJUMP3
:
11949 removed
= nds32_elf_relax_longjump3 (abfd
, sec
, irel
, internal_relocs
,
11950 &insn_len
, contents
, isymbuf
,
11953 case R_NDS32_LONGCALL4
:
11954 removed
= nds32_elf_relax_longcall4 (abfd
, sec
, irel
, internal_relocs
,
11955 &insn_len
, contents
, isymbuf
,
11958 case R_NDS32_LONGCALL5
:
11959 removed
= nds32_elf_relax_longcall5 (abfd
, sec
, irel
, internal_relocs
,
11960 &insn_len
, contents
, isymbuf
,
11963 case R_NDS32_LONGCALL6
:
11964 removed
= nds32_elf_relax_longcall6 (abfd
, sec
, irel
, internal_relocs
,
11965 &insn_len
, contents
, isymbuf
,
11968 case R_NDS32_LONGJUMP4
:
11969 removed
= nds32_elf_relax_longjump4 (abfd
, sec
, irel
, internal_relocs
,
11970 &insn_len
, contents
, isymbuf
,
11973 case R_NDS32_LONGJUMP5
:
11974 removed
= nds32_elf_relax_longjump5 (abfd
, sec
, irel
, internal_relocs
,
11975 &insn_len
, &seq_len
, contents
,
11976 isymbuf
, symtab_hdr
);
11978 case R_NDS32_LONGJUMP6
:
11979 removed
= nds32_elf_relax_longjump6 (abfd
, sec
, irel
, internal_relocs
,
11980 &insn_len
, &seq_len
, contents
,
11981 isymbuf
, symtab_hdr
);
11983 case R_NDS32_LONGJUMP7
:
11984 removed
= nds32_elf_relax_longjump7 (abfd
, sec
, irel
, internal_relocs
,
11985 &insn_len
, &seq_len
, contents
,
11986 isymbuf
, symtab_hdr
);
11988 case R_NDS32_LOADSTORE
:
11989 removed
= nds32_elf_relax_loadstore (link_info
, abfd
, sec
, irel
,
11990 internal_relocs
, &insn_len
,
11991 contents
, isymbuf
, symtab_hdr
,
11994 case R_NDS32_LO12S0_RELA
:
11995 case R_NDS32_LO12S1_RELA
:
11996 case R_NDS32_LO12S2_DP_RELA
:
11997 case R_NDS32_LO12S2_SP_RELA
:
11998 case R_NDS32_LO12S2_RELA
:
11999 /* Relax for low part. */
12000 nds32_elf_relax_lo12 (link_info
, abfd
, sec
, irel
, internal_relocs
,
12001 contents
, isymbuf
, symtab_hdr
);
12003 /* It is impossible to delete blank, so just continue. */
12005 case R_NDS32_GOT_LO12
:
12006 case R_NDS32_GOTOFF_LO12
:
12007 case R_NDS32_PLTREL_LO12
:
12008 case R_NDS32_PLT_GOTREL_LO12
:
12009 case R_NDS32_GOTPC_LO12
:
12010 /* Relax for PIC gp-relative low part. */
12011 nds32_elf_relax_piclo12 (link_info
, abfd
, sec
, irel
, contents
,
12012 isymbuf
, symtab_hdr
);
12014 /* It is impossible to delete blank, so just continue. */
12016 case R_NDS32_TLS_LE_LO12
:
12017 /* Relax for LE TLS low part. */
12018 nds32_elf_relax_letlslo12 (link_info
, abfd
, irel
, contents
,
12019 isymbuf
, symtab_hdr
);
12021 /* It is impossible to delete blank, so just continue. */
12023 case R_NDS32_TLS_LE_ADD
:
12024 nds32_elf_relax_letlsadd (link_info
, abfd
, sec
, irel
, internal_relocs
,
12025 contents
, isymbuf
, symtab_hdr
, again
);
12026 /* It is impossible to delete blank, so just continue. */
12028 case R_NDS32_TLS_LE_LS
:
12029 nds32_elf_relax_letlsls (link_info
, abfd
, sec
, irel
, internal_relocs
,
12030 contents
, isymbuf
, symtab_hdr
, again
);
12033 removed
= nds32_elf_relax_ptr (abfd
, sec
, irel
, internal_relocs
,
12034 &insn_len
, &seq_len
, contents
);
12036 case R_NDS32_PLT_GOT_SUFF
:
12037 nds32_elf_relax_pltgot_suff (link_info
, abfd
, sec
, irel
,
12038 internal_relocs
, contents
,
12039 isymbuf
, symtab_hdr
, again
);
12040 /* It is impossible to delete blank, so just continue. */
12042 case R_NDS32_GOT_SUFF
:
12043 nds32_elf_relax_got_suff (link_info
, abfd
, sec
, irel
,
12044 internal_relocs
, contents
,
12045 symtab_hdr
, again
);
12046 /* It is impossible to delete blank, so just continue. */
12048 case R_NDS32_GOTOFF_SUFF
:
12049 nds32_elf_relax_gotoff_suff (link_info
, abfd
, sec
, irel
,
12050 internal_relocs
, contents
,
12051 isymbuf
, symtab_hdr
, again
);
12052 /* It is impossible to delete blank, so just continue. */
12058 if (removed
&& seq_len
- insn_len
> 0)
12060 if (!insert_nds32_elf_blank
12061 (&relax_blank_list
, irel
->r_offset
+ insn_len
,
12062 seq_len
- insn_len
))
12068 calc_nds32_blank_total (relax_blank_list
);
12070 if (table
->relax_fp_as_gp
)
12072 if (!nds32_relax_fp_as_gp (link_info
, abfd
, sec
, internal_relocs
,
12078 if (!nds32_fag_remove_unused_fpbase (abfd
, sec
, internal_relocs
,
12084 nds32_elf_pick_relax (FALSE
, sec
, again
, table
, link_info
);
12088 if (!nds32_relax_adjust_label (abfd
, sec
, internal_relocs
, contents
,
12089 &relax_blank_list
, optimize
, opt_size
))
12093 /* It doesn't matter optimize_for_space_no_align anymore.
12094 If object file is assembled with flag '-Os',
12095 the we don't adjust jump-destination on 4-byte boundary. */
12097 if (relax_blank_list
)
12099 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
12100 relax_blank_list
= NULL
;
12105 /* Closing the section, so we don't relax it anymore. */
12106 bfd_vma sec_size_align
;
12107 Elf_Internal_Rela
*tmp_rel
;
12109 /* Pad to alignment boundary. Only handle current section alignment. */
12110 sec_size_align
= (sec
->size
+ (~((-1U) << sec
->alignment_power
)))
12111 & ((-1U) << sec
->alignment_power
);
12112 if ((sec_size_align
- sec
->size
) & 0x2)
12114 insn16
= NDS32_NOP16
;
12115 bfd_putb16 (insn16
, contents
+ sec
->size
);
12119 while (sec_size_align
!= sec
->size
)
12121 insn
= NDS32_NOP32
;
12122 bfd_putb32 (insn
, contents
+ sec
->size
);
12126 tmp_rel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
12127 irelend
, R_NDS32_RELAX_ENTRY
);
12128 if (tmp_rel
!= irelend
)
12129 tmp_rel
->r_addend
|= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG
;
12131 clean_nds32_elf_blank ();
12135 if (internal_relocs
!= NULL
12136 && elf_section_data (sec
)->relocs
!= internal_relocs
)
12137 free (internal_relocs
);
12139 if (contents
!= NULL
12140 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
12143 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (bfd_byte
*) isymbuf
)
12153 static struct bfd_elf_special_section
const nds32_elf_special_sections
[] =
12155 {".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
12156 {".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
12161 nds32_elf_output_arch_syms (bfd
*output_bfd ATTRIBUTE_UNUSED
,
12162 struct bfd_link_info
*info
,
12163 void *finfo ATTRIBUTE_UNUSED
,
12164 bfd_boolean (*func
) (void *, const char *,
12165 Elf_Internal_Sym
*,
12167 struct elf_link_hash_entry
*)
12170 FILE *sym_ld_script
= NULL
;
12171 struct elf_nds32_link_hash_table
*table
;
12173 table
= nds32_elf_hash_table (info
);
12174 sym_ld_script
= table
->sym_ld_script
;
12176 if (check_start_export_sym
)
12177 fprintf (sym_ld_script
, "}\n");
12182 static enum elf_reloc_type_class
12183 nds32_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
12184 const asection
*rel_sec ATTRIBUTE_UNUSED
,
12185 const Elf_Internal_Rela
*rela
)
12187 switch ((int) ELF32_R_TYPE (rela
->r_info
))
12189 case R_NDS32_RELATIVE
:
12190 return reloc_class_relative
;
12191 case R_NDS32_JMP_SLOT
:
12192 return reloc_class_plt
;
12194 return reloc_class_copy
;
12196 return reloc_class_normal
;
12200 /* Put target dependent option into info hash table. */
12202 bfd_elf32_nds32_set_target_option (struct bfd_link_info
*link_info
,
12203 int relax_fp_as_gp
,
12204 int eliminate_gc_relocs
,
12205 FILE * sym_ld_script
, int load_store_relax
,
12206 int target_optimize
, int relax_status
,
12207 int relax_round
, FILE * ex9_export_file
,
12208 FILE * ex9_import_file
,
12209 int update_ex9_table
, int ex9_limit
,
12210 bfd_boolean ex9_loop_aware
,
12211 bfd_boolean ifc_loop_aware
)
12213 struct elf_nds32_link_hash_table
*table
;
12215 table
= nds32_elf_hash_table (link_info
);
12219 table
->relax_fp_as_gp
= relax_fp_as_gp
;
12220 table
->eliminate_gc_relocs
= eliminate_gc_relocs
;
12221 table
->sym_ld_script
= sym_ld_script
;
12222 table
->load_store_relax
= load_store_relax
;
12223 table
->target_optimize
= target_optimize
;
12224 table
->relax_status
= relax_status
;
12225 table
->relax_round
= relax_round
;
12226 table
->ex9_export_file
= ex9_export_file
;
12227 table
->ex9_import_file
= ex9_import_file
;
12228 table
->update_ex9_table
= update_ex9_table
;
12229 table
->ex9_limit
= ex9_limit
;
12230 table
->ex9_loop_aware
= ex9_loop_aware
;
12231 table
->ifc_loop_aware
= ifc_loop_aware
;
12234 /* These functions and data-structures are used for fp-as-gp
12237 #define FAG_THRESHOLD 3 /* At least 3 gp-access. */
12238 /* lwi37.fp covers 508 bytes, but there may be 32-byte padding between
12239 the read-only section and read-write section. */
12240 #define FAG_WINDOW (508 - 32)
12242 /* An nds32_fag represent a gp-relative access.
12243 We find best fp-base by using a sliding window
12244 to find a base address which can cover most gp-access. */
12247 struct nds32_fag
*next
; /* NULL-teminated linked list. */
12248 bfd_vma addr
; /* The address of this fag. */
12249 Elf_Internal_Rela
**relas
; /* The relocations associated with this fag.
12250 It is used for applying FP7U2_FLAG. */
12251 int count
; /* How many times this address is referred.
12252 There should be exactly `count' relocations
12254 int relas_capcity
; /* The buffer size of relas.
12255 We use an array instead of linked-list,
12256 and realloc is used to adjust buffer size. */
12260 nds32_fag_init (struct nds32_fag
*head
)
12262 memset (head
, 0, sizeof (struct nds32_fag
));
12266 nds32_fag_verify (struct nds32_fag
*head
)
12268 struct nds32_fag
*iter
;
12269 struct nds32_fag
*prev
;
12275 if (prev
&& prev
->addr
>= iter
->addr
)
12276 puts ("Bug in fp-as-gp insertion.");
12282 /* Insert a fag in ascending order.
12283 If a fag of the same address already exists,
12284 they are chained by relas array. */
12287 nds32_fag_insert (struct nds32_fag
*head
, bfd_vma addr
,
12288 Elf_Internal_Rela
* rel
)
12290 struct nds32_fag
*iter
;
12291 struct nds32_fag
*new_fag
;
12292 const int INIT_RELAS_CAP
= 4;
12295 iter
->next
&& iter
->next
->addr
<= addr
;
12297 /* Find somewhere to insert. */ ;
12299 /* `iter' will be equal to `head' if the list is empty. */
12300 if (iter
!= head
&& iter
->addr
== addr
)
12302 /* The address exists in the list.
12303 Insert `rel' into relocation list, relas. */
12305 /* Check whether relas is big enough. */
12306 if (iter
->count
>= iter
->relas_capcity
)
12308 iter
->relas_capcity
*= 2;
12309 iter
->relas
= bfd_realloc
12310 (iter
->relas
, iter
->relas_capcity
* sizeof (void *));
12312 iter
->relas
[iter
->count
++] = rel
;
12316 /* This is a new address. Create a fag node for it. */
12317 new_fag
= bfd_malloc (sizeof (struct nds32_fag
));
12318 memset (new_fag
, 0, sizeof (*new_fag
));
12319 new_fag
->addr
= addr
;
12320 new_fag
->count
= 1;
12321 new_fag
->next
= iter
->next
;
12322 new_fag
->relas_capcity
= INIT_RELAS_CAP
;
12323 new_fag
->relas
= (Elf_Internal_Rela
**)
12324 bfd_malloc (new_fag
->relas_capcity
* sizeof (void *));
12325 new_fag
->relas
[0] = rel
;
12326 iter
->next
= new_fag
;
12328 nds32_fag_verify (head
);
12332 nds32_fag_free_list (struct nds32_fag
*head
)
12334 struct nds32_fag
*iter
;
12339 struct nds32_fag
*tmp
= iter
;
12347 /* Find the best fp-base address.
12348 The relocation associated with that address is returned,
12349 so we can track the symbol instead of a fixed address.
12351 When relaxation, the address of an datum may change,
12352 because a text section is shrinked, so the data section
12353 moves forward. If the aligments of text and data section
12354 are different, their distance may change too.
12355 Therefore, tracking a fixed address is not appriate. */
12358 nds32_fag_find_base (struct nds32_fag
*head
, struct nds32_fag
**bestpp
)
12360 struct nds32_fag
*base
; /* First fag in the window. */
12361 struct nds32_fag
*last
; /* First fag outside the window. */
12362 int accu
= 0; /* Usage accumulation. */
12363 struct nds32_fag
*best
; /* Best fag. */
12364 int baccu
= 0; /* Best accumulation. */
12366 /* Use first fag for initial, and find the last fag in the window.
12368 In each iteration, we could simply subtract previous fag
12369 and accumulate following fags which are inside the window,
12370 untill we each the end. */
12372 if (head
->next
== NULL
)
12378 /* Initialize base. */
12382 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12384 accu
+= last
->count
;
12388 /* Record the best base in each iteration. */
12391 accu
-= base
->count
;
12393 /* Account fags in window. */
12394 for (/* Nothing. */;
12395 last
&& last
->addr
< base
->addr
+ FAG_WINDOW
;
12397 accu
+= last
->count
;
12399 /* A better fp-base? */
12412 /* Apply R_NDS32_INSN16_FP7U2_FLAG on gp-relative accesses,
12413 so we can convert it fo fp-relative access later.
12414 `best_fag' is the best fp-base. Only those inside the window
12415 of best_fag is applied the flag. */
12418 nds32_fag_mark_relax (struct bfd_link_info
*link_info
,
12419 bfd
*abfd
, struct nds32_fag
*best_fag
,
12420 Elf_Internal_Rela
*internal_relocs
,
12421 Elf_Internal_Rela
*irelend
)
12423 struct nds32_fag
*ifag
;
12424 bfd_vma best_fpbase
, gp
;
12427 output_bfd
= abfd
->sections
->output_section
->owner
;
12428 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
12429 best_fpbase
= best_fag
->addr
;
12431 if (best_fpbase
> gp
+ sdata_range
[1][1]
12432 || best_fpbase
< gp
- sdata_range
[1][0])
12435 /* Mark these inside the window R_NDS32_INSN16_FP7U2_FLAG flag,
12436 so we know they can be converted to lwi37.fp. */
12437 for (ifag
= best_fag
;
12438 ifag
&& ifag
->addr
< best_fpbase
+ FAG_WINDOW
; ifag
= ifag
->next
)
12442 for (i
= 0; i
< ifag
->count
; i
++)
12444 Elf_Internal_Rela
*insn16_rel
;
12445 Elf_Internal_Rela
*fag_rel
;
12447 fag_rel
= ifag
->relas
[i
];
12449 /* Only if this is within the WINDOWS, FP7U2_FLAG
12452 insn16_rel
= find_relocs_at_address
12453 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12455 if (insn16_rel
!= irelend
)
12456 insn16_rel
->r_addend
= R_NDS32_INSN16_FP7U2_FLAG
;
12462 /* Reset INSN16 to clean fp as gp. */
12465 nds32_fag_unmark_relax (struct nds32_fag
*fag
,
12466 Elf_Internal_Rela
*internal_relocs
,
12467 Elf_Internal_Rela
*irelend
)
12469 struct nds32_fag
*ifag
;
12471 Elf_Internal_Rela
*insn16_rel
;
12472 Elf_Internal_Rela
*fag_rel
;
12474 for (ifag
= fag
; ifag
; ifag
= ifag
->next
)
12476 for (i
= 0; i
< ifag
->count
; i
++)
12478 fag_rel
= ifag
->relas
[i
];
12480 /* Restore the INSN16 relocation. */
12481 insn16_rel
= find_relocs_at_address
12482 (fag_rel
, internal_relocs
, irelend
, R_NDS32_INSN16
);
12484 if (insn16_rel
!= irelend
)
12485 insn16_rel
->r_addend
&= ~R_NDS32_INSN16_FP7U2_FLAG
;
12490 /* This is the main function of fp-as-gp optimization.
12491 It should be called by relax_section. */
12494 nds32_relax_fp_as_gp (struct bfd_link_info
*link_info
,
12495 bfd
*abfd
, asection
*sec
,
12496 Elf_Internal_Rela
*internal_relocs
,
12497 Elf_Internal_Rela
*irelend
,
12498 Elf_Internal_Sym
*isymbuf
)
12500 Elf_Internal_Rela
*begin_rel
= NULL
;
12501 Elf_Internal_Rela
*irel
;
12502 struct nds32_fag fag_head
;
12503 Elf_Internal_Shdr
*symtab_hdr
;
12504 bfd_byte
*contents
;
12505 bfd_boolean ifc_inside
= FALSE
;
12507 /* FIXME: Can we bfd_elf_link_read_relocs for the relocs? */
12509 /* Per-function fp-base selection.
12510 1. Create a list for all the gp-relative access.
12511 2. Base on those gp-relative address,
12512 find a fp-base which can cover most access.
12513 3. Use the fp-base for fp-as-gp relaxation.
12515 NOTE: If fp-as-gp is not worth to do, (e.g., less than 3 times),
12517 1. delete the `la $fp, _FP_BASE_' instruction and
12518 2. not convert lwi.gp to lwi37.fp.
12520 To delete the _FP_BASE_ instruction, we simply apply
12521 R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG flag in the r_addend to disable it.
12523 To suppress the conversion, we simply NOT to apply
12524 R_NDS32_INSN16_FP7U2_FLAG flag. */
12526 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12528 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
12529 || !nds32_get_local_syms (abfd
, sec
, &isymbuf
))
12532 /* Check whether it is worth for fp-as-gp optimization,
12533 i.e., at least 3 gp-load.
12535 Set R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG if we should NOT
12536 apply this optimization. */
12538 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12540 /* We recognize R_NDS32_RELAX_REGION_BEGIN/_END for the region.
12541 One we enter the begin of the region, we track all the LW/ST
12542 instructions, so when we leave the region, we try to find
12543 the best fp-base address for those LW/ST instructions. */
12545 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12546 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12548 /* Begin of the region. */
12550 /* xgettext:c-format */
12551 _bfd_error_handler (_("%B: Nested OMIT_FP in %A."), abfd
, sec
);
12554 nds32_fag_init (&fag_head
);
12555 ifc_inside
= FALSE
;
12557 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12558 && (irel
->r_addend
& R_NDS32_RELAX_REGION_OMIT_FP_FLAG
))
12561 struct nds32_fag
*best_fag
, *tmp_fag
;
12564 /* End of the region.
12565 Check whether it is worth to do fp-as-gp. */
12567 if (begin_rel
== NULL
)
12569 /* xgettext:c-format */
12570 _bfd_error_handler (_("%B: Unmatched OMIT_FP in %A."), abfd
, sec
);
12574 accu
= nds32_fag_find_base (&fag_head
, &best_fag
);
12576 /* Clean FP7U2_FLAG because they may set ever. */
12577 tmp_fag
= fag_head
.next
;
12578 nds32_fag_unmark_relax (tmp_fag
, internal_relocs
, irelend
);
12580 /* Check if it is worth, and FP_BASE is near enough to SDA_BASE. */
12581 if (accu
< FAG_THRESHOLD
12582 || !nds32_fag_mark_relax (link_info
, abfd
, best_fag
,
12583 internal_relocs
, irelend
))
12585 /* Not worth to do fp-as-gp. */
12586 begin_rel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
12587 begin_rel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
12588 irel
->r_addend
|= R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
;
12589 irel
->r_addend
&= ~R_NDS32_RELAX_REGION_OMIT_FP_FLAG
;
12590 nds32_fag_free_list (&fag_head
);
12595 /* R_SYM of R_NDS32_RELAX_REGION_BEGIN is not used by assembler,
12596 so we use it to record the distance to the reloction of best
12598 dist
= best_fag
->relas
[0] - begin_rel
;
12599 BFD_ASSERT (dist
> 0 && dist
< 0xffffff);
12600 /* Use high 16 bits of addend to record the _FP_BASE_ matched
12601 relocation. And get the base value when relocating. */
12602 begin_rel
->r_addend
&= (0x1 << 16) - 1;
12603 begin_rel
->r_addend
|= dist
<< 16;
12605 nds32_fag_free_list (&fag_head
);
12609 if (begin_rel
== NULL
|| ifc_inside
)
12610 /* Skip if we are not in the region of fp-as-gp. */
12613 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S2_RELA
12614 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA17S2_RELA
)
12619 /* A gp-relative access is found. Insert it to the fag-list. */
12621 /* Rt is necessary an RT3, so it can be converted to lwi37.fp. */
12622 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12623 if (!N32_IS_RT3 (insn
))
12626 addr
= calculate_memory_address (abfd
, irel
, isymbuf
, symtab_hdr
);
12627 nds32_fag_insert (&fag_head
, addr
, irel
);
12629 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA_FP7U2_RELA
)
12633 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_17IFC_PCREL_RELA
12634 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
12636 /* Suppress fp as gp when encounter ifc. */
12644 /* Remove unused `la $fp, _FD_BASE_' instruction. */
12647 nds32_fag_remove_unused_fpbase (bfd
*abfd
, asection
*sec
,
12648 Elf_Internal_Rela
*internal_relocs
,
12649 Elf_Internal_Rela
*irelend
)
12651 Elf_Internal_Rela
*irel
;
12652 Elf_Internal_Shdr
*symtab_hdr
;
12653 bfd_byte
*contents
= NULL
;
12654 nds32_elf_blank_t
*relax_blank_list
= NULL
;
12655 bfd_boolean result
= TRUE
;
12656 bfd_boolean unused_region
= FALSE
;
12659 NOTE: Disable fp-as-gp if we encounter ifcall relocations.
12660 * R_NDS32_17IFC_PCREL_RELA
12661 * R_NDS32_10IFCU_PCREL_RELA
12666 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
12667 nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
);
12669 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
12671 /* To remove unused fp-base, we simply find the REGION_NOT_OMIT_FP
12672 we marked to in previous pass.
12673 DO NOT scan relocations again, since we've alreadly decided it
12674 and set the flag. */
12675 const char *syname
;
12679 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
12680 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
12681 unused_region
= TRUE
;
12682 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
12683 && (irel
->r_addend
& R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG
))
12684 unused_region
= FALSE
;
12686 /* We're not in the region. */
12687 if (!unused_region
)
12690 /* _FP_BASE_ must be a GLOBAL symbol. */
12691 syndx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
12692 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
12695 /* The symbol name must be _FP_BASE_. */
12696 syname
= elf_sym_hashes (abfd
)[syndx
]->root
.root
.string
;
12697 if (strcmp (syname
, FP_BASE_NAME
) != 0)
12700 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA19S0_RELA
)
12702 /* addi.gp $fp, -256 */
12703 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12704 if (insn
!= INSN_ADDIGP_TO_FP
)
12707 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_SDA15S0_RELA
)
12709 /* addi $fp, $gp, -256 */
12710 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12711 if (insn
!= INSN_ADDI_GP_TO_FP
)
12714 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_20_RELA
)
12716 /* movi $fp, FP_BASE */
12717 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
12718 if (insn
!= INSN_MOVI_TO_FP
)
12724 /* We got here because a FP_BASE instruction is found. */
12725 if (!insert_nds32_elf_blank_recalc_total
12726 (&relax_blank_list
, irel
->r_offset
, 4))
12731 if (relax_blank_list
)
12733 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
12734 relax_blank_list
= NULL
;
12743 /* This is a version of bfd_generic_get_relocated_section_contents.
12744 We need this variety because relaxation will modify the dwarf
12745 infomation. When there is undefined symbol reference error mesage,
12746 linker need to dump line number where the symbol be used. However
12747 the address is be relaxed, it can not get the original dwarf contents.
12748 The variety only modify function call for reading in the section. */
12751 nds32_elf_get_relocated_section_contents (bfd
*abfd
,
12752 struct bfd_link_info
*link_info
,
12753 struct bfd_link_order
*link_order
,
12755 bfd_boolean relocatable
,
12758 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
12759 asection
*input_section
= link_order
->u
.indirect
.section
;
12761 arelent
**reloc_vector
;
12764 reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
12765 if (reloc_size
< 0)
12768 /* Read in the section. */
12769 if (!nds32_get_section_contents (input_bfd
, input_section
, &data
, FALSE
))
12772 if (reloc_size
== 0)
12775 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
12776 if (reloc_vector
== NULL
)
12779 reloc_count
= bfd_canonicalize_reloc (input_bfd
, input_section
,
12780 reloc_vector
, symbols
);
12781 if (reloc_count
< 0)
12784 if (reloc_count
> 0)
12787 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
12789 char *error_message
= NULL
;
12791 bfd_reloc_status_type r
;
12793 symbol
= *(*parent
)->sym_ptr_ptr
;
12794 if (symbol
->section
&& discarded_section (symbol
->section
))
12797 static reloc_howto_type none_howto
12798 = HOWTO (0, 0, 0, 0, FALSE
, 0, complain_overflow_dont
, NULL
,
12799 "unused", FALSE
, 0, 0, FALSE
);
12801 p
= data
+ (*parent
)->address
* bfd_octets_per_byte (input_bfd
);
12802 _bfd_clear_contents ((*parent
)->howto
, input_bfd
, input_section
,
12804 (*parent
)->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
12805 (*parent
)->addend
= 0;
12806 (*parent
)->howto
= &none_howto
;
12810 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
12812 relocatable
? abfd
: NULL
,
12817 asection
*os
= input_section
->output_section
;
12819 /* A partial link, so keep the relocs. */
12820 os
->orelocation
[os
->reloc_count
] = *parent
;
12824 if (r
!= bfd_reloc_ok
)
12828 case bfd_reloc_undefined
:
12829 (*link_info
->callbacks
->undefined_symbol
)
12830 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12831 input_bfd
, input_section
, (*parent
)->address
, TRUE
);
12833 case bfd_reloc_dangerous
:
12834 BFD_ASSERT (error_message
!= NULL
);
12835 (*link_info
->callbacks
->reloc_dangerous
)
12836 (link_info
, error_message
,
12837 input_bfd
, input_section
, (*parent
)->address
);
12839 case bfd_reloc_overflow
:
12840 (*link_info
->callbacks
->reloc_overflow
)
12842 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
12843 (*parent
)->howto
->name
, (*parent
)->addend
,
12844 input_bfd
, input_section
, (*parent
)->address
);
12846 case bfd_reloc_outofrange
:
12848 This error can result when processing some partially
12849 complete binaries. Do not abort, but issue an error
12850 message instead. */
12851 link_info
->callbacks
->einfo
12852 /* xgettext:c-format */
12853 (_("%X%P: %B(%A): relocation \"%R\" goes out of range\n"),
12854 abfd
, input_section
, * parent
);
12865 free (reloc_vector
);
12869 free (reloc_vector
);
12873 /* Link-time IFC relaxation.
12874 In this optimization, we chains jump instructions
12875 of the same destination with ifcall. */
12878 /* List to save jal and j relocation. */
12879 struct elf_nds32_ifc_symbol_entry
12882 struct elf_link_hash_entry
*h
;
12883 struct elf_nds32_ifc_irel_list
*irel_head
;
12884 unsigned long insn
;
12886 int enable
; /* Apply ifc. */
12887 int ex9_enable
; /* Apply ifc after ex9. */
12888 struct elf_nds32_ifc_symbol_entry
*next
;
12891 struct elf_nds32_ifc_irel_list
12893 Elf_Internal_Rela
*irel
;
12896 /* If this is set, then it is the last instruction for
12897 ifc-chain, so it must be keep for the actual branching. */
12899 struct elf_nds32_ifc_irel_list
*next
;
12902 static struct elf_nds32_ifc_symbol_entry
*ifc_symbol_head
= NULL
;
12904 /* Insert symbol of jal and j for ifc. */
12907 nds32_elf_ifc_insert_symbol (asection
*sec
,
12908 struct elf_link_hash_entry
*h
,
12909 Elf_Internal_Rela
*irel
,
12910 unsigned long insn
)
12912 struct elf_nds32_ifc_symbol_entry
*ptr
= ifc_symbol_head
;
12914 /* Check there is target of existing entry the same as the new one. */
12915 while (ptr
!= NULL
)
12917 if (((h
== NULL
&& ptr
->sec
== sec
12918 && ELF32_R_SYM (ptr
->irel_head
->irel
->r_info
) == ELF32_R_SYM (irel
->r_info
)
12919 && ptr
->irel_head
->irel
->r_addend
== irel
->r_addend
)
12922 && ptr
->insn
== insn
)
12924 /* The same target exist, so insert into list. */
12925 struct elf_nds32_ifc_irel_list
*irel_list
= ptr
->irel_head
;
12927 while (irel_list
->next
!= NULL
)
12928 irel_list
= irel_list
->next
;
12929 irel_list
->next
= bfd_malloc (sizeof (struct elf_nds32_ifc_irel_list
));
12930 irel_list
= irel_list
->next
;
12931 irel_list
->irel
= irel
;
12932 irel_list
->keep
= 1;
12935 irel_list
->sec
= NULL
;
12937 irel_list
->sec
= sec
;
12938 irel_list
->next
= NULL
;
12941 if (ptr
->next
== NULL
)
12946 /* There is no same target entry, so build a new one. */
12947 if (ifc_symbol_head
== NULL
)
12949 ifc_symbol_head
= bfd_malloc (sizeof (struct elf_nds32_ifc_symbol_entry
));
12950 ptr
= ifc_symbol_head
;
12954 ptr
->next
= bfd_malloc (sizeof (struct elf_nds32_ifc_symbol_entry
));
12959 ptr
->irel_head
= bfd_malloc (sizeof (struct elf_nds32_ifc_irel_list
));
12960 ptr
->irel_head
->irel
= irel
;
12962 ptr
->irel_head
->keep
= 1;
12966 /* Local symbols. */
12968 ptr
->irel_head
->sec
= NULL
;
12972 /* Global symbol. */
12974 ptr
->irel_head
->sec
= sec
;
12977 ptr
->irel_head
->next
= NULL
;
12980 ptr
->ex9_enable
= 0;
12984 /* Gather all jal and j instructions. */
12987 nds32_elf_ifc_calc (struct bfd_link_info
*info
,
12988 bfd
*abfd
, asection
*sec
)
12990 Elf_Internal_Rela
*internal_relocs
;
12991 Elf_Internal_Rela
*irelend
;
12992 Elf_Internal_Rela
*irel
;
12993 Elf_Internal_Shdr
*symtab_hdr
;
12994 bfd_byte
*contents
= NULL
;
12995 uint32_t insn
, insn_with_reg
;
12996 unsigned long r_symndx
;
12997 struct elf_link_hash_entry
*h
;
12998 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (abfd
);
12999 struct elf_nds32_link_hash_table
*table
;
13000 bfd_boolean ifc_loop_aware
;
13002 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
13003 TRUE
/* keep_memory */);
13004 irelend
= internal_relocs
+ sec
->reloc_count
;
13005 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
13007 /* Check if the object enable ifc. */
13008 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
, irelend
,
13009 R_NDS32_RELAX_ENTRY
);
13013 || ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
13014 || (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
13015 && !(irel
->r_addend
& R_NDS32_RELAX_ENTRY_IFC_FLAG
)))
13018 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
13021 table
= nds32_elf_hash_table (info
);
13022 ifc_loop_aware
= table
->ifc_loop_aware
;
13023 while (irel
!= NULL
&& irel
< irelend
)
13025 /* Traverse all relocation and gather all of them to build the list. */
13027 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
)
13029 if (ifc_loop_aware
== 1
13030 && (irel
->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
) != 0)
13032 /* Check the region if loop or not. If it is true and
13033 ifc-loop-aware is true, ignore the region till region end. */
13034 while (irel
!= NULL
13036 && (ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_REGION_END
13037 || (irel
->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
) != 0))
13042 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_25_PCREL_RELA
)
13044 insn
= bfd_getb32 (contents
+ irel
->r_offset
);
13045 nds32_elf_get_insn_with_reg (irel
, insn
, &insn_with_reg
);
13046 r_symndx
= ELF32_R_SYM (irel
->r_info
);
13047 if (r_symndx
< symtab_hdr
->sh_info
)
13049 /* Local symbol. */
13050 nds32_elf_ifc_insert_symbol (sec
, NULL
, irel
, insn_with_reg
);
13054 /* External symbol. */
13055 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
13056 nds32_elf_ifc_insert_symbol (sec
, h
, irel
, insn_with_reg
);
13064 /* Determine whether j and jal should be substituted. */
13067 nds32_elf_ifc_filter (struct bfd_link_info
*info
)
13069 struct elf_nds32_ifc_symbol_entry
*ptr
= ifc_symbol_head
;
13070 struct elf_nds32_ifc_irel_list
*irel_ptr
= NULL
;
13071 struct elf_nds32_ifc_irel_list
*irel_keeper
= NULL
;
13072 struct elf_nds32_link_hash_table
*table
;
13073 int target_optimize
;
13076 table
= nds32_elf_hash_table (info
);
13077 target_optimize
= table
->target_optimize
;
13080 irel_ptr
= ptr
->irel_head
;
13081 if (ptr
->h
== NULL
)
13083 /* Local symbol. */
13084 irel_keeper
= irel_ptr
;
13085 while (irel_ptr
&& irel_ptr
->next
)
13087 /* Check there is jump target can be used. */
13088 if ((irel_ptr
->next
->irel
->r_offset
13089 - irel_keeper
->irel
->r_offset
) > 1022)
13090 irel_keeper
= irel_ptr
->next
;
13094 irel_ptr
->keep
= 0;
13096 irel_ptr
= irel_ptr
->next
;
13101 /* Global symbol. */
13102 /* We have to get the absolute address and decide
13103 whether to keep it or not. */
13106 address
= (irel_ptr
->irel
->r_offset
13107 + irel_ptr
->sec
->output_section
->vma
13108 + irel_ptr
->sec
->output_offset
);
13109 irel_ptr
->addr
= address
;
13110 irel_ptr
= irel_ptr
->next
;
13113 irel_ptr
= ptr
->irel_head
;
13116 /* Sort by address. */
13117 struct elf_nds32_ifc_irel_list
*irel_dest
= irel_ptr
;
13118 struct elf_nds32_ifc_irel_list
*irel_temp
= irel_ptr
;
13119 struct elf_nds32_ifc_irel_list
*irel_ptr_prev
= NULL
;
13120 struct elf_nds32_ifc_irel_list
*irel_dest_prev
= NULL
;
13122 /* Get the smallest one. */
13123 while (irel_temp
->next
)
13125 if (irel_temp
->next
->addr
< irel_dest
->addr
)
13127 irel_dest_prev
= irel_temp
;
13128 irel_dest
= irel_temp
->next
;
13130 irel_temp
= irel_temp
->next
;
13133 if (irel_dest
!= irel_ptr
)
13136 irel_ptr_prev
->next
= irel_dest
;
13137 if (irel_dest_prev
)
13138 irel_dest_prev
->next
= irel_ptr
;
13139 irel_temp
= irel_ptr
->next
;
13140 irel_ptr
->next
= irel_dest
->next
;
13141 irel_dest
->next
= irel_temp
;
13143 irel_ptr_prev
= irel_ptr
;
13144 irel_ptr
= irel_ptr
->next
;
13147 irel_ptr
= ptr
->irel_head
;
13148 irel_keeper
= irel_ptr
;
13149 while (irel_ptr
&& irel_ptr
->next
)
13151 if ((irel_ptr
->next
->addr
- irel_keeper
->addr
) > 1022)
13152 irel_keeper
= irel_ptr
->next
;
13156 irel_ptr
->keep
= 0;
13158 irel_ptr
= irel_ptr
->next
;
13162 /* Ex9 enable. Reserve it for ex9. */
13163 if ((target_optimize
& NDS32_RELAX_EX9_ON
)
13164 && ptr
->irel_head
!= irel_keeper
)
13170 /* Determine whether j and jal should be substituted after ex9 done. */
13173 nds32_elf_ifc_filter_after_ex9 (void)
13175 struct elf_nds32_ifc_symbol_entry
*ptr
= ifc_symbol_head
;
13176 struct elf_nds32_ifc_irel_list
*irel_ptr
= NULL
;
13180 if (ptr
->enable
== 0)
13182 /* Check whether ifc is applied or not. */
13183 irel_ptr
= ptr
->irel_head
;
13184 ptr
->ex9_enable
= 1;
13187 if (ELF32_R_TYPE (irel_ptr
->irel
->r_info
) == R_NDS32_TRAN
)
13190 ptr
->ex9_enable
= 0;
13193 irel_ptr
= irel_ptr
->next
;
13200 /* Wrapper to do ifc relaxation. */
13203 nds32_elf_ifc_finish (struct bfd_link_info
*info
)
13206 struct elf_nds32_link_hash_table
*table
;
13208 table
= nds32_elf_hash_table (info
);
13209 relax_status
= table
->relax_status
;
13211 if (!(relax_status
& NDS32_RELAX_JUMP_IFC_DONE
))
13212 nds32_elf_ifc_filter (info
);
13214 nds32_elf_ifc_filter_after_ex9 ();
13216 if (!nds32_elf_ifc_replace (info
))
13220 table
->relax_status
|= NDS32_RELAX_JUMP_IFC_DONE
;
13224 /* Traverse the result of ifc filter and replace it with ifcall9. */
13227 nds32_elf_ifc_replace (struct bfd_link_info
*info
)
13229 struct elf_nds32_ifc_symbol_entry
*ptr
= ifc_symbol_head
;
13230 struct elf_nds32_ifc_irel_list
*irel_ptr
= NULL
;
13231 nds32_elf_blank_t
*relax_blank_list
= NULL
;
13232 bfd_byte
*contents
= NULL
;
13233 Elf_Internal_Rela
*internal_relocs
;
13234 Elf_Internal_Rela
*irel
;
13235 Elf_Internal_Rela
*irelend
;
13236 unsigned short insn16
= INSN_IFCALL9
;
13237 struct elf_nds32_link_hash_table
*table
;
13240 table
= nds32_elf_hash_table (info
);
13241 relax_status
= table
->relax_status
;
13245 /* Traverse the ifc gather list, and replace the
13246 filter entries by ifcall9. */
13247 if ((!(relax_status
& NDS32_RELAX_JUMP_IFC_DONE
) && ptr
->enable
== 1)
13248 || ((relax_status
& NDS32_RELAX_JUMP_IFC_DONE
)
13249 && ptr
->ex9_enable
== 1))
13251 irel_ptr
= ptr
->irel_head
;
13252 if (ptr
->h
== NULL
)
13254 /* Local symbol. */
13255 internal_relocs
= _bfd_elf_link_read_relocs
13256 (ptr
->sec
->owner
, ptr
->sec
, NULL
, NULL
, TRUE
/* keep_memory */);
13257 irelend
= internal_relocs
+ ptr
->sec
->reloc_count
;
13259 if (!nds32_get_section_contents (ptr
->sec
->owner
, ptr
->sec
,
13265 if (irel_ptr
->keep
== 0 && irel_ptr
->next
)
13267 /* The one can be replaced. We have to check whether
13268 there is any alignment point in the region. */
13269 irel
= irel_ptr
->irel
;
13270 while (((irel_ptr
->next
->keep
== 0
13271 && irel
< irel_ptr
->next
->irel
)
13272 || (irel_ptr
->next
->keep
== 1 && irel
< irelend
))
13273 && !(ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
13274 && (irel
->r_addend
& 0x1f) == 2))
13276 if (irel
>= irelend
13277 || !(ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
13278 && (irel
->r_addend
& 0x1f) == 2
13279 && ((irel
->r_offset
- get_nds32_elf_blank_total
13280 (&relax_blank_list
, irel
->r_offset
, 1))
13283 /* Replace by ifcall9. */
13284 bfd_putb16 (insn16
, contents
+ irel_ptr
->irel
->r_offset
);
13285 if (!insert_nds32_elf_blank_recalc_total
13286 (&relax_blank_list
, irel_ptr
->irel
->r_offset
+ 2, 2))
13288 irel_ptr
->irel
->r_info
=
13289 ELF32_R_INFO (ELF32_R_SYM (irel_ptr
->irel
->r_info
),
13290 R_NDS32_10IFCU_PCREL_RELA
);
13293 irel_ptr
= irel_ptr
->next
;
13296 /* Delete the redundant code. */
13297 if (relax_blank_list
)
13299 nds32_elf_relax_delete_blanks (ptr
->sec
->owner
, ptr
->sec
,
13301 relax_blank_list
= NULL
;
13306 /* Global symbol. */
13309 if (irel_ptr
->keep
== 0 && irel_ptr
->next
)
13311 /* The one can be replaced, and we have to check
13312 whether there is any alignment point in the region. */
13313 internal_relocs
= _bfd_elf_link_read_relocs
13314 (irel_ptr
->sec
->owner
, irel_ptr
->sec
, NULL
, NULL
,
13315 TRUE
/* keep_memory */);
13316 irelend
= internal_relocs
+ irel_ptr
->sec
->reloc_count
;
13317 if (!nds32_get_section_contents (irel_ptr
->sec
->owner
,
13318 irel_ptr
->sec
, &contents
,
13322 irel
= irel_ptr
->irel
;
13323 while (((irel_ptr
->sec
== irel_ptr
->next
->sec
13324 && irel_ptr
->next
->keep
== 0
13325 && irel
< irel_ptr
->next
->irel
)
13326 || ((irel_ptr
->sec
!= irel_ptr
->next
->sec
13327 || irel_ptr
->next
->keep
== 1)
13328 && irel
< irelend
))
13329 && !(ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
13330 && (irel
->r_addend
& 0x1f) == 2))
13332 if (irel
>= irelend
13333 || !(ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LABEL
13334 && (irel
->r_addend
& 0x1f) == 2
13335 && ((irel
->r_offset
13336 - get_nds32_elf_blank_total (&relax_blank_list
,
13337 irel
->r_offset
, 1)) & 0x02) == 0))
13339 /* Replace by ifcall9. */
13340 bfd_putb16 (insn16
, contents
+ irel_ptr
->irel
->r_offset
);
13341 if (!insert_nds32_elf_blank_recalc_total
13342 (&relax_blank_list
, irel_ptr
->irel
->r_offset
+ 2, 2))
13345 /* Delete the redundant code, and clear the relocation. */
13346 nds32_elf_relax_delete_blanks (irel_ptr
->sec
->owner
,
13349 irel_ptr
->irel
->r_info
=
13350 ELF32_R_INFO (ELF32_R_SYM (irel_ptr
->irel
->r_info
),
13351 R_NDS32_10IFCU_PCREL_RELA
);
13352 relax_blank_list
= NULL
;
13356 irel_ptr
= irel_ptr
->next
;
13366 /* Relocate ifcall. */
13369 nds32_elf_ifc_reloc (void)
13371 struct elf_nds32_ifc_symbol_entry
*ptr
= ifc_symbol_head
;
13372 struct elf_nds32_ifc_irel_list
*irel_ptr
= NULL
;
13373 struct elf_nds32_ifc_irel_list
*irel_keeper
= NULL
;
13374 bfd_vma relocation
, address
;
13375 unsigned short insn16
;
13376 bfd_byte
*contents
= NULL
;
13377 static bfd_boolean done
= FALSE
;
13386 /* Check the entry is enable ifcall. */
13387 if (ptr
->enable
== 1 || ptr
->ex9_enable
== 1)
13389 /* Get the reserve jump. */
13390 irel_ptr
= ptr
->irel_head
;
13393 if (irel_ptr
->keep
== 1)
13395 irel_keeper
= irel_ptr
;
13398 irel_ptr
= irel_ptr
->next
;
13401 irel_ptr
= ptr
->irel_head
;
13402 if (ptr
->h
== NULL
)
13404 /* Local symbol. */
13405 if (!nds32_get_section_contents (ptr
->sec
->owner
, ptr
->sec
,
13411 if (irel_ptr
->keep
== 0
13412 && ELF32_R_TYPE (irel_ptr
->irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
13414 relocation
= irel_keeper
->irel
->r_offset
;
13415 relocation
= relocation
- irel_ptr
->irel
->r_offset
;
13416 while (irel_keeper
&& relocation
> 1022)
13418 irel_keeper
= irel_keeper
->next
;
13419 if (irel_keeper
&& irel_keeper
->keep
== 1)
13421 relocation
= irel_keeper
->irel
->r_offset
;
13422 relocation
= relocation
- irel_ptr
->irel
->r_offset
;
13425 if (relocation
> 1022)
13427 /* Double check. */
13428 irel_keeper
= ptr
->irel_head
;
13429 while (irel_keeper
)
13431 if (irel_keeper
->keep
== 1)
13433 relocation
= irel_keeper
->irel
->r_offset
;
13434 relocation
= relocation
- irel_ptr
->irel
->r_offset
;
13436 if (relocation
<= 1022)
13438 irel_keeper
= irel_keeper
->next
;
13443 irel_ptr
->irel
->r_info
=
13444 ELF32_R_INFO (ELF32_R_SYM (irel_ptr
->irel
->r_info
),
13446 insn16
= INSN_IFCALL9
| (relocation
>> 1);
13447 bfd_putb16 (insn16
, contents
+ irel_ptr
->irel
->r_offset
);
13449 irel_ptr
= irel_ptr
->next
;
13454 /* Global symbol. */
13457 if (irel_ptr
->keep
== 0
13458 && ELF32_R_TYPE (irel_ptr
->irel
->r_info
) == R_NDS32_10IFCU_PCREL_RELA
)
13460 /* Get the distance between ifcall and jump. */
13461 relocation
= (irel_keeper
->irel
->r_offset
13462 + irel_keeper
->sec
->output_section
->vma
13463 + irel_keeper
->sec
->output_offset
);
13464 address
= (irel_ptr
->irel
->r_offset
13465 + irel_ptr
->sec
->output_section
->vma
13466 + irel_ptr
->sec
->output_offset
);
13467 relocation
= relocation
- address
;
13469 /* The distance is over ragne, find callee again. */
13470 while (irel_keeper
&& relocation
> 1022)
13472 irel_keeper
= irel_keeper
->next
;
13473 if (irel_keeper
&& irel_keeper
->keep
==1)
13475 relocation
= (irel_keeper
->irel
->r_offset
13476 + irel_keeper
->sec
->output_section
->vma
13477 + irel_keeper
->sec
->output_offset
);
13478 relocation
= relocation
- address
;
13482 if (relocation
> 1022)
13484 /* Double check. */
13485 irel_keeper
= ptr
->irel_head
;
13486 while (irel_keeper
)
13488 if (irel_keeper
->keep
== 1)
13491 relocation
= (irel_keeper
->irel
->r_offset
13492 + irel_keeper
->sec
->output_section
->vma
13493 + irel_keeper
->sec
->output_offset
);
13494 relocation
= relocation
- address
;
13496 if (relocation
<= 1022)
13498 irel_keeper
= irel_keeper
->next
;
13503 if (!nds32_get_section_contents
13504 (irel_ptr
->sec
->owner
, irel_ptr
->sec
, &contents
, TRUE
))
13506 insn16
= INSN_IFCALL9
| (relocation
>> 1);
13507 bfd_putb16 (insn16
, contents
+ irel_ptr
->irel
->r_offset
);
13508 irel_ptr
->irel
->r_info
=
13509 ELF32_R_INFO (ELF32_R_SYM (irel_ptr
->irel
->r_info
),
13512 irel_ptr
=irel_ptr
->next
;
13522 /* End of IFC relaxation. */
13524 /* EX9 Instruction Table Relaxation. */
13526 /* Global hash list. */
13527 struct elf_link_hash_entry_list
13529 struct elf_link_hash_entry
*h
;
13530 struct elf_link_hash_entry_list
*next
;
13533 /* Save different destination but same insn. */
13534 struct elf_link_hash_entry_mul_list
13536 /* Global symbol times. */
13538 /* Save relocation for each global symbol but useful?? */
13539 Elf_Internal_Rela
*irel
;
13540 /* For sethi, two sethi may have the same high-part but different low-parts. */
13541 Elf_Internal_Rela rel_backup
;
13542 struct elf_link_hash_entry_list
*h_list
;
13543 struct elf_link_hash_entry_mul_list
*next
;
13546 /* Instruction hash table. */
13547 struct elf_nds32_code_hash_entry
13549 struct bfd_hash_entry root
;
13551 /* For insn that can use relocation or constant ex: sethi. */
13554 struct elf_link_hash_entry_mul_list
*m_list
;
13555 /* Using r_addend. */
13556 Elf_Internal_Rela
*irel
;
13557 /* Using r_info. */
13558 Elf_Internal_Rela rel_backup
;
13561 /* Instruction count list. */
13562 struct elf_nds32_insn_times_entry
13564 const char *string
;
13568 struct elf_link_hash_entry_mul_list
*m_list
;
13569 Elf_Internal_Rela
*irel
;
13570 Elf_Internal_Rela rel_backup
;
13571 struct elf_nds32_insn_times_entry
*next
;
13574 /* J and JAL symbol list. */
13575 struct elf_nds32_symbol_entry
13578 unsigned long insn
;
13579 struct elf_nds32_symbol_entry
*next
;
13582 /* Relocation list. */
13583 struct elf_nds32_irel_entry
13585 Elf_Internal_Rela
*irel
;
13586 struct elf_nds32_irel_entry
*next
;
13589 /* ex9.it insn need to be fixed. */
13590 struct elf_nds32_ex9_refix
13592 Elf_Internal_Rela
*irel
;
13594 struct elf_link_hash_entry
*h
;
13596 struct elf_nds32_ex9_refix
*next
;
13599 static struct bfd_hash_table ex9_code_table
;
13600 static struct elf_nds32_insn_times_entry
*ex9_insn_head
= NULL
;
13601 static struct elf_nds32_ex9_refix
*ex9_refix_head
= NULL
;
13603 /* EX9 hash function. */
13605 static struct bfd_hash_entry
*
13606 nds32_elf_code_hash_newfunc (struct bfd_hash_entry
*entry
,
13607 struct bfd_hash_table
*table
,
13608 const char *string
)
13610 struct elf_nds32_code_hash_entry
*ret
;
13612 /* Allocate the structure if it has not already been allocated by a
13616 entry
= (struct bfd_hash_entry
*)
13617 bfd_hash_allocate (table
, sizeof (*ret
));
13622 /* Call the allocation method of the superclass. */
13623 entry
= bfd_hash_newfunc (entry
, table
, string
);
13627 ret
= (struct elf_nds32_code_hash_entry
*) entry
;
13629 ret
->const_insn
= 0;
13630 ret
->m_list
= NULL
;
13636 /* Insert ex9 entry
13637 this insert must be stable sorted by times. */
13640 nds32_elf_ex9_insert_entry (struct elf_nds32_insn_times_entry
*ptr
)
13642 struct elf_nds32_insn_times_entry
*temp
;
13643 struct elf_nds32_insn_times_entry
*temp2
;
13645 if (ex9_insn_head
== NULL
)
13647 ex9_insn_head
= ptr
;
13652 temp
= ex9_insn_head
;
13653 temp2
= ex9_insn_head
;
13654 while (temp
->next
&&
13655 (temp
->next
->times
>= ptr
->times
13656 || temp
->times
== -1))
13658 if (temp
->times
== -1)
13662 if (ptr
->times
> temp
->times
&& temp
->times
!= -1)
13665 if (temp2
->times
== -1)
13668 ex9_insn_head
= ptr
;
13670 else if (temp
->next
== NULL
)
13677 ptr
->next
= temp
->next
;
13683 /* Examine each insn times in hash table.
13684 Handle multi-link hash entry.
13686 TODO: This function doesn't assign so much info since it is fake. */
13689 nds32_elf_examine_insn_times (struct elf_nds32_code_hash_entry
*h
)
13691 struct elf_nds32_insn_times_entry
*ptr
;
13694 if (h
->m_list
== NULL
)
13696 /* Local symbol insn or insn without relocation. */
13700 ptr
= (struct elf_nds32_insn_times_entry
*)
13701 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13702 ptr
->times
= h
->times
;
13703 ptr
->string
= h
->root
.string
;
13704 ptr
->m_list
= NULL
;
13706 ptr
->irel
= h
->irel
;
13707 ptr
->rel_backup
= h
->rel_backup
;
13708 nds32_elf_ex9_insert_entry (ptr
);
13712 /* Global symbol insn. */
13713 /* Only sethi insn has multiple m_list. */
13714 struct elf_link_hash_entry_mul_list
*m_list
= h
->m_list
;
13719 times
+= m_list
->times
;
13720 m_list
= m_list
->next
;
13724 m_list
= h
->m_list
;
13725 ptr
= (struct elf_nds32_insn_times_entry
*)
13726 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13727 ptr
->times
= times
; /* Use the total times. */
13728 ptr
->string
= h
->root
.string
;
13729 ptr
->m_list
= m_list
;
13731 ptr
->irel
= m_list
->irel
;
13732 ptr
->rel_backup
= m_list
->rel_backup
;
13733 nds32_elf_ex9_insert_entry (ptr
);
13735 if (h
->const_insn
== 1)
13737 /* sethi with constant value. */
13741 ptr
= (struct elf_nds32_insn_times_entry
*)
13742 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13743 ptr
->times
= h
->times
;
13744 ptr
->string
= h
->root
.string
;
13745 ptr
->m_list
= NULL
;
13748 ptr
->rel_backup
= h
->rel_backup
;
13749 nds32_elf_ex9_insert_entry (ptr
);
13755 /* Count each insn times in hash table.
13756 Handle multi-link hash entry. */
13759 nds32_elf_count_insn_times (struct elf_nds32_code_hash_entry
*h
)
13761 int reservation
, times
;
13762 unsigned long relocation
, min_relocation
;
13763 struct elf_nds32_insn_times_entry
*ptr
;
13765 if (h
->m_list
== NULL
)
13767 /* Local symbol insn or insn without relocation. */
13770 ptr
= (struct elf_nds32_insn_times_entry
*)
13771 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13772 ptr
->times
= h
->times
;
13773 ptr
->string
= h
->root
.string
;
13774 ptr
->m_list
= NULL
;
13776 ptr
->irel
= h
->irel
;
13777 ptr
->rel_backup
= h
->rel_backup
;
13778 nds32_elf_ex9_insert_entry (ptr
);
13782 /* Global symbol insn. */
13783 /* Only sethi insn has multiple m_list. */
13784 struct elf_link_hash_entry_mul_list
*m_list
= h
->m_list
;
13786 if (ELF32_R_TYPE (m_list
->rel_backup
.r_info
) == R_NDS32_HI20_RELA
13787 && m_list
->next
!= NULL
)
13789 /* Sethi insn has different symbol or addend but has same hi20. */
13793 min_relocation
= 0xffffffff;
13796 /* Get the minimum sethi address
13797 and calculate how many entry the sethi-list have to use. */
13798 if ((m_list
->h_list
->h
->root
.type
== bfd_link_hash_defined
13799 || m_list
->h_list
->h
->root
.type
== bfd_link_hash_defweak
)
13800 && (m_list
->h_list
->h
->root
.u
.def
.section
!= NULL
13801 && m_list
->h_list
->h
->root
.u
.def
.section
->output_section
!= NULL
))
13803 relocation
= (m_list
->h_list
->h
->root
.u
.def
.value
+
13804 m_list
->h_list
->h
->root
.u
.def
.section
->output_section
->vma
+
13805 m_list
->h_list
->h
->root
.u
.def
.section
->output_offset
);
13806 relocation
+= m_list
->irel
->r_addend
;
13810 if (relocation
< min_relocation
)
13811 min_relocation
= relocation
;
13812 times
+= m_list
->times
;
13813 m_list
= m_list
->next
;
13815 if (min_relocation
< ex9_relax_size
)
13816 reservation
= (min_relocation
>> 12) + 1;
13818 reservation
= (min_relocation
>> 12)
13819 - ((min_relocation
- ex9_relax_size
) >> 12) + 1;
13820 if (reservation
< (times
/ 3))
13822 /* Efficient enough to use ex9. */
13825 for (i
= reservation
; i
> 0; i
--)
13827 /* Allocate number of reservation ex9 entry. */
13828 ptr
= (struct elf_nds32_insn_times_entry
*)
13829 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13830 ptr
->times
= h
->m_list
->times
/ reservation
;
13831 ptr
->string
= h
->root
.string
;
13832 ptr
->m_list
= h
->m_list
;
13834 ptr
->irel
= h
->m_list
->irel
;
13835 ptr
->rel_backup
= h
->m_list
->rel_backup
;
13836 nds32_elf_ex9_insert_entry (ptr
);
13842 /* Normal global symbol that means no different address symbol
13843 using same ex9 entry. */
13844 if (m_list
->times
>= 3)
13846 ptr
= (struct elf_nds32_insn_times_entry
*)
13847 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13848 ptr
->times
= m_list
->times
;
13849 ptr
->string
= h
->root
.string
;
13850 ptr
->m_list
= h
->m_list
;
13852 ptr
->irel
= h
->m_list
->irel
;
13853 ptr
->rel_backup
= h
->m_list
->rel_backup
;
13854 nds32_elf_ex9_insert_entry (ptr
);
13858 if (h
->const_insn
== 1)
13860 /* sethi with constant value. */
13864 ptr
= (struct elf_nds32_insn_times_entry
*)
13865 bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
13866 ptr
->times
= h
->times
;
13867 ptr
->string
= h
->root
.string
;
13868 ptr
->m_list
= NULL
;
13871 ptr
->rel_backup
= h
->rel_backup
;
13872 nds32_elf_ex9_insert_entry (ptr
);
13879 /* Hash table traverse function. */
13882 nds32_elf_code_hash_traverse (int (*func
) (struct elf_nds32_code_hash_entry
*))
13886 ex9_code_table
.frozen
= 1;
13887 for (i
= 0; i
< ex9_code_table
.size
; i
++)
13889 struct bfd_hash_entry
*p
;
13891 for (p
= ex9_code_table
.table
[i
]; p
!= NULL
; p
= p
->next
)
13892 if (!func ((struct elf_nds32_code_hash_entry
*) p
))
13896 ex9_code_table
.frozen
= 0;
13900 /* Give order number to insn list. */
13903 nds32_elf_order_insn_times (struct bfd_link_info
*info
)
13905 struct elf_nds32_insn_times_entry
*ex9_insn
;
13906 struct elf_nds32_insn_times_entry
*temp
= NULL
;
13907 struct elf_nds32_link_hash_table
*table
;
13911 if (ex9_insn_head
== NULL
)
13914 /* The max number of entries is 512. */
13915 ex9_insn
= ex9_insn_head
;
13916 table
= nds32_elf_hash_table (info
);
13917 ex9_limit
= table
->ex9_limit
;
13919 ex9_insn
= ex9_insn_head
;
13921 while (ex9_insn
!= NULL
&& number
< ex9_limit
)
13923 ex9_insn
->order
= number
;
13926 ex9_insn
= ex9_insn
->next
;
13929 if (ex9_insn
&& temp
)
13932 while (ex9_insn
!= NULL
)
13934 /* Free useless entry. */
13936 ex9_insn
= ex9_insn
->next
;
13941 /* Build .ex9.itable section. */
13944 nds32_elf_ex9_build_itable (struct bfd_link_info
*link_info
)
13946 asection
*table_sec
;
13947 struct elf_nds32_insn_times_entry
*ptr
;
13950 bfd_byte
*contents
= NULL
;
13952 for (it_abfd
= link_info
->input_bfds
; it_abfd
!= NULL
;
13953 it_abfd
= it_abfd
->link
.next
)
13955 /* Find the section .ex9.itable, and put all entries into it. */
13956 table_sec
= bfd_get_section_by_name (it_abfd
, ".ex9.itable");
13957 if (table_sec
!= NULL
)
13959 if (!nds32_get_section_contents (it_abfd
, table_sec
, &contents
, TRUE
))
13962 for (ptr
= ex9_insn_head
; ptr
!=NULL
; ptr
= ptr
->next
)
13965 table_sec
->size
= number
* 4;
13970 elf_elfheader (link_info
->output_bfd
)->e_flags
|= E_NDS32_HAS_EX9_INST
;
13972 for (ptr
= ex9_insn_head
; ptr
!=NULL
; ptr
= ptr
->next
)
13976 val
= strtol (ptr
->string
, NULL
, 16);
13977 bfd_putb32 ((bfd_vma
) val
, (char *) contents
+ (number
* 4));
13985 /* Get insn with regs according to relocation type. */
13988 nds32_elf_get_insn_with_reg (Elf_Internal_Rela
*irel
,
13989 uint32_t insn
, uint32_t *insn_with_reg
)
13991 reloc_howto_type
*howto
= NULL
;
13994 || (ELF32_R_TYPE (irel
->r_info
) >= (int) ARRAY_SIZE (nds32_elf_howto_table
)
13995 && (ELF32_R_TYPE (irel
->r_info
) - R_NDS32_RELAX_ENTRY
)
13996 >= (int) ARRAY_SIZE (nds32_elf_relax_howto_table
)))
13998 *insn_with_reg
= insn
;
14002 howto
= bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (irel
->r_info
));
14003 *insn_with_reg
= insn
& (0xffffffff ^ howto
->dst_mask
);
14006 /* Mask number of address bits according to relocation. */
14008 static unsigned long
14009 nds32_elf_irel_mask (Elf_Internal_Rela
*irel
)
14011 reloc_howto_type
*howto
= NULL
;
14014 || (ELF32_R_TYPE (irel
->r_info
) >= (int) ARRAY_SIZE (nds32_elf_howto_table
)
14015 && (ELF32_R_TYPE (irel
->r_info
) - R_NDS32_RELAX_ENTRY
)
14016 >= (int) ARRAY_SIZE (nds32_elf_relax_howto_table
)))
14019 howto
= bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (irel
->r_info
));
14020 return howto
->dst_mask
;
14024 nds32_elf_insert_irel_entry (struct elf_nds32_irel_entry
**irel_list
,
14025 struct elf_nds32_irel_entry
*irel_ptr
)
14027 if (*irel_list
== NULL
)
14029 *irel_list
= irel_ptr
;
14030 irel_ptr
->next
= NULL
;
14034 irel_ptr
->next
= *irel_list
;
14035 *irel_list
= irel_ptr
;
14040 nds32_elf_ex9_insert_fix (asection
* sec
, Elf_Internal_Rela
* irel
,
14041 struct elf_link_hash_entry
*h
, int order
)
14043 struct elf_nds32_ex9_refix
*ptr
;
14045 ptr
= bfd_malloc (sizeof (struct elf_nds32_ex9_refix
));
14049 ptr
->order
= order
;
14052 if (ex9_refix_head
== NULL
)
14053 ex9_refix_head
= ptr
;
14056 struct elf_nds32_ex9_refix
*temp
= ex9_refix_head
;
14058 while (temp
->next
!= NULL
)
14067 CLEAN_PRE
= 1 << 1,
14071 /* Check relocation type if supporting for ex9. */
14074 nds32_elf_ex9_relocation_check (struct bfd_link_info
*info
,
14075 Elf_Internal_Rela
**irel
,
14076 Elf_Internal_Rela
*irelend
,
14077 nds32_elf_blank_t
*relax_blank_list
,
14078 asection
*sec
,bfd_vma
*off
,
14079 bfd_byte
*contents
)
14081 /* Suppress ex9 if `.no_relax ex9' or inner loop. */
14082 bfd_boolean nested_ex9
, nested_loop
;
14083 bfd_boolean ex9_loop_aware
;
14084 /* We use the highest 1 byte of result to record
14085 how many bytes location counter has to move. */
14087 Elf_Internal_Rela
*irel_save
= NULL
;
14088 struct elf_nds32_link_hash_table
*table
;
14090 table
= nds32_elf_hash_table (info
);
14091 ex9_loop_aware
= table
->ex9_loop_aware
;
14093 while ((*irel
) != NULL
&& (*irel
) < irelend
&& *off
== (*irel
)->r_offset
)
14095 switch (ELF32_R_TYPE ((*irel
)->r_info
))
14097 case R_NDS32_RELAX_REGION_BEGIN
:
14098 /* Ignore code block. */
14099 nested_ex9
= FALSE
;
14100 nested_loop
= FALSE
;
14101 if (((*irel
)->r_addend
& R_NDS32_RELAX_REGION_NO_EX9_FLAG
)
14103 && ((*irel
)->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
)))
14105 /* Check the region if loop or not. If it is true and
14106 ex9-loop-aware is true, ignore the region till region end. */
14107 /* To save the status for in .no_relax ex9 region and
14108 loop region to conform the block can do ex9 relaxation. */
14109 nested_ex9
= ((*irel
)->r_addend
& R_NDS32_RELAX_REGION_NO_EX9_FLAG
);
14110 nested_loop
= (ex9_loop_aware
14111 && ((*irel
)->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
));
14112 while ((*irel
) && (*irel
) < irelend
&& (nested_ex9
|| nested_loop
))
14115 if (ELF32_R_TYPE ((*irel
)->r_info
) == R_NDS32_RELAX_REGION_BEGIN
)
14117 /* There may be nested region. */
14118 if (((*irel
)->r_addend
& R_NDS32_RELAX_REGION_NO_EX9_FLAG
) != 0)
14120 else if (ex9_loop_aware
14121 && ((*irel
)->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
))
14122 nested_loop
= TRUE
;
14124 else if (ELF32_R_TYPE ((*irel
)->r_info
) == R_NDS32_RELAX_REGION_END
)
14126 /* The end of region. */
14127 if (((*irel
)->r_addend
& R_NDS32_RELAX_REGION_NO_EX9_FLAG
) != 0)
14128 nested_ex9
= FALSE
;
14129 else if (ex9_loop_aware
14130 && ((*irel
)->r_addend
& R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG
))
14131 nested_loop
= FALSE
;
14133 else if (ELF32_R_TYPE ((*irel
)->r_info
) == R_NDS32_LABEL
14134 && ((*irel
)->r_addend
& 0x1f) == 2)
14136 /* Alignment exist in the region. */
14137 result
|= CLEAN_PRE
;
14138 if (((*irel
)->r_offset
-
14139 get_nds32_elf_blank_total (&relax_blank_list
,
14140 (*irel
)->r_offset
, 0)) & 0x02)
14141 result
|= PUSH_PRE
;
14144 if ((*irel
) >= irelend
)
14147 *off
= (*irel
)->r_offset
;
14149 /* The final instruction in the region, regard this one as data to ignore it. */
14150 result
|= DATA_EXIST
;
14155 case R_NDS32_LABEL
:
14156 if (((*irel
)->r_addend
& 0x1f) == 2)
14158 /* Check this point is align and decide to do ex9 or not. */
14159 result
|= CLEAN_PRE
;
14160 if (((*irel
)->r_offset
-
14161 get_nds32_elf_blank_total (&relax_blank_list
,
14162 (*irel
)->r_offset
, 0)) & 0x02)
14163 result
|= PUSH_PRE
;
14166 case R_NDS32_32_RELA
:
14168 result
|= (4 << 24);
14169 result
|= DATA_EXIST
;
14171 case R_NDS32_16_RELA
:
14173 result
|= (2 << 24);
14174 result
|= DATA_EXIST
;
14178 /* The least code alignment is 2. If the data is only one byte,
14179 we have to shift one more byte. */
14180 if ((*irel
)->r_addend
== 1)
14181 result
|= ((*irel
)->r_addend
<< 25) ;
14183 result
|= ((*irel
)->r_addend
<< 24) ;
14185 result
|= DATA_EXIST
;
14188 case R_NDS32_25_PCREL_RELA
:
14189 case R_NDS32_SDA16S3_RELA
:
14190 case R_NDS32_SDA15S3_RELA
:
14191 case R_NDS32_SDA15S3
:
14192 case R_NDS32_SDA17S2_RELA
:
14193 case R_NDS32_SDA15S2_RELA
:
14194 case R_NDS32_SDA12S2_SP_RELA
:
14195 case R_NDS32_SDA12S2_DP_RELA
:
14196 case R_NDS32_SDA15S2
:
14197 case R_NDS32_SDA18S1_RELA
:
14198 case R_NDS32_SDA15S1_RELA
:
14199 case R_NDS32_SDA15S1
:
14200 case R_NDS32_SDA19S0_RELA
:
14201 case R_NDS32_SDA15S0_RELA
:
14202 case R_NDS32_SDA15S0
:
14203 case R_NDS32_HI20_RELA
:
14204 case R_NDS32_LO12S0_ORI_RELA
:
14205 case R_NDS32_LO12S0_RELA
:
14206 case R_NDS32_LO12S1_RELA
:
14207 case R_NDS32_LO12S2_RELA
:
14208 /* These relocation is supported ex9 relaxation currently. */
14209 /* We have to save the relocation for using later, since we have
14210 to check there is any alignment in the same address. */
14214 /* Not support relocations. */
14215 if (ELF32_R_TYPE ((*irel
)->r_info
) < ARRAY_SIZE (nds32_elf_howto_table
)
14216 && ELF32_R_TYPE ((*irel
)->r_info
) != R_NDS32_NONE
14217 && ELF32_R_TYPE ((*irel
)->r_info
) != R_NDS32_INSN16
)
14219 /* Note: To optimize aggressively, it maybe can ignore R_NDS32_INSN16 here.
14220 But we have to consider if there is any side-effect. */
14221 if (!(result
& DATA_EXIST
))
14223 /* We have to confirm there is no data relocation in the
14224 same address. In general case, this won't happen. */
14225 /* We have to do ex9 conservative, for those relocation not
14226 considerd we ignore instruction. */
14227 result
|= DATA_EXIST
;
14228 if (*(contents
+ *off
) & 0x80)
14229 result
|= (2 << 24);
14231 result
|= (4 << 24);
14236 if ((*irel
) < irelend
14237 && ((*irel
) + 1) < irelend
14238 && (*irel
)->r_offset
== ((*irel
) + 1)->r_offset
)
14239 /* There are relocations pointing to the same address, we have to
14240 check all of them. */
14252 /* Replace with ex9 instruction. */
14255 nds32_elf_ex9_push_insn (uint16_t insn16
, bfd_byte
*contents
, bfd_vma pre_off
,
14256 nds32_elf_blank_t
**relax_blank_list
,
14257 struct elf_nds32_irel_entry
*pre_irel_ptr
,
14258 struct elf_nds32_irel_entry
**irel_list
)
14262 /* Implement the ex9 relaxation. */
14263 bfd_putb16 (insn16
, contents
+ pre_off
);
14264 if (!insert_nds32_elf_blank_recalc_total (relax_blank_list
,
14267 if (pre_irel_ptr
!= NULL
)
14268 nds32_elf_insert_irel_entry (irel_list
, pre_irel_ptr
);
14273 /* Replace input file instruction which is in ex9 itable. */
14276 nds32_elf_ex9_replace_instruction (struct bfd_link_info
*info
, bfd
*abfd
, asection
*sec
)
14278 struct elf_nds32_insn_times_entry
*ex9_insn
= ex9_insn_head
;
14279 bfd_byte
*contents
= NULL
;
14281 uint16_t insn16
, insn_ex9
;
14282 /* `pre_*' are used to track previous instruction that can use ex9.it. */
14283 bfd_vma pre_off
= -1;
14284 uint16_t pre_insn16
= 0;
14285 struct elf_nds32_irel_entry
*pre_irel_ptr
= NULL
;
14286 Elf_Internal_Rela
*internal_relocs
;
14287 Elf_Internal_Rela
*irel
;
14288 Elf_Internal_Rela
*irelend
;
14289 Elf_Internal_Shdr
*symtab_hdr
;
14290 Elf_Internal_Sym
*isym
= NULL
;
14291 nds32_elf_blank_t
*relax_blank_list
= NULL
;
14293 uint32_t insn_with_reg
= 0;
14295 uint32_t it_insn_with_reg
;
14296 unsigned long r_symndx
;
14298 struct elf_nds32_irel_entry
*irel_list
= NULL
;
14299 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (abfd
);
14300 int data_flag
, do_replace
, save_irel
;
14301 struct elf_link_hash_entry_list
*h_list
;
14304 /* Load section instructions, relocations, and symbol table. */
14305 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
)
14306 || !nds32_get_local_syms (abfd
, sec
, &isym
))
14309 _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, TRUE
/* keep_memory */);
14310 irelend
= internal_relocs
+ sec
->reloc_count
;
14311 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
14315 /* Check if the object enable ex9. */
14316 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
,
14317 irelend
, R_NDS32_RELAX_ENTRY
);
14319 /* Check this section trigger ex9 relaxation. */
14322 || ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
14323 || (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
14324 && !(irel
->r_addend
& R_NDS32_RELAX_ENTRY_EX9_FLAG
)))
14327 irel
= internal_relocs
;
14329 /* Check alignment and fetch proper relocation. */
14330 while (off
< sec
->size
)
14332 struct elf_link_hash_entry
*h
= NULL
;
14333 struct elf_nds32_irel_entry
*irel_ptr
= NULL
;
14335 /* Syn the instruction and the relocation. */
14336 while (irel
!= NULL
&& irel
< irelend
&& irel
->r_offset
< off
)
14339 data_flag
= nds32_elf_ex9_relocation_check (info
, &irel
, irelend
,
14340 relax_blank_list
, sec
,
14342 if (data_flag
& PUSH_PRE
)
14343 if (!nds32_elf_ex9_push_insn (pre_insn16
, contents
, pre_off
,
14344 &relax_blank_list
, pre_irel_ptr
,
14348 if (data_flag
& CLEAN_PRE
)
14352 pre_irel_ptr
= NULL
;
14354 if (data_flag
& DATA_EXIST
)
14356 /* We save the move offset in the highest byte. */
14357 off
+= (data_flag
>> 24);
14361 if (*(contents
+ off
) & 0x80)
14363 /* 2-byte instruction. */
14368 /* Load the instruction and its opcode with register for comparing. */
14369 ex9_insn
= ex9_insn_head
;
14370 insn
= bfd_getb32 (contents
+ off
);
14374 it_insn
= strtol (ex9_insn
->string
, NULL
, 16);
14375 it_insn_with_reg
= 0;
14379 if (irel
!= NULL
&& irel
< irelend
&& irel
->r_offset
== off
)
14381 /* Insn with relocation. */
14382 nds32_elf_get_insn_with_reg (irel
, insn
, &insn_with_reg
);
14384 if (ex9_insn
->irel
!= NULL
)
14385 nds32_elf_get_insn_with_reg (ex9_insn
->irel
, it_insn
,
14386 &it_insn_with_reg
);
14388 if (ex9_insn
->irel
!= NULL
14389 && (ELF32_R_TYPE (irel
->r_info
) ==
14390 ELF32_R_TYPE (ex9_insn
->irel
->r_info
))
14391 && (insn_with_reg
== it_insn_with_reg
))
14393 /* Insn relocation and format is the same as table entry. */
14395 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_25_PCREL_RELA
14396 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S0_ORI_RELA
14397 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S0_RELA
14398 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S1_RELA
14399 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_RELA
14400 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3
14401 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0
)
14402 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3_RELA
14403 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0_RELA
)
14404 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA12S2_DP_RELA
14405 && ELF32_R_TYPE (irel
->r_info
) <=
14406 R_NDS32_SDA12S2_SP_RELA
)
14407 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA16S3_RELA
14408 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA19S0_RELA
))
14410 r_symndx
= ELF32_R_SYM (irel
->r_info
);
14411 if (r_symndx
< symtab_hdr
->sh_info
)
14413 /* Local symbol. */
14414 int shndx
= isym
[r_symndx
].st_shndx
;
14416 isec
= elf_elfsections (abfd
)[shndx
]->bfd_section
;
14417 if (ex9_insn
->sec
== isec
14418 && ex9_insn
->irel
->r_addend
== irel
->r_addend
14419 && ex9_insn
->irel
->r_info
== irel
->r_info
)
14427 /* External symbol. */
14428 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
14429 if (ex9_insn
->m_list
)
14431 h_list
= ex9_insn
->m_list
->h_list
;
14435 && (ex9_insn
->m_list
->irel
->r_addend
==
14442 h_list
= h_list
->next
;
14447 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_HI20_RELA
)
14449 r_symndx
= ELF32_R_SYM (irel
->r_info
);
14450 if (r_symndx
< symtab_hdr
->sh_info
)
14452 /* Local symbols. Compare its base symbol and offset. */
14453 int shndx
= isym
[r_symndx
].st_shndx
;
14455 isec
= elf_elfsections (abfd
)[shndx
]->bfd_section
;
14456 if (ex9_insn
->sec
== isec
14457 && ex9_insn
->irel
->r_addend
== irel
->r_addend
14458 && ex9_insn
->irel
->r_info
== irel
->r_info
)
14466 /* External symbol. */
14467 struct elf_link_hash_entry_mul_list
*m_list
;
14469 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
14470 m_list
= ex9_insn
->m_list
;
14474 h_list
= m_list
->h_list
;
14479 && (m_list
->irel
->r_addend
14480 == irel
->r_addend
))
14485 && ex9_insn
->m_list
14486 && ex9_insn
->m_list
== ex9_insn
->next
->m_list
)
14488 /* sethi multiple entry must be fixed */
14489 nds32_elf_ex9_insert_fix (sec
, irel
,
14490 h
, ex9_insn
->order
);
14494 h_list
= h_list
->next
;
14496 m_list
= m_list
->next
;
14502 /* Import table: Check the symbol hash table and the
14503 jump target. Only R_NDS32_25_PCREL_RELA now. */
14504 else if (ex9_insn
->times
== -1
14505 && ELF32_R_TYPE (irel
->r_info
) == R_NDS32_25_PCREL_RELA
)
14507 nds32_elf_get_insn_with_reg (irel
, it_insn
, &it_insn_with_reg
);
14508 if (insn_with_reg
== it_insn_with_reg
)
14511 bfd_vma relocation
;
14513 r_symndx
= ELF32_R_SYM (irel
->r_info
);
14514 if (r_symndx
>= symtab_hdr
->sh_info
)
14516 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
14517 if ((h
->root
.type
== bfd_link_hash_defined
14518 || h
->root
.type
== bfd_link_hash_defweak
)
14519 && h
->root
.u
.def
.section
!= NULL
14520 && h
->root
.u
.def
.section
->output_section
!= NULL
14521 && h
->root
.u
.def
.section
->gc_mark
== 1
14522 && bfd_is_abs_section (h
->root
.u
.def
.section
)
14523 && h
->root
.u
.def
.value
> sec
->size
)
14525 relocation
= h
->root
.u
.def
.value
+
14526 h
->root
.u
.def
.section
->output_section
->vma
+
14527 h
->root
.u
.def
.section
->output_offset
;
14528 relocation
+= irel
->r_addend
;
14529 insn
= insn_with_reg
14530 | ((relocation
>> 1) & 0xffffff);
14531 snprintf (code
, sizeof (code
), "%08x", insn
);
14532 if (strcmp (code
, ex9_insn
->string
) == 0)
14541 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
14542 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
14543 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
14545 /* These relocations do not have to relocate contens, so it can
14546 be regard as instruction without relocation. */
14547 if (insn
== it_insn
&& ex9_insn
->irel
== NULL
)
14553 /* Instruction without relocation, we only
14554 have to compare their byte code. */
14555 if (insn
== it_insn
&& ex9_insn
->irel
== NULL
)
14559 /* Insntruction match so replacing the code here. */
14560 if (do_replace
== 1)
14562 /* There are two formats of ex9 instruction. */
14563 if (ex9_insn
->order
< 32)
14564 insn_ex9
= INSN_EX9_IT_2
;
14566 insn_ex9
= INSN_EX9_IT_1
;
14567 insn16
= insn_ex9
| ex9_insn
->order
;
14569 /* Insert ex9 instruction. */
14570 nds32_elf_ex9_push_insn (pre_insn16
, contents
, pre_off
,
14571 &relax_blank_list
, pre_irel_ptr
,
14574 pre_insn16
= insn16
;
14578 /* For instuction with relocation do relax. */
14579 irel_ptr
= (struct elf_nds32_irel_entry
*)
14580 bfd_malloc (sizeof (struct elf_nds32_irel_entry
));
14581 irel_ptr
->irel
= irel
;
14582 irel_ptr
->next
= NULL
;
14583 pre_irel_ptr
= irel_ptr
;
14586 pre_irel_ptr
= NULL
;
14589 ex9_insn
= ex9_insn
->next
;
14594 /* Insert ex9 instruction. */
14595 nds32_elf_ex9_push_insn (pre_insn16
, contents
, pre_off
,
14596 &relax_blank_list
, pre_irel_ptr
,
14599 /* Delete the redundant code. */
14600 if (relax_blank_list
)
14602 nds32_elf_relax_delete_blanks (abfd
, sec
, relax_blank_list
);
14603 relax_blank_list
= NULL
;
14606 /* Clear the relocation that is replaced by ex9. */
14609 struct elf_nds32_irel_entry
*irel_ptr
;
14611 irel_ptr
= irel_list
;
14612 irel_list
= irel_ptr
->next
;
14613 irel_ptr
->irel
->r_info
=
14614 ELF32_R_INFO (ELF32_R_SYM (irel_ptr
->irel
->r_info
), R_NDS32_TRAN
);
14620 /* Initialize ex9 hash table. */
14623 nds32_elf_ex9_init (void)
14625 if (!bfd_hash_table_init_n (&ex9_code_table
, nds32_elf_code_hash_newfunc
,
14626 sizeof (struct elf_nds32_code_hash_entry
),
14629 _bfd_error_handler (_("Linker: cannot init ex9 hash table error \n"));
14635 /* Predict how many bytes will be relaxed with ex9 and ifc. */
14638 nds32_elf_ex9_total_relax (struct bfd_link_info
*info
)
14640 struct elf_nds32_insn_times_entry
*ex9_insn
;
14641 struct elf_nds32_insn_times_entry
*temp
;
14642 int target_optimize
;
14643 struct elf_nds32_link_hash_table
*table
;
14645 if (ex9_insn_head
== NULL
)
14648 table
= nds32_elf_hash_table (info
);
14649 target_optimize
= table
->target_optimize
;
14650 ex9_insn
= ex9_insn_head
;
14653 ex9_relax_size
= ex9_insn
->times
* 2 + ex9_relax_size
;
14655 ex9_insn
= ex9_insn
->next
;
14658 ex9_insn_head
= NULL
;
14660 if ((target_optimize
& NDS32_RELAX_JUMP_IFC_ON
))
14662 /* Examine ifc reduce size. */
14663 struct elf_nds32_ifc_symbol_entry
*ifc_ent
= ifc_symbol_head
;
14664 struct elf_nds32_ifc_irel_list
*irel_ptr
= NULL
;
14669 if (ifc_ent
->enable
== 0)
14672 irel_ptr
= ifc_ent
->irel_head
;
14676 irel_ptr
= irel_ptr
->next
;
14680 ifc_ent
= ifc_ent
->next
;
14682 ex9_relax_size
+= size
;
14686 /* Finish ex9 table. */
14689 nds32_elf_ex9_finish (struct bfd_link_info
*link_info
)
14691 nds32_elf_code_hash_traverse (nds32_elf_examine_insn_times
);
14692 nds32_elf_order_insn_times (link_info
);
14693 nds32_elf_ex9_total_relax (link_info
);
14694 /* Traverse the hash table and count its times. */
14695 nds32_elf_code_hash_traverse (nds32_elf_count_insn_times
);
14696 nds32_elf_order_insn_times (link_info
);
14697 nds32_elf_ex9_build_itable (link_info
);
14700 /* Relocate the entries in ex9 table. */
14703 nds32_elf_ex9_reloc_insn (struct elf_nds32_insn_times_entry
*ptr
,
14704 struct bfd_link_info
*link_info
)
14706 Elf_Internal_Sym
*isym
= NULL
;
14707 bfd_vma relocation
= -1;
14708 struct elf_link_hash_entry
*h
;
14710 if (ptr
->m_list
!= NULL
)
14712 /* Global symbol. */
14713 h
= ptr
->m_list
->h_list
->h
;
14714 if ((h
->root
.type
== bfd_link_hash_defined
14715 || h
->root
.type
== bfd_link_hash_defweak
)
14716 && h
->root
.u
.def
.section
!= NULL
14717 && h
->root
.u
.def
.section
->output_section
!= NULL
)
14720 relocation
= h
->root
.u
.def
.value
+
14721 h
->root
.u
.def
.section
->output_section
->vma
+
14722 h
->root
.u
.def
.section
->output_offset
;
14723 relocation
+= ptr
->m_list
->irel
->r_addend
;
14728 else if (ptr
->sec
!=NULL
)
14730 /* Local symbol. */
14731 Elf_Internal_Sym sym
;
14732 asection
*sec
= NULL
;
14734 asection
*isec_ptr
= &isec
;
14735 Elf_Internal_Rela irel_backup
= *(ptr
->irel
);
14736 asection
*sec_backup
= ptr
->sec
;
14737 bfd
*abfd
= ptr
->sec
->owner
;
14739 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
14741 isym
= isym
+ ELF32_R_SYM (ptr
->irel
->r_info
);
14743 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
14748 /* The purpose is same as elf_link_input_bfd. */
14749 if (isec_ptr
!= NULL
14750 && isec_ptr
->sec_info_type
== SEC_INFO_TYPE_MERGE
14751 && ELF_ST_TYPE (isym
->st_info
) != STT_SECTION
)
14754 _bfd_merged_section_offset (ptr
->sec
->output_section
->owner
, &isec_ptr
,
14755 elf_section_data (isec_ptr
)->sec_info
,
14758 relocation
= _bfd_elf_rela_local_sym (link_info
->output_bfd
, &sym
,
14759 &ptr
->sec
, ptr
->irel
);
14760 if (ptr
->irel
!= NULL
)
14761 relocation
+= ptr
->irel
->r_addend
;
14763 /* Restore origin value since there may be some insntructions that
14764 could not be replaced with ex9.it. */
14765 *(ptr
->irel
) = irel_backup
;
14766 ptr
->sec
= sec_backup
;
14772 /* Import ex9 table and build list. */
14775 nds32_elf_ex9_import_table (struct bfd_link_info
*info
)
14778 bfd_byte
*contents
;
14779 FILE *ex9_import_file
;
14780 int update_ex9_table
;
14781 struct elf_nds32_link_hash_table
*table
;
14783 table
= nds32_elf_hash_table (info
);
14784 ex9_import_file
= table
->ex9_import_file
;
14785 rewind (table
->ex9_import_file
);
14787 contents
= bfd_malloc (sizeof (bfd_byte
) * 4);
14789 /* Read instructions from the input file and build the list. */
14790 while (!feof (ex9_import_file
))
14792 unsigned long insn
;
14794 struct elf_nds32_insn_times_entry
*ptr
;
14797 nread
= fread (contents
, sizeof (bfd_byte
) * 4, 1, ex9_import_file
);
14798 /* Ignore the final byte 0x0a. */
14801 insn
= bfd_getb32 (contents
);
14802 code
= bfd_malloc (sizeof (char) * 9);
14803 snprintf (code
, 9, "%08lx", (insn
& 0xffffffff));
14804 ptr
= bfd_malloc (sizeof (struct elf_nds32_insn_times_entry
));
14805 ptr
->string
= code
;
14809 ptr
->m_list
= NULL
;
14810 ptr
->rel_backup
.r_offset
= 0;
14811 ptr
->rel_backup
.r_info
= 0;
14812 ptr
->rel_backup
.r_addend
= 0;
14815 nds32_elf_ex9_insert_entry (ptr
);
14819 update_ex9_table
= table
->update_ex9_table
;
14820 if (update_ex9_table
== 1)
14822 /* It has to consider of sethi need to use multiple page
14823 but it not be done yet. */
14824 nds32_elf_code_hash_traverse (nds32_elf_examine_insn_times
);
14825 nds32_elf_order_insn_times (info
);
14829 /* Export ex9 table. */
14832 nds32_elf_ex9_export (struct bfd_link_info
*info
,
14833 bfd_byte
*contents
, int size
)
14835 FILE *ex9_export_file
;
14836 struct elf_nds32_link_hash_table
*table
;
14838 table
= nds32_elf_hash_table (info
);
14839 ex9_export_file
= table
->ex9_export_file
;
14840 fwrite (contents
, sizeof (bfd_byte
), size
, ex9_export_file
);
14841 fclose (ex9_export_file
);
14844 /* Adjust relocations of J and JAL in ex9.itable.
14845 Export ex9 table. */
14848 nds32_elf_ex9_reloc_jmp (struct bfd_link_info
*link_info
)
14850 asection
*table_sec
= NULL
;
14851 struct elf_nds32_insn_times_entry
*ex9_insn
= ex9_insn_head
;
14852 struct elf_nds32_insn_times_entry
*temp_ptr
, *temp_ptr2
;
14854 uint32_t insn
, insn_with_reg
, source_insn
;
14855 bfd_byte
*contents
= NULL
, *source_contents
= NULL
;
14858 int shift
, update_ex9_table
, offset
= 0;
14859 reloc_howto_type
*howto
= NULL
;
14860 Elf_Internal_Rela rel_backup
;
14861 unsigned short insn_ex9
;
14862 struct elf_nds32_link_hash_table
*table
;
14863 FILE *ex9_export_file
;
14864 static bfd_boolean done
= FALSE
;
14871 table
= nds32_elf_hash_table (link_info
);
14873 table
->relax_status
|= NDS32_RELAX_EX9_DONE
;
14876 update_ex9_table
= table
->update_ex9_table
;
14877 /* Generated ex9.itable exactly. */
14878 if (update_ex9_table
== 0)
14880 for (it_abfd
= link_info
->input_bfds
; it_abfd
!= NULL
;
14881 it_abfd
= it_abfd
->link
.next
)
14883 table_sec
= bfd_get_section_by_name (it_abfd
, ".ex9.itable");
14884 if (table_sec
!= NULL
)
14888 if (table_sec
!= NULL
)
14892 output_bfd
= table_sec
->output_section
->owner
;
14893 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
14894 if (table_sec
->size
== 0)
14897 if (!nds32_get_section_contents (it_abfd
, table_sec
, &contents
, TRUE
))
14906 output_bfd
= link_info
->input_bfds
->sections
->output_section
->owner
;
14907 nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
14908 contents
= bfd_malloc (sizeof (bfd_byte
) * 2048);
14911 /* Relocate instruction. */
14914 bfd_vma relocation
, min_relocation
= 0xffffffff;
14916 insn
= strtol (ex9_insn
->string
, NULL
, 16);
14918 if (ex9_insn
->m_list
!= NULL
|| ex9_insn
->sec
!= NULL
)
14920 if (ex9_insn
->m_list
)
14921 rel_backup
= ex9_insn
->m_list
->rel_backup
;
14923 rel_backup
= ex9_insn
->rel_backup
;
14925 nds32_elf_get_insn_with_reg (&rel_backup
, insn
, &insn_with_reg
);
14927 bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE
14928 (rel_backup
.r_info
));
14929 shift
= howto
->rightshift
;
14930 if (ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_25_PCREL_RELA
14931 || ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_LO12S0_ORI_RELA
14932 || ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_LO12S0_RELA
14933 || ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_LO12S1_RELA
14934 || ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_LO12S2_RELA
)
14936 relocation
= nds32_elf_ex9_reloc_insn (ex9_insn
, link_info
);
14938 insn_with_reg
| ((relocation
>> shift
) &
14939 nds32_elf_irel_mask (&rel_backup
));
14940 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
14942 else if ((ELF32_R_TYPE (rel_backup
.r_info
) >= R_NDS32_SDA15S3
14943 && ELF32_R_TYPE (rel_backup
.r_info
) <= R_NDS32_SDA15S0
)
14944 || (ELF32_R_TYPE (rel_backup
.r_info
) >= R_NDS32_SDA15S3_RELA
14945 && ELF32_R_TYPE (rel_backup
.r_info
) <= R_NDS32_SDA15S0_RELA
)
14946 || (ELF32_R_TYPE (rel_backup
.r_info
) >= R_NDS32_SDA12S2_DP_RELA
14947 && ELF32_R_TYPE (rel_backup
.r_info
) <= R_NDS32_SDA12S2_SP_RELA
)
14948 || (ELF32_R_TYPE (rel_backup
.r_info
) >= R_NDS32_SDA16S3_RELA
14949 && ELF32_R_TYPE (rel_backup
.r_info
) <= R_NDS32_SDA19S0_RELA
))
14951 relocation
= nds32_elf_ex9_reloc_insn (ex9_insn
, link_info
);
14953 insn_with_reg
| (((relocation
- gp
) >> shift
) &
14954 nds32_elf_irel_mask (&rel_backup
));
14955 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
14957 else if (ELF32_R_TYPE (rel_backup
.r_info
) == R_NDS32_HI20_RELA
)
14959 /* Sethi may be multiple entry for one insn. */
14960 if (ex9_insn
->next
&& ex9_insn
->m_list
14961 && ex9_insn
->m_list
== ex9_insn
->next
->m_list
)
14963 struct elf_link_hash_entry_mul_list
*m_list
;
14964 struct elf_nds32_ex9_refix
*fix_ptr
;
14965 struct elf_link_hash_entry
*h
;
14967 temp_ptr
= ex9_insn
;
14968 temp_ptr2
= ex9_insn
;
14969 m_list
= ex9_insn
->m_list
;
14972 h
= m_list
->h_list
->h
;
14973 relocation
= h
->root
.u
.def
.value
+
14974 h
->root
.u
.def
.section
->output_section
->vma
+
14975 h
->root
.u
.def
.section
->output_offset
;
14976 relocation
+= m_list
->irel
->r_addend
;
14978 if (relocation
< min_relocation
)
14979 min_relocation
= relocation
;
14980 m_list
= m_list
->next
;
14982 relocation
= min_relocation
;
14984 /* Put insntruction into ex9 table. */
14985 insn
= insn_with_reg
14986 | ((relocation
>> shift
) & nds32_elf_irel_mask (&rel_backup
));
14987 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
14988 relocation
= relocation
+ 0x1000; /* hi20 */
14990 while (ex9_insn
->next
&& ex9_insn
->m_list
14991 && ex9_insn
->m_list
== ex9_insn
->next
->m_list
)
14993 /* Multiple sethi. */
14994 ex9_insn
= ex9_insn
->next
;
14997 insn_with_reg
| ((relocation
>> shift
) &
14998 nds32_elf_irel_mask (&rel_backup
));
14999 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
15000 relocation
= relocation
+ 0x1000; /* hi20 */
15003 fix_ptr
= ex9_refix_head
;
15006 /* Fix ex9 insn. */
15007 /* temp_ptr2 points to the head of multiple sethi. */
15008 temp_ptr
= temp_ptr2
;
15009 while (fix_ptr
->order
!= temp_ptr
->order
&& fix_ptr
->next
)
15011 fix_ptr
= fix_ptr
->next
;
15013 if (fix_ptr
->order
!= temp_ptr
->order
)
15016 /* Set source insn. */
15018 fix_ptr
->h
->root
.u
.def
.value
+
15019 fix_ptr
->h
->root
.u
.def
.section
->output_section
->vma
+
15020 fix_ptr
->h
->root
.u
.def
.section
->output_offset
;
15021 relocation
+= fix_ptr
->irel
->r_addend
;
15022 /* sethi imm is imm20s. */
15023 source_insn
= insn_with_reg
| ((relocation
>> shift
) & 0xfffff);
15027 /* Match entry and source code. */
15028 insn
= bfd_getb32 (contents
+ (temp_ptr
->order
) * 4 + offset
);
15029 if (insn
== source_insn
)
15031 /* Fix the ex9 insn. */
15032 if (temp_ptr
->order
!= fix_ptr
->order
)
15034 if (!nds32_get_section_contents
15035 (fix_ptr
->sec
->owner
, fix_ptr
->sec
,
15036 &source_contents
, TRUE
))
15038 (_("Linker: error cannot fixed ex9 relocation \n"));
15039 if (temp_ptr
->order
< 32)
15040 insn_ex9
= INSN_EX9_IT_2
;
15042 insn_ex9
= INSN_EX9_IT_1
;
15043 insn_ex9
= insn_ex9
| temp_ptr
->order
;
15044 bfd_putb16 (insn_ex9
, source_contents
+ fix_ptr
->irel
->r_offset
);
15050 if (!temp_ptr
->next
|| temp_ptr
->m_list
!= temp_ptr
->next
->m_list
)
15052 (_("Linker: error cannot fixed ex9 relocation \n"));
15054 temp_ptr
= temp_ptr
->next
;
15057 fix_ptr
= fix_ptr
->next
;
15062 relocation
= nds32_elf_ex9_reloc_insn (ex9_insn
, link_info
);
15063 insn
= insn_with_reg
15064 | ((relocation
>> shift
) & nds32_elf_irel_mask (&rel_backup
));
15065 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
15071 /* Insn without relocation does not have to be fixed
15072 if need to update export table. */
15073 if (update_ex9_table
== 1)
15074 bfd_putb32 (insn
, contents
+ (ex9_insn
->order
) * 4);
15076 ex9_insn
= ex9_insn
->next
;
15080 ex9_export_file
= table
->ex9_export_file
;
15081 if (ex9_export_file
!= NULL
)
15082 nds32_elf_ex9_export (link_info
, contents
, table_sec
->size
);
15083 else if (update_ex9_table
== 1)
15085 table
->ex9_export_file
= table
->ex9_import_file
;
15086 rewind (table
->ex9_export_file
);
15087 nds32_elf_ex9_export (link_info
, contents
, size
);
15091 /* Generate ex9 hash table. */
15094 nds32_elf_ex9_build_hash_table (bfd
*abfd
, asection
*sec
,
15095 struct bfd_link_info
*link_info
)
15097 Elf_Internal_Rela
*internal_relocs
;
15098 Elf_Internal_Rela
*irelend
;
15099 Elf_Internal_Rela
*irel
;
15100 Elf_Internal_Rela
*jrel
;
15101 Elf_Internal_Rela rel_backup
;
15102 Elf_Internal_Shdr
*symtab_hdr
;
15103 Elf_Internal_Sym
*isym
= NULL
;
15105 struct elf_link_hash_entry
**sym_hashes
;
15106 bfd_byte
*contents
= NULL
;
15108 unsigned long r_symndx
;
15109 uint32_t insn
, insn_with_reg
;
15110 struct elf_link_hash_entry
*h
;
15111 int data_flag
, shift
, align
;
15112 bfd_vma relocation
;
15113 /* Suppress ex9 if `.no_relax ex9' or inner loop. */
15114 reloc_howto_type
*howto
= NULL
;
15116 sym_hashes
= elf_sym_hashes (abfd
);
15117 /* Load section instructions, relocations, and symbol table. */
15118 if (!nds32_get_section_contents (abfd
, sec
, &contents
, TRUE
))
15121 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
15122 TRUE
/* keep_memory */);
15123 irelend
= internal_relocs
+ sec
->reloc_count
;
15124 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
15125 if (!nds32_get_local_syms (abfd
, sec
, &isym
))
15128 /* Check the object if enable ex9. */
15129 irel
= find_relocs_at_address (internal_relocs
, internal_relocs
, irelend
,
15130 R_NDS32_RELAX_ENTRY
);
15132 /* Check this section trigger ex9 relaxation. */
15135 || ELF32_R_TYPE (irel
->r_info
) != R_NDS32_RELAX_ENTRY
15136 || (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_ENTRY
15137 && !(irel
->r_addend
& R_NDS32_RELAX_ENTRY_EX9_FLAG
)))
15140 irel
= internal_relocs
;
15142 /* Push each insn into hash table. */
15143 while (off
< sec
->size
)
15146 struct elf_nds32_code_hash_entry
*entry
;
15148 while (irel
!= NULL
&& irel
< irelend
&& irel
->r_offset
< off
)
15151 data_flag
= nds32_elf_ex9_relocation_check (link_info
, &irel
, irelend
,
15152 NULL
, sec
, &off
, contents
);
15153 if (data_flag
& DATA_EXIST
)
15155 /* We save the move offset in the highest byte. */
15156 off
+= (data_flag
>> 24);
15160 if (*(contents
+ off
) & 0x80)
15169 rel_backup
.r_info
= 0;
15170 rel_backup
.r_offset
= 0;
15171 rel_backup
.r_addend
= 0;
15172 /* Load the instruction and its opcode with register for comparing. */
15173 insn
= bfd_getb32 (contents
+ off
);
15175 if (irel
!= NULL
&& irel
< irelend
&& irel
->r_offset
== off
)
15177 nds32_elf_get_insn_with_reg (irel
, insn
, &insn_with_reg
);
15178 howto
= bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (irel
->r_info
));
15179 shift
= howto
->rightshift
;
15180 align
= (1 << shift
) - 1;
15181 if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_25_PCREL_RELA
15182 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_HI20_RELA
15183 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S0_ORI_RELA
15184 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S0_RELA
15185 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S1_RELA
15186 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_LO12S2_RELA
15187 ||(ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3
15188 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0
)
15189 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3_RELA
15190 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0_RELA
)
15191 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA12S2_DP_RELA
15192 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA12S2_SP_RELA
)
15193 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA16S3_RELA
15194 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA19S0_RELA
))
15196 r_symndx
= ELF32_R_SYM (irel
->r_info
);
15198 rel_backup
= *irel
;
15199 if (r_symndx
< symtab_hdr
->sh_info
)
15201 /* Local symbol. */
15202 int shndx
= isym
[r_symndx
].st_shndx
;
15204 bfd_vma st_value
= (isym
+ r_symndx
)->st_value
;
15205 isec
= elf_elfsections (abfd
)[shndx
]->bfd_section
;
15206 relocation
= (isec
->output_section
->vma
+ isec
->output_offset
15207 + st_value
+ irel
->r_addend
);
15211 /* External symbol. */
15212 bfd_boolean warned ATTRIBUTE_UNUSED
;
15213 bfd_boolean ignored ATTRIBUTE_UNUSED
;
15214 bfd_boolean unresolved_reloc ATTRIBUTE_UNUSED
;
15217 /* Maybe there is a better way to get h and relocation */
15218 RELOC_FOR_GLOBAL_SYMBOL (link_info
, abfd
, sec
, irel
,
15219 r_symndx
, symtab_hdr
, sym_hashes
,
15220 h
, sym_sec
, relocation
,
15221 unresolved_reloc
, warned
, ignored
);
15222 relocation
+= irel
->r_addend
;
15223 if ((h
->root
.type
!= bfd_link_hash_defined
15224 && h
->root
.type
!= bfd_link_hash_defweak
)
15225 || strcmp (h
->root
.root
.string
, "_FP_BASE_") == 0)
15232 /* Check for gp relative instruction alignment. */
15233 if ((ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3
15234 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0
)
15235 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA15S3_RELA
15236 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA15S0_RELA
)
15237 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA12S2_DP_RELA
15238 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA12S2_SP_RELA
)
15239 || (ELF32_R_TYPE (irel
->r_info
) >= R_NDS32_SDA16S3_RELA
15240 && ELF32_R_TYPE (irel
->r_info
) <= R_NDS32_SDA19S0_RELA
))
15243 bfd
*output_bfd
= sec
->output_section
->owner
;
15244 bfd_reloc_status_type r
;
15246 /* If the symbol is in the abs section, the out_bfd will be null.
15247 This happens when the relocation has a symbol@GOTOFF. */
15248 r
= nds32_elf_final_sda_base (output_bfd
, link_info
, &gp
, FALSE
);
15249 if (r
!= bfd_reloc_ok
)
15257 /* Make sure alignment is correct. */
15258 if (relocation
& align
)
15260 /* Incorrect alignment. */
15262 /* xgettext:c-format */
15263 (_("%B: warning: unaligned small data access "
15264 "for entry: {%Ld, %Ld, %Ld}, addr = %#Lx, align = %#x"),
15265 abfd
, irel
->r_offset
,
15266 irel
->r_info
, irel
->r_addend
, relocation
, align
);
15272 insn
= insn_with_reg
15273 | ((relocation
>> shift
) & nds32_elf_irel_mask (irel
));
15275 else if (ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_BEGIN
15276 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_RELAX_REGION_END
15277 || ELF32_R_TYPE (irel
->r_info
) == R_NDS32_NONE
)
15279 /* These relocations do not have to relocate contens, so it can
15280 be regard as instruction without relocation. */
15289 snprintf (code
, sizeof (code
), "%08x", insn
);
15291 entry
= (struct elf_nds32_code_hash_entry
*)
15292 bfd_hash_lookup (&ex9_code_table
, code
, TRUE
, TRUE
);
15296 (_("failed creating ex9.it %s hash table entry"), code
);
15301 if (h
->root
.type
== bfd_link_hash_undefined
)
15303 /* Global symbol. */
15304 /* In order to do sethi with different symbol but same value. */
15305 if (entry
->m_list
== NULL
)
15307 struct elf_link_hash_entry_mul_list
*m_list_new
;
15308 struct elf_link_hash_entry_list
*h_list_new
;
15310 m_list_new
= (struct elf_link_hash_entry_mul_list
*)
15311 bfd_malloc (sizeof (struct elf_link_hash_entry_mul_list
));
15312 h_list_new
= (struct elf_link_hash_entry_list
*)
15313 bfd_malloc (sizeof (struct elf_link_hash_entry_list
));
15314 entry
->m_list
= m_list_new
;
15315 m_list_new
->h_list
= h_list_new
;
15316 m_list_new
->rel_backup
= rel_backup
;
15317 m_list_new
->times
= 1;
15318 m_list_new
->irel
= jrel
;
15319 m_list_new
->next
= NULL
;
15321 h_list_new
->next
= NULL
;
15325 struct elf_link_hash_entry_mul_list
*m_list
= entry
->m_list
;
15326 struct elf_link_hash_entry_list
*h_list
;
15330 /* Build the different symbols that point to the same address. */
15331 h_list
= m_list
->h_list
;
15332 if (h_list
->h
->root
.u
.def
.value
== h
->root
.u
.def
.value
15333 && h_list
->h
->root
.u
.def
.section
->output_section
->vma
15334 == h
->root
.u
.def
.section
->output_section
->vma
15335 && h_list
->h
->root
.u
.def
.section
->output_offset
15336 == h
->root
.u
.def
.section
->output_offset
15337 && m_list
->rel_backup
.r_addend
== rel_backup
.r_addend
)
15340 m_list
->irel
= jrel
;
15341 while (h_list
->h
!= h
&& h_list
->next
)
15342 h_list
= h_list
->next
;
15343 if (h_list
->h
!= h
)
15345 struct elf_link_hash_entry_list
*h_list_new
;
15347 h_list_new
= (struct elf_link_hash_entry_list
*)
15348 bfd_malloc (sizeof (struct elf_link_hash_entry_list
));
15349 h_list
->next
= h_list_new
;
15351 h_list_new
->next
= NULL
;
15355 /* The sethi case may have different address but the
15356 hi20 is the same. */
15357 else if (ELF32_R_TYPE (jrel
->r_info
) == R_NDS32_HI20_RELA
15358 && m_list
->next
== NULL
)
15360 struct elf_link_hash_entry_mul_list
*m_list_new
;
15361 struct elf_link_hash_entry_list
*h_list_new
;
15363 m_list_new
= (struct elf_link_hash_entry_mul_list
*)
15364 bfd_malloc (sizeof (struct elf_link_hash_entry_mul_list
));
15365 h_list_new
= (struct elf_link_hash_entry_list
*)
15366 bfd_malloc (sizeof (struct elf_link_hash_entry_list
));
15367 m_list
->next
= m_list_new
;
15368 m_list_new
->h_list
= h_list_new
;
15369 m_list_new
->rel_backup
= rel_backup
;
15370 m_list_new
->times
= 1;
15371 m_list_new
->irel
= jrel
;
15372 m_list_new
->next
= NULL
;
15374 h_list_new
->next
= NULL
;
15377 m_list
= m_list
->next
;
15388 /* Local symbol and insn without relocation*/
15390 entry
->rel_backup
= rel_backup
;
15393 /* Use in sethi insn with constant and global symbol in same format. */
15395 entry
->const_insn
= 1;
15397 entry
->irel
= jrel
;
15405 /* Set the _ITB_BASE, and point it to ex9 table. */
15408 nds32_elf_ex9_itb_base (struct bfd_link_info
*link_info
)
15412 bfd
*output_bfd
= NULL
;
15413 struct bfd_link_hash_entry
*bh
= NULL
;
15415 if (is_ITB_BASE_set
== 1)
15418 is_ITB_BASE_set
= 1;
15420 bh
= bfd_link_hash_lookup (link_info
->hash
, "_ITB_BASE_", FALSE
, FALSE
, TRUE
);
15422 if (bh
&& (bh
->type
== bfd_link_hash_defined
15423 || bh
->type
== bfd_link_hash_defweak
))
15426 for (abfd
= link_info
->input_bfds
; abfd
!= NULL
;
15427 abfd
= abfd
->link
.next
)
15429 sec
= bfd_get_section_by_name (abfd
, ".ex9.itable");
15432 output_bfd
= sec
->output_section
->owner
;
15436 if (output_bfd
== NULL
)
15438 output_bfd
= link_info
->output_bfd
;
15439 if (output_bfd
->sections
== NULL
)
15442 sec
= bfd_abs_section_ptr
;
15444 bh
= bfd_link_hash_lookup (link_info
->hash
, "_ITB_BASE_",
15445 FALSE
, FALSE
, TRUE
);
15446 return (_bfd_generic_link_add_one_symbol
15447 (link_info
, output_bfd
, "_ITB_BASE_",
15448 BSF_GLOBAL
| BSF_WEAK
, sec
, 0,
15449 (const char *) NULL
, FALSE
, get_elf_backend_data
15450 (output_bfd
)->collect
, &bh
));
15454 #define ELF_ARCH bfd_arch_nds32
15455 #define ELF_MACHINE_CODE EM_NDS32
15456 #define ELF_MAXPAGESIZE 0x1000
15457 #define ELF_TARGET_ID NDS32_ELF_DATA
15459 #define TARGET_BIG_SYM nds32_elf32_be_vec
15460 #define TARGET_BIG_NAME "elf32-nds32be"
15461 #define TARGET_LITTLE_SYM nds32_elf32_le_vec
15462 #define TARGET_LITTLE_NAME "elf32-nds32le"
15464 #define elf_info_to_howto nds32_info_to_howto
15465 #define elf_info_to_howto_rel nds32_info_to_howto_rel
15467 #define bfd_elf32_bfd_link_hash_table_create nds32_elf_link_hash_table_create
15468 #define bfd_elf32_bfd_merge_private_bfd_data nds32_elf_merge_private_bfd_data
15469 #define bfd_elf32_bfd_print_private_bfd_data nds32_elf_print_private_bfd_data
15470 #define bfd_elf32_bfd_relax_section nds32_elf_relax_section
15471 #define bfd_elf32_bfd_set_private_flags nds32_elf_set_private_flags
15473 #define bfd_elf32_mkobject nds32_elf_mkobject
15474 #define elf_backend_action_discarded nds32_elf_action_discarded
15475 #define elf_backend_add_symbol_hook nds32_elf_add_symbol_hook
15476 #define elf_backend_check_relocs nds32_elf_check_relocs
15477 #define elf_backend_adjust_dynamic_symbol nds32_elf_adjust_dynamic_symbol
15478 #define elf_backend_create_dynamic_sections nds32_elf_create_dynamic_sections
15479 #define elf_backend_finish_dynamic_sections nds32_elf_finish_dynamic_sections
15480 #define elf_backend_finish_dynamic_symbol nds32_elf_finish_dynamic_symbol
15481 #define elf_backend_size_dynamic_sections nds32_elf_size_dynamic_sections
15482 #define elf_backend_relocate_section nds32_elf_relocate_section
15483 #define elf_backend_gc_mark_hook nds32_elf_gc_mark_hook
15484 #define elf_backend_grok_prstatus nds32_elf_grok_prstatus
15485 #define elf_backend_grok_psinfo nds32_elf_grok_psinfo
15486 #define elf_backend_reloc_type_class nds32_elf_reloc_type_class
15487 #define elf_backend_copy_indirect_symbol nds32_elf_copy_indirect_symbol
15488 #define elf_backend_link_output_symbol_hook nds32_elf_output_symbol_hook
15489 #define elf_backend_output_arch_syms nds32_elf_output_arch_syms
15490 #define elf_backend_object_p nds32_elf_object_p
15491 #define elf_backend_final_write_processing nds32_elf_final_write_processing
15492 #define elf_backend_special_sections nds32_elf_special_sections
15493 #define bfd_elf32_bfd_get_relocated_section_contents \
15494 nds32_elf_get_relocated_section_contents
15496 #define elf_backend_can_gc_sections 1
15497 #define elf_backend_can_refcount 1
15498 #define elf_backend_want_got_plt 1
15499 #define elf_backend_plt_readonly 1
15500 #define elf_backend_want_plt_sym 0
15501 #define elf_backend_got_header_size 12
15502 #define elf_backend_may_use_rel_p 1
15503 #define elf_backend_default_use_rela_p 1
15504 #define elf_backend_may_use_rela_p 1
15505 #define elf_backend_dtrel_excludes_plt 1
15507 #include "elf32-target.h"
15509 #undef ELF_MAXPAGESIZE
15510 #define ELF_MAXPAGESIZE 0x2000
15512 #undef TARGET_BIG_SYM
15513 #define TARGET_BIG_SYM nds32_elf32_linux_be_vec
15514 #undef TARGET_BIG_NAME
15515 #define TARGET_BIG_NAME "elf32-nds32be-linux"
15516 #undef TARGET_LITTLE_SYM
15517 #define TARGET_LITTLE_SYM nds32_elf32_linux_le_vec
15518 #undef TARGET_LITTLE_NAME
15519 #define TARGET_LITTLE_NAME "elf32-nds32le-linux"
15521 #define elf32_bed elf32_nds32_lin_bed
15523 #include "elf32-target.h"