]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/nds32elf.em
Revert "Remove LIBINTL_DEP"
[thirdparty/binutils-gdb.git] / ld / emultempl / nds32elf.em
1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
3 # Contributed by Andes Technology Corporation.
4 #
5 # This file is part of the GNU Binutils.
6 #
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.
11 #
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.
16 #
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,
20 # MA 02110-1301, USA.
21 #
22
23 fragment <<EOF
24
25 #include "elf-bfd.h"
26 #include "elf/nds32.h"
27 #include <stdint.h>
28 #include "elf32-nds32.h"
29
30 static int relax_fp_as_gp = 1; /* --mrelax-omit-fp */
31 static int eliminate_gc_relocs = 0; /* --meliminate-gc-relocs */
32 static FILE *sym_ld_script = NULL; /* --mgen-symbol-ld-script=<file> */
33 static int hyper_relax = 1; /* --mhyper-relax */
34 static int tls_desc_trampoline = 0; /* --m[no]tlsdesc-trampoline. */
35 /* Disable if linking a dynamically linked executable. */
36 static int load_store_relax = 1;
37
38 /* Save the target options into output bfd to avoid using to many global
39 variables. Do this after the output has been created, but before
40 inputs are read. */
41 static void
42 nds32_elf_create_output_section_statements (void)
43 {
44 if (strstr (bfd_get_target (link_info.output_bfd), "nds32") == NULL)
45 {
46 /* Check the output target is nds32. */
47 einfo (_("%F%P: error: cannot change output format whilst "
48 "linking %s binaries\n"), "NDS32");
49 return;
50 }
51
52 bfd_elf32_nds32_set_target_option (&link_info,
53 relax_fp_as_gp,
54 eliminate_gc_relocs,
55 sym_ld_script,
56 hyper_relax,
57 tls_desc_trampoline,
58 load_store_relax);
59 }
60
61 static void
62 nds32_elf_after_parse (void)
63 {
64 if (bfd_link_relocatable (&link_info)
65 || bfd_link_pic (&link_info))
66 DISABLE_RELAXATION;
67
68 if (!RELAXATION_ENABLED)
69 relax_fp_as_gp = 0;
70
71 ldelf_after_parse ();
72 }
73
74 static void
75 nds32_elf_after_open (void)
76 {
77 unsigned int arch_ver = (unsigned int)-1;
78 unsigned int abi_ver = (unsigned int)-1;
79 bfd *abfd;
80
81 /* For now, make sure all object files are of the same architecture.
82 We may try to merge object files with different architecture together. */
83 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
84 {
85 if (arch_ver == (unsigned int)-1 && E_N1_ARCH != (elf_elfheader (abfd)->e_flags & EF_NDS_ARCH))
86 arch_ver = elf_elfheader (abfd)->e_flags & EF_NDS_ARCH ;
87
88 if (abi_ver == (unsigned int)-1)
89 {
90 /* Initialize ABI version, if not ABI0.
91 (OS uses empty file to create empty ELF with ABI0). */
92 if ((elf_elfheader (abfd)->e_flags & EF_NDS_ABI) != 0)
93 abi_ver = elf_elfheader (abfd)->e_flags & EF_NDS_ABI ;
94 }
95 else if ((elf_elfheader (abfd)->e_flags & EF_NDS_ABI) != 0
96 && abi_ver != (elf_elfheader (abfd)->e_flags & EF_NDS_ABI))
97 {
98 /* Incompatible objects. */
99 einfo (_("%F%P: %pB: ABI version of object files mismatched\n"),
100 abfd);
101 }
102 }
103
104 /* Check object files if the target is dynamic linked executable
105 or shared object. */
106 if (elf_hash_table (&link_info)->dynamic_sections_created
107 || bfd_link_pic (&link_info)
108 || bfd_link_pie (&link_info))
109 {
110 /* Dynamic linked executable with SDA and non-PIC.
111 Turn off load/store relaxtion. */
112 /* This may support in the future. */
113 load_store_relax = 0 ;
114 relax_fp_as_gp = 0;
115 }
116
117 /* Call the standard elf routine. */
118 gld${EMULATION_NAME}_after_open ();
119 }
120
121 static void
122 nds32_elf_after_allocation (void)
123 {
124 /* Call default after allocation callback.
125 1. This is where relaxation is done.
126 2. It calls ldelf_map_segments to build ELF segment table.
127 3. Any relaxation requires relax being done must be called after it. */
128 gld${EMULATION_NAME}_after_allocation ();
129 }
130
131 EOF
132 # Define some shell vars to insert bits of code into the standard elf
133 # parse_args and list_options functions.
134 #
135 PARSE_AND_LIST_LONGOPTS='
136 { "mfp-as-gp", no_argument, NULL, OPTION_FP_AS_GP},
137 { "mno-fp-as-gp", no_argument, NULL, OPTION_NO_FP_AS_GP},
138 { "mexport-symbols", required_argument, NULL, OPTION_EXPORT_SYMBOLS},
139 { "mhyper-relax", required_argument, NULL, OPTION_HYPER_RELAX},
140 { "mtlsdesc-trampoline", no_argument, NULL, OPTION_TLSDESC_TRAMPOLINE},
141 { "mno-tlsdesc-trampoline", no_argument, NULL, OPTION_NO_TLSDESC_TRAMPOLINE},
142 /* These are deprecated options. Remove them in the future. */
143 { "mrelax-reduce-fp-update", no_argument, NULL, OPTION_REDUCE_FP_UPDATE},
144 { "mrelax-no-reduce-fp-update", no_argument, NULL, OPTION_NO_REDUCE_FP_UPDATE},
145 { "mbaseline", required_argument, NULL, OPTION_BASELINE},
146 { "meliminate-gc-relocs", no_argument, NULL, OPTION_ELIM_GC_RELOCS},
147 { "mrelax-omit-fp", no_argument, NULL, OPTION_FP_AS_GP},
148 { "mrelax-no-omit-fp", no_argument, NULL, OPTION_NO_FP_AS_GP},
149 { "mgen-symbol-ld-script", required_argument, NULL, OPTION_EXPORT_SYMBOLS},
150 '
151 PARSE_AND_LIST_OPTIONS='
152 fprintf (file, _("\
153 --m[no-]fp-as-gp Disable/enable fp-as-gp relaxation\n"));
154 fprintf (file, _("\
155 --mexport-symbols=FILE Exporting symbols in linker script\n"));
156 fprintf (file, _("\
157 --mhyper-relax=level Adjust relax level (low|medium|high). default: medium\n"));
158 fprintf (file, _("\
159 --m[no-]tlsdesc-trampoline Disable/enable TLS DESC trampoline\n"));
160 '
161 PARSE_AND_LIST_ARGS_CASES='
162 case OPTION_BASELINE:
163 einfo (_("%P: --mbaseline is not used anymore\n"));
164 break;
165 case OPTION_ELIM_GC_RELOCS:
166 eliminate_gc_relocs = 1;
167 break;
168 case OPTION_FP_AS_GP:
169 case OPTION_NO_FP_AS_GP:
170 relax_fp_as_gp = (optc == OPTION_FP_AS_GP);
171 break;
172 case OPTION_REDUCE_FP_UPDATE:
173 case OPTION_NO_REDUCE_FP_UPDATE:
174 einfo (_("%P: --relax-[no-]reduce-fp-updat is not used anymore\n"));
175 break;
176 case OPTION_EXPORT_SYMBOLS:
177 if (!optarg)
178 einfo (_("%P: missing file for --mexport-symbols\n"), optarg);
179
180 if(strcmp (optarg, "-") == 0)
181 sym_ld_script = stdout;
182 else
183 {
184 sym_ld_script = fopen (optarg, FOPEN_WT);
185 if(sym_ld_script == NULL)
186 einfo (_("%F%P: cannot open map file %s: %E\n"), optarg);
187 }
188 break;
189 case OPTION_HYPER_RELAX:
190 if (!optarg)
191 einfo (_("%P: valid arguments to --mhyper-relax=(low|medium|high)\n"));
192
193 if (strcmp (optarg, "low") == 0)
194 hyper_relax = 0;
195 else if (strcmp (optarg, "medium") == 0)
196 hyper_relax = 1;
197 else if (strcmp (optarg, "high") == 0)
198 hyper_relax = 2;
199 else
200 einfo (_("%P: valid arguments to --mhyper-relax=(low|medium|high)\n"));
201
202 break;
203 case OPTION_TLSDESC_TRAMPOLINE:
204 tls_desc_trampoline = 1;
205 break;
206 case OPTION_NO_TLSDESC_TRAMPOLINE:
207 tls_desc_trampoline = 0;
208 break;
209 '
210 LDEMUL_AFTER_OPEN=nds32_elf_after_open
211 LDEMUL_AFTER_PARSE=nds32_elf_after_parse
212 LDEMUL_AFTER_ALLOCATION=nds32_elf_after_allocation
213 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=nds32_elf_create_output_section_statements