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