This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR bfd/14207: linker can produce a NULL GNU_RELRO segment


Hi,

GNU_RELRO segment may not be generated since on-disk portion of
PT_LOAD segment may not be aligned to common page size.  This patch add
a dummy .relro section to make sure that on-disk portion of PT_LOAD
segment is aligned to common page size.  OK to install?

Thanks.


H.J.
----
bfd/

2012-06-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR bfd/14207
	* elf-bfd.h (elf_link_hash_table): Add srelro.

	* elf.c (assign_file_positions_for_non_load_sections): Abort
	if PT_GNU_RELRO segment is invalid.

	* elflink.c (elf_link_add_object_symbols): Create .relro section
	for -z relro.

ld/

2012-06-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14207
	* scripttempl/elf.sc: Add .relro section for PT_GNU_RELRO
	segment.

ld/testsuite/

2012-06-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/14207
	* ld-x86-64/x86-64.exp: Run pr14207.

	* ld-x86-64/pr14207.d: New file.
	* ld-x86-64/pr14207.s: Likewise.

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 889ce12..50ee7bb 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -530,6 +530,7 @@ struct elf_link_hash_table
   asection *iplt;
   asection *irelplt;
   asection *irelifunc;
+  asection *srelro;
 };
 
 /* Look up an entry in an ELF linker hash table.  */
diff --git a/bfd/elf.c b/bfd/elf.c
index d97da9f..b8b883f 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4924,6 +4924,9 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 		      && lp->p_vaddr + lp->p_filesz >= link_info->relro_end)
 		    break;
 		}
+
+	      if (lp == (phdrs + count) && link_info->relro)
+		abort ();
 	    }
 	  else
 	    {
diff --git a/bfd/elflink.c b/bfd/elflink.c
index a9d95bd..60c2531 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3688,6 +3688,24 @@ error_free_dyn:
       elf_dt_audit (abfd) = audit; 
     }
 
+  if (info->relro && htab->srelro == NULL)
+    {
+      asection *s; 
+      s = bfd_make_section_anyway_with_flags (abfd, ".relro",
+					      (SEC_LINKER_CREATED
+					       | SEC_ALLOC
+					       | SEC_LOAD 
+					       | SEC_KEEP));
+      if (s == NULL
+	  || ! bfd_set_section_alignment (abfd, s,
+					  bfd_log2 (bed->commonpagesize)))
+	{
+	  info->callbacks->einfo ("%P: Cannot create .relro section.\n");
+	  goto error_return;
+	}
+      htab->srelro = s;
+    }
+
   /* If this is a dynamic object, we always link against the .dynsym
      symbol table, not the .symtab symbol table.  The dynamic linker
      will only see the .dynsym symbol table, so there is no reason to
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index 37a3124..2762194 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -122,7 +122,9 @@ DATA_SEGMENT_END=""
 if test -n "${COMMONPAGESIZE}"; then
   DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
   DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
-  DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
+  DATA_SEGMENT_RELRO_END="
+  .relro	${RELOCATING-0} : { *(.relro) }
+  . = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
 fi
 if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
   INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
diff --git a/ld/testsuite/ld-x86-64/pr14207.d b/ld/testsuite/ld-x86-64/pr14207.d
new file mode 100644
index 0000000..c5a8896
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr14207.d
@@ -0,0 +1,8 @@
+#name: PR ld/14207
+#as: --64
+#ld: -melf_x86_64 -shared -z relro -z now
+#readelf: -l --wide
+
+#...
+   03     .init_array .fini_array .jcr .data.rel.ro .dynamic .got 
+#...
diff --git a/ld/testsuite/ld-x86-64/pr14207.s b/ld/testsuite/ld-x86-64/pr14207.s
new file mode 100644
index 0000000..496e67e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr14207.s
@@ -0,0 +1,24 @@
+	
+	.section .ctors, "aw"
+	.space 0x10, 1
+	
+	.section .dtors, "aw"
+	.space 0x10, 2
+
+	.section .jcr, "aw"
+	.space 0x8, 3
+	
+	.section .data.rel.ro
+	.p2align 4
+	.space 0x20, 3
+
+	.section .dynamic
+	.space 0xb0, 2
+
+	.section .got
+	.space 0x2a8, 4
+	
+	.bss
+	.zero 0x840
+
+
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index b9af8de..1eb1b1c 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -209,6 +209,7 @@ run_dump_test "pr13947"
 run_dump_test "pr12570a"
 run_dump_test "pr12570b"
 run_dump_test "pr14215"
+run_dump_test "pr14207"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]