MIPS/LD: Fix memory fault linking non-PIC object in to shared library
authorFaraz Shahbazker <fshahbazker@wavecomp.com>
Sat, 18 May 2019 08:19:03 +0000 (01:19 -0700)
committerFaraz Shahbazker <fshahbazker@wavecomp.com>
Tue, 21 May 2019 18:55:08 +0000 (11:55 -0700)
bfd/
* elfxx-mips.c (_bfd_mips_elf_check_relocs): Add NULL pointer
checks.  Search the RELA table for n64 relocations.

ld/
* testsuite/ld-mips-elf/pic-reloc-5.d: New test.
* testsuite/ld-mips-elf/pic-reloc-6.d: New test.
* testsuite/ld-mips-elf/pic-reloc-7.d: New test.
* testsuite/ld-mips-elf/pic-reloc-5.s: New test source.
* testsuite/ld-mips-elf/pic-reloc-6.s: New test source.
* testsuite/ld-mips-elf/pic-reloc-7.s: New test source.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.

bfd/ChangeLog
bfd/elfxx-mips.c
ld/ChangeLog
ld/testsuite/ld-mips-elf/mips-elf.exp
ld/testsuite/ld-mips-elf/pic-reloc-5.d [new file with mode: 0644]
ld/testsuite/ld-mips-elf/pic-reloc-5.s [new file with mode: 0644]
ld/testsuite/ld-mips-elf/pic-reloc-6.d [new file with mode: 0644]
ld/testsuite/ld-mips-elf/pic-reloc-6.s [new file with mode: 0644]
ld/testsuite/ld-mips-elf/pic-reloc-7.d [new file with mode: 0644]
ld/testsuite/ld-mips-elf/pic-reloc-7.s [new file with mode: 0644]

index deca7784d398f224afc62667f089bed1beceecfa..4335227db6a7b84a2246f857249e46bf90aff66c 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-21  Faraz Shahbazker  <fshahbazker@wavecomp.com>
+
+       * elfxx-mips.c (_bfd_mips_elf_check_relocs): Add NULL pointer
+       checks.  Search the RELA table for n64 relocations.
+
 2019-05-21  Matthew Fortune  <matthew.fortune@mips.com>
            Faraz Shahbazker  <fshahbazker@wavecomp.com>
 
index 8c1ad72aa8388362a5135bf2e8b1436a08265344..28e95bcc08a70d390b76be46b4d6714a57e8c05a 100644 (file)
@@ -9115,7 +9115,7 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                break;
 
              /* Likewise an absolute symbol.  */
-             if (bfd_is_abs_symbol (&h->root))
+             if (h != NULL && bfd_is_abs_symbol (&h->root))
                break;
 
              /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
@@ -9133,13 +9133,16 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
            case R_MIPS16_26:
            case R_MIPS_26:
            case R_MICROMIPS_26_S1:
-             howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, FALSE);
-             info->callbacks->einfo
-               /* xgettext:c-format */
-               (_("%X%H: relocation %s against `%s' cannot be used"
-                  " when making a shared object; recompile with -fPIC\n"),
-                abfd, sec, rel->r_offset, howto->name,
-                (h) ? h->root.root.string : "a local symbol");
+             howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, r_type, NEWABI_P (abfd));
+             /* An error for unsupported relocations is raised as part
+                of the above search, so we can skip the following.  */
+             if (howto != NULL)
+               info->callbacks->einfo
+                 /* xgettext:c-format */
+                 (_("%X%H: relocation %s against `%s' cannot be used"
+                    " when making a shared object; recompile with -fPIC\n"),
+                  abfd, sec, rel->r_offset, howto->name,
+                  (h) ? h->root.root.string : "a local symbol");
              break;
            default:
              break;
index 6896a72be41eb04a595bef2e3a0d989ff95b3567..beba62e233da63151e932147477b2657a2a95966 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-21  Faraz Shahbazker  <fshahbazker@wavecomp.com>
+
+       * testsuite/ld-mips-elf/pic-reloc-5.d: New test.
+       * testsuite/ld-mips-elf/pic-reloc-6.d: New test.
+       * testsuite/ld-mips-elf/pic-reloc-7.d: New test.
+       * testsuite/ld-mips-elf/pic-reloc-5.s: New test source.
+       * testsuite/ld-mips-elf/pic-reloc-6.s: New test source.
+       * testsuite/ld-mips-elf/pic-reloc-7.s: New test source.
+       * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
+
 2019-05-21  Matthew Fortune  <matthew.fortune@mips.com>
            Faraz Shahbazker  <fshahbazker@wavecomp.com>
 
