This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Patch to ignore invalid symbol section index.
- To: Per Cederqvist <ceder at lysator dot liu dot se>
- Subject: Patch to ignore invalid symbol section index.
- From: "H . J . Lu" <hjl at valinux dot com>
- Date: Tue, 13 Feb 2001 17:08:52 -0800
- Cc: ronis at onsager dot chem dot mcgill dot ca, binutils at sourceware dot cygnus dot com
- References: <x2ae7qkvt1.fsf@lysator.liu.se>
On Wed, Feb 14, 2001 at 12:27:54AM +0100, Per Cederqvist wrote:
> Summary: ld dies with segmentation fault, apparently trying to modify
> bfd_abs_section.
>
> fdct_mmx.o: fdct_mmx.s
> nasm -o fdct_mmx.o -f elf fdct_mmx.s
>
nasm generates bogus symbol table for ELF .o files:
Symbol table '.symtab' contains 8 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 FILE LOCAL DEFAULT ABS mmx_main.asm
2: 00000000 0 SECTION LOCAL DEFAULT ABS
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3: 00000000 0 SECTION LOCAL DEFAULT 1
4: 00000014 0 NOTYPE LOCAL DEFAULT 1 y_loop
5: 00000026 0 NOTYPE LOCAL DEFAULT 1 endconvert
6: 00000000 0 NOTYPE GLOBAL DEFAULT 1 _ConvertMMX
7: 0000001a 0 NOTYPE GLOBAL DEFAULT 1 _mmxreturn
As the result, ld dumps core while trying to modify bfd_abs_section.
Here is a patch.
H.J.
----
2001-02-13 H.J. Lu <hjl@gnu.org>
* elflink.h (elf_link_input_bfd): Ignore invalid symbol section
index.
Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.50
diff -u -p -r1.50 elflink.h
--- elflink.h 2001/02/10 23:40:38 1.50
+++ elflink.h 2001/02/14 01:07:39
@@ -5527,14 +5527,24 @@ elf_link_input_bfd (finfo, input_bfd)
}
}
+ name = NULL;
if (isym->st_shndx == SHN_UNDEF)
- isec = bfd_und_section_ptr;
+ {
+ isec = bfd_und_section_ptr;
+ name = isec->name;
+ }
else if (isym->st_shndx > 0 && isym->st_shndx < SHN_LORESERVE)
isec = section_from_elf_index (input_bfd, isym->st_shndx);
else if (isym->st_shndx == SHN_ABS)
- isec = bfd_abs_section_ptr;
+ {
+ isec = bfd_abs_section_ptr;
+ name = isec->name;
+ }
else if (isym->st_shndx == SHN_COMMON)
- isec = bfd_com_section_ptr;
+ {
+ isec = bfd_com_section_ptr;
+ name = isec->name;
+ }
else
{
/* Who knows? */
@@ -5553,7 +5563,17 @@ elf_link_input_bfd (finfo, input_bfd)
/* Save away all section symbol values. */
if (isec != NULL)
- isec->symbol->value = isym->st_value;
+ {
+ if (name)
+ {
+ (*_bfd_error_handler)
+ (_("%s: invalid symbol section index 0x%x (%s) ingored"),
+ bfd_get_filename (input_bfd), isym->st_shndx,
+ name);
+ continue;
+ }
+ isec->symbol->value = isym->st_value;
+ }
/* If this is a discarded link-once section symbol, update
it's value to that of the kept section symbol. The