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 /* 32 bit ELF emulation code for ${EMULATION_NAME}
7 Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
11 This file is part of GLD, the Gnu Linker.
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.
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.
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. */
27 #define TARGET_IS_${EMULATION_NAME}
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));
50 gld${EMULATION_NAME}_before_parse()
52 ldfile_output_architecture = bfd_arch_${ARCH};
53 config.dynamic_link = true;
56 /* This is called after the sections have been attached to output
57 sections, but before any sizes or addresses have been set. */
60 gld${EMULATION_NAME}_before_allocation ()
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);
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,
73 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
75 /* Let the user override the dynamic linker we are using. */
76 if (command_line.interpreter != NULL
79 sinterp->contents = (bfd_byte *) command_line.interpreter;
80 sinterp->_raw_size = strlen (command_line.interpreter) + 1;
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. */
90 gld${EMULATION_NAME}_find_statement_assignment (s)
91 lang_statement_union_type *s;
93 if (s->header.type == lang_assignment_statement_enum)
94 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
97 /* Look through an expression for an assignment statement. */
100 gld${EMULATION_NAME}_find_exp_assignment (exp)
103 switch (exp->type.node_class)
106 if (strcmp (exp->assign.dst, ".") != 0)
108 if (! bfd_elf32_record_link_assignment (output_bfd, &link_info,
110 einfo ("%P%F: failed to record assignment to %s: %E\n",
113 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
117 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
118 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
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);
128 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
137 gld${EMULATION_NAME}_get_script(isfile)
141 if test -n "$COMPILE_IN"
143 # Scripts compiled in.
145 # sed commands to quote an ld script as a C string.
152 cat >>e${EMULATION_NAME}.c <<EOF
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`;
165 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
170 # Scripts read from the filesystem.
172 cat >>e${EMULATION_NAME}.c <<EOF
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";
185 return "ldscripts/${EMULATION_NAME}.x";
191 cat >>e${EMULATION_NAME}.c <<EOF
193 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
195 gld${EMULATION_NAME}_before_parse,
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,