index cbbd9add6afec0bd8638871cc09e6a8d7c7b10b3..07d1dc3ecce19a7ace64f3dc6881162f4d515560 100644 (file)
@@ -1649,3 +1649,10 @@ run_dump_test "pic-reloc-1"
 run_dump_test "pic-reloc-2"
 run_dump_test "pic-reloc-3"
 run_dump_test "pic-reloc-4"
+run_dump_test_o32 "pic-reloc-5"
+run_dump_test_o32 "pic-reloc-5" [list [list name (microMIPS)] \
+                                     [list as "-mmicromips"]]
+run_dump_test_o32 "pic-reloc-6"
+run_dump_test_n64 "pic-reloc-7"
+run_dump_test_n64 "pic-reloc-7" [list [list name (microMIPS)] \
+                                     [list as "-mmicromips"]]
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-5.d b/ld/testsuite/ld-mips-elf/pic-reloc-5.d
new file mode 100644 (file)
index 0000000..1b9d07e
--- /dev/null
@@ -0,0 +1,6 @@
+#name: MIPS PIC relocation 5
+#ld: -shared -T pic-reloc-ordinary.ld
+#target: [check_shared_lib_support]
+#error: \A[^\n]*: in function `foo':\n
+#error:   \(\.text\+0x0\): relocation R_(MICRO|)MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC\n
+#error:   \(\.text\+0x8\): relocation R_(MICRO|)MIPS_HI16 against `bar' cannot be used when making a shared object; recompile with -fPIC\Z
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-5.s b/ld/testsuite/ld-mips-elf/pic-reloc-5.s
new file mode 100644 (file)
index 0000000..b8ebd8c
--- /dev/null
@@ -0,0 +1,10 @@
+       .text
+       .globl  foo
+       .ent    foo
+foo:
+$LCL:
+       lui     $2, %hi($LCL)
+       addiu   $2, %lo($LCL)
+       lui     $2, %hi(bar)
+       addiu   $2, %lo(bar)
+       .end    foo
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-6.d b/ld/testsuite/ld-mips-elf/pic-reloc-6.d
new file mode 100644 (file)
index 0000000..68be687
--- /dev/null
@@ -0,0 +1,7 @@
+#name: MIPS PIC relocation 6 (MIPS16)
+#ld: -shared -T pic-reloc-ordinary.ld
+#target: [check_shared_lib_support]
+#as: -mips16
+#error: \A[^\n]*: in function `foo':\n
+#error:   \(\.text\+0x0\): relocation R_MIPS16_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC\n
+#error:   \(\.text\+0x8\): relocation R_MIPS16_HI16 against `bar' cannot be used when making a shared object; recompile with -fPIC\Z
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-6.s b/ld/testsuite/ld-mips-elf/pic-reloc-6.s
new file mode 100644 (file)
index 0000000..777ea26
--- /dev/null
@@ -0,0 +1,10 @@
+       .text
+       .globl  foo
+       .ent    foo
+foo:
+$LCL:
+       li      $2, %hi($LCL)
+       addiu   $2, %lo($LCL)
+       li      $2, %hi(bar)
+       addiu   $2, %lo(bar)
+       .end    foo
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-7.d b/ld/testsuite/ld-mips-elf/pic-reloc-7.d
new file mode 100644 (file)
index 0000000..e5dfa58
--- /dev/null
@@ -0,0 +1,8 @@
+#name: MIPS PIC relocation 7
+#ld: -shared -T pic-reloc-ordinary.ld
+#target: [check_shared_lib_support]
+#error: \A[^\n]*: in function `foo':\n
+#error:   \(\.text\+0x0\): relocation R_(MICRO|)MIPS_HIGHEST against `a local symbol' cannot be used when making a shared object; recompile with -fPIC\n
+#error:   \(\.text\+0x4\): relocation R_(MICRO|)MIPS_HIGHER against `a local symbol' cannot be used when making a shared object; recompile with -fPIC\n
+#error:   \(\.text\+0x8\): relocation R_(MICRO|)MIPS_HIGHEST against `bar' cannot be used when making a shared object; recompile with -fPIC\n
+#error:   \(\.text\+0xc\): relocation R_(MICRO|)MIPS_HIGHER against `bar' cannot be used when making a shared object; recompile with -fPIC\Z
diff --git a/ld/testsuite/ld-mips-elf/pic-reloc-7.s b/ld/testsuite/ld-mips-elf/pic-reloc-7.s
new file mode 100644 (file)
index 0000000..3ad55f0
--- /dev/null
@@ -0,0 +1,10 @@
+       .text
+       .globl  foo
+       .ent    foo
+foo:
+$LCL:
+       lui     $2, %highest($LCL)
+       addiu   $2, %higher($LCL)
+       lui     $2, %highest(bar)
+       addiu   $2, %higher(bar)
+       .end    foo