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