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