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.
8 Written by Steve Chamberlain <sac@cygnus.com>
9 ELF support by Ian Lance Taylor <ian@cygnus.com>
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 ()
62 /* If we are going to make any variable assignments, we need to let
63 the ELF backend know about them in case the variables are
64 referred to by dynamic objects. */
65 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
67 /* Let the ELF backend work out the sizes of any sections required
68 by dynamic linking. */
69 if (! bfd_elf32_size_dynamic_sections (output_bfd, &link_info))
70 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
73 /* This is called by the before_allocation routine via
74 lang_for_each_statement. It locates any assignment statements, and
75 tells the ELF backend about them, in case they are assignments to
76 symbols which are referred to by dynamic objects. */
79 gld${EMULATION_NAME}_find_statement_assignment (s)
80 lang_statement_union_type *s;
82 if (s->header.type == lang_assignment_statement_enum)
83 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
86 /* Look through an expression for an assignment statement. */
89 gld${EMULATION_NAME}_find_exp_assignment (exp)
92 switch (exp->type.node_class)
95 if (strcmp (exp->assign.dst, ".") != 0)
97 if (! bfd_elf32_record_link_assignment (output_bfd, &link_info,
99 einfo ("%P%F: failed to record assignment to %s: %E\n",
102 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
106 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
107 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
111 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
112 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
113 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
117 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
126 gld${EMULATION_NAME}_get_script(isfile)
130 if test -n "$COMPILE_IN"
132 # Scripts compiled in.
134 # sed commands to quote an ld script as a C string.
141 cat >>e${EMULATION_NAME}.c <<EOF
145 if (link_info.relocateable == true && config.build_constructors == true)
146 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
147 else if (link_info.relocateable == true)
148 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
149 else if (!config.text_read_only)
150 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
151 else if (!config.magic_demand_paged)
152 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
154 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
159 # Scripts read from the filesystem.
161 cat >>e${EMULATION_NAME}.c <<EOF
165 if (link_info.relocateable == true && config.build_constructors == true)
166 return "ldscripts/${EMULATION_NAME}.xu";
167 else if (link_info.relocateable == true)
168 return "ldscripts/${EMULATION_NAME}.xr";
169 else if (!config.text_read_only)
170 return "ldscripts/${EMULATION_NAME}.xbn";
171 else if (!config.magic_demand_paged)
172 return "ldscripts/${EMULATION_NAME}.xn";
174 return "ldscripts/${EMULATION_NAME}.x";
180 cat >>e${EMULATION_NAME}.c <<EOF
182 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
184 gld${EMULATION_NAME}_before_parse,
188 after_allocation_default,
189 set_output_arch_default,
190 ldemul_default_target,
191 gld${EMULATION_NAME}_before_allocation,
192 gld${EMULATION_NAME}_get_script,