bfd/
[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}
5e2f1575
AM
7 Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
8 2004 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 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
RH
71{
72 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
6f798e5c 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 */
121 einfo (_("Errors encountered processing file %s"), is->filename);
122 }
123 }
124 }
125
126 /* We have seen it all. Allocate it, and carry on */
127 bfd_arm_allocate_interworking_sections (& link_info);
128}
129
130static void
0c7a8e5a 131gld${EMULATION_NAME}_after_open (void)
252b5132 132{
f11523b0 133 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
252b5132 134 {
f11523b0
NC
135 /* The arm backend needs special fields in the output hash structure.
136 These will only be created if the output format is an arm format,
137 hence we do not support linking and changing output formats at the
138 same time. Use a link followed by objcopy to change output formats. */
139 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
140 return;
252b5132 141 }
0c7a8e5a 142
f11523b0
NC
143 {
144 LANG_FOR_EACH_INPUT_STATEMENT (is)
145 {
146 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
147 break;
148 }
149 }
252b5132
RH
150}
151
6f798e5c 152static void
0c7a8e5a 153gld${EMULATION_NAME}_finish (void)
6f798e5c
NC
154{
155 struct bfd_link_hash_entry * h;
156
157 if (thumb_entry_symbol == NULL)
158 return;
0c7a8e5a 159
b34976b6
AM
160 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
161 FALSE, FALSE, TRUE);
6f798e5c
NC
162
163 if (h != (struct bfd_link_hash_entry *) NULL
164 && (h->type == bfd_link_hash_defined
165 || h->type == bfd_link_hash_defweak)
166 && h->u.def.section->output_section != NULL)
167 {
168 static char buffer[32];
169 bfd_vma val;
0c7a8e5a 170
6f798e5c
NC
171 /* Special procesing is required for a Thumb entry symbol. The
172 bottom bit of its address must be set. */
173 val = (h->u.def.value
174 + bfd_get_section_vma (output_bfd,
175 h->u.def.section->output_section)
176 + h->u.def.section->output_offset);
0c7a8e5a 177
6f798e5c
NC
178 val |= 1;
179
180 /* Now convert this value into a string and store it in entry_symbol
0c7a8e5a 181 where the lang_finish() function will pick it up. */
6f798e5c
NC
182 buffer[0] = '0';
183 buffer[1] = 'x';
0c7a8e5a 184
6f798e5c
NC
185 sprintf_vma (buffer + 2, val);
186
e3e942e9 187 if (entry_symbol.name != NULL && entry_from_cmdline)
6f798e5c 188 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
e3e942e9
AM
189 thumb_entry_symbol, entry_symbol.name);
190 entry_symbol.name = buffer;
6f798e5c
NC
191 }
192 else
193 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
194}
195
252b5132 196static char *
0c7a8e5a 197gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
198EOF
199
200if test -n "$COMPILE_IN"
201then
202# Scripts compiled in.
203
204# sed commands to quote an ld script as a C string.
597e2591 205sc="-f stringify.sed"
252b5132
RH
206
207cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 208{
252b5132
RH
209 *isfile = 0;
210
1049f94e 211 if (link_info.relocatable && config.build_constructors)
252b5132
RH
212 return
213EOF
b34976b6 214sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1049f94e 215echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
b34976b6
AM
216sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
217echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
218sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
219echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
220sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
221echo ' ; else return' >> e${EMULATION_NAME}.c
222sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
223echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
224
225else
226# Scripts read from the filesystem.
227
228cat >>e${EMULATION_NAME}.c <<EOF
0c7a8e5a 229{
252b5132
RH
230 *isfile = 1;
231
1049f94e 232 if (link_info.relocatable && config.build_constructors)
252b5132 233 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 234 else if (link_info.relocatable)
252b5132
RH
235 return "ldscripts/${EMULATION_NAME}.xr";
236 else if (!config.text_read_only)
237 return "ldscripts/${EMULATION_NAME}.xbn";
238 else if (!config.magic_demand_paged)
239 return "ldscripts/${EMULATION_NAME}.xn";
240 else
241 return "ldscripts/${EMULATION_NAME}.x";
242}
243EOF
244
245fi
246
247cat >>e${EMULATION_NAME}.c <<EOF
248
0c7a8e5a 249struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132
RH
250{
251 gld${EMULATION_NAME}_before_parse,
252 syslib_default,
253 hll_default,
254 after_parse_default,
255 gld${EMULATION_NAME}_after_open,
256 after_allocation_default,
257 set_output_arch_default,
258 ldemul_default_target,
259 gld${EMULATION_NAME}_before_allocation,
260 gld${EMULATION_NAME}_get_script,
261 "${EMULATION_NAME}",
262 "${OUTPUT_FORMAT}",
e1c47aa4
AM
263 gld${EMULATION_NAME}_finish,
264 NULL, /* create output section statements */
265 NULL, /* open dynamic archive */
266 NULL, /* place orphan */
267 NULL, /* set symbols */
3bcf5557
AM
268 NULL, /* parse_args */
269 gld${EMULATION_NAME}_add_options,
270 gld${EMULATION_NAME}_handle_option,
e1c47aa4
AM
271 NULL, /* unrecognised file */
272 gld${EMULATION_NAME}_list_options,
40d109bf 273 NULL, /* recognized file */
fac1652d
AM
274 NULL, /* find_potential_libraries */
275 NULL /* new_vers_pattern */
252b5132
RH
276};
277EOF
This page took 0.244853 seconds and 4 git commands to generate.