Blame SOURCES/binutils-2.25.1-aarch64-overflow-warnings.patch

4910d4
diff -rup binutils-2.25.1.orig/ld/testsuite/ld-aarch64/aarch64-elf.exp binutils-2.25.1/ld/testsuite/ld-aarch64/aarch64-elf.exp
4910d4
--- binutils-2.25.1.orig/ld/testsuite/ld-aarch64/aarch64-elf.exp	2016-02-09 10:10:22.885172174 +0000
4910d4
+++ binutils-2.25.1/ld/testsuite/ld-aarch64/aarch64-elf.exp	2016-02-09 10:10:31.657218088 +0000
4910d4
@@ -99,6 +99,8 @@ run_dump_test "emit-relocs-309-low-bad"
4910d4
 run_dump_test "emit-relocs-311"
4910d4
 run_dump_test "emit-relocs-312"
4910d4
 
4910d4
+run_dump_test "reloc-overflow-bad"
4910d4
+
4910d4
 # test addend correctness when --emit-relocs specified for non-relocatable obj.
4910d4
 run_dump_test "emit-relocs-local-addend"
4910d4
 # test addend correctness when -r specified.
4910d4
@@ -185,9 +187,9 @@ run_dump_test "dt_textrel"
4910d4
 
4910d4
 set aarch64elflinktests {
4910d4
   {"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s}
4910d4
-  {} "copy-reloc-so.so"}
4910d4
+    {} "copy-reloc-so.so"}
4910d4
   {"ld-aarch64/exe with copy relocation" "-e0 tmpdir/copy-reloc-so.so" "" ""
4910d4
-  {copy-reloc-exe.s} {{objdump -R copy-reloc.d}} "copy-reloc"}
4910d4
+    {copy-reloc-exe.s} {{objdump -R copy-reloc.d}} "copy-reloc"}
4910d4
 }
4910d4
 
4910d4
 run_ld_link_tests $aarch64elflinktests
