Thu Jun 16 14:25:22 1994 Eric Youngdale (ericy@cais.cais.com)
[deliverable/binutils-gdb.git] / ld / emultempl / elf32.em
CommitLineData
2a9fa50c
ILT
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3cat >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 <sac@cygnus.com>
9 ELF support by Ian Lance Taylor <ian@cygnus.com>
10
11This file is part of GLD, the Gnu Linker.
12
13This program is free software; you can redistribute it and/or modify
14it under the terms of the GNU General Public License as published by
15the Free Software Foundation; either version 2 of the License, or
16(at your option) any later version.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, 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
42static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
43static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
44static void gld${EMULATION_NAME}_find_statement_assignment
45 PARAMS ((lang_statement_union_type *));
46static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
47static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
48
49static void
50gld${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
59static void
60gld${EMULATION_NAME}_before_allocation ()
61{
7fb9ca5f
ILT
62 asection *sinterp;
63
2a9fa50c
ILT
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. */
7fb9ca5f
ILT
71 if (! bfd_elf32_size_dynamic_sections (output_bfd, &link_info,
72 &sinterp))
2a9fa50c 73 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
7fb9ca5f
ILT
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 }
2a9fa50c
ILT
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
89static void
90gld${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
99static void
100gld${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
136static char *
137gld${EMULATION_NAME}_get_script(isfile)
138 int *isfile;
139EOF
140
141if test -n "$COMPILE_IN"
142then
143# Scripts compiled in.
144
145# sed commands to quote an ld script as a C string.
146sc='s/["\\]/\\&/g
147s/$/\\n\\/
1481s/^/"/
149$s/$/n"/
150'
151
152cat >>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}
167EOF
168
169else
170# Scripts read from the filesystem.
171
172cat >>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}
187EOF
188
189fi
190
191cat >>e${EMULATION_NAME}.c <<EOF
192
193struct 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};
207EOF
This page took 0.033373 seconds and 4 git commands to generate.