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