| 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 (char *name) |
| 39 | { |
| 40 | ld_emulation->hll (name); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | ldemul_syslib (char *name) |
| 45 | { |
| 46 | ld_emulation->syslib (name); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | ldemul_after_parse (void) |
| 51 | { |
| 52 | ld_emulation->after_parse (); |
| 53 | } |
| 54 | |
| 55 | void |
| 56 | ldemul_before_parse (void) |
| 57 | { |
| 58 | ld_emulation->before_parse (); |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | ldemul_after_open (void) |
| 63 | { |
| 64 | ld_emulation->after_open (); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | ldemul_after_allocation (void) |
| 69 | { |
| 70 | ld_emulation->after_allocation (); |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | ldemul_before_allocation (void) |
| 75 | { |
| 76 | if (ld_emulation->before_allocation) |
| 77 | ld_emulation->before_allocation (); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | ldemul_set_output_arch (void) |
| 82 | { |
| 83 | ld_emulation->set_output_arch (); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | ldemul_finish (void) |
| 88 | { |
| 89 | if (ld_emulation->finish) |
| 90 | ld_emulation->finish (); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | ldemul_set_symbols (void) |
| 95 | { |
| 96 | if (ld_emulation->set_symbols) |
| 97 | ld_emulation->set_symbols (); |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | ldemul_create_output_section_statements (void) |
| 102 | { |
| 103 | if (ld_emulation->create_output_section_statements) |
| 104 | ld_emulation->create_output_section_statements (); |
| 105 | } |
| 106 | |
| 107 | char * |
| 108 | ldemul_get_script (int *isfile) |
| 109 | { |
| 110 | return ld_emulation->get_script (isfile); |
| 111 | } |
| 112 | |
| 113 | bfd_boolean |
| 114 | ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search, |
| 115 | lang_input_statement_type *entry) |
| 116 | { |
| 117 | if (ld_emulation->open_dynamic_archive) |
| 118 | return (*ld_emulation->open_dynamic_archive) (arch, search, entry); |
| 119 | return FALSE; |
| 120 | } |
| 121 | |
| 122 | bfd_boolean |
| 123 | ldemul_place_orphan (lang_input_statement_type *file, asection *s) |
| 124 | { |
| 125 | if (ld_emulation->place_orphan) |
| 126 | return (*ld_emulation->place_orphan) (file, s); |
| 127 | return FALSE; |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | ldemul_add_options (int ns, char **shortopts, int nl, |
| 132 | struct option **longopts, int nrl, |
| 133 | struct option **really_longopts) |
| 134 | { |
| 135 | if (ld_emulation->add_options) |
| 136 | (*ld_emulation->add_options) (ns, shortopts, nl, longopts, |
| 137 | nrl, really_longopts); |
| 138 | } |
| 139 | |
| 140 | bfd_boolean |
| 141 | ldemul_handle_option (int optc) |
| 142 | { |
| 143 | if (ld_emulation->handle_option) |
| 144 | return (*ld_emulation->handle_option) (optc); |
| 145 | return FALSE; |
| 146 | } |
| 147 | |
| 148 | bfd_boolean |
| 149 | ldemul_parse_args (int argc, char **argv) |
| 150 | { |
| 151 | /* Try and use the emulation parser if there is one. */ |
| 152 | if (ld_emulation->parse_args) |
| 153 | return (*ld_emulation->parse_args) (argc, argv); |
| 154 | return FALSE; |
| 155 | } |
| 156 | |
| 157 | /* Let the emulation code handle an unrecognized file. */ |
| 158 | |
| 159 | bfd_boolean |
| 160 | ldemul_unrecognized_file (lang_input_statement_type *entry) |
| 161 | { |
| 162 | if (ld_emulation->unrecognized_file) |
| 163 | return (*ld_emulation->unrecognized_file) (entry); |
| 164 | return FALSE; |
| 165 | } |
| 166 | |
| 167 | /* Let the emulation code handle a recognized file. */ |
| 168 | |
| 169 | bfd_boolean |
| 170 | ldemul_recognized_file (lang_input_statement_type *entry) |
| 171 | { |
| 172 | if (ld_emulation->recognized_file) |
| 173 | return (*ld_emulation->recognized_file) (entry); |
| 174 | return FALSE; |
| 175 | } |
| 176 | |
| 177 | char * |
| 178 | ldemul_choose_target (int argc, char **argv) |
| 179 | { |
| 180 | return ld_emulation->choose_target (argc, argv); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /* The default choose_target function. */ |
| 185 | |
| 186 | char * |
| 187 | ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) |
| 188 | { |
| 189 | char *from_outside = getenv (TARGET_ENVIRON); |
| 190 | if (from_outside != (char *) NULL) |
| 191 | return from_outside; |
| 192 | return ld_emulation->target_name; |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | after_parse_default (void) |
| 197 | { |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | after_open_default (void) |
| 202 | { |
| 203 | } |
| 204 | |
| 205 | void |
| 206 | after_allocation_default (void) |
| 207 | { |
| 208 | } |
| 209 | |
| 210 | void |
| 211 | before_allocation_default (void) |
| 212 | { |
| 213 | } |
| 214 | |
| 215 | void |
| 216 | set_output_arch_default (void) |
| 217 | { |
| 218 | /* Set the output architecture and machine if possible. */ |
| 219 | bfd_set_arch_mach (output_bfd, |
| 220 | ldfile_output_architecture, ldfile_output_machine); |
| 221 | } |
| 222 | |
| 223 | void |
| 224 | syslib_default (char *ignore ATTRIBUTE_UNUSED) |
| 225 | { |
| 226 | info_msg (_("%S SYSLIB ignored\n")); |
| 227 | } |
| 228 | |
| 229 | void |
| 230 | hll_default (char *ignore ATTRIBUTE_UNUSED) |
| 231 | { |
| 232 | info_msg (_("%S HLL ignored\n")); |
| 233 | } |
| 234 | |
| 235 | ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST }; |
| 236 | |
| 237 | void |
| 238 | ldemul_choose_mode (char *target) |
| 239 | { |
| 240 | ld_emulation_xfer_type **eptr = ld_emulations; |
| 241 | /* Ignore "gld" prefix. */ |
| 242 | if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd') |
| 243 | target += 3; |
| 244 | for (; *eptr; eptr++) |
| 245 | { |
| 246 | if (strcmp (target, (*eptr)->emulation_name) == 0) |
| 247 | { |
| 248 | ld_emulation = *eptr; |
| 249 | return; |
| 250 | } |
| 251 | } |
| 252 | einfo (_("%P: unrecognised emulation mode: %s\n"), target); |
| 253 | einfo (_("Supported emulations: ")); |
| 254 | ldemul_list_emulations (stderr); |
| 255 | einfo ("%F\n"); |
| 256 | } |
| 257 | |
| 258 | void |
| 259 | ldemul_list_emulations (FILE *f) |
| 260 | { |
| 261 | ld_emulation_xfer_type **eptr = ld_emulations; |
| 262 | bfd_boolean first = TRUE; |
| 263 | |
| 264 | for (; *eptr; eptr++) |
| 265 | { |
| 266 | if (first) |
| 267 | first = FALSE; |
| 268 | else |
| 269 | fprintf (f, " "); |
| 270 | fprintf (f, "%s", (*eptr)->emulation_name); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | void |
| 275 | ldemul_list_emulation_options (FILE *f) |
| 276 | { |
| 277 | ld_emulation_xfer_type **eptr; |
| 278 | int options_found = 0; |
| 279 | |
| 280 | for (eptr = ld_emulations; *eptr; eptr++) |
| 281 | { |
| 282 | ld_emulation_xfer_type *emul = *eptr; |
| 283 | |
| 284 | if (emul->list_options) |
| 285 | { |
| 286 | fprintf (f, "%s: \n", emul->emulation_name); |
| 287 | |
| 288 | emul->list_options (f); |
| 289 | |
| 290 | options_found = 1; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if (! options_found) |
| 295 | fprintf (f, _(" no emulation specific options.\n")); |
| 296 | } |
| 297 | |
| 298 | int |
| 299 | ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry) |
| 300 | { |
| 301 | if (ld_emulation->find_potential_libraries) |
| 302 | return ld_emulation->find_potential_libraries (name, entry); |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | struct bfd_elf_version_expr * |
| 308 | ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry) |
| 309 | { |
| 310 | if (ld_emulation->new_vers_pattern) |
| 311 | entry = (*ld_emulation->new_vers_pattern) (entry); |
| 312 | return entry; |
| 313 | } |