source cleanups; fix finding scripts

This commit is contained in:
David MacKenzie 1993-07-15 21:43:28 +00:00
parent a5ef437e7f
commit bbd2521f26
5 changed files with 85 additions and 65 deletions

View File

@ -1,3 +1,24 @@
Thu Jul 15 12:44:35 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* ldfile.c (ldfile_open_file): In error message, use the name the
user gave (e.g., "-lc"), rather than the base file name.
* ldexp.c (exp_fold_tree): Don't assign an int to an enum.
* ldmain.[ch]: Remove initial Q_ from function names.
* ldexp.c, ldindr.c, ldlang.c: Change callers.
* ldfile.c, ldmain.c, ldgram.y: Rename option_v to trace_file_tries.
* ldlang.c (lang_process): Move loading of default script from
here to main. Add a "/" to start of script name to prevent
finding it in "." first.
* ldmain.c (set_scripts_dir): Don't look in "." first.
* ldgram.y, ldlang.c, ldsym.c: Remove traces of unused var
option_longmap.
Thu Jul 15 10:55:59 1993 Ian Lance Taylor (ian@cygnus.com) Thu Jul 15 10:55:59 1993 Ian Lance Taylor (ian@cygnus.com)
* Makefile.in (em_m88kbcs.c): Correct dependency. * Makefile.in (em_m88kbcs.c): Correct dependency.

View File

