summaryrefslogtreecommitdiffstats
path: root/ld/emultempl
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2000-10-16 19:08:45 +0000
committerNick Clifton <nickc@redhat.com>2000-10-16 19:08:45 +0000
commit6e45556a3635f2c407cc5871457ca787e9e2578b (patch)
tree8232bcbf4a1edbdeacf033608343218cdbae3fbe /ld/emultempl
parent710c2d976fc00d688eecef00338a988fb3e981c7 (diff)
downloadppe42-binutils-6e45556a3635f2c407cc5871457ca787e9e2578b.tar.gz
ppe42-binutils-6e45556a3635f2c407cc5871457ca787e9e2578b.zip
Add tests of return values from bfd function calls
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/pe.em87
1 files changed, 59 insertions, 28 deletions
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index bbf0c942e2..62d6959429 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -839,7 +839,8 @@ gld_${EMULATION_NAME}_after_open ()
{
int idata2 = 0, reloc_count=0, is_imp = 0;
asection *sec;
- /* See if this is an import library thunk */
+
+ /* See if this is an import library thunk. */
for (sec = is->the_bfd->sections; sec; sec = sec->next)
{
if (strcmp (sec->name, ".idata\$2") == 0)
@@ -848,53 +849,83 @@ gld_${EMULATION_NAME}_after_open ()
is_imp = 1;
reloc_count += sec->reloc_count;
}
+
if (is_imp && !idata2 && reloc_count)
{
- /* it is, look for the reference to head and see if it's
- from our own library */
+ /* It is, look for the reference to head and see if it's
+ from our own library. */
for (sec = is->the_bfd->sections; sec; sec = sec->next)
{
int i;
- int symsize;
+ long symsize;
+ long relsize;
asymbol **symbols;
- int relsize;
arelent **relocs;
int nrelocs;
symsize = bfd_get_symtab_upper_bound (is->the_bfd);
- symbols = (asymbol **) xmalloc (symsize);
- bfd_canonicalize_symtab (is->the_bfd, symbols);
+ 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)
+ {
+ einfo ("%X%P: unable to process symbols: %E");
+ return;
+ }
+
relocs = (arelent **) xmalloc ((size_t) relsize);
nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
relocs, symbols);
- for (i=0; i<nrelocs; i++)
+ if (nrelocs < 0)
+ {
+ free (relocs);
+ einfo ("%X%P: unable to process relocs: %E");
+ return;
+ }
+
+ for (i = 0; i < nrelocs; i++)
{
struct symbol_cache_entry *s;
+ struct bfd_link_hash_entry * blhe;
+ bfd *other_bfd;
+ char *n;
+
s = (relocs[i]->sym_ptr_ptr)[0];
- if (!s->flags & BSF_LOCAL)
- {
- /* thunk section with reloc to another bfd... */
- struct bfd_link_hash_entry *blhe;
- blhe = bfd_link_hash_lookup (link_info.hash,
- s->name,
- false, false, true);
- if (blhe && blhe->type == bfd_link_hash_defined)
- {
- bfd *other_bfd = blhe->u.def.section->owner;
- if (strcmp (is->the_bfd->my_archive->filename,
- other_bfd->my_archive->filename))
- {
- /* Rename this implib to match the other */
- char *n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
- strcpy (n, other_bfd->my_archive->filename);
- is->the_bfd->my_archive->filename = n;
- }
- }
- }
+
+ if (s->flags & BSF_LOCAL)
+ continue;
+
+ /* Thunk section with reloc to another bfd. */
+ blhe = bfd_link_hash_lookup (link_info.hash,
+ s->name,
+ false, false, true);
+
+ if (blhe == NULL
+ || blhe->type != bfd_link_hash_defined)
+ continue;
+
+ other_bfd = blhe->u.def.section->owner;
+
+ if (strcmp (is->the_bfd->my_archive->filename,
+ other_bfd->my_archive->filename) == 0)
+ continue;
+
+ /* Rename this implib to match the other. */
+ n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
+
+ strcpy (n, other_bfd->my_archive->filename);
+
+ is->the_bfd->my_archive->filename = n;
}
free (relocs);
+ /* Note - we do not free the symbols,
+ they are now cached in the BFD. */
}
}
}
OpenPOWER on IntegriCloud