This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR12921
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 24 Jun 2011 13:28:15 +0930
- Subject: PR12921
I've committed this patch to both mainline and 2.21.
PR ld/12921
* elf.c (assign_file_positions_for_load_sections): Don't align
sh_offset for all SHT_NOBITS sections here, just .tbss sections
that don't get a PT_LOAD.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.541
diff -u -p -r1.541 elf.c
--- bfd/elf.c 16 Jun 2011 12:34:19 -0000 1.541
+++ bfd/elf.c 23 Jun 2011 15:26:38 -0000
@@ -4684,24 +4684,26 @@ assign_file_positions_for_load_sections
}
else
{
- if (p->p_type == PT_LOAD
- || (this_hdr->sh_type == SHT_NOBITS
- && (this_hdr->sh_flags & SHF_TLS) != 0
- && this_hdr->sh_offset == 0))
+ if (p->p_type == PT_LOAD)
{
- if (this_hdr->sh_type == SHT_NOBITS)
- {
- /* These sections don't really need sh_offset,
- but give them one anyway. */
- bfd_vma adjust = vma_page_aligned_bias (this_hdr->sh_addr,
- off, align);
- this_hdr->sh_offset = sec->filepos = off + adjust;
- }
- else
- {
- this_hdr->sh_offset = sec->filepos = off;
- off += this_hdr->sh_size;
- }
+ this_hdr->sh_offset = sec->filepos = off;
+ if (this_hdr->sh_type != SHT_NOBITS)
+ off += this_hdr->sh_size;
+ }
+ else if (this_hdr->sh_type == SHT_NOBITS
+ && (this_hdr->sh_flags & SHF_TLS) != 0
+ && this_hdr->sh_offset == 0)
+ {
+ /* This is a .tbss section that didn't get a PT_LOAD.
+ (See _bfd_elf_map_sections_to_segments "Create a
+ final PT_LOAD".) Set sh_offset to the value it
+ would have if we had created a zero p_filesz and
+ p_memsz PT_LOAD header for the section. This
+ also makes the PT_TLS header have the same
+ p_offset value. */
+ bfd_vma adjust = vma_page_aligned_bias (this_hdr->sh_addr,
+ off, align);
+ this_hdr->sh_offset = sec->filepos = off + adjust;
}
if (this_hdr->sh_type != SHT_NOBITS)
--
Alan Modra
Australia Development Lab, IBM