1 /* NDS32-specific support for 32-bit ELF.
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
29 /* Relocation flags encoded in r_addend. */
31 /* Relocation flags for R_NDS32_ERLAX_ENTRY. */
33 /* Set if relax on this section is done or disabled. */
34 #define R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG (1 << 31)
35 /* Optimize for performance. */
36 #define R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG (1 << 30)
37 /* Optimize for size. Branch destination 4-byte adjustment
39 #define R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG (1 << 29)
40 /* To distinguish the assembly code generated by compiler
41 or written manually. */
42 #define R_NDS32_RELAX_ENTRY_VERBATIM_FLAG (1 << 28)
43 /* EX9 and link-time IFC must be explicitly enabled, so we
44 won't mess up handcraft assembly code. */
45 /* Enable EX9 optimization for this section. */
46 #define R_NDS32_RELAX_ENTRY_EX9_FLAG (1 << 2)
47 /* Enable IFC optimization for this section. */
48 #define R_NDS32_RELAX_ENTRY_IFC_FLAG (1 << 3)
49 /* Two bits for ICT to comply with files without directive. */
50 /* ICT small model. */
51 #define R_NDS32_RELAX_ENTRY_ICT_SMALL (0x2 << 4)
52 /* ICT large model. */
53 #define R_NDS32_RELAX_ENTRY_ICT_LARGE (0x3 << 4)
54 /* Mask for get ict bits. */
55 #define R_NDS32_RELAX_ENTRY_ICT_MASK (0x3 << 4)
58 /* Relocation flags for R_NDS32_INSN16. */
60 /* Tag the nop16 can be removed. */
61 #define R_NDS32_INSN16_CONVERT_FLAG (1 << 0)
62 /* Convert a gp-relative access (e.g., lwi.gp)
63 to fp-as-gp access (lwi37.fp).
64 This value is used by linker internally only.
65 It's fine to change the vlaue. */
66 #define R_NDS32_INSN16_FP7U2_FLAG (1 << 1)
68 /* Relocation flags for R_NDS32_RELAX_REGION_OMIT_FP_START/END. */
70 /* OMIT_FP_FLAG marks the region for applying fp-as-gp
72 #define R_NDS32_RELAX_REGION_OMIT_FP_FLAG (1 << 0)
73 /* NOT_OMIT_FP_FLAG is set if this region is not worth
75 #define R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG (1 << 1)
76 /* Suppress EX9 optimization in the region. */
77 #define R_NDS32_RELAX_REGION_NO_EX9_FLAG (1 << 2)
78 /* A Innermost loop region. Some optimizations is suppressed
79 in this region due to performance drop. */
80 #define R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG (1 << 4)
82 /* Tag range for LOADSTORE relocation. */
85 NDS32_LOADSTORE_NONE = 0x0,
86 NDS32_LOADSTORE_BYTE = 0x1,
87 NDS32_LOADSTORE_HALF = 0x2,
88 NDS32_LOADSTORE_WORD = 0x4,
89 NDS32_LOADSTORE_FLOAT_S = 0x8,
90 NDS32_LOADSTORE_FLOAT_D = 0x10,
91 NDS32_LOADSTORE_IMM = 0x20
94 /* Relax tag for nds32_elf_relax_section, we have to specify which
95 optimization do in this round. */
98 NDS32_RELAX_NONE_ROUND = 0,
99 NDS32_RELAX_NORMAL_ROUND,
100 NDS32_RELAX_JUMP_IFC_ROUND,
101 NDS32_RELAX_EX9_BUILD_ROUND,
102 NDS32_RELAX_EX9_REPLACE_ROUND,
103 NDS32_RELAX_EMPTY_ROUND
106 /* Optimization status mask. */
107 #define NDS32_RELAX_JUMP_IFC_DONE (1 << 0)
108 #define NDS32_RELAX_EX9_DONE (1 << 1)
110 /* Optimization turn on mask. */
111 #define NDS32_RELAX_JUMP_IFC_ON (1 << 0)
112 #define NDS32_RELAX_EX9_ON (1 << 1)
114 extern void nds32_insertion_sort
115 (void *, size_t, size_t, int (*) (const void *, const void *));
117 extern int nds32_elf_ex9_init (void);
118 extern int nds32_convert_32_to_16 (bfd *, uint32_t, uint16_t *, int *);
119 extern int nds32_convert_16_to_32 (bfd *, uint16_t, uint32_t *);
120 extern void bfd_elf32_nds32_set_target_option (struct bfd_link_info *,
121 int, int, FILE *, int,
122 int, int, int, FILE *,
124 bfd_boolean, bfd_boolean);
126 #define nds32_elf_hash_table(info) \
127 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
128 == NDS32_ELF_DATA ? \
129 ((struct elf_nds32_link_hash_table *) ((info)->hash)) : NULL)
131 /* Hash table structure for target nds32. There are some members to
132 save target options passed from nds32elf.em to bfd. */
134 struct elf_nds32_link_hash_table
136 struct elf_link_hash_table root;
138 /* Short-cuts to get to dynamic linker sections. */
142 /* Small local sym to section mapping cache. */
143 struct sym_cache sym_cache;
145 /* Target dependent options. */
146 int relax_fp_as_gp; /* --mrelax-omit-fp */
147 int eliminate_gc_relocs; /* --meliminate-gc-relocs */
148 FILE *sym_ld_script; /* --mgen-symbol-ld-script=<file> */
149 /* Disable if linking a dynamically linked executable. */
150 int load_store_relax;
151 int target_optimize; /* Switch optimization. */
152 int relax_status; /* Finished optimization. */
153 int relax_round; /* Going optimization. */
154 FILE *ex9_export_file; /* --mexport-ex9=<file> */
155 FILE *ex9_import_file; /* --mimport-ex9=<file> */
156 int update_ex9_table; /* --mupdate-ex9. */
158 bfd_boolean ex9_loop_aware; /* Ignore ex9 if inside a loop. */
159 bfd_boolean ifc_loop_aware; /* Ignore ifc if inside a loop. */