Back to index

cell-binutils  2.17cvs20070401
ldemul.c
Go to the documentation of this file.
00001 /* ldemul.c -- clearing house for ld emulation states
00002    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
00003    2001, 2002, 2003, 2005
00004    Free Software Foundation, Inc.
00005 
00006 This file is part of GLD, the Gnu Linker.
00007 
00008 GLD is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2, or (at your option)
00011 any later version.
00012 
00013 GLD is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with GLD; see the file COPYING.  If not, write to the Free
00020 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021 02110-1301, USA.  */
00022 
00023 #include "config.h"
00024 #include "bfd.h"
00025 #include "sysdep.h"
00026 #include "getopt.h"
00027 #include "bfdlink.h"
00028 
00029 #include "ld.h"
00030 #include "ldmisc.h"
00031 #include "ldexp.h"
00032 #include "ldlang.h"
00033 #include "ldfile.h"
00034 #include "ldemul.h"
00035 #include "ldmain.h"
00036 #include "ldemul-list.h"
00037 
00038 static ld_emulation_xfer_type *ld_emulation;
00039 
00040 void
00041 ldemul_hll (char *name)
00042 {
00043   ld_emulation->hll (name);
00044 }
00045 
00046 void
00047 ldemul_syslib (char *name)
00048 {
00049   ld_emulation->syslib (name);
00050 }
00051 
00052 void
00053 ldemul_after_parse (void)
00054 {
00055   ld_emulation->after_parse ();
00056 }
00057 
00058 void
00059 ldemul_before_parse (void)
00060 {
00061   ld_emulation->before_parse ();
00062 }
00063 
00064 void
00065 ldemul_after_open (void)
00066 {
00067   ld_emulation->after_open ();
00068 }
00069 
00070 void
00071 ldemul_after_allocation (void)
00072 {
00073   ld_emulation->after_allocation ();
00074 }
00075 
00076 void
00077 ldemul_before_allocation (void)
00078 {
00079   ld_emulation->before_allocation ();
00080 }
00081 
00082 void
00083 ldemul_set_output_arch (void)
00084 {
00085   ld_emulation->set_output_arch ();
00086 }
00087 
00088 void
00089 ldemul_finish (void)
00090 {
00091   ld_emulation->finish ();
00092 }
00093 
00094 void
00095 ldemul_set_symbols (void)
00096 {
00097   if (ld_emulation->set_symbols)
00098     ld_emulation->set_symbols ();
00099 }
00100 
00101 void
00102 ldemul_create_output_section_statements (void)
00103 {
00104   if (ld_emulation->create_output_section_statements)
00105     ld_emulation->create_output_section_statements ();
00106 }
00107 
00108 char *
00109 ldemul_get_script (int *isfile)
00110 {
00111   return ld_emulation->get_script (isfile);
00112 }
00113 
00114 bfd_boolean
00115 ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
00116                           lang_input_statement_type *entry)
00117 {
00118   if (ld_emulation->open_dynamic_archive)
00119     return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
00120   return FALSE;
00121 }
00122 
00123 bfd_boolean
00124 ldemul_place_orphan (asection *s)
00125 {
00126   if (ld_emulation->place_orphan)
00127     return (*ld_emulation->place_orphan) (s);
00128   return FALSE;
00129 }
00130 
00131 void
00132 ldemul_add_options (int ns, char **shortopts, int nl,
00133                   struct option **longopts, int nrl,
00134                   struct option **really_longopts)
00135 {
00136   if (ld_emulation->add_options)
00137     (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
00138                               nrl, really_longopts);
00139 }
00140 
00141 bfd_boolean
00142 ldemul_handle_option (int optc)
00143 {
00144   if (ld_emulation->handle_option)
00145     return (*ld_emulation->handle_option) (optc);
00146   return FALSE;
00147 }
00148 
00149 bfd_boolean
00150 ldemul_parse_args (int argc, char **argv)
00151 {
00152   /* Try and use the emulation parser if there is one.  */
00153   if (ld_emulation->parse_args)
00154     return (*ld_emulation->parse_args) (argc, argv);
00155   return FALSE;
00156 }
00157 
00158 /* Let the emulation code handle an unrecognized file.  */
00159 
00160 bfd_boolean
00161 ldemul_unrecognized_file (lang_input_statement_type *entry)
00162 {
00163   if (ld_emulation->unrecognized_file)
00164     return (*ld_emulation->unrecognized_file) (entry);
00165   return FALSE;
00166 }
00167 
00168 /* Let the emulation code handle a recognized file.  */
00169 
00170 bfd_boolean
00171 ldemul_recognized_file (lang_input_statement_type *entry)
00172 {
00173   if (ld_emulation->recognized_file)
00174     return (*ld_emulation->recognized_file) (entry);
00175   return FALSE;
00176 }
00177 
00178 char *
00179 ldemul_choose_target (int argc, char **argv)
00180 {
00181   return ld_emulation->choose_target (argc, argv);
00182 }
00183 
00184 
00185 /* The default choose_target function.  */
00186 
00187 char *
00188 ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
00189 {
00190   char *from_outside = getenv (TARGET_ENVIRON);
00191   if (from_outside != (char *) NULL)
00192     return from_outside;
00193   return ld_emulation->target_name;
00194 }
00195 
00196 void
00197 after_parse_default (void)
00198 {
00199 }
00200 
00201 void
00202 after_open_default (void)
00203 {
00204 }
00205 
00206 void
00207 after_allocation_default (void)
00208 {
00209 }
00210 
00211 void
00212 before_allocation_default (void)
00213 {
00214   if (!link_info.relocatable)
00215     strip_excluded_output_sections ();
00216 }
00217 
00218 void
00219 finish_default (void)
00220 {
00221   if (!link_info.relocatable)
00222     _bfd_fix_excluded_sec_syms (output_bfd, &link_info);
00223 }
00224 
00225 void
00226 set_output_arch_default (void)
00227 {
00228   /* Set the output architecture and machine if possible.  */
00229   bfd_set_arch_mach (output_bfd,
00230                    ldfile_output_architecture, ldfile_output_machine);
00231 }
00232 
00233 void
00234 syslib_default (char *ignore ATTRIBUTE_UNUSED)
00235 {
00236   info_msg (_("%S SYSLIB ignored\n"));
00237 }
00238 
00239 void
00240 hll_default (char *ignore ATTRIBUTE_UNUSED)
00241 {
00242   info_msg (_("%S HLL ignored\n"));
00243 }
00244 
00245 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
00246 
00247 void
00248 ldemul_choose_mode (char *target)
00249 {
00250   ld_emulation_xfer_type **eptr = ld_emulations;
00251   /* Ignore "gld" prefix.  */
00252   if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
00253     target += 3;
00254   for (; *eptr; eptr++)
00255     {
00256       if (strcmp (target, (*eptr)->emulation_name) == 0)
00257        {
00258          ld_emulation = *eptr;
00259          return;
00260        }
00261     }
00262   einfo (_("%P: unrecognised emulation mode: %s\n"), target);
00263   einfo (_("Supported emulations: "));
00264   ldemul_list_emulations (stderr);
00265   einfo ("%F\n");
00266 }
00267 
00268 void
00269 ldemul_list_emulations (FILE *f)
00270 {
00271   ld_emulation_xfer_type **eptr = ld_emulations;
00272   bfd_boolean first = TRUE;
00273 
00274   for (; *eptr; eptr++)
00275     {
00276       if (first)
00277        first = FALSE;
00278       else
00279        fprintf (f, " ");
00280       fprintf (f, "%s", (*eptr)->emulation_name);
00281     }
00282 }
00283 
00284 void
00285 ldemul_list_emulation_options (FILE *f)
00286 {
00287   ld_emulation_xfer_type **eptr;
00288   int options_found = 0;
00289 
00290   for (eptr = ld_emulations; *eptr; eptr++)
00291     {
00292       ld_emulation_xfer_type *emul = *eptr;
00293 
00294       if (emul->list_options)
00295        {
00296          fprintf (f, "%s: \n", emul->emulation_name);
00297 
00298          emul->list_options (f);
00299 
00300          options_found = 1;
00301        }
00302     }
00303 
00304   if (! options_found)
00305     fprintf (f, _("  no emulation specific options.\n"));
00306 }
00307 
00308 int
00309 ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
00310 {
00311   if (ld_emulation->find_potential_libraries)
00312     return ld_emulation->find_potential_libraries (name, entry);
00313 
00314   return 0;
00315 }
00316 
00317 struct bfd_elf_version_expr *
00318 ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
00319 {
00320   if (ld_emulation->new_vers_pattern)
00321     entry = (*ld_emulation->new_vers_pattern) (entry);
00322   return entry;
00323 }