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