* bfd.c (struct _bfd): Correct outsymbols comment.
* bfd-in2.h: Regenerate.
* linker.c (bfd_generic_link_read_symbols): Renamed from..
(generic_link_read_symbols): ..this, and made global.
include/
* bfdlink.h (bfd_generic_link_read_symbols): Declare.
ld/
PR 6478
* ldcref.c (check_local_sym_xref): Use bfd_generic_link_read_symbols.
Don't free symbol pointer array.
(check_refs): Likewise.
* ldmain.c (warning_callback): Likewise.
* ldmisc.c (vfinfo): Likewise.
* pe-dll.c (process_def_file): Likewise.
(pe_walk_relocs_of_symbol, generate_reloc): Likewise.
* emultempl/pe.em (pe_find_data_imports): Likewise.
(gld_${EMULATION_NAME}_after_open): Likewise.
* emultempl/pep.em (pep_find_data_imports): Likewise.
(gld_${EMULATION_NAME}_after_open): Likewise.
* ldlang.h (lang_input_statement_type): Delete asymbols, symbol_count,
passive_position, closed.
* ldlang.c (new_afile): Don't set asymbols and symbol_count.
* ldmain.c (add_archive_element): xcalloc lang_input_statement_type.
+2008-08-17 Alan Modra <amodra@bigpond.net.au>
+
+ * bfd.c (struct _bfd): Correct outsymbols comment.
+ * bfd-in2.h: Regenerate.
+ * linker.c (bfd_generic_link_read_symbols): Renamed from..
+ (generic_link_read_symbols): ..this, and made global.
+
2008-08-15 Alan Modra <amodra@bigpond.net.au>
PR 6526
/* Used for input and output. */
unsigned int symcount;
- /* Symbol table for output BFD (with symcount entries). */
+ /* Symbol table for output BFD (with symcount entries).
+ Also used by the linker to cache input BFD symbols. */
struct bfd_symbol **outsymbols;
/* Used for slurped dynamic symbol tables. */
. {* Used for input and output. *}
. unsigned int symcount;
.
-. {* Symbol table for output BFD (with symcount entries). *}
+. {* Symbol table for output BFD (with symcount entries).
+. Also used by the linker to cache input BFD symbols. *}
. struct bfd_symbol **outsymbols;
.
. {* Used for slurped dynamic symbol tables. *}
the hash table pointing to different instances of the symbol
structure. */
-static bfd_boolean
-generic_link_read_symbols (bfd *abfd)
+bfd_boolean
+bfd_generic_link_read_symbols (bfd *abfd)
{
if (bfd_get_outsymbols (abfd) == NULL)
{
bfd_size_type symcount;
struct bfd_symbol **outsyms;
- if (! generic_link_read_symbols (abfd))
+ if (!bfd_generic_link_read_symbols (abfd))
return FALSE;
symcount = _bfd_generic_link_get_symcount (abfd);
outsyms = _bfd_generic_link_get_symbols (abfd);
*pneeded = FALSE;
- if (! generic_link_read_symbols (abfd))
+ if (!bfd_generic_link_read_symbols (abfd))
return FALSE;
pp = _bfd_generic_link_get_symbols (abfd);
asymbol **sym_ptr;
asymbol **sym_end;
- if (! generic_link_read_symbols (input_bfd))
+ if (!bfd_generic_link_read_symbols (input_bfd))
return FALSE;
/* Create a filename symbol if we are supposed to. */
have retrieved them by this point, but we are being called by
a specific linker, presumably because we are linking
different types of object files together. */
- if (! generic_link_read_symbols (input_bfd))
+ if (!bfd_generic_link_read_symbols (input_bfd))
return FALSE;
/* Since we have been called by a specific linker, rather than
+2008-08-17 Alan Modra <amodra@bigpond.net.au>
+
+ * bfdlink.h (bfd_generic_link_read_symbols): Declare.
+
2008-08-08 Anatoly Sokolov <aesok@post.ru>
* elf/avr.h (E_AVR_MACH_AVR25, E_AVR_MACH_AVR31,
extern void bfd_link_repair_undef_list
(struct bfd_link_hash_table *table);
+/* Read symbols and cache symbol pointer array in outsymbols. */
+extern bfd_boolean bfd_generic_link_read_symbols (bfd *);
+
struct bfd_sym_chain
{
struct bfd_sym_chain *next;
+2008-08-17 Alan Modra <amodra@bigpond.net.au>
+
+ PR 6478
+ * ldcref.c (check_local_sym_xref): Use bfd_generic_link_read_symbols.
+ Don't free symbol pointer array.
+ (check_refs): Likewise.
+ * ldmain.c (warning_callback): Likewise.
+ * ldmisc.c (vfinfo): Likewise.
+ * pe-dll.c (process_def_file): Likewise.
+ (pe_walk_relocs_of_symbol, generate_reloc): Likewise.
+ * emultempl/pe.em (pe_find_data_imports): Likewise.
+ (gld_${EMULATION_NAME}_after_open): Likewise.
+ * emultempl/pep.em (pep_find_data_imports): Likewise.
+ (gld_${EMULATION_NAME}_after_open): Likewise.
+ * ldlang.h (lang_input_statement_type): Delete asymbols, symbol_count,
+ passive_position, closed.
+ * ldlang.c (new_afile): Don't set asymbols and symbol_count.
+ * ldmain.c (add_archive_element): xcalloc lang_input_statement_type.
+
2008-08-15 Alan Modra <amodra@bigpond.net.au>
PR 6526
{
bfd *b = sym->u.def.section->owner;
asymbol **symbols;
- int nsyms, symsize, i;
+ int nsyms, i;
if (link_info.pei386_auto_import == -1)
{
}
}
- symsize = bfd_get_symtab_upper_bound (b);
- symbols = (asymbol **) xmalloc (symsize);
- nsyms = bfd_canonicalize_symtab (b, symbols);
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"), b);
+ return;
+ }
+
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
for (i = 0; i < nsyms; i++)
{
for (sec = is->the_bfd->sections; sec; sec = sec->next)
{
int i;
- long symsize;
long relsize;
asymbol **symbols;
arelent **relocs;
int nrelocs;
- symsize = bfd_get_symtab_upper_bound (is->the_bfd);
- if (symsize < 1)
- break;
relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
if (relsize < 1)
break;
- symbols = (asymbol **) xmalloc (symsize);
- symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
- if (symsize < 0)
+ if (!bfd_generic_link_read_symbols (is->the_bfd))
{
- einfo ("%X%P: unable to process symbols: %E");
+ einfo (_("%B%F: could not read symbols: %E\n"),
+ is->the_bfd);
return;
}
+ symbols = bfd_get_outsymbols (is->the_bfd);
relocs = (arelent **) xmalloc ((size_t) relsize);
nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
if (is_imp && stub_sec)
{
- long symsize;
asymbol **symbols;
- long src_count;
+ long nsyms, src_count;
struct bfd_link_hash_entry * blhe;
- symsize = bfd_get_symtab_upper_bound (is->the_bfd);
- symbols = xmalloc (symsize);
- symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
+ if (!bfd_generic_link_read_symbols (is->the_bfd))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"),
+ is->the_bfd);
+ return;
+ }
+ symbols = bfd_get_outsymbols (is->the_bfd);
+ nsyms = bfd_get_symcount (is->the_bfd);
- for (src_count = 0; src_count < symsize; src_count++)
+ for (src_count = 0; src_count < nsyms; src_count++)
{
if (symbols[src_count]->section->id == stub_sec->id)
{
stub_sec->flags |= SEC_EXCLUDE;
}
}
- free (symbols);
}
}
}
{
bfd *b = sym->u.def.section->owner;
asymbol **symbols;
- int nsyms, symsize, i;
+ int nsyms, i;
if (link_info.pei386_auto_import == -1)
{
}
}
- symsize = bfd_get_symtab_upper_bound (b);
- symbols = xmalloc (symsize);
- nsyms = bfd_canonicalize_symtab (b, symbols);
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"), b);
+ return;
+ }
+
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
for (i = 0; i < nsyms; i++)
{
for (sec = is->the_bfd->sections; sec; sec = sec->next)
{
int i;
- long symsize;
long relsize;
asymbol **symbols;
arelent **relocs;
int nrelocs;
- symsize = bfd_get_symtab_upper_bound (is->the_bfd);
- if (symsize < 1)
- break;
relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
if (relsize < 1)
break;
- symbols = xmalloc (symsize);
- symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
- if (symsize < 0)
+ if (!bfd_generic_link_read_symbols (is->the_bfd))
{
- einfo ("%X%P: unable to process symbols: %E");
+ einfo (_("%B%F: could not read symbols: %E\n"),
+ is->the_bfd);
return;
}
+ symbols = bfd_get_outsymbols (is->the_bfd);
relocs = xmalloc ((size_t) relsize);
nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
check_local_sym_xref (lang_input_statement_type *statement)
{
bfd *abfd;
- lang_input_statement_type *li;
- asymbol **asymbols, **syms;
+ asymbol **syms;
abfd = statement->the_bfd;
if (abfd == NULL)
return;
- li = abfd->usrdata;
- if (li != NULL && li->asymbols != NULL)
- asymbols = li->asymbols;
- else
- {
- long symsize;
- long symbol_count;
-
- symsize = bfd_get_symtab_upper_bound (abfd);
- if (symsize < 0)
- einfo (_("%B%F: could not read symbols; %E\n"), abfd);
- asymbols = xmalloc (symsize);
- symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
- if (symbol_count < 0)
- einfo (_("%B%F: could not read symbols: %E\n"), abfd);
- if (li != NULL)
- {
- li->asymbols = asymbols;
- li->symbol_count = symbol_count;
- }
- }
+ if (!bfd_generic_link_read_symbols (abfd))
+ einfo (_("%B%F: could not read symbols: %E\n"), abfd);
- for (syms = asymbols; *syms; ++syms)
+ for (syms = bfd_get_outsymbols (abfd); *syms; ++syms)
{
asymbol *sym = *syms;
if (sym->flags & (BSF_GLOBAL | BSF_WARNING | BSF_INDIRECT | BSF_FILE))
check_refs (symname, FALSE, sym->section, abfd, ncrs);
}
}
-
- if (li == NULL)
- free (asymbols);
}
/* Check one symbol to see if it is a prohibited cross reference. */
bfd *abfd,
struct lang_nocrossrefs *ncrs)
{
- lang_input_statement_type *li;
- asymbol **asymbols;
struct check_refs_info info;
/* We need to look through the relocations for this BFD, to see
the BFD in which the symbol is defined, since even a single
BFD might contain a prohibited cross reference. */
- li = abfd->usrdata;
- if (li != NULL && li->asymbols != NULL)
- asymbols = li->asymbols;
- else
- {
- long symsize;
- long symbol_count;
-
- symsize = bfd_get_symtab_upper_bound (abfd);
- if (symsize < 0)
- einfo (_("%B%F: could not read symbols; %E\n"), abfd);
- asymbols = xmalloc (symsize);
- symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
- if (symbol_count < 0)
- einfo (_("%B%F: could not read symbols: %E\n"), abfd);
- if (li != NULL)
- {
- li->asymbols = asymbols;
- li->symbol_count = symbol_count;
- }
- }
+ if (!bfd_generic_link_read_symbols (abfd))
+ einfo (_("%B%F: could not read symbols: %E\n"), abfd);
info.sym_name = name;
info.global = global;
info.defsec = sec;
info.ncrs = ncrs;
- info.asymbols = asymbols;
+ info.asymbols = bfd_get_outsymbols (abfd);
bfd_map_over_sections (abfd, check_reloc_refs, &info);
-
- if (li == NULL)
- free (asymbols);
}
/* This is called via bfd_map_over_sections. INFO->SYM_NAME is a symbol
FAIL ();
}
p->the_bfd = NULL;
- p->asymbols = NULL;
p->next_real_file = NULL;
p->next = NULL;
- p->symbol_count = 0;
p->dynamic = config.dynamic_link;
p->add_needed = add_needed;
p->as_needed = as_needed;
bfd *the_bfd;
- file_ptr passive_position;
-
- /* Symbol table of the file. */
- asymbol **asymbols;
- unsigned int symbol_count;
-
/* Point to the next file - whatever it is, wanders up and down
archives */
union lang_statement_union *next;
const char *target;
- unsigned int closed : 1;
unsigned int is_archive : 1;
/* 1 means search a set of directories for this file. */
{
lang_input_statement_type *input;
- input = xmalloc (sizeof (lang_input_statement_type));
+ input = xcalloc (1, sizeof (lang_input_statement_type));
input->filename = abfd->filename;
input->local_sym_name = abfd->filename;
input->the_bfd = abfd;
- input->asymbols = NULL;
- input->next = NULL;
- input->just_syms_flag = FALSE;
- input->loaded = FALSE;
- input->search_dirs_flag = FALSE;
-
- /* FIXME: The following fields are not set: header.next,
- header.type, closed, passive_position, symbol_count,
- next_real_file, is_archive, target, real. This bit of code is
- from the old decode_library_subfile function. I don't know
- whether any of those fields matters. */
ldlang_add_file (input);
einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
else
{
- lang_input_statement_type *entry;
- asymbol **asymbols;
struct warning_callback_info info;
/* Look through the relocs to see if we can find a plausible
address. */
- entry = (lang_input_statement_type *) abfd->usrdata;
- if (entry != NULL && entry->asymbols != NULL)
- asymbols = entry->asymbols;
- else
- {
- long symsize;
- long symbol_count;
-
- symsize = bfd_get_symtab_upper_bound (abfd);
- if (symsize < 0)
- einfo (_("%B%F: could not read symbols: %E\n"), abfd);
- asymbols = xmalloc (symsize);
- symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
- if (symbol_count < 0)
- einfo (_("%B%F: could not read symbols: %E\n"), abfd);
- if (entry != NULL)
- {
- entry->asymbols = asymbols;
- entry->symbol_count = symbol_count;
- }
- }
+
+ if (!bfd_generic_link_read_symbols (abfd))
+ einfo (_("%B%F: could not read symbols: %E\n"), abfd);
info.found = FALSE;
info.warning = warning;
info.symbol = symbol;
- info.asymbols = asymbols;
+ info.asymbols = bfd_get_outsymbols (abfd);
bfd_map_over_sections (abfd, warning_find_reloc, &info);
if (! info.found)
einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
-
- if (entry == NULL)
- free (asymbols);
}
return TRUE;
bfd *abfd;
asection *section;
bfd_vma offset;
- lang_input_statement_type *entry;
- asymbol **asymbols;
+ asymbol **asymbols = NULL;
const char *filename;
const char *functionname;
unsigned int linenumber;
section = va_arg (arg, asection *);
offset = va_arg (arg, bfd_vma);
- if (abfd == NULL)
- {
- entry = NULL;
- asymbols = NULL;
- }
- else
+ if (abfd != NULL)
{
- entry = (lang_input_statement_type *) abfd->usrdata;
- if (entry != (lang_input_statement_type *) NULL
- && entry->asymbols != (asymbol **) NULL)
- asymbols = entry->asymbols;
- else
- {
- long symsize;
- long sym_count;
-
- symsize = bfd_get_symtab_upper_bound (abfd);
- if (symsize < 0)
- einfo (_("%B%F: could not read symbols\n"), abfd);
- asymbols = xmalloc (symsize);
- sym_count = bfd_canonicalize_symtab (abfd, asymbols);
- if (sym_count < 0)
- einfo (_("%B%F: could not read symbols\n"), abfd);
- if (entry != (lang_input_statement_type *) NULL)
- {
- entry->asymbols = asymbols;
- entry->symbol_count = sym_count;
- }
- }
+ if (!bfd_generic_link_read_symbols (abfd))
+ einfo (_("%B%F: could not read symbols: %E\n"), abfd);
+
+ asymbols = bfd_get_outsymbols (abfd);
}
/* The GNU Coding Standard requires that error messages
else
lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
- if (asymbols != NULL && entry == NULL)
- free (asymbols);
-
if (discard_last)
{
last_bfd = NULL;
for (b = info->input_bfds; b; b = b->link_next)
{
asymbol **symbols;
- int nsyms, symsize;
+ int nsyms;
- symsize = bfd_get_symtab_upper_bound (b);
- symbols = xmalloc (symsize);
- nsyms = bfd_canonicalize_symtab (b, symbols);
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"), b);
+ return;
+ }
+
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
for (j = 0; j < nsyms; j++)
{
for (b = info->input_bfds; b; b = b->link_next)
{
asymbol **symbols;
- int nsyms, symsize;
+ int nsyms;
- symsize = bfd_get_symtab_upper_bound (b);
- symbols = xmalloc (symsize);
- nsyms = bfd_canonicalize_symtab (b, symbols);
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"), b);
+ return;
+ }
+
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
for (s = b->sections; s; s = s->next)
{
{
bfd_vma sec_vma = s->output_section->vma + s->output_offset;
asymbol **symbols;
- int nsyms, symsize;
+ int nsyms;
/* If it's not loaded, we don't need to relocate it this way. */
if (!(s->output_section->flags & SEC_LOAD))
continue;
}
- symsize = bfd_get_symtab_upper_bound (b);
- symbols = xmalloc (symsize);
- nsyms = bfd_canonicalize_symtab (b, symbols);
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%B%F: could not read symbols: %E\n"), b);
+ return;
+ }
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
relsize = bfd_get_reloc_upper_bound (b, s);
relocs = xmalloc (relsize);
nrelocs = bfd_canonicalize_reloc (b, s, relocs, symbols);