1991-10-16 20:39:40 +01:00
|
|
|
/* All symbol handling for the linker
|
|
|
|
Copyright (C) 1991 Free Software Foundation, Inc.
|
|
|
|
Written by Steve Chamberlain steve@cygnus.com
|
1993-03-30 19:49:00 +02:00
|
|
|
|
1991-03-21 22:29:06 +01:00
|
|
|
This file is part of GLD, the Gnu Linker.
|
|
|
|
|
1991-10-16 20:39:40 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
1991-03-21 22:29:06 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
1991-10-16 20:39:40 +01:00
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1991-10-16 20:39:40 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
1991-03-21 22:29:06 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
1991-10-16 20:39:40 +01:00
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
/*
|
1991-08-06 23:28:21 +02:00
|
|
|
We keep a hash table of global symbols. Each entry in a hash table
|
|
|
|
is called an ldsym_type. Each has three chains; a pointer to a
|
|
|
|
chain of definitions for the symbol (hopefully one long), a pointer
|
|
|
|
to a chain of references to the symbol, and a pointer to a chain of
|
|
|
|
common symbols. Each pointer points into the canonical symbol table
|
1992-05-06 22:31:01 +02:00
|
|
|
provided by bfd, each one of which points to an asymbol. During
|
1991-08-06 23:28:21 +02:00
|
|
|
linkage, the linker uses the udata field to point to the next entry
|
|
|
|
in a canonical table....
|
|
|
|
|
|
|
|
|
|
|
|
ld_sym
|
|
|
|
| |
|
|
|
|
+----------+ +----------+
|
|
|
|
| defs | a canonical symbol table
|
|
|
|
+----------+ +----------+
|
|
|
|
| refs | -----> | one entry| -----> asymbol
|
|
|
|
+----------+ +----------+ | |
|
|
|
|
| coms | | | +---------+
|
1993-05-03 21:47:38 +02:00
|
|
|
+----------+ +----------+ | udata |-----> another canonical
|
|
|
|
+---------+ symbol
|
1991-08-06 23:28:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It is very simple to make all the symbol pointers point to the same
|
|
|
|
definition - just run down the chain and make the asymbols pointers
|
|
|
|
within the canonical table point to the asymbol attacthed to the
|
|
|
|
definition of the symbol.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1991-03-21 22:29:06 +01:00
|
|
|
#include "bfd.h"
|
1991-10-11 12:28:27 +01:00
|
|
|
#include "sysdep.h"
|
1991-03-21 22:29:06 +01:00
|
|
|
|
|
|
|
#include "ld.h"
|
|
|
|
#include "ldsym.h"
|
|
|
|
#include "ldmisc.h"
|
|
|
|
#include "ldlang.h"
|
|
|
|
/* IMPORT */
|
1992-10-29 01:21:36 +01:00
|
|
|
extern int symbol_truncate;
|
1991-03-21 22:29:06 +01:00
|
|
|
extern bfd *output_bfd;
|
1991-04-17 04:03:34 +02:00
|
|
|
extern strip_symbols_type strip_symbols;
|
|
|
|
extern discard_locals_type discard_locals;
|
1991-03-21 22:29:06 +01:00
|
|
|
/* Head and tail of global symbol table chronological list */
|
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
ldsym_type *symbol_head = (ldsym_type *) NULL;
|
1991-03-21 22:29:06 +01:00
|
|
|
ldsym_type **symbol_tail_ptr = &symbol_head;
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
CONST char *keepsyms_file;
|
|
|
|
int kept_syms;
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1992-01-24 23:36:06 +01:00
|
|
|
extern ld_config_type config;
|
|
|
|
|
1992-05-05 01:38:42 +02:00
|
|
|
struct obstack global_sym_obstack;
|
|
|
|
#define obstack_chunk_alloc ldmalloc
|
|
|
|
#define obstack_chunk_free free
|
|
|
|
|
1991-03-21 22:29:06 +01:00
|
|
|
/*
|
|
|
|
incremented for each symbol in the ldsym_type table
|
1993-03-30 19:49:00 +02:00
|
|
|
no matter what flavour it is
|
1991-03-21 22:29:06 +01:00
|
|
|
*/
|
|
|
|
unsigned int global_symbol_count;
|
|
|
|
|
|
|
|
/* IMPORTS */
|
|
|
|
|
|
|
|
/* LOCALS */
|
|
|
|
#define TABSIZE 1009
|
|
|
|
static ldsym_type *global_symbol_hash_table[TABSIZE];
|
|
|
|
|
|
|
|
/* Compute the hash code for symbol name KEY. */
|
1993-03-30 19:49:00 +02:00
|
|
|
static
|
1991-08-06 23:28:21 +02:00
|
|
|
#ifdef __GNUC__
|
1993-03-30 19:49:00 +02:00
|
|
|
__inline
|
1991-08-06 23:28:21 +02:00
|
|
|
#endif
|
1991-11-12 05:26:12 +01:00
|
|
|
|
1991-03-21 22:29:06 +01:00
|
|
|
int
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
hash_string (key)
|
|
|
|
CONST char *key;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
1991-08-06 23:28:21 +02:00
|
|
|
register CONST char *cp;
|
1991-03-21 22:29:06 +01:00
|
|
|
register int k;
|
1992-10-29 01:21:36 +01:00
|
|
|
register int l = 0;
|
1991-03-21 22:29:06 +01:00
|
|
|
cp = key;
|
|
|
|
k = 0;
|
1993-03-30 19:49:00 +02:00
|
|
|
while (*cp && l < symbol_truncate)
|
|
|
|
{
|
|
|
|
k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff;
|
|
|
|
l++;
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
1991-08-06 23:28:21 +02:00
|
|
|
static
|
|
|
|
#ifdef __GNUC__
|
1993-03-30 19:49:00 +02:00
|
|
|
__inline
|
1993-02-09 16:56:11 +01:00
|
|
|
#endif
|
1993-03-30 19:49:00 +02:00
|
|
|
ldsym_type *
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
search (key, hashval)
|
|
|
|
CONST char *key;
|
|
|
|
int hashval;
|
1991-08-06 23:28:21 +02:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
ldsym_type *bp;
|
1991-08-06 23:28:21 +02:00
|
|
|
for (bp = global_symbol_hash_table[hashval]; bp; bp = bp->link)
|
1993-03-30 19:49:00 +02:00
|
|
|
if (!strncmp (key, bp->name, symbol_truncate))
|
|
|
|
{
|
|
|
|
if (bp->flags & SYM_INDIRECT)
|
|
|
|
{
|
|
|
|
/* Use the symbol we're aliased to instead */
|
|
|
|
return (ldsym_type *) (bp->sdefs_chain);
|
|
|
|
}
|
|
|
|
return bp;
|
1991-08-06 23:28:21 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1991-03-21 22:29:06 +01:00
|
|
|
/* Get the symbol table entry for the global symbol named KEY.
|
|
|
|
Create one if there is none. */
|
|
|
|
ldsym_type *
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
ldsym_get (key)
|
|
|
|
CONST char *key;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
|
|
|
register int hashval;
|
|
|
|
register ldsym_type *bp;
|
|
|
|
|
|
|
|
/* Determine the proper bucket. */
|
|
|
|
|
|
|
|
hashval = hash_string (key) % TABSIZE;
|
|
|
|
|
|
|
|
/* Search the bucket. */
|
1993-03-30 19:49:00 +02:00
|
|
|
bp = search (key, hashval);
|
|
|
|
if (bp)
|
|
|
|
{
|
|
|
|
return bp;
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
|
|
|
|
/* Nothing was found; create a new symbol table entry. */
|
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
bp = (ldsym_type *) obstack_alloc (&global_sym_obstack, (bfd_size_type) (sizeof (ldsym_type)));
|
|
|
|
bp->srefs_chain = (asymbol **) NULL;
|
|
|
|
bp->sdefs_chain = (asymbol **) NULL;
|
|
|
|
bp->scoms_chain = (asymbol **) NULL;
|
|
|
|
bp->name = obstack_copy (&global_sym_obstack, key, strlen (key) + 1);
|
1991-08-02 01:29:23 +02:00
|
|
|
bp->flags = 0;
|
1991-03-21 22:29:06 +01:00
|
|
|
/* Add the entry to the bucket. */
|
|
|
|
|
|
|
|
bp->link = global_symbol_hash_table[hashval];
|
|
|
|
global_symbol_hash_table[hashval] = bp;
|
|
|
|
|
|
|
|
/* Keep the chronological list up to date too */
|
|
|
|
*symbol_tail_ptr = bp;
|
|
|
|
symbol_tail_ptr = &bp->next;
|
|
|
|
bp->next = 0;
|
|
|
|
global_symbol_count++;
|
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Like `ldsym_get' but return 0 if the symbol is not already known. */
|
|
|
|
|
|
|
|
ldsym_type *
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
ldsym_get_soft (key)
|
|
|
|
CONST char *key;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
|
|
|
register int hashval;
|
|
|
|
/* Determine which bucket. */
|
|
|
|
|
|
|
|
hashval = hash_string (key) % TABSIZE;
|
|
|
|
|
|
|
|
/* Search the bucket. */
|
1993-03-30 19:49:00 +02:00
|
|
|
return search (key, hashval);
|
1991-03-21 22:29:06 +01:00
|
|
|
}
|
|
|
|
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
static asymbol **
|
|
|
|
process_keepsyms (table, size)
|
1993-03-30 19:49:00 +02:00
|
|
|
asymbol **table;
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
int size;
|
|
|
|
{
|
|
|
|
struct obstack obstack;
|
|
|
|
char *start_of_obstack;
|
|
|
|
FILE *ks_file = 0;
|
|
|
|
asymbol **out = table;
|
|
|
|
asymbol **end = table + size;
|
|
|
|
asymbol **sym;
|
|
|
|
|
|
|
|
if (!keepsyms_file || size == 0)
|
|
|
|
return end;
|
|
|
|
obstack_init (&obstack);
|
|
|
|
obstack_alloc (&obstack, 1);
|
|
|
|
obstack_finish (&obstack);
|
|
|
|
start_of_obstack = obstack_alloc (&obstack, 1);
|
|
|
|
ks_file = fopen (keepsyms_file, "r");
|
|
|
|
if (!ks_file)
|
|
|
|
{
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg ("%X%P: cannot open keep-symbols file `%s'\n", keepsyms_file);
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
goto egress;
|
|
|
|
}
|
|
|
|
errno = 0;
|
1991-03-21 22:29:06 +01:00
|
|
|
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
#define KEEP(S) \
|
1993-02-26 00:47:21 +01:00
|
|
|
do { asymbol **p = (S), *tmp = *out; *out = *p; *p = tmp; out++; } while (0)
|
1991-03-21 22:29:06 +01:00
|
|
|
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
while (!feof (ks_file) && !ferror (ks_file))
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *ptr;
|
|
|
|
int found = 0;
|
1991-03-21 22:29:06 +01:00
|
|
|
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
obstack_free (&obstack, start_of_obstack);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = getc (ks_file);
|
|
|
|
if (c == '\n')
|
|
|
|
c = 0;
|
|
|
|
obstack_1grow (&obstack, c);
|
|
|
|
}
|
|
|
|
while (c > 0);
|
|
|
|
if (c == EOF)
|
|
|
|
{
|
|
|
|
if (!feof (ks_file))
|
|
|
|
/* error occurred */
|
|
|
|
{
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg ("%X%P: error reading keep-symbols file `%s': %E\n",
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
keepsyms_file);
|
|
|
|
out = end;
|
|
|
|
goto egress;
|
|
|
|
}
|
|
|
|
if (obstack_next_free (&obstack) != obstack_base (&obstack) + 1)
|
|
|
|
/* eof in middle of symbol */
|
|
|
|
{
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg ("%X%P: eof reached mid-line while reading keep-symbols file `%s'\n",
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
keepsyms_file);
|
|
|
|
out = end;
|
|
|
|
goto egress;
|
|
|
|
}
|
|
|
|
/* All okay -- no incomplete lines, EOF reached. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr = obstack_next_free (&obstack) - 2;
|
|
|
|
/* discard trailing trash */
|
|
|
|
while (*ptr == ' '
|
|
|
|
|| *ptr == '\t')
|
|
|
|
*ptr-- = 0;
|
|
|
|
ptr = obstack_base (&obstack);
|
|
|
|
for (sym = out; sym < end; sym++)
|
1992-10-29 01:21:36 +01:00
|
|
|
if (!strncmp ((*sym)->name, ptr, symbol_truncate))
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
{
|
|
|
|
KEEP (sym);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
if (!found)
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg ("%P: symbol `%s' (requested to be kept) not found\n", ptr);
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
}
|
|
|
|
/* It'd be slightly faster to move this pass above the previous one,
|
|
|
|
but that'd mean any symbols preserved in this pass would generate
|
|
|
|
warnings if they were also listed in the keepsyms file. */
|
|
|
|
for (sym = out; sym < end; sym++)
|
|
|
|
{
|
|
|
|
asymbol *s = *sym;
|
|
|
|
if (s->section == &bfd_und_section
|
1993-01-26 20:56:17 +01:00
|
|
|
|| bfd_is_com_section (s->section)
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
|| s->flags & BSF_KEEP_G)
|
|
|
|
KEEP (sym);
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
egress:
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
obstack_free (&obstack, start_of_obstack);
|
|
|
|
if (ks_file)
|
|
|
|
fclose (ks_file);
|
|
|
|
return out;
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
list_file_locals (entry)
|
1993-03-30 19:49:00 +02:00
|
|
|
lang_input_statement_type *entry;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
|
|
|
asymbol **q;
|
1992-01-24 23:36:06 +01:00
|
|
|
fprintf (config.map_file, "\nLocal symbols of ");
|
1993-03-30 19:49:00 +02:00
|
|
|
minfo ("%I", entry);
|
1992-01-24 23:36:06 +01:00
|
|
|
fprintf (config.map_file, ":\n\n");
|
1993-03-30 19:49:00 +02:00
|
|
|
if (entry->asymbols)
|
|
|
|
{
|
|
|
|
for (q = entry->asymbols; *q; q++)
|
|
|
|
{
|
|
|
|
asymbol *p = *q;
|
|
|
|
/* If this is a definition,
|
1991-03-21 22:29:06 +01:00
|
|
|
update it if necessary by this file's start address. */
|
1993-03-30 19:49:00 +02:00
|
|
|
if (p->flags & BSF_LOCAL)
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg (" %V %s\n", p->value, p->name);
|
1993-03-30 19:49:00 +02:00
|
|
|
}
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
print_file_stuff (f)
|
|
|
|
lang_input_statement_type * f;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
fprintf (config.map_file, " %s\n", f->filename);
|
|
|
|
if (f->just_syms_flag)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " symbols only\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asection *s;
|
1993-07-15 23:43:28 +02:00
|
|
|
if (true)
|
1992-05-05 01:38:42 +02:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
for (s = f->the_bfd->sections;
|
|
|
|
s != (asection *) NULL;
|
|
|
|
s = s->next)
|
|
|
|
{
|
|
|
|
print_address (s->output_offset);
|
|
|
|
if (s->reloc_done)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " %08x 2**%2ud %s\n",
|
|
|
|
(unsigned) bfd_get_section_size_after_reloc (s),
|
|
|
|
s->alignment_power, s->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " %08x 2**%2ud %s\n",
|
|
|
|
(unsigned) bfd_get_section_size_before_reloc (s),
|
|
|
|
s->alignment_power, s->name);
|
|
|
|
}
|
|
|
|
}
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
else
|
1992-05-05 01:38:42 +02:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
for (s = f->the_bfd->sections;
|
|
|
|
s != (asection *) NULL;
|
|
|
|
s = s->next)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, "%s ", s->name);
|
|
|
|
print_address (s->output_offset);
|
|
|
|
fprintf (config.map_file, "(%x)", (unsigned) bfd_get_section_size_after_reloc (s));
|
|
|
|
}
|
|
|
|
fprintf (config.map_file, "hex \n");
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
1992-01-24 23:36:06 +01:00
|
|
|
fprintf (config.map_file, "\n");
|
1991-03-21 22:29:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldsym_print_symbol_table ()
|
|
|
|
{
|
1992-01-24 23:36:06 +01:00
|
|
|
fprintf (config.map_file, "**FILES**\n\n");
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
lang_for_each_file (print_file_stuff);
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
fprintf (config.map_file, "**GLOBAL SYMBOLS**\n\n");
|
|
|
|
fprintf (config.map_file, "offset section offset symbol\n");
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
|
|
|
register ldsym_type *sp;
|
|
|
|
|
|
|
|
for (sp = symbol_head; sp; sp = sp->next)
|
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
if (sp->flags & SYM_INDIRECT)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, "indirect %s to %s\n",
|
|
|
|
sp->name, (((ldsym_type *) (sp->sdefs_chain))->name));
|
1991-11-06 02:21:19 +01:00
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sp->sdefs_chain)
|
|
|
|
{
|
|
|
|
asymbol *defsym = *(sp->sdefs_chain);
|
|
|
|
asection *defsec = bfd_get_section (defsym);
|
|
|
|
print_address (defsym->value);
|
|
|
|
if (defsec)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " %-10s",
|
|
|
|
bfd_section_name (output_bfd,
|
|
|
|
defsec));
|
|
|
|
print_space ();
|
|
|
|
print_address (defsym->value + defsec->vma);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " .......");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sp->scoms_chain)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, "common ");
|
|
|
|
print_address ((*(sp->scoms_chain))->value);
|
|
|
|
fprintf (config.map_file, " %s ", sp->name);
|
|
|
|
}
|
|
|
|
else if (sp->sdefs_chain)
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, " %s ", sp->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (config.map_file, "undefined ");
|
|
|
|
fprintf (config.map_file, "%s ", sp->name);
|
|
|
|
|
|
|
|
}
|
1991-11-06 02:21:19 +01:00
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
print_nl ();
|
1991-03-21 22:29:06 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern lang_output_section_statement_type *create_object_symbols;
|
|
|
|
extern char lprefix;
|
|
|
|
static asymbol **
|
1993-03-30 19:49:00 +02:00
|
|
|
write_file_locals (output_buffer)
|
|
|
|
asymbol **output_buffer;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
LANG_FOR_EACH_INPUT_STATEMENT (entry)
|
1992-05-05 01:38:42 +02:00
|
|
|
{
|
|
|
|
/* Run trough the symbols and work out what to do with them */
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Add one for the filename symbol if needed */
|
1993-03-30 19:49:00 +02:00
|
|
|
if (create_object_symbols
|
|
|
|
!= (lang_output_section_statement_type *) NULL)
|
|
|
|
{
|
|
|
|
asection *s;
|
|
|
|
for (s = entry->the_bfd->sections;
|
|
|
|
s != (asection *) NULL;
|
|
|
|
s = s->next)
|
|
|
|
{
|
|
|
|
if (s->output_section == create_object_symbols->bfd_section)
|
|
|
|
{
|
|
|
|
/* Add symbol to this section */
|
|
|
|
asymbol *newsym =
|
|
|
|
(asymbol *) bfd_make_empty_symbol (entry->the_bfd);
|
|
|
|
newsym->name = entry->local_sym_name;
|
|
|
|
/* The symbol belongs to the output file's text section */
|
|
|
|
|
|
|
|
/* The value is the start of this section in the output file*/
|
|
|
|
newsym->value = 0;
|
|
|
|
/* FIXME: Usurping BSF_KEEP_G flag, since it's defined as
|
1993-08-06 22:13:28 +02:00
|
|
|
"used by the linker" and I can't find any other code that
|
|
|
|
uses it. Should be a cleaner way of doing this (like an
|
|
|
|
"application flags" field in the symbol structure?). */
|
1993-10-25 17:35:23 +01:00
|
|
|
newsym->flags = BSF_LOCAL | BSF_KEEP_G | BSF_FILE;
|
1993-03-30 19:49:00 +02:00
|
|
|
newsym->section = s;
|
|
|
|
*output_buffer++ = newsym;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
for (i = 0; i < entry->symbol_count; i++)
|
1992-05-05 01:38:42 +02:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
asymbol *p = entry->asymbols[i];
|
|
|
|
/* FIXME, temporary hack, since not all of ld knows about the new abs section convention */
|
|
|
|
|
|
|
|
if (p->section == 0)
|
|
|
|
p->section = &bfd_abs_section;
|
1993-10-29 20:02:26 +01:00
|
|
|
if ((p->flags & BSF_GLOBAL)
|
|
|
|
|| (p->flags & BSF_WEAK))
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
1993-09-18 00:11:00 +02:00
|
|
|
/* If this symbol is marked as occurring now, rather than
|
|
|
|
at the end, output it now. This is used for COFF C_EXT
|
|
|
|
FCN symbols. FIXME: There must be a better way. */
|
1993-03-30 19:49:00 +02:00
|
|
|
if (bfd_asymbol_bfd (p) == entry->the_bfd
|
1993-10-29 20:02:26 +01:00
|
|
|
&& (p->flags & BSF_NOT_AT_END))
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
|
|
|
*(output_buffer++) = p;
|
|
|
|
p->flags |= BSF_KEEP;
|
|
|
|
}
|
1992-08-21 03:43:49 +02:00
|
|
|
}
|
1992-05-05 01:38:42 +02:00
|
|
|
else
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
|
|
|
if (p->section == &bfd_ind_section)
|
|
|
|
{
|
|
|
|
/* Dont think about indirect symbols */
|
|
|
|
}
|
1993-10-29 20:02:26 +01:00
|
|
|
else if (p->flags & BSF_DEBUGGING)
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
|
|
|
/* Only keep the debugger symbols if no stripping required */
|
|
|
|
if (strip_symbols == STRIP_NONE)
|
|
|
|
{
|
|
|
|
*output_buffer++ = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (p->section == &bfd_und_section
|
|
|
|
|| bfd_is_com_section (p->section))
|
|
|
|
{
|
|
|
|
/* These must be global. */
|
|
|
|
}
|
1993-10-29 20:02:26 +01:00
|
|
|
else if (p->flags & BSF_LOCAL)
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
|
|
|
if (discard_locals == DISCARD_ALL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (discard_locals == DISCARD_L &&
|
|
|
|
(p->name[0] == lprefix))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (p->flags == BSF_WARNING)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*output_buffer++ = p;
|
|
|
|
}
|
|
|
|
}
|
1993-06-02 00:44:42 +02:00
|
|
|
else if (p->flags & BSF_CONSTRUCTOR)
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
1993-06-02 00:44:42 +02:00
|
|
|
if (strip_symbols != STRIP_ALL)
|
|
|
|
{
|
|
|
|
*output_buffer++ = p;
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FAIL ();
|
|
|
|
}
|
|
|
|
}
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
|
|
|
|
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
return output_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static asymbol **
|
1993-03-30 19:49:00 +02:00
|
|
|
write_file_globals (symbol_table)
|
|
|
|
asymbol **symbol_table;
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
FOR_EACH_LDSYM (sp)
|
|
|
|
{
|
|
|
|
if (sp->flags & SYM_INDIRECT)
|
|
|
|
{
|
|
|
|
asymbol *bufp = (*(sp->srefs_chain));
|
|
|
|
ldsym_type *aliased_to = (ldsym_type *) (sp->sdefs_chain);
|
|
|
|
if (aliased_to->sdefs_chain)
|
|
|
|
{
|
|
|
|
asymbol *p = aliased_to->sdefs_chain[0];
|
|
|
|
bufp->value = p->value;
|
|
|
|
bufp->section = p->section;
|
|
|
|
bufp->flags = p->flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufp->value = 0;
|
|
|
|
bufp->flags = 0;
|
|
|
|
bufp->section = &bfd_und_section;
|
|
|
|
}
|
|
|
|
*symbol_table++ = bufp;
|
|
|
|
}
|
|
|
|
else if ((sp->flags & SYM_INDIRECT) == 0 && sp->sdefs_chain != (asymbol **) NULL)
|
|
|
|
{
|
1991-03-21 22:29:06 +01:00
|
|
|
asymbol *bufp = (*(sp->sdefs_chain));
|
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
if ((bufp->flags & BSF_KEEP) == 0)
|
|
|
|
{
|
|
|
|
ASSERT (bufp != (asymbol *) NULL);
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
bufp->name = sp->name;
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
if (sp->scoms_chain != (asymbol **) NULL)
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
{
|
|
|
|
/*
|
1991-03-21 22:29:06 +01:00
|
|
|
defined as common but not allocated, this happens
|
|
|
|
only with -r and not -d, write out a common
|
|
|
|
definition
|
|
|
|
*/
|
1993-03-30 19:49:00 +02:00
|
|
|
bufp = *(sp->scoms_chain);
|
|
|
|
}
|
|
|
|
*symbol_table++ = bufp;
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
else if (sp->scoms_chain != (asymbol **) NULL)
|
|
|
|
{
|
1991-03-21 22:29:06 +01:00
|
|
|
/* This symbol is a common - just output */
|
|
|
|
asymbol *bufp = (*(sp->scoms_chain));
|
|
|
|
*symbol_table++ = bufp;
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
else if (sp->srefs_chain != (asymbol **) NULL)
|
|
|
|
{
|
1991-03-21 22:29:06 +01:00
|
|
|
/* This symbol is undefined but has a reference */
|
|
|
|
asymbol *bufp = (*(sp->srefs_chain));
|
|
|
|
*symbol_table++ = bufp;
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
else
|
|
|
|
{
|
1991-03-21 22:29:06 +01:00
|
|
|
/*
|
|
|
|
This symbol has neither defs nor refs, it must have come
|
|
|
|
from the command line, since noone has used it it has no
|
1993-03-30 19:49:00 +02:00
|
|
|
data attatched, so we'll ignore it
|
1991-03-21 22:29:06 +01:00
|
|
|
*/
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
return symbol_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1993-03-30 19:49:00 +02:00
|
|
|
ldsym_write ()
|
1991-03-21 22:29:06 +01:00
|
|
|
{
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
if (keepsyms_file != 0
|
|
|
|
&& strip_symbols != STRIP_SOME)
|
|
|
|
{
|
1993-09-28 21:51:22 +01:00
|
|
|
info_msg ("%P: `-retain-symbols-file' overrides `-s' and `-S'\n");
|
* Makefile.in (ldexp.o, ldctor.o, ldlang.o, ldmain.o, ldwrite.o, lexsup.o,
mri.o, relax.o): Indicate dependence on ldgram.h.
* ld.h (strip_symbols_type): Add value STRIP_SOME.
* ldgram.y (OPTION_RETAIN_SYMBOLS_FILE): New terminal token.
(lang_add_keepsyms_file): New function.
* ldlex.l: Handle "-retain-symbols-file".
* ldsym.c (keepsyms_file, kept_syms): New vars.
(process_keepsyms): New functihon; reads file, marks symbols for saving.
(write_file_locals): File symbols should always be kept.
(ldsym_write): Warn about "-retain-symbols-file" overriding "-S" and "-s".
Process retain-symbols file before setting symtab.
* ldsym.h (SYM_KEEP): New flag for ldsym_type flags.
(keepsyms_file, kept_syms): Declare them.
* ldmain.c (main): Non-fatal errors should still cause non-zero exit status
even with -r.
1992-09-25 23:05:20 +02:00
|
|
|
strip_symbols = STRIP_SOME;
|
|
|
|
}
|
1993-03-30 19:49:00 +02:00
|
|
|
if (strip_symbols != STRIP_ALL)
|
|
|
|
{
|
|
|
|
/* We know the maximum size of the symbol table -
|
1991-03-21 22:29:06 +01:00
|
|
|
it's the size of all the global symbols ever seen +
|
|
|
|
the size of all the symbols from all the files +
|
|
|
|
the number of files (for the per file symbols)
|
|
|
|
+1 (for the null at the end)
|
|
|
|
*/
|
1993-03-30 19:49:00 +02:00
|
|
|
extern unsigned int total_files_seen;
|
|
|
|
extern unsigned int total_symbols_seen;
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
asymbol **symbol_table = (asymbol **)
|
|
|
|
ldmalloc ((bfd_size_type) (global_symbol_count +
|
|
|
|
total_files_seen +
|
|
|
|
total_symbols_seen + 1) * sizeof (asymbol *));
|
|
|
|
asymbol **tablep = write_file_locals (symbol_table);
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
tablep = write_file_globals (tablep);
|
|
|
|
tablep = process_keepsyms (symbol_table, tablep - symbol_table);
|
1991-03-21 22:29:06 +01:00
|
|
|
|
1993-03-30 19:49:00 +02:00
|
|
|
*tablep = (asymbol *) NULL;
|
|
|
|
bfd_set_symtab (output_bfd, symbol_table, (unsigned) (tablep - symbol_table));
|
|
|
|
}
|
1991-03-21 22:29:06 +01:00
|
|
|
}
|
1991-03-27 03:29:23 +01:00
|
|
|
|
|
|
|
/*
|
1993-03-30 19:49:00 +02:00
|
|
|
return true if the supplied symbol name is not in the
|
1991-03-27 03:29:23 +01:00
|
|
|
linker symbol table
|
|
|
|
*/
|
1993-03-30 19:49:00 +02:00
|
|
|
boolean
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
ldsym_undefined (sym)
|
|
|
|
CONST char *sym;
|
1991-03-27 03:29:23 +01:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
ldsym_type *from_table = ldsym_get_soft (sym);
|
|
|
|
if (from_table != (ldsym_type *) NULL)
|
|
|
|
{
|
|
|
|
if (from_table->sdefs_chain != (asymbol **) NULL)
|
|
|
|
return false;
|
|
|
|
}
|
1991-03-27 03:29:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
1992-05-05 01:38:42 +02:00
|
|
|
|
|
|
|
void
|
* ldfile.c (ldfile_open_command): Don't try .ld extension.
It wasn't documented (or likely used) and wastes time.
(try_open): If EXTEN is empty, don't try it.
* ldctor.c, lderror.c, ldexp.c, ldfile.c, ldindr.c, ldlang.c,
ldlex.l, ldmain.c, ldmisc.c, ldsym.c, ldver.c, ldwarn.c,
ldwrite.c, lexsup.c, mri.c, relax.c: Replace DEFUN macro calls
with normal function declarations.
* Move *.em to emultempl/*.em. Move *.sh to emulparams/*.sh.
Move *.sc-sh to scripttempl/*.sc.
* {emultempl,emulparams,scripttempl}/README: New files.
* sh.em, st2000.em, z8ksim.em, h8300hms.em, h8500hms.em: Files
removed, replaced with generic.em.
* h8300.sh, h8500.sh, h8300.sc, h8500.sc: Renamed from
h8[35]00hms.s[ch]. Change their contents to omit the "hms".
* *.em (*_get_script): Return script name instead of script contents.
* ldlang.c (lang_process): Change caller.
* ldlex.l, ldgram.y: Recognize -m option.
Check for input files after *all* options in grammar.
* ldmain.c (main): Check for -m options. Add default directory
for -m.
* mkscript.c: File removed.
* genscripts.sh: Take two more parameters, tooldirlib and libdir,
to add to the default LIB_PATH.
Look for input files in the new subdirectories.
Create the scripts in emulations subdirectory and don't filter
them through mkscript.
* configure.in: Make the emulations subdirectory.
* Makefile.in: Account for all of the above changes.
Remove unused .SUFFIXES. Get libgcc.a path with gcc
-print-libgcc-file-name instead of $(libdir)/libgcc.a.
Put CFLAGS last in the compilation rules.
Add -I../bfd to INCLUDES so sysdep.h is found.
* ldfile.c (try_open): If opening without the extension fails,
try with the extension even if -v or -V was given.
had_script is imported (from ldgram.y), not exported.
1993-06-17 22:55:43 +02:00
|
|
|
ldsym_init ()
|
1992-05-05 01:38:42 +02:00
|
|
|
{
|
1993-03-30 19:49:00 +02:00
|
|
|
obstack_begin (&global_sym_obstack, 20000);
|
1992-05-05 01:38:42 +02:00
|
|
|
}
|