Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/ld/ldfile.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Linker file opening and searching.
    2    Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001
     2   Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
    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.  */
     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.  */
    2121
    2222/* ldfile.c:  look after all the file stuff.  */
     
    2525#include "sysdep.h"
    2626#include "bfdlink.h"
     27#include "safe-ctype.h"
    2728#include "ld.h"
    2829#include "ldmisc.h"
     
    3132#include "ldfile.h"
    3233#include "ldmain.h"
    33 #include "ldgram.h"
     34#include <ldgram.h>
    3435#include "ldlex.h"
    3536#include "ldemul.h"
    3637#include "libiberty.h"
    37 
    38 #include <ctype.h>
    39 
    40 const char *ldfile_input_filename;
    41 boolean ldfile_assumed_script = false;
    42 const char *ldfile_output_machine_name = "";
     38#include "filenames.h"
     39
     40const char * ldfile_input_filename;
     41bfd_boolean  ldfile_assumed_script = FALSE;
     42const char * ldfile_output_machine_name = "";
    4343unsigned long ldfile_output_machine;
    4444enum bfd_architecture ldfile_output_architecture;
    45 search_dirs_type *search_head;
     45search_dirs_type * search_head;
    4646
    4747#ifndef MPW
    4848#ifdef VMS
    49 char *slash = "";
     49char * slash = "";
    5050#else
    5151#if defined (_WIN32) && ! defined (__CYGWIN32__)
    52 char *slash = "\\";
     52char * slash = "\\";
    5353#else
    54 char *slash = "/";
     54char * slash = "/";
    5555#endif
    5656#endif
    5757#else /* MPW */
    5858/* The MPW path char is a colon.  */
    59 char *slash = ":";
     59char * slash = ":";
    6060#endif /* MPW */
    6161
    62 /* LOCAL */
    63 
    64 static search_dirs_type **search_tail_ptr = &search_head;
    65 
    66 typedef struct search_arch {
     62typedef struct search_arch
     63{
    6764  char *name;
    6865  struct search_arch *next;
    6966} search_arch_type;
    7067
     68static search_dirs_type **search_tail_ptr = &search_head;
    7169static search_arch_type *search_arch_head;
    7270static search_arch_type **search_arch_tail_ptr = &search_arch_head;
    7371
    74 static FILE *try_open PARAMS ((const char *name, const char *exten));
     72static FILE *try_open
     73  PARAMS ((const char *, const char *));
     74static bfd_boolean is_sysrooted_pathname
     75  PARAMS ((const char *, bfd_boolean));
     76
     77/* Test whether a pathname, after canonicalization, is the same or a
     78   sub-directory of the sysroot directory.  */
     79
     80static bfd_boolean
     81is_sysrooted_pathname (name, notsame)
     82     const char *name;
     83     bfd_boolean notsame;
     84{
     85  char * realname = ld_canon_sysroot ? lrealpath (name) : NULL;
     86  int len;
     87  bfd_boolean result;
     88
     89  if (! realname)
     90    return FALSE;
     91 
     92  len = strlen (realname);
     93
     94  if (((! notsame && len == ld_canon_sysroot_len)
     95       || (len >= ld_canon_sysroot_len
     96           && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])
     97           && (realname[ld_canon_sysroot_len] = '\0') == '\0'))
     98      && FILENAME_CMP (ld_canon_sysroot, realname) == 0)
     99    result = TRUE;
     100  else
     101    result = FALSE;
     102
     103  if (realname)
     104    free (realname);
     105
     106  return result;
     107}
     108
     109/* Adds NAME to the library search path.
     110   Makes a copy of NAME using xmalloc().  */
    75111
    76112void
    77113ldfile_add_library_path (name, cmdline)
    78114     const char *name;
    79      boolean cmdline;
     115     bfd_boolean cmdline;
    80116{
    81117  search_dirs_type *new;
     118
     119  if (!cmdline && config.only_cmd_line_lib_dirs)
     120    return;
    82121
    83122  new = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
    84123  new->next = NULL;
    85   new->name = name;
    86124  new->cmdline = cmdline;
    87125  *search_tail_ptr = new;
    88126  search_tail_ptr = &new->next;
     127
     128  /* If a directory is marked as honoring sysroot, prepend the sysroot path
     129     now.  */
     130  if (name[0] == '=')
     131    {
     132      new->name = concat (ld_sysroot, name + 1, NULL);
     133      new->sysrooted = TRUE;
     134    }
     135  else
     136    {
     137      new->name = xstrdup (name);
     138      new->sysrooted = is_sysrooted_pathname (name, FALSE);
     139    }
    89140}
    90141
    91142/* Try to open a BFD for a lang_input_statement.  */
    92143
    93 boolean
     144bfd_boolean
    94145ldfile_try_open_bfd (attempt, entry)
    95146     const char *attempt;
     
    110161      if (bfd_get_error () == bfd_error_invalid_target)
    111162        einfo (_("%F%P: invalid BFD target `%s'\n"), entry->target);
    112       return false;
     163      return FALSE;
    113164    }
    114165
     
    130181        {
    131182          if (! bfd_check_format (check, bfd_object))
    132             return true;
    133           if (bfd_arch_get_compatible (check, output_bfd) == NULL)
     183            {
     184              if (check == entry->the_bfd
     185                  && bfd_get_error () == bfd_error_file_not_recognized
     186                  && ! ldemul_unrecognized_file (entry))
     187                {
     188                  int token, skip = 0;
     189                  char *arg, *arg1, *arg2, *arg3;
     190                  extern FILE *yyin;
     191
     192                  /* Try to interpret the file as a linker script.  */
     193                  ldfile_open_command_file (attempt);
     194
     195                  ldfile_assumed_script = TRUE;
     196                  parser_input = input_selected;
     197                  ldlex_both ();
     198                  token = INPUT_SCRIPT;
     199                  while (token != 0)
     200                    {
     201                      switch (token)
     202                        {
     203                        case OUTPUT_FORMAT:
     204                          if ((token = yylex ()) != '(')
     205                            continue;
     206                          if ((token = yylex ()) != NAME)
     207                            continue;
     208                          arg1 = yylval.name;
     209                          arg2 = NULL;
     210                          arg3 = NULL;
     211                          token = yylex ();
     212                          if (token == ',')
     213                            {
     214                              if ((token = yylex ()) != NAME)
     215                                {
     216                                  free (arg1);
     217                                  continue;
     218                                }
     219                              arg2 = yylval.name;
     220                              if ((token = yylex ()) != ','
     221                                  || (token = yylex ()) != NAME)
     222                                {
     223                                  free (arg1);
     224                                  free (arg2);
     225                                  continue;
     226                                }
     227                              arg3 = yylval.name;
     228                              token = yylex ();
     229                            }
     230                          if (token == ')')
     231                            {
     232                              switch (command_line.endian)
     233                                {
     234                                default:
     235                                case ENDIAN_UNSET:
     236                                  arg = arg1; break;
     237                                case ENDIAN_BIG:
     238                                  arg = arg2 ? arg2 : arg1; break;
     239                                case ENDIAN_LITTLE:
     240                                  arg = arg3 ? arg3 : arg1; break;
     241                                }
     242                              if (strcmp (arg, lang_get_output_target ()) != 0)
     243                                skip = 1;
     244                            }
     245                          free (arg1);
     246                          if (arg2) free (arg2);
     247                          if (arg3) free (arg3);
     248                          break;
     249                        case NAME:
     250                        case LNAME:
     251                        case VERS_IDENTIFIER:
     252                        case VERS_TAG:
     253                          free (yylval.name);
     254                          break;
     255                        case INT:
     256                          if (yylval.bigint.str)
     257                            free (yylval.bigint.str);
     258                          break;
     259                        }
     260                      token = yylex ();
     261                    }
     262                  ldlex_popstate ();
     263                  ldfile_assumed_script = FALSE;
     264                  fclose (yyin);
     265                  yyin = NULL;
     266                  if (skip)
     267                    {
     268                      einfo (_("%P: skipping incompatible %s when searching for %s\n"),
     269                             attempt, entry->local_sym_name);
     270                      bfd_close (entry->the_bfd);
     271                      entry->the_bfd = NULL;
     272                      return FALSE;
     273                    }
     274                }
     275              return TRUE;
     276            }
     277
     278          if ((bfd_arch_get_compatible (check, output_bfd,
     279                                        command_line.accept_unknown_input_arch) == NULL)
     280              /* XCOFF archives can have 32 and 64 bit objects.  */
     281              && ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour
     282                    && bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour
     283                    && bfd_check_format (entry->the_bfd, bfd_archive)))
    134284            {
    135285              einfo (_("%P: skipping incompatible %s when searching for %s\n"),
     
    137287              bfd_close (entry->the_bfd);
    138288              entry->the_bfd = NULL;
    139               return false;
     289              return FALSE;
    140290            }
    141291        }
    142292    }
    143293
    144   return true;
     294  return TRUE;
    145295}
    146296
     
    148298   archive, use ARCH, LIB and SUFFIX to modify the file name.  */
    149299
    150 boolean
     300bfd_boolean
    151301ldfile_open_file_search (arch, entry, lib, suffix)
    152302     const char *arch;
     
    161311  if (! entry->is_archive)
    162312    {
    163       if (ldfile_try_open_bfd (entry->filename, entry))
    164         return true;
     313      if (entry->sysrooted && IS_ABSOLUTE_PATH (entry->filename))
     314        {
     315          char *name = concat (ld_sysroot, entry->filename,
     316                               (const char *) NULL);
     317          if (ldfile_try_open_bfd (name, entry))
     318            {
     319              entry->filename = name;
     320              return TRUE;
     321            }
     322          free (name);
     323        }
     324      else if (ldfile_try_open_bfd (entry->filename, entry))
     325        {
     326          entry->sysrooted = IS_ABSOLUTE_PATH (entry->filename)
     327            && is_sysrooted_pathname (entry->filename, TRUE);
     328          return TRUE;
     329        }
     330
     331      if (IS_ABSOLUTE_PATH (entry->filename))
     332        return FALSE;
    165333    }
    166334
     
    174342        {
    175343          if (ldemul_open_dynamic_archive (arch, search, entry))
    176             return true;
     344            {
     345              entry->sysrooted = search->sysrooted;
     346              return TRUE;
     347            }
    177348        }
    178349
     
    188359        sprintf (string, "%s%s%s%s%s%s", search->name, slash,
    189360                 lib, entry->filename, arch, suffix);
    190       else if (entry->filename[0] == '/' || entry->filename[0] == '.'
    191 #if defined (__MSDOS__) || defined (_WIN32)
    192                || entry->filename[0] == '\\'
    193                || (isalpha (entry->filename[0])
    194                    && entry->filename[1] == ':')
    195 #endif
    196           )
    197         strcpy (string, entry->filename);
    198361      else
    199362        sprintf (string, "%s%s%s", search->name, slash, entry->filename);
     
    202365        {
    203366          entry->filename = string;
    204           return true;
     367          entry->sysrooted = search->sysrooted;
     368          return TRUE;
    205369        }
    206370
     
    208372    }
    209373
    210   return false;
     374  return FALSE;
    211375}
    212376
     
    233397    {
    234398      search_arch_type *arch;
    235       boolean found = false;
     399      bfd_boolean found = FALSE;
    236400
    237401      /* Try to open <filename><suffix> or lib<filename><suffix>.a */
     
    256420         again.  */
    257421      if (found)
    258         entry->search_dirs_flag = false;
     422        entry->search_dirs_flag = FALSE;
     423      else if (entry->sysrooted
     424               && ld_sysroot
     425               && IS_ABSOLUTE_PATH (entry->local_sym_name))
     426        einfo (_("%F%P: cannot find %s inside %s\n"),
     427               entry->local_sym_name, ld_sysroot);
    259428      else
    260429        einfo (_("%F%P: cannot find %s\n"), entry->local_sym_name);
     
    303472
    304473/* Try to open NAME; if that fails, look for it in any directories
    305    specified with -L, without and with EXTEND apppended.  */
     474   specified with -L, without and with EXTEND appended.  */
    306475
    307476FILE *
     
    351520  ldfile_input_filename = name;
    352521  lineno = 1;
    353   had_script = true;
     522
     523  saved_script_handle = ldlex_input_stack;
    354524}
    355525
     
    414584void
    415585ldfile_add_arch (in_name)
    416      CONST char *in_name;
     586     const char *in_name;
    417587{
    418588  char *name = xstrdup (in_name);
     
    426596  while (*name)
    427597    {
    428       if (isupper ((unsigned char) *name))
    429         *name = tolower ((unsigned char) *name);
     598      *name = TOLOWER (*name);
    430599      name++;
    431600    }
     
    440609void
    441610ldfile_set_output_arch (string)
    442      CONST char *string;
     611     const char *string;
    443612{
    444613  const bfd_arch_info_type *arch = bfd_scan_arch (string);
Note: See TracChangeset for help on using the changeset viewer.