This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Avoid ld segfaults on nasm objects


Hi!

For
pm_entry: equ 0x100000
        section .text
        call pm_entry - 0x08000
nasm -f elf creates
Symbol table '.symtab' contains 5 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS /tmp/x.asm
     2: 00000000     0 SECTION LOCAL  DEFAULT  ABS
     3: 00000000     0 SECTION LOCAL  DEFAULT    1
     4: 00100000     0 NOTYPE  LOCAL  DEFAULT  ABS pm_entry

(note SHN_ABS STT_SECTION symbol).  I believe that this is wrong,
but probably ld shouldn't crash on it.

BTW: I'm not sure what exactly is ld doing when number of sections
is bigger than 65536, particularly I don't see anything that would
remap internal symbol's st_shndx SHN_LORESERVE..SHN_HIRESERVE range
to something above any other sections (say 0xffffff00+) but
many places iterate over elf_elfsections array from the beginning
to elf_numsections and not even checking if elf_elfsections (abfd)[i]
is not NULL nor skipping i >= SHN_LORESERVE and i <= SHN_HIRESERVE
range.  If there is supposed to be a gap, several places need adjusting
and the skipping of the gap below is needed, otherwise just
isym->st_shndx < elf_numsections (abfd) would be enough.

2004-12-09  Jakub Jelinek  <jakub@redhat.com>

	* elf.c (bfd_elf_local_sym_name): Avoid crashes with invalid
	st_shndx on STT_SECTION sections.

--- bfd/elf.c.jj	2004-12-09 14:20:13.000000000 +0100
+++ bfd/elf.c	2004-12-09 14:56:29.301561039 +0100
@@ -409,7 +409,10 @@ bfd_elf_local_sym_name (bfd *abfd, Elf_I
 {
   unsigned int iname = isym->st_name;
   unsigned int shindex = elf_tdata (abfd)->symtab_hdr.sh_link;
-  if (iname == 0 && ELF_ST_TYPE (isym->st_info) == STT_SECTION)
+  if (iname == 0 && ELF_ST_TYPE (isym->st_info) == STT_SECTION
+      /* Check for a bogus st_shndx to avoid crashing.  */
+      && isym->st_shndx < elf_numsections (abfd)
+      && !(isym->st_shndx >= SHN_LORESERVE && isym->st_shndx <= SHN_HIRESERVE))
     {
       iname = elf_elfsections (abfd)[isym->st_shndx]->sh_name;
       shindex = elf_elfheader (abfd)->e_shstrndx;

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]