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