Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
b34976b6 | 3 | if [ -z "$MACHINE" ]; then |
86af25fe L |
4 | OUTPUT_ARCH=${ARCH} |
5 | else | |
6 | OUTPUT_ARCH=${ARCH}:${MACHINE} | |
7 | fi | |
252b5132 RH |
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} | |
3bcf5557 | 12 | Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003 |
b71e2778 | 13 | Free Software Foundation, Inc. |
252b5132 RH |
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" | |
252b5132 RH |
41 | #include "ldmisc.h" |
42 | #include "ldexp.h" | |
43 | #include "ldlang.h" | |
b71e2778 AM |
44 | #include "ldfile.h" |
45 | #include "ldemul.h" | |
252b5132 | 46 | |
252b5132 | 47 | static void |
0c7a8e5a | 48 | gld${EMULATION_NAME}_before_parse (void) |
252b5132 | 49 | { |
86af25fe L |
50 | const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}"); |
51 | if (arch) | |
52 | { | |
53 | ldfile_output_architecture = arch->arch; | |
54 | ldfile_output_machine = arch->mach; | |
55 | ldfile_output_machine_name = arch->printable_name; | |
56 | } | |
57 | else | |
58 | ldfile_output_architecture = bfd_arch_${ARCH}; | |
b34976b6 AM |
59 | config.dynamic_link = TRUE; |
60 | config.has_shared = TRUE; | |
252b5132 RH |
61 | } |
62 | ||
63 | /* Try to open a dynamic archive. This is where we know that Linux | |
64 | dynamic libraries have an extension of .sa. */ | |
65 | ||
b34976b6 | 66 | static bfd_boolean |
0c7a8e5a AM |
67 | gld${EMULATION_NAME}_open_dynamic_archive |
68 | (const char *arch, search_dirs_type *search, lang_input_statement_type *entry) | |
252b5132 RH |
69 | { |
70 | char *string; | |
71 | ||
72 | if (! entry->is_archive) | |
b34976b6 | 73 | return FALSE; |
252b5132 RH |
74 | |
75 | string = (char *) xmalloc (strlen (search->name) | |
76 | + strlen (entry->filename) | |
77 | + strlen (arch) | |
78 | + sizeof "/lib.sa"); | |
79 | ||
80 | sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch); | |
81 | ||
82 | if (! ldfile_try_open_bfd (string, entry)) | |
83 | { | |
84 | free (string); | |
b34976b6 | 85 | return FALSE; |
252b5132 RH |
86 | } |
87 | ||
88 | entry->filename = string; | |
89 | ||
b34976b6 | 90 | return TRUE; |
252b5132 RH |
91 | } |
92 | ||
93 | /* This is called by the create_output_section_statements routine via | |
94 | lang_for_each_statement. It locates any address assignment to | |
95 | .text, and modifies it to include the size of the headers. This | |
96 | causes -Ttext to mean the starting address of the header, rather | |
97 | than the starting address of .text, which is compatible with other | |
98 | Linux tools. */ | |
99 | ||
100 | static void | |
0c7a8e5a | 101 | gld${EMULATION_NAME}_find_address_statement (lang_statement_union_type *s) |
252b5132 RH |
102 | { |
103 | if (s->header.type == lang_address_statement_enum | |
104 | && strcmp (s->address_statement.section_name, ".text") == 0) | |
105 | { | |
106 | ASSERT (s->address_statement.address->type.node_class == etree_value); | |
107 | s->address_statement.address->value.value += 0x20; | |
108 | } | |
109 | } | |
110 | ||
111 | /* This is called before opening the input BFD's. */ | |
112 | ||
113 | static void | |
0c7a8e5a | 114 | gld${EMULATION_NAME}_create_output_section_statements (void) |
252b5132 RH |
115 | { |
116 | lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement); | |
117 | } | |
118 | ||
119 | /* This is called after the sections have been attached to output | |
120 | sections, but before any sizes or addresses have been set. */ | |
121 | ||
122 | static void | |
0c7a8e5a | 123 | gld${EMULATION_NAME}_before_allocation (void) |
252b5132 | 124 | { |
1049f94e | 125 | if (link_info.relocatable) |
252b5132 RH |
126 | return; |
127 | ||
128 | /* Let the backend work out the sizes of any sections required by | |
129 | dynamic linking. */ | |
130 | if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info)) | |
131 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); | |
132 | } | |
133 | ||
134 | static char * | |
0c7a8e5a | 135 | gld${EMULATION_NAME}_get_script (int *isfile) |
252b5132 RH |
136 | EOF |
137 | ||
138 | if test -n "$COMPILE_IN" | |
139 | then | |
140 | # Scripts compiled in. | |
141 | ||
142 | # sed commands to quote an ld script as a C string. | |
597e2591 | 143 | sc="-f stringify.sed" |
252b5132 RH |
144 | |
145 | cat >>e${EMULATION_NAME}.c <<EOF | |
b34976b6 | 146 | { |
252b5132 RH |
147 | *isfile = 0; |
148 | ||
1049f94e | 149 | if (link_info.relocatable && config.build_constructors) |
597e2591 | 150 | return |
252b5132 | 151 | EOF |
b34976b6 | 152 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1049f94e | 153 | echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
154 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
155 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
156 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
157 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
158 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
159 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
160 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
161 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
162 | |
163 | else | |
164 | # Scripts read from the filesystem. | |
165 | ||
166 | cat >>e${EMULATION_NAME}.c <<EOF | |
b34976b6 | 167 | { |
252b5132 RH |
168 | *isfile = 1; |
169 | ||
1049f94e | 170 | if (link_info.relocatable && config.build_constructors) |
252b5132 | 171 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 172 | else if (link_info.relocatable) |
252b5132 RH |
173 | return "ldscripts/${EMULATION_NAME}.xr"; |
174 | else if (!config.text_read_only) | |
175 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
176 | else if (!config.magic_demand_paged) | |
177 | return "ldscripts/${EMULATION_NAME}.xn"; | |
178 | else | |
179 | return "ldscripts/${EMULATION_NAME}.x"; | |
180 | } | |
181 | EOF | |
182 | ||
183 | fi | |
184 | ||
185 | cat >>e${EMULATION_NAME}.c <<EOF | |
186 | ||
b34976b6 | 187 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
252b5132 RH |
188 | { |
189 | gld${EMULATION_NAME}_before_parse, | |
190 | syslib_default, | |
191 | hll_default, | |
192 | after_parse_default, | |
193 | after_open_default, | |
194 | after_allocation_default, | |
195 | set_output_arch_default, | |
196 | ldemul_default_target, | |
197 | gld${EMULATION_NAME}_before_allocation, | |
198 | gld${EMULATION_NAME}_get_script, | |
199 | "${EMULATION_NAME}", | |
200 | "${OUTPUT_FORMAT}", | |
e1c47aa4 | 201 | NULL, /* finish */ |
252b5132 | 202 | gld${EMULATION_NAME}_create_output_section_statements, |
49bdcdba | 203 | gld${EMULATION_NAME}_open_dynamic_archive, |
e1c47aa4 AM |
204 | NULL, /* place orphan */ |
205 | NULL, /* set symbols */ | |
206 | NULL, /* parse args */ | |
3bcf5557 AM |
207 | NULL, /* add_options */ |
208 | NULL, /* handle_option */ | |
e1c47aa4 AM |
209 | NULL, /* unrecognized file */ |
210 | NULL, /* list options */ | |
40d109bf | 211 | NULL, /* recognized file */ |
fac1652d AM |
212 | NULL, /* find_potential_libraries */ |
213 | NULL /* new_vers_pattern */ | |
252b5132 RH |
214 | }; |
215 | EOF |