This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Objcopy fix for relocation sections


On Tue, Jul 27, 2004 at 05:04:27PM -0400, Daniel Jacobowitz wrote:
> I still haven't let this die...
> 
> Alan, your suggested patch to assign rel positions earlier does not
> work.  The problem is that SHT_REL sections may not be sized yet during
> linking.  If they aren't, we assign them a file position and then
> assign the following section the same file position because they have a
> placeholder size of 0.  My only testcase for this to date is a MIPS
> bootloader, which uses --emit-relocs.  My guess is that otherwise the
> relocation sections are at the end anyway.

By the way, when Alan merged other changes to the 2.15 branch, this one
got picked up somehow.  So the above testcase fails using an unmodified
binutils 2.15 release.

> We ought to be able to size reloc sections at this point.  We can't do
> it before the call to _bfd_elf_compute_section_file_positions because
> they haven't been initialized yet in a final link.  And I don't want to
> do it inside _bfd_elf_compute_section_file_positions, because there are
> calls to that function from other places than final link processing. 
> That leads me to this patch.
> 
> I think it's right because if we are linking we'll go through the call
> in elf_bfd_final_link instead, and if we're not linking then the reloc
> sections will have correct sizes and can be placed earlier.  This is
> similar to my previous patch, but has a better understanding behind it.

This, unfortunately, was mistaken.  It seems to be OK for binutils and
ld, but gas hasn't sized the relocation sections yet; that doesn't
happen until write_relocs.

It seems that we don't need to size relocation sections when linking -
that's OK, bfd_set_section_contents won't be called before output
begins - or when assembling to an object file, or when outputing an
object file from objcopy.  In the latter cases write_relocs will take
care of everything.

That train of thought gives me this patch against 2.15, or the
equivalent for HEAD.  Tested on i386-linux, and with the previous
failing testcases.  OK?  James, does this one behave better?

-- 
Daniel Jacobowitz

2004-08-03  Daniel Jacobowitz  <dan@debian.org>

	* elf.c (assign_file_positions_except_relocs): Revert unintended
	change from 2004-04-08.
	(_bfd_elf_set_section_contents): Call
	_bfd_elf_assign_file_positions_for_relocs when starting output
	for executables and shared libraries.

--- elf.c.orig	2004-08-03 17:01:54.000000000 -0400
+++ elf.c	2004-08-03 18:18:23.000000000 -0400
@@ -4265,7 +4265,9 @@ assign_file_positions_except_relocs (bfd
 	      off = _bfd_elf_assign_file_position_for_section (hdr, off,
 							       FALSE);
 	    }
-	  else if (hdr == i_shdrpp[tdata->symtab_section]
+	  else if (hdr->sh_type == SHT_REL
+		   || hdr->sh_type == SHT_RELA
+		   || hdr == i_shdrpp[tdata->symtab_section]
 		   || hdr == i_shdrpp[tdata->symtab_shndx_section]
 		   || hdr == i_shdrpp[tdata->strtab_section])
 	    hdr->sh_offset = -1;
@@ -6159,9 +6161,13 @@ _bfd_elf_set_section_contents (bfd *abfd
   Elf_Internal_Shdr *hdr;
   bfd_signed_vma pos;
 
-  if (! abfd->output_has_begun
-      && ! _bfd_elf_compute_section_file_positions (abfd, NULL))
-    return FALSE;
+  if (! abfd->output_has_begun)
+    {
+      if (! _bfd_elf_compute_section_file_positions (abfd, NULL))
+	return FALSE;
+      if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
+	_bfd_elf_assign_file_positions_for_relocs (abfd);
+    }
 
   hdr = &elf_section_data (section)->this_hdr;
   pos = hdr->sh_offset + offset;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]