This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Objcopy fix for relocation sections
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Daniel Jacobowitz <drow at false dot org>
- Cc: binutils at sources dot redhat dot com
- Date: Wed, 8 Sep 2004 09:27:00 +0930
- Subject: Re: Objcopy fix for relocation sections
- References: <20031222210543.GA3418@nevyn.them.org> <20031223032137.GD1618@bubble.sa.bigpond.net.au> <20040727210426.GA11595@nevyn.them.org> <20040803225601.GA22637@nevyn.them.org> <20040805092703.GF12879@bubble.modra.org> <20040805131429.GA14075@nevyn.them.org>
After having a good look at what is going on here, I believe the
following patch is the correct solution. Would you please check
that it fixes the original problem? I tested that this change
cures a similar problem on powerpc-linux (at least the FSF version,
where we output debug relocs). Prior to this patch, using a .so
created during the ld testsuite run, I get
$ ../../binutils/objcopy vp.so xxx.so
../../binutils/objcopy: xxx.so: File truncated
As the comment I added says, some reloc sections are not handled
specially by bfd (see bfd_section_from_shdr). These should be
treated as normal bfd sections.
* elf.c (assign_file_positions_except_relocs): Assign relocs
stored in a bfd section.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.242
diff -u -p -r1.242 elf.c
--- bfd/elf.c 6 Sep 2004 20:55:22 -0000 1.242
+++ bfd/elf.c 7 Sep 2004 23:47:57 -0000
@@ -4423,10 +4423,13 @@ get_program_header_size (bfd *abfd)
_bfd_elf_compute_section_file_positions. All the section sizes and
VMAs must be known before this is called.
- We do not consider reloc sections at this point, unless they form
- part of the loadable image. Reloc sections are assigned file
- positions in assign_file_positions_for_relocs, which is called by
- write_object_contents and final_link.
+ Reloc sections come in two flavours: Those processed specially as
+ "side-channel" data attached to a section to which they apply, and
+ those that bfd doesn't process as relocations. The latter sort are
+ stored in a normal bfd section by bfd_section_from_shdr. We don't
+ consider the former sort here, unless they form part of the loadable
+ image. Reloc sections not assigned here will be handled later by
+ assign_file_positions_for_relocs.
We also don't set the positions of the .symtab and .strtab here. */
@@ -4458,8 +4461,8 @@ assign_file_positions_except_relocs (bfd
Elf_Internal_Shdr *hdr;
hdr = *hdrpp;
- if (hdr->sh_type == SHT_REL
- || hdr->sh_type == SHT_RELA
+ if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
+ && hdr->bfd_section == NULL)
|| i == tdata->symtab_section
|| i == tdata->symtab_shndx_section
|| i == tdata->strtab_section)
@@ -4514,8 +4517,8 @@ assign_file_positions_except_relocs (bfd
off = _bfd_elf_assign_file_position_for_section (hdr, off,
FALSE);
}
- else if (hdr->sh_type == SHT_REL
- || hdr->sh_type == SHT_RELA
+ else if (((hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
+ && hdr->bfd_section == NULL)
|| hdr == i_shdrpp[tdata->symtab_section]
|| hdr == i_shdrpp[tdata->symtab_shndx_section]
|| hdr == i_shdrpp[tdata->strtab_section])
--
Alan Modra
IBM OzLabs - Linux Technology Centre