Add a more helpful warning message to explain why some AArch64 relocations can overflow.
authorNick Clifton <nickc@redhat.com>
Tue, 9 Feb 2016 09:56:21 +0000 (09:56 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 9 Feb 2016 10:47:54 +0000 (10:47 +0000)
bfd * elfnn-aarch64.c (elfNN_aarch64_relocate_section): Add a more
helpful warning message to explain why certain AArch64 relocs
might overflow.

ld * testsuite/ld-aarch64/reloc-overflow-bad.d: New test.
* testsuite/ld-aarch64/reloc-overflow-1.s: New source file.
* testsuite/ld-aarch64/reloc-overflow-2.s: New source file.
* testsuite/ld-aarch64/aarch64-elf.exp: Run the new test.

bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/reloc-overflow-1.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/reloc-overflow-2.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/reloc-overflow-bad.d [new file with mode: 0644]

index 88c663c19a3235e26941bf95f253ec7250b4b4a6..3c2e8cbdba6c8675b353d462d0f14d9463c23174 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-09  Nick Clifton  <nickc@redhat.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_relocate_section): Add a more
+       helpful warning message to explain why certain AArch64 relocs
+       might overflow.
+
 2016-02-05  Simon Marchi  <simon.marchi@ericsson.com>
 
        * pe-mips.c (coff_mips_reloc): Fix formatting.
index 292470df73ed97768880b172cf7e995cbb31dc4f..99acab4e7d0b60223e8a2984be1355c64f76e225 100644 (file)
@@ -6405,10 +6405,6 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
          break;
        }
 
-      if (!save_addend)
-       addend = 0;
-
-
       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
          because such sections are not SEC_ALLOC and thus ld.so will
          not process them.  */
@@ -6448,6 +6444,34 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
                     name, input_bfd, input_section, rel->r_offset);
                  return FALSE;
                }
+             /* Overflow can occur when a variable is referenced with a type
+                that has a larger alignment than the type with which it was
+                declared. eg:
+                  file1.c: extern int foo; int a (void) { return foo; }
+                  file2.c: char bar, foo, baz;
+                If the variable is placed into a data section at an offset
+                that is incompatible with the larger alignment requirement
+                overflow will occur.  (Strictly speaking this is not overflow
+                but rather an alignment problem, but the bfd_reloc_ error
+                enum does not have a value to cover that situation).
+
+                Try to catch this situation here and provide a more helpful
+                error message to the user.  */
+             if (addend & ((1 << howto->rightshift) - 1)
+                 /* FIXME: Are we testing all of the appropriate reloc
+                    types here ?  */
+                 && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
+                     || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
+               {
+                 info->callbacks->warning
+                   (info, _("One possible cause of this error is that the \
+symbol is being referenced in the indicated code as if it had a larger \
+alignment than was declared where it was defined."),
+                    name, input_bfd, input_section, rel->r_offset);
+               }
              break;
 
            case bfd_reloc_undefined:
@@ -6482,6 +6506,9 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
              break;
            }
        }
+
+      if (!save_addend)
+       addend = 0;
     }
 
   return TRUE;
index 584a8dd09d9c79210ee356fa5484833f3267b5a3..fb4d31f53564ee08b49b6137803fd109991eb5b5 100644 (file)
@@ -1,3 +1,10 @@
+2016-02-09  Nick Clifton  <nickc@redhat.com>
+
+       * testsuite/ld-aarch64/reloc-overflow-bad.d: New test.
+       * testsuite/ld-aarch64/reloc-overflow-1.s: New source file.
+       * testsuite/ld-aarch64/reloc-overflow-2.s: New source file.
+       * testsuite/ld-aarch64/aarch64-elf.exp: Run the new test.
+
 2016-02-04  Nick Clifton  <nickc@redhat.com>
 
        * testsuite/ld-arm/arm-elf.exp: Remove ARM NOREAD section tests.
index 939539ec809a51b9371d9c8bf66e2bbe6ddc4093..d0b33cf5a466690ccb2f6e6d0e4a23dffcaae3b2 100644 (file)
@@ -159,6 +159,8 @@ run_dump_test "emit-relocs-537"
 run_dump_test "emit-relocs-537-overflow"
 run_dump_test "emit-relocs-538"
 
+run_dump_test "reloc-overflow-bad"
+
 # test addend correctness when --emit-relocs specified for non-relocatable obj.
 run_dump_test "emit-relocs-local-addend"
 # test addend correctness when -r specified.
@@ -281,9 +283,9 @@ run_dump_test "plt_mapping_symbol"
 
 set aarch64elflinktests {
   {"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s}
-  {} "copy-reloc-so.so"}
+    {} "copy-reloc-so.so"}
   {"ld-aarch64/exe with copy relocation" "-e0 tmpdir/copy-reloc-so.so" "" ""
-  {copy-reloc-exe.s} {{objdump -R copy-reloc.d}} "copy-reloc"}
+    {copy-reloc-exe.s} {{objdump -R copy-reloc.d}} "copy-reloc"}
 }
 
 run_ld_link_tests $aarch64elflinktests
diff --git a/ld/testsuite/ld-aarch64/reloc-overflow-1.s b/ld/testsuite/ld-aarch64/reloc-overflow-1.s
new file mode 100644 (file)
index 0000000..9f85fd8
--- /dev/null
@@ -0,0 +1,14 @@
+        .file   "1.c"
+        .text
+        .align  2
+        .p2align 3,,7
+        .global dec
+        .arch armv8-a+fp+simd
+        //.tune generic
+        .type   dec, %function
+dec:
+        adrp    x0, var_2
+        ldr     w0, [x0, #:lo12:var_2]
+        ret
+        .size   dec, .-dec
+        .ident  "GCC: (GNU) 6.0.0 20160208 (experimental) [trunk revision 233206]"
diff --git a/ld/testsuite/ld-aarch64/reloc-overflow-2.s b/ld/testsuite/ld-aarch64/reloc-overflow-2.s
new file mode 100644 (file)
index 0000000..4956f01
--- /dev/null
@@ -0,0 +1,5 @@
+        .file   "2.c"
+        .comm   var_3,1,1
+        .comm   var_2,1,1
+        .comm   var_1,1,1
+        .ident  "GCC: (GNU) 6.0.0 20160208 (experimental) [trunk revision 233206]"
diff --git a/ld/testsuite/ld-aarch64/reloc-overflow-bad.d b/ld/testsuite/ld-aarch64/reloc-overflow-bad.d
new file mode 100644 (file)
index 0000000..39f7e31
--- /dev/null
@@ -0,0 +1,4 @@
+#source: reloc-overflow-1.s
+#source: reloc-overflow-2.s
+#ld: -e0
+#error: .*One possible cause.*