[PATCH] D38614: [ELF][MIPS] Check for overflow when writing R_MIPS_CALL16 and R_MIPS_TLS_GOTTPREL

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 09:17:49 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL315073: [ELF][MIPS] Check for overflow when writing R_MIPS_CALL16 and… (authored by arichardson).

Repository:
  rL LLVM

https://reviews.llvm.org/D38614

Files:
  lld/trunk/ELF/Arch/Mips.cpp
  lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s


Index: lld/trunk/ELF/Arch/Mips.cpp
===================================================================
--- lld/trunk/ELF/Arch/Mips.cpp
+++ lld/trunk/ELF/Arch/Mips.cpp
@@ -501,21 +501,21 @@
       writeMicroRelocation32<E>(Loc, Val, 16, 0);
     }
     break;
+  case R_MIPS_CALL16:
   case R_MIPS_GOT_DISP:
   case R_MIPS_GOT_PAGE:
   case R_MIPS_GPREL16:
   case R_MIPS_TLS_GD:
+  case R_MIPS_TLS_GOTTPREL:
   case R_MIPS_TLS_LDM:
     checkInt<16>(Loc, Val, Type);
     LLVM_FALLTHROUGH;
-  case R_MIPS_CALL16:
   case R_MIPS_CALL_LO16:
   case R_MIPS_GOT_LO16:
   case R_MIPS_GOT_OFST:
   case R_MIPS_LO16:
   case R_MIPS_PCLO16:
   case R_MIPS_TLS_DTPREL_LO16:
-  case R_MIPS_TLS_GOTTPREL:
   case R_MIPS_TLS_TPREL_LO16:
     writeRelocation<E>(Loc, Val, 16, 0);
     break;
Index: lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s
===================================================================
--- lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s
+++ lld/trunk/test/ELF/mips-out-of-bounds-call16-reloc.s
@@ -0,0 +1,29 @@
+# Check that we create an error on an out-of-bounds R_MIPS_CALL_16
+
+# REQUIRES: mips
+# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o
+# RUN: not ld.lld %t1.o -o %t.exe 2>&1 | FileCheck %s
+
+# CHECK: relocation R_MIPS_CALL16 out of range
+
+.macro generate_values
+  .irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+    .irp j, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+      .irp k, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+        .irp l, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+          .text
+          .globl sym_\i\j\k\l
+          sym_\i\j\k\l:
+          nop
+          lw $25,%call16(sym_\i\j\k\l)($28)
+        .endr
+      .endr
+    .endr
+  .endr
+.endm
+
+generate_values
+
+.globl __start
+__start:
+  nop


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38614.118014.patch
Type: text/x-patch
Size: 1746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171006/923f6148/attachment.bin>


More information about the llvm-commits mailing list