This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: Fix relro strip test for MIPS
- From: "H.J. Lu" <hjl at lucon dot org>
- To: binutils at sourceware dot org
- Date: Wed, 10 Oct 2007 19:25:27 -0700
- Subject: Re: PATCH: Fix relro strip test for MIPS
- References: <20070919181413.GA12519@lucon.org> <20070920063212.GB29574@bubble.grove.modra.org> <20070920175725.GA19023@lucon.org> <20070920180751.GA9886@caradoc.them.org> <20070920185820.GA19623@lucon.org> <20070921165900.GA19837@lucon.org> <20070922211708.GA30459@lucon.org> <20070927042444.GB21314@bubble.grove.modra.org> <20071010181118.GA12326@lucon.org> <20071011000531.GA1513@bubble.grove.modra.org>
On Thu, Oct 11, 2007 at 09:35:31AM +0930, Alan Modra wrote:
> On Wed, Oct 10, 2007 at 11:11:18AM -0700, H.J. Lu wrote:
> > On Thu, Sep 27, 2007 at 01:54:44PM +0930, Alan Modra wrote:
> > > On Sat, Sep 22, 2007 at 02:17:08PM -0700, H.J. Lu wrote:
> > > > We can call assign_file_positions_for_load_sections to get the
> > > > load section layout and find out if the PT_GNU_RELRO segment will
> > > > be empty or not.
> > >
> > > I haven't been following this thread closely, but I really don't like
> > > calling assign_file_positions_for_load_sections early like this.
> > > Can't you determine whether a PT_GNU_RELRO program header will be
> > > needed just by looking at the PT_LOAD sections in
> > > _bfd_elf_map_sections_to_segments?
> > >
> >
> > This patch
> >
> > http://sourceware.org/ml/binutils/2007-09/msg00324.html
> >
> > doesn't call assign_file_positions_for_load_sections.
>
> This patch is OK.
>
I am checking in this equivalent patch. There is no need for the
loop. We can just use the first and last sections to compute the
file size.
H.J.
----
2007-10-10 H.J. Lu <hongjiu.lu@intel.com>
* elf.c (get_program_header_size): Always add a PT_GNU_RELRO
segment for -z relro.
(_bfd_elf_map_sections_to_segments): Make a PT_GNU_RELRO
segment only when needed.
--- bfd/elf.c.relro 2007-10-10 19:02:12.000000000 -0700
+++ bfd/elf.c 2007-10-10 19:16:42.000000000 -0700
@@ -3362,13 +3362,12 @@ get_program_header_size (bfd *abfd, stru
{
/* We need a PT_DYNAMIC segment. */
++segs;
+ }
- if (info->relro)
- {
- /* We need a PT_GNU_RELRO segment only when there is a
- PT_DYNAMIC segment. */
- ++segs;
- }
+ if (info->relro)
+ {
+ /* We need a PT_GNU_RELRO segment. */
+ ++segs;
}
if (elf_tdata (abfd)->eh_frame_hdr)
@@ -3991,21 +3990,38 @@ _bfd_elf_map_sections_to_segments (bfd *
pm = &m->next;
}
- if (dynsec != NULL && info->relro)
+ if (info->relro)
{
- /* We make a PT_GNU_RELRO segment only when there is a
- PT_DYNAMIC segment. */
- amt = sizeof (struct elf_segment_map);
- m = bfd_zalloc (abfd, amt);
- if (m == NULL)
- goto error_return;
- m->next = NULL;
- m->p_type = PT_GNU_RELRO;
- m->p_flags = PF_R;
- m->p_flags_valid = 1;
+ for (m = mfirst; m != NULL; m = m->next)
+ {
+ if (m->p_type == PT_LOAD)
+ {
+ asection *last = m->sections[m->count - 1];
+ bfd_vma vaddr = m->sections[0]->vma;
+ bfd_vma filesz = last->vma - vaddr + last->size;
+
+ if (vaddr < info->relro_end
+ && vaddr >= info->relro_start
+ && (vaddr + filesz) >= info->relro_end)
+ break;
+ }
+ }
- *pm = m;
- pm = &m->next;
+ /* Make a PT_GNU_RELRO segment only when it isn't empty. */
+ if (m != NULL)
+ {
+ amt = sizeof (struct elf_segment_map);
+ m = bfd_zalloc (abfd, amt);
+ if (m == NULL)
+ goto error_return;
+ m->next = NULL;
+ m->p_type = PT_GNU_RELRO;
+ m->p_flags = PF_R;
+ m->p_flags_valid = 1;
+
+ *pm = m;
+ pm = &m->next;
+ }
}
free (sections);