1# $FreeBSD: head/contrib/binutils/ld/emultempl/elf32.em 77319 2001-05-28 06:21:27Z obrien $
| 1# $FreeBSD: head/contrib/binutils/ld/emultempl/elf32.em 78841 2001-06-26 17:57:37Z obrien $
|
2 3 4# This shell script emits a C file. -*- C -*- 5# It does some substitutions. 6# This file is now misnamed, because it supports both 32 bit and 64 bit 7# ELF emulations. 8test -z "${ELFSIZE}" && ELFSIZE=32 9cat >e${EMULATION_NAME}.c <<EOF 10/* This file is is generated by a shell script. DO NOT EDIT! */ 11 12/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
| 2 3 4# This shell script emits a C file. -*- C -*- 5# It does some substitutions. 6# This file is now misnamed, because it supports both 32 bit and 64 bit 7# ELF emulations. 8test -z "${ELFSIZE}" && ELFSIZE=32 9cat >e${EMULATION_NAME}.c <<EOF 10/* This file is is generated by a shell script. DO NOT EDIT! */ 11 12/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
|
13 Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
| 13 Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
|
14 Free Software Foundation, Inc. 15 Written by Steve Chamberlain <sac@cygnus.com> 16 ELF support by Ian Lance Taylor <ian@cygnus.com> 17 18This file is part of GLD, the Gnu Linker. 19 20This program is free software; you can redistribute it and/or modify 21it under the terms of the GNU General Public License as published by 22the Free Software Foundation; either version 2 of the License, or 23(at your option) any later version. 24 25This program is distributed in the hope that it will be useful, 26but WITHOUT ANY WARRANTY; without even the implied warranty of 27MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28GNU General Public License for more details. 29 30You should have received a copy of the GNU General Public License 31along with this program; if not, write to the Free Software 32Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 33 34#define TARGET_IS_${EMULATION_NAME} 35 36#include "bfd.h" 37#include "sysdep.h"
| 14 Free Software Foundation, Inc. 15 Written by Steve Chamberlain <sac@cygnus.com> 16 ELF support by Ian Lance Taylor <ian@cygnus.com> 17 18This file is part of GLD, the Gnu Linker. 19 20This program is free software; you can redistribute it and/or modify 21it under the terms of the GNU General Public License as published by 22the Free Software Foundation; either version 2 of the License, or 23(at your option) any later version. 24 25This program is distributed in the hope that it will be useful, 26but WITHOUT ANY WARRANTY; without even the implied warranty of 27MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28GNU General Public License for more details. 29 30You should have received a copy of the GNU General Public License 31along with this program; if not, write to the Free Software 32Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 33 34#define TARGET_IS_${EMULATION_NAME} 35 36#include "bfd.h" 37#include "sysdep.h"
|
| 38#include "libiberty.h"
|
38 39#include <ctype.h> 40 41#include "bfdlink.h" 42 43#include "ld.h" 44#include "ldmain.h" 45#include "ldmisc.h" 46#include "ldexp.h" 47#include "ldlang.h" 48#include "ldfile.h" 49#include "ldemul.h" 50#include "ldgram.h" 51#include "elf/common.h" 52 53static void gld${EMULATION_NAME}_before_parse PARAMS ((void)); 54static void gld${EMULATION_NAME}_vercheck 55 PARAMS ((lang_input_statement_type *)); 56static void gld${EMULATION_NAME}_stat_needed 57 PARAMS ((lang_input_statement_type *)); 58static boolean gld${EMULATION_NAME}_try_needed PARAMS ((const char *, int)); 59static boolean gld${EMULATION_NAME}_search_needed 60 PARAMS ((const char *, const char *, int)); 61static void gld${EMULATION_NAME}_check_needed 62 PARAMS ((lang_input_statement_type *)); 63static void gld${EMULATION_NAME}_after_open PARAMS ((void)); 64static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *)); 65static void gld${EMULATION_NAME}_find_statement_assignment 66 PARAMS ((lang_statement_union_type *)); 67static void gld${EMULATION_NAME}_before_allocation PARAMS ((void)); 68static boolean gld${EMULATION_NAME}_open_dynamic_archive 69 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *)); 70static lang_output_section_statement_type *output_rel_find PARAMS ((void)); 71static boolean gld${EMULATION_NAME}_place_orphan 72 PARAMS ((lang_input_statement_type *, asection *)); 73static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile)); 74 75EOF 76 77# Import any needed special functions and/or overrides. 78# 79if test -n "$EXTRA_EM_FILE" ; then 80. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em 81fi 82 83# Functions in this file can be overridden by setting the LDEMUL_* shell 84# variables. If the name of the overriding function is the same as is 85# defined in this file, then don't output this file's version. 86# If a different overriding name is given then output the standard function 87# as presumably it is called from the overriding function. 88# 89if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then 90cat >>e${EMULATION_NAME}.c <<EOF 91 92static void 93gld${EMULATION_NAME}_before_parse () 94{ 95 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`; 96 config.dynamic_link = ${DYNAMIC_LINK-true}; 97 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`; 98} 99 100EOF 101fi 102 103cat >>e${EMULATION_NAME}.c <<EOF 104 105/* These variables are required to pass information back and forth 106 between after_open and check_needed and stat_needed and vercheck. */ 107 108static struct bfd_link_needed_list *global_needed; 109static struct stat global_stat; 110static boolean global_found; 111static struct bfd_link_needed_list *global_vercheck_needed; 112static boolean global_vercheck_failed; 113 114 115/* On Linux, it's possible to have different versions of the same 116 shared library linked against different versions of libc. The 117 dynamic linker somehow tags which libc version to use in 118 /etc/ld.so.cache, and, based on the libc that it sees in the 119 executable, chooses which version of the shared library to use. 120 121 We try to do a similar check here by checking whether this shared 122 library needs any other shared libraries which may conflict with 123 libraries we have already included in the link. If it does, we 124 skip it, and try to find another shared library farther on down the 125 link path. 126 127 This is called via lang_for_each_input_file. 128 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object 129 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find 130 a conflicting version. */ 131 132static void 133gld${EMULATION_NAME}_vercheck (s) 134 lang_input_statement_type *s; 135{
| 39 40#include <ctype.h> 41 42#include "bfdlink.h" 43 44#include "ld.h" 45#include "ldmain.h" 46#include "ldmisc.h" 47#include "ldexp.h" 48#include "ldlang.h" 49#include "ldfile.h" 50#include "ldemul.h" 51#include "ldgram.h" 52#include "elf/common.h" 53 54static void gld${EMULATION_NAME}_before_parse PARAMS ((void)); 55static void gld${EMULATION_NAME}_vercheck 56 PARAMS ((lang_input_statement_type *)); 57static void gld${EMULATION_NAME}_stat_needed 58 PARAMS ((lang_input_statement_type *)); 59static boolean gld${EMULATION_NAME}_try_needed PARAMS ((const char *, int)); 60static boolean gld${EMULATION_NAME}_search_needed 61 PARAMS ((const char *, const char *, int)); 62static void gld${EMULATION_NAME}_check_needed 63 PARAMS ((lang_input_statement_type *)); 64static void gld${EMULATION_NAME}_after_open PARAMS ((void)); 65static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *)); 66static void gld${EMULATION_NAME}_find_statement_assignment 67 PARAMS ((lang_statement_union_type *)); 68static void gld${EMULATION_NAME}_before_allocation PARAMS ((void)); 69static boolean gld${EMULATION_NAME}_open_dynamic_archive 70 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *)); 71static lang_output_section_statement_type *output_rel_find PARAMS ((void)); 72static boolean gld${EMULATION_NAME}_place_orphan 73 PARAMS ((lang_input_statement_type *, asection *)); 74static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile)); 75 76EOF 77 78# Import any needed special functions and/or overrides. 79# 80if test -n "$EXTRA_EM_FILE" ; then 81. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em 82fi 83 84# Functions in this file can be overridden by setting the LDEMUL_* shell 85# variables. If the name of the overriding function is the same as is 86# defined in this file, then don't output this file's version. 87# If a different overriding name is given then output the standard function 88# as presumably it is called from the overriding function. 89# 90if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then 91cat >>e${EMULATION_NAME}.c <<EOF 92 93static void 94gld${EMULATION_NAME}_before_parse () 95{ 96 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`; 97 config.dynamic_link = ${DYNAMIC_LINK-true}; 98 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`; 99} 100 101EOF 102fi 103 104cat >>e${EMULATION_NAME}.c <<EOF 105 106/* These variables are required to pass information back and forth 107 between after_open and check_needed and stat_needed and vercheck. */ 108 109static struct bfd_link_needed_list *global_needed; 110static struct stat global_stat; 111static boolean global_found; 112static struct bfd_link_needed_list *global_vercheck_needed; 113static boolean global_vercheck_failed; 114 115 116/* On Linux, it's possible to have different versions of the same 117 shared library linked against different versions of libc. The 118 dynamic linker somehow tags which libc version to use in 119 /etc/ld.so.cache, and, based on the libc that it sees in the 120 executable, chooses which version of the shared library to use. 121 122 We try to do a similar check here by checking whether this shared 123 library needs any other shared libraries which may conflict with 124 libraries we have already included in the link. If it does, we 125 skip it, and try to find another shared library farther on down the 126 link path. 127 128 This is called via lang_for_each_input_file. 129 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object 130 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find 131 a conflicting version. */ 132 133static void 134gld${EMULATION_NAME}_vercheck (s) 135 lang_input_statement_type *s; 136{
|
136 const char *soname, *f;
| 137 const char *soname;
|
137 struct bfd_link_needed_list *l; 138 139 if (global_vercheck_failed) 140 return; 141 if (s->the_bfd == NULL 142 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0) 143 return; 144 145 soname = bfd_elf_get_dt_soname (s->the_bfd); 146 if (soname == NULL)
| 138 struct bfd_link_needed_list *l; 139 140 if (global_vercheck_failed) 141 return; 142 if (s->the_bfd == NULL 143 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0) 144 return; 145 146 soname = bfd_elf_get_dt_soname (s->the_bfd); 147 if (soname == NULL)
|
147 soname = bfd_get_filename (s->the_bfd);
| 148 soname = basename (bfd_get_filename (s->the_bfd));
|
148
| 149
|
149 f = strrchr (soname, '/'); 150 if (f != NULL) 151 ++f; 152 else 153 f = soname; 154
| |
155 for (l = global_vercheck_needed; l != NULL; l = l->next) 156 { 157 const char *suffix; 158
| 150 for (l = global_vercheck_needed; l != NULL; l = l->next) 151 { 152 const char *suffix; 153
|
159 if (strcmp (f, l->name) == 0)
| 154 if (strcmp (soname, l->name) == 0)
|
160 { 161 /* Probably can't happen, but it's an easy check. */ 162 continue; 163 } 164 165 if (strchr (l->name, '/') != NULL) 166 continue; 167 168 suffix = strstr (l->name, ".so."); 169 if (suffix == NULL) 170 continue; 171 172 suffix += sizeof ".so." - 1; 173
| 155 { 156 /* Probably can't happen, but it's an easy check. */ 157 continue; 158 } 159 160 if (strchr (l->name, '/') != NULL) 161 continue; 162 163 suffix = strstr (l->name, ".so."); 164 if (suffix == NULL) 165 continue; 166 167 suffix += sizeof ".so." - 1; 168
|
174 if (strncmp (f, l->name, suffix - l->name) == 0)
| 169 if (strncmp (soname, l->name, suffix - l->name) == 0)
|
175 { 176 /* Here we know that S is a dynamic object FOO.SO.VER1, and 177 the object we are considering needs a dynamic object 178 FOO.SO.VER2, and VER1 and VER2 are different. This 179 appears to be a version mismatch, so we tell the caller 180 to try a different version of this library. */ 181 global_vercheck_failed = true; 182 return; 183 } 184 } 185} 186 187 188/* See if an input file matches a DT_NEEDED entry by running stat on 189 the file. */ 190 191static void 192gld${EMULATION_NAME}_stat_needed (s) 193 lang_input_statement_type *s; 194{ 195 struct stat st; 196 const char *suffix; 197 const char *soname;
| 170 { 171 /* Here we know that S is a dynamic object FOO.SO.VER1, and 172 the object we are considering needs a dynamic object 173 FOO.SO.VER2, and VER1 and VER2 are different. This 174 appears to be a version mismatch, so we tell the caller 175 to try a different version of this library. */ 176 global_vercheck_failed = true; 177 return; 178 } 179 } 180} 181 182 183/* See if an input file matches a DT_NEEDED entry by running stat on 184 the file. */ 185 186static void 187gld${EMULATION_NAME}_stat_needed (s) 188 lang_input_statement_type *s; 189{ 190 struct stat st; 191 const char *suffix; 192 const char *soname;
|
198 const char *f;
| |
199 200 if (global_found) 201 return; 202 if (s->the_bfd == NULL) 203 return; 204 205 if (bfd_stat (s->the_bfd, &st) != 0) 206 { 207 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd); 208 return; 209 } 210 211 if (st.st_dev == global_stat.st_dev 212 && st.st_ino == global_stat.st_ino) 213 { 214 global_found = true; 215 return; 216 } 217 218 /* We issue a warning if it looks like we are including two 219 different versions of the same shared library. For example, 220 there may be a problem if -lc picks up libc.so.6 but some other 221 shared library has a DT_NEEDED entry of libc.so.5. This is a 222 heuristic test, and it will only work if the name looks like 223 NAME.so.VERSION. FIXME: Depending on file names is error-prone. 224 If we really want to issue warnings about mixing version numbers 225 of shared libraries, we need to find a better way. */ 226 227 if (strchr (global_needed->name, '/') != NULL) 228 return; 229 suffix = strstr (global_needed->name, ".so."); 230 if (suffix == NULL) 231 return; 232 suffix += sizeof ".so." - 1; 233 234 soname = bfd_elf_get_dt_soname (s->the_bfd); 235 if (soname == NULL)
| 193 194 if (global_found) 195 return; 196 if (s->the_bfd == NULL) 197 return; 198 199 if (bfd_stat (s->the_bfd, &st) != 0) 200 { 201 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd); 202 return; 203 } 204 205 if (st.st_dev == global_stat.st_dev 206 && st.st_ino == global_stat.st_ino) 207 { 208 global_found = true; 209 return; 210 } 211 212 /* We issue a warning if it looks like we are including two 213 different versions of the same shared library. For example, 214 there may be a problem if -lc picks up libc.so.6 but some other 215 shared library has a DT_NEEDED entry of libc.so.5. This is a 216 heuristic test, and it will only work if the name looks like 217 NAME.so.VERSION. FIXME: Depending on file names is error-prone. 218 If we really want to issue warnings about mixing version numbers 219 of shared libraries, we need to find a better way. */ 220 221 if (strchr (global_needed->name, '/') != NULL) 222 return; 223 suffix = strstr (global_needed->name, ".so."); 224 if (suffix == NULL) 225 return; 226 suffix += sizeof ".so." - 1; 227 228 soname = bfd_elf_get_dt_soname (s->the_bfd); 229 if (soname == NULL)
|
236 soname = s->filename;
| 230 soname = basename (s->filename);
|
237
| 231
|
238 f = strrchr (soname, '/'); 239 if (f != NULL) 240 ++f; 241 else 242 f = soname; 243 244 if (strncmp (f, global_needed->name, suffix - global_needed->name) == 0)
| 232 if (strncmp (soname, global_needed->name, 233 suffix - global_needed->name) == 0)
|
245 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
| 234 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
|
246 global_needed->name, global_needed->by, f);
| 235 global_needed->name, global_needed->by, soname);
|
247} 248 249 250/* This function is called for each possible name for a dynamic object 251 named by a DT_NEEDED entry. The FORCE parameter indicates whether 252 to skip the check for a conflicting version. */ 253 254static boolean 255gld${EMULATION_NAME}_try_needed (name, force) 256 const char *name; 257 int force; 258{ 259 bfd *abfd; 260 const char *soname; 261 262 abfd = bfd_openr (name, bfd_get_target (output_bfd)); 263 if (abfd == NULL) 264 return false; 265 if (! bfd_check_format (abfd, bfd_object)) 266 { 267 (void) bfd_close (abfd); 268 return false; 269 } 270 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) 271 { 272 (void) bfd_close (abfd); 273 return false; 274 } 275 276 /* Check whether this object would include any conflicting library 277 versions. If FORCE is set, then we skip this check; we use this 278 the second time around, if we couldn't find any compatible 279 instance of the shared library. */ 280 281 if (! force) 282 { 283 struct bfd_link_needed_list *needed; 284 285 if (! bfd_elf_get_bfd_needed_list (abfd, &needed)) 286 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd); 287 288 if (needed != NULL) 289 { 290 global_vercheck_needed = needed; 291 global_vercheck_failed = false; 292 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck); 293 if (global_vercheck_failed) 294 { 295 (void) bfd_close (abfd); 296 /* Return false to force the caller to move on to try 297 another file on the search path. */ 298 return false; 299 } 300 301 /* But wait! It gets much worse. On Linux, if a shared 302 library does not use libc at all, we are supposed to skip 303 it the first time around in case we encounter a shared 304 library later on with the same name which does use the 305 version of libc that we want. This is much too horrible 306 to use on any system other than Linux. */ 307 308EOF 309case ${target} in 310 *-*-linux-gnu*) 311 cat >>e${EMULATION_NAME}.c <<EOF 312 { 313 struct bfd_link_needed_list *l; 314 315 for (l = needed; l != NULL; l = l->next) 316 if (strncmp (l->name, "libc.so", 7) == 0) 317 break; 318 if (l == NULL) 319 { 320 (void) bfd_close (abfd); 321 return false; 322 } 323 } 324 325EOF 326 ;; 327esac 328cat >>e${EMULATION_NAME}.c <<EOF 329 } 330 } 331 332 /* We've found a dynamic object matching the DT_NEEDED entry. */ 333 334 /* We have already checked that there is no other input file of the 335 same name. We must now check again that we are not including the 336 same file twice. We need to do this because on many systems 337 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will 338 reference libc.so.1. If we have already included libc.so, we 339 don't want to include libc.so.1 if they are the same file, and we 340 can only check that using stat. */ 341 342 if (bfd_stat (abfd, &global_stat) != 0) 343 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd); 344 345 /* First strip off everything before the last '/'. */
| 236} 237 238 239/* This function is called for each possible name for a dynamic object 240 named by a DT_NEEDED entry. The FORCE parameter indicates whether 241 to skip the check for a conflicting version. */ 242 243static boolean 244gld${EMULATION_NAME}_try_needed (name, force) 245 const char *name; 246 int force; 247{ 248 bfd *abfd; 249 const char *soname; 250 251 abfd = bfd_openr (name, bfd_get_target (output_bfd)); 252 if (abfd == NULL) 253 return false; 254 if (! bfd_check_format (abfd, bfd_object)) 255 { 256 (void) bfd_close (abfd); 257 return false; 258 } 259 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) 260 { 261 (void) bfd_close (abfd); 262 return false; 263 } 264 265 /* Check whether this object would include any conflicting library 266 versions. If FORCE is set, then we skip this check; we use this 267 the second time around, if we couldn't find any compatible 268 instance of the shared library. */ 269 270 if (! force) 271 { 272 struct bfd_link_needed_list *needed; 273 274 if (! bfd_elf_get_bfd_needed_list (abfd, &needed)) 275 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd); 276 277 if (needed != NULL) 278 { 279 global_vercheck_needed = needed; 280 global_vercheck_failed = false; 281 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck); 282 if (global_vercheck_failed) 283 { 284 (void) bfd_close (abfd); 285 /* Return false to force the caller to move on to try 286 another file on the search path. */ 287 return false; 288 } 289 290 /* But wait! It gets much worse. On Linux, if a shared 291 library does not use libc at all, we are supposed to skip 292 it the first time around in case we encounter a shared 293 library later on with the same name which does use the 294 version of libc that we want. This is much too horrible 295 to use on any system other than Linux. */ 296 297EOF 298case ${target} in 299 *-*-linux-gnu*) 300 cat >>e${EMULATION_NAME}.c <<EOF 301 { 302 struct bfd_link_needed_list *l; 303 304 for (l = needed; l != NULL; l = l->next) 305 if (strncmp (l->name, "libc.so", 7) == 0) 306 break; 307 if (l == NULL) 308 { 309 (void) bfd_close (abfd); 310 return false; 311 } 312 } 313 314EOF 315 ;; 316esac 317cat >>e${EMULATION_NAME}.c <<EOF 318 } 319 } 320 321 /* We've found a dynamic object matching the DT_NEEDED entry. */ 322 323 /* We have already checked that there is no other input file of the 324 same name. We must now check again that we are not including the 325 same file twice. We need to do this because on many systems 326 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will 327 reference libc.so.1. If we have already included libc.so, we 328 don't want to include libc.so.1 if they are the same file, and we 329 can only check that using stat. */ 330 331 if (bfd_stat (abfd, &global_stat) != 0) 332 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd); 333 334 /* First strip off everything before the last '/'. */
|
346 soname = strrchr (abfd->filename, '/'); 347 if (soname) 348 soname++; 349 else 350 soname = abfd->filename;
| 335 soname = basename (abfd->filename);
|
351 352 if (trace_file_tries) 353 info_msg (_("found %s at %s\n"), soname, name); 354 355 global_found = false; 356 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); 357 if (global_found) 358 { 359 /* Return true to indicate that we found the file, even though 360 we aren't going to do anything with it. */ 361 return true; 362 } 363 364 /* Tell the ELF backend that we don't want the output file to have a 365 DT_NEEDED entry for this file. */ 366 bfd_elf_set_dt_needed_name (abfd, ""); 367 368 /* Tell the ELF backend that the output file needs a DT_NEEDED 369 entry for this file if it is used to resolve the reference in 370 a regular object. */ 371 bfd_elf_set_dt_needed_soname (abfd, soname); 372 373 /* Add this file into the symbol table. */ 374 if (! bfd_link_add_symbols (abfd, &link_info)) 375 einfo ("%F%B: could not read symbols: %E\n", abfd); 376 377 return true; 378} 379 380 381/* Search for a needed file in a path. */ 382 383static boolean 384gld${EMULATION_NAME}_search_needed (path, name, force) 385 const char *path; 386 const char *name; 387 int force; 388{ 389 const char *s; 390 size_t len; 391 392 if (name[0] == '/') 393 return gld${EMULATION_NAME}_try_needed (name, force); 394 395 if (path == NULL || *path == '\0') 396 return false; 397 len = strlen (name); 398 while (1) 399 { 400 char *filename, *sset; 401 402 s = strchr (path, ':'); 403 if (s == NULL) 404 s = path + strlen (path); 405 406 filename = (char *) xmalloc (s - path + len + 2); 407 if (s == path) 408 sset = filename; 409 else 410 { 411 memcpy (filename, path, s - path); 412 filename[s - path] = '/'; 413 sset = filename + (s - path) + 1; 414 } 415 strcpy (sset, name); 416 417 if (gld${EMULATION_NAME}_try_needed (filename, force)) 418 return true; 419 420 free (filename); 421 422 if (*s == '\0') 423 break; 424 path = s + 1; 425 } 426 427 return false; 428} 429 430EOF 431if [ "x${host}" = "x${target}" ] ; then 432 case " ${EMULATION_LIBPATH} " in 433 *" ${EMULATION_NAME} "*) 434 case ${target} in 435 *-*-freebsd*) 436 cat >>e${EMULATION_NAME}.c <<EOF 437/* 438 * Read the system search path the FreeBSD way rather than like Linux. 439 */ 440#include <elf-hints.h> 441 442static boolean gld${EMULATION_NAME}_check_ld_elf_hints 443 PARAMS ((const char *, int)); 444 445static boolean 446gld${EMULATION_NAME}_check_ld_elf_hints (name, force) 447 const char *name; 448 int force; 449{ 450 static boolean initialized; 451 static char *ld_elf_hints; 452 453 if (! initialized) 454 { 455 FILE *f; 456 457 f = fopen (_PATH_ELF_HINTS, FOPEN_RB); 458 if (f != NULL) 459 { 460 struct elfhints_hdr hdr; 461 462 if (fread(&hdr, 1, sizeof(hdr), f) == sizeof(hdr) && 463 hdr.magic == ELFHINTS_MAGIC && 464 hdr.version == 1) 465 { 466 if (fseek(f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1) 467 { 468 char *b; 469 470 b = (char *) xmalloc (hdr.dirlistlen + 1); 471 if (fread(b, 1, hdr.dirlistlen + 1, f) != 472 hdr.dirlistlen + 1) 473 { 474 free(b); 475 } 476 else 477 { 478 ld_elf_hints = b; 479 } 480 } 481 } 482 fclose (f); 483 } 484 485 initialized = true; 486 } 487 488 if (ld_elf_hints == NULL) 489 return false; 490 491 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, name, force); 492} 493EOF 494 # FreeBSD 495 ;; 496 497 *-*-linux-gnu*) 498 cat >>e${EMULATION_NAME}.c <<EOF 499 500/* For a native linker, check the file /etc/ld.so.conf for directories 501 in which we may find shared libraries. /etc/ld.so.conf is really 502 only meaningful on Linux. */ 503 504static boolean gld${EMULATION_NAME}_check_ld_so_conf 505 PARAMS ((const char *, int)); 506 507static boolean 508gld${EMULATION_NAME}_check_ld_so_conf (name, force) 509 const char *name; 510 int force; 511{ 512 static boolean initialized; 513 static char *ld_so_conf; 514 515 if (! initialized) 516 { 517 FILE *f; 518 519 f = fopen ("/etc/ld.so.conf", FOPEN_RT); 520 if (f != NULL) 521 { 522 char *b; 523 size_t len, alloc; 524 int c; 525 526 len = 0; 527 alloc = 100; 528 b = (char *) xmalloc (alloc); 529 530 while ((c = getc (f)) != EOF) 531 { 532 if (len + 1 >= alloc) 533 { 534 alloc *= 2; 535 b = (char *) xrealloc (b, alloc); 536 } 537 if (c != ':' 538 && c != ' ' 539 && c != '\t' 540 && c != '\n' 541 && c != ',') 542 { 543 b[len] = c; 544 ++len; 545 } 546 else 547 { 548 if (len > 0 && b[len - 1] != ':') 549 { 550 b[len] = ':'; 551 ++len; 552 } 553 } 554 } 555 556 if (len > 0 && b[len - 1] == ':') 557 --len; 558 559 if (len > 0) 560 b[len] = '\0'; 561 else 562 { 563 free (b); 564 b = NULL; 565 } 566 567 fclose (f); 568 569 ld_so_conf = b; 570 } 571 572 initialized = true; 573 } 574 575 if (ld_so_conf == NULL) 576 return false; 577 578 return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force); 579} 580 581EOF 582 # Linux 583 ;; 584 esac 585 esac 586fi 587cat >>e${EMULATION_NAME}.c <<EOF 588 589/* See if an input file matches a DT_NEEDED entry by name. */ 590 591static void 592gld${EMULATION_NAME}_check_needed (s) 593 lang_input_statement_type *s; 594{ 595 if (global_found) 596 return; 597 598 if (s->filename != NULL) 599 { 600 const char *f; 601 602 if (strcmp (s->filename, global_needed->name) == 0) 603 { 604 global_found = true; 605 return; 606 } 607 608 if (s->search_dirs_flag) 609 { 610 f = strrchr (s->filename, '/'); 611 if (f != NULL 612 && strcmp (f + 1, global_needed->name) == 0) 613 { 614 global_found = true; 615 return; 616 } 617 } 618 } 619 620 if (s->the_bfd != NULL) 621 { 622 const char *soname; 623 624 soname = bfd_elf_get_dt_soname (s->the_bfd); 625 if (soname != NULL 626 && strcmp (soname, global_needed->name) == 0) 627 { 628 global_found = true; 629 return; 630 } 631 } 632} 633 634EOF 635 636if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then 637cat >>e${EMULATION_NAME}.c <<EOF 638 639/* This is called after all the input files have been opened. */ 640 641static void 642gld${EMULATION_NAME}_after_open () 643{ 644 struct bfd_link_needed_list *needed, *l; 645 646 /* We only need to worry about this when doing a final link. */ 647 if (link_info.relocateable || link_info.shared) 648 return; 649 650 /* Get the list of files which appear in DT_NEEDED entries in 651 dynamic objects included in the link (often there will be none). 652 For each such file, we want to track down the corresponding 653 library, and include the symbol table in the link. This is what 654 the runtime dynamic linker will do. Tracking the files down here 655 permits one dynamic object to include another without requiring 656 special action by the person doing the link. Note that the 657 needed list can actually grow while we are stepping through this 658 loop. */ 659 needed = bfd_elf_get_needed_list (output_bfd, &link_info); 660 for (l = needed; l != NULL; l = l->next) 661 { 662 struct bfd_link_needed_list *ll; 663 int force; 664 665 /* If we've already seen this file, skip it. */ 666 for (ll = needed; ll != l; ll = ll->next) 667 if (strcmp (ll->name, l->name) == 0) 668 break; 669 if (ll != l) 670 continue; 671 672 /* See if this file was included in the link explicitly. */ 673 global_needed = l; 674 global_found = false; 675 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); 676 if (global_found) 677 continue; 678 679 if (trace_file_tries) 680 info_msg (_("%s needed by %B\n"), l->name, l->by); 681 682 /* We need to find this file and include the symbol table. We 683 want to search for the file in the same way that the dynamic 684 linker will search. That means that we want to use 685 rpath_link, rpath, then the environment variable 686 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH 687 entries (native only), then the linker script LIB_SEARCH_DIRS. 688 We do not search using the -L arguments. 689 690 We search twice. The first time, we skip objects which may 691 introduce version mismatches. The second time, we force 692 their use. See gld${EMULATION_NAME}_vercheck comment. */ 693 for (force = 0; force < 2; force++) 694 { 695 size_t len; 696 search_dirs_type *search; 697EOF 698if [ "x${host}" = "x${target}" ] ; then 699 case " ${EMULATION_LIBPATH} " in 700 *" ${EMULATION_NAME} "*) 701cat >>e${EMULATION_NAME}.c <<EOF 702 const char *lib_path; 703 struct bfd_link_needed_list *rp; 704 int found; 705EOF 706 ;; 707 esac 708fi 709cat >>e${EMULATION_NAME}.c <<EOF 710 711 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link, 712 l->name, force)) 713 break; 714EOF 715if [ "x${host}" = "x${target}" ] ; then 716 case " ${EMULATION_LIBPATH} " in 717 *" ${EMULATION_NAME} "*) 718cat >>e${EMULATION_NAME}.c <<EOF 719 if (gld${EMULATION_NAME}_search_needed (command_line.rpath, 720 l->name, force)) 721 break; 722 if (command_line.rpath_link == NULL 723 && command_line.rpath == NULL) 724 { 725 lib_path = (const char *) getenv ("LD_RUN_PATH"); 726 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, 727 force)) 728 break; 729 } 730 lib_path = (const char *) getenv ("LD_LIBRARY_PATH"); 731 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) 732 break; 733 734 found = 0; 735 rp = bfd_elf_get_runpath_list (output_bfd, &link_info); 736 for (; !found && rp != NULL; rp = rp->next) 737 { 738 found = (rp->by == l->by 739 && gld${EMULATION_NAME}_search_needed (rp->name, 740 l->name, 741 force)); 742 } 743 if (found) 744 break; 745 746EOF 747 ;; 748 esac 749fi 750cat >>e${EMULATION_NAME}.c <<EOF 751 len = strlen (l->name); 752 for (search = search_head; search != NULL; search = search->next) 753 { 754 char *filename; 755 756 if (search->cmdline) 757 continue; 758 filename = (char *) xmalloc (strlen (search->name) + len + 2); 759 sprintf (filename, "%s/%s", search->name, l->name); 760 if (gld${EMULATION_NAME}_try_needed (filename, force)) 761 break; 762 free (filename); 763 } 764 if (search != NULL) 765 break; 766EOF 767if [ "x${host}" = "x${target}" ] ; then 768 case " ${EMULATION_LIBPATH} " in 769 *" ${EMULATION_NAME} "*) 770 case ${target} in 771 *-*-freebsd*) 772 cat >>e${EMULATION_NAME}.c <<EOF 773 if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force)) 774 break; 775EOF 776 ;; 777 *-*-linux-gnu*) 778 cat >>e${EMULATION_NAME}.c <<EOF 779 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force)) 780 break; 781EOF 782 # Linux 783 ;; 784 esac 785 ;; 786 esac 787fi 788cat >>e${EMULATION_NAME}.c <<EOF 789 } 790 791 if (force < 2) 792 continue; 793 794 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n", 795 l->name, l->by); 796 } 797} 798 799EOF 800fi 801 802cat >>e${EMULATION_NAME}.c <<EOF 803 804/* Look through an expression for an assignment statement. */ 805 806static void 807gld${EMULATION_NAME}_find_exp_assignment (exp) 808 etree_type *exp; 809{ 810 struct bfd_link_hash_entry *h; 811 812 switch (exp->type.node_class) 813 { 814 case etree_provide: 815 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, 816 false, false, false); 817 if (h == NULL) 818 break; 819 820 /* We call record_link_assignment even if the symbol is defined. 821 This is because if it is defined by a dynamic object, we 822 actually want to use the value defined by the linker script, 823 not the value from the dynamic object (because we are setting 824 symbols like etext). If the symbol is defined by a regular 825 object, then, as it happens, calling record_link_assignment 826 will do no harm. */ 827 828 /* Fall through. */ 829 case etree_assign: 830 if (strcmp (exp->assign.dst, ".") != 0) 831 { 832 if (! (bfd_elf${ELFSIZE}_record_link_assignment 833 (output_bfd, &link_info, exp->assign.dst, 834 exp->type.node_class == etree_provide ? true : false))) 835 einfo ("%P%F: failed to record assignment to %s: %E\n", 836 exp->assign.dst); 837 } 838 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); 839 break; 840 841 case etree_binary: 842 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); 843 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); 844 break; 845 846 case etree_trinary: 847 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); 848 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); 849 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); 850 break; 851 852 case etree_unary: 853 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); 854 break; 855 856 default: 857 break; 858 } 859} 860 861 862/* This is called by the before_allocation routine via 863 lang_for_each_statement. It locates any assignment statements, and 864 tells the ELF backend about them, in case they are assignments to 865 symbols which are referred to by dynamic objects. */ 866 867static void 868gld${EMULATION_NAME}_find_statement_assignment (s) 869 lang_statement_union_type *s; 870{ 871 if (s->header.type == lang_assignment_statement_enum) 872 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); 873} 874 875EOF 876 877if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then 878cat >>e${EMULATION_NAME}.c <<EOF 879 880/* This is called after the sections have been attached to output 881 sections, but before any sizes or addresses have been set. */ 882 883static void 884gld${EMULATION_NAME}_before_allocation () 885{ 886 const char *rpath; 887 asection *sinterp; 888 889 /* If we are going to make any variable assignments, we need to let 890 the ELF backend know about them in case the variables are 891 referred to by dynamic objects. */ 892 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment); 893 894 /* Let the ELF backend work out the sizes of any sections required 895 by dynamic linking. */ 896 rpath = command_line.rpath; 897 if (rpath == NULL) 898 rpath = (const char *) getenv ("LD_RUN_PATH"); 899 if (! (bfd_elf${ELFSIZE}_size_dynamic_sections 900 (output_bfd, command_line.soname, rpath, 901 command_line.export_dynamic, command_line.filter_shlib, 902 (const char * const *) command_line.auxiliary_filters, 903 &link_info, &sinterp, lang_elf_version_info))) 904 einfo ("%P%F: failed to set dynamic section sizes: %E\n"); 905 906 /* Let the user override the dynamic linker we are using. */ 907 if (command_line.interpreter != NULL 908 && sinterp != NULL) 909 { 910 sinterp->contents = (bfd_byte *) command_line.interpreter; 911 sinterp->_raw_size = strlen (command_line.interpreter) + 1; 912 } 913 914 /* Look for any sections named .gnu.warning. As a GNU extensions, 915 we treat such sections as containing warning messages. We print 916 out the warning message, and then zero out the section size so 917 that it does not get copied into the output file. */ 918 919 { 920 LANG_FOR_EACH_INPUT_STATEMENT (is) 921 { 922 asection *s; 923 bfd_size_type sz; 924 char *msg; 925 boolean ret; 926 927 if (is->just_syms_flag) 928 continue; 929 930 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning"); 931 if (s == NULL) 932 continue; 933 934 sz = bfd_section_size (is->the_bfd, s); 935 msg = xmalloc ((size_t) sz + 1); 936 if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz)) 937 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", 938 is->the_bfd); 939 msg[sz] = '\0'; 940 ret = link_info.callbacks->warning (&link_info, msg, 941 (const char *) NULL, 942 is->the_bfd, (asection *) NULL, 943 (bfd_vma) 0); 944 ASSERT (ret); 945 free (msg); 946 947 /* Clobber the section size, so that we don't waste copying the 948 warning into the output file. */ 949 s->_raw_size = 0; 950 } 951 } 952} 953 954EOF 955fi 956 957if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then 958cat >>e${EMULATION_NAME}.c <<EOF 959 960/* Try to open a dynamic archive. This is where we know that ELF 961 dynamic libraries have an extension of .so (or .sl on oddball systems 962 like hpux). */ 963 964static boolean 965gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) 966 const char *arch; 967 search_dirs_type *search; 968 lang_input_statement_type *entry; 969{ 970 const char *filename; 971 char *string; 972 973 if (! entry->is_archive) 974 return false; 975 976 filename = entry->filename; 977 978 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION 979 is defined, but it does not seem worth the headache to optimize 980 away those two bytes of space. */ 981 string = (char *) xmalloc (strlen (search->name) 982 + strlen (filename) 983 + strlen (arch) 984#ifdef EXTRA_SHLIB_EXTENSION 985 + strlen (EXTRA_SHLIB_EXTENSION) 986#endif 987 + sizeof "/lib.so"); 988 989 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); 990 991#ifdef EXTRA_SHLIB_EXTENSION 992 /* Try the .so extension first. If that fails build a new filename 993 using EXTRA_SHLIB_EXTENSION. */ 994 if (! ldfile_try_open_bfd (string, entry)) 995 sprintf (string, "%s/lib%s%s%s", search->name, 996 filename, arch, EXTRA_SHLIB_EXTENSION); 997#endif 998 999 if (! ldfile_try_open_bfd (string, entry)) 1000 { 1001 free (string); 1002 return false; 1003 } 1004 1005 entry->filename = string; 1006 1007 /* We have found a dynamic object to include in the link. The ELF 1008 backend linker will create a DT_NEEDED entry in the .dynamic 1009 section naming this file. If this file includes a DT_SONAME 1010 entry, it will be used. Otherwise, the ELF linker will just use 1011 the name of the file. For an archive found by searching, like 1012 this one, the DT_NEEDED entry should consist of just the name of 1013 the file, without the path information used to find it. Note 1014 that we only need to do this if we have a dynamic object; an 1015 archive will never be referenced by a DT_NEEDED entry. 1016 1017 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not 1018 very pretty. I haven't been able to think of anything that is 1019 pretty, though. */ 1020 if (bfd_check_format (entry->the_bfd, bfd_object) 1021 && (entry->the_bfd->flags & DYNAMIC) != 0) 1022 {
| 336 337 if (trace_file_tries) 338 info_msg (_("found %s at %s\n"), soname, name); 339 340 global_found = false; 341 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); 342 if (global_found) 343 { 344 /* Return true to indicate that we found the file, even though 345 we aren't going to do anything with it. */ 346 return true; 347 } 348 349 /* Tell the ELF backend that we don't want the output file to have a 350 DT_NEEDED entry for this file. */ 351 bfd_elf_set_dt_needed_name (abfd, ""); 352 353 /* Tell the ELF backend that the output file needs a DT_NEEDED 354 entry for this file if it is used to resolve the reference in 355 a regular object. */ 356 bfd_elf_set_dt_needed_soname (abfd, soname); 357 358 /* Add this file into the symbol table. */ 359 if (! bfd_link_add_symbols (abfd, &link_info)) 360 einfo ("%F%B: could not read symbols: %E\n", abfd); 361 362 return true; 363} 364 365 366/* Search for a needed file in a path. */ 367 368static boolean 369gld${EMULATION_NAME}_search_needed (path, name, force) 370 const char *path; 371 const char *name; 372 int force; 373{ 374 const char *s; 375 size_t len; 376 377 if (name[0] == '/') 378 return gld${EMULATION_NAME}_try_needed (name, force); 379 380 if (path == NULL || *path == '\0') 381 return false; 382 len = strlen (name); 383 while (1) 384 { 385 char *filename, *sset; 386 387 s = strchr (path, ':'); 388 if (s == NULL) 389 s = path + strlen (path); 390 391 filename = (char *) xmalloc (s - path + len + 2); 392 if (s == path) 393 sset = filename; 394 else 395 { 396 memcpy (filename, path, s - path); 397 filename[s - path] = '/'; 398 sset = filename + (s - path) + 1; 399 } 400 strcpy (sset, name); 401 402 if (gld${EMULATION_NAME}_try_needed (filename, force)) 403 return true; 404 405 free (filename); 406 407 if (*s == '\0') 408 break; 409 path = s + 1; 410 } 411 412 return false; 413} 414 415EOF 416if [ "x${host}" = "x${target}" ] ; then 417 case " ${EMULATION_LIBPATH} " in 418 *" ${EMULATION_NAME} "*) 419 case ${target} in 420 *-*-freebsd*) 421 cat >>e${EMULATION_NAME}.c <<EOF 422/* 423 * Read the system search path the FreeBSD way rather than like Linux. 424 */ 425#include <elf-hints.h> 426 427static boolean gld${EMULATION_NAME}_check_ld_elf_hints 428 PARAMS ((const char *, int)); 429 430static boolean 431gld${EMULATION_NAME}_check_ld_elf_hints (name, force) 432 const char *name; 433 int force; 434{ 435 static boolean initialized; 436 static char *ld_elf_hints; 437 438 if (! initialized) 439 { 440 FILE *f; 441 442 f = fopen (_PATH_ELF_HINTS, FOPEN_RB); 443 if (f != NULL) 444 { 445 struct elfhints_hdr hdr; 446 447 if (fread(&hdr, 1, sizeof(hdr), f) == sizeof(hdr) && 448 hdr.magic == ELFHINTS_MAGIC && 449 hdr.version == 1) 450 { 451 if (fseek(f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1) 452 { 453 char *b; 454 455 b = (char *) xmalloc (hdr.dirlistlen + 1); 456 if (fread(b, 1, hdr.dirlistlen + 1, f) != 457 hdr.dirlistlen + 1) 458 { 459 free(b); 460 } 461 else 462 { 463 ld_elf_hints = b; 464 } 465 } 466 } 467 fclose (f); 468 } 469 470 initialized = true; 471 } 472 473 if (ld_elf_hints == NULL) 474 return false; 475 476 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, name, force); 477} 478EOF 479 # FreeBSD 480 ;; 481 482 *-*-linux-gnu*) 483 cat >>e${EMULATION_NAME}.c <<EOF 484 485/* For a native linker, check the file /etc/ld.so.conf for directories 486 in which we may find shared libraries. /etc/ld.so.conf is really 487 only meaningful on Linux. */ 488 489static boolean gld${EMULATION_NAME}_check_ld_so_conf 490 PARAMS ((const char *, int)); 491 492static boolean 493gld${EMULATION_NAME}_check_ld_so_conf (name, force) 494 const char *name; 495 int force; 496{ 497 static boolean initialized; 498 static char *ld_so_conf; 499 500 if (! initialized) 501 { 502 FILE *f; 503 504 f = fopen ("/etc/ld.so.conf", FOPEN_RT); 505 if (f != NULL) 506 { 507 char *b; 508 size_t len, alloc; 509 int c; 510 511 len = 0; 512 alloc = 100; 513 b = (char *) xmalloc (alloc); 514 515 while ((c = getc (f)) != EOF) 516 { 517 if (len + 1 >= alloc) 518 { 519 alloc *= 2; 520 b = (char *) xrealloc (b, alloc); 521 } 522 if (c != ':' 523 && c != ' ' 524 && c != '\t' 525 && c != '\n' 526 && c != ',') 527 { 528 b[len] = c; 529 ++len; 530 } 531 else 532 { 533 if (len > 0 && b[len - 1] != ':') 534 { 535 b[len] = ':'; 536 ++len; 537 } 538 } 539 } 540 541 if (len > 0 && b[len - 1] == ':') 542 --len; 543 544 if (len > 0) 545 b[len] = '\0'; 546 else 547 { 548 free (b); 549 b = NULL; 550 } 551 552 fclose (f); 553 554 ld_so_conf = b; 555 } 556 557 initialized = true; 558 } 559 560 if (ld_so_conf == NULL) 561 return false; 562 563 return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force); 564} 565 566EOF 567 # Linux 568 ;; 569 esac 570 esac 571fi 572cat >>e${EMULATION_NAME}.c <<EOF 573 574/* See if an input file matches a DT_NEEDED entry by name. */ 575 576static void 577gld${EMULATION_NAME}_check_needed (s) 578 lang_input_statement_type *s; 579{ 580 if (global_found) 581 return; 582 583 if (s->filename != NULL) 584 { 585 const char *f; 586 587 if (strcmp (s->filename, global_needed->name) == 0) 588 { 589 global_found = true; 590 return; 591 } 592 593 if (s->search_dirs_flag) 594 { 595 f = strrchr (s->filename, '/'); 596 if (f != NULL 597 && strcmp (f + 1, global_needed->name) == 0) 598 { 599 global_found = true; 600 return; 601 } 602 } 603 } 604 605 if (s->the_bfd != NULL) 606 { 607 const char *soname; 608 609 soname = bfd_elf_get_dt_soname (s->the_bfd); 610 if (soname != NULL 611 && strcmp (soname, global_needed->name) == 0) 612 { 613 global_found = true; 614 return; 615 } 616 } 617} 618 619EOF 620 621if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then 622cat >>e${EMULATION_NAME}.c <<EOF 623 624/* This is called after all the input files have been opened. */ 625 626static void 627gld${EMULATION_NAME}_after_open () 628{ 629 struct bfd_link_needed_list *needed, *l; 630 631 /* We only need to worry about this when doing a final link. */ 632 if (link_info.relocateable || link_info.shared) 633 return; 634 635 /* Get the list of files which appear in DT_NEEDED entries in 636 dynamic objects included in the link (often there will be none). 637 For each such file, we want to track down the corresponding 638 library, and include the symbol table in the link. This is what 639 the runtime dynamic linker will do. Tracking the files down here 640 permits one dynamic object to include another without requiring 641 special action by the person doing the link. Note that the 642 needed list can actually grow while we are stepping through this 643 loop. */ 644 needed = bfd_elf_get_needed_list (output_bfd, &link_info); 645 for (l = needed; l != NULL; l = l->next) 646 { 647 struct bfd_link_needed_list *ll; 648 int force; 649 650 /* If we've already seen this file, skip it. */ 651 for (ll = needed; ll != l; ll = ll->next) 652 if (strcmp (ll->name, l->name) == 0) 653 break; 654 if (ll != l) 655 continue; 656 657 /* See if this file was included in the link explicitly. */ 658 global_needed = l; 659 global_found = false; 660 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); 661 if (global_found) 662 continue; 663 664 if (trace_file_tries) 665 info_msg (_("%s needed by %B\n"), l->name, l->by); 666 667 /* We need to find this file and include the symbol table. We 668 want to search for the file in the same way that the dynamic 669 linker will search. That means that we want to use 670 rpath_link, rpath, then the environment variable 671 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH 672 entries (native only), then the linker script LIB_SEARCH_DIRS. 673 We do not search using the -L arguments. 674 675 We search twice. The first time, we skip objects which may 676 introduce version mismatches. The second time, we force 677 their use. See gld${EMULATION_NAME}_vercheck comment. */ 678 for (force = 0; force < 2; force++) 679 { 680 size_t len; 681 search_dirs_type *search; 682EOF 683if [ "x${host}" = "x${target}" ] ; then 684 case " ${EMULATION_LIBPATH} " in 685 *" ${EMULATION_NAME} "*) 686cat >>e${EMULATION_NAME}.c <<EOF 687 const char *lib_path; 688 struct bfd_link_needed_list *rp; 689 int found; 690EOF 691 ;; 692 esac 693fi 694cat >>e${EMULATION_NAME}.c <<EOF 695 696 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link, 697 l->name, force)) 698 break; 699EOF 700if [ "x${host}" = "x${target}" ] ; then 701 case " ${EMULATION_LIBPATH} " in 702 *" ${EMULATION_NAME} "*) 703cat >>e${EMULATION_NAME}.c <<EOF 704 if (gld${EMULATION_NAME}_search_needed (command_line.rpath, 705 l->name, force)) 706 break; 707 if (command_line.rpath_link == NULL 708 && command_line.rpath == NULL) 709 { 710 lib_path = (const char *) getenv ("LD_RUN_PATH"); 711 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, 712 force)) 713 break; 714 } 715 lib_path = (const char *) getenv ("LD_LIBRARY_PATH"); 716 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) 717 break; 718 719 found = 0; 720 rp = bfd_elf_get_runpath_list (output_bfd, &link_info); 721 for (; !found && rp != NULL; rp = rp->next) 722 { 723 found = (rp->by == l->by 724 && gld${EMULATION_NAME}_search_needed (rp->name, 725 l->name, 726 force)); 727 } 728 if (found) 729 break; 730 731EOF 732 ;; 733 esac 734fi 735cat >>e${EMULATION_NAME}.c <<EOF 736 len = strlen (l->name); 737 for (search = search_head; search != NULL; search = search->next) 738 { 739 char *filename; 740 741 if (search->cmdline) 742 continue; 743 filename = (char *) xmalloc (strlen (search->name) + len + 2); 744 sprintf (filename, "%s/%s", search->name, l->name); 745 if (gld${EMULATION_NAME}_try_needed (filename, force)) 746 break; 747 free (filename); 748 } 749 if (search != NULL) 750 break; 751EOF 752if [ "x${host}" = "x${target}" ] ; then 753 case " ${EMULATION_LIBPATH} " in 754 *" ${EMULATION_NAME} "*) 755 case ${target} in 756 *-*-freebsd*) 757 cat >>e${EMULATION_NAME}.c <<EOF 758 if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force)) 759 break; 760EOF 761 ;; 762 *-*-linux-gnu*) 763 cat >>e${EMULATION_NAME}.c <<EOF 764 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force)) 765 break; 766EOF 767 # Linux 768 ;; 769 esac 770 ;; 771 esac 772fi 773cat >>e${EMULATION_NAME}.c <<EOF 774 } 775 776 if (force < 2) 777 continue; 778 779 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n", 780 l->name, l->by); 781 } 782} 783 784EOF 785fi 786 787cat >>e${EMULATION_NAME}.c <<EOF 788 789/* Look through an expression for an assignment statement. */ 790 791static void 792gld${EMULATION_NAME}_find_exp_assignment (exp) 793 etree_type *exp; 794{ 795 struct bfd_link_hash_entry *h; 796 797 switch (exp->type.node_class) 798 { 799 case etree_provide: 800 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, 801 false, false, false); 802 if (h == NULL) 803 break; 804 805 /* We call record_link_assignment even if the symbol is defined. 806 This is because if it is defined by a dynamic object, we 807 actually want to use the value defined by the linker script, 808 not the value from the dynamic object (because we are setting 809 symbols like etext). If the symbol is defined by a regular 810 object, then, as it happens, calling record_link_assignment 811 will do no harm. */ 812 813 /* Fall through. */ 814 case etree_assign: 815 if (strcmp (exp->assign.dst, ".") != 0) 816 { 817 if (! (bfd_elf${ELFSIZE}_record_link_assignment 818 (output_bfd, &link_info, exp->assign.dst, 819 exp->type.node_class == etree_provide ? true : false))) 820 einfo ("%P%F: failed to record assignment to %s: %E\n", 821 exp->assign.dst); 822 } 823 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); 824 break; 825 826 case etree_binary: 827 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); 828 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); 829 break; 830 831 case etree_trinary: 832 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); 833 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); 834 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); 835 break; 836 837 case etree_unary: 838 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); 839 break; 840 841 default: 842 break; 843 } 844} 845 846 847/* This is called by the before_allocation routine via 848 lang_for_each_statement. It locates any assignment statements, and 849 tells the ELF backend about them, in case they are assignments to 850 symbols which are referred to by dynamic objects. */ 851 852static void 853gld${EMULATION_NAME}_find_statement_assignment (s) 854 lang_statement_union_type *s; 855{ 856 if (s->header.type == lang_assignment_statement_enum) 857 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); 858} 859 860EOF 861 862if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then 863cat >>e${EMULATION_NAME}.c <<EOF 864 865/* This is called after the sections have been attached to output 866 sections, but before any sizes or addresses have been set. */ 867 868static void 869gld${EMULATION_NAME}_before_allocation () 870{ 871 const char *rpath; 872 asection *sinterp; 873 874 /* If we are going to make any variable assignments, we need to let 875 the ELF backend know about them in case the variables are 876 referred to by dynamic objects. */ 877 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment); 878 879 /* Let the ELF backend work out the sizes of any sections required 880 by dynamic linking. */ 881 rpath = command_line.rpath; 882 if (rpath == NULL) 883 rpath = (const char *) getenv ("LD_RUN_PATH"); 884 if (! (bfd_elf${ELFSIZE}_size_dynamic_sections 885 (output_bfd, command_line.soname, rpath, 886 command_line.export_dynamic, command_line.filter_shlib, 887 (const char * const *) command_line.auxiliary_filters, 888 &link_info, &sinterp, lang_elf_version_info))) 889 einfo ("%P%F: failed to set dynamic section sizes: %E\n"); 890 891 /* Let the user override the dynamic linker we are using. */ 892 if (command_line.interpreter != NULL 893 && sinterp != NULL) 894 { 895 sinterp->contents = (bfd_byte *) command_line.interpreter; 896 sinterp->_raw_size = strlen (command_line.interpreter) + 1; 897 } 898 899 /* Look for any sections named .gnu.warning. As a GNU extensions, 900 we treat such sections as containing warning messages. We print 901 out the warning message, and then zero out the section size so 902 that it does not get copied into the output file. */ 903 904 { 905 LANG_FOR_EACH_INPUT_STATEMENT (is) 906 { 907 asection *s; 908 bfd_size_type sz; 909 char *msg; 910 boolean ret; 911 912 if (is->just_syms_flag) 913 continue; 914 915 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning"); 916 if (s == NULL) 917 continue; 918 919 sz = bfd_section_size (is->the_bfd, s); 920 msg = xmalloc ((size_t) sz + 1); 921 if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz)) 922 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", 923 is->the_bfd); 924 msg[sz] = '\0'; 925 ret = link_info.callbacks->warning (&link_info, msg, 926 (const char *) NULL, 927 is->the_bfd, (asection *) NULL, 928 (bfd_vma) 0); 929 ASSERT (ret); 930 free (msg); 931 932 /* Clobber the section size, so that we don't waste copying the 933 warning into the output file. */ 934 s->_raw_size = 0; 935 } 936 } 937} 938 939EOF 940fi 941 942if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then 943cat >>e${EMULATION_NAME}.c <<EOF 944 945/* Try to open a dynamic archive. This is where we know that ELF 946 dynamic libraries have an extension of .so (or .sl on oddball systems 947 like hpux). */ 948 949static boolean 950gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) 951 const char *arch; 952 search_dirs_type *search; 953 lang_input_statement_type *entry; 954{ 955 const char *filename; 956 char *string; 957 958 if (! entry->is_archive) 959 return false; 960 961 filename = entry->filename; 962 963 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION 964 is defined, but it does not seem worth the headache to optimize 965 away those two bytes of space. */ 966 string = (char *) xmalloc (strlen (search->name) 967 + strlen (filename) 968 + strlen (arch) 969#ifdef EXTRA_SHLIB_EXTENSION 970 + strlen (EXTRA_SHLIB_EXTENSION) 971#endif 972 + sizeof "/lib.so"); 973 974 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); 975 976#ifdef EXTRA_SHLIB_EXTENSION 977 /* Try the .so extension first. If that fails build a new filename 978 using EXTRA_SHLIB_EXTENSION. */ 979 if (! ldfile_try_open_bfd (string, entry)) 980 sprintf (string, "%s/lib%s%s%s", search->name, 981 filename, arch, EXTRA_SHLIB_EXTENSION); 982#endif 983 984 if (! ldfile_try_open_bfd (string, entry)) 985 { 986 free (string); 987 return false; 988 } 989 990 entry->filename = string; 991 992 /* We have found a dynamic object to include in the link. The ELF 993 backend linker will create a DT_NEEDED entry in the .dynamic 994 section naming this file. If this file includes a DT_SONAME 995 entry, it will be used. Otherwise, the ELF linker will just use 996 the name of the file. For an archive found by searching, like 997 this one, the DT_NEEDED entry should consist of just the name of 998 the file, without the path information used to find it. Note 999 that we only need to do this if we have a dynamic object; an 1000 archive will never be referenced by a DT_NEEDED entry. 1001 1002 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not 1003 very pretty. I haven't been able to think of anything that is 1004 pretty, though. */ 1005 if (bfd_check_format (entry->the_bfd, bfd_object) 1006 && (entry->the_bfd->flags & DYNAMIC) != 0) 1007 {
|
1023 char *needed_name; 1024
| |
1025 ASSERT (entry->is_archive && entry->search_dirs_flag); 1026 1027 /* Rather than duplicating the logic above. Just use the
| 1008 ASSERT (entry->is_archive && entry->search_dirs_flag); 1009 1010 /* Rather than duplicating the logic above. Just use the
|
1028 filename we recorded earlier.
| 1011 filename we recorded earlier. */
|
1029
| 1012
|
1030 First strip off everything before the last '/'. */ 1031 filename = strrchr (entry->filename, '/'); 1032 filename++; 1033 1034 needed_name = (char *) xmalloc (strlen (filename) + 1); 1035 strcpy (needed_name, filename); 1036 bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name);
| 1013 filename = xstrdup (basename (entry->filename)); 1014 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
|
1037 } 1038 1039 return true; 1040} 1041 1042EOF 1043fi 1044cat >>e${EMULATION_NAME}.c <<EOF 1045 1046/* A variant of lang_output_section_find. Used by place_orphan. */ 1047 1048static lang_output_section_statement_type * 1049output_rel_find () 1050{ 1051 lang_statement_union_type *u; 1052 lang_output_section_statement_type *lookup; 1053 1054 for (u = lang_output_section_statement.head; 1055 u != (lang_statement_union_type *) NULL; 1056 u = lookup->next) 1057 { 1058 lookup = &u->output_section_statement; 1059 if (strncmp (".rel", lookup->name, 4) == 0 1060 && lookup->bfd_section != NULL 1061 && (lookup->bfd_section->flags & SEC_ALLOC) != 0) 1062 { 1063 return lookup; 1064 } 1065 } 1066 return (lang_output_section_statement_type *) NULL; 1067} 1068 1069EOF 1070 1071if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then 1072cat >>e${EMULATION_NAME}.c <<EOF 1073 1074/* Place an orphan section. We use this to put random SHF_ALLOC 1075 sections in the right segment. */ 1076 1077struct orphan_save { 1078 lang_output_section_statement_type *os; 1079 asection **section; 1080 lang_statement_union_type **stmt; 1081}; 1082 1083static boolean 1084gld${EMULATION_NAME}_place_orphan (file, s) 1085 lang_input_statement_type *file; 1086 asection *s; 1087{ 1088 static struct orphan_save hold_text; 1089 static struct orphan_save hold_rodata; 1090 static struct orphan_save hold_data; 1091 static struct orphan_save hold_bss; 1092 static struct orphan_save hold_rel; 1093 static struct orphan_save hold_interp; 1094 static struct orphan_save hold_sdata; 1095 static int count = 1; 1096 struct orphan_save *place; 1097 lang_statement_list_type *old; 1098 lang_statement_list_type add; 1099 etree_type *address; 1100 const char *secname; 1101 const char *outsecname; 1102 const char *ps = NULL; 1103 lang_output_section_statement_type *os; 1104 1105 secname = bfd_get_section_name (s->owner, s); 1106 1107 if (! config.unique_orphan_sections && ! unique_section_p (secname)) 1108 { 1109 /* Look through the script to see where to place this section. */ 1110 os = lang_output_section_find (secname); 1111 1112 if (os != NULL 1113 && os->bfd_section != NULL 1114 && ((s->flags ^ os->bfd_section->flags) 1115 & (SEC_LOAD | SEC_ALLOC)) == 0) 1116 { 1117 /* We have already placed a section with this name. */ 1118 wild_doit (&os->children, s, os, file); 1119 return true; 1120 } 1121 } 1122 1123 if (hold_text.os == NULL) 1124 hold_text.os = lang_output_section_find (".text"); 1125 1126 /* If this is a final link, then always put .gnu.warning.SYMBOL 1127 sections into the .text section to get them out of the way. */ 1128 if (! link_info.shared 1129 && ! link_info.relocateable 1130 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0 1131 && hold_text.os != NULL) 1132 { 1133 wild_doit (&hold_text.os->children, s, hold_text.os, file); 1134 return true; 1135 } 1136 1137 /* Decide which segment the section should go in based on the 1138 section name and section flags. We put loadable .note sections 1139 right after the .interp section, so that the PT_NOTE segment is 1140 stored right after the program headers where the OS can read it 1141 in the first page. */ 1142#define HAVE_SECTION(hold, name) \ 1143(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) 1144 1145 if (s->flags & SEC_EXCLUDE) 1146 return false; 1147 1148 place = NULL; 1149 if ((s->flags & SEC_ALLOC) == 0) 1150 ; 1151 else if ((s->flags & SEC_LOAD) != 0 1152 && strncmp (secname, ".note", 5) == 0 1153 && HAVE_SECTION (hold_interp, ".interp")) 1154 place = &hold_interp; 1155 else if ((s->flags & SEC_HAS_CONTENTS) == 0 1156 && HAVE_SECTION (hold_bss, ".bss")) 1157 place = &hold_bss; 1158 else if ((s->flags & SEC_SMALL_DATA) != 0 1159 && HAVE_SECTION (hold_sdata, ".sdata")) 1160 place = &hold_sdata; 1161 else if ((s->flags & SEC_READONLY) == 0 1162 && HAVE_SECTION (hold_data, ".data")) 1163 place = &hold_data; 1164 else if (strncmp (secname, ".rel", 4) == 0 1165 && (hold_rel.os != NULL 1166 || (hold_rel.os = output_rel_find ()) != NULL)) 1167 place = &hold_rel; 1168 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY 1169 && HAVE_SECTION (hold_rodata, ".rodata")) 1170 place = &hold_rodata; 1171 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY) 1172 && hold_text.os != NULL) 1173 place = &hold_text; 1174 1175#undef HAVE_SECTION 1176 1177 /* Choose a unique name for the section. This will be needed if the 1178 same section name appears in the input file with different 1179 loadable or allocatable characteristics. */ 1180 outsecname = secname; 1181 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) 1182 { 1183 outsecname = bfd_get_unique_section_name (output_bfd, 1184 outsecname, 1185 &count); 1186 if (outsecname == NULL) 1187 einfo ("%F%P: place_orphan failed: %E\n"); 1188 } 1189 1190 /* Start building a list of statements for this section. 1191 First save the current statement pointer. */ 1192 old = stat_ptr; 1193 1194 /* If we have found an appropriate place for the output section 1195 statements for this orphan, add them to our own private list, 1196 inserting them later into the global statement list. */ 1197 if (place != NULL) 1198 { 1199 stat_ptr = &add; 1200 lang_list_init (stat_ptr); 1201 } 1202 1203 if (config.build_constructors) 1204 { 1205 /* If the name of the section is representable in C, then create 1206 symbols to mark the start and the end of the section. */ 1207 for (ps = outsecname; *ps != '\0'; ps++) 1208 if (! isalnum ((unsigned char) *ps) && *ps != '_') 1209 break; 1210 if (*ps == '\0') 1211 { 1212 char *symname; 1213 etree_type *e_align; 1214 1215 symname = (char *) xmalloc (ps - outsecname + sizeof "__start_"); 1216 sprintf (symname, "__start_%s", outsecname); 1217 e_align = exp_unop (ALIGN_K, 1218 exp_intop ((bfd_vma) 1 << s->alignment_power)); 1219 lang_add_assignment (exp_assop ('=', symname, e_align)); 1220 } 1221 } 1222 1223 if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) 1224 address = exp_intop ((bfd_vma) 0); 1225 else 1226 address = NULL; 1227 1228 os = lang_enter_output_section_statement (outsecname, address, 0, 1229 (bfd_vma) 0, 1230 (etree_type *) NULL, 1231 (etree_type *) NULL, 1232 (etree_type *) NULL); 1233 1234 wild_doit (&os->children, s, os, file); 1235 1236 lang_leave_output_section_statement 1237 ((bfd_vma) 0, "*default*", 1238 (struct lang_output_section_phdr_list *) NULL, "*default*"); 1239 1240 if (config.build_constructors && *ps == '\0') 1241 { 1242 char *symname; 1243 1244 /* lang_leave_ouput_section_statement resets stat_ptr. Put 1245 stat_ptr back where we want it. */ 1246 if (place != NULL) 1247 stat_ptr = &add; 1248 1249 symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_"); 1250 sprintf (symname, "__stop_%s", outsecname); 1251 lang_add_assignment (exp_assop ('=', symname, 1252 exp_nameop (NAME, "."))); 1253 } 1254 1255 /* Restore the global list pointer. */ 1256 stat_ptr = old; 1257 1258 if (place != NULL) 1259 { 1260 asection *snew, **pps; 1261 1262 snew = os->bfd_section; 1263 if (place->section != NULL 1264 || (place->os->bfd_section != NULL 1265 && place->os->bfd_section != snew)) 1266 { 1267 /* Shuffle the section to make the output file look neater. 1268 This is really only cosmetic. */ 1269 if (place->section == NULL) 1270 { 1271#if 0 1272 /* Finding the end of the list is a little tricky. We 1273 make a wild stab at it by comparing section flags. */ 1274 flagword first_flags = place->os->bfd_section->flags; 1275 for (pps = &place->os->bfd_section->next; 1276 *pps != NULL && (*pps)->flags == first_flags; 1277 pps = &(*pps)->next) 1278 ; 1279 place->section = pps; 1280#else 1281 /* Put orphans after the first section on the list. */ 1282 place->section = &place->os->bfd_section->next; 1283#endif 1284 } 1285 1286 /* Unlink the section. */ 1287 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next) 1288 ; 1289 *pps = snew->next; 1290 1291 /* Now tack it on to the "place->os" section list. */ 1292 snew->next = *place->section; 1293 *place->section = snew; 1294 } 1295 place->section = &snew->next; /* Save the end of this list. */ 1296 1297 if (add.head != NULL) 1298 { 1299 /* We try to put the output statements in some sort of 1300 reasonable order here, because they determine the final 1301 load addresses of the orphan sections. */ 1302 if (place->stmt == NULL) 1303 { 1304 /* Put the new statement list right at the head. */ 1305 *add.tail = place->os->header.next; 1306 place->os->header.next = add.head; 1307 } 1308 else 1309 { 1310 /* Put it after the last orphan statement we added. */ 1311 *add.tail = *place->stmt; 1312 *place->stmt = add.head; 1313 } 1314 1315 /* Fix the global list pointer if we happened to tack our 1316 new list at the tail. */ 1317 if (*old->tail == add.head) 1318 old->tail = add.tail; 1319 1320 /* Save the end of this list. */ 1321 place->stmt = add.tail; 1322 } 1323 } 1324 1325 return true; 1326} 1327 1328EOF 1329fi 1330 1331if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then 1332cat >>e${EMULATION_NAME}.c <<EOF 1333 1334static char * 1335gld${EMULATION_NAME}_get_script (isfile) 1336 int *isfile; 1337EOF 1338 1339if test -n "$COMPILE_IN" 1340then 1341# Scripts compiled in. 1342 1343# sed commands to quote an ld script as a C string. 1344sc="-f stringify.sed" 1345 1346cat >>e${EMULATION_NAME}.c <<EOF 1347{ 1348 *isfile = 0; 1349 1350 if (link_info.relocateable == true && config.build_constructors == true) 1351 return 1352EOF 1353sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 1354echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c 1355sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 1356echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 1357sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 1358echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 1359sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 1360 1361if test -n "$GENERATE_SHLIB_SCRIPT" ; then 1362echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c 1363sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c 1364fi 1365 1366echo ' ; else return' >> e${EMULATION_NAME}.c 1367sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 1368echo '; }' >> e${EMULATION_NAME}.c 1369 1370else 1371# Scripts read from the filesystem. 1372 1373cat >>e${EMULATION_NAME}.c <<EOF 1374{ 1375 *isfile = 1; 1376 1377 if (link_info.relocateable == true && config.build_constructors == true) 1378 return "ldscripts/${EMULATION_NAME}.xu"; 1379 else if (link_info.relocateable == true) 1380 return "ldscripts/${EMULATION_NAME}.xr"; 1381 else if (!config.text_read_only) 1382 return "ldscripts/${EMULATION_NAME}.xbn"; 1383 else if (!config.magic_demand_paged) 1384 return "ldscripts/${EMULATION_NAME}.xn"; 1385 else if (link_info.shared) 1386 return "ldscripts/${EMULATION_NAME}.xs"; 1387 else 1388 return "ldscripts/${EMULATION_NAME}.x"; 1389} 1390 1391EOF 1392fi 1393fi 1394 1395if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1396 1397if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then 1398 1399if test -n "$PARSE_AND_LIST_PROLOGUE" ; then 1400cat >>e${EMULATION_NAME}.c <<EOF 1401 $PARSE_AND_LIST_PROLOGUE 1402EOF 1403fi 1404 1405cat >>e${EMULATION_NAME}.c <<EOF 1406 1407#include "getopt.h" 1408 1409#define OPTION_DISABLE_NEW_DTAGS (400) 1410#define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
| 1015 } 1016 1017 return true; 1018} 1019 1020EOF 1021fi 1022cat >>e${EMULATION_NAME}.c <<EOF 1023 1024/* A variant of lang_output_section_find. Used by place_orphan. */ 1025 1026static lang_output_section_statement_type * 1027output_rel_find () 1028{ 1029 lang_statement_union_type *u; 1030 lang_output_section_statement_type *lookup; 1031 1032 for (u = lang_output_section_statement.head; 1033 u != (lang_statement_union_type *) NULL; 1034 u = lookup->next) 1035 { 1036 lookup = &u->output_section_statement; 1037 if (strncmp (".rel", lookup->name, 4) == 0 1038 && lookup->bfd_section != NULL 1039 && (lookup->bfd_section->flags & SEC_ALLOC) != 0) 1040 { 1041 return lookup; 1042 } 1043 } 1044 return (lang_output_section_statement_type *) NULL; 1045} 1046 1047EOF 1048 1049if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then 1050cat >>e${EMULATION_NAME}.c <<EOF 1051 1052/* Place an orphan section. We use this to put random SHF_ALLOC 1053 sections in the right segment. */ 1054 1055struct orphan_save { 1056 lang_output_section_statement_type *os; 1057 asection **section; 1058 lang_statement_union_type **stmt; 1059}; 1060 1061static boolean 1062gld${EMULATION_NAME}_place_orphan (file, s) 1063 lang_input_statement_type *file; 1064 asection *s; 1065{ 1066 static struct orphan_save hold_text; 1067 static struct orphan_save hold_rodata; 1068 static struct orphan_save hold_data; 1069 static struct orphan_save hold_bss; 1070 static struct orphan_save hold_rel; 1071 static struct orphan_save hold_interp; 1072 static struct orphan_save hold_sdata; 1073 static int count = 1; 1074 struct orphan_save *place; 1075 lang_statement_list_type *old; 1076 lang_statement_list_type add; 1077 etree_type *address; 1078 const char *secname; 1079 const char *outsecname; 1080 const char *ps = NULL; 1081 lang_output_section_statement_type *os; 1082 1083 secname = bfd_get_section_name (s->owner, s); 1084 1085 if (! config.unique_orphan_sections && ! unique_section_p (secname)) 1086 { 1087 /* Look through the script to see where to place this section. */ 1088 os = lang_output_section_find (secname); 1089 1090 if (os != NULL 1091 && os->bfd_section != NULL 1092 && ((s->flags ^ os->bfd_section->flags) 1093 & (SEC_LOAD | SEC_ALLOC)) == 0) 1094 { 1095 /* We have already placed a section with this name. */ 1096 wild_doit (&os->children, s, os, file); 1097 return true; 1098 } 1099 } 1100 1101 if (hold_text.os == NULL) 1102 hold_text.os = lang_output_section_find (".text"); 1103 1104 /* If this is a final link, then always put .gnu.warning.SYMBOL 1105 sections into the .text section to get them out of the way. */ 1106 if (! link_info.shared 1107 && ! link_info.relocateable 1108 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0 1109 && hold_text.os != NULL) 1110 { 1111 wild_doit (&hold_text.os->children, s, hold_text.os, file); 1112 return true; 1113 } 1114 1115 /* Decide which segment the section should go in based on the 1116 section name and section flags. We put loadable .note sections 1117 right after the .interp section, so that the PT_NOTE segment is 1118 stored right after the program headers where the OS can read it 1119 in the first page. */ 1120#define HAVE_SECTION(hold, name) \ 1121(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) 1122 1123 if (s->flags & SEC_EXCLUDE) 1124 return false; 1125 1126 place = NULL; 1127 if ((s->flags & SEC_ALLOC) == 0) 1128 ; 1129 else if ((s->flags & SEC_LOAD) != 0 1130 && strncmp (secname, ".note", 5) == 0 1131 && HAVE_SECTION (hold_interp, ".interp")) 1132 place = &hold_interp; 1133 else if ((s->flags & SEC_HAS_CONTENTS) == 0 1134 && HAVE_SECTION (hold_bss, ".bss")) 1135 place = &hold_bss; 1136 else if ((s->flags & SEC_SMALL_DATA) != 0 1137 && HAVE_SECTION (hold_sdata, ".sdata")) 1138 place = &hold_sdata; 1139 else if ((s->flags & SEC_READONLY) == 0 1140 && HAVE_SECTION (hold_data, ".data")) 1141 place = &hold_data; 1142 else if (strncmp (secname, ".rel", 4) == 0 1143 && (hold_rel.os != NULL 1144 || (hold_rel.os = output_rel_find ()) != NULL)) 1145 place = &hold_rel; 1146 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY 1147 && HAVE_SECTION (hold_rodata, ".rodata")) 1148 place = &hold_rodata; 1149 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY) 1150 && hold_text.os != NULL) 1151 place = &hold_text; 1152 1153#undef HAVE_SECTION 1154 1155 /* Choose a unique name for the section. This will be needed if the 1156 same section name appears in the input file with different 1157 loadable or allocatable characteristics. */ 1158 outsecname = secname; 1159 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) 1160 { 1161 outsecname = bfd_get_unique_section_name (output_bfd, 1162 outsecname, 1163 &count); 1164 if (outsecname == NULL) 1165 einfo ("%F%P: place_orphan failed: %E\n"); 1166 } 1167 1168 /* Start building a list of statements for this section. 1169 First save the current statement pointer. */ 1170 old = stat_ptr; 1171 1172 /* If we have found an appropriate place for the output section 1173 statements for this orphan, add them to our own private list, 1174 inserting them later into the global statement list. */ 1175 if (place != NULL) 1176 { 1177 stat_ptr = &add; 1178 lang_list_init (stat_ptr); 1179 } 1180 1181 if (config.build_constructors) 1182 { 1183 /* If the name of the section is representable in C, then create 1184 symbols to mark the start and the end of the section. */ 1185 for (ps = outsecname; *ps != '\0'; ps++) 1186 if (! isalnum ((unsigned char) *ps) && *ps != '_') 1187 break; 1188 if (*ps == '\0') 1189 { 1190 char *symname; 1191 etree_type *e_align; 1192 1193 symname = (char *) xmalloc (ps - outsecname + sizeof "__start_"); 1194 sprintf (symname, "__start_%s", outsecname); 1195 e_align = exp_unop (ALIGN_K, 1196 exp_intop ((bfd_vma) 1 << s->alignment_power)); 1197 lang_add_assignment (exp_assop ('=', symname, e_align)); 1198 } 1199 } 1200 1201 if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) 1202 address = exp_intop ((bfd_vma) 0); 1203 else 1204 address = NULL; 1205 1206 os = lang_enter_output_section_statement (outsecname, address, 0, 1207 (bfd_vma) 0, 1208 (etree_type *) NULL, 1209 (etree_type *) NULL, 1210 (etree_type *) NULL); 1211 1212 wild_doit (&os->children, s, os, file); 1213 1214 lang_leave_output_section_statement 1215 ((bfd_vma) 0, "*default*", 1216 (struct lang_output_section_phdr_list *) NULL, "*default*"); 1217 1218 if (config.build_constructors && *ps == '\0') 1219 { 1220 char *symname; 1221 1222 /* lang_leave_ouput_section_statement resets stat_ptr. Put 1223 stat_ptr back where we want it. */ 1224 if (place != NULL) 1225 stat_ptr = &add; 1226 1227 symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_"); 1228 sprintf (symname, "__stop_%s", outsecname); 1229 lang_add_assignment (exp_assop ('=', symname, 1230 exp_nameop (NAME, "."))); 1231 } 1232 1233 /* Restore the global list pointer. */ 1234 stat_ptr = old; 1235 1236 if (place != NULL) 1237 { 1238 asection *snew, **pps; 1239 1240 snew = os->bfd_section; 1241 if (place->section != NULL 1242 || (place->os->bfd_section != NULL 1243 && place->os->bfd_section != snew)) 1244 { 1245 /* Shuffle the section to make the output file look neater. 1246 This is really only cosmetic. */ 1247 if (place->section == NULL) 1248 { 1249#if 0 1250 /* Finding the end of the list is a little tricky. We 1251 make a wild stab at it by comparing section flags. */ 1252 flagword first_flags = place->os->bfd_section->flags; 1253 for (pps = &place->os->bfd_section->next; 1254 *pps != NULL && (*pps)->flags == first_flags; 1255 pps = &(*pps)->next) 1256 ; 1257 place->section = pps; 1258#else 1259 /* Put orphans after the first section on the list. */ 1260 place->section = &place->os->bfd_section->next; 1261#endif 1262 } 1263 1264 /* Unlink the section. */ 1265 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next) 1266 ; 1267 *pps = snew->next; 1268 1269 /* Now tack it on to the "place->os" section list. */ 1270 snew->next = *place->section; 1271 *place->section = snew; 1272 } 1273 place->section = &snew->next; /* Save the end of this list. */ 1274 1275 if (add.head != NULL) 1276 { 1277 /* We try to put the output statements in some sort of 1278 reasonable order here, because they determine the final 1279 load addresses of the orphan sections. */ 1280 if (place->stmt == NULL) 1281 { 1282 /* Put the new statement list right at the head. */ 1283 *add.tail = place->os->header.next; 1284 place->os->header.next = add.head; 1285 } 1286 else 1287 { 1288 /* Put it after the last orphan statement we added. */ 1289 *add.tail = *place->stmt; 1290 *place->stmt = add.head; 1291 } 1292 1293 /* Fix the global list pointer if we happened to tack our 1294 new list at the tail. */ 1295 if (*old->tail == add.head) 1296 old->tail = add.tail; 1297 1298 /* Save the end of this list. */ 1299 place->stmt = add.tail; 1300 } 1301 } 1302 1303 return true; 1304} 1305 1306EOF 1307fi 1308 1309if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then 1310cat >>e${EMULATION_NAME}.c <<EOF 1311 1312static char * 1313gld${EMULATION_NAME}_get_script (isfile) 1314 int *isfile; 1315EOF 1316 1317if test -n "$COMPILE_IN" 1318then 1319# Scripts compiled in. 1320 1321# sed commands to quote an ld script as a C string. 1322sc="-f stringify.sed" 1323 1324cat >>e${EMULATION_NAME}.c <<EOF 1325{ 1326 *isfile = 0; 1327 1328 if (link_info.relocateable == true && config.build_constructors == true) 1329 return 1330EOF 1331sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 1332echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c 1333sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 1334echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 1335sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 1336echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 1337sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 1338 1339if test -n "$GENERATE_SHLIB_SCRIPT" ; then 1340echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c 1341sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c 1342fi 1343 1344echo ' ; else return' >> e${EMULATION_NAME}.c 1345sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 1346echo '; }' >> e${EMULATION_NAME}.c 1347 1348else 1349# Scripts read from the filesystem. 1350 1351cat >>e${EMULATION_NAME}.c <<EOF 1352{ 1353 *isfile = 1; 1354 1355 if (link_info.relocateable == true && config.build_constructors == true) 1356 return "ldscripts/${EMULATION_NAME}.xu"; 1357 else if (link_info.relocateable == true) 1358 return "ldscripts/${EMULATION_NAME}.xr"; 1359 else if (!config.text_read_only) 1360 return "ldscripts/${EMULATION_NAME}.xbn"; 1361 else if (!config.magic_demand_paged) 1362 return "ldscripts/${EMULATION_NAME}.xn"; 1363 else if (link_info.shared) 1364 return "ldscripts/${EMULATION_NAME}.xs"; 1365 else 1366 return "ldscripts/${EMULATION_NAME}.x"; 1367} 1368 1369EOF 1370fi 1371fi 1372 1373if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1374 1375if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then 1376 1377if test -n "$PARSE_AND_LIST_PROLOGUE" ; then 1378cat >>e${EMULATION_NAME}.c <<EOF 1379 $PARSE_AND_LIST_PROLOGUE 1380EOF 1381fi 1382 1383cat >>e${EMULATION_NAME}.c <<EOF 1384 1385#include "getopt.h" 1386 1387#define OPTION_DISABLE_NEW_DTAGS (400) 1388#define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
|
| 1389#define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
|
1411 1412static struct option longopts[] = 1413{ 1414EOF 1415 1416if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1417cat >>e${EMULATION_NAME}.c <<EOF 1418 /* getopt allows abbreviations, so we do this to stop it from 1419 treating -d/-e as abbreviations for these options. */ 1420 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, 1421 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, 1422 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, 1423 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
| 1390 1391static struct option longopts[] = 1392{ 1393EOF 1394 1395if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1396cat >>e${EMULATION_NAME}.c <<EOF 1397 /* getopt allows abbreviations, so we do this to stop it from 1398 treating -d/-e as abbreviations for these options. */ 1399 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, 1400 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, 1401 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, 1402 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
|
| 1403 {"Bgroup", no_argument, NULL, OPTION_GROUP}, 1404 {"Bgroup", no_argument, NULL, OPTION_GROUP},
|
1424EOF 1425fi 1426 1427if test -n "$PARSE_AND_LIST_LONGOPTS" ; then 1428cat >>e${EMULATION_NAME}.c <<EOF 1429 $PARSE_AND_LIST_LONGOPTS 1430EOF 1431fi 1432 1433cat >>e${EMULATION_NAME}.c <<EOF 1434 {NULL, no_argument, NULL, 0} 1435}; 1436 1437 1438static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **)); 1439 1440static int 1441gld${EMULATION_NAME}_parse_args (argc, argv) 1442 int argc; 1443 char ** argv; 1444{ 1445 int longind; 1446 int optc; 1447 static int prevoptind = -1; 1448 int prevopterr = opterr; 1449 int wanterror; 1450 1451 if (prevoptind != optind) 1452 opterr = 0; 1453 1454 wanterror = opterr; 1455 prevoptind = optind; 1456 1457 optc = getopt_long_only (argc, argv, 1458 "-${PARSE_AND_LIST_SHORTOPTS}z:", longopts, 1459 &longind); 1460 opterr = prevopterr; 1461 1462 switch (optc) 1463 { 1464 default: 1465 if (wanterror) 1466 xexit (1); 1467 optind = prevoptind; 1468 return 0; 1469 1470EOF 1471 1472if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1473cat >>e${EMULATION_NAME}.c <<EOF 1474 case OPTION_DISABLE_NEW_DTAGS: 1475 link_info.new_dtags = false; 1476 break; 1477 1478 case OPTION_ENABLE_NEW_DTAGS: 1479 link_info.new_dtags = true; 1480 break; 1481
| 1405EOF 1406fi 1407 1408if test -n "$PARSE_AND_LIST_LONGOPTS" ; then 1409cat >>e${EMULATION_NAME}.c <<EOF 1410 $PARSE_AND_LIST_LONGOPTS 1411EOF 1412fi 1413 1414cat >>e${EMULATION_NAME}.c <<EOF 1415 {NULL, no_argument, NULL, 0} 1416}; 1417 1418 1419static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **)); 1420 1421static int 1422gld${EMULATION_NAME}_parse_args (argc, argv) 1423 int argc; 1424 char ** argv; 1425{ 1426 int longind; 1427 int optc; 1428 static int prevoptind = -1; 1429 int prevopterr = opterr; 1430 int wanterror; 1431 1432 if (prevoptind != optind) 1433 opterr = 0; 1434 1435 wanterror = opterr; 1436 prevoptind = optind; 1437 1438 optc = getopt_long_only (argc, argv, 1439 "-${PARSE_AND_LIST_SHORTOPTS}z:", longopts, 1440 &longind); 1441 opterr = prevopterr; 1442 1443 switch (optc) 1444 { 1445 default: 1446 if (wanterror) 1447 xexit (1); 1448 optind = prevoptind; 1449 return 0; 1450 1451EOF 1452 1453if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1454cat >>e${EMULATION_NAME}.c <<EOF 1455 case OPTION_DISABLE_NEW_DTAGS: 1456 link_info.new_dtags = false; 1457 break; 1458 1459 case OPTION_ENABLE_NEW_DTAGS: 1460 link_info.new_dtags = true; 1461 break; 1462
|
| 1463 case OPTION_GROUP: 1464 link_info.flags_1 |= (bfd_vma) DF_1_GROUP; 1465 /* Groups must be self-contained. */ 1466 link_info.no_undefined = true; 1467 break; 1468
|
1482 case 'z': 1483 if (strcmp (optarg, "initfirst") == 0) 1484 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; 1485 else if (strcmp (optarg, "interpose") == 0) 1486 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; 1487 else if (strcmp (optarg, "loadfltr") == 0) 1488 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; 1489 else if (strcmp (optarg, "nodefaultlib") == 0) 1490 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; 1491 else if (strcmp (optarg, "nodelete") == 0) 1492 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; 1493 else if (strcmp (optarg, "nodlopen") == 0) 1494 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; 1495 else if (strcmp (optarg, "nodump") == 0) 1496 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; 1497 else if (strcmp (optarg, "now") == 0) 1498 { 1499 link_info.flags |= (bfd_vma) DF_BIND_NOW; 1500 link_info.flags_1 |= (bfd_vma) DF_1_NOW; 1501 } 1502 else if (strcmp (optarg, "origin") == 0) 1503 { 1504 link_info.flags |= (bfd_vma) DF_ORIGIN; 1505 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; 1506 }
| 1469 case 'z': 1470 if (strcmp (optarg, "initfirst") == 0) 1471 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; 1472 else if (strcmp (optarg, "interpose") == 0) 1473 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; 1474 else if (strcmp (optarg, "loadfltr") == 0) 1475 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; 1476 else if (strcmp (optarg, "nodefaultlib") == 0) 1477 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; 1478 else if (strcmp (optarg, "nodelete") == 0) 1479 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; 1480 else if (strcmp (optarg, "nodlopen") == 0) 1481 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; 1482 else if (strcmp (optarg, "nodump") == 0) 1483 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; 1484 else if (strcmp (optarg, "now") == 0) 1485 { 1486 link_info.flags |= (bfd_vma) DF_BIND_NOW; 1487 link_info.flags_1 |= (bfd_vma) DF_1_NOW; 1488 } 1489 else if (strcmp (optarg, "origin") == 0) 1490 { 1491 link_info.flags |= (bfd_vma) DF_ORIGIN; 1492 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; 1493 }
|
| 1494 else if (strcmp (optarg, "defs") == 0) 1495 link_info.no_undefined = true;
|
1507 /* What about the other Solaris -z options? FIXME. */ 1508 break; 1509EOF 1510fi 1511 1512if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then 1513cat >>e${EMULATION_NAME}.c <<EOF 1514 $PARSE_AND_LIST_ARGS_CASES 1515EOF 1516fi 1517 1518cat >>e${EMULATION_NAME}.c <<EOF 1519 } 1520 1521 return 1; 1522} 1523 1524EOF 1525fi 1526 1527if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 1528cat >>e${EMULATION_NAME}.c <<EOF 1529 1530static void gld${EMULATION_NAME}_list_options PARAMS ((FILE * file)); 1531 1532static void 1533gld${EMULATION_NAME}_list_options (file) 1534 FILE * file; 1535{ 1536EOF 1537 1538if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1539cat >>e${EMULATION_NAME}.c <<EOF
| 1496 /* What about the other Solaris -z options? FIXME. */ 1497 break; 1498EOF 1499fi 1500 1501if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then 1502cat >>e${EMULATION_NAME}.c <<EOF 1503 $PARSE_AND_LIST_ARGS_CASES 1504EOF 1505fi 1506 1507cat >>e${EMULATION_NAME}.c <<EOF 1508 } 1509 1510 return 1; 1511} 1512 1513EOF 1514fi 1515 1516if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 1517cat >>e${EMULATION_NAME}.c <<EOF 1518 1519static void gld${EMULATION_NAME}_list_options PARAMS ((FILE * file)); 1520 1521static void 1522gld${EMULATION_NAME}_list_options (file) 1523 FILE * file; 1524{ 1525EOF 1526 1527if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1528cat >>e${EMULATION_NAME}.c <<EOF
|
| 1529 fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n"));
|
1540 fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n")); 1541 fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n"));
| 1530 fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n")); 1531 fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n"));
|
| 1532 fprintf (file, _(" -z defs\t\tDisallows undefined symbols\n"));
|
1542 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); 1543 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); 1544 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); 1545 fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n")); 1546 fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n")); 1547 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); 1548 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); 1549 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); 1550 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n")); 1551 fprintf (file, _("\t\t\t at runtime\n")); 1552 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n")); 1553EOF 1554fi 1555 1556if test -n "$PARSE_AND_LIST_OPTIONS" ; then 1557cat >>e${EMULATION_NAME}.c <<EOF 1558 $PARSE_AND_LIST_OPTIONS 1559EOF 1560fi 1561 1562cat >>e${EMULATION_NAME}.c <<EOF 1563} 1564EOF 1565 1566if test -n "$PARSE_AND_LIST_EPILOGUE" ; then 1567cat >>e${EMULATION_NAME}.c <<EOF 1568 $PARSE_AND_LIST_EPILOGUE 1569EOF 1570fi 1571fi 1572else 1573if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then 1574cat >>e${EMULATION_NAME}.c <<EOF 1575#define gld${EMULATION_NAME}_parse_args NULL 1576EOF 1577fi 1578if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 1579cat >>e${EMULATION_NAME}.c <<EOF 1580#define gld${EMULATION_NAME}_list_options NULL 1581EOF 1582fi 1583fi 1584 1585cat >>e${EMULATION_NAME}.c <<EOF 1586 1587struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 1588{ 1589 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, 1590 ${LDEMUL_SYSLIB-syslib_default}, 1591 ${LDEMUL_HLL-hll_default}, 1592 ${LDEMUL_AFTER_PARSE-after_parse_default}, 1593 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, 1594 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default}, 1595 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, 1596 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, 1597 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, 1598 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, 1599 "${EMULATION_NAME}", 1600 "${OUTPUT_FORMAT}", 1601 ${LDEMUL_FINISH-NULL}, 1602 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, 1603 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, 1604 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, 1605 ${LDEMUL_SET_SYMBOLS-NULL}, 1606 ${LDEMUL_PARSE_ARGS-gld${EMULATION_NAME}_parse_args}, 1607 ${LDEMUL_UNRECOGNIZED_FILE-NULL}, 1608 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, 1609 ${LDEMUL_RECOGNIZED_FILE-NULL}, 1610 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, 1611}; 1612EOF
| 1533 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); 1534 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); 1535 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); 1536 fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n")); 1537 fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n")); 1538 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); 1539 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); 1540 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); 1541 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n")); 1542 fprintf (file, _("\t\t\t at runtime\n")); 1543 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n")); 1544EOF 1545fi 1546 1547if test -n "$PARSE_AND_LIST_OPTIONS" ; then 1548cat >>e${EMULATION_NAME}.c <<EOF 1549 $PARSE_AND_LIST_OPTIONS 1550EOF 1551fi 1552 1553cat >>e${EMULATION_NAME}.c <<EOF 1554} 1555EOF 1556 1557if test -n "$PARSE_AND_LIST_EPILOGUE" ; then 1558cat >>e${EMULATION_NAME}.c <<EOF 1559 $PARSE_AND_LIST_EPILOGUE 1560EOF 1561fi 1562fi 1563else 1564if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then 1565cat >>e${EMULATION_NAME}.c <<EOF 1566#define gld${EMULATION_NAME}_parse_args NULL 1567EOF 1568fi 1569if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 1570cat >>e${EMULATION_NAME}.c <<EOF 1571#define gld${EMULATION_NAME}_list_options NULL 1572EOF 1573fi 1574fi 1575 1576cat >>e${EMULATION_NAME}.c <<EOF 1577 1578struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 1579{ 1580 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, 1581 ${LDEMUL_SYSLIB-syslib_default}, 1582 ${LDEMUL_HLL-hll_default}, 1583 ${LDEMUL_AFTER_PARSE-after_parse_default}, 1584 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, 1585 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default}, 1586 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, 1587 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, 1588 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, 1589 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, 1590 "${EMULATION_NAME}", 1591 "${OUTPUT_FORMAT}", 1592 ${LDEMUL_FINISH-NULL}, 1593 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, 1594 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, 1595 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, 1596 ${LDEMUL_SET_SYMBOLS-NULL}, 1597 ${LDEMUL_PARSE_ARGS-gld${EMULATION_NAME}_parse_args}, 1598 ${LDEMUL_UNRECOGNIZED_FILE-NULL}, 1599 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, 1600 ${LDEMUL_RECOGNIZED_FILE-NULL}, 1601 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, 1602}; 1603EOF
|