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