Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | # This file is now misnamed, because it supports both 32 bit and 64 bit | |
4 | # ELF emulations. | |
5 | test -z "${ELFSIZE}" && ELFSIZE=32 | |
86af25fe L |
6 | if [ -z "$MACHINE" ]; then |
7 | OUTPUT_ARCH=${ARCH} | |
8 | else | |
9 | OUTPUT_ARCH=${ARCH}:${MACHINE} | |
10 | fi | |
92b93329 | 11 | fragment <<EOF |
252b5132 RH |
12 | /* This file is is generated by a shell script. DO NOT EDIT! */ |
13 | ||
14 | /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME} | |
6f2750fe | 15 | Copyright (C) 1991-2016 Free Software Foundation, Inc. |
252b5132 RH |
16 | Written by Steve Chamberlain <sac@cygnus.com> |
17 | ELF support by Ian Lance Taylor <ian@cygnus.com> | |
18 | ||
f96b4a7b NC |
19 | This file is part of the GNU Binutils. |
20 | ||
21 | This program is free software; you can redistribute it and/or modify | |
22 | it under the terms of the GNU General Public License as published by | |
23 | the Free Software Foundation; either version 3 of the License, or | |
24 | (at your option) any later version. | |
25 | ||
26 | This program is distributed in the hope that it will be useful, | |
27 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29 | GNU General Public License for more details. | |
30 | ||
31 | You should have received a copy of the GNU General Public License | |
32 | along with this program; if not, write to the Free Software | |
33 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
34 | MA 02110-1301, USA. */ | |
252b5132 RH |
35 | |
36 | #define TARGET_IS_${EMULATION_NAME} | |
37 | ||
252b5132 | 38 | #include "sysdep.h" |
3db64b00 | 39 | #include "bfd.h" |
1c9acd94 | 40 | #include "libiberty.h" |
8056826a | 41 | #include "safe-ctype.h" |
42627821 | 42 | #include "filenames.h" |
fcf65871 | 43 | #include "getopt.h" |
24382dca | 44 | #include <fcntl.h> |
252b5132 RH |
45 | |
46 | #include "bfdlink.h" | |
47 | ||
48 | #include "ld.h" | |
49 | #include "ldmain.h" | |
252b5132 RH |
50 | #include "ldmisc.h" |
51 | #include "ldexp.h" | |
52 | #include "ldlang.h" | |
b71e2778 AM |
53 | #include "ldfile.h" |
54 | #include "ldemul.h" | |
61e2488c | 55 | #include "ldbuildid.h" |
df2a7313 | 56 | #include <ldgram.h> |
e0ee487b | 57 | #include "elf/common.h" |
ecca9871 | 58 | #include "elf-bfd.h" |
07f1e47a | 59 | #include "filenames.h" |
252b5132 | 60 | |
0c7a8e5a AM |
61 | /* Declare functions used by various EXTRA_EM_FILEs. */ |
62 | static void gld${EMULATION_NAME}_before_parse (void); | |
5fe2850d | 63 | static void gld${EMULATION_NAME}_after_parse (void); |
0c7a8e5a AM |
64 | static void gld${EMULATION_NAME}_after_open (void); |
65 | static void gld${EMULATION_NAME}_before_allocation (void); | |
eaeb0a9d | 66 | static void gld${EMULATION_NAME}_after_allocation (void); |
c2edb4b8 | 67 | static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan |
8a99a385 | 68 | (asection *, const char *, int); |
41392f03 AM |
69 | EOF |
70 | ||
d3989512 JJ |
71 | if [ "x${USE_LIBPATH}" = xyes ] ; then |
72 | case ${target} in | |
a5244b7e | 73 | *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*) |
92b93329 | 74 | fragment <<EOF |
0b48acfe | 75 | #ifdef HAVE_GLOB |
d3989512 | 76 | #include <glob.h> |
0b48acfe | 77 | #endif |
d3989512 JJ |
78 | EOF |
79 | ;; | |
80 | esac | |
81 | fi | |
82 | ||
41392f03 AM |
83 | # Import any needed special functions and/or overrides. |
84 | # | |
92b93329 | 85 | source_em ${srcdir}/emultempl/elf-generic.em |
41392f03 | 86 | if test -n "$EXTRA_EM_FILE" ; then |
92b93329 | 87 | source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em |
41392f03 AM |
88 | fi |
89 | ||
f813923c | 90 | # Functions in this file can be overridden by setting the LDEMUL_* shell |
41392f03 AM |
91 | # variables. If the name of the overriding function is the same as is |
92 | # defined in this file, then don't output this file's version. | |
93 | # If a different overriding name is given then output the standard function | |
94 | # as presumably it is called from the overriding function. | |
95 | # | |
96 | if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then | |
92b93329 | 97 | fragment <<EOF |
41392f03 | 98 | |
252b5132 | 99 | static void |
0c7a8e5a | 100 | gld${EMULATION_NAME}_before_parse (void) |
252b5132 | 101 | { |
5e2f1575 | 102 | ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); |
66be1055 | 103 | input_flags.dynamic = ${DYNAMIC_LINK-TRUE}; |
b34976b6 | 104 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; |
4724d37e | 105 | config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
caa65211 | 106 | `if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`; |
d9689752 | 107 | link_info.check_relocs_after_open_input = `if test "x${CHECK_RELOCS_AFTER_OPEN_INPUT}" = xyes ; then echo TRUE ; else echo FALSE ; fi`; |
663fa543 L |
108 | } |
109 | ||
822b8bf4 | 110 | EOF |
663fa543 | 111 | fi |
822b8bf4 | 112 | |
5fe2850d L |
113 | if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then |
114 | fragment <<EOF | |
115 | ||
116 | static void | |
117 | gld${EMULATION_NAME}_after_parse (void) | |
118 | { | |
119 | if (bfd_link_pie (&link_info)) | |
120 | link_info.flags_1 |= (bfd_vma) DF_1_PIE; | |
121 | ||
122 | after_parse_default (); | |
123 | } | |
124 | ||
125 | EOF | |
126 | fi | |
127 | ||
4a43e768 | 128 | if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then |
92b93329 | 129 | fragment <<EOF |
ddbb8a31 | 130 | /* Handle the generation of DT_NEEDED tags. */ |
4a43e768 AM |
131 | |
132 | static bfd_boolean | |
133 | gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry) | |
134 | { | |
96d56e9f | 135 | int link_class = 0; |
4a43e768 AM |
136 | |
137 | /* Tell the ELF linker that we don't want the output file to have a | |
138 | DT_NEEDED entry for this file, unless it is used to resolve | |
139 | references in a regular object. */ | |
66be1055 | 140 | if (entry->flags.add_DT_NEEDED_for_regular) |
96d56e9f | 141 | link_class = DYN_AS_NEEDED; |
e56f61be L |
142 | |
143 | /* Tell the ELF linker that we don't want the output file to have a | |
144 | DT_NEEDED entry for any dynamic library in DT_NEEDED tags from | |
145 | this file at all. */ | |
66be1055 | 146 | if (!entry->flags.add_DT_NEEDED_for_dynamic) |
96d56e9f | 147 | link_class |= DYN_NO_ADD_NEEDED; |
e56f61be | 148 | |
66be1055 | 149 | if (entry->flags.just_syms |
12b9ff6c L |
150 | && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0) |
151 | einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"), | |
152 | entry->the_bfd); | |
153 | ||
ddbb8a31 | 154 | if (link_class == 0 |
e56f61be L |
155 | || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0) |
156 | return FALSE; | |
157 | ||
1e9cc1c2 | 158 | bfd_elf_set_dyn_lib_class (entry->the_bfd, |
4724d37e | 159 | (enum dynamic_lib_link_class) link_class); |
4a43e768 AM |
160 | |
161 | /* Continue on with normal load_symbols processing. */ | |
162 | return FALSE; | |
163 | } | |
164 | EOF | |
165 | fi | |
166 | ||
92b93329 | 167 | fragment <<EOF |
252b5132 RH |
168 | |
169 | /* These variables are required to pass information back and forth | |
170 | between after_open and check_needed and stat_needed and vercheck. */ | |
171 | ||
172 | static struct bfd_link_needed_list *global_needed; | |
173 | static struct stat global_stat; | |
e13629bc | 174 | static lang_input_statement_type *global_found; |
252b5132 | 175 | static struct bfd_link_needed_list *global_vercheck_needed; |
b34976b6 | 176 | static bfd_boolean global_vercheck_failed; |
252b5132 | 177 | |
7ee314fa AM |
178 | /* These variables are used to implement target options */ |
179 | ||
180 | static char *audit; /* colon (typically) separated list of libs */ | |
181 | static char *depaudit; /* colon (typically) separated list of libs */ | |
252b5132 | 182 | |
30e8ee25 AM |
183 | /* Style of .note.gnu.build-id section. */ |
184 | static const char *emit_note_gnu_build_id; | |
185 | ||
04925e1e AM |
186 | /* On Linux, it's possible to have different versions of the same |
187 | shared library linked against different versions of libc. The | |
188 | dynamic linker somehow tags which libc version to use in | |
189 | /etc/ld.so.cache, and, based on the libc that it sees in the | |
190 | executable, chooses which version of the shared library to use. | |
252b5132 | 191 | |
04925e1e AM |
192 | We try to do a similar check here by checking whether this shared |
193 | library needs any other shared libraries which may conflict with | |
194 | libraries we have already included in the link. If it does, we | |
195 | skip it, and try to find another shared library farther on down the | |
196 | link path. | |
252b5132 | 197 | |
04925e1e AM |
198 | This is called via lang_for_each_input_file. |
199 | GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object | |
f813923c | 200 | which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find |
04925e1e | 201 | a conflicting version. */ |
252b5132 | 202 | |
04925e1e | 203 | static void |
0c7a8e5a | 204 | gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s) |
04925e1e | 205 | { |
1c9acd94 | 206 | const char *soname; |
04925e1e | 207 | struct bfd_link_needed_list *l; |
252b5132 | 208 | |
04925e1e AM |
209 | if (global_vercheck_failed) |
210 | return; | |
211 | if (s->the_bfd == NULL | |
212 | || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0) | |
213 | return; | |
252b5132 | 214 | |
04925e1e AM |
215 | soname = bfd_elf_get_dt_soname (s->the_bfd); |
216 | if (soname == NULL) | |
fed2999d | 217 | soname = lbasename (bfd_get_filename (s->the_bfd)); |
04925e1e AM |
218 | |
219 | for (l = global_vercheck_needed; l != NULL; l = l->next) | |
220 | { | |
221 | const char *suffix; | |
222 | ||
42627821 | 223 | if (filename_cmp (soname, l->name) == 0) |
04925e1e AM |
224 | { |
225 | /* Probably can't happen, but it's an easy check. */ | |
226 | continue; | |
252b5132 RH |
227 | } |
228 | ||
04925e1e | 229 | if (strchr (l->name, '/') != NULL) |
252b5132 RH |
230 | continue; |
231 | ||
04925e1e AM |
232 | suffix = strstr (l->name, ".so."); |
233 | if (suffix == NULL) | |
234 | continue; | |
235 | ||
236 | suffix += sizeof ".so." - 1; | |
237 | ||
42627821 | 238 | if (filename_ncmp (soname, l->name, suffix - l->name) == 0) |
04925e1e AM |
239 | { |
240 | /* Here we know that S is a dynamic object FOO.SO.VER1, and | |
0c7a8e5a AM |
241 | the object we are considering needs a dynamic object |
242 | FOO.SO.VER2, and VER1 and VER2 are different. This | |
243 | appears to be a version mismatch, so we tell the caller | |
244 | to try a different version of this library. */ | |
b34976b6 | 245 | global_vercheck_failed = TRUE; |
04925e1e AM |
246 | return; |
247 | } | |
252b5132 RH |
248 | } |
249 | } | |
250 | ||
252b5132 | 251 | |
04925e1e AM |
252 | /* See if an input file matches a DT_NEEDED entry by running stat on |
253 | the file. */ | |
254 | ||
255 | static void | |
0c7a8e5a | 256 | gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s) |
252b5132 | 257 | { |
04925e1e AM |
258 | struct stat st; |
259 | const char *suffix; | |
260 | const char *soname; | |
252b5132 | 261 | |
e13629bc | 262 | if (global_found != NULL) |
04925e1e AM |
263 | return; |
264 | if (s->the_bfd == NULL) | |
265 | return; | |
e13629bc AM |
266 | |
267 | /* If this input file was an as-needed entry, and wasn't found to be | |
268 | needed at the stage it was linked, then don't say we have loaded it. */ | |
269 | if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0) | |
7cedef86 | 270 | return; |
04925e1e AM |
271 | |
272 | if (bfd_stat (s->the_bfd, &st) != 0) | |
252b5132 | 273 | { |
04925e1e AM |
274 | einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd); |
275 | return; | |
276 | } | |
252b5132 | 277 | |
9eabd475 ZW |
278 | /* Some operating systems, e.g. Windows, do not provide a meaningful |
279 | st_ino; they always set it to zero. (Windows does provide a | |
280 | meaningful st_dev.) Do not indicate a duplicate library in that | |
281 | case. While there is no guarantee that a system that provides | |
282 | meaningful inode numbers will never set st_ino to zero, this is | |
283 | merely an optimization, so we do not need to worry about false | |
284 | negatives. */ | |
04925e1e | 285 | if (st.st_dev == global_stat.st_dev |
9eabd475 ZW |
286 | && st.st_ino == global_stat.st_ino |
287 | && st.st_ino != 0) | |
04925e1e | 288 | { |
e13629bc | 289 | global_found = s; |
04925e1e AM |
290 | return; |
291 | } | |
252b5132 | 292 | |
04925e1e AM |
293 | /* We issue a warning if it looks like we are including two |
294 | different versions of the same shared library. For example, | |
295 | there may be a problem if -lc picks up libc.so.6 but some other | |
296 | shared library has a DT_NEEDED entry of libc.so.5. This is a | |
f813923c | 297 | heuristic test, and it will only work if the name looks like |
04925e1e AM |
298 | NAME.so.VERSION. FIXME: Depending on file names is error-prone. |
299 | If we really want to issue warnings about mixing version numbers | |
300 | of shared libraries, we need to find a better way. */ | |
252b5132 | 301 | |
04925e1e AM |
302 | if (strchr (global_needed->name, '/') != NULL) |
303 | return; | |
304 | suffix = strstr (global_needed->name, ".so."); | |
305 | if (suffix == NULL) | |
306 | return; | |
307 | suffix += sizeof ".so." - 1; | |
252b5132 | 308 | |
04925e1e AM |
309 | soname = bfd_elf_get_dt_soname (s->the_bfd); |
310 | if (soname == NULL) | |
fed2999d | 311 | soname = lbasename (s->filename); |
252b5132 | 312 | |
42627821 | 313 | if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0) |
04925e1e | 314 | einfo ("%P: warning: %s, needed by %B, may conflict with %s\n", |
1c9acd94 | 315 | global_needed->name, global_needed->by, soname); |
252b5132 RH |
316 | } |
317 | ||
e56f61be L |
318 | struct dt_needed |
319 | { | |
320 | bfd *by; | |
321 | const char *name; | |
322 | }; | |
04925e1e | 323 | |
252b5132 RH |
324 | /* This function is called for each possible name for a dynamic object |
325 | named by a DT_NEEDED entry. The FORCE parameter indicates whether | |
326 | to skip the check for a conflicting version. */ | |
327 | ||
b34976b6 | 328 | static bfd_boolean |
e56f61be L |
329 | gld${EMULATION_NAME}_try_needed (struct dt_needed *needed, |
330 | int force) | |
252b5132 RH |
331 | { |
332 | bfd *abfd; | |
e56f61be | 333 | const char *name = needed->name; |
ec4eb78a | 334 | const char *soname; |
96d56e9f | 335 | int link_class; |
252b5132 | 336 | |
f13a99db | 337 | abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd)); |
252b5132 | 338 | if (abfd == NULL) |
b34976b6 | 339 | return FALSE; |
4a114e3e L |
340 | |
341 | /* Linker needs to decompress sections. */ | |
342 | abfd->flags |= BFD_DECOMPRESS; | |
343 | ||
252b5132 RH |
344 | if (! bfd_check_format (abfd, bfd_object)) |
345 | { | |
cde43e70 | 346 | bfd_close (abfd); |
b34976b6 | 347 | return FALSE; |
252b5132 RH |
348 | } |
349 | if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) | |
350 | { | |
cde43e70 | 351 | bfd_close (abfd); |
b34976b6 | 352 | return FALSE; |
252b5132 RH |
353 | } |
354 | ||
c4bb8067 | 355 | /* For DT_NEEDED, they have to match. */ |
f13a99db | 356 | if (abfd->xvec != link_info.output_bfd->xvec) |
c4bb8067 L |
357 | { |
358 | bfd_close (abfd); | |
b34976b6 | 359 | return FALSE; |
c4bb8067 L |
360 | } |
361 | ||
252b5132 RH |
362 | /* Check whether this object would include any conflicting library |
363 | versions. If FORCE is set, then we skip this check; we use this | |
364 | the second time around, if we couldn't find any compatible | |
365 | instance of the shared library. */ | |
366 | ||
367 | if (! force) | |
368 | { | |
91d6fa6a | 369 | struct bfd_link_needed_list *needs; |
252b5132 | 370 | |
91d6fa6a | 371 | if (! bfd_elf_get_bfd_needed_list (abfd, &needs)) |
252b5132 RH |
372 | einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd); |
373 | ||
91d6fa6a | 374 | if (needs != NULL) |
252b5132 | 375 | { |
91d6fa6a | 376 | global_vercheck_needed = needs; |
b34976b6 | 377 | global_vercheck_failed = FALSE; |
252b5132 RH |
378 | lang_for_each_input_file (gld${EMULATION_NAME}_vercheck); |
379 | if (global_vercheck_failed) | |
380 | { | |
cde43e70 | 381 | bfd_close (abfd); |
b34976b6 | 382 | /* Return FALSE to force the caller to move on to try |
0c7a8e5a | 383 | another file on the search path. */ |
b34976b6 | 384 | return FALSE; |
252b5132 RH |
385 | } |
386 | ||
387 | /* But wait! It gets much worse. On Linux, if a shared | |
0c7a8e5a AM |
388 | library does not use libc at all, we are supposed to skip |
389 | it the first time around in case we encounter a shared | |
390 | library later on with the same name which does use the | |
391 | version of libc that we want. This is much too horrible | |
392 | to use on any system other than Linux. */ | |
252b5132 RH |
393 | |
394 | EOF | |
395 | case ${target} in | |
a5244b7e | 396 | *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*) |
92b93329 | 397 | fragment <<EOF |
252b5132 RH |
398 | { |
399 | struct bfd_link_needed_list *l; | |
400 | ||
91d6fa6a | 401 | for (l = needs; l != NULL; l = l->next) |
0112cd26 | 402 | if (CONST_STRNEQ (l->name, "libc.so")) |
252b5132 RH |
403 | break; |
404 | if (l == NULL) | |
405 | { | |
cde43e70 | 406 | bfd_close (abfd); |
b34976b6 | 407 | return FALSE; |
252b5132 RH |
408 | } |
409 | } | |
410 | ||
411 | EOF | |
412 | ;; | |
413 | esac | |
92b93329 | 414 | fragment <<EOF |
252b5132 RH |
415 | } |
416 | } | |
417 | ||
418 | /* We've found a dynamic object matching the DT_NEEDED entry. */ | |
419 | ||
04925e1e AM |
420 | /* We have already checked that there is no other input file of the |
421 | same name. We must now check again that we are not including the | |
422 | same file twice. We need to do this because on many systems | |
423 | libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will | |
424 | reference libc.so.1. If we have already included libc.so, we | |
425 | don't want to include libc.so.1 if they are the same file, and we | |
426 | can only check that using stat. */ | |
427 | ||
428 | if (bfd_stat (abfd, &global_stat) != 0) | |
429 | einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd); | |
ec4eb78a L |
430 | |
431 | /* First strip off everything before the last '/'. */ | |
fed2999d | 432 | soname = lbasename (abfd->filename); |
ec4eb78a | 433 | |
cd6f1cf3 | 434 | if (verbose) |
ec4eb78a L |
435 | info_msg (_("found %s at %s\n"), soname, name); |
436 | ||
e13629bc | 437 | global_found = NULL; |
04925e1e | 438 | lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); |
e13629bc | 439 | if (global_found != NULL) |
04925e1e | 440 | { |
b34976b6 | 441 | /* Return TRUE to indicate that we found the file, even though |
0c7a8e5a | 442 | we aren't going to do anything with it. */ |
b34976b6 | 443 | return TRUE; |
04925e1e AM |
444 | } |
445 | ||
4a43e768 AM |
446 | /* Specify the soname to use. */ |
447 | bfd_elf_set_dt_needed_name (abfd, soname); | |
04925e1e | 448 | |
4a43e768 AM |
449 | /* Tell the ELF linker that we don't want the output file to have a |
450 | DT_NEEDED entry for this file, unless it is used to resolve | |
451 | references in a regular object. */ | |
96d56e9f | 452 | link_class = DYN_DT_NEEDED; |
e56f61be L |
453 | |
454 | /* Tell the ELF linker that we don't want the output file to have a | |
455 | DT_NEEDED entry for this file at all if the entry is from a file | |
456 | with DYN_NO_ADD_NEEDED. */ | |
7e9f0867 AM |
457 | if (needed->by != NULL |
458 | && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0) | |
96d56e9f | 459 | link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED; |
e56f61be | 460 | |
1e9cc1c2 | 461 | bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class); |
04925e1e AM |
462 | |
463 | /* Add this file into the symbol table. */ | |
464 | if (! bfd_link_add_symbols (abfd, &link_info)) | |
8ff4c1f3 | 465 | einfo ("%F%B: error adding symbols: %E\n", abfd); |
04925e1e | 466 | |
b34976b6 | 467 | return TRUE; |
04925e1e AM |
468 | } |
469 | ||
470 | ||
471 | /* Search for a needed file in a path. */ | |
472 | ||
b34976b6 | 473 | static bfd_boolean |
e56f61be L |
474 | gld${EMULATION_NAME}_search_needed (const char *path, |
475 | struct dt_needed *n, int force) | |
04925e1e AM |
476 | { |
477 | const char *s; | |
e56f61be | 478 | const char *name = n->name; |
04925e1e | 479 | size_t len; |
e56f61be | 480 | struct dt_needed needed; |
04925e1e | 481 | |
cc5ce052 | 482 | if (name[0] == '/') |
e56f61be | 483 | return gld${EMULATION_NAME}_try_needed (n, force); |
cc5ce052 | 484 | |
04925e1e | 485 | if (path == NULL || *path == '\0') |
b34976b6 | 486 | return FALSE; |
e56f61be L |
487 | |
488 | needed.by = n->by; | |
489 | needed.name = n->name; | |
490 | ||
04925e1e AM |
491 | len = strlen (name); |
492 | while (1) | |
493 | { | |
494 | char *filename, *sset; | |
495 | ||
c76308d2 | 496 | s = strchr (path, config.rpath_separator); |
04925e1e AM |
497 | if (s == NULL) |
498 | s = path + strlen (path); | |
499 | ||
07f1e47a AM |
500 | #if HAVE_DOS_BASED_FILE_SYSTEM |
501 | /* Assume a match on the second char is part of drive specifier. */ | |
502 | else if (config.rpath_separator == ':' | |
503 | && s == path + 1 | |
504 | && ISALPHA (*path)) | |
505 | { | |
506 | s = strchr (s + 1, config.rpath_separator); | |
507 | if (s == NULL) | |
508 | s = path + strlen (path); | |
509 | } | |
510 | #endif | |
04925e1e AM |
511 | filename = (char *) xmalloc (s - path + len + 2); |
512 | if (s == path) | |
513 | sset = filename; | |
514 | else | |
515 | { | |
516 | memcpy (filename, path, s - path); | |
517 | filename[s - path] = '/'; | |
518 | sset = filename + (s - path) + 1; | |
519 | } | |
520 | strcpy (sset, name); | |
521 | ||
e56f61be L |
522 | needed.name = filename; |
523 | if (gld${EMULATION_NAME}_try_needed (&needed, force)) | |
b34976b6 | 524 | return TRUE; |
04925e1e AM |
525 | |
526 | free (filename); | |
527 | ||
528 | if (*s == '\0') | |
529 | break; | |
530 | path = s + 1; | |
531 | } | |
532 | ||
b34976b6 | 533 | return FALSE; |
04925e1e AM |
534 | } |
535 | ||
536 | EOF | |
9c8ebd6a | 537 | if [ "x${USE_LIBPATH}" = xyes ] ; then |
92b93329 | 538 | fragment <<EOF |
9c8ebd6a | 539 | |
c76308d2 RS |
540 | /* Add the sysroot to every entry in a path separated by |
541 | config.rpath_separator. */ | |
9c8ebd6a DJ |
542 | |
543 | static char * | |
0c7a8e5a | 544 | gld${EMULATION_NAME}_add_sysroot (const char *path) |
9c8ebd6a DJ |
545 | { |
546 | int len, colons, i; | |
547 | char *ret, *p; | |
548 | ||
549 | len = strlen (path); | |
550 | colons = 0; | |
551 | i = 0; | |
552 | while (path[i]) | |
c76308d2 | 553 | if (path[i++] == config.rpath_separator) |
9c8ebd6a DJ |
554 | colons++; |
555 | ||
556 | if (path[i]) | |
557 | colons++; | |
558 | ||
42644a89 | 559 | len = len + (colons + 1) * strlen (ld_sysroot); |
9c8ebd6a DJ |
560 | ret = xmalloc (len + 1); |
561 | strcpy (ret, ld_sysroot); | |
562 | p = ret + strlen (ret); | |
563 | i = 0; | |
564 | while (path[i]) | |
c76308d2 | 565 | if (path[i] == config.rpath_separator) |
9c8ebd6a | 566 | { |
0c7a8e5a | 567 | *p++ = path[i++]; |
9c8ebd6a DJ |
568 | strcpy (p, ld_sysroot); |
569 | p = p + strlen (p); | |
9c8ebd6a DJ |
570 | } |
571 | else | |
572 | *p++ = path[i++]; | |
573 | ||
574 | *p = 0; | |
575 | return ret; | |
576 | } | |
04925e1e | 577 | |
3dc16cab DJ |
578 | EOF |
579 | case ${target} in | |
ebe1fac1 | 580 | *-*-freebsd* | *-*-dragonfly*) |
92b93329 | 581 | fragment <<EOF |
ebe1fac1 NC |
582 | /* Read the system search path the FreeBSD way rather than the Linux way. */ |
583 | #ifdef HAVE_ELF_HINTS_H | |
584 | #include <elf-hints.h> | |
585 | #else | |
586 | #include "elf-hints-local.h" | |
587 | #endif | |
588 | ||
589 | static bfd_boolean | |
d5c8b1f8 AM |
590 | gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l, |
591 | int force) | |
ebe1fac1 NC |
592 | { |
593 | static bfd_boolean initialized; | |
594 | static char *ld_elf_hints; | |
595 | struct dt_needed needed; | |
596 | ||
597 | if (!initialized) | |
598 | { | |
599 | FILE *f; | |
600 | char *tmppath; | |
601 | ||
ff7a0acf | 602 | tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL); |
ebe1fac1 NC |
603 | f = fopen (tmppath, FOPEN_RB); |
604 | free (tmppath); | |
605 | if (f != NULL) | |
606 | { | |
607 | struct elfhints_hdr hdr; | |
608 | ||
609 | if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr) | |
610 | && hdr.magic == ELFHINTS_MAGIC | |
611 | && hdr.version == 1) | |
612 | { | |
613 | if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1) | |
614 | { | |
615 | char *b; | |
616 | ||
617 | b = xmalloc (hdr.dirlistlen + 1); | |
618 | if (fread (b, 1, hdr.dirlistlen + 1, f) == | |
619 | hdr.dirlistlen + 1) | |
620 | ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b); | |
e13629bc | 621 | |
ebe1fac1 NC |
622 | free (b); |
623 | } | |
624 | } | |
625 | fclose (f); | |
626 | } | |
627 | ||
628 | initialized = TRUE; | |
629 | } | |
630 | ||
631 | if (ld_elf_hints == NULL) | |
632 | return FALSE; | |
633 | ||
d5c8b1f8 AM |
634 | needed.by = l->by; |
635 | needed.name = l->name; | |
636 | return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force); | |
ebe1fac1 NC |
637 | } |
638 | EOF | |
639 | # FreeBSD | |
640 | ;; | |
641 | ||
a5244b7e | 642 | *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*) |
92b93329 | 643 | fragment <<EOF |
04925e1e AM |
644 | /* For a native linker, check the file /etc/ld.so.conf for directories |
645 | in which we may find shared libraries. /etc/ld.so.conf is really | |
482e8b32 | 646 | only meaningful on Linux. */ |
04925e1e | 647 | |
d3989512 | 648 | struct gld${EMULATION_NAME}_ld_so_conf |
04925e1e | 649 | { |
d3989512 JJ |
650 | char *path; |
651 | size_t len, alloc; | |
652 | }; | |
04925e1e | 653 | |
dfcffada | 654 | static bfd_boolean |
d3989512 JJ |
655 | gld${EMULATION_NAME}_parse_ld_so_conf |
656 | (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename); | |
657 | ||
658 | static void | |
659 | gld${EMULATION_NAME}_parse_ld_so_conf_include | |
660 | (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename, | |
661 | const char *pattern) | |
662 | { | |
663 | char *newp = NULL; | |
0b48acfe | 664 | #ifdef HAVE_GLOB |
d3989512 | 665 | glob_t gl; |
0b48acfe | 666 | #endif |
d3989512 JJ |
667 | |
668 | if (pattern[0] != '/') | |
04925e1e | 669 | { |
d3989512 JJ |
670 | char *p = strrchr (filename, '/'); |
671 | size_t patlen = strlen (pattern) + 1; | |
04925e1e | 672 | |
d3989512 JJ |
673 | newp = xmalloc (p - filename + 1 + patlen); |
674 | memcpy (newp, filename, p - filename + 1); | |
675 | memcpy (newp + (p - filename + 1), pattern, patlen); | |
676 | pattern = newp; | |
677 | } | |
04925e1e | 678 | |
0b48acfe | 679 | #ifdef HAVE_GLOB |
d3989512 JJ |
680 | if (glob (pattern, 0, NULL, &gl) == 0) |
681 | { | |
682 | size_t i; | |
683 | ||
684 | for (i = 0; i < gl.gl_pathc; ++i) | |
685 | gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]); | |
686 | globfree (&gl); | |
687 | } | |
0b48acfe MM |
688 | #else |
689 | /* If we do not have glob, treat the pattern as a literal filename. */ | |
690 | gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern); | |
691 | #endif | |
d3989512 JJ |
692 | |
693 | if (newp) | |
694 | free (newp); | |
695 | } | |
696 | ||
dfcffada | 697 | static bfd_boolean |
d3989512 JJ |
698 | gld${EMULATION_NAME}_parse_ld_so_conf |
699 | (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename) | |
700 | { | |
701 | FILE *f = fopen (filename, FOPEN_RT); | |
563f4125 JJ |
702 | char *line; |
703 | size_t linelen; | |
d3989512 JJ |
704 | |
705 | if (f == NULL) | |
dfcffada | 706 | return FALSE; |
d3989512 | 707 | |
563f4125 JJ |
708 | linelen = 256; |
709 | line = xmalloc (linelen); | |
710 | do | |
d3989512 | 711 | { |
563f4125 JJ |
712 | char *p = line, *q; |
713 | ||
714 | /* Normally this would use getline(3), but we need to be portable. */ | |
715 | while ((q = fgets (p, linelen - (p - line), f)) != NULL | |
716 | && strlen (q) == linelen - (p - line) - 1 | |
717 | && line[linelen - 2] != '\n') | |
718 | { | |
719 | line = xrealloc (line, 2 * linelen); | |
720 | p = line + linelen - 1; | |
721 | linelen += linelen; | |
722 | } | |
723 | ||
724 | if (q == NULL && p == line) | |
725 | break; | |
d3989512 JJ |
726 | |
727 | p = strchr (line, '\n'); | |
728 | if (p) | |
729 | *p = '\0'; | |
730 | ||
731 | /* Because the file format does not know any form of quoting we | |
732 | can search forward for the next '#' character and if found | |
733 | make it terminating the line. */ | |
734 | p = strchr (line, '#'); | |
735 | if (p) | |
736 | *p = '\0'; | |
737 | ||
738 | /* Remove leading whitespace. NUL is no whitespace character. */ | |
739 | p = line; | |
740 | while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v') | |
741 | ++p; | |
742 | ||
743 | /* If the line is blank it is ignored. */ | |
744 | if (p[0] == '\0') | |
745 | continue; | |
04925e1e | 746 | |
0112cd26 | 747 | if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t')) |
d3989512 JJ |
748 | { |
749 | char *dir, c; | |
750 | p += 8; | |
751 | do | |
04925e1e | 752 | { |
d3989512 JJ |
753 | while (*p == ' ' || *p == '\t') |
754 | ++p; | |
04925e1e | 755 | |
d3989512 JJ |
756 | if (*p == '\0') |
757 | break; | |
252b5132 | 758 | |
d3989512 JJ |
759 | dir = p; |
760 | ||
761 | while (*p != ' ' && *p != '\t' && *p) | |
762 | ++p; | |
763 | ||
764 | c = *p; | |
765 | *p++ = '\0'; | |
766 | if (dir[0] != '\0') | |
767 | gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename, | |
768 | dir); | |
769 | } | |
770 | while (c != '\0'); | |
771 | } | |
772 | else | |
773 | { | |
774 | char *dir = p; | |
775 | while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f' | |
776 | && *p != '\r' && *p != '\v') | |
777 | ++p; | |
778 | ||
779 | while (p != dir && p[-1] == '/') | |
780 | --p; | |
781 | if (info->path == NULL) | |
782 | { | |
783 | info->alloc = p - dir + 1 + 256; | |
784 | info->path = xmalloc (info->alloc); | |
785 | info->len = 0; | |
786 | } | |
04925e1e AM |
787 | else |
788 | { | |
d3989512 JJ |
789 | if (info->len + 1 + (p - dir) >= info->alloc) |
790 | { | |
791 | info->alloc += p - dir + 256; | |
792 | info->path = xrealloc (info->path, info->alloc); | |
793 | } | |
c76308d2 | 794 | info->path[info->len++] = config.rpath_separator; |
04925e1e | 795 | } |
d3989512 JJ |
796 | memcpy (info->path + info->len, dir, p - dir); |
797 | info->len += p - dir; | |
798 | info->path[info->len] = '\0'; | |
799 | } | |
800 | } | |
563f4125 | 801 | while (! feof (f)); |
d3989512 JJ |
802 | free (line); |
803 | fclose (f); | |
dfcffada | 804 | return TRUE; |
d3989512 | 805 | } |
252b5132 | 806 | |
d3989512 | 807 | static bfd_boolean |
d5c8b1f8 AM |
808 | gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l, |
809 | int force) | |
d3989512 JJ |
810 | { |
811 | static bfd_boolean initialized; | |
812 | static char *ld_so_conf; | |
813 | struct dt_needed needed; | |
252b5132 | 814 | |
d3989512 JJ |
815 | if (! initialized) |
816 | { | |
817 | char *tmppath; | |
818 | struct gld${EMULATION_NAME}_ld_so_conf info; | |
9c8ebd6a | 819 | |
d3989512 JJ |
820 | info.path = NULL; |
821 | info.len = info.alloc = 0; | |
ff7a0acf AM |
822 | tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf", |
823 | (const char *) NULL); | |
dfcffada AM |
824 | if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath)) |
825 | { | |
826 | free (tmppath); | |
ff7a0acf AM |
827 | tmppath = concat (ld_sysroot, "/etc/ld.so.conf", |
828 | (const char *) NULL); | |
dfcffada AM |
829 | gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath); |
830 | } | |
d3989512 | 831 | free (tmppath); |
dfcffada | 832 | |
d3989512 JJ |
833 | if (info.path) |
834 | { | |
835 | char *d = gld${EMULATION_NAME}_add_sysroot (info.path); | |
836 | free (info.path); | |
837 | ld_so_conf = d; | |
04925e1e | 838 | } |
b34976b6 | 839 | initialized = TRUE; |
04925e1e | 840 | } |
49e56c49 | 841 | |
04925e1e | 842 | if (ld_so_conf == NULL) |
b34976b6 | 843 | return FALSE; |
252b5132 | 844 | |
e56f61be | 845 | |
d5c8b1f8 AM |
846 | needed.by = l->by; |
847 | needed.name = l->name; | |
e56f61be | 848 | return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force); |
252b5132 RH |
849 | } |
850 | ||
04925e1e | 851 | EOF |
9c8ebd6a DJ |
852 | # Linux |
853 | ;; | |
04925e1e AM |
854 | esac |
855 | fi | |
92b93329 | 856 | fragment <<EOF |
04925e1e | 857 | |
252b5132 RH |
858 | /* See if an input file matches a DT_NEEDED entry by name. */ |
859 | ||
860 | static void | |
0c7a8e5a | 861 | gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s) |
252b5132 | 862 | { |
e13629bc AM |
863 | const char *soname; |
864 | ||
865 | /* Stop looking if we've found a loaded lib. */ | |
866 | if (global_found != NULL | |
867 | && (bfd_elf_get_dyn_lib_class (global_found->the_bfd) | |
868 | & DYN_AS_NEEDED) == 0) | |
252b5132 RH |
869 | return; |
870 | ||
e13629bc AM |
871 | if (s->filename == NULL || s->the_bfd == NULL) |
872 | return; | |
873 | ||
874 | /* Don't look for a second non-loaded as-needed lib. */ | |
875 | if (global_found != NULL | |
876 | && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0) | |
7cedef86 AM |
877 | return; |
878 | ||
42627821 | 879 | if (filename_cmp (s->filename, global_needed->name) == 0) |
252b5132 | 880 | { |
e13629bc AM |
881 | global_found = s; |
882 | return; | |
883 | } | |
577a0623 | 884 | |
66be1055 | 885 | if (s->flags.search_dirs) |
e13629bc AM |
886 | { |
887 | const char *f = strrchr (s->filename, '/'); | |
888 | if (f != NULL | |
42627821 | 889 | && filename_cmp (f + 1, global_needed->name) == 0) |
577a0623 | 890 | { |
e13629bc | 891 | global_found = s; |
577a0623 AM |
892 | return; |
893 | } | |
252b5132 RH |
894 | } |
895 | ||
e13629bc AM |
896 | soname = bfd_elf_get_dt_soname (s->the_bfd); |
897 | if (soname != NULL | |
42627821 | 898 | && filename_cmp (soname, global_needed->name) == 0) |
252b5132 | 899 | { |
e13629bc AM |
900 | global_found = s; |
901 | return; | |
252b5132 | 902 | } |
252b5132 RH |
903 | } |
904 | ||
41392f03 AM |
905 | EOF |
906 | ||
907 | if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then | |
92b93329 | 908 | fragment <<EOF |
04925e1e | 909 | |
24382dca | 910 | static bfd_size_type |
677e5a92 | 911 | id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED) |
24382dca | 912 | { |
30e8ee25 | 913 | const char *style = emit_note_gnu_build_id; |
24382dca | 914 | bfd_size_type size; |
61e2488c | 915 | bfd_size_type build_id_size; |
24382dca | 916 | |
24382dca RM |
917 | size = offsetof (Elf_External_Note, name[sizeof "GNU"]); |
918 | size = (size + 3) & -(bfd_size_type) 4; | |
919 | ||
61e2488c JT |
920 | build_id_size = compute_build_id_size (style); |
921 | if (build_id_size) | |
922 | size += build_id_size; | |
24382dca RM |
923 | else |
924 | size = 0; | |
925 | ||
926 | return size; | |
927 | } | |
928 | ||
24382dca | 929 | static bfd_boolean |
30e8ee25 | 930 | write_build_id (bfd *abfd) |
24382dca RM |
931 | { |
932 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
30e8ee25 AM |
933 | struct elf_obj_tdata *t = elf_tdata (abfd); |
934 | const char *style; | |
24382dca RM |
935 | asection *asec; |
936 | Elf_Internal_Shdr *i_shdr; | |
937 | unsigned char *contents, *id_bits; | |
938 | bfd_size_type size; | |
30e8ee25 | 939 | file_ptr position; |
24382dca RM |
940 | Elf_External_Note *e_note; |
941 | ||
c0355132 AM |
942 | style = t->o->build_id.style; |
943 | asec = t->o->build_id.sec; | |
83e4970b | 944 | if (bfd_is_abs_section (asec->output_section)) |
24382dca | 945 | { |
83e4970b AM |
946 | einfo (_("%P: warning: .note.gnu.build-id section discarded," |
947 | " --build-id ignored.\n")); | |
948 | return TRUE; | |
24382dca RM |
949 | } |
950 | i_shdr = &elf_section_data (asec->output_section)->this_hdr; | |
951 | ||
952 | if (i_shdr->contents == NULL) | |
953 | { | |
b2ff8454 | 954 | if (asec->contents == NULL) |
1e9cc1c2 | 955 | asec->contents = (unsigned char *) xmalloc (asec->size); |
b2ff8454 | 956 | contents = asec->contents; |
24382dca | 957 | } |
b2ff8454 RM |
958 | else |
959 | contents = i_shdr->contents + asec->output_offset; | |
24382dca | 960 | |
1e9cc1c2 | 961 | e_note = (Elf_External_Note *) contents; |
24382dca RM |
962 | size = offsetof (Elf_External_Note, name[sizeof "GNU"]); |
963 | size = (size + 3) & -(bfd_size_type) 4; | |
964 | id_bits = contents + size; | |
965 | size = asec->size - size; | |
966 | ||
967 | bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz); | |
968 | bfd_h_put_32 (abfd, size, &e_note->descsz); | |
969 | bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type); | |
970 | memcpy (e_note->name, "GNU", sizeof "GNU"); | |
971 | ||
61e2488c | 972 | generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size); |
24382dca | 973 | |
30e8ee25 | 974 | position = i_shdr->sh_offset + asec->output_offset; |
b2ff8454 | 975 | size = asec->size; |
30e8ee25 | 976 | return (bfd_seek (abfd, position, SEEK_SET) == 0 |
b2ff8454 | 977 | && bfd_bwrite (contents, size, abfd) == size); |
24382dca RM |
978 | } |
979 | ||
30e8ee25 AM |
980 | /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */ |
981 | ||
982 | static bfd_boolean | |
983 | setup_build_id (bfd *ibfd) | |
984 | { | |
985 | asection *s; | |
986 | bfd_size_type size; | |
987 | flagword flags; | |
988 | ||
989 | size = id_note_section_size (ibfd); | |
990 | if (size == 0) | |
991 | { | |
992 | einfo ("%P: warning: unrecognized --build-id style ignored.\n"); | |
993 | return FALSE; | |
994 | } | |
995 | ||
996 | flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY | |
997 | | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA); | |
998 | s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags); | |
999 | if (s != NULL && bfd_set_section_alignment (ibfd, s, 2)) | |
1000 | { | |
1001 | struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd); | |
c0355132 AM |
1002 | t->o->build_id.after_write_object_contents = &write_build_id; |
1003 | t->o->build_id.style = emit_note_gnu_build_id; | |
1004 | t->o->build_id.sec = s; | |
1005 | elf_section_type (s) = SHT_NOTE; | |
1006 | s->size = size; | |
1007 | return TRUE; | |
30e8ee25 AM |
1008 | } |
1009 | ||
1010 | einfo ("%P: warning: Cannot create .note.gnu.build-id section," | |
1011 | " --build-id ignored.\n"); | |
1012 | return FALSE; | |
1013 | } | |
24382dca | 1014 | |
04925e1e | 1015 | /* This is called after all the input files have been opened. */ |
252b5132 RH |
1016 | |
1017 | static void | |
0c7a8e5a | 1018 | gld${EMULATION_NAME}_after_open (void) |
252b5132 | 1019 | { |
04925e1e | 1020 | struct bfd_link_needed_list *needed, *l; |
d10e7fcc AM |
1021 | struct elf_link_hash_table *htab; |
1022 | ||
5c3049d2 AM |
1023 | after_open_default (); |
1024 | ||
d10e7fcc AM |
1025 | htab = elf_hash_table (&link_info); |
1026 | if (!is_elf_hash_table (htab)) | |
1027 | return; | |
252b5132 | 1028 | |
30e8ee25 | 1029 | if (emit_note_gnu_build_id != NULL) |
c0065db7 RM |
1030 | { |
1031 | bfd *abfd; | |
c0065db7 | 1032 | |
a654efd6 L |
1033 | /* Find an ELF input. */ |
1034 | for (abfd = link_info.input_bfds; | |
c72f2fb2 | 1035 | abfd != (bfd *) NULL; abfd = abfd->link.next) |
ca0694ad AM |
1036 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour |
1037 | && bfd_count_sections (abfd) != 0) | |
a654efd6 | 1038 | break; |
c0065db7 | 1039 | |
30e8ee25 AM |
1040 | /* PR 10555: If there are no ELF input files do not try to |
1041 | create a .note.gnu-build-id section. */ | |
1042 | if (abfd == NULL | |
1043 | || !setup_build_id (abfd)) | |
c0065db7 | 1044 | { |
30e8ee25 AM |
1045 | free ((char *) emit_note_gnu_build_id); |
1046 | emit_note_gnu_build_id = NULL; | |
c0065db7 RM |
1047 | } |
1048 | } | |
1049 | ||
0e1862bb | 1050 | if (bfd_link_relocatable (&link_info)) |
76f0cad6 NC |
1051 | { |
1052 | if (link_info.execstack == ! link_info.noexecstack) | |
1053 | /* PR ld/16744: If "-z [no]execstack" has been specified on the | |
1054 | command line and we are perfoming a relocatable link then no | |
1055 | PT_GNU_STACK segment will be created and so the | |
1056 | linkinfo.[no]execstack values set in _handle_option() will have no | |
1057 | effect. Instead we create a .note.GNU-stack section in much the | |
1058 | same way as the assembler does with its --[no]execstack option. */ | |
1059 | (void) bfd_make_section_with_flags (link_info.input_bfds, | |
1060 | ".note.GNU-stack", | |
1061 | SEC_READONLY | (link_info.execstack ? SEC_CODE : 0)); | |
1062 | ||
1063 | return; | |
1064 | } | |
d10e7fcc | 1065 | |
2f0c68f2 | 1066 | if (!link_info.traditional_format) |
eb3d5f3b | 1067 | { |
a654efd6 L |
1068 | bfd *abfd, *elfbfd = NULL; |
1069 | bfd_boolean warn_eh_frame = FALSE; | |
d10e7fcc | 1070 | asection *s; |
2f0c68f2 | 1071 | int seen_type = 0; |
eb3d5f3b | 1072 | |
c72f2fb2 | 1073 | for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next) |
eb3d5f3b | 1074 | { |
2f0c68f2 CM |
1075 | int type = 0; |
1076 | for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next) | |
4440bb77 | 1077 | { |
2f0c68f2 CM |
1078 | const char *name = bfd_get_section_name (abfd, s); |
1079 | ||
1080 | if (bfd_is_abs_section (s->output_section)) | |
1081 | continue; | |
1082 | if (CONST_STRNEQ (name, ".eh_frame_entry")) | |
1083 | type = COMPACT_EH_HDR; | |
1084 | else if (strcmp (name, ".eh_frame") == 0 && s->size > 8) | |
1085 | type = DWARF2_EH_HDR; | |
4440bb77 | 1086 | } |
2f0c68f2 CM |
1087 | |
1088 | if (type != 0) | |
1089 | { | |
1090 | if (seen_type == 0) | |
1091 | { | |
1092 | seen_type = type; | |
1093 | } | |
1094 | else if (seen_type != type) | |
1095 | { | |
1096 | einfo (_("%P%F: compact frame descriptions incompatible with" | |
1097 | " DWARF2 .eh_frame from %B\n"), | |
1098 | type == DWARF2_EH_HDR ? abfd : elfbfd); | |
1099 | break; | |
1100 | } | |
1101 | ||
1102 | if (!elfbfd | |
1103 | && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0)) | |
1104 | { | |
1105 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) | |
1106 | elfbfd = abfd; | |
1107 | ||
1108 | warn_eh_frame = TRUE; | |
1109 | } | |
1110 | } | |
1111 | ||
1112 | if (seen_type == COMPACT_EH_HDR) | |
1113 | link_info.eh_frame_hdr_type = COMPACT_EH_HDR; | |
1114 | ||
1115 | if (bfd_count_sections (abfd) == 0) | |
1116 | continue; | |
d10e7fcc | 1117 | } |
a654efd6 | 1118 | if (elfbfd) |
d10e7fcc AM |
1119 | { |
1120 | const struct elf_backend_data *bed; | |
1121 | ||
a654efd6 L |
1122 | bed = get_elf_backend_data (elfbfd); |
1123 | s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr", | |
1124 | bed->dynamic_sec_flags | |
1125 | | SEC_READONLY); | |
d10e7fcc | 1126 | if (s != NULL |
a654efd6 L |
1127 | && bfd_set_section_alignment (elfbfd, s, 2)) |
1128 | { | |
1129 | htab->eh_info.hdr_sec = s; | |
1130 | warn_eh_frame = FALSE; | |
1131 | } | |
eb3d5f3b | 1132 | } |
a654efd6 L |
1133 | if (warn_eh_frame) |
1134 | einfo ("%P: warning: Cannot create .eh_frame_hdr section," | |
1135 | " --eh-frame-hdr ignored.\n"); | |
eb3d5f3b JB |
1136 | } |
1137 | ||
04925e1e AM |
1138 | /* Get the list of files which appear in DT_NEEDED entries in |
1139 | dynamic objects included in the link (often there will be none). | |
1140 | For each such file, we want to track down the corresponding | |
1141 | library, and include the symbol table in the link. This is what | |
1142 | the runtime dynamic linker will do. Tracking the files down here | |
1143 | permits one dynamic object to include another without requiring | |
1144 | special action by the person doing the link. Note that the | |
1145 | needed list can actually grow while we are stepping through this | |
1146 | loop. */ | |
f13a99db | 1147 | needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info); |
04925e1e | 1148 | for (l = needed; l != NULL; l = l->next) |
252b5132 | 1149 | { |
04925e1e | 1150 | struct bfd_link_needed_list *ll; |
e56f61be | 1151 | struct dt_needed n, nn; |
04925e1e | 1152 | int force; |
252b5132 | 1153 | |
7e9f0867 | 1154 | /* If the lib that needs this one was --as-needed and wasn't |
4706eab9 | 1155 | found to be needed, then this lib isn't needed either. */ |
7e9f0867 | 1156 | if (l->by != NULL |
4706eab9 AM |
1157 | && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0) |
1158 | continue; | |
1159 | ||
1160 | /* Skip the lib if --no-copy-dt-needed-entries and | |
1161 | --allow-shlib-undefined is in effect. */ | |
1162 | if (l->by != NULL | |
1163 | && link_info.unresolved_syms_in_shared_libs == RM_IGNORE | |
1164 | && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0) | |
7e9f0867 AM |
1165 | continue; |
1166 | ||
04925e1e AM |
1167 | /* If we've already seen this file, skip it. */ |
1168 | for (ll = needed; ll != l; ll = ll->next) | |
7e9f0867 AM |
1169 | if ((ll->by == NULL |
1170 | || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0) | |
1171 | && strcmp (ll->name, l->name) == 0) | |
04925e1e AM |
1172 | break; |
1173 | if (ll != l) | |
1174 | continue; | |
252b5132 | 1175 | |
04925e1e AM |
1176 | /* See if this file was included in the link explicitly. */ |
1177 | global_needed = l; | |
e13629bc | 1178 | global_found = NULL; |
04925e1e | 1179 | lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); |
e13629bc AM |
1180 | if (global_found != NULL |
1181 | && (bfd_elf_get_dyn_lib_class (global_found->the_bfd) | |
1182 | & DYN_AS_NEEDED) == 0) | |
04925e1e | 1183 | continue; |
252b5132 | 1184 | |
e56f61be L |
1185 | n.by = l->by; |
1186 | n.name = l->name; | |
1187 | nn.by = l->by; | |
cd6f1cf3 | 1188 | if (verbose) |
ec4eb78a L |
1189 | info_msg (_("%s needed by %B\n"), l->name, l->by); |
1190 | ||
e13629bc AM |
1191 | /* As-needed libs specified on the command line (or linker script) |
1192 | take priority over libs found in search dirs. */ | |
1193 | if (global_found != NULL) | |
1194 | { | |
1195 | nn.name = global_found->filename; | |
1196 | if (gld${EMULATION_NAME}_try_needed (&nn, TRUE)) | |
1197 | continue; | |
1198 | } | |
1199 | ||
04925e1e AM |
1200 | /* We need to find this file and include the symbol table. We |
1201 | want to search for the file in the same way that the dynamic | |
1202 | linker will search. That means that we want to use | |
1203 | rpath_link, rpath, then the environment variable | |
ec4eb78a L |
1204 | LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH |
1205 | entries (native only), then the linker script LIB_SEARCH_DIRS. | |
1206 | We do not search using the -L arguments. | |
252b5132 | 1207 | |
04925e1e AM |
1208 | We search twice. The first time, we skip objects which may |
1209 | introduce version mismatches. The second time, we force | |
1210 | their use. See gld${EMULATION_NAME}_vercheck comment. */ | |
1211 | for (force = 0; force < 2; force++) | |
1212 | { | |
04925e1e AM |
1213 | size_t len; |
1214 | search_dirs_type *search; | |
6dd8c765 | 1215 | EOF |
ff925e69 | 1216 | if [ "x${NATIVE}" = xyes ] ; then |
92b93329 | 1217 | fragment <<EOF |
dcb0bd0e | 1218 | const char *lib_path; |
ff925e69 KK |
1219 | EOF |
1220 | fi | |
1221 | if [ "x${USE_LIBPATH}" = xyes ] ; then | |
92b93329 | 1222 | fragment <<EOF |
6dd8c765 L |
1223 | struct bfd_link_needed_list *rp; |
1224 | int found; | |
1225 | EOF | |
6dd8c765 | 1226 | fi |
92b93329 | 1227 | fragment <<EOF |
252b5132 | 1228 | |
04925e1e | 1229 | if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link, |
e56f61be | 1230 | &n, force)) |
04925e1e | 1231 | break; |
dcb0bd0e | 1232 | EOF |
9c8ebd6a | 1233 | if [ "x${USE_LIBPATH}" = xyes ] ; then |
92b93329 | 1234 | fragment <<EOF |
04925e1e | 1235 | if (gld${EMULATION_NAME}_search_needed (command_line.rpath, |
e56f61be | 1236 | &n, force)) |
04925e1e | 1237 | break; |
9c8ebd6a DJ |
1238 | EOF |
1239 | fi | |
1240 | if [ "x${NATIVE}" = xyes ] ; then | |
92b93329 | 1241 | fragment <<EOF |
04925e1e AM |
1242 | if (command_line.rpath_link == NULL |
1243 | && command_line.rpath == NULL) | |
1244 | { | |
1245 | lib_path = (const char *) getenv ("LD_RUN_PATH"); | |
e56f61be | 1246 | if (gld${EMULATION_NAME}_search_needed (lib_path, &n, |
04925e1e AM |
1247 | force)) |
1248 | break; | |
1249 | } | |
04925e1e | 1250 | lib_path = (const char *) getenv ("LD_LIBRARY_PATH"); |
e56f61be | 1251 | if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force)) |
04925e1e | 1252 | break; |
9c8ebd6a DJ |
1253 | EOF |
1254 | fi | |
1255 | if [ "x${USE_LIBPATH}" = xyes ] ; then | |
92b93329 | 1256 | fragment <<EOF |
ec4eb78a | 1257 | found = 0; |
f13a99db | 1258 | rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info); |
6dd8c765 | 1259 | for (; !found && rp != NULL; rp = rp->next) |
ec4eb78a | 1260 | { |
3074964f AM |
1261 | const char *tmpname = rp->name; |
1262 | ||
1263 | if (IS_ABSOLUTE_PATH (tmpname)) | |
1264 | tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname); | |
ec4eb78a | 1265 | found = (rp->by == l->by |
9c8ebd6a | 1266 | && gld${EMULATION_NAME}_search_needed (tmpname, |
e56f61be | 1267 | &n, |
ec4eb78a | 1268 | force)); |
3074964f AM |
1269 | if (tmpname != rp->name) |
1270 | free ((char *) tmpname); | |
ec4eb78a L |
1271 | } |
1272 | if (found) | |
1273 | break; | |
1274 | ||
04925e1e | 1275 | EOF |
04925e1e | 1276 | fi |
c1446dba L |
1277 | if [ "x${USE_LIBPATH}" = xyes ] ; then |
1278 | case ${target} in | |
ebe1fac1 | 1279 | *-*-freebsd* | *-*-dragonfly*) |
92b93329 | 1280 | fragment <<EOF |
d5c8b1f8 | 1281 | if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force)) |
ebe1fac1 NC |
1282 | break; |
1283 | EOF | |
1284 | # FreeBSD | |
1285 | ;; | |
1286 | ||
a5244b7e | 1287 | *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*) |
92b93329 | 1288 | fragment <<EOF |
d5c8b1f8 | 1289 | if (gld${EMULATION_NAME}_check_ld_so_conf (l, force)) |
c1446dba L |
1290 | break; |
1291 | ||
1292 | EOF | |
eeaa4577 | 1293 | # Linux |
c1446dba L |
1294 | ;; |
1295 | esac | |
1296 | fi | |
92b93329 | 1297 | fragment <<EOF |
04925e1e AM |
1298 | len = strlen (l->name); |
1299 | for (search = search_head; search != NULL; search = search->next) | |
1300 | { | |
1301 | char *filename; | |
252b5132 | 1302 | |
04925e1e AM |
1303 | if (search->cmdline) |
1304 | continue; | |
1305 | filename = (char *) xmalloc (strlen (search->name) + len + 2); | |
1306 | sprintf (filename, "%s/%s", search->name, l->name); | |
e56f61be L |
1307 | nn.name = filename; |
1308 | if (gld${EMULATION_NAME}_try_needed (&nn, force)) | |
04925e1e AM |
1309 | break; |
1310 | free (filename); | |
1311 | } | |
1312 | if (search != NULL) | |
1313 | break; | |
1314 | EOF | |
92b93329 | 1315 | fragment <<EOF |
04925e1e | 1316 | } |
252b5132 | 1317 | |
04925e1e AM |
1318 | if (force < 2) |
1319 | continue; | |
252b5132 | 1320 | |
e374f1d9 | 1321 | einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n", |
04925e1e AM |
1322 | l->name, l->by); |
1323 | } | |
2f0c68f2 CM |
1324 | |
1325 | if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR) | |
1326 | if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE) | |
1327 | einfo (_("%P%F: Failed to parse EH frame entries.\n")); | |
04925e1e | 1328 | } |
252b5132 | 1329 | |
41392f03 AM |
1330 | EOF |
1331 | fi | |
1332 | ||
92b93329 | 1333 | fragment <<EOF |
252b5132 | 1334 | |
04925e1e | 1335 | /* Look through an expression for an assignment statement. */ |
252b5132 | 1336 | |
04925e1e | 1337 | static void |
0c7a8e5a | 1338 | gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp) |
04925e1e | 1339 | { |
4ea42fb7 | 1340 | bfd_boolean provide = FALSE; |
04925e1e AM |
1341 | |
1342 | switch (exp->type.node_class) | |
252b5132 | 1343 | { |
04925e1e | 1344 | case etree_provide: |
bded3693 | 1345 | case etree_provided: |
4ea42fb7 AM |
1346 | provide = TRUE; |
1347 | /* Fall thru */ | |
1348 | case etree_assign: | |
04925e1e AM |
1349 | /* We call record_link_assignment even if the symbol is defined. |
1350 | This is because if it is defined by a dynamic object, we | |
1351 | actually want to use the value defined by the linker script, | |
1352 | not the value from the dynamic object (because we are setting | |
1353 | symbols like etext). If the symbol is defined by a regular | |
1354 | object, then, as it happens, calling record_link_assignment | |
1355 | will do no harm. */ | |
04925e1e | 1356 | if (strcmp (exp->assign.dst, ".") != 0) |
252b5132 | 1357 | { |
f13a99db AM |
1358 | if (!bfd_elf_record_link_assignment (link_info.output_bfd, |
1359 | &link_info, | |
fe21a8fc L |
1360 | exp->assign.dst, provide, |
1361 | exp->assign.hidden)) | |
04925e1e AM |
1362 | einfo ("%P%F: failed to record assignment to %s: %E\n", |
1363 | exp->assign.dst); | |
252b5132 | 1364 | } |
04925e1e AM |
1365 | gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); |
1366 | break; | |
252b5132 | 1367 | |
04925e1e AM |
1368 | case etree_binary: |
1369 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); | |
1370 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); | |
1371 | break; | |
252b5132 | 1372 | |
04925e1e AM |
1373 | case etree_trinary: |
1374 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); | |
1375 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); | |
1376 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); | |
1377 | break; | |
252b5132 | 1378 | |
04925e1e AM |
1379 | case etree_unary: |
1380 | gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); | |
1381 | break; | |
252b5132 | 1382 | |
04925e1e AM |
1383 | default: |
1384 | break; | |
252b5132 RH |
1385 | } |
1386 | } | |
1387 | ||
04925e1e AM |
1388 | |
1389 | /* This is called by the before_allocation routine via | |
1390 | lang_for_each_statement. It locates any assignment statements, and | |
1391 | tells the ELF backend about them, in case they are assignments to | |
1392 | symbols which are referred to by dynamic objects. */ | |
1393 | ||
1394 | static void | |
0c7a8e5a | 1395 | gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s) |
04925e1e AM |
1396 | { |
1397 | if (s->header.type == lang_assignment_statement_enum) | |
1398 | gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); | |
1399 | } | |
1400 | ||
41392f03 AM |
1401 | EOF |
1402 | ||
1403 | if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then | |
57e6abd2 AO |
1404 | if test x"${ELF_INTERPRETER_NAME+set}" = xset; then |
1405 | ELF_INTERPRETER_SET_DEFAULT=" | |
1406 | if (sinterp != NULL) | |
1407 | { | |
5718918d AM |
1408 | sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME}; |
1409 | sinterp->size = strlen ((char *) sinterp->contents) + 1; | |
57e6abd2 AO |
1410 | } |
1411 | ||
1412 | " | |
1413 | else | |
1414 | ELF_INTERPRETER_SET_DEFAULT= | |
1415 | fi | |
92b93329 | 1416 | fragment <<EOF |
04925e1e | 1417 | |
7ee314fa | 1418 | /* used by before_allocation and handle_option. */ |
4724d37e | 1419 | static void |
91d6fa6a | 1420 | gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg) |
7ee314fa AM |
1421 | { |
1422 | if (*to == NULL) | |
91d6fa6a | 1423 | *to = xstrdup (op_arg); |
7ee314fa AM |
1424 | else |
1425 | { | |
1426 | size_t to_len = strlen (*to); | |
91d6fa6a | 1427 | size_t op_arg_len = strlen (op_arg); |
7ee314fa AM |
1428 | char *buf; |
1429 | char *cp = *to; | |
1430 | ||
1431 | /* First see whether OPTARG is already in the path. */ | |
1432 | do | |
1433 | { | |
91d6fa6a NC |
1434 | if (strncmp (op_arg, cp, op_arg_len) == 0 |
1435 | && (cp[op_arg_len] == 0 | |
1436 | || cp[op_arg_len] == config.rpath_separator)) | |
7ee314fa AM |
1437 | /* We found it. */ |
1438 | break; | |
1439 | ||
1440 | /* Not yet found. */ | |
1441 | cp = strchr (cp, config.rpath_separator); | |
1442 | if (cp != NULL) | |
1443 | ++cp; | |
1444 | } | |
1445 | while (cp != NULL); | |
1446 | ||
1447 | if (cp == NULL) | |
1448 | { | |
91d6fa6a | 1449 | buf = xmalloc (to_len + op_arg_len + 2); |
7ee314fa | 1450 | sprintf (buf, "%s%c%s", *to, |
91d6fa6a | 1451 | config.rpath_separator, op_arg); |
7ee314fa AM |
1452 | free (*to); |
1453 | *to = buf; | |
1454 | } | |
1455 | } | |
1456 | } | |
1457 | ||
b6518b38 NC |
1458 | #if defined(__GNUC__) && GCC_VERSION < 4006 |
1459 | /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */ | |
1460 | static struct bfd_link_hash_entry ehdr_start_empty; | |
1461 | #endif | |
1462 | ||
252b5132 RH |
1463 | /* This is called after the sections have been attached to output |
1464 | sections, but before any sizes or addresses have been set. */ | |
1465 | ||
1466 | static void | |
0c7a8e5a | 1467 | gld${EMULATION_NAME}_before_allocation (void) |
252b5132 RH |
1468 | { |
1469 | const char *rpath; | |
1470 | asection *sinterp; | |
7ee314fa | 1471 | bfd *abfd; |
4199e3b8 | 1472 | struct elf_link_hash_entry *ehdr_start = NULL; |
a0bde398 L |
1473 | #if defined(__GNUC__) && GCC_VERSION < 4006 |
1474 | /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */ | |
b6518b38 | 1475 | struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty; |
a0bde398 | 1476 | #else |
4a0bc59e | 1477 | struct bfd_link_hash_entry ehdr_start_save; |
a0bde398 | 1478 | #endif |
252b5132 | 1479 | |
b4d040b1 | 1480 | if (is_elf_hash_table (link_info.hash)) |
a5382c42 MR |
1481 | { |
1482 | _bfd_elf_tls_setup (link_info.output_bfd, &link_info); | |
e1918d23 | 1483 | |
cde7cb01 MR |
1484 | /* Make __ehdr_start hidden if it has been referenced, to |
1485 | prevent the symbol from being dynamic. */ | |
0e1862bb | 1486 | if (!bfd_link_relocatable (&link_info)) |
c2763e27 RM |
1487 | { |
1488 | struct elf_link_hash_entry *h | |
1489 | = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start", | |
1490 | FALSE, FALSE, TRUE); | |
1491 | ||
1492 | /* Only adjust the export class if the symbol was referenced | |
1493 | and not defined, otherwise leave it alone. */ | |
1494 | if (h != NULL | |
1495 | && (h->root.type == bfd_link_hash_new | |
1496 | || h->root.type == bfd_link_hash_undefined | |
1497 | || h->root.type == bfd_link_hash_undefweak | |
1498 | || h->root.type == bfd_link_hash_common)) | |
1499 | { | |
1500 | _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE); | |
1501 | if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL) | |
1502 | h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; | |
4199e3b8 AM |
1503 | /* Don't leave the symbol undefined. Undefined hidden |
1504 | symbols typically won't have dynamic relocations, but | |
1505 | we most likely will need dynamic relocations for | |
1506 | __ehdr_start if we are building a PIE or shared | |
1507 | library. */ | |
1508 | ehdr_start = h; | |
1509 | ehdr_start_save = h->root; | |
1510 | h->root.type = bfd_link_hash_defined; | |
1511 | h->root.u.def.section = bfd_abs_section_ptr; | |
1512 | h->root.u.def.value = 0; | |
c2763e27 RM |
1513 | } |
1514 | } | |
cde7cb01 | 1515 | |
a5382c42 MR |
1516 | /* If we are going to make any variable assignments, we need to |
1517 | let the ELF backend know about them in case the variables are | |
1518 | referred to by dynamic objects. */ | |
1519 | lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment); | |
1520 | } | |
252b5132 RH |
1521 | |
1522 | /* Let the ELF backend work out the sizes of any sections required | |
1523 | by dynamic linking. */ | |
1524 | rpath = command_line.rpath; | |
1525 | if (rpath == NULL) | |
1526 | rpath = (const char *) getenv ("LD_RUN_PATH"); | |
7ee314fa | 1527 | |
c72f2fb2 | 1528 | for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next) |
8dd881b6 L |
1529 | if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) |
1530 | { | |
1531 | const char *audit_libs = elf_dt_audit (abfd); | |
7ee314fa | 1532 | |
4724d37e | 1533 | /* If the input bfd contains an audit entry, we need to add it as |
8dd881b6 L |
1534 | a dep audit entry. */ |
1535 | if (audit_libs && *audit_libs != '\0') | |
1536 | { | |
1537 | char *cp = xstrdup (audit_libs); | |
1538 | do | |
1539 | { | |
1540 | int more = 0; | |
1541 | char *cp2 = strchr (cp, config.rpath_separator); | |
7ee314fa | 1542 | |
8dd881b6 L |
1543 | if (cp2) |
1544 | { | |
1545 | *cp2 = '\0'; | |
1546 | more = 1; | |
1547 | } | |
7ee314fa | 1548 | |
8dd881b6 L |
1549 | if (cp != NULL && *cp != '\0') |
1550 | gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp); | |
1551 | ||
1552 | cp = more ? ++cp2 : NULL; | |
1553 | } | |
1554 | while (cp != NULL); | |
1555 | } | |
1556 | } | |
7ee314fa | 1557 | |
5a580b3a | 1558 | if (! (bfd_elf_size_dynamic_sections |
f13a99db | 1559 | (link_info.output_bfd, command_line.soname, rpath, |
7ee314fa | 1560 | command_line.filter_shlib, audit, depaudit, |
252b5132 | 1561 | (const char * const *) command_line.auxiliary_filters, |
fd91d419 | 1562 | &link_info, &sinterp))) |
252b5132 | 1563 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); |
8423293d | 1564 | |
57e6abd2 | 1565 | ${ELF_INTERPRETER_SET_DEFAULT} |
252b5132 RH |
1566 | /* Let the user override the dynamic linker we are using. */ |
1567 | if (command_line.interpreter != NULL | |
1568 | && sinterp != NULL) | |
1569 | { | |
1570 | sinterp->contents = (bfd_byte *) command_line.interpreter; | |
eea6121a | 1571 | sinterp->size = strlen (command_line.interpreter) + 1; |
252b5132 RH |
1572 | } |
1573 | ||
1574 | /* Look for any sections named .gnu.warning. As a GNU extensions, | |
1575 | we treat such sections as containing warning messages. We print | |
1576 | out the warning message, and then zero out the section size so | |
1577 | that it does not get copied into the output file. */ | |
1578 | ||
1579 | { | |
1580 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
1581 | { | |
1582 | asection *s; | |
1583 | bfd_size_type sz; | |
1584 | char *msg; | |
252b5132 | 1585 | |
66be1055 | 1586 | if (is->flags.just_syms) |
252b5132 RH |
1587 | continue; |
1588 | ||
1589 | s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning"); | |
1590 | if (s == NULL) | |
1591 | continue; | |
1592 | ||
eea6121a | 1593 | sz = s->size; |
1e9cc1c2 | 1594 | msg = (char *) xmalloc ((size_t) (sz + 1)); |
bc251d50 | 1595 | if (! bfd_get_section_contents (is->the_bfd, s, msg, |
8c675694 | 1596 | (file_ptr) 0, sz)) |
252b5132 RH |
1597 | einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", |
1598 | is->the_bfd); | |
bc251d50 | 1599 | msg[sz] = '\0'; |
1a72702b AM |
1600 | (*link_info.callbacks->warning) (&link_info, msg, |
1601 | (const char *) NULL, is->the_bfd, | |
1602 | (asection *) NULL, (bfd_vma) 0); | |
252b5132 RH |
1603 | free (msg); |
1604 | ||
9e3be61d AM |
1605 | /* Clobber the section size, so that we don't waste space |
1606 | copying the warning into the output file. If we've already | |
1607 | sized the output section, adjust its size. The adjustment | |
1608 | is on rawsize because targets that size sections early will | |
1609 | have called lang_reset_memory_regions after sizing. */ | |
1610 | if (s->output_section != NULL | |
1611 | && s->output_section->rawsize >= s->size) | |
1612 | s->output_section->rawsize -= s->size; | |
1613 | ||
eea6121a | 1614 | s->size = 0; |
11d2f718 | 1615 | |
9e3be61d AM |
1616 | /* Also set SEC_EXCLUDE, so that local symbols defined in the |
1617 | warning section don't get copied to the output. */ | |
a14a5de3 | 1618 | s->flags |= SEC_EXCLUDE | SEC_KEEP; |
252b5132 RH |
1619 | } |
1620 | } | |
8423293d | 1621 | |
1e035701 | 1622 | before_allocation_default (); |
8423293d | 1623 | |
f13a99db | 1624 | if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info)) |
8423293d | 1625 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); |
4199e3b8 AM |
1626 | |
1627 | if (ehdr_start != NULL) | |
1628 | { | |
1629 | /* If we twiddled __ehdr_start to defined earlier, put it back | |
1630 | as it was. */ | |
1631 | ehdr_start->root.type = ehdr_start_save.type; | |
1632 | ehdr_start->root.u = ehdr_start_save.u; | |
1633 | } | |
252b5132 RH |
1634 | } |
1635 | ||
41392f03 AM |
1636 | EOF |
1637 | fi | |
1638 | ||
1639 | if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then | |
92b93329 | 1640 | fragment <<EOF |
252b5132 | 1641 | |
04925e1e AM |
1642 | /* Try to open a dynamic archive. This is where we know that ELF |
1643 | dynamic libraries have an extension of .so (or .sl on oddball systems | |
1644 | like hpux). */ | |
1645 | ||
b34976b6 | 1646 | static bfd_boolean |
0c7a8e5a AM |
1647 | gld${EMULATION_NAME}_open_dynamic_archive |
1648 | (const char *arch, search_dirs_type *search, lang_input_statement_type *entry) | |
252b5132 | 1649 | { |
04925e1e AM |
1650 | const char *filename; |
1651 | char *string; | |
d4ae5fb0 AM |
1652 | size_t len; |
1653 | bfd_boolean opened = FALSE; | |
252b5132 | 1654 | |
66be1055 | 1655 | if (! entry->flags.maybe_archive) |
b34976b6 | 1656 | return FALSE; |
252b5132 | 1657 | |
04925e1e | 1658 | filename = entry->filename; |
d4ae5fb0 AM |
1659 | len = strlen (search->name) + strlen (filename); |
1660 | if (entry->flags.full_name_provided) | |
1661 | { | |
1662 | len += sizeof "/"; | |
1663 | string = (char *) xmalloc (len); | |
1664 | sprintf (string, "%s/%s", search->name, filename); | |
1665 | } | |
1666 | else | |
1667 | { | |
1668 | size_t xlen = 0; | |
252b5132 | 1669 | |
d4ae5fb0 | 1670 | len += strlen (arch) + sizeof "/lib.so"; |
04925e1e | 1671 | #ifdef EXTRA_SHLIB_EXTENSION |
d4ae5fb0 AM |
1672 | xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3 |
1673 | ? strlen (EXTRA_SHLIB_EXTENSION) - 3 | |
1674 | : 0); | |
04925e1e | 1675 | #endif |
d4ae5fb0 AM |
1676 | string = (char *) xmalloc (len + xlen); |
1677 | sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); | |
04925e1e | 1678 | #ifdef EXTRA_SHLIB_EXTENSION |
d4ae5fb0 AM |
1679 | /* Try the .so extension first. If that fails build a new filename |
1680 | using EXTRA_SHLIB_EXTENSION. */ | |
1681 | opened = ldfile_try_open_bfd (string, entry); | |
1682 | if (!opened) | |
1683 | strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION); | |
04925e1e | 1684 | #endif |
d4ae5fb0 | 1685 | } |
04925e1e | 1686 | |
d4ae5fb0 | 1687 | if (!opened && !ldfile_try_open_bfd (string, entry)) |
252b5132 | 1688 | { |
04925e1e | 1689 | free (string); |
b34976b6 | 1690 | return FALSE; |
04925e1e | 1691 | } |
252b5132 | 1692 | |
04925e1e | 1693 | entry->filename = string; |
252b5132 | 1694 | |
04925e1e AM |
1695 | /* We have found a dynamic object to include in the link. The ELF |
1696 | backend linker will create a DT_NEEDED entry in the .dynamic | |
1697 | section naming this file. If this file includes a DT_SONAME | |
1698 | entry, it will be used. Otherwise, the ELF linker will just use | |
1699 | the name of the file. For an archive found by searching, like | |
1700 | this one, the DT_NEEDED entry should consist of just the name of | |
1701 | the file, without the path information used to find it. Note | |
1702 | that we only need to do this if we have a dynamic object; an | |
1703 | archive will never be referenced by a DT_NEEDED entry. | |
252b5132 | 1704 | |
04925e1e AM |
1705 | FIXME: This approach--using bfd_elf_set_dt_needed_name--is not |
1706 | very pretty. I haven't been able to think of anything that is | |
1707 | pretty, though. */ | |
1708 | if (bfd_check_format (entry->the_bfd, bfd_object) | |
1709 | && (entry->the_bfd->flags & DYNAMIC) != 0) | |
1710 | { | |
66be1055 | 1711 | ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs); |
252b5132 | 1712 | |
04925e1e | 1713 | /* Rather than duplicating the logic above. Just use the |
1c9acd94 | 1714 | filename we recorded earlier. */ |
04925e1e | 1715 | |
d4ae5fb0 AM |
1716 | if (!entry->flags.full_name_provided) |
1717 | filename = lbasename (entry->filename); | |
1c9acd94 | 1718 | bfd_elf_set_dt_needed_name (entry->the_bfd, filename); |
04925e1e AM |
1719 | } |
1720 | ||
b34976b6 | 1721 | return TRUE; |
04925e1e AM |
1722 | } |
1723 | ||
41392f03 AM |
1724 | EOF |
1725 | fi | |
cde43e70 AM |
1726 | |
1727 | if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then | |
92b93329 | 1728 | fragment <<EOF |
41392f03 | 1729 | |
afd7a018 | 1730 | /* A variant of lang_output_section_find used by place_orphan. */ |
04925e1e | 1731 | |
04925e1e | 1732 | static lang_output_section_statement_type * |
2a36a117 | 1733 | output_rel_find (asection *sec, int isdyn) |
04925e1e | 1734 | { |
04925e1e | 1735 | lang_output_section_statement_type *lookup; |
ba493122 | 1736 | lang_output_section_statement_type *last = NULL; |
2a36a117 | 1737 | lang_output_section_statement_type *last_alloc = NULL; |
48f2ff54 | 1738 | lang_output_section_statement_type *last_ro_alloc = NULL; |
ba493122 AM |
1739 | lang_output_section_statement_type *last_rel = NULL; |
1740 | lang_output_section_statement_type *last_rel_alloc = NULL; | |
24cdb50a | 1741 | int rela = sec->name[4] == 'a'; |
04925e1e | 1742 | |
afd7a018 AM |
1743 | for (lookup = &lang_output_section_statement.head->output_section_statement; |
1744 | lookup != NULL; | |
1745 | lookup = lookup->next) | |
04925e1e | 1746 | { |
66c103b7 | 1747 | if (lookup->constraint >= 0 |
0112cd26 | 1748 | && CONST_STRNEQ (lookup->name, ".rel")) |
04925e1e | 1749 | { |
24cdb50a | 1750 | int lookrela = lookup->name[4] == 'a'; |
ba493122 | 1751 | |
2a36a117 AM |
1752 | /* .rel.dyn must come before all other reloc sections, to suit |
1753 | GNU ld.so. */ | |
1754 | if (isdyn) | |
1755 | break; | |
1756 | ||
1757 | /* Don't place after .rel.plt as doing so results in wrong | |
1758 | dynamic tags. */ | |
1759 | if (strcmp (".plt", lookup->name + 4 + lookrela) == 0) | |
ba493122 | 1760 | break; |
2a36a117 AM |
1761 | |
1762 | if (rela == lookrela || last_rel == NULL) | |
24cdb50a | 1763 | last_rel = lookup; |
2a36a117 AM |
1764 | if ((rela == lookrela || last_rel_alloc == NULL) |
1765 | && lookup->bfd_section != NULL | |
ba493122 AM |
1766 | && (lookup->bfd_section->flags & SEC_ALLOC) != 0) |
1767 | last_rel_alloc = lookup; | |
04925e1e | 1768 | } |
2a36a117 AM |
1769 | |
1770 | last = lookup; | |
1771 | if (lookup->bfd_section != NULL | |
1772 | && (lookup->bfd_section->flags & SEC_ALLOC) != 0) | |
48f2ff54 AM |
1773 | { |
1774 | last_alloc = lookup; | |
1775 | if ((lookup->bfd_section->flags & SEC_READONLY) != 0) | |
1776 | last_ro_alloc = lookup; | |
1777 | } | |
252b5132 | 1778 | } |
ba493122 AM |
1779 | |
1780 | if (last_rel_alloc) | |
1781 | return last_rel_alloc; | |
1782 | ||
1783 | if (last_rel) | |
1784 | return last_rel; | |
1785 | ||
48f2ff54 AM |
1786 | if (last_ro_alloc) |
1787 | return last_ro_alloc; | |
1788 | ||
2a36a117 AM |
1789 | if (last_alloc) |
1790 | return last_alloc; | |
1791 | ||
ba493122 | 1792 | return last; |
252b5132 RH |
1793 | } |
1794 | ||
1795 | /* Place an orphan section. We use this to put random SHF_ALLOC | |
1796 | sections in the right segment. */ | |
1797 | ||
c2edb4b8 | 1798 | static lang_output_section_statement_type * |
8a99a385 AM |
1799 | gld${EMULATION_NAME}_place_orphan (asection *s, |
1800 | const char *secname, | |
1801 | int constraint) | |
252b5132 | 1802 | { |
afd7a018 AM |
1803 | static struct orphan_save hold[] = |
1804 | { | |
1805 | { ".text", | |
1806 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE, | |
1807 | 0, 0, 0, 0 }, | |
1808 | { ".rodata", | |
1809 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA, | |
1810 | 0, 0, 0, 0 }, | |
d85e71fe L |
1811 | { ".tdata", |
1812 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL, | |
1813 | 0, 0, 0, 0 }, | |
afd7a018 AM |
1814 | { ".data", |
1815 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA, | |
1816 | 0, 0, 0, 0 }, | |
1817 | { ".bss", | |
1818 | SEC_ALLOC, | |
1819 | 0, 0, 0, 0 }, | |
1820 | { 0, | |
1821 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA, | |
1822 | 0, 0, 0, 0 }, | |
1823 | { ".interp", | |
1824 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA, | |
1825 | 0, 0, 0, 0 }, | |
1826 | { ".sdata", | |
1827 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA, | |
07890c07 | 1828 | 0, 0, 0, 0 }, |
175b7cd4 | 1829 | { ".comment", |
07890c07 AM |
1830 | SEC_HAS_CONTENTS, |
1831 | 0, 0, 0, 0 }, | |
afd7a018 AM |
1832 | }; |
1833 | enum orphan_save_index | |
1834 | { | |
1835 | orphan_text = 0, | |
1836 | orphan_rodata, | |
d85e71fe | 1837 | orphan_tdata, |
afd7a018 AM |
1838 | orphan_data, |
1839 | orphan_bss, | |
1840 | orphan_rel, | |
1841 | orphan_interp, | |
07890c07 AM |
1842 | orphan_sdata, |
1843 | orphan_nonalloc | |
afd7a018 AM |
1844 | }; |
1845 | static int orphan_init_done = 0; | |
6a345e87 | 1846 | struct orphan_save *place; |
afd7a018 | 1847 | lang_output_section_statement_type *after; |
252b5132 | 1848 | lang_output_section_statement_type *os; |
b5f14a6d | 1849 | lang_output_section_statement_type *match_by_name = NULL; |
24cdb50a | 1850 | int isdyn = 0; |
ecca9871 L |
1851 | int iself = s->owner->xvec->flavour == bfd_target_elf_flavour; |
1852 | unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL; | |
199af150 AM |
1853 | flagword flags; |
1854 | asection *nexts; | |
252b5132 | 1855 | |
0e1862bb | 1856 | if (!bfd_link_relocatable (&link_info) |
24cdb50a | 1857 | && link_info.combreloc |
ecca9871 | 1858 | && (s->flags & SEC_ALLOC)) |
24cdb50a | 1859 | { |
ecca9871 L |
1860 | if (iself) |
1861 | switch (sh_type) | |
1862 | { | |
1863 | case SHT_RELA: | |
1864 | secname = ".rela.dyn"; | |
1865 | isdyn = 1; | |
1866 | break; | |
1867 | case SHT_REL: | |
1868 | secname = ".rel.dyn"; | |
1869 | isdyn = 1; | |
1870 | break; | |
1871 | default: | |
1872 | break; | |
1873 | } | |
0112cd26 | 1874 | else if (CONST_STRNEQ (secname, ".rel")) |
ecca9871 L |
1875 | { |
1876 | secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn"; | |
1877 | isdyn = 1; | |
1878 | } | |
24cdb50a | 1879 | } |
aea4bd9d | 1880 | |
bcacc0f5 | 1881 | /* Look through the script to see where to place this section. */ |
d127ecce AM |
1882 | if (constraint == 0) |
1883 | for (os = lang_output_section_find (secname); | |
1884 | os != NULL; | |
1885 | os = next_matching_output_section_statement (os, 0)) | |
1886 | { | |
1887 | /* If we don't match an existing output section, tell | |
1888 | lang_insert_orphan to create a new output section. */ | |
1889 | constraint = SPECIAL; | |
1890 | ||
1891 | if (os->bfd_section != NULL | |
1892 | && (os->bfd_section->flags == 0 | |
199af150 AM |
1893 | || (((s->flags ^ os->bfd_section->flags) |
1894 | & (SEC_LOAD | SEC_ALLOC)) == 0 | |
1895 | && _bfd_elf_match_sections_by_type (link_info.output_bfd, | |
1896 | os->bfd_section, | |
1897 | s->owner, s)))) | |
d127ecce AM |
1898 | { |
1899 | /* We already have an output section statement with this | |
1900 | name, and its bfd section has compatible flags. | |
1901 | If the section already exists but does not have any flags | |
1902 | set, then it has been created by the linker, probably as a | |
1903 | result of a --section-start command line switch. */ | |
b9c361e0 | 1904 | lang_add_section (&os->children, s, NULL, os); |
d127ecce AM |
1905 | return os; |
1906 | } | |
b5f14a6d DD |
1907 | |
1908 | /* Save unused output sections in case we can match them | |
1909 | against orphans later. */ | |
1910 | if (os->bfd_section == NULL) | |
1911 | match_by_name = os; | |
d127ecce | 1912 | } |
252b5132 | 1913 | |
b5f14a6d DD |
1914 | /* If we didn't match an active output section, see if we matched an |
1915 | unused one and use that. */ | |
1916 | if (match_by_name) | |
1917 | { | |
b9c361e0 | 1918 | lang_add_section (&match_by_name->children, s, NULL, match_by_name); |
b5f14a6d DD |
1919 | return match_by_name; |
1920 | } | |
1921 | ||
afd7a018 AM |
1922 | if (!orphan_init_done) |
1923 | { | |
1924 | struct orphan_save *ho; | |
07890c07 | 1925 | |
afd7a018 AM |
1926 | for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho) |
1927 | if (ho->name != NULL) | |
1928 | { | |
1929 | ho->os = lang_output_section_find (ho->name); | |
1930 | if (ho->os != NULL && ho->os->flags == 0) | |
1931 | ho->os->flags = ho->flags; | |
1932 | } | |
1933 | orphan_init_done = 1; | |
1934 | } | |
252b5132 RH |
1935 | |
1936 | /* If this is a final link, then always put .gnu.warning.SYMBOL | |
1937 | sections into the .text section to get them out of the way. */ | |
0e1862bb | 1938 | if (bfd_link_executable (&link_info) |
bcacc0f5 | 1939 | && CONST_STRNEQ (s->name, ".gnu.warning.") |
afd7a018 | 1940 | && hold[orphan_text].os != NULL) |
252b5132 | 1941 | { |
c2edb4b8 | 1942 | os = hold[orphan_text].os; |
b9c361e0 | 1943 | lang_add_section (&os->children, s, NULL, os); |
c2edb4b8 | 1944 | return os; |
252b5132 RH |
1945 | } |
1946 | ||
077fcd6a L |
1947 | flags = s->flags; |
1948 | if (!bfd_link_relocatable (&link_info)) | |
1949 | { | |
1950 | nexts = s; | |
1951 | while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)) | |
1952 | != NULL) | |
1953 | if (nexts->output_section == NULL | |
1954 | && (nexts->flags & SEC_EXCLUDE) == 0 | |
1955 | && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 | |
1956 | && (nexts->owner->flags & DYNAMIC) == 0 | |
1957 | && nexts->owner->usrdata != NULL | |
1958 | && !(((lang_input_statement_type *) nexts->owner->usrdata) | |
1959 | ->flags.just_syms) | |
1960 | && _bfd_elf_match_sections_by_type (nexts->owner, nexts, | |
1961 | s->owner, s)) | |
1962 | flags = (((flags ^ SEC_READONLY) | |
1963 | | (nexts->flags ^ SEC_READONLY)) | |
1964 | ^ SEC_READONLY); | |
1965 | } | |
1966 | ||
252b5132 RH |
1967 | /* Decide which segment the section should go in based on the |
1968 | section name and section flags. We put loadable .note sections | |
1969 | right after the .interp section, so that the PT_NOTE segment is | |
1970 | stored right after the program headers where the OS can read it | |
1971 | in the first page. */ | |
aea4bd9d | 1972 | |
71bfc0ae | 1973 | place = NULL; |
199af150 | 1974 | if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0) |
07890c07 | 1975 | place = &hold[orphan_nonalloc]; |
199af150 | 1976 | else if ((flags & SEC_ALLOC) == 0) |
71bfc0ae | 1977 | ; |
199af150 | 1978 | else if ((flags & SEC_LOAD) != 0 |
ecca9871 | 1979 | && ((iself && sh_type == SHT_NOTE) |
0112cd26 | 1980 | || (!iself && CONST_STRNEQ (secname, ".note")))) |
afd7a018 | 1981 | place = &hold[orphan_interp]; |
199af150 | 1982 | else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0) |
afd7a018 | 1983 | place = &hold[orphan_bss]; |
199af150 | 1984 | else if ((flags & SEC_SMALL_DATA) != 0) |
afd7a018 | 1985 | place = &hold[orphan_sdata]; |
199af150 | 1986 | else if ((flags & SEC_THREAD_LOCAL) != 0) |
d85e71fe | 1987 | place = &hold[orphan_tdata]; |
199af150 | 1988 | else if ((flags & SEC_READONLY) == 0) |
afd7a018 | 1989 | place = &hold[orphan_data]; |
ecca9871 | 1990 | else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL)) |
0112cd26 | 1991 | || (!iself && CONST_STRNEQ (secname, ".rel"))) |
199af150 | 1992 | && (flags & SEC_LOAD) != 0) |
afd7a018 | 1993 | place = &hold[orphan_rel]; |
199af150 | 1994 | else if ((flags & SEC_CODE) == 0) |
afd7a018 AM |
1995 | place = &hold[orphan_rodata]; |
1996 | else | |
1997 | place = &hold[orphan_text]; | |
71bfc0ae | 1998 | |
afd7a018 | 1999 | after = NULL; |
5ba47421 | 2000 | if (place != NULL) |
252b5132 | 2001 | { |
afd7a018 | 2002 | if (place->os == NULL) |
5ba47421 | 2003 | { |
afd7a018 AM |
2004 | if (place->name != NULL) |
2005 | place->os = lang_output_section_find (place->name); | |
2006 | else | |
2007 | place->os = output_rel_find (s, isdyn); | |
5ba47421 | 2008 | } |
afd7a018 AM |
2009 | after = place->os; |
2010 | if (after == NULL) | |
93638471 AM |
2011 | after |
2012 | = lang_output_section_find_by_flags (s, flags, &place->os, | |
2013 | _bfd_elf_match_sections_by_type); | |
afd7a018 AM |
2014 | if (after == NULL) |
2015 | /* *ABS* is always the first output section statement. */ | |
2016 | after = &lang_output_section_statement.head->output_section_statement; | |
252b5132 RH |
2017 | } |
2018 | ||
c2edb4b8 | 2019 | return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL); |
252b5132 | 2020 | } |
c56feb2b AM |
2021 | EOF |
2022 | fi | |
2023 | ||
eaeb0a9d | 2024 | if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then |
92b93329 | 2025 | fragment <<EOF |
252b5132 | 2026 | |
deb04cdb | 2027 | static void |
eaeb0a9d | 2028 | gld${EMULATION_NAME}_after_allocation (void) |
deb04cdb | 2029 | { |
75938853 AM |
2030 | int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info); |
2031 | ||
2032 | if (need_layout < 0) | |
2033 | einfo ("%X%P: .eh_frame/.stab edit: %E\n"); | |
2034 | else | |
2035 | gld${EMULATION_NAME}_map_segments (need_layout); | |
73d074b4 | 2036 | } |
41392f03 AM |
2037 | EOF |
2038 | fi | |
2039 | ||
2040 | if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then | |
92b93329 | 2041 | fragment <<EOF |
252b5132 RH |
2042 | |
2043 | static char * | |
0c7a8e5a | 2044 | gld${EMULATION_NAME}_get_script (int *isfile) |
252b5132 RH |
2045 | EOF |
2046 | ||
7225345d | 2047 | if test x"$COMPILE_IN" = xyes |
252b5132 RH |
2048 | then |
2049 | # Scripts compiled in. | |
2050 | ||
2051 | # sed commands to quote an ld script as a C string. | |
597e2591 | 2052 | sc="-f stringify.sed" |
252b5132 | 2053 | |
92b93329 | 2054 | fragment <<EOF |
60bcf0fa | 2055 | { |
252b5132 RH |
2056 | *isfile = 0; |
2057 | ||
0e1862bb | 2058 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
597e2591 | 2059 | return |
252b5132 | 2060 | EOF |
afd7a018 | 2061 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
0e1862bb | 2062 | echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c |
afd7a018 AM |
2063 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
2064 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
2065 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
61585df2 | 2066 | if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else |
afd7a018 AM |
2067 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c |
2068 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
db6751f2 | 2069 | fi |
36af4a4e JJ |
2070 | if test -n "$GENERATE_PIE_SCRIPT" ; then |
2071 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then | |
0e1862bb L |
2072 | echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c |
2073 | echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c | |
2074 | echo ' && link_info.relro' >> e${EMULATION_NAME}.c | |
fbfca19e | 2075 | echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c |
afd7a018 | 2076 | sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c |
0e1862bb L |
2077 | echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c |
2078 | echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c | |
afd7a018 | 2079 | sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c |
36af4a4e | 2080 | fi |
0e1862bb | 2081 | echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c |
afd7a018 | 2082 | sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c |
36af4a4e | 2083 | fi |
252b5132 | 2084 | if test -n "$GENERATE_SHLIB_SCRIPT" ; then |
82434356 | 2085 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then |
0e1862bb | 2086 | echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c |
8c37241b | 2087 | echo ' && link_info.relro' >> e${EMULATION_NAME}.c |
fbfca19e | 2088 | echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c |
afd7a018 | 2089 | sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c |
0e1862bb | 2090 | echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c |
afd7a018 | 2091 | sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c |
82434356 | 2092 | fi |
0e1862bb | 2093 | echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c |
afd7a018 | 2094 | sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c |
252b5132 | 2095 | fi |
82434356 | 2096 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then |
8c37241b | 2097 | echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c |
fbfca19e | 2098 | echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c |
afd7a018 AM |
2099 | sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c |
2100 | echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c | |
2101 | sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c | |
82434356 | 2102 | fi |
afd7a018 AM |
2103 | echo ' ; else return' >> e${EMULATION_NAME}.c |
2104 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
2105 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
2106 | |
2107 | else | |
2108 | # Scripts read from the filesystem. | |
2109 | ||
92b93329 | 2110 | fragment <<EOF |
60bcf0fa | 2111 | { |
252b5132 RH |
2112 | *isfile = 1; |
2113 | ||
0e1862bb | 2114 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
252b5132 | 2115 | return "ldscripts/${EMULATION_NAME}.xu"; |
0e1862bb | 2116 | else if (bfd_link_relocatable (&link_info)) |
252b5132 RH |
2117 | return "ldscripts/${EMULATION_NAME}.xr"; |
2118 | else if (!config.text_read_only) | |
2119 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
a060b769 AM |
2120 | EOF |
2121 | if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : | |
2122 | else | |
92b93329 | 2123 | fragment <<EOF |
252b5132 RH |
2124 | else if (!config.magic_demand_paged) |
2125 | return "ldscripts/${EMULATION_NAME}.xn"; | |
a060b769 AM |
2126 | EOF |
2127 | fi | |
36af4a4e JJ |
2128 | if test -n "$GENERATE_PIE_SCRIPT" ; then |
2129 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then | |
92b93329 | 2130 | fragment <<EOF |
0e1862bb L |
2131 | else if (bfd_link_pie (&link_info) |
2132 | && link_info.combreloc | |
2133 | && link_info.relro | |
2134 | && (link_info.flags & DF_BIND_NOW)) | |
8c37241b | 2135 | return "ldscripts/${EMULATION_NAME}.xdw"; |
0e1862bb L |
2136 | else if (bfd_link_pie (&link_info) |
2137 | && link_info.combreloc) | |
36af4a4e JJ |
2138 | return "ldscripts/${EMULATION_NAME}.xdc"; |
2139 | EOF | |
2140 | fi | |
92b93329 | 2141 | fragment <<EOF |
0e1862bb | 2142 | else if (bfd_link_pie (&link_info)) |
36af4a4e JJ |
2143 | return "ldscripts/${EMULATION_NAME}.xd"; |
2144 | EOF | |
2145 | fi | |
a060b769 AM |
2146 | if test -n "$GENERATE_SHLIB_SCRIPT" ; then |
2147 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then | |
92b93329 | 2148 | fragment <<EOF |
0e1862bb | 2149 | else if (bfd_link_dll (&link_info) && link_info.combreloc |
fbfca19e | 2150 | && link_info.relro && (link_info.flags & DF_BIND_NOW)) |
8c37241b | 2151 | return "ldscripts/${EMULATION_NAME}.xsw"; |
0e1862bb | 2152 | else if (bfd_link_dll (&link_info) && link_info.combreloc) |
a060b769 AM |
2153 | return "ldscripts/${EMULATION_NAME}.xsc"; |
2154 | EOF | |
2155 | fi | |
92b93329 | 2156 | fragment <<EOF |
0e1862bb | 2157 | else if (bfd_link_dll (&link_info)) |
252b5132 | 2158 | return "ldscripts/${EMULATION_NAME}.xs"; |
a060b769 AM |
2159 | EOF |
2160 | fi | |
2161 | if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then | |
92b93329 | 2162 | fragment <<EOF |
8c37241b | 2163 | else if (link_info.combreloc && link_info.relro |
fbfca19e | 2164 | && (link_info.flags & DF_BIND_NOW)) |
8c37241b | 2165 | return "ldscripts/${EMULATION_NAME}.xw"; |
a060b769 AM |
2166 | else if (link_info.combreloc) |
2167 | return "ldscripts/${EMULATION_NAME}.xc"; | |
2168 | EOF | |
2169 | fi | |
92b93329 | 2170 | fragment <<EOF |
252b5132 RH |
2171 | else |
2172 | return "ldscripts/${EMULATION_NAME}.x"; | |
2173 | } | |
252b5132 | 2174 | |
3b108066 | 2175 | EOF |
41392f03 AM |
2176 | fi |
2177 | fi | |
3b108066 | 2178 | |
e0ee487b | 2179 | if test -n "$PARSE_AND_LIST_PROLOGUE" ; then |
92b93329 | 2180 | fragment <<EOF |
e0ee487b L |
2181 | $PARSE_AND_LIST_PROLOGUE |
2182 | EOF | |
2183 | fi | |
2184 | ||
92b93329 | 2185 | fragment <<EOF |
e0ee487b | 2186 | |
6c1439be L |
2187 | #define OPTION_DISABLE_NEW_DTAGS (400) |
2188 | #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1) | |
a1ab1d2a | 2189 | #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1) |
65765700 | 2190 | #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1) |
b58f81ae | 2191 | #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1) |
fdc90cb4 | 2192 | #define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1) |
c0065db7 | 2193 | #define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1) |
7ee314fa | 2194 | #define OPTION_AUDIT (OPTION_BUILD_ID + 1) |
0ce398f1 | 2195 | #define OPTION_COMPRESS_DEBUG (OPTION_AUDIT + 1) |
e13629bc | 2196 | |
3bcf5557 | 2197 | static void |
0c7a8e5a AM |
2198 | gld${EMULATION_NAME}_add_options |
2199 | (int ns, char **shortopts, int nl, struct option **longopts, | |
2200 | int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED) | |
e0ee487b | 2201 | { |
fb42df5e AM |
2202 | EOF |
2203 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
2204 | fragment <<EOF | |
7ee314fa | 2205 | static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:"; |
fb42df5e AM |
2206 | EOF |
2207 | else | |
2208 | fragment <<EOF | |
2209 | static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:"; | |
2210 | EOF | |
2211 | fi | |
2212 | fragment <<EOF | |
3bcf5557 | 2213 | static const struct option xtra_long[] = { |
fb42df5e AM |
2214 | EOF |
2215 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
2216 | fragment <<EOF | |
7ee314fa | 2217 | {"audit", required_argument, NULL, OPTION_AUDIT}, |
fb42df5e AM |
2218 | {"Bgroup", no_argument, NULL, OPTION_GROUP}, |
2219 | EOF | |
2220 | fi | |
2221 | fragment <<EOF | |
2222 | {"build-id", optional_argument, NULL, OPTION_BUILD_ID}, | |
0ce398f1 | 2223 | {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG}, |
e0ee487b | 2224 | EOF |
e0ee487b | 2225 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then |
92b93329 | 2226 | fragment <<EOF |
fb42df5e | 2227 | {"depaudit", required_argument, NULL, 'P'}, |
3bcf5557 AM |
2228 | {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, |
2229 | {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, | |
2230 | {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR}, | |
b58f81ae | 2231 | {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS}, |
fdc90cb4 | 2232 | {"hash-style", required_argument, NULL, OPTION_HASH_STYLE}, |
e0ee487b L |
2233 | EOF |
2234 | fi | |
e0ee487b | 2235 | if test -n "$PARSE_AND_LIST_LONGOPTS" ; then |
92b93329 | 2236 | fragment <<EOF |
3bcf5557 | 2237 | $PARSE_AND_LIST_LONGOPTS |
e0ee487b L |
2238 | EOF |
2239 | fi | |
92b93329 | 2240 | fragment <<EOF |
3bcf5557 AM |
2241 | {NULL, no_argument, NULL, 0} |
2242 | }; | |
2243 | ||
2244 | *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short)); | |
2245 | memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short)); | |
2246 | *longopts = (struct option *) | |
2247 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); | |
2248 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); | |
2249 | } | |
04925e1e | 2250 | |
24382dca | 2251 | #define DEFAULT_BUILD_ID_STYLE "sha1" |
c0065db7 | 2252 | |
3bcf5557 | 2253 | static bfd_boolean |
0c7a8e5a | 2254 | gld${EMULATION_NAME}_handle_option (int optc) |
e0ee487b | 2255 | { |
e0ee487b L |
2256 | switch (optc) |
2257 | { | |
2258 | default: | |
3bcf5557 | 2259 | return FALSE; |
6c1439be | 2260 | |
c0065db7 | 2261 | case OPTION_BUILD_ID: |
30e8ee25 | 2262 | if (emit_note_gnu_build_id != NULL) |
c0065db7 | 2263 | { |
30e8ee25 AM |
2264 | free ((char *) emit_note_gnu_build_id); |
2265 | emit_note_gnu_build_id = NULL; | |
c0065db7 RM |
2266 | } |
2267 | if (optarg == NULL) | |
2268 | optarg = DEFAULT_BUILD_ID_STYLE; | |
2269 | if (strcmp (optarg, "none")) | |
30e8ee25 | 2270 | emit_note_gnu_build_id = xstrdup (optarg); |
c0065db7 | 2271 | break; |
fb42df5e | 2272 | |
0ce398f1 L |
2273 | case OPTION_COMPRESS_DEBUG: |
2274 | if (strcasecmp (optarg, "none") == 0) | |
2275 | link_info.compress_debug = COMPRESS_DEBUG_NONE; | |
2276 | else if (strcasecmp (optarg, "zlib") == 0) | |
19a7fe52 | 2277 | link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB; |
0ce398f1 L |
2278 | else if (strcasecmp (optarg, "zlib-gnu") == 0) |
2279 | link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB; | |
2280 | else if (strcasecmp (optarg, "zlib-gabi") == 0) | |
2281 | link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB; | |
2282 | else | |
2283 | einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"), | |
2284 | optarg); | |
2285 | break; | |
fb42df5e AM |
2286 | EOF |
2287 | ||
2288 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
2289 | fragment <<EOF | |
7ee314fa | 2290 | case OPTION_AUDIT: |
4724d37e | 2291 | gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg); |
7ee314fa | 2292 | break; |
fb42df5e | 2293 | |
7ee314fa AM |
2294 | case 'P': |
2295 | gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg); | |
2296 | break; | |
c0065db7 | 2297 | |
6c1439be | 2298 | case OPTION_DISABLE_NEW_DTAGS: |
b34976b6 | 2299 | link_info.new_dtags = FALSE; |
6c1439be L |
2300 | break; |
2301 | ||
2302 | case OPTION_ENABLE_NEW_DTAGS: | |
b34976b6 | 2303 | link_info.new_dtags = TRUE; |
6c1439be L |
2304 | break; |
2305 | ||
65765700 | 2306 | case OPTION_EH_FRAME_HDR: |
2f0c68f2 | 2307 | link_info.eh_frame_hdr_type = DWARF2_EH_HDR; |
65765700 JJ |
2308 | break; |
2309 | ||
a1ab1d2a UD |
2310 | case OPTION_GROUP: |
2311 | link_info.flags_1 |= (bfd_vma) DF_1_GROUP; | |
2312 | /* Groups must be self-contained. */ | |
560e09e9 NC |
2313 | link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; |
2314 | link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; | |
a1ab1d2a UD |
2315 | break; |
2316 | ||
b58f81ae DJ |
2317 | case OPTION_EXCLUDE_LIBS: |
2318 | add_excluded_libs (optarg); | |
2319 | break; | |
2320 | ||
fdc90cb4 JJ |
2321 | case OPTION_HASH_STYLE: |
2322 | link_info.emit_hash = FALSE; | |
2323 | link_info.emit_gnu_hash = FALSE; | |
2324 | if (strcmp (optarg, "sysv") == 0) | |
2325 | link_info.emit_hash = TRUE; | |
2326 | else if (strcmp (optarg, "gnu") == 0) | |
2327 | link_info.emit_gnu_hash = TRUE; | |
2328 | else if (strcmp (optarg, "both") == 0) | |
2329 | { | |
2330 | link_info.emit_hash = TRUE; | |
2331 | link_info.emit_gnu_hash = TRUE; | |
2332 | } | |
2333 | else | |
2334 | einfo (_("%P%F: invalid hash style \`%s'\n"), optarg); | |
2335 | break; | |
2336 | ||
fb42df5e AM |
2337 | EOF |
2338 | fi | |
2339 | fragment <<EOF | |
e0ee487b | 2340 | case 'z': |
fb42df5e AM |
2341 | if (strcmp (optarg, "defs") == 0) |
2342 | link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; | |
2343 | else if (strcmp (optarg, "muldefs") == 0) | |
2344 | link_info.allow_multiple_definition = TRUE; | |
2345 | else if (CONST_STRNEQ (optarg, "max-page-size=")) | |
2346 | { | |
2347 | char *end; | |
2348 | ||
2349 | config.maxpagesize = strtoul (optarg + 14, &end, 0); | |
2350 | if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0) | |
2351 | einfo (_("%P%F: invalid maxium page size \`%s'\n"), | |
2352 | optarg + 14); | |
2353 | } | |
2354 | else if (CONST_STRNEQ (optarg, "common-page-size=")) | |
2355 | { | |
2356 | char *end; | |
2357 | config.commonpagesize = strtoul (optarg + 17, &end, 0); | |
2358 | if (*end | |
2359 | || (config.commonpagesize & (config.commonpagesize - 1)) != 0) | |
2360 | einfo (_("%P%F: invalid common page size \`%s'\n"), | |
2361 | optarg + 17); | |
2362 | } | |
04c3a755 NS |
2363 | else if (CONST_STRNEQ (optarg, "stack-size=")) |
2364 | { | |
2365 | char *end; | |
2366 | link_info.stacksize = strtoul (optarg + 11, &end, 0); | |
2367 | if (*end || link_info.stacksize < 0) | |
2368 | einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11); | |
2369 | if (!link_info.stacksize) | |
2370 | /* Use -1 for explicit no-stack, because zero means | |
2371 | 'default'. */ | |
2372 | link_info.stacksize = -1; | |
2373 | } | |
fb42df5e AM |
2374 | else if (strcmp (optarg, "execstack") == 0) |
2375 | { | |
2376 | link_info.execstack = TRUE; | |
2377 | link_info.noexecstack = FALSE; | |
2378 | } | |
2379 | else if (strcmp (optarg, "noexecstack") == 0) | |
2380 | { | |
2381 | link_info.noexecstack = TRUE; | |
2382 | link_info.execstack = FALSE; | |
2383 | } | |
2384 | EOF | |
d258b828 | 2385 | |
fb42df5e AM |
2386 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then |
2387 | fragment <<EOF | |
b039ef04 L |
2388 | else if (strcmp (optarg, "global") == 0) |
2389 | link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL; | |
fb42df5e | 2390 | else if (strcmp (optarg, "initfirst") == 0) |
e0ee487b L |
2391 | link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; |
2392 | else if (strcmp (optarg, "interpose") == 0) | |
2393 | link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; | |
2394 | else if (strcmp (optarg, "loadfltr") == 0) | |
2395 | link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; | |
2396 | else if (strcmp (optarg, "nodefaultlib") == 0) | |
2397 | link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; | |
2398 | else if (strcmp (optarg, "nodelete") == 0) | |
2399 | link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; | |
2400 | else if (strcmp (optarg, "nodlopen") == 0) | |
2401 | link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; | |
2402 | else if (strcmp (optarg, "nodump") == 0) | |
2403 | link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; | |
2404 | else if (strcmp (optarg, "now") == 0) | |
2405 | { | |
2406 | link_info.flags |= (bfd_vma) DF_BIND_NOW; | |
2407 | link_info.flags_1 |= (bfd_vma) DF_1_NOW; | |
2408 | } | |
5fa222e4 AM |
2409 | else if (strcmp (optarg, "lazy") == 0) |
2410 | { | |
2411 | link_info.flags &= ~(bfd_vma) DF_BIND_NOW; | |
2412 | link_info.flags_1 &= ~(bfd_vma) DF_1_NOW; | |
2413 | } | |
e0ee487b L |
2414 | else if (strcmp (optarg, "origin") == 0) |
2415 | { | |
2416 | link_info.flags |= (bfd_vma) DF_ORIGIN; | |
2417 | link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; | |
2418 | } | |
db6751f2 | 2419 | else if (strcmp (optarg, "combreloc") == 0) |
b34976b6 | 2420 | link_info.combreloc = TRUE; |
db6751f2 | 2421 | else if (strcmp (optarg, "nocombreloc") == 0) |
b34976b6 | 2422 | link_info.combreloc = FALSE; |
8bd621d8 | 2423 | else if (strcmp (optarg, "nocopyreloc") == 0) |
0c7a8e5a | 2424 | link_info.nocopyreloc = TRUE; |
8c37241b JJ |
2425 | else if (strcmp (optarg, "relro") == 0) |
2426 | link_info.relro = TRUE; | |
2427 | else if (strcmp (optarg, "norelro") == 0) | |
2428 | link_info.relro = FALSE; | |
b8871f35 L |
2429 | else if (strcmp (optarg, "common") == 0) |
2430 | link_info.elf_stt_common = elf_stt_common; | |
2431 | else if (strcmp (optarg, "nocommon") == 0) | |
2432 | link_info.elf_stt_common = no_elf_stt_common; | |
c192a133 AM |
2433 | else if (strcmp (optarg, "text") == 0) |
2434 | link_info.error_textrel = TRUE; | |
2435 | else if (strcmp (optarg, "notext") == 0) | |
2436 | link_info.error_textrel = FALSE; | |
2437 | else if (strcmp (optarg, "textoff") == 0) | |
2438 | link_info.error_textrel = FALSE; | |
88b882e9 | 2439 | EOF |
fb42df5e | 2440 | fi |
88b882e9 | 2441 | |
eba27bd7 L |
2442 | if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then |
2443 | fragment <<EOF | |
2444 | $PARSE_AND_LIST_ARGS_CASE_Z | |
2445 | EOF | |
2446 | fi | |
2447 | ||
92b93329 | 2448 | fragment <<EOF |
fb42df5e AM |
2449 | else |
2450 | einfo (_("%P: warning: -z %s ignored.\n"), optarg); | |
6c1439be | 2451 | break; |
e0ee487b | 2452 | EOF |
e0ee487b L |
2453 | |
2454 | if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then | |
92b93329 | 2455 | fragment <<EOF |
e0ee487b L |
2456 | $PARSE_AND_LIST_ARGS_CASES |
2457 | EOF | |
2458 | fi | |
2459 | ||
92b93329 | 2460 | fragment <<EOF |
e0ee487b L |
2461 | } |
2462 | ||
3bcf5557 | 2463 | return TRUE; |
e0ee487b L |
2464 | } |
2465 | ||
41392f03 | 2466 | EOF |
41392f03 | 2467 | |
4b209b22 | 2468 | if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then |
c58212ea | 2469 | gld_list_options="gld${EMULATION_NAME}_list_options" |
eba27bd7 | 2470 | if test -n "$PARSE_AND_LIST_OPTIONS"; then |
92b93329 | 2471 | fragment <<EOF |
41392f03 | 2472 | |
e0ee487b | 2473 | static void |
0c7a8e5a | 2474 | gld${EMULATION_NAME}_list_options (FILE * file) |
e0ee487b | 2475 | { |
fb42df5e | 2476 | EOF |
e0ee487b L |
2477 | |
2478 | if test -n "$PARSE_AND_LIST_OPTIONS" ; then | |
92b93329 | 2479 | fragment <<EOF |
e0ee487b L |
2480 | $PARSE_AND_LIST_OPTIONS |
2481 | EOF | |
2482 | fi | |
2483 | ||
92b93329 | 2484 | fragment <<EOF |
e0ee487b L |
2485 | } |
2486 | EOF | |
c58212ea L |
2487 | else |
2488 | gld_list_options="NULL" | |
2489 | fi | |
e0ee487b L |
2490 | |
2491 | if test -n "$PARSE_AND_LIST_EPILOGUE" ; then | |
92b93329 | 2492 | fragment <<EOF |
e0ee487b L |
2493 | $PARSE_AND_LIST_EPILOGUE |
2494 | EOF | |
2495 | fi | |
41392f03 | 2496 | fi |
e0ee487b | 2497 | |
92b93329 | 2498 | fragment <<EOF |
252b5132 | 2499 | |
60bcf0fa | 2500 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
252b5132 | 2501 | { |
41392f03 AM |
2502 | ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, |
2503 | ${LDEMUL_SYSLIB-syslib_default}, | |
2504 | ${LDEMUL_HLL-hll_default}, | |
5fe2850d | 2505 | ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse}, |
41392f03 | 2506 | ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, |
eaeb0a9d | 2507 | ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}, |
41392f03 AM |
2508 | ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, |
2509 | ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, | |
2510 | ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, | |
2511 | ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, | |
252b5132 RH |
2512 | "${EMULATION_NAME}", |
2513 | "${OUTPUT_FORMAT}", | |
eaeb0a9d | 2514 | ${LDEMUL_FINISH-finish_default}, |
41392f03 AM |
2515 | ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, |
2516 | ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, | |
2517 | ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, | |
2518 | ${LDEMUL_SET_SYMBOLS-NULL}, | |
3bcf5557 AM |
2519 | ${LDEMUL_PARSE_ARGS-NULL}, |
2520 | gld${EMULATION_NAME}_add_options, | |
2521 | gld${EMULATION_NAME}_handle_option, | |
41392f03 | 2522 | ${LDEMUL_UNRECOGNIZED_FILE-NULL}, |
c58212ea | 2523 | ${LDEMUL_LIST_OPTIONS-${gld_list_options}}, |
4a43e768 | 2524 | ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols}, |
41392f03 | 2525 | ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, |
7a2f2d82 DD |
2526 | ${LDEMUL_NEW_VERS_PATTERN-NULL}, |
2527 | ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL} | |
252b5132 RH |
2528 | }; |
2529 | EOF |