public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* improve Xtensa bfd error handling
@ 2004-11-11 23:10 Bob Wilson
  0 siblings, 0 replies; only message in thread
From: Bob Wilson @ 2004-11-11 23:10 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]

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  <bob.wilson@acm.org>

	* 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.



[-- Attachment #2: bfd-prop-tables.patch --]
[-- Type: text/plain, Size: 2016 bytes --]

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-11 23:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-11 23:10 improve Xtensa bfd error handling Bob Wilson

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).