This is the mail archive of the binutils-cvs@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]

[binutils-gdb] ld: add an error in case of address space overflow.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d40e34db392f834793fb9af487121776b4cec6e7

commit d40e34db392f834793fb9af487121776b4cec6e7
Author: Tristan Gingold <gingold@adacore.com>
Date:   Fri Mar 10 15:16:19 2017 +0100

    ld: add an error in case of address space overflow.
    
    ld/
    	* ldlang.c (lang_check_section_addresses): Check for address space
    	overflow.
    	* testsuite/ld-checks/checks.exp (overflow_check): New procedure
    	* testsuite/ld-checks/over.s: New test source.
    	* testsuite/ld-checks/over.d: New test.
    	* testsuite/ld-checks/over2.s: New test source.
    	* testsuite/ld-checks/over2.d: New test.

Diff:
---
 ld/ChangeLog                      | 10 ++++++++++
 ld/ldlang.c                       | 20 ++++++++++++++++++++
 ld/testsuite/ld-checks/checks.exp | 13 +++++++++++++
 ld/testsuite/ld-checks/over.d     |  4 ++++
 ld/testsuite/ld-checks/over.s     |  7 +++++++
 ld/testsuite/ld-checks/over2.d    |  8 ++++++++
 ld/testsuite/ld-checks/over2.s    |  4 ++++
 7 files changed, 66 insertions(+)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 44e6895..c164710 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2017-03-13  Tristan Gingold  <gingold@adacore.com>
+
+	* ldlang.c (lang_check_section_addresses): Check for address space
+	overflow.
+	* testsuite/ld-checks/checks.exp (overflow_check): New procedure
+	* testsuite/ld-checks/over.s: New test source.
+	* testsuite/ld-checks/over.d: New test.
+	* testsuite/ld-checks/over2.s: New test source.
+	* testsuite/ld-checks/over2.d: New test.
+
 2017-03-13  Alexey Neyman  <stilor@att.net>
 
 	* emulparams/elf32ppccommon.sh (LIBPATH_SUFFIX): Set from target
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 6011a00..a0638ea 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4768,6 +4768,7 @@ lang_check_section_addresses (void)
   asection *s, *p;
   struct check_sec *sections;
   size_t i, count;
+  bfd_vma addr_mask;
   bfd_vma s_start;
   bfd_vma s_end;
   bfd_vma p_start = 0;
@@ -4775,6 +4776,25 @@ lang_check_section_addresses (void)
   lang_memory_region_type *m;
   bfd_boolean overlays;
 
+  /* Detect address space overflow.  */
+  addr_mask = ((bfd_vma) 1 <<
+	       (bfd_arch_bits_per_address (link_info.output_bfd) - 1)) - 1;
+  addr_mask = (addr_mask << 1) + 1;
+  for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
+    {
+      s_end = (s->vma + s->size) & addr_mask;
+      if (s_end != 0 && s_end < s->vma)
+	einfo (_("%X%P: section %s VMA wraps around address space\n"),
+	       s->name);
+      else
+	{
+	  s_end = (s->lma + s->size) & addr_mask;
+	  if (s_end != 0 && s_end < s->lma)
+	    einfo (_("%X%P: section %s LMA wraps around address space\n"),
+		   s->name);
+	}
+    }
+
   if (bfd_count_sections (link_info.output_bfd) <= 1)
     return;
 
diff --git a/ld/testsuite/ld-checks/checks.exp b/ld/testsuite/ld-checks/checks.exp
index b1c8454..782f50a 100644
--- a/ld/testsuite/ld-checks/checks.exp
+++ b/ld/testsuite/ld-checks/checks.exp
@@ -78,4 +78,17 @@ proc section_check {} {
     }
 }
 
+proc overflow_check {} {
+    # Test only on some 32-bit targets that are often tested
+    if { ![istarget i?86-*-*]
+	 && ![istarget powerpc-*-*]
+	 && ![istarget arm*-*-*] } {
+	return
+    }
+
+    run_dump_test "over"
+    run_dump_test "over2"
+}
+
 section_check
+overflow_check
diff --git a/ld/testsuite/ld-checks/over.d b/ld/testsuite/ld-checks/over.d
new file mode 100644
index 0000000..e34bea9
--- /dev/null
+++ b/ld/testsuite/ld-checks/over.d
@@ -0,0 +1,4 @@
+#name: section size overflow
+#source: over.s
+#ld: -Ttext=0xfffffffc
+#error: .* section .text VMA wraps around address space
diff --git a/ld/testsuite/ld-checks/over.s b/ld/testsuite/ld-checks/over.s
new file mode 100644
index 0000000..7f8d4b5
--- /dev/null
+++ b/ld/testsuite/ld-checks/over.s
@@ -0,0 +1,7 @@
+	.text
+	.globl _start
+_start:
+	.long 0
+	.long 0
+	.long 0
+	.long 0
diff --git a/ld/testsuite/ld-checks/over2.d b/ld/testsuite/ld-checks/over2.d
new file mode 100644
index 0000000..511b917
--- /dev/null
+++ b/ld/testsuite/ld-checks/over2.d
@@ -0,0 +1,8 @@
+#name: section size overflow
+#source: over2.s
+#ld: -Ttext=0xfffffffc
+#nm: -n
+
+#...
+fffffffc T _start
+#pass
diff --git a/ld/testsuite/ld-checks/over2.s b/ld/testsuite/ld-checks/over2.s
new file mode 100644
index 0000000..dc6de0e
--- /dev/null
+++ b/ld/testsuite/ld-checks/over2.s
@@ -0,0 +1,4 @@
+	.text
+	.globl _start
+_start:
+	.long 0


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