aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2008-08-17 03:12:50 +0000
committerAlan Modra <amodra@gmail.com>2008-08-17 03:12:50 +0000
commit5c1d2f5f4c7747c36eae8be3abd4ef4e9669690c (patch)
tree3be4145ee7086fe0315ad0ce506626b5ca560759 /ld
parent1f5064de53c27d99fb92efd65a6785e2f1ec0835 (diff)
downloadgdb-5c1d2f5f4c7747c36eae8be3abd4ef4e9669690c.zip
gdb-5c1d2f5f4c7747c36eae8be3abd4ef4e9669690c.tar.gz
gdb-5c1d2f5f4c7747c36eae8be3abd4ef4e9669690c.tar.bz2
bfd/
* 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.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog19
-rw-r--r--ld/emultempl/pe.em42
-rw-r--r--ld/emultempl/pep.em25
-rw-r--r--ld/ldcref.c61
-rw-r--r--ld/ldlang.c2
-rw-r--r--ld/ldlang.h7
-rw-r--r--ld/ldmain.c44
-rw-r--r--ld/ldmisc.c39
-rw-r--r--ld/pe-dll.c38
9 files changed, 99 insertions, 178 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0e718a8..213b5f0 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,22 @@
+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
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 08cfcfc..865cfaa 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -922,7 +922,7 @@ pe_find_data_imports (void)
{
bfd *b = sym->u.def.section->owner;
asymbol **symbols;
- int nsyms, symsize, i;
+ int nsyms, i;
if (link_info.pei386_auto_import == -1)
{
@@ -940,9 +940,14 @@ This should work unless it involves constant data structures referencing symbols
}
}
- 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++)
{
@@ -1094,26 +1099,22 @@ gld_${EMULATION_NAME}_after_open (void)
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,
@@ -1309,16 +1310,20 @@ gld_${EMULATION_NAME}_after_open (void)
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)
{
@@ -1335,7 +1340,6 @@ gld_${EMULATION_NAME}_after_open (void)
stub_sec->flags |= SEC_EXCLUDE;
}
}
- free (symbols);
}
}
}
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 2fae386..21bcf01 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -881,7 +881,7 @@ pep_find_data_imports (void)
{
bfd *b = sym->u.def.section->owner;
asymbol **symbols;
- int nsyms, symsize, i;
+ int nsyms, i;
if (link_info.pei386_auto_import == -1)
{
@@ -899,9 +899,14 @@ This should work unless it involves constant data structures referencing symbols
}
}
- 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++)
{
@@ -1032,26 +1037,22 @@ gld_${EMULATION_NAME}_after_open (void)
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,
diff --git a/ld/ldcref.c b/ld/ldcref.c
index 890b61c..3fcaafe 100644
--- a/ld/ldcref.c
+++ b/ld/ldcref.c
@@ -478,36 +478,16 @@ static void
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))
@@ -529,9 +509,6 @@ check_local_sym_xref (lang_input_statement_type *statement)
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. */
@@ -597,8 +574,6 @@ check_refs (const char *name,
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
@@ -607,37 +582,15 @@ check_refs (const char *name,
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
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 2f5c213..e991646 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1033,10 +1033,8 @@ new_afile (const char *name,
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;
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 6de4267..4846197 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -232,12 +232,6 @@ typedef struct lang_input_statement_struct
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;
@@ -247,7 +241,6 @@ typedef struct lang_input_statement_struct
const char *target;
- unsigned int closed : 1;
unsigned int is_archive : 1;
/* 1 means search a set of directories for this file. */
diff --git a/ld/ldmain.c b/ld/ldmain.c
index bf3c0e6..7060587 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -778,21 +778,10 @@ add_archive_element (struct bfd_link_info *info,
{
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);
@@ -1107,45 +1096,22 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
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;
diff --git a/ld/ldmisc.c b/ld/ldmisc.c
index bdae82e..d49cf17 100644
--- a/ld/ldmisc.c
+++ b/ld/ldmisc.c
@@ -269,8 +269,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
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;
@@ -280,35 +279,12 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
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
@@ -375,9 +351,6 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
else
lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
- if (asymbols != NULL && entry == NULL)
- free (asymbols);
-
if (discard_last)
{
last_bfd = NULL;
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index c6c656a..ea84999 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -615,11 +615,16 @@ process_def_file (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
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++)
{
@@ -1141,11 +1146,16 @@ pe_walk_relocs_of_symbol (struct bfd_link_info *info,
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)
{
@@ -1215,7 +1225,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
{
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))
@@ -1235,10 +1245,14 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
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);