file make-gas.com was initially added on branch binutils-2_10-branch.
[binutils.git] / ld / emultempl / armcoff.em
blobd73b3d172fba3cb121661b4c06499b266795090e
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! */
6 /* emulate the original gld for the given ${EMULATION_NAME}
7    Copyright (C) 1991, 93, 96, 97, 98, 1999 Free Software Foundation, Inc.
8    Written by Steve Chamberlain steve@cygnus.com
10 This file is part of GLD, the Gnu Linker.
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 2 of the License, or
15 (at your option) any later version.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
26 #define TARGET_IS_${EMULATION_NAME}
28 #include "bfd.h"
29 #include "sysdep.h"
30 #include "bfdlink.h"
31 #include "getopt.h"
33 #include "ld.h"
34 #include "ldmain.h"
35 #include "ldemul.h"
36 #include "ldfile.h"
37 #include "ldmisc.h"
39 #include "ldexp.h"
40 #include "ldlang.h"
42 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
43 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
44 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
45 static int  gld${EMULATION_NAME}_parse_args PARAMS((int, char **));
46 static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
47 static void gld${EMULATION_NAME}_finish PARAMS ((void));
49 /* If true, then interworking stubs which support calls to old, non-interworking
50    aware ARM code should be generated.  */
52 static int support_old_code = 0;
53 static char * thumb_entry_symbol = NULL;
55 #define OPTION_SUPPORT_OLD_CODE         300
56 #define OPTION_THUMB_ENTRY              301
58 static struct option longopts[] =
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}
65 static void
66 gld${EMULATION_NAME}_list_options (file)
67      FILE * file;
69   fprintf (file, _("  --support-old-code   Support interworking with old code\n"));
70   fprintf (file, _("  --thumb-entry=<sym>  Set the entry point to be Thumb symbol <sym>\n"));
73 static int
74 gld${EMULATION_NAME}_parse_args (argc, argv)
75      int     argc;
76      char ** argv;
78   int        longind;
79   int        optc;
80   int        prevoptind = optind;
81   int        prevopterr = opterr;
82   int        wanterror;
83   static int lastoptind = -1;
85   if (lastoptind != optind)
86     opterr = 0;
87   
88   wanterror  = opterr;
89   lastoptind = optind;
91   optc   = getopt_long_only (argc, argv, "-", longopts, & longind);
92   opterr = prevopterr;
94   switch (optc)
95     {
96     default:
97       if (wanterror)
98         xexit (1);
99       optind =  prevoptind;
100       return 0;
102     case OPTION_SUPPORT_OLD_CODE:
103       support_old_code = 1;
104       break;
106     case OPTION_THUMB_ENTRY:
107       thumb_entry_symbol = optarg;
108       break;
109     }
110   
111   return 1;
114 static void
115 gld${EMULATION_NAME}_before_parse ()
117 #ifndef TARGET_                 /* I.e., if not generic.  */
118   ldfile_set_output_arch ("`echo ${ARCH}`");
119 #endif /* not TARGET_ */
122 /* This is called after the sections have been attached to output
123    sections, but before any sizes or addresses have been set.  */
125 static void
126 gld${EMULATION_NAME}_before_allocation ()
128   /* we should be able to set the size of the interworking stub section */
130   /* Here we rummage through the found bfds to collect glue information */
131   /* FIXME: should this be based on a command line option? krk@cygnus.com */
132   {
133     LANG_FOR_EACH_INPUT_STATEMENT (is)
134       {
135         if (! bfd_arm_process_before_allocation
136             (is->the_bfd, & link_info, support_old_code))
137           {
138             /* xgettext:c-format */
139             einfo (_("Errors encountered processing file %s"), is->filename);
140           }
141       }
142   }
144   /* We have seen it all. Allocate it, and carry on */
145   bfd_arm_allocate_interworking_sections (& link_info);
148 static void
149 gld${EMULATION_NAME}_after_open ()
151   if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
152     {
153       /* The arm backend needs special fields in the output hash structure.
154          These will only be created if the output format is an arm format,
155          hence we do not support linking and changing output formats at the
156          same time.  Use a link followed by objcopy to change output formats.  */
157       einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
158       return;
159     }
160   
161   {
162     LANG_FOR_EACH_INPUT_STATEMENT (is)
163       {
164         if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
165           break;
166       }
167   }
170 static void
171 gld${EMULATION_NAME}_finish PARAMS((void))
173   struct bfd_link_hash_entry * h;
175   if (thumb_entry_symbol == NULL)
176     return;
177   
178   h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
180   if (h != (struct bfd_link_hash_entry *) NULL
181       && (h->type == bfd_link_hash_defined
182           || h->type == bfd_link_hash_defweak)
183       && h->u.def.section->output_section != NULL)
184     {
185       static char buffer[32];
186       bfd_vma val;
187       
188       /* Special procesing is required for a Thumb entry symbol.  The
189          bottom bit of its address must be set.  */
190       val = (h->u.def.value
191              + bfd_get_section_vma (output_bfd,
192                                     h->u.def.section->output_section)
193              + h->u.def.section->output_offset);
194       
195       val |= 1;
197       /* Now convert this value into a string and store it in entry_symbol
198          where the lang_finish() function will pick it up.  */
199       buffer[0] = '0';
200       buffer[1] = 'x';
201       
202       sprintf_vma (buffer + 2, val);
204       if (entry_symbol != NULL && entry_from_cmdline)
205         einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
206                thumb_entry_symbol, entry_symbol);
207       entry_symbol = buffer;
208     }
209   else
210     einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
213 static char *
214 gld${EMULATION_NAME}_get_script (isfile)
215      int *isfile;
218 if test -n "$COMPILE_IN"
219 then
220 # Scripts compiled in.
222 # sed commands to quote an ld script as a C string.
223 sc="-f stringify.sed"
225 cat >>e${EMULATION_NAME}.c <<EOF
226 {                            
227   *isfile = 0;
229   if (link_info.relocateable == true && config.build_constructors == true)
230     return
232 sed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
233 echo '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
234 sed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
235 echo '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
236 sed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
237 echo '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
238 sed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
239 echo '  ; else return'                                     >> e${EMULATION_NAME}.c
240 sed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
241 echo '; }'                                                 >> e${EMULATION_NAME}.c
243 else
244 # Scripts read from the filesystem.
246 cat >>e${EMULATION_NAME}.c <<EOF
247 {                            
248   *isfile = 1;
250   if (link_info.relocateable == true && config.build_constructors == true)
251     return "ldscripts/${EMULATION_NAME}.xu";
252   else if (link_info.relocateable == true)
253     return "ldscripts/${EMULATION_NAME}.xr";
254   else if (!config.text_read_only)
255     return "ldscripts/${EMULATION_NAME}.xbn";
256   else if (!config.magic_demand_paged)
257     return "ldscripts/${EMULATION_NAME}.xn";
258   else
259     return "ldscripts/${EMULATION_NAME}.x";
265 cat >>e${EMULATION_NAME}.c <<EOF
267 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
269   gld${EMULATION_NAME}_before_parse,
270   syslib_default,
271   hll_default,
272   after_parse_default,
273   gld${EMULATION_NAME}_after_open,
274   after_allocation_default,
275   set_output_arch_default,
276   ldemul_default_target,
277   gld${EMULATION_NAME}_before_allocation,
278   gld${EMULATION_NAME}_get_script,
279   "${EMULATION_NAME}",
280   "${OUTPUT_FORMAT}",
281   gld${EMULATION_NAME}_finish,
282   NULL, /* create output section statements */
283   NULL, /* open dynamic archive */
284   NULL, /* place orphan */
285   NULL, /* set symbols */
286   gld${EMULATION_NAME}_parse_args,
287   NULL, /* unrecognised file */
288   gld${EMULATION_NAME}_list_options,
289   NULL, /* recognized file */
290   NULL  /* find_potential_libraries */