This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: ld/3015: -z relro may create PT_NULL segment
On Tue, Aug 15, 2006 at 12:30:15PM +0930, Alan Modra wrote:
> On Mon, Aug 14, 2006 at 05:41:26PM -0700, H. J. Lu wrote:
> > - p->p_type = PT_NULL;
> > + /* elf_modify_segment_map will delete empty PT_LOAD
> > + segments. */
> > + p->p_type = PT_LOAD;
>
> But elf_modify_segment_map is called *before*
> assign_file_positions_for_non_load_sections.
>
Here is a different patch with testcases. There is no need for
PT_GNU_RELRO segment if there is no PT_DYNAMIC segment. Also
PT_GNU_RELRO segment should always has alignment 1.
H.J.
----
bfd/
2006-08-16 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3015
* elf.c (get_program_header_size): Add a PT_GNU_RELRO segment only
if there is a PT_DYNAMIC segment.
(_bfd_elf_map_sections_to_segments): Likewise.
(assign_file_positions_for_load_sections): Set PT_GNU_RELRO
segment alignment to 1.
ld/testsuite/
2006-08-16 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3015
* ld-elf/binutils.exp: Add tests for "-z relro".
--- binutils/bfd/elf.c.relro 2006-08-16 10:08:02.000000000 -0700
+++ binutils/bfd/elf.c 2006-08-16 14:51:14.000000000 -0700
@@ -3622,6 +3622,13 @@ get_program_header_size (bfd *abfd, stru
{
/* We need a PT_DYNAMIC segment. */
++segs;
+
+ if (elf_tdata (abfd)->relro)
+ {
+ /* We need a PT_GNU_RELRO segment only when there is a
+ PT_DYNAMIC segment. */
+ ++segs;
+ }
}
if (elf_tdata (abfd)->eh_frame_hdr)
@@ -3636,12 +3643,6 @@ get_program_header_size (bfd *abfd, stru
++segs;
}
- if (elf_tdata (abfd)->relro)
- {
- /* We need a PT_GNU_RELRO segment. */
- ++segs;
- }
-
for (s = abfd->sections; s != NULL; s = s->next)
{
if ((s->flags & SEC_LOAD) != 0
@@ -4110,8 +4111,10 @@ _bfd_elf_map_sections_to_segments (bfd *
pm = &m->next;
}
- if (elf_tdata (abfd)->relro)
+ if (dynsec != NULL && elf_tdata (abfd)->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)
@@ -4591,9 +4594,11 @@ assign_file_positions_for_load_sections
p->p_memsz += o->offset + o->size;
}
- if (align > p->p_align
- && (p->p_type != PT_LOAD
- || (abfd->flags & D_PAGED) == 0))
+ if (p->p_type == PT_GNU_RELRO)
+ p->p_align = 1;
+ else if (align > p->p_align
+ && (p->p_type != PT_LOAD
+ || (abfd->flags & D_PAGED) == 0))
p->p_align = align;
}
--- binutils/ld/testsuite/ld-elf/binutils.exp.relro 2006-06-01 09:15:59.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/binutils.exp 2006-08-16 14:25:49.000000000 -0700
@@ -101,6 +101,11 @@ binutils_test strip "-shared" maxpage1
binutils_test objcopy "" maxpage1
binutils_test objcopy "-shared" maxpage1
+binutils_test strip "-z relro" maxpage1
+binutils_test strip "-z relro -shared" maxpage1
+binutils_test objcopy "-z relro" maxpage1
+binutils_test objcopy "-z relro -shared" maxpage1
+
binutils_test objcopy "" tbss1
binutils_test objcopy "-shared" tbss1
binutils_test objcopy "-z max-page-size=0x100000" tbss1