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