| 1 | /* ldemul.c -- clearing house for ld emulation states | 
|---|
| 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2003 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 |  | 
|---|
| 5 | This file is part of GLD, the Gnu Linker. | 
|---|
| 6 |  | 
|---|
| 7 | GLD is free software; you can redistribute it and/or modify | 
|---|
| 8 | it under the terms of the GNU General Public License as published by | 
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 10 | any later version. | 
|---|
| 11 |  | 
|---|
| 12 | GLD is distributed in the hope that it will be useful, | 
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 15 | GNU General Public License for more details. | 
|---|
| 16 |  | 
|---|
| 17 | You should have received a copy of the GNU General Public License | 
|---|
| 18 | along with GLD; see the file COPYING.  If not, write to the Free | 
|---|
| 19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | 
|---|
| 20 | 02111-1307, USA.  */ | 
|---|
| 21 |  | 
|---|
| 22 | #include "bfd.h" | 
|---|
| 23 | #include "sysdep.h" | 
|---|
| 24 | #include "getopt.h" | 
|---|
| 25 |  | 
|---|
| 26 | #include "ld.h" | 
|---|
| 27 | #include "ldmisc.h" | 
|---|
| 28 | #include "ldexp.h" | 
|---|
| 29 | #include "ldlang.h" | 
|---|
| 30 | #include "ldfile.h" | 
|---|
| 31 | #include "ldemul.h" | 
|---|
| 32 | #include "ldmain.h" | 
|---|
| 33 | #include "ldemul-list.h" | 
|---|
| 34 |  | 
|---|
| 35 | ld_emulation_xfer_type *ld_emulation; | 
|---|
| 36 |  | 
|---|
| 37 | void | 
|---|
| 38 | ldemul_hll (name) | 
|---|
| 39 | char *name; | 
|---|
| 40 | { | 
|---|
| 41 | ld_emulation->hll (name); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | void | 
|---|
| 45 | ldemul_syslib (name) | 
|---|
| 46 | char *name; | 
|---|
| 47 | { | 
|---|
| 48 | ld_emulation->syslib (name); | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | void | 
|---|
| 52 | ldemul_after_parse () | 
|---|
| 53 | { | 
|---|
| 54 | ld_emulation->after_parse (); | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | void | 
|---|
| 58 | ldemul_before_parse () | 
|---|
| 59 | { | 
|---|
| 60 | ld_emulation->before_parse (); | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | void | 
|---|
| 64 | ldemul_after_open () | 
|---|
| 65 | { | 
|---|
| 66 | ld_emulation->after_open (); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | void | 
|---|
| 70 | ldemul_after_allocation () | 
|---|
| 71 | { | 
|---|
| 72 | ld_emulation->after_allocation (); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | void | 
|---|
| 76 | ldemul_before_allocation () | 
|---|
| 77 | { | 
|---|
| 78 | if (ld_emulation->before_allocation) | 
|---|
| 79 | ld_emulation->before_allocation (); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | void | 
|---|
| 83 | ldemul_set_output_arch () | 
|---|
| 84 | { | 
|---|
| 85 | ld_emulation->set_output_arch (); | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | void | 
|---|
| 89 | ldemul_finish () | 
|---|
| 90 | { | 
|---|
| 91 | if (ld_emulation->finish) | 
|---|
| 92 | ld_emulation->finish (); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | void | 
|---|
| 96 | ldemul_set_symbols () | 
|---|
| 97 | { | 
|---|
| 98 | if (ld_emulation->set_symbols) | 
|---|
| 99 | ld_emulation->set_symbols (); | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | void | 
|---|
| 103 | ldemul_create_output_section_statements () | 
|---|
| 104 | { | 
|---|
| 105 | if (ld_emulation->create_output_section_statements) | 
|---|
| 106 | ld_emulation->create_output_section_statements (); | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | char * | 
|---|
| 110 | ldemul_get_script (isfile) | 
|---|
| 111 | int *isfile; | 
|---|
| 112 | { | 
|---|
| 113 | return ld_emulation->get_script (isfile); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | bfd_boolean | 
|---|
| 117 | ldemul_open_dynamic_archive (arch, search, entry) | 
|---|
| 118 | const char *arch; | 
|---|
| 119 | search_dirs_type *search; | 
|---|
| 120 | lang_input_statement_type *entry; | 
|---|
| 121 | { | 
|---|
| 122 | if (ld_emulation->open_dynamic_archive) | 
|---|
| 123 | return (*ld_emulation->open_dynamic_archive) (arch, search, entry); | 
|---|
| 124 | return FALSE; | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | bfd_boolean | 
|---|
| 128 | ldemul_place_orphan (file, s) | 
|---|
| 129 | lang_input_statement_type *file; | 
|---|
| 130 | asection *s; | 
|---|
| 131 | { | 
|---|
| 132 | if (ld_emulation->place_orphan) | 
|---|
| 133 | return (*ld_emulation->place_orphan) (file, s); | 
|---|
| 134 | return FALSE; | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | void | 
|---|
| 138 | ldemul_add_options (ns, shortopts, nl, longopts, nrl, really_longopts) | 
|---|
| 139 | int ns; | 
|---|
| 140 | char **shortopts; | 
|---|
| 141 | int nl; | 
|---|
| 142 | struct option **longopts; | 
|---|
| 143 | int nrl; | 
|---|
| 144 | struct option **really_longopts; | 
|---|
| 145 | { | 
|---|
| 146 | if (ld_emulation->add_options) | 
|---|
| 147 | (*ld_emulation->add_options) (ns, shortopts, nl, longopts, | 
|---|
| 148 | nrl, really_longopts); | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | bfd_boolean | 
|---|
| 152 | ldemul_handle_option (optc) | 
|---|
| 153 | int optc; | 
|---|
| 154 | { | 
|---|
| 155 | if (ld_emulation->handle_option) | 
|---|
| 156 | return (*ld_emulation->handle_option) (optc); | 
|---|
| 157 | return FALSE; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | bfd_boolean | 
|---|
| 161 | ldemul_parse_args (argc, argv) | 
|---|
| 162 | int argc; | 
|---|
| 163 | char **argv; | 
|---|
| 164 | { | 
|---|
| 165 | /* Try and use the emulation parser if there is one.  */ | 
|---|
| 166 | if (ld_emulation->parse_args) | 
|---|
| 167 | return (*ld_emulation->parse_args) (argc, argv); | 
|---|
| 168 | return FALSE; | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | /* Let the emulation code handle an unrecognized file.  */ | 
|---|
| 172 |  | 
|---|
| 173 | bfd_boolean | 
|---|
| 174 | ldemul_unrecognized_file (entry) | 
|---|
| 175 | lang_input_statement_type *entry; | 
|---|
| 176 | { | 
|---|
| 177 | if (ld_emulation->unrecognized_file) | 
|---|
| 178 | return (*ld_emulation->unrecognized_file) (entry); | 
|---|
| 179 | return FALSE; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | /* Let the emulation code handle a recognized file.  */ | 
|---|
| 183 |  | 
|---|
| 184 | bfd_boolean | 
|---|
| 185 | ldemul_recognized_file (entry) | 
|---|
| 186 | lang_input_statement_type *entry; | 
|---|
| 187 | { | 
|---|
| 188 | if (ld_emulation->recognized_file) | 
|---|
| 189 | return (*ld_emulation->recognized_file) (entry); | 
|---|
| 190 | return FALSE; | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | char * | 
|---|
| 194 | ldemul_choose_target (argc, argv) | 
|---|
| 195 | int argc; | 
|---|
| 196 | char **argv; | 
|---|
| 197 | { | 
|---|
| 198 | return ld_emulation->choose_target (argc, argv); | 
|---|
| 199 | } | 
|---|
| 200 |  | 
|---|
| 201 |  | 
|---|
| 202 | /* The default choose_target function.  */ | 
|---|
| 203 |  | 
|---|
| 204 | char * | 
|---|
| 205 | ldemul_default_target (argc, argv) | 
|---|
| 206 | int argc ATTRIBUTE_UNUSED; | 
|---|
| 207 | char **argv ATTRIBUTE_UNUSED; | 
|---|
| 208 | { | 
|---|
| 209 | char *from_outside = getenv (TARGET_ENVIRON); | 
|---|
| 210 | if (from_outside != (char *) NULL) | 
|---|
| 211 | return from_outside; | 
|---|
| 212 | return ld_emulation->target_name; | 
|---|
| 213 | } | 
|---|
| 214 |  | 
|---|
| 215 | void | 
|---|
| 216 | after_parse_default () | 
|---|
| 217 | { | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | void | 
|---|
| 221 | after_open_default () | 
|---|
| 222 | { | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | void | 
|---|
| 226 | after_allocation_default () | 
|---|
| 227 | { | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | void | 
|---|
| 231 | before_allocation_default () | 
|---|
| 232 | { | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | void | 
|---|
| 236 | set_output_arch_default () | 
|---|
| 237 | { | 
|---|
| 238 | /* Set the output architecture and machine if possible.  */ | 
|---|
| 239 | bfd_set_arch_mach (output_bfd, | 
|---|
| 240 | ldfile_output_architecture, ldfile_output_machine); | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | void | 
|---|
| 244 | syslib_default (ignore) | 
|---|
| 245 | char *ignore ATTRIBUTE_UNUSED; | 
|---|
| 246 | { | 
|---|
| 247 | info_msg (_("%S SYSLIB ignored\n")); | 
|---|
| 248 | } | 
|---|
| 249 |  | 
|---|
| 250 | void | 
|---|
| 251 | hll_default (ignore) | 
|---|
| 252 | char *ignore ATTRIBUTE_UNUSED; | 
|---|
| 253 | { | 
|---|
| 254 | info_msg (_("%S HLL ignored\n")); | 
|---|
| 255 | } | 
|---|
| 256 |  | 
|---|
| 257 | ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST }; | 
|---|
| 258 |  | 
|---|
| 259 | void | 
|---|
| 260 | ldemul_choose_mode (target) | 
|---|
| 261 | char *target; | 
|---|
| 262 | { | 
|---|
| 263 | ld_emulation_xfer_type **eptr = ld_emulations; | 
|---|
| 264 | /* Ignore "gld" prefix.  */ | 
|---|
| 265 | if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd') | 
|---|
| 266 | target += 3; | 
|---|
| 267 | for (; *eptr; eptr++) | 
|---|
| 268 | { | 
|---|
| 269 | if (strcmp (target, (*eptr)->emulation_name) == 0) | 
|---|
| 270 | { | 
|---|
| 271 | ld_emulation = *eptr; | 
|---|
| 272 | return; | 
|---|
| 273 | } | 
|---|
| 274 | } | 
|---|
| 275 | einfo (_("%P: unrecognised emulation mode: %s\n"), target); | 
|---|
| 276 | einfo (_("Supported emulations: ")); | 
|---|
| 277 | ldemul_list_emulations (stderr); | 
|---|
| 278 | einfo ("%F\n"); | 
|---|
| 279 | } | 
|---|
| 280 |  | 
|---|
| 281 | void | 
|---|
| 282 | ldemul_list_emulations (f) | 
|---|
| 283 | FILE *f; | 
|---|
| 284 | { | 
|---|
| 285 | ld_emulation_xfer_type **eptr = ld_emulations; | 
|---|
| 286 | bfd_boolean first = TRUE; | 
|---|
| 287 |  | 
|---|
| 288 | for (; *eptr; eptr++) | 
|---|
| 289 | { | 
|---|
| 290 | if (first) | 
|---|
| 291 | first = FALSE; | 
|---|
| 292 | else | 
|---|
| 293 | fprintf (f, " "); | 
|---|
| 294 | fprintf (f, "%s", (*eptr)->emulation_name); | 
|---|
| 295 | } | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | void | 
|---|
| 299 | ldemul_list_emulation_options (f) | 
|---|
| 300 | FILE *f; | 
|---|
| 301 | { | 
|---|
| 302 | ld_emulation_xfer_type **eptr; | 
|---|
| 303 | int options_found = 0; | 
|---|
| 304 |  | 
|---|
| 305 | for (eptr = ld_emulations; *eptr; eptr++) | 
|---|
| 306 | { | 
|---|
| 307 | ld_emulation_xfer_type *emul = *eptr; | 
|---|
| 308 |  | 
|---|
| 309 | if (emul->list_options) | 
|---|
| 310 | { | 
|---|
| 311 | fprintf (f, "%s: \n", emul->emulation_name); | 
|---|
| 312 |  | 
|---|
| 313 | emul->list_options (f); | 
|---|
| 314 |  | 
|---|
| 315 | options_found = 1; | 
|---|
| 316 | } | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | if (! options_found) | 
|---|
| 320 | fprintf (f, _("  no emulation specific options.\n")); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | int | 
|---|
| 324 | ldemul_find_potential_libraries (name, entry) | 
|---|
| 325 | char *name; | 
|---|
| 326 | lang_input_statement_type *entry; | 
|---|
| 327 | { | 
|---|
| 328 | if (ld_emulation->find_potential_libraries) | 
|---|
| 329 | return ld_emulation->find_potential_libraries (name, entry); | 
|---|
| 330 |  | 
|---|
| 331 | return 0; | 
|---|
| 332 | } | 
|---|
| 333 |  | 
|---|
| 334 | struct bfd_elf_version_expr * | 
|---|
| 335 | ldemul_new_vers_pattern (entry) | 
|---|
| 336 | struct bfd_elf_version_expr *entry; | 
|---|
| 337 | { | 
|---|
| 338 | if (ld_emulation->new_vers_pattern) | 
|---|
| 339 | entry = (*ld_emulation->new_vers_pattern) (entry); | 
|---|
| 340 | return entry; | 
|---|
| 341 | } | 
|---|
| 342 |  | 
|---|
| 343 | /* Added by the EMX/OS2 port */ | 
|---|
| 344 | void | 
|---|
| 345 | ldemul_finish_link (char *filename) | 
|---|
| 346 | { | 
|---|
| 347 | if (ld_emulation->finish_link) | 
|---|
| 348 | ld_emulation->finish_link (filename); | 
|---|
| 349 | } | 
|---|