public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid ld segfaults on nasm objects
@ 2004-12-09 14:29 Jakub Jelinek
  2004-12-10  4:42 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-12-09 14:29 UTC (permalink / raw)
  To: binutils; +Cc: hpa

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Avoid ld segfaults on nasm objects
  2004-12-09 14:29 [PATCH] Avoid ld segfaults on nasm objects Jakub Jelinek
@ 2004-12-10  4:42 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2004-12-10  4:42 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: binutils, hpa

On Thu, Dec 09, 2004 at 03:29:40PM +0100, Jakub Jelinek wrote:
> 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

Well, no, any internal symbol in that range won't be mapped.  However,
ld won't create normal elf sections that use these reserved indices, so
the values set for st_shndx, eg. in elf_link_output_extsym from
_bfd_elf_section_from_bfd_section, won't be in that range.

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

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-12-10  4:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-09 14:29 [PATCH] Avoid ld segfaults on nasm objects Jakub Jelinek
2004-12-10  4:42 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).