@ -40,7 +40,7 @@ enum bfd_architecture ldfile_output_architecture;
/* IMPORT */ /* IMPORT */
extern boolean had_script; extern boolean had_script;
extern boolean option_v; extern boolean trace_file_tries;
#ifdef VMS #ifdef VMS
@ -92,7 +92,7 @@ char *attempt;
lang_input_statement_type *entry; lang_input_statement_type *entry;
{ {
entry->the_bfd = bfd_openr(attempt, entry->target); entry->the_bfd = bfd_openr(attempt, entry->target);
if (option_v == true ) { if (trace_file_tries == true ) {
info("attempt to open %s %s\n", attempt, info("attempt to open %s %s\n", attempt,
(entry->the_bfd == (bfd *)NULL) ? "failed" : "succeeded" ); (entry->the_bfd == (bfd *)NULL) ? "failed" : "succeeded" );
} }
@ -174,14 +174,13 @@ lang_input_statement_type *entry;
} }
} }
else { else {
entry->the_bfd = cached_bfd_openr (entry->filename, entry); entry->the_bfd = cached_bfd_openr (entry->filename, entry);
} }
if (!entry->the_bfd) einfo("%F%P: Can't open %s, %E\n", entry->filename);
if (!entry->the_bfd)
einfo("%F%P: cannot open %s: %E\n", entry->local_sym_name);
} }
@ -196,7 +195,7 @@ char *exten;
char buff[1000]; char buff[1000];
result = fopen(name, "r"); result = fopen(name, "r");
if (option_v == true) { if (trace_file_tries == true) {
if (result == (FILE *)NULL) { if (result == (FILE *)NULL) {
info("can't find "); info("can't find ");
} }
@ -209,7 +208,7 @@ char *exten;
if (*exten) { if (*exten) {
sprintf(buff, "%s%s", name, exten); sprintf(buff, "%s%s", name, exten);
result = fopen(buff, "r"); result = fopen(buff, "r");
if (option_v == true) { if (trace_file_tries == true) {
if (result == (FILE *)NULL) { if (result == (FILE *)NULL) {
info("can't find "); info("can't find ");
} }
@ -254,7 +253,7 @@ char *name;
ldlex_input_stack = find_a_name(name, ""); ldlex_input_stack = find_a_name(name, "");
if (ldlex_input_stack == (FILE *)NULL) { if (ldlex_input_stack == (FILE *)NULL) {
einfo("%P%F cannot open load script file %s, %E\n",name); einfo("%P%F: cannot open load script file %s: %E\n",name);
} }
lex_push_file(ldlex_input_stack, name); lex_push_file(ldlex_input_stack, name);

View File

@ -38,11 +38,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define YYDEBUG 1 #define YYDEBUG 1
boolean option_v;
extern unsigned int lineno; extern unsigned int lineno;
extern boolean trace_file_tries;
extern boolean trace_files; extern boolean trace_files;
extern boolean write_map; extern boolean write_map;
extern boolean option_longmap;
extern int g_switch_value; extern int g_switch_value;
boolean hex_mode; boolean hex_mode;
static int typebits; static int typebits;
@ -192,7 +191,7 @@ command_line_option:
| OPTION_V | OPTION_V
{ {
ldversion(1); ldversion(1);
option_v = true; trace_file_tries = true;
} }
| OPTION_version | OPTION_version
{ {

View File

@ -49,7 +49,9 @@ static void set_scripts_dir ();
/* IMPORTS */ /* IMPORTS */
extern boolean lang_has_input_file; extern boolean lang_has_input_file;
extern boolean trace_files; extern boolean force_make_executable;
extern boolean relaxing;
extern boolean had_script;
/* EXPORTS */ /* EXPORTS */
@ -62,8 +64,6 @@ char *program_name;
/* The file that we're creating */ /* The file that we're creating */
bfd *output_bfd = 0; bfd *output_bfd = 0;
extern boolean option_v;
/* set if -y on the command line */ /* set if -y on the command line */
int had_y; int had_y;
@ -93,28 +93,20 @@ unsigned int commons_pending;
unsigned int undefined_global_sym_count; unsigned int undefined_global_sym_count;
/* Count the number of warning symbols encountered. */
int warning_count;
/* have we had a load script ? */
extern boolean had_script;
/* Nonzero means print names of input files as processed. */ /* Nonzero means print names of input files as processed. */
boolean trace_files; boolean trace_files;
/* Nonzero means same, but note open failures, too. */
boolean trace_file_tries;
/* 1 => write load map. */ /* 1 => write load map. */
boolean write_map; boolean write_map;
#ifdef GNU960 #ifdef GNU960
/* Indicates whether output file will be b.out (default) or coff */ /* Indicates whether output file will be b.out (default) or coff */
enum target_flavour output_flavor = BFD_BOUT_FORMAT; enum target_flavour output_flavor = BFD_BOUT_FORMAT;
#endif #endif
/* Force the make_executable to be output, even if there are non-fatal
errors */
boolean force_make_executable;
/* A count of the total number of local symbols ever seen - by adding /* A count of the total number of local symbols ever seen - by adding
the symbol_count field of each newly read afile.*/ the symbol_count field of each newly read afile.*/
@ -143,7 +135,7 @@ main (argc, argv)
/* Initialize the data about options. */ /* Initialize the data about options. */
trace_files = false; trace_files = trace_file_tries = false;
write_map = false; write_map = false;
config.relocateable_output = false; config.relocateable_output = false;
command_line.force_common_definition = false; command_line.force_common_definition = false;
@ -160,7 +152,6 @@ main (argc, argv)
/* Initialize the cumulative counts of symbols. */ /* Initialize the cumulative counts of symbols. */
undefined_global_sym_count = 0; undefined_global_sym_count = 0;
warning_count = 0;
multiple_def_count = 0; multiple_def_count = 0;
commons_pending = 0; commons_pending = 0;
@ -176,21 +167,35 @@ main (argc, argv)
lang_has_input_file = false; lang_has_input_file = false;
parse_args (argc, argv); parse_args (argc, argv);
if (had_script == false)
{
/* Read the emulation's appropriate default script. */
char *scriptname = ldemul_get_script ();
/* sizeof counts the terminating NUL. */
size_t size = strlen (scriptname) + sizeof ("-T /ldscripts/");
char *buf = (char *) ldmalloc(size);
/* The initial slash prevents finding the script in `.' first. */
sprintf (buf, "-T /ldscripts/%s", scriptname);
parse_line (buf, 0);
free (buf);
}
if (config.relocateable_output && command_line.relax) if (config.relocateable_output && command_line.relax)
{ {
einfo ("%P%F: -relax and -r may not be used together\n"); einfo ("%P%F: -relax and -r may not be used together\n");
} }
lang_final (); lang_final ();
if (trace_files)
{
info ("%P: mode %s\n", emulation);
}
if (lang_has_input_file == false) if (lang_has_input_file == false)
{ {
einfo ("%P%F: No input files\n"); einfo ("%P%F: No input files\n");
} }
if (trace_files)
{
info ("%P: mode %s\n", emulation);
}
ldemul_after_parse (); ldemul_after_parse ();
@ -205,7 +210,7 @@ main (argc, argv)
config.map_file = fopen (config.map_filename, FOPEN_WT); config.map_file = fopen (config.map_filename, FOPEN_WT);
if (config.map_file == (FILE *) NULL) if (config.map_file == (FILE *) NULL)
{ {
einfo ("%P%F: can't open map file %s, %E\n", einfo ("%P%F: cannot open map file %s: %E\n",
config.map_filename); config.map_filename);
} }
} }
@ -348,10 +353,9 @@ check_for_scripts_dir (dir)
Libraries will be searched for here too, but that's ok. Libraries will be searched for here too, but that's ok.
We look for the "ldscripts" directory in: We look for the "ldscripts" directory in:
the curent dir
SCRIPTDIR (passed from Makefile) SCRIPTDIR (passed from Makefile)
the dir where this program is the dir where this program is (for using it from the build tree)
the dir where this program is/../lib */ the dir where this program is/../lib (for installing the tool suite elsewhere) */
static void static void
set_scripts_dir () set_scripts_dir ()
@ -359,22 +363,27 @@ set_scripts_dir ()
char *end, *dir; char *end, *dir;
size_t dirlen; size_t dirlen;
if (check_for_scripts_dir ("."))
return; /* Newest version, most likely. */
if (check_for_scripts_dir (SCRIPTDIR)) if (check_for_scripts_dir (SCRIPTDIR))
return; /* We've been installed normally. */ return; /* We've been installed normally. */
/* Look for "ldscripts" in the dir where our binary is. */ /* Look for "ldscripts" in the dir where our binary is. */
end = strrchr (program_name, '/'); end = strrchr (program_name, '/');
if (!end) if (end)
return; {
dirlen = end - program_name;
/* Make a copy of program_name in dir.
Leave room for later "/../lib". */
dir = (char *) ldmalloc (dirlen + 8);
strncpy (dir, program_name, dirlen);
dir[dirlen] = '\0';
}
else
{
dirlen = 1;
dir = (char *) ldmalloc (dirlen + 8);
strcpy (dir, ".");
}
/* Make a copy of program_name in dir. */
dirlen = end - program_name;
dir = (char *) ldmalloc (dirlen + 8); /* Leave room for later "/../lib". */
strncpy (dir, program_name, dirlen);
dir[dirlen] = '\0';
if (check_for_scripts_dir (dir)) if (check_for_scripts_dir (dir))
return; /* Don't free dir. */ return; /* Don't free dir. */
@ -387,7 +396,7 @@ set_scripts_dir ()
} }
void void
Q_read_entry_symbols (desc, entry) read_entry_symbols (desc, entry)
bfd *desc; bfd *desc;
struct lang_input_statement_struct *entry; struct lang_input_statement_struct *entry;
{ {
@ -440,10 +449,8 @@ Whilst all this is going on we keep a count of the number of multiple
definitions seen, undefined global symbols and pending commons. definitions seen, undefined global symbols and pending commons.
*/ */
extern boolean relaxing;
void void
Q_enter_global_ref (nlist_p, name) enter_global_ref (nlist_p, name)
asymbol ** nlist_p; /* pointer into symbol table from incoming bfd */ asymbol ** nlist_p; /* pointer into symbol table from incoming bfd */
CONST char *name; /* name of symbol in linker table */ CONST char *name; /* name of symbol in linker table */
{ {
@ -602,7 +609,7 @@ Q_enter_global_ref (nlist_p, name)
} }
static void static void
Q_enter_file_symbols (entry) enter_file_symbols (entry)
lang_input_statement_type *entry; lang_input_statement_type *entry;
{ {
asymbol **q; asymbol **q;
@ -613,7 +620,7 @@ Q_enter_file_symbols (entry)
ldlang_add_file (entry); ldlang_add_file (entry);
if (trace_files || option_v) if (trace_files || trace_file_tries)
{ {
info ("%I\n", entry); info ("%I\n", entry);
} }
@ -669,7 +676,7 @@ Q_enter_file_symbols (entry)
|| bfd_is_com_section (p->section) || bfd_is_com_section (p->section)
|| (p->flags & BSF_CONSTRUCTOR)) || (p->flags & BSF_CONSTRUCTOR))
{ {
Q_enter_global_ref (q, p->name); enter_global_ref (q, p->name);
} }
} }
@ -746,13 +753,13 @@ ldmain_open_file_read_symbol (entry)
entry->the_bfd->usrdata = (PTR) entry; entry->the_bfd->usrdata = (PTR) entry;
Q_read_entry_symbols (entry->the_bfd, entry); read_entry_symbols (entry->the_bfd, entry);
/* look through the sections in the file and see if any of them /* look through the sections in the file and see if any of them
are constructors */ are constructors */
ldlang_check_for_constructors (entry); ldlang_check_for_constructors (entry);
Q_enter_file_symbols (entry); enter_file_symbols (entry);
} }
#ifdef GNU960 #ifdef GNU960
else if (gnu960_check_format (entry->the_bfd, bfd_archive)) else if (gnu960_check_format (entry->the_bfd, bfd_archive))
@ -920,7 +927,7 @@ symdef_library (entry)
if (archive_member_lang_input_statement_struct->loaded == false) if (archive_member_lang_input_statement_struct->loaded == false)
{ {
Q_read_entry_symbols (archive_member_bfd, archive_member_lang_input_statement_struct); read_entry_symbols (archive_member_bfd, archive_member_lang_input_statement_struct);
/* Now scan the symbol table and decide whether to load. */ /* Now scan the symbol table and decide whether to load. */
@ -933,7 +940,7 @@ symdef_library (entry)
not_finished = true; not_finished = true;
Q_enter_file_symbols (archive_member_lang_input_statement_struct); enter_file_symbols (archive_member_lang_input_statement_struct);
if (prev) if (prev)
prev->chain = archive_member_lang_input_statement_struct; prev->chain = archive_member_lang_input_statement_struct;
@ -1008,11 +1015,11 @@ linear_library (entry)
return; return;
if (subentry->loaded == false) if (subentry->loaded == false)
{ {
Q_read_entry_symbols (archive, subentry); read_entry_symbols (archive, subentry);
if (subfile_wanted_p (subentry) == true) if (subfile_wanted_p (subentry) == true)
{ {
Q_enter_file_symbols (subentry); enter_file_symbols (subentry);
if (prev) if (prev)
prev->chain = subentry; prev->chain = subentry;

View File

@ -82,8 +82,6 @@ unsigned int global_symbol_count;
/* IMPORTS */ /* IMPORTS */
extern boolean option_longmap;
/* LOCALS */ /* LOCALS */
#define TABSIZE 1009 #define TABSIZE 1009
static ldsym_type *global_symbol_hash_table[TABSIZE]; static ldsym_type *global_symbol_hash_table[TABSIZE];
@ -324,7 +322,7 @@ print_file_stuff (f)
else else
{ {
asection *s; asection *s;
if (true || option_longmap) if (true)
{ {
for (s = f->the_bfd->sections; for (s = f->the_bfd->sections;
s != (asection *) NULL; s != (asection *) NULL;
@ -426,10 +424,6 @@ ldsym_print_symbol_table ()
} }
} }
if (option_longmap)
{
lang_for_each_file (list_file_locals);
}
} }
extern lang_output_section_statement_type *create_object_symbols; extern lang_output_section_statement_type *create_object_symbols;