]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/linux.em
Update year range in copyright notice of binutils files
[thirdparty/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}
b3adc24a 12 Copyright (C) 1991-2020 Free Software Foundation, Inc.
252b5132
RH
13 Written by Steve Chamberlain <sac@cygnus.com>
14 Linux support by Eric Youngdale <ericy@cais.cais.com>
15
f96b4a7b 16 This file is part of the GNU Binutils.
252b5132 17
f96b4a7b
NC
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.
252b5132 22
f96b4a7b
NC
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.
252b5132 27
f96b4a7b
NC
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. */
252b5132
RH
32
33#define TARGET_IS_${EMULATION_NAME}
34
252b5132 35#include "sysdep.h"
3db64b00 36#include "bfd.h"
252b5132 37#include "bfdlink.h"
1ff6de03 38#include "ctf-api.h"
252b5132
RH
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/:.*//'`);
66be1055 52 input_flags.dynamic = TRUE;
b34976b6 53 config.has_shared = TRUE;
5c3261b0 54 link_info.check_relocs_after_open_input = TRUE;
576438f0 55 link_info.relro = DEFAULT_LD_Z_RELRO;
252b5132
RH
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
b34976b6 61static bfd_boolean
0c7a8e5a
AM
62gld${EMULATION_NAME}_open_dynamic_archive
63 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
252b5132
RH
64{
65 char *string;
66
d4ae5fb0 67 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
b34976b6 68 return FALSE;
252b5132
RH
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);
b34976b6 80 return FALSE;
252b5132
RH
81 }
82
83 entry->filename = string;
84
b34976b6 85 return TRUE;
252b5132
RH
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
95static void
0c7a8e5a 96gld${EMULATION_NAME}_find_address_statement (lang_statement_union_type *s)
252b5132
RH
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
108static void
0c7a8e5a 109gld${EMULATION_NAME}_create_output_section_statements (void)
252b5132
RH
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
117static void
0c7a8e5a 118gld${EMULATION_NAME}_before_allocation (void)
252b5132 119{
0e1862bb 120 if (bfd_link_relocatable (&link_info))
252b5132
RH
121 return;
122
123 /* Let the backend work out the sizes of any sections required by
124 dynamic linking. */
f13a99db
AM
125 if (! bfd_${EMULATION_NAME}_size_dynamic_sections (link_info.output_bfd,
126 &link_info))
df5f2391 127 einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
8423293d 128
1e035701 129 before_allocation_default ();
252b5132
RH
130}
131
132static char *
0c7a8e5a 133gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
134EOF
135
7225345d 136if test x"$COMPILE_IN" = xyes
252b5132
RH
137then
138# Scripts compiled in.
139
140# sed commands to quote an ld script as a C string.
597e2591 141sc="-f stringify.sed"
252b5132 142
92b93329 143fragment <<EOF
b34976b6 144{
252b5132
RH
145 *isfile = 0;
146
0e1862bb 147 if (bfd_link_relocatable (&link_info) && config.build_constructors)
597e2591 148 return
252b5132 149EOF
b34976b6 150sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
0e1862bb 151echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
b34976b6
AM
152sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
153echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
154sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
155echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
156sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
157echo ' ; else return' >> e${EMULATION_NAME}.c
158sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
159echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
160
161else
162# Scripts read from the filesystem.
163
92b93329 164fragment <<EOF
b34976b6 165{
252b5132
RH
166 *isfile = 1;
167
0e1862bb 168 if (bfd_link_relocatable (&link_info) && config.build_constructors)
252b5132 169 return "ldscripts/${EMULATION_NAME}.xu";
0e1862bb 170 else if (bfd_link_relocatable (&link_info))
252b5132
RH
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}
179EOF
180
181fi
182
92b93329 183fragment <<EOF
252b5132 184
b34976b6 185struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132
RH
186{
187 gld${EMULATION_NAME}_before_parse,
188 syslib_default,
189 hll_default,
190 after_parse_default,
191 after_open_default,
5c3261b0 192 after_check_relocs_default,
252b5132
RH
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}",
1e035701 200 finish_default,
252b5132 201 gld${EMULATION_NAME}_create_output_section_statements,
49bdcdba 202 gld${EMULATION_NAME}_open_dynamic_archive,
e1c47aa4
AM
203 NULL, /* place orphan */
204 NULL, /* set symbols */
205 NULL, /* parse args */
3bcf5557
AM
206 NULL, /* add_options */
207 NULL, /* handle_option */
e1c47aa4
AM
208 NULL, /* unrecognized file */
209 NULL, /* list options */
40d109bf 210 NULL, /* recognized file */
fac1652d 211 NULL, /* find_potential_libraries */
7a2f2d82 212 NULL, /* new_vers_pattern */
1ff6de03
NA
213 NULL, /* extra_map_file_text */
214 ${LDEMUL_EMIT_CTF_EARLY-NULL},
215 ${LDEMUL_EXAMINE_STRTAB_FOR_CTF-NULL}
252b5132
RH
216};
217EOF