Initial revision
[binutils.git] / ld / emultempl / armelf_oabi.em
blobc0526e5d6f7410413d371f4bb689ddcecb768a72
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 #define bfd_elf32_arm_allocate_interworking_sections \
29         bfd_elf32_arm_oabi_allocate_interworking_sections
30 #define bfd_elf32_arm_get_bfd_for_interworking \
31         bfd_elf32_arm_oabi_get_bfd_for_interworking
32 #define bfd_elf32_arm_process_before_allocation \
33         bfd_elf32_arm_oabi_process_before_allocation
35 #include "bfd.h"
36 #include "sysdep.h"
37 #include "bfdlink.h"
38 #include "getopt.h"
40 #include "ld.h"
41 #include "ldmain.h"
42 #include "ldemul.h"
43 #include "ldfile.h"
44 #include "ldmisc.h"
46 #include "ldexp.h"
47 #include "ldlang.h"
49 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
50 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
51 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
53 static void
54 gld${EMULATION_NAME}_before_parse ()
56 #ifndef TARGET_                 /* I.e., if not generic.  */
57   ldfile_set_output_arch ("`echo ${ARCH}`");
58 #endif /* not TARGET_ */
61 /* This is called after the sections have been attached to output
62    sections, but before any sizes or addresses have been set.  */
64 static void
65 gld${EMULATION_NAME}_before_allocation ()
67   /* we should be able to set the size of the interworking stub section */
69   /* Here we rummage through the found bfds to collect glue information */
70   /* FIXME: should this be based on a command line option? krk@cygnus.com */
71   {
72     LANG_FOR_EACH_INPUT_STATEMENT (is)
73       {
74         if (!bfd_elf32_arm_process_before_allocation (is->the_bfd, &link_info))
75           {
76             /* xgettext:c-format */
77             einfo (_("Errors encountered processing file %s"), is->filename);
78           }
79       }
80   }
82   /* We have seen it all. Allocate it, and carry on */
83   bfd_elf32_arm_allocate_interworking_sections (& link_info);
86 static void
87 gld${EMULATION_NAME}_after_open ()
90   LANG_FOR_EACH_INPUT_STATEMENT (is)
91     {
92       /* The interworking bfd must be the last one to be processed */
93       if (!is->next)
94          bfd_elf32_arm_get_bfd_for_interworking (is->the_bfd, & link_info);
95     }
98 static char *
99 gld${EMULATION_NAME}_get_script (isfile)
100      int *isfile;
103 if test -n "$COMPILE_IN"
104 then
105 # Scripts compiled in.
107 # sed commands to quote an ld script as a C string.
108 sc="-f ${srcdir}/emultempl/stringify.sed"
110 cat >>e${EMULATION_NAME}.c <<EOF
111 {                            
112   *isfile = 0;
114   if (link_info.relocateable == true && config.build_constructors == true)
115     return
117 sed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
118 echo '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
119 sed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
120 echo '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
121 sed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
122 echo '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
123 sed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
124 echo '  ; else return'                                     >> e${EMULATION_NAME}.c
125 sed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
126 echo '; }'                                                 >> e${EMULATION_NAME}.c
128 else
129 # Scripts read from the filesystem.
131 cat >>e${EMULATION_NAME}.c <<EOF
132 {                            
133   *isfile = 1;
135   if (link_info.relocateable == true && config.build_constructors == true)
136     return "ldscripts/${EMULATION_NAME}.xu";
137   else if (link_info.relocateable == true)
138     return "ldscripts/${EMULATION_NAME}.xr";
139   else if (!config.text_read_only)
140     return "ldscripts/${EMULATION_NAME}.xbn";
141   else if (!config.magic_demand_paged)
142     return "ldscripts/${EMULATION_NAME}.xn";
143   else
144     return "ldscripts/${EMULATION_NAME}.x";
150 cat >>e${EMULATION_NAME}.c <<EOF
152 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
154   gld${EMULATION_NAME}_before_parse,
155   syslib_default,
156   hll_default,
157   after_parse_default,
158   gld${EMULATION_NAME}_after_open,
159   after_allocation_default,
160   set_output_arch_default,
161   ldemul_default_target,
162   gld${EMULATION_NAME}_before_allocation,
163   gld${EMULATION_NAME}_get_script,
164   "${EMULATION_NAME}",
165   "${OUTPUT_FORMAT}",
166   NULL, /* finish */
167   NULL, /* create output section statements */
168   NULL, /* open dynamic archive */
169   NULL, /* place orphan */
170   NULL, /* set_symbols */
171   NULL,
172   NULL, /* unrecognised file */
173   NULL