This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: --gc-sections leads to relocation truncated to fit: R_PPC64_REL24 against .opd +$bignum
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Olaf Hering <olh at suse dot de>, binutils at sources dot redhat dot com
- Date: Mon, 6 Jun 2005 22:46:49 +0930
- Subject: Re: --gc-sections leads to relocation truncated to fit: R_PPC64_REL24 against .opd +$bignum
- References: <20050605201519.GA28143@suse.de> <20050606125856.GD2677@bubble.grove.modra.org>
Olaf pointed out that the bfd_alloc can fail. A scan over elf64-ppc.c
reveal another place that needs fixing too.
* elf64-ppc.c (ppc_stub_name): Return immediately on bfd_malloc fail.
(ppc64_elf_edit_opd): Ignore zero size .opd. Check bfd_alloc
return value.
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.209
diff -u -p -r1.209 elf64-ppc.c
--- bfd/elf64-ppc.c 6 Jun 2005 12:59:54 -0000 1.209
+++ bfd/elf64-ppc.c 6 Jun 2005 13:11:09 -0000
@@ -3581,26 +3581,26 @@ ppc_stub_name (const asection *input_sec
{
len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
stub_name = bfd_malloc (len);
- if (stub_name != NULL)
- {
- sprintf (stub_name, "%08x.%s+%x",
- input_section->id & 0xffffffff,
- h->elf.root.root.string,
- (int) rel->r_addend & 0xffffffff);
- }
+ if (stub_name == NULL)
+ return stub_name;
+
+ sprintf (stub_name, "%08x.%s+%x",
+ input_section->id & 0xffffffff,
+ h->elf.root.root.string,
+ (int) rel->r_addend & 0xffffffff);
}
else
{
len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
stub_name = bfd_malloc (len);
- if (stub_name != NULL)
- {
- sprintf (stub_name, "%08x.%x:%x+%x",
- input_section->id & 0xffffffff,
- sym_sec->id & 0xffffffff,
- (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
- (int) rel->r_addend & 0xffffffff);
- }
+ if (stub_name == NULL)
+ return stub_name;
+
+ sprintf (stub_name, "%08x.%x:%x+%x",
+ input_section->id & 0xffffffff,
+ sym_sec->id & 0xffffffff,
+ (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
+ (int) rel->r_addend & 0xffffffff);
}
if (stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
stub_name[len - 2] = 0;
@@ -6176,7 +6176,7 @@ ppc64_elf_edit_opd (bfd *obfd, struct bf
bfd_size_type cnt_16b = 0;
sec = bfd_get_section_by_name (ibfd, ".opd");
- if (sec == NULL)
+ if (sec == NULL || sec->size == 0)
continue;
amt = sec->size * sizeof (long) / 8;
@@ -6186,6 +6186,8 @@ ppc64_elf_edit_opd (bfd *obfd, struct bf
/* check_relocs hasn't been called. Must be a ld -r link
or --just-symbols object. */
opd_adjust = bfd_alloc (obfd, amt);
+ if (opd_adjust == NULL)
+ return FALSE;
ppc64_elf_section_data (sec)->opd.adjust = opd_adjust;
}
memset (opd_adjust, 0, amt);
--
Alan Modra
IBM OzLabs - Linux Technology Centre