1 | # This shell script emits a C file. -*- C -*-
|
---|
2 | # It does some substitutions.
|
---|
3 | if [ -z "$MACHINE" ]; then
|
---|
4 | OUTPUT_ARCH=${ARCH}
|
---|
5 | else
|
---|
6 | OUTPUT_ARCH=${ARCH}:${MACHINE}
|
---|
7 | fi
|
---|
8 | cat >e${EMULATION_NAME}.c <<EOF
|
---|
9 | /* This file is is generated by a shell script. DO NOT EDIT! */
|
---|
10 |
|
---|
11 | /* Linux a.out emulation code for ${EMULATION_NAME}
|
---|
12 | Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003
|
---|
13 | Free Software Foundation, Inc.
|
---|
14 | Written by Steve Chamberlain <sac@cygnus.com>
|
---|
15 | Linux support by Eric Youngdale <ericy@cais.cais.com>
|
---|
16 |
|
---|
17 | This file is part of GLD, the Gnu Linker.
|
---|
18 |
|
---|
19 | This program is free software; you can redistribute it and/or modify
|
---|
20 | it under the terms of the GNU General Public License as published by
|
---|
21 | the Free Software Foundation; either version 2 of the License, or
|
---|
22 | (at your option) any later version.
|
---|
23 |
|
---|
24 | This program is distributed in the hope that it will be useful,
|
---|
25 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
27 | GNU General Public License for more details.
|
---|
28 |
|
---|
29 | You should have received a copy of the GNU General Public License
|
---|
30 | along with this program; if not, write to the Free Software
|
---|
31 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
32 |
|
---|
33 | #define TARGET_IS_${EMULATION_NAME}
|
---|
34 |
|
---|
35 | #include "bfd.h"
|
---|
36 | #include "sysdep.h"
|
---|
37 | #include "bfdlink.h"
|
---|
38 |
|
---|
39 | #include "ld.h"
|
---|
40 | #include "ldmain.h"
|
---|
41 | #include "ldmisc.h"
|
---|
42 | #include "ldexp.h"
|
---|
43 | #include "ldlang.h"
|
---|
44 | #include "ldfile.h"
|
---|
45 | #include "ldemul.h"
|
---|
46 |
|
---|
47 | static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
|
---|
48 | static bfd_boolean gld${EMULATION_NAME}_open_dynamic_archive
|
---|
49 | PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
|
---|
50 | static void gld${EMULATION_NAME}_find_address_statement
|
---|
51 | PARAMS ((lang_statement_union_type *));
|
---|
52 | static void gld${EMULATION_NAME}_create_output_section_statements
|
---|
53 | PARAMS ((void));
|
---|
54 | static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
|
---|
55 | static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
|
---|
56 |
|
---|
57 | static void
|
---|
58 | gld${EMULATION_NAME}_before_parse()
|
---|
59 | {
|
---|
60 | const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
|
---|
61 | if (arch)
|
---|
62 | {
|
---|
63 | ldfile_output_architecture = arch->arch;
|
---|
64 | ldfile_output_machine = arch->mach;
|
---|
65 | ldfile_output_machine_name = arch->printable_name;
|
---|
66 | }
|
---|
67 | else
|
---|
68 | ldfile_output_architecture = bfd_arch_${ARCH};
|
---|
69 | config.dynamic_link = TRUE;
|
---|
70 | config.has_shared = TRUE;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /* Try to open a dynamic archive. This is where we know that Linux
|
---|
74 | dynamic libraries have an extension of .sa. */
|
---|
75 |
|
---|
76 | static bfd_boolean
|
---|
77 | gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
|
---|
78 | const char *arch;
|
---|
79 | search_dirs_type *search;
|
---|
80 | lang_input_statement_type *entry;
|
---|
81 | {
|
---|
82 | char *string;
|
---|
83 |
|
---|
84 | if (! entry->is_archive)
|
---|
85 | return FALSE;
|
---|
86 |
|
---|
87 | string = (char *) xmalloc (strlen (search->name)
|
---|
88 | + strlen (entry->filename)
|
---|
89 | + strlen (arch)
|
---|
90 | + sizeof "/lib.sa");
|
---|
91 |
|
---|
92 | sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch);
|
---|
93 |
|
---|
94 | if (! ldfile_try_open_bfd (string, entry))
|
---|
95 | {
|
---|
96 | free (string);
|
---|
97 | return FALSE;
|
---|
98 | }
|
---|
99 |
|
---|
100 | entry->filename = string;
|
---|
101 |
|
---|
102 | return TRUE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* This is called by the create_output_section_statements routine via
|
---|
106 | lang_for_each_statement. It locates any address assignment to
|
---|
107 | .text, and modifies it to include the size of the headers. This
|
---|
108 | causes -Ttext to mean the starting address of the header, rather
|
---|
109 | than the starting address of .text, which is compatible with other
|
---|
110 | Linux tools. */
|
---|
111 |
|
---|
112 | static void
|
---|
113 | gld${EMULATION_NAME}_find_address_statement (s)
|
---|
114 | lang_statement_union_type *s;
|
---|
115 | {
|
---|
116 | if (s->header.type == lang_address_statement_enum
|
---|
117 | && strcmp (s->address_statement.section_name, ".text") == 0)
|
---|
118 | {
|
---|
119 | ASSERT (s->address_statement.address->type.node_class == etree_value);
|
---|
120 | s->address_statement.address->value.value += 0x20;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* This is called before opening the input BFD's. */
|
---|
125 |
|
---|
126 | static void
|
---|
127 | gld${EMULATION_NAME}_create_output_section_statements ()
|
---|
128 | {
|
---|
129 | lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement);
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* This is called after the sections have been attached to output
|
---|
133 | sections, but before any sizes or addresses have been set. */
|
---|
134 |
|
---|
135 | static void
|
---|
136 | gld${EMULATION_NAME}_before_allocation ()
|
---|
137 | {
|
---|
138 | if (link_info.relocateable)
|
---|
139 | return;
|
---|
140 |
|
---|
141 | /* Let the backend work out the sizes of any sections required by
|
---|
142 | dynamic linking. */
|
---|
143 | if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info))
|
---|
144 | einfo ("%P%F: failed to set dynamic section sizes: %E\n");
|
---|
145 | }
|
---|
146 |
|
---|
147 | static char *
|
---|
148 | gld${EMULATION_NAME}_get_script(isfile)
|
---|
149 | int *isfile;
|
---|
150 | EOF
|
---|
151 |
|
---|
152 | if test -n "$COMPILE_IN"
|
---|
153 | then
|
---|
154 | # Scripts compiled in.
|
---|
155 |
|
---|
156 | # sed commands to quote an ld script as a C string.
|
---|
157 | sc="-f stringify.sed"
|
---|
158 |
|
---|
159 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
160 | {
|
---|
161 | *isfile = 0;
|
---|
162 |
|
---|
163 | if (link_info.relocateable && config.build_constructors)
|
---|
164 | return
|
---|
165 | EOF
|
---|
166 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
|
---|
167 | echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
|
---|
168 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
|
---|
169 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
|
---|
170 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
|
---|
171 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
|
---|
172 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
|
---|
173 | echo ' ; else return' >> e${EMULATION_NAME}.c
|
---|
174 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
|
---|
175 | echo '; }' >> e${EMULATION_NAME}.c
|
---|
176 |
|
---|
177 | else
|
---|
178 | # Scripts read from the filesystem.
|
---|
179 |
|
---|
180 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
181 | {
|
---|
182 | *isfile = 1;
|
---|
183 |
|
---|
184 | if (link_info.relocateable && config.build_constructors)
|
---|
185 | return "ldscripts/${EMULATION_NAME}.xu";
|
---|
186 | else if (link_info.relocateable)
|
---|
187 | return "ldscripts/${EMULATION_NAME}.xr";
|
---|
188 | else if (!config.text_read_only)
|
---|
189 | return "ldscripts/${EMULATION_NAME}.xbn";
|
---|
190 | else if (!config.magic_demand_paged)
|
---|
191 | return "ldscripts/${EMULATION_NAME}.xn";
|
---|
192 | else
|
---|
193 | return "ldscripts/${EMULATION_NAME}.x";
|
---|
194 | }
|
---|
195 | EOF
|
---|
196 |
|
---|
197 | fi
|
---|
198 |
|
---|
199 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
200 |
|
---|
201 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
|
---|
202 | {
|
---|
203 | gld${EMULATION_NAME}_before_parse,
|
---|
204 | syslib_default,
|
---|
205 | hll_default,
|
---|
206 | after_parse_default,
|
---|
207 | after_open_default,
|
---|
208 | after_allocation_default,
|
---|
209 | set_output_arch_default,
|
---|
210 | ldemul_default_target,
|
---|
211 | gld${EMULATION_NAME}_before_allocation,
|
---|
212 | gld${EMULATION_NAME}_get_script,
|
---|
213 | "${EMULATION_NAME}",
|
---|
214 | "${OUTPUT_FORMAT}",
|
---|
215 | NULL, /* finish */
|
---|
216 | gld${EMULATION_NAME}_create_output_section_statements,
|
---|
217 | gld${EMULATION_NAME}_open_dynamic_archive,
|
---|
218 | NULL, /* place orphan */
|
---|
219 | NULL, /* set symbols */
|
---|
220 | NULL, /* parse args */
|
---|
221 | NULL, /* add_options */
|
---|
222 | NULL, /* handle_option */
|
---|
223 | NULL, /* unrecognized file */
|
---|
224 | NULL, /* list options */
|
---|
225 | NULL, /* recognized file */
|
---|
226 | NULL, /* find_potential_libraries */
|
---|
227 | NULL /* new_vers_pattern */
|
---|
228 | };
|
---|
229 | EOF
|
---|