[ARM] LD / BFD segfault with local, absolute symbol
Thomas Schwinge
thomas@codesourcery.com
Thu Sep 30 09:11:00 GMT 2010
Hello!
When processing an object file that contains a local, absolute symbol
with LD / BFD, there's a segfault:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000451e9f in elf32_arm_size_stubs (output_bfd=0x7329c0, stub_bfd=0x747320, info=0x71ed60, group_size=1,
add_stub_section=0x422c65 <elf32_arm_add_stub_section>, layout_sections_again=0x422d42 <gldarm_layout_sections_again>) at ../../HEAD/src/bfd/elf32-arm.c:4505
4505 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
(gdb) list
4500 if (local_syms == NULL)
4501 goto error_ret_free_internal;
4502 }
4503
4504 sym = local_syms + r_indx;
4505 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4506 sym_sec = hdr->bfd_section;
4507 if (!sym_sec)
4508 /* This is an undefined symbol. It can never
4509 be resolved. */
(gdb) bt
#0 0x0000000000451e9f in elf32_arm_size_stubs (output_bfd=0x7329c0, stub_bfd=0x747320, info=0x71ed60, group_size=1,
add_stub_section=0x422c65 <elf32_arm_add_stub_section>, layout_sections_again=0x422d42 <gldarm_layout_sections_again>) at ../../HEAD/src/bfd/elf32-arm.c:4505
#1 0x00000000004230ec in gldarmelf_after_allocation () at earmelf.c:426
#2 0x000000000041e87f in ldemul_after_allocation () at ../../HEAD/src/ld/ldemul.c:72
#3 0x0000000000415bcc in lang_process () at ../../HEAD/src/ld/ldlang.c:6427
#4 0x0000000000419837 in main (argc=4, argv=0x7fffffffdc28) at ../../HEAD/src/ld/ldmain.c:457
(gdb) print *sym
$1 = {st_value = 2147483672, st_size = 0, st_name = 4, st_info = 0 '\000', st_other = 0 '\000', st_shndx = 4294967281}
(gdb) print /x sym->st_value
$2 = 0x80000018
(gdb) print /x sym->st_shndx
$3 = 0xfffffff1
The latter one is surely an invalid array index -- it is SHN_ABS. Fixed
with this patch; this boilerplate code is used in a bunch of other files,
too. OK to apply?
bfd/
2010-09-30 Thomas Schwinge <thomas@codesourcery.com>
* elf32-arm.c (elf32_arm_size_stubs): Don't choke on local symbols in
SHN_UNDEF, SHN_ABS, SHN_COMMON.
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.242
diff -u -p -U4 -r1.242 elf32-arm.c
--- bfd/elf32-arm.c 24 Sep 2010 12:14:23 -0000 1.242
+++ bfd/elf32-arm.c 30 Sep 2010 09:06:16 -0000
@@ -4485,9 +4485,8 @@ elf32_arm_size_stubs (bfd *output_bfd,
if (r_indx < symtab_hdr->sh_info)
{
/* It's a local symbol. */
Elf_Internal_Sym *sym;
- Elf_Internal_Shdr *hdr;
if (local_syms == NULL)
{
local_syms
@@ -4501,10 +4500,18 @@ elf32_arm_size_stubs (bfd *output_bfd,
goto error_ret_free_internal;
}
sym = local_syms + r_indx;
- hdr = elf_elfsections (input_bfd)[sym->st_shndx];
- sym_sec = hdr->bfd_section;
+ if (sym->st_shndx == SHN_UNDEF)
+ sym_sec = bfd_und_section_ptr;
+ else if (sym->st_shndx == SHN_ABS)
+ sym_sec = bfd_abs_section_ptr;
+ else if (sym->st_shndx == SHN_COMMON)
+ sym_sec = bfd_com_section_ptr;
+ else
+ sym_sec =
+ bfd_section_from_elf_index (input_bfd, sym->st_shndx);
+
if (!sym_sec)
/* This is an undefined symbol. It can never
be resolved. */
continue;
Regards,
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20100930/2561f1a5/attachment.sig>
More information about the Binutils
mailing list