]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/linux.em
19990502 sourceware import
[thirdparty/binutils-gdb.git] / ld / emultempl / linux.em
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! */
5
6 /* Linux a.out emulation code for ${EMULATION_NAME}
7 Copyright (C) 1991, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
8 Written by Steve Chamberlain <sac@cygnus.com>
9 Linux support by Eric Youngdale <ericy@cais.cais.com>
10
11 This file is part of GLD, the Gnu Linker.
12
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.
17
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.
22
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "ldmain.h"
35 #include "ldemul.h"
36 #include "ldfile.h"
37 #include "ldmisc.h"
38 #include "ldexp.h"
39 #include "ldlang.h"
40
41 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
42 static boolean gld${EMULATION_NAME}_open_dynamic_archive
43 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
44 static void gld${EMULATION_NAME}_find_address_statement
45 PARAMS ((lang_statement_union_type *));
46 static void gld${EMULATION_NAME}_create_output_section_statements
47 PARAMS ((void));
48 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
49 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
50
51 static void
52 gld${EMULATION_NAME}_before_parse()
53 {
54 ldfile_output_architecture = bfd_arch_${ARCH};
55 config.dynamic_link = true;
56 config.has_shared = true;
57 }
58
59 /* Try to open a dynamic archive. This is where we know that Linux
60 dynamic libraries have an extension of .sa. */
61
62 static boolean
63 gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
64 const char *arch;
65 search_dirs_type *search;
66 lang_input_statement_type *entry;
67 {
68 char *string;
69
70 if (! entry->is_archive)
71 return false;
72
73 string = (char *) xmalloc (strlen (search->name)
74 + strlen (entry->filename)
75 + strlen (arch)
76 + sizeof "/lib.sa");
77
78 sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch);
79
80 if (! ldfile_try_open_bfd (string, entry))
81 {
82 free (string);
83 return false;
84 }
85
86 entry->filename = string;
87
88 return true;
89 }
90
91 /* This is called by the create_output_section_statements routine via
92 lang_for_each_statement. It locates any address assignment to
93 .text, and modifies it to include the size of the headers. This
94 causes -Ttext to mean the starting address of the header, rather
95 than the starting address of .text, which is compatible with other
96 Linux tools. */
97
98 static void
99 gld${EMULATION_NAME}_find_address_statement (s)
100 lang_statement_union_type *s;
101 {
102 if (s->header.type == lang_address_statement_enum
103 && strcmp (s->address_statement.section_name, ".text") == 0)
104 {
105 ASSERT (s->address_statement.address->type.node_class == etree_value);
106 s->address_statement.address->value.value += 0x20;
107 }
108 }
109
110 /* This is called before opening the input BFD's. */
111
112 static void
113 gld${EMULATION_NAME}_create_output_section_statements ()
114 {
115 lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement);
116 }
117
118 /* This is called after the sections have been attached to output
119 sections, but before any sizes or addresses have been set. */
120
121 static void
122 gld${EMULATION_NAME}_before_allocation ()
123 {
124 if (link_info.relocateable)
125 return;
126
127 /* Let the backend work out the sizes of any sections required by
128 dynamic linking. */
129 if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info))
130 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
131 }
132
133 static char *
134 gld${EMULATION_NAME}_get_script(isfile)
135 int *isfile;
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.
143 sc='s/["\\]/\\&/g
144 s/$/\\n\\/
145 1s/^/"/
146 $s/$/n"/
147 '
148
149 cat >>e${EMULATION_NAME}.c <<EOF
150 {
151 *isfile = 0;
152
153 if (link_info.relocateable == true && config.build_constructors == true)
154 return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
155 else if (link_info.relocateable == true)
156 return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
157 else if (!config.text_read_only)
158 return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
159 else if (!config.magic_demand_paged)
160 return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
161 else
162 return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
163 }
164 EOF
165
166 else
167 # Scripts read from the filesystem.
168
169 cat >>e${EMULATION_NAME}.c <<EOF
170 {
171 *isfile = 1;
172
173 if (link_info.relocateable == true && config.build_constructors == true)
174 return "ldscripts/${EMULATION_NAME}.xu";
175 else if (link_info.relocateable == true)
176 return "ldscripts/${EMULATION_NAME}.xr";
177 else if (!config.text_read_only)
178 return "ldscripts/${EMULATION_NAME}.xbn";
179 else if (!config.magic_demand_paged)
180 return "ldscripts/${EMULATION_NAME}.xn";
181 else
182 return "ldscripts/${EMULATION_NAME}.x";
183 }
184 EOF
185
186 fi
187
188 cat >>e${EMULATION_NAME}.c <<EOF
189
190 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
191 {
192 gld${EMULATION_NAME}_before_parse,
193 syslib_default,
194 hll_default,
195 after_parse_default,
196 after_open_default,
197 after_allocation_default,
198 set_output_arch_default,
199 ldemul_default_target,
200 gld${EMULATION_NAME}_before_allocation,
201 gld${EMULATION_NAME}_get_script,
202 "${EMULATION_NAME}",
203 "${OUTPUT_FORMAT}",
204 NULL,
205 gld${EMULATION_NAME}_create_output_section_statements,
206 gld${EMULATION_NAME}_open_dynamic_archive
207 };
208 EOF