From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30330 invoked by alias); 11 Nov 2004 23:10:04 -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 30299 invoked from network); 11 Nov 2004 23:09:58 -0000 Received: from unknown (HELO mail-in.hq.tensilica.com) (65.205.227.29) by sourceware.org with SMTP; 11 Nov 2004 23:09:58 -0000 Received: from egret.hq.tensilica.com (IDENT:+2OruUyE3Crw1qVPctLwO6+WW9TRNgqX@egret.hq.tensilica.com [192.168.11.80]) by mail-in.hq.tensilica.com (8.11.6/8.9.3) with ESMTP id iABN9vK10325 for ; Thu, 11 Nov 2004 15:09:57 -0800 Received: from tensilica.com (IDENT:WQtj9DMFFGP8J3bXRITerh2qe5rJVuBk@egret.hq.tensilica.com [192.168.11.80]) by egret.hq.tensilica.com (8.11.6/8.11.6) with ESMTP id iABN9vw32046 for ; Thu, 11 Nov 2004 15:09:57 -0800 Message-ID: <4193F145.3070702@tensilica.com> Date: Thu, 11 Nov 2004 23:10:00 -0000 From: Bob Wilson Organization: Tensilica, Inc. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 MIME-Version: 1.0 To: binutils@sources.redhat.com Subject: improve Xtensa bfd error handling Content-Type: multipart/mixed; boundary="------------070303060802080503030807" X-SW-Source: 2004-11/txt/msg00197.txt.bz2 This is a multi-part message in MIME format. --------------070303060802080503030807 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 603 This patch changes a runtime assertion about the contents of Xtensa property tables into an error check. Removing the relocations from an Xtensa object file, e.g., by running strip, may cause some property table entries to overlap, which is not expected. The linker should fail with an error instead of an assertion failure if this happens. Committed on the mainline. 2004-11-11 Bob Wilson * elf32-xtensa.c (property_table_compare): Remove assertion about entries with the same address and non-zero size. (xtensa_read_table_entries): Report such entries as errors. --------------070303060802080503030807 Content-Type: text/plain; name="bfd-prop-tables.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="bfd-prop-tables.patch" Content-length: 2016 Index: elf32-xtensa.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v retrieving revision 1.38 diff -u -p -r1.38 elf32-xtensa.c --- elf32-xtensa.c 21 Oct 2004 16:29:11 -0000 1.38 +++ elf32-xtensa.c 11 Nov 2004 22:55:35 -0000 @@ -523,12 +523,6 @@ property_table_compare (const void *ap, if (a->address == b->address) { - /* The only circumstance where two entries may legitimately have the - same address is when one of them is a zero-size placeholder to - mark a place where fill can be inserted. The zero-size entry should - come first. */ - BFD_ASSERT ((a->size == 0 || b->size == 0)); - if (a->size != b->size) return (a->size - b->size); @@ -585,7 +579,7 @@ xtensa_read_table_entries (bfd *abfd, bfd_size_type table_size = 0; bfd_byte *table_data; property_table_entry *blocks; - int block_count; + int blk, block_count; bfd_size_type num_records; Elf_Internal_Rela *internal_relocs; bfd_vma section_addr; @@ -700,6 +694,25 @@ xtensa_read_table_entries (bfd *abfd, /* Now sort them into address order for easy reference. */ qsort (blocks, block_count, sizeof (property_table_entry), property_table_compare); + + /* Check that the table contents are valid. Problems may occur, + for example, if an unrelocated object file is stripped. */ + for (blk = 1; blk < block_count; blk++) + { + /* The only circumstance where two entries may legitimately + have the same address is when one of them is a zero-size + placeholder to mark a place where fill can be inserted. + The zero-size entry should come first. */ + if (blocks[blk - 1].address == blocks[blk].address && + blocks[blk - 1].size != 0) + { + (*_bfd_error_handler) (_("%B(%A): invalid property table"), + abfd, section); + bfd_set_error (bfd_error_bad_value); + free (blocks); + return -1; + } + } } *table_p = blocks; --------------070303060802080503030807--