aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2007-09-18 00:25:07 +0000
committerH.J. Lu <hjl.tools@gmail.com>2007-09-18 00:25:07 +0000
commitb10a8ae01c27969e5104f76209272fb457c1e20b (patch)
tree6005c9c87f56f91ee161c26390fedc00d0222271 /ld
parent87dcefc059a01fa0d2db1cc00cc6f8f4de505291 (diff)
downloadfsf-binutils-gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.zip
fsf-binutils-gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.tar.gz
fsf-binutils-gdb-b10a8ae01c27969e5104f76209272fb457c1e20b.tar.bz2
bfd/
2007-09-17 H.J. Lu <hongjiu.lu@intel.com> PR binutils/3281 PR binutils/5037 * elf-bfd.h (elf_obj_tdata): Remove relro. * elf.c (get_program_header_size): Check info->relro instead of elf_tdata (abfd)->relro. (_bfd_elf_map_sections_to_segments): Likewise. (assign_file_positions_for_load_sections): Don't set PT_GNU_RELRO segment alignment here. (assign_file_positions_for_non_load_sections): Properly set up PT_GNU_RELRO segment for copying executable/shared library. (rewrite_elf_program_header): Remove PT_GNU_RELRO segment. (copy_elf_program_header): Set p_size and p_size_valid fields for PT_GNU_RELRO segment. include/elf/ 2007-09-17 H.J. Lu <hongjiu.lu@intel.com> PR binutils/3281 PR binutils/5037 * internal.h (elf_segment_map): Add p_size and p_size_valid. (ELF_IS_SECTION_IN_SEGMENT): Allow SHF_TLS sections in PT_GNU_RELRO segments. ld/ 2007-09-17 H.J. Lu <hongjiu.lu@intel.com> PR binutils/3281 PR binutils/5037 * ldexp.h (ldexp_control): Add relro, relro_start_stat and relro_end_stat. * ldexp.c (fold_binary): Set expld.dataseg.relro to exp_dataseg_relro_start or exp_dataseg_relro_end when seeing DATA_SEGMENT_ALIGN or DATA_SEGMENT_RELRO_END, respectively. * ldlang.c (lang_size_sections_1): Properly set expld.dataseg.relro_start_stat and expld.dataseg.relro_end_stat. (find_relro_section_callback): New function. (lang_find_relro_sections_1): Likewise. (lang_find_relro_sections): Likewise. (lang_process): Call lang_find_relro_sections for non-relocatable link. ld/testsuite/ 2007-09-17 H.J. Lu <hongjiu.lu@intel.com> PR binutils/3281 PR binutils/5037 * ld-elf/binutils.exp: Update "-z relro" tests to use relro1.s. Add "-z relro" tests with relro2.s. Add "-z relro" tests with TLS for objcopy. * ld-elf/relro1.s: New file. * ld-elf/relro2.s: Likewise.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog21
-rw-r--r--ld/ldexp.c2
-rw-r--r--ld/ldexp.h11
-rw-r--r--ld/ldlang.c101
-rw-r--r--ld/testsuite/ChangeLog11
-rw-r--r--ld/testsuite/ld-elf/binutils.exp28
-rw-r--r--ld/testsuite/ld-elf/relro1.s14
-rw-r--r--ld/testsuite/ld-elf/relro2.s5
8 files changed, 188 insertions, 5 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 1e35221..e5a5129 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,24 @@
+2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR binutils/3281
+ PR binutils/5037
+ * ldexp.h (ldexp_control): Add relro, relro_start_stat and
+ relro_end_stat.
+
+ * ldexp.c (fold_binary): Set expld.dataseg.relro to
+ exp_dataseg_relro_start or exp_dataseg_relro_end when
+ seeing DATA_SEGMENT_ALIGN or DATA_SEGMENT_RELRO_END,
+ respectively.
+
+ * ldlang.c (lang_size_sections_1): Properly set
+ expld.dataseg.relro_start_stat and
+ expld.dataseg.relro_end_stat.
+ (find_relro_section_callback): New function.
+ (lang_find_relro_sections_1): Likewise.
+ (lang_find_relro_sections): Likewise.
+ (lang_process): Call lang_find_relro_sections for
+ non-relocatable link.
+
2007-09-17 Nick Clifton <nickc@redhat.com>
* po/es.po: Updated Spanish translation.
diff --git a/ld/ldexp.c b/ld/ldexp.c
index 9b95808..5e2812d 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -390,6 +390,7 @@ fold_binary (etree_type *tree)
break;
case DATA_SEGMENT_ALIGN:
+ expld.dataseg.relro = exp_dataseg_relro_start;
if (expld.phase != lang_first_phase_enum
&& expld.section == bfd_abs_section_ptr
&& (expld.dataseg.phase == exp_dataseg_none
@@ -425,6 +426,7 @@ fold_binary (etree_type *tree)
break;
case DATA_SEGMENT_RELRO_END:
+ expld.dataseg.relro = exp_dataseg_relro_end;
if (expld.phase != lang_first_phase_enum
&& (expld.dataseg.phase == exp_dataseg_align_seen
|| expld.dataseg.phase == exp_dataseg_adjust
diff --git a/ld/ldexp.h b/ld/ldexp.h
index 5c8bad2..1e0069d 100644
--- a/ld/ldexp.h
+++ b/ld/ldexp.h
@@ -98,6 +98,8 @@ typedef enum {
lang_final_phase_enum
} lang_phase_type;
+union lang_statement_union;
+
struct ldexp_control {
/* Modify expression evaluation depending on this. */
lang_phase_type phase;
@@ -125,6 +127,15 @@ struct ldexp_control {
} phase;
bfd_vma base, min_base, relro_end, end, pagesize, maxpagesize;
+
+ enum {
+ exp_dataseg_relro_none,
+ exp_dataseg_relro_start,
+ exp_dataseg_relro_end,
+ } relro;
+
+ union lang_statement_union *relro_start_stat;
+ union lang_statement_union *relro_end_stat;
} dataseg;
};
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 7ecd477..b06cabd 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4636,10 +4636,32 @@ lang_size_sections_1
bfd_vma newdot = dot;
etree_type *tree = s->assignment_statement.exp;
+ expld.dataseg.relro = exp_dataseg_relro_none;
+
exp_fold_tree (tree,
output_section_statement->bfd_section,
&newdot);
+ if (expld.dataseg.relro == exp_dataseg_relro_start)
+ {
+ if (!expld.dataseg.relro_start_stat)
+ expld.dataseg.relro_start_stat = s;
+ else
+ {
+ ASSERT (expld.dataseg.relro_start_stat == s);
+ }
+ }
+ else if (expld.dataseg.relro == exp_dataseg_relro_end)
+ {
+ if (!expld.dataseg.relro_end_stat)
+ expld.dataseg.relro_end_stat = s;
+ else
+ {
+ ASSERT (expld.dataseg.relro_end_stat == s);
+ }
+ }
+ expld.dataseg.relro = exp_dataseg_relro_none;
+
/* This symbol is relative to this section. */
if ((tree->type.node_class == etree_provided
|| tree->type.node_class == etree_assign)
@@ -5665,6 +5687,81 @@ lang_gc_sections (void)
bfd_gc_sections (output_bfd, &link_info);
}
+/* Worker for lang_find_relro_sections_1. */
+
+static void
+find_relro_section_callback (lang_wild_statement_type *ptr ATTRIBUTE_UNUSED,
+ struct wildcard_list *sec ATTRIBUTE_UNUSED,
+ asection *section,
+ lang_input_statement_type *file ATTRIBUTE_UNUSED,
+ void *data)
+{
+ /* Discarded, excluded and ignored sections effectively have zero
+ size. */
+ if (section->output_section != NULL
+ && section->output_section->owner == output_bfd
+ && (section->output_section->flags & SEC_EXCLUDE) == 0
+ && !IGNORE_SECTION (section)
+ && section->size != 0)
+ {
+ bfd_boolean *has_relro_section = (bfd_boolean *) data;
+ *has_relro_section = TRUE;
+ }
+}
+
+/* Iterate over sections for relro sections. */
+
+static void
+lang_find_relro_sections_1 (lang_statement_union_type *s,
+ bfd_boolean *has_relro_section)
+{
+ if (*has_relro_section)
+ return;
+
+ for (; s != NULL; s = s->header.next)
+ {
+ if (s == expld.dataseg.relro_end_stat)
+ break;
+
+ switch (s->header.type)
+ {
+ case lang_wild_statement_enum:
+ walk_wild (&s->wild_statement,
+ find_relro_section_callback,
+ has_relro_section);
+ break;
+ case lang_constructors_statement_enum:
+ lang_find_relro_sections_1 (constructor_list.head,
+ has_relro_section);
+ break;
+ case lang_output_section_statement_enum:
+ lang_find_relro_sections_1 (s->output_section_statement.children.head,
+ has_relro_section);
+ break;
+ case lang_group_statement_enum:
+ lang_find_relro_sections_1 (s->group_statement.children.head,
+ has_relro_section);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static void
+lang_find_relro_sections (void)
+{
+ bfd_boolean has_relro_section = FALSE;
+
+ /* Check all sections in the link script. */
+
+ lang_find_relro_sections_1 (expld.dataseg.relro_start_stat,
+ &has_relro_section);
+
+ if (!has_relro_section)
+ link_info.relro = FALSE;
+}
+
/* Relax all sections until bfd_relax_section gives up. */
static void
@@ -5792,6 +5889,10 @@ lang_process (void)
section positions, since they will affect SIZEOF_HEADERS. */
lang_record_phdrs ();
+ /* Check relro sections. */
+ if (link_info.relro && ! link_info.relocatable)
+ lang_find_relro_sections ();
+
/* Size up the sections. */
lang_size_sections (NULL, !command_line.relax);
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 0f4a239..9905b02 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2007-09-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR binutils/3281
+ PR binutils/5037
+ * ld-elf/binutils.exp: Update "-z relro" tests to use relro1.s.
+ Add "-z relro" tests with relro2.s. Add "-z relro" tests with
+ TLS for objcopy.
+
+ * ld-elf/relro1.s: New file.
+ * ld-elf/relro2.s: Likewise.
+
2007-09-04 Mike Frysinger <vapier@gentoo.org>
* lib/ld-lib.exp (default_ld_compile): Pull in global CXXFLAGS and
diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp
index ba7ac36..92b7d27 100644
--- a/ld/testsuite/ld-elf/binutils.exp
+++ b/ld/testsuite/ld-elf/binutils.exp
@@ -104,24 +104,42 @@ 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 strip "-z relro" relro1
+binutils_test strip "-z relro -shared" relro1
+binutils_test objcopy "-z relro" relro1
+binutils_test objcopy "-z relro -shared" relro1
+if { ([istarget "i?86-*-elf*"]
+ || ([istarget "i?86-*-linux*"]
+ && ![istarget "*-*-*aout*"]
+ && ![istarget "*-*-*oldld*"])
+ || [istarget "x86_64-*-linux*"]
+ || [istarget "amd64-*-linux*"]) } {
+ binutils_test strip "-z relro -shared" relro2
+ binutils_test objcopy "-z relro -shared" relro2
+}
binutils_test objcopy "" tbss1
+binutils_test objcopy "-z relro" tbss1
binutils_test objcopy "-shared" tbss1
+binutils_test objcopy "-shared -z relro" tbss1
binutils_test objcopy "-z max-page-size=0x100000" tbss1
binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tbss1
binutils_test objcopy "" tdata1
+binutils_test objcopy "-z relro" tdata1
binutils_test objcopy "-shared" tdata1
+binutils_test objcopy "-shared -z relro" tdata1
binutils_test objcopy "-z max-page-size=0x100000" tdata1
binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tdata1
binutils_test objcopy "" tbss2
+binutils_test objcopy "-z relro" tbss2
binutils_test objcopy "-shared" tbss2
+binutils_test objcopy "-shared -z relro" tbss2
binutils_test objcopy "-z max-page-size=0x100000" tbss2
binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tbss2
-binutils_test objcopy "-z max-page-size=0x100000" tdata2
+
binutils_test objcopy "" tdata2
+binutils_test objcopy "-z relro" tdata2
binutils_test objcopy "-shared" tdata2
+binutils_test objcopy "-shared -z relro" tdata2
+binutils_test objcopy "-z max-page-size=0x100000" tdata2
binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tdata2
diff --git a/ld/testsuite/ld-elf/relro1.s b/ld/testsuite/ld-elf/relro1.s
new file mode 100644
index 0000000..76c956d
--- /dev/null
+++ b/ld/testsuite/ld-elf/relro1.s
@@ -0,0 +1,14 @@
+ .globl main
+ .globl start
+ .globl _start
+ .globl __start
+ .text
+main:
+start:
+_start:
+__start:
+ .long 0
+ .data
+ .long 0
+ .section .data.rel.ro,"aw",%progbits
+ .long 0
diff --git a/ld/testsuite/ld-elf/relro2.s b/ld/testsuite/ld-elf/relro2.s
new file mode 100644
index 0000000..0bbf366
--- /dev/null
+++ b/ld/testsuite/ld-elf/relro2.s
@@ -0,0 +1,5 @@
+ .text
+ .globl x
+ .type x, @function
+x:
+ jmp foo@PLT