Update year range in copyright notice of binutils files
[deliverable/binutils-gdb.git] / ld / emultempl / armcoff.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
92b93329 3fragment <<EOF
252b5132
RH
4/* This file is is generated by a shell script. DO NOT EDIT! */
5
6/* emulate the original gld for the given ${EMULATION_NAME}
b3adc24a 7 Copyright (C) 1991-2020 Free Software Foundation, Inc.
252b5132
RH
8 Written by Steve Chamberlain steve@cygnus.com
9
f96b4a7b
NC
10 This file is part of the GNU Binutils.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
25 MA 02110-1301, USA. */
252b5132
RH
26
27#define TARGET_IS_${EMULATION_NAME}
28
252b5132 29#include "sysdep.h"
3db64b00 30#include "bfd.h"
252b5132 31#include "bfdlink.h"
1ff6de03 32#include "ctf-api.h"
252b5132
RH
33#include "getopt.h"
34
35#include "ld.h"
36#include "ldmain.h"
252b5132
RH
37#include "ldmisc.h"
38
39#include "ldexp.h"
40#include "ldlang.h"
b71e2778
AM
41#include "ldfile.h"
42#include "ldemul.h"
252b5132 43
0c7a8e5a
AM
44/* If TRUE, then interworking stubs which support calls to old,
45 non-interworking aware ARM code should be generated. */
252b5132
RH
46
47static int support_old_code = 0;
6f798e5c 48static char * thumb_entry_symbol = NULL;
252b5132
RH
49
50#define OPTION_SUPPORT_OLD_CODE 300
6f798e5c 51#define OPTION_THUMB_ENTRY 301
252b5132 52
3bcf5557 53static void
0c7a8e5a
AM
54gld${EMULATION_NAME}_add_options
55 (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
56 struct option **longopts, int nrl ATTRIBUTE_UNUSED,
57 struct option **really_longopts ATTRIBUTE_UNUSED)
252b5132 58{
3bcf5557
AM
59 static const struct option xtra_long[] = {
60 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
61 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
62 {NULL, no_argument, NULL, 0}
63 };
64
0c7a8e5a
AM
65 *longopts = xrealloc (*longopts,
66 nl * sizeof (struct option) + sizeof (xtra_long));
3bcf5557
AM
67 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
68}
252b5132
RH
69
70static void
0c7a8e5a 71gld${EMULATION_NAME}_list_options (FILE *file)
252b5132 72{
442996ee
AM
73 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
74 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
252b5132
RH
75}
76
3bcf5557 77static bfd_boolean
0c7a8e5a 78gld${EMULATION_NAME}_handle_option (int optc)
252b5132 79{
252b5132
RH
80 switch (optc)
81 {
82 default:
3bcf5557 83 return FALSE;
252b5132
RH
84
85 case OPTION_SUPPORT_OLD_CODE:
86 support_old_code = 1;
87 break;
6f798e5c
NC
88
89 case OPTION_THUMB_ENTRY:
90 thumb_entry_symbol = optarg;
91 break;
252b5132 92 }
0c7a8e5a 93
3bcf5557 94 return TRUE;
252b5132
RH
95}
96\f
97static void
0c7a8e5a 98gld${EMULATION_NAME}_before_parse (void)
252b5132
RH
99{
100#ifndef TARGET_ /* I.e., if not generic. */
5e2f1575 101 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
252b5132
RH
102#endif /* not TARGET_ */
103}
104
105/* This is called after the sections have been attached to output
106 sections, but before any sizes or addresses have been set. */
107
108static void
0c7a8e5a 109gld${EMULATION_NAME}_before_allocation (void)
252b5132
RH
110{
111 /* we should be able to set the size of the interworking stub section */
112
113 /* Here we rummage through the found bfds to collect glue information */
114 /* FIXME: should this be based on a command line option? krk@cygnus.com */
115 {
116 LANG_FOR_EACH_INPUT_STATEMENT (is)
117 {
118 if (! bfd_arm_process_before_allocation
119 (is->the_bfd, & link_info, support_old_code))
120 {
121 /* xgettext:c-format */
df5f2391
AM
122 einfo (_("%P: errors encountered processing file %s\n"),
123 is->filename);
252b5132
RH
124 }
125 }
126 }
127
128 /* We have seen it all. Allocate it, and carry on */
129 bfd_arm_allocate_interworking_sections (& link_info);
8423293d 130
1e035701 131 before_allocation_default ();
252b5132
RH
132}
133
134static void
0c7a8e5a 135gld${EMULATION_NAME}_after_open (void)
252b5132 136{
5c3049d2
AM
137 after_open_default ();
138
f13a99db 139 if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL)
252b5132 140 {
f11523b0
NC
141 /* The arm backend needs special fields in the output hash structure.
142 These will only be created if the output format is an arm format,
143 hence we do not support linking and changing output formats at the
144 same time. Use a link followed by objcopy to change output formats. */
df5f2391
AM
145 einfo (_("%F%P: error: cannot change output format "
146 "whilst linking %s binaries\n"), "ARM");
f11523b0 147 return;
252b5132 148 }
0c7a8e5a 149
f11523b0
NC
150 {
151 LANG_FOR_EACH_INPUT_STATEMENT (is)
152 {
153 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
154 break;
155 }
156 }
252b5132
RH
157}
158
6f798e5c 159static void
0c7a8e5a 160gld${EMULATION_NAME}_finish (void)
6f798e5c 161{
74541ad4 162 if (thumb_entry_symbol != NULL)
6f798e5c 163 {
74541ad4
AM
164 struct bfd_link_hash_entry * h;
165
166 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
167 FALSE, FALSE, TRUE);
168
169 if (h != (struct bfd_link_hash_entry *) NULL
170 && (h->type == bfd_link_hash_defined
171 || h->type == bfd_link_hash_defweak)
172 && h->u.def.section->output_section != NULL)
173 {
174 static char buffer[32];
175 bfd_vma val;
176
177 /* Special procesing is required for a Thumb entry symbol. The
178 bottom bit of its address must be set. */
179 val = (h->u.def.value
fd361982 180 + bfd_section_vma (h->u.def.section->output_section)
74541ad4
AM
181 + h->u.def.section->output_offset);
182
183 val |= 1;
184
185 /* Now convert this value into a string and store it in entry_symbol
186 where the lang_finish() function will pick it up. */
187 buffer[0] = '0';
188 buffer[1] = 'x';
189
190 sprintf_vma (buffer + 2, val);
191
192 if (entry_symbol.name != NULL && entry_from_cmdline)
193 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
194 thumb_entry_symbol, entry_symbol.name);
195 entry_symbol.name = buffer;
196 }
197 else
c58dea77 198 einfo (_("%P: warning: cannot find thumb start symbol %s\n"),
74541ad4 199 thumb_entry_symbol);
6f798e5c 200 }
1e035701
AM
201
202 finish_default ();
6f798e5c
NC
203}
204
252b5132 205static char *
0c7a8e5a 206gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
207EOF
208
7225345d 209if test x"$COMPILE_IN" = xyes
252b5132
RH
210then
211# Scripts compiled in.
212
213# sed commands to quote an ld script as a C string.
597e2591 214sc="-f stringify.sed"
252b5132 215
92b93329 216fragment <<EOF
0c7a8e5a 217{
252b5132
RH
218 *isfile = 0;
219
0e1862bb 220 if (bfd_link_relocatable (&link_info) && config.build_constructors)
252b5132
RH
221 return
222EOF
b34976b6 223sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
0e1862bb 224echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
b34976b6
AM
225sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
226echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
227sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
228echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
229sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
230echo ' ; else return' >> e${EMULATION_NAME}.c
231sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
232echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
233
234else
235# Scripts read from the filesystem.
236
92b93329 237fragment <<EOF
0c7a8e5a 238{
252b5132
RH
239 *isfile = 1;
240
0e1862bb 241 if (bfd_link_relocatable (&link_info) && config.build_constructors)
252b5132 242 return "ldscripts/${EMULATION_NAME}.xu";
0e1862bb 243 else if (bfd_link_relocatable (&link_info))
252b5132
RH
244 return "ldscripts/${EMULATION_NAME}.xr";
245 else if (!config.text_read_only)
246 return "ldscripts/${EMULATION_NAME}.xbn";
247 else if (!config.magic_demand_paged)
248 return "ldscripts/${EMULATION_NAME}.xn";
249 else
250 return "ldscripts/${EMULATION_NAME}.x";
251}
252EOF
253
254fi
255
92b93329 256fragment <<EOF
252b5132 257
0c7a8e5a 258struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132
RH
259{
260 gld${EMULATION_NAME}_before_parse,
261 syslib_default,
262 hll_default,
263 after_parse_default,
264 gld${EMULATION_NAME}_after_open,
5c3261b0 265 after_check_relocs_default,
252b5132
RH
266 after_allocation_default,
267 set_output_arch_default,
268 ldemul_default_target,
269 gld${EMULATION_NAME}_before_allocation,
270 gld${EMULATION_NAME}_get_script,
271 "${EMULATION_NAME}",
272 "${OUTPUT_FORMAT}",
e1c47aa4
AM
273 gld${EMULATION_NAME}_finish,
274 NULL, /* create output section statements */
275 NULL, /* open dynamic archive */
276 NULL, /* place orphan */
277 NULL, /* set symbols */
3bcf5557
AM
278 NULL, /* parse_args */
279 gld${EMULATION_NAME}_add_options,
280 gld${EMULATION_NAME}_handle_option,
e1c47aa4
AM
281 NULL, /* unrecognised file */
282 gld${EMULATION_NAME}_list_options,
40d109bf 283 NULL, /* recognized file */
fac1652d 284 NULL, /* find_potential_libraries */
7a2f2d82 285 NULL, /* new_vers_pattern */
1ff6de03
NA
286 NULL, /* extra_map_file_text */
287 ${LDEMUL_EMIT_CTF_EARLY-NULL},
288 ${LDEMUL_EXAMINE_STRTAB_FOR_CTF-NULL}
252b5132
RH
289};
290EOF
This page took 0.817015 seconds and 4 git commands to generate.