This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Fix stripping of objects where empty sections preceede .dynamic
- From: Jakub Jelinek <jakub at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Tue, 4 Jan 2005 12:29:40 +0100
- Subject: [PATCH] Fix stripping of objects where empty sections preceede .dynamic
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Quite recent ppc32 ld.so has:
[10] .eh_frame_hdr PROGBITS 000165f4 0165f4 000044 00 A 0 0 4
[11] .eh_frame PROGBITS 00016638 016638 00013c 00 A 0 0 4
[12] .data.rel.ro PROGBITS 00026e48 016e48 0000f8 00 WA 0 0 4
[13] .got2 PROGBITS 00026f40 016f40 000000 00 WA 0 0 1
[14] .dynamic DYNAMIC 00026f40 016f40 0000c0 08 WA 3 0 4
[15] .data PROGBITS 00027000 017000 000000 00 WA 0 0 1
LOAD 0x000000 0x00000000 0x00000000 0x16774 0x16774 R E 0x10000
LOAD 0x016e48 0x00026e48 0x00026e48 0x00b10 0x00c40 RWE 0x10000
DYNAMIC 0x016f40 0x00026f40 0x00026f40 0x000c0 0x000c0 RW 0x4
GNU_EH_FRAME 0x0165f4 0x000165f4 0x000165f4 0x00044 0x00044 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
GNU_RELRO 0x016e48 0x00026e48 0x00026e48 0x001b8 0x001b8 R E 0x1
Note the empty section right before .dynamic. There is nothing wrong
on this and there could very well be empty user sections before that place.
Unfortunately this can't be stripped:
./strip-new ld-2.3.4.so
BFD: stDnME2S: The first section in the PT_DYNAMIC segment is not the .dynamic section
./strip-new: stDnME2S: Bad value
BFD: stDnME2S: The first section in the PT_DYNAMIC segment is not the .dynamic section
./strip-new: stDnME2S: Bad value
/* Make sure the .dynamic section is the first section in the
PT_DYNAMIC segment. */
else if (p->p_type == PT_DYNAMIC
&& m->count > 1
&& strcmp (m->sections[0]->name, ".dynamic") != 0)
{
_bfd_error_handler
(_("%B: The first section in the PT_DYNAMIC segment is not the .dynamic section"),
abfd);
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
The problem is that copy_private_bfd_data doesn't put just .dynamic section
into PT_DYNAMIC segment, but also the empty section(s) right before it.
The following patch cures this. I didn't want to hardcode .dynamic section
name always, so the test just puts into the segment all non-empty sections
that fall into PT_DYNAMIC's bounds. Not sure if it is possible to create
empty PT_DYNAMIC, so just in case it also adds .dynamic section by name
if it is empty.
Ok?
2005-01-04 Jakub Jelinek <jakub@redhat.com>
* bfd/elf.c (INCLUDE_SECTION_IN_SEGMENT): Don't put empty sections into
PT_DYNAMIC segment, unless .dynamic.
--- bfd/elf.c.jj 2005-01-04 11:28:35.000000000 +0100
+++ bfd/elf.c 2005-01-04 12:12:02.225247166 +0100
@@ -4965,7 +4965,9 @@ copy_private_bfd_data (bfd *ibfd, bfd *o
4. The section has not already been allocated to a previous segment.
5. PT_GNU_STACK segments do not include any sections.
6. PT_TLS segment includes only SHF_TLS sections.
- 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. */
+ 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.
+ 8. PT_DYNAMIC should not contain empty sections (with the possible
+ exception of .dynamic). */
#define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed) \
((((segment->p_paddr \
? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr) \
@@ -4979,6 +4981,9 @@ copy_private_bfd_data (bfd *ibfd, bfd *o
&& (segment->p_type == PT_LOAD \
|| segment->p_type == PT_TLS \
|| (section->flags & SEC_THREAD_LOCAL) == 0) \
+ && (segment->p_type != PT_DYNAMIC \
+ || SECTION_SIZE (section, segment) \
+ || !strcmp (bfd_get_section_name (ibfd, section), ".dynamic")) \
&& ! section->segment_mark)
/* Returns TRUE iff seg1 starts after the end of seg2. */
Jakub