From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1005 invoked by alias); 9 Dec 2004 14:29:52 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 756 invoked from network); 9 Dec 2004 14:29:42 -0000 Received: from unknown (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 9 Dec 2004 14:29:42 -0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id iB9ETfmv023261; Thu, 9 Dec 2004 15:29:41 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id iB9ETeSm023260; Thu, 9 Dec 2004 15:29:40 +0100 Date: Thu, 09 Dec 2004 14:29:00 -0000 From: Jakub Jelinek To: binutils@sources.redhat.com Cc: hpa@zytor.com Subject: [PATCH] Avoid ld segfaults on nasm objects Message-ID: <20041209142940.GG5149@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-SW-Source: 2004-12/txt/msg00093.txt.bz2 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 * 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