[lld] r236729 - [ARM] Check overflow of R_ARM_PREL31

Denis Protivensky dprotivensky at accesssoftek.com
Thu May 7 07:05:30 PDT 2015


Author: denis-protivensky
Date: Thu May  7 09:05:30 2015
New Revision: 236729

URL: http://llvm.org/viewvc/llvm-project?rev=236729&view=rev
Log:
[ARM] Check overflow of R_ARM_PREL31

Modified:
    lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
    lld/trunk/test/elf/ARM/rel-arm-prel31.test

Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp?rev=236729&r1=236728&r2=236729&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp Thu May  7 09:05:30 2015
@@ -92,7 +92,7 @@ static Reference::Addend readAddend(cons
   case R_ARM_TLS_TPOFF32:
     return (int32_t)read32le(location);
   case R_ARM_PREL31:
-    return (int32_t)(read32le(location) & 0x7FFFFFFF);
+    return llvm::SignExtend64<31>(read32le(location) & 0x7FFFFFFF);
   case R_ARM_THM_CALL:
   case R_ARM_THM_JUMP24:
     return readAddend_THM_CALL(location);
@@ -180,6 +180,9 @@ static std::error_code relocR_ARM_PREL31
                                          bool addressesThumb) {
   uint64_t T = addressesThumb;
   uint32_t result = (uint32_t)(((S + A) | T) - P);
+  if (!llvm::isInt<31>((int32_t)result))
+    return make_out_of_range_reloc_error();
+
   const uint32_t mask = 0x7FFFFFFF;
   uint32_t rel31 = result & mask;
 

Modified: lld/trunk/test/elf/ARM/rel-arm-prel31.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/rel-arm-prel31.test?rev=236729&r1=236728&r2=236729&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/rel-arm-prel31.test (original)
+++ lld/trunk/test/elf/ARM/rel-arm-prel31.test Thu May  7 09:05:30 2015
@@ -1,7 +1,7 @@
 # Check handling of R_ARM_PREL31 relocation.
-# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: yaml2obj -format=elf -docnum=1 %s > %t-o.o
 # RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \
-# RUN: --noinhibit-exec %t-o.o -o %t
+# RUN: --noinhibit-exec --defsym=main=__gxx_personality_v0 %t-o.o -o %t
 # RUN: llvm-objdump -s -t %t | FileCheck %s
 
 # CHECK: Contents of section .ARM.extab:
@@ -9,6 +9,14 @@
 # CHECK: SYMBOL TABLE:
 # CHECK: 00400054 g     F .text	{{[0-9a-f]+}} __gxx_personality_v0
 
+# RUN: yaml2obj -format=elf -docnum=2 %s > %t-o.o
+# RUN: not lld -flavor gnu -target arm -m armelf_linux_eabi -Bstatic \
+# RUN: --noinhibit-exec --defsym=main=__gxx_personality_v0 %t-o.o -o %t 2> %t-error
+# RUN: FileCheck -check-prefix=OVERFLOW %s < %t-error
+
+# OVERFLOW: Relocation out of range {{.*}} (R_ARM_PREL31)
+
+# good.o
 ---
 FileHeader:
   Class:           ELFCLASS32
@@ -43,5 +51,40 @@ Symbols:
       Type:            STT_FUNC
       Section:         .text
       Value:           0x1
-...
 
+# overflow.o
+---
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_ARM
+  Flags:           [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:            .ARM.extab
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC ]
+    AddressAlign:    0x4
+    Content:         0000004084019701B0B0B008FFFF01080E2432003A040000
+  - Name:            .rel.ARM.extab
+    Type:            SHT_REL
+    Link:            .symtab
+    AddressAlign:    0x4
+    Info:            .ARM.extab
+    Relocations:
+      - Offset:          0
+        Symbol:          __gxx_personality_v0
+        Type:            R_ARM_PREL31
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x4
+    Content:         80B400AF00231846BD465DF8047B704780B582B000AF3B1D1846FFF7FEFFFFF7FEFFFFF7FEFF0420FFF7FEFF0346184601230360002240F20001C0F20001FFF7FEFF3B1D1846FFF7FEFFFFF7FEFF00BF
+Symbols:
+  Local:
+  Global:
+    - Name:            __gxx_personality_v0
+      Type:            STT_FUNC
+      Section:         .text
+      Value:           0x1
+...





More information about the llvm-commits mailing list