PATCH: Fix alpha relocation overflow (Re: PATCH: Add _bfd_elf_provide_symbol)

H. J. Lu hjl@lucon.org
Mon Apr 25 17:31:00 GMT 2005


On Mon, Apr 25, 2005 at 05:17:24PM +0200, Michael Matz wrote:
> > Do you have a simple testcase for alpha which I can run on Linux/i386?
> 
> I've packed together the elf-init.oS file from the system, a small c file 
> providing some symbols needed from that .oS, and this file precompiled for 
> alpha.  So you should be able to reproduce the problem with:
> 
> % ld elf-init.oS a.o
> 
> with a cross linker.  This will of course not create a functioning 
> executable, but will demonstrate the linking error.  With my patch this 
> works.  Hope this helps.
> 

How about this patch?


H.J.
----
2005-04-25  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols):
	Use the first SEC_ALLOC section which isn't SEC_CODE or the
	last SEC_CODE section if the section doesn't exist.

--- ld/emultempl/elf32.em.alpha	2005-04-25 09:24:59.000000000 -0700
+++ ld/emultempl/elf32.em	2005-04-25 10:19:53.000000000 -0700
@@ -1463,8 +1463,22 @@ gld${EMULATION_NAME}_provide_bound_symbo
     }
   else
     {
+      /* We have to choose those values very carefully.  Some targets,
+	 like alpha, may have relocation overflow with 0.  We use the
+	 first SEC_ALLOC section which isn't SEC_CODE or the last
+	 SEC_CODE section.   */
       start_val = 0;
       end_val = 0;
+      for (s = output_bfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_ALLOC) != 0)
+	    {
+	      start_val = s->vma;
+	      end_val = start_val + s->size;
+	      if ((s->flags & SEC_CODE) == 0)
+		break;
+	    }
+	}
     }
   _bfd_elf_provide_symbol (&link_info, start, start_val);
   _bfd_elf_provide_symbol (&link_info, end, end_val);



More information about the Binutils mailing list