ldmain.c (ld_canon_sysroot, ld_canon_sysroot_len): Define. (main): Initialize them.
ldfile.c: Include pathnames.h. (is_sysrooted_pathname): New. (ldfile_add_library_path): Use it. (ldfile_open_file_search): Likewise. Use IS_ABSOLUTE_PATH. Don't search_dirs if given an absolute pathname. (ldfile_open_file): Issue error message for sysrooted absolute pathnames.
This commit is contained in:
parent
2cf6873cae
commit
3fe38064ba
6 changed files with 105 additions and 41 deletions
15
ld/ChangeLog
15
ld/ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2003-03-25 Alexandre Oliva <aoliva@redhat.com>
|
||||||
|
|
||||||
|
* ldmain.h (ld_canon_sysroot, ld_canon_sysroot_len): Declare.
|
||||||
|
* ldmain.c (ld_canon_sysroot, ld_canon_sysroot_len): Define.
|
||||||
|
(main): Initialize them.
|
||||||
|
* ldfile.c: Include pathnames.h.
|
||||||
|
(is_sysrooted_pathname): New.
|
||||||
|
(ldfile_add_library_path): Use it.
|
||||||
|
(ldfile_open_file_search): Likewise. Use IS_ABSOLUTE_PATH. Don't
|
||||||
|
search_dirs if given an absolute pathname.
|
||||||
|
(ldfile_open_file): Issue error message for sysrooted
|
||||||
|
absolute pathnames.
|
||||||
|
* Makefile.am: Updated dependencies.
|
||||||
|
* Makefile.in: Rebuild.
|
||||||
|
|
||||||
2003-03-24 Daniel Néri <dne@mayonnaise.net>
|
2003-03-24 Daniel Néri <dne@mayonnaise.net>
|
||||||
|
|
||||||
* ld.texinfo: Rename all occurances of C54X to TIC54X.
|
* ld.texinfo: Rename all occurances of C54X to TIC54X.
|
||||||
|
|
|
@ -1613,7 +1613,7 @@ ldfile.o: ldfile.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
||||||
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
||||||
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
|
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
|
||||||
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
|
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
|
||||||
ldlex.h ldemul.h $(INCDIR)/libiberty.h
|
ldlex.h ldemul.h $(INCDIR)/libiberty.h $(INCDIR)/filenames.h
|
||||||
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
||||||
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
||||||
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
|
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
|
||||||
|
|
|
@ -2313,7 +2313,7 @@ ldfile.o: ldfile.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
||||||
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
||||||
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
|
$(INCDIR)/bfdlink.h $(INCDIR)/safe-ctype.h ld.h $(INCDIR)/bin-bugs.h \
|
||||||
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
|
ldmisc.h ldexp.h ldlang.h ldfile.h ldmain.h ldgram.h \
|
||||||
ldlex.h ldemul.h $(INCDIR)/libiberty.h
|
ldlex.h ldemul.h $(INCDIR)/libiberty.h $(INCDIR)/filenames.h
|
||||||
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
ldlang.o: ldlang.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \
|
||||||
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
$(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/fopen-same.h \
|
||||||
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
|
$(INCDIR)/libiberty.h $(INCDIR)/safe-ctype.h $(INCDIR)/obstack.h \
|
||||||
|
|
109
ld/ldfile.c
109
ld/ldfile.c
|
@ -2,22 +2,22 @@
|
||||||
Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
|
Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GLD, the Gnu Linker.
|
This file is part of GLD, the Gnu Linker.
|
||||||
|
|
||||||
GLD is free software; you can redistribute it and/or modify
|
GLD is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2, or (at your option)
|
the Free Software Foundation; either version 2, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
GLD is distributed in the hope that it will be useful,
|
GLD is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with GLD; see the file COPYING. If not, write to the Free
|
along with GLD; see the file COPYING. If not, write to the Free
|
||||||
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||||
02111-1307, USA. */
|
02111-1307, USA. */
|
||||||
|
|
||||||
/* ldfile.c: look after all the file stuff. */
|
/* ldfile.c: look after all the file stuff. */
|
||||||
|
|
||||||
|
@ -35,42 +35,76 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||||
#include "ldlex.h"
|
#include "ldlex.h"
|
||||||
#include "ldemul.h"
|
#include "ldemul.h"
|
||||||
#include "libiberty.h"
|
#include "libiberty.h"
|
||||||
|
#include "filenames.h"
|
||||||
|
|
||||||
const char *ldfile_input_filename;
|
const char * ldfile_input_filename;
|
||||||
bfd_boolean ldfile_assumed_script = FALSE;
|
bfd_boolean ldfile_assumed_script = FALSE;
|
||||||
const char *ldfile_output_machine_name = "";
|
const char * ldfile_output_machine_name = "";
|
||||||
unsigned long ldfile_output_machine;
|
unsigned long ldfile_output_machine;
|
||||||
enum bfd_architecture ldfile_output_architecture;
|
enum bfd_architecture ldfile_output_architecture;
|
||||||
search_dirs_type *search_head;
|
search_dirs_type * search_head;
|
||||||
|
|
||||||
#ifndef MPW
|
#ifndef MPW
|
||||||
#ifdef VMS
|
#ifdef VMS
|
||||||
char *slash = "";
|
char * slash = "";
|
||||||
#else
|
#else
|
||||||
#if defined (_WIN32) && ! defined (__CYGWIN32__)
|
#if defined (_WIN32) && ! defined (__CYGWIN32__)
|
||||||
char *slash = "\\";
|
char * slash = "\\";
|
||||||
#else
|
#else
|
||||||
char *slash = "/";
|
char * slash = "/";
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else /* MPW */
|
#else /* MPW */
|
||||||
/* The MPW path char is a colon. */
|
/* The MPW path char is a colon. */
|
||||||
char *slash = ":";
|
char * slash = ":";
|
||||||
#endif /* MPW */
|
#endif /* MPW */
|
||||||
|
|
||||||
/* LOCAL */
|
typedef struct search_arch
|
||||||
|
{
|
||||||
static search_dirs_type **search_tail_ptr = &search_head;
|
|
||||||
|
|
||||||
typedef struct search_arch {
|
|
||||||
char *name;
|
char *name;
|
||||||
struct search_arch *next;
|
struct search_arch *next;
|
||||||
} search_arch_type;
|
} search_arch_type;
|
||||||
|
|
||||||
|
static search_dirs_type **search_tail_ptr = &search_head;
|
||||||
static search_arch_type *search_arch_head;
|
static search_arch_type *search_arch_head;
|
||||||
static search_arch_type **search_arch_tail_ptr = &search_arch_head;
|
static search_arch_type **search_arch_tail_ptr = &search_arch_head;
|
||||||
|
|
||||||
static FILE *try_open PARAMS ((const char *name, const char *exten));
|
static FILE *try_open
|
||||||
|
PARAMS ((const char *, const char *));
|
||||||
|
static bfd_boolean is_sysrooted_pathname
|
||||||
|
PARAMS ((const char *, bfd_boolean));
|
||||||
|
|
||||||
|
/* Test whether a pathname, after canonicalization, is the same or a
|
||||||
|
sub-directory of the sysroot directory. */
|
||||||
|
|
||||||
|
static bfd_boolean
|
||||||
|
is_sysrooted_pathname (name, notsame)
|
||||||
|
const char *name;
|
||||||
|
bfd_boolean notsame;
|
||||||
|
{
|
||||||
|
char * realname = ld_canon_sysroot ? lrealpath (name) : NULL;
|
||||||
|
int len;
|
||||||
|
bfd_boolean result;
|
||||||
|
|
||||||
|
if (! realname)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
len = strlen (realname);
|
||||||
|
|
||||||
|
if (((! notsame && len == ld_canon_sysroot_len)
|
||||||
|
|| (len >= ld_canon_sysroot_len
|
||||||
|
&& IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])
|
||||||
|
&& (realname[ld_canon_sysroot_len] = '\0') == '\0'))
|
||||||
|
&& FILENAME_CMP (ld_canon_sysroot, realname) == 0)
|
||||||
|
result = TRUE;
|
||||||
|
else
|
||||||
|
result = FALSE;
|
||||||
|
|
||||||
|
if (realname)
|
||||||
|
free (realname);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ldfile_add_library_path (name, cmdline)
|
ldfile_add_library_path (name, cmdline)
|
||||||
|
@ -97,7 +131,7 @@ ldfile_add_library_path (name, cmdline)
|
||||||
new->sysrooted = TRUE;
|
new->sysrooted = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
new->sysrooted = FALSE;
|
new->sysrooted = is_sysrooted_pathname (new->name, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to open a BFD for a lang_input_statement. */
|
/* Try to open a BFD for a lang_input_statement. */
|
||||||
|
@ -271,7 +305,7 @@ ldfile_open_file_search (arch, entry, lib, suffix)
|
||||||
directory first. */
|
directory first. */
|
||||||
if (! entry->is_archive)
|
if (! entry->is_archive)
|
||||||
{
|
{
|
||||||
if (entry->sysrooted && entry->filename[0] == '/')
|
if (entry->sysrooted && IS_ABSOLUTE_PATH (entry->filename))
|
||||||
{
|
{
|
||||||
char *name = concat (ld_sysroot, entry->filename,
|
char *name = concat (ld_sysroot, entry->filename,
|
||||||
(const char *) NULL);
|
(const char *) NULL);
|
||||||
|
@ -284,9 +318,13 @@ ldfile_open_file_search (arch, entry, lib, suffix)
|
||||||
}
|
}
|
||||||
else if (ldfile_try_open_bfd (entry->filename, entry))
|
else if (ldfile_try_open_bfd (entry->filename, entry))
|
||||||
{
|
{
|
||||||
entry->sysrooted = FALSE;
|
entry->sysrooted = IS_ABSOLUTE_PATH (entry->filename)
|
||||||
|
&& is_sysrooted_pathname (entry->filename, TRUE);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IS_ABSOLUTE_PATH (entry->filename))
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (search = search_head;
|
for (search = search_head;
|
||||||
|
@ -315,14 +353,6 @@ ldfile_open_file_search (arch, entry, lib, suffix)
|
||||||
if (entry->is_archive)
|
if (entry->is_archive)
|
||||||
sprintf (string, "%s%s%s%s%s%s", search->name, slash,
|
sprintf (string, "%s%s%s%s%s%s", search->name, slash,
|
||||||
lib, entry->filename, arch, suffix);
|
lib, entry->filename, arch, suffix);
|
||||||
else if (entry->filename[0] == '/' || entry->filename[0] == '.'
|
|
||||||
#if defined (__MSDOS__) || defined (_WIN32)
|
|
||||||
|| entry->filename[0] == '\\'
|
|
||||||
|| (ISALPHA (entry->filename[0])
|
|
||||||
&& entry->filename[1] == ':')
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
strcpy (string, entry->filename);
|
|
||||||
else
|
else
|
||||||
sprintf (string, "%s%s%s", search->name, slash, entry->filename);
|
sprintf (string, "%s%s%s", search->name, slash, entry->filename);
|
||||||
|
|
||||||
|
@ -385,6 +415,11 @@ ldfile_open_file (entry)
|
||||||
again. */
|
again. */
|
||||||
if (found)
|
if (found)
|
||||||
entry->search_dirs_flag = FALSE;
|
entry->search_dirs_flag = FALSE;
|
||||||
|
else if (entry->sysrooted
|
||||||
|
&& ld_sysroot
|
||||||
|
&& IS_ABSOLUTE_PATH (entry->local_sym_name))
|
||||||
|
einfo (_("%F%P: cannot find %s inside %s\n"),
|
||||||
|
entry->local_sym_name, ld_sysroot);
|
||||||
else
|
else
|
||||||
einfo (_("%F%P: cannot find %s\n"), entry->local_sym_name);
|
einfo (_("%F%P: cannot find %s\n"), entry->local_sym_name);
|
||||||
}
|
}
|
||||||
|
|
12
ld/ldmain.c
12
ld/ldmain.c
|
@ -72,6 +72,10 @@ char *program_name;
|
||||||
/* The prefix for system library directories. */
|
/* The prefix for system library directories. */
|
||||||
char *ld_sysroot;
|
char *ld_sysroot;
|
||||||
|
|
||||||
|
/* The canonical representation of ld_sysroot. */
|
||||||
|
char * ld_canon_sysroot;
|
||||||
|
int ld_canon_sysroot_len;
|
||||||
|
|
||||||
/* The file that we're creating. */
|
/* The file that we're creating. */
|
||||||
bfd *output_bfd = 0;
|
bfd *output_bfd = 0;
|
||||||
|
|
||||||
|
@ -234,6 +238,14 @@ main (argc, argv)
|
||||||
#endif
|
#endif
|
||||||
ld_sysroot = TARGET_SYSTEM_ROOT;
|
ld_sysroot = TARGET_SYSTEM_ROOT;
|
||||||
|
|
||||||
|
if (ld_sysroot && *ld_sysroot)
|
||||||
|
ld_canon_sysroot = lrealpath (ld_sysroot);
|
||||||
|
|
||||||
|
if (ld_canon_sysroot)
|
||||||
|
ld_canon_sysroot_len = strlen (ld_canon_sysroot);
|
||||||
|
else
|
||||||
|
ld_canon_sysroot_len = -1;
|
||||||
|
|
||||||
/* Set the default BFD target based on the configured target. Doing
|
/* Set the default BFD target based on the configured target. Doing
|
||||||
this permits the linker to be configured for a particular target,
|
this permits the linker to be configured for a particular target,
|
||||||
and linked against a shared BFD library which was configured for
|
and linked against a shared BFD library which was configured for
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
extern char *program_name;
|
extern char *program_name;
|
||||||
extern char *ld_sysroot;
|
extern char *ld_sysroot;
|
||||||
|
extern char *ld_canon_sysroot;
|
||||||
|
extern int ld_canon_sysroot_len;
|
||||||
extern bfd *output_bfd;
|
extern bfd *output_bfd;
|
||||||
extern char *default_target;
|
extern char *default_target;
|
||||||
extern bfd_boolean trace_files;
|
extern bfd_boolean trace_files;
|
||||||
|
@ -37,6 +39,6 @@ extern struct bfd_link_info link_info;
|
||||||
|
|
||||||
extern void add_ysym PARAMS ((const char *));
|
extern void add_ysym PARAMS ((const char *));
|
||||||
extern void add_wrap PARAMS ((const char *));
|
extern void add_wrap PARAMS ((const char *));
|
||||||
extern void add_keepsyms_file PARAMS ((const char *filename));
|
extern void add_keepsyms_file PARAMS ((const char *));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue