]> Git Repo - binutils.git/blob - ld/emultempl/elf32.em
Don't pass AS and ASFLAGS, it's now done in the testing code.
[binutils.git] / ld / emultempl / elf32.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 /* 32 bit ELF emulation code for ${EMULATION_NAME}
7    Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
8    Written by Steve Chamberlain <[email protected]>
9    ELF support by Ian Lance Taylor <[email protected]>
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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
26
27 #define TARGET_IS_${EMULATION_NAME}
28
29 #include "bfd.h"
30 #include "sysdep.h"
31 #include "bfdlink.h"
32
33 #include "ld.h"
34 #include "config.h"
35 #include "ldmain.h"
36 #include "ldemul.h"
37 #include "ldfile.h"
38 #include "ldmisc.h"
39 #include "ldexp.h"
40 #include "ldlang.h"
41
42 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
43 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
44 static void gld${EMULATION_NAME}_find_statement_assignment
45   PARAMS ((lang_statement_union_type *));
46 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
47 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
48
49 static void
50 gld${EMULATION_NAME}_before_parse()
51 {
52   ldfile_output_architecture = bfd_arch_${ARCH};
53   config.dynamic_link = true;
54 }
55
56 /* This is called after the sections have been attached to output
57    sections, but before any sizes or addresses have been set.  */
58
59 static void
60 gld${EMULATION_NAME}_before_allocation ()
61 {
62   asection *sinterp;
63
64   /* If we are going to make any variable assignments, we need to let
65      the ELF backend know about them in case the variables are
66      referred to by dynamic objects.  */
67   lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
68
69   /* Let the ELF backend work out the sizes of any sections required
70      by dynamic linking.  */
71   if (! bfd_elf32_size_dynamic_sections (output_bfd, &link_info,
72                                          &sinterp))
73     einfo ("%P%F: failed to set dynamic section sizes: %E\n");
74
75   /* Let the user override the dynamic linker we are using.  */
76   if (command_line.interpreter != NULL
77       && sinterp != NULL)
78     {
79       sinterp->contents = (bfd_byte *) command_line.interpreter;
80       sinterp->_raw_size = strlen (command_line.interpreter) + 1;
81     }
82 }
83
84 /* This is called by the before_allocation routine via
85    lang_for_each_statement.  It locates any assignment statements, and
86    tells the ELF backend about them, in case they are assignments to
87    symbols which are referred to by dynamic objects.  */
88
89 static void
90 gld${EMULATION_NAME}_find_statement_assignment (s)
91      lang_statement_union_type *s;
92 {
93   if (s->header.type == lang_assignment_statement_enum)
94     gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
95 }
96
97 /* Look through an expression for an assignment statement.  */
98
99 static void
100 gld${EMULATION_NAME}_find_exp_assignment (exp)
101      etree_type *exp;
102 {
103   switch (exp->type.node_class)
104     {
105     case etree_assign:
106       if (strcmp (exp->assign.dst, ".") != 0)
107         {
108           if (! bfd_elf32_record_link_assignment (output_bfd, &link_info,
109                                                   exp->assign.dst))
110             einfo ("%P%F: failed to record assignment to %s: %E\n",
111                    exp->assign.dst);
112         }
113       gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
114       break;
115
116     case etree_binary:
117       gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
118       gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
119       break;
120
121     case etree_trinary:
122       gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
123       gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
124       gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
125       break;
126
127     case etree_unary:
128       gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
129       break;
130
131     default:
132       break;
133     }
134 }
135
136 static char *
137 gld${EMULATION_NAME}_get_script(isfile)
138      int *isfile;
139 EOF
140
141 if test -n "$COMPILE_IN"
142 then
143 # Scripts compiled in.
144
145 # sed commands to quote an ld script as a C string.
146 sc='s/["\\]/\\&/g
147 s/$/\\n\\/
148 1s/^/"/
149 $s/$/n"/
150 '
151
152 cat >>e${EMULATION_NAME}.c <<EOF
153 {                            
154   *isfile = 0;
155
156   if (link_info.relocateable == true && config.build_constructors == true)
157     return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
158   else if (link_info.relocateable == true)
159     return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
160   else if (!config.text_read_only)
161     return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
162   else if (!config.magic_demand_paged)
163     return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
164   else
165     return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
166 }
167 EOF
168
169 else
170 # Scripts read from the filesystem.
171
172 cat >>e${EMULATION_NAME}.c <<EOF
173 {                            
174   *isfile = 1;
175
176   if (link_info.relocateable == true && config.build_constructors == true)
177     return "ldscripts/${EMULATION_NAME}.xu";
178   else if (link_info.relocateable == true)
179     return "ldscripts/${EMULATION_NAME}.xr";
180   else if (!config.text_read_only)
181     return "ldscripts/${EMULATION_NAME}.xbn";
182   else if (!config.magic_demand_paged)
183     return "ldscripts/${EMULATION_NAME}.xn";
184   else
185     return "ldscripts/${EMULATION_NAME}.x";
186 }
187 EOF
188
189 fi
190
191 cat >>e${EMULATION_NAME}.c <<EOF
192
193 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
194 {
195   gld${EMULATION_NAME}_before_parse,
196   syslib_default,
197   hll_default,
198   after_parse_default,
199   after_allocation_default,
200   set_output_arch_default,
201   ldemul_default_target,
202   gld${EMULATION_NAME}_before_allocation,
203   gld${EMULATION_NAME}_get_script,
204   "${EMULATION_NAME}",
205   "${OUTPUT_FORMAT}"
206 };
207 EOF
This page took 0.038965 seconds and 4 git commands to generate.