4910d4
--- /dev/null	2016-02-09 07:51:32.551961845 +0000
4910d4
+++ binutils-2.25.1/ld/testsuite/ld-aarch64/reloc-overflow-bad.d	2016-02-09 10:10:31.658218093 +0000
4910d4
@@ -0,0 +1,4 @@
4910d4
+#source: reloc-overflow-1.s
4910d4
+#source: reloc-overflow-2.s
4910d4
+#ld: -e0
4910d4
+#error: .*One possible cause.*
4910d4
--- /dev/null	2016-02-09 07:51:32.551961845 +0000
4910d4
+++ binutils-2.25.1/ld/testsuite/ld-aarch64/reloc-overflow-1.s	2016-02-09 10:10:31.658218093 +0000
4910d4
@@ -0,0 +1,14 @@
4910d4
+        .file   "1.c"
4910d4
+        .text
4910d4
+        .align  2
4910d4
+        .p2align 3,,7
4910d4
+        .global dec
4910d4
+        .arch armv8-a+fp+simd
4910d4
+        //.tune generic
4910d4
+        .type   dec, %function
4910d4
+dec:
4910d4
+        adrp    x0, var_2
4910d4
+        ldr     w0, [x0, #:lo12:var_2]
4910d4
+        ret
4910d4
+        .size   dec, .-dec
4910d4
+        .ident  "GCC: (GNU) 6.0.0 20160208 (experimental) [trunk revision 233206]"
4910d4
--- /dev/null	2016-02-09 07:51:32.551961845 +0000
4910d4
+++ binutils-2.25.1/ld/testsuite/ld-aarch64/reloc-overflow-2.s	2016-02-09 10:10:31.658218093 +0000
4910d4
@@ -0,0 +1,5 @@
4910d4
+        .file   "2.c"
4910d4
+        .comm   var_3,1,1
4910d4
+        .comm   var_2,1,1
4910d4
+        .comm   var_1,1,1
4910d4
+        .ident  "GCC: (GNU) 6.0.0 20160208 (experimental) [trunk revision 233206]"
4910d4
--- binutils-2.25.1.orig/bfd/elfnn-aarch64.c	2016-02-09 10:10:22.528170305 +0000
4910d4
+++ binutils-2.25.1/bfd/elfnn-aarch64.c	2016-02-09 10:21:25.663638222 +0000
4910d4
@@ -5134,10 +5134,6 @@ elfNN_aarch64_relocate_section (bfd *out
4910d4
 	  break;
4910d4
 	}
4910d4
 
4910d4
-      if (!save_addend)
4910d4
-	addend = 0;
4910d4
-
4910d4
-
4910d4
       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4910d4
          because such sections are not SEC_ALLOC and thus ld.so will
4910d4
          not process them.  */
4910d4
@@ -5157,6 +5153,9 @@ elfNN_aarch64_relocate_section (bfd *out
4910d4
 
4910d4
       if (r != bfd_reloc_ok && r != bfd_reloc_continue)
4910d4
 	{
4910d4
+	  bfd_reloc_code_real_type real_r_type
4910d4
+	    = elfNN_aarch64_bfd_reloc_from_type (r_type);
4910d4
+
4910d4
 	  switch (r)
4910d4
 	    {
4910d4
 	    case bfd_reloc_overflow:
4910d4
@@ -5170,6 +5169,35 @@ elfNN_aarch64_relocate_section (bfd *out
4910d4
 			 (bfd_vma) 0, input_bfd, input_section,
4910d4
 			 rel->r_offset))))
4910d4
 		return FALSE;
4910d4
+
4910d4
+	      /* Overflow can occur when a variable is referenced with a type
4910d4
+		 that has a larger alignment than the type with which it was
4910d4
+		 declared. eg:
4910d4
+		   file1.c: extern int foo; int a (void) { return foo; }
4910d4
+		   file2.c: char bar, foo, baz;
4910d4
+		 If the variable is placed into a data section at an offset
4910d4
+		 that is incompatible with the larger alignment requirement
4910d4
+		 overflow will occur.  (Strictly speaking this is not overflow
4910d4
+		 but rather an alignment problem, but the bfd_reloc_ error
4910d4
+		 enum does not have a value to cover that situation).
4910d4
+
4910d4
+		 Try to catch this situation here and provide a more helpful
4910d4
+		 error message to the user.  */
4910d4
+	      if (addend & ((1 << howto->rightshift) - 1)
4910d4
+		  /* FIXME: Are we testing all of the appropriate reloc
4910d4
+		     types here ?  */
4910d4
+		  && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
4910d4
+		      || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
4910d4
+		      || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
4910d4
+		      || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
4910d4
+		      || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
4910d4
+		{
4910d4
+		  info->callbacks->warning
4910d4
+		    (info, _("One possible cause of this error is that the \
4910d4
+symbol is being referenced in the indicated code as if it had a larger \
4910d4
+alignment than was declared where it was defined."),
4910d4
+		     name, input_bfd, input_section, rel->r_offset);
4910d4
+		}
4910d4
 	      break;
4910d4
 
4910d4
 	    case bfd_reloc_undefined:
4910d4
@@ -5204,6 +5232,9 @@ elfNN_aarch64_relocate_section (bfd *out
4910d4
 	      break;
4910d4
 	    }
4910d4
 	}
4910d4
+
4910d4
+      if (!save_addend)
4910d4
+	addend = 0;
4910d4
     }
4910d4
 
4910d4
   return TRUE;
4910d4
@@ -7777,7 +7808,6 @@ elfNN_aarch64_finish_dynamic_sections (b
4910d4
 
4910d4
 	  bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
4910d4
 	}
4910d4
-
4910d4
     }
4910d4
 
4910d4
   /* Fill in the special first entry in the procedure linkage table.  */