[lld] r236841 - [ARM] Check overflow of R_ARM_CALL/JUMP24

Denis Protivensky dprotivensky at accesssoftek.com
Fri May 8 05:36:41 PDT 2015


Author: denis-protivensky
Date: Fri May  8 07:36:40 2015
New Revision: 236841

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

Modified:
    lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
    lld/trunk/test/elf/ARM/rel-arm-call.test
    lld/trunk/test/elf/ARM/rel-arm-jump24.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=236841&r1=236840&r2=236841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp Fri May  8 07:36:40 2015
@@ -313,6 +313,9 @@ static std::error_code relocR_ARM_CALL(u
   const bool switchMode = addressesThumb;
 
   uint32_t result = (uint32_t)(((S + A) | T) - P);
+  if (!llvm::isInt<26>((int32_t)result))
+    return make_out_of_range_reloc_error();
+
   const uint32_t imm24 = (result & 0x03FFFFFC) >> 2;
 
   DEBUG(llvm::dbgs() << "\t\tHandle " << LLVM_FUNCTION_NAME << " -";
@@ -337,6 +340,9 @@ static std::error_code relocR_ARM_JUMP24
                                          bool addressesThumb) {
   uint64_t T = addressesThumb;
   uint32_t result = (uint32_t)(((S + A) | T) - P);
+  if (!llvm::isInt<26>((int32_t)result))
+    return make_out_of_range_reloc_error();
+
   const uint32_t imm24 = (result & 0x03FFFFFC) >> 2;
 
   DEBUG(llvm::dbgs() << "\t\tHandle " << LLVM_FUNCTION_NAME << " -";

Modified: lld/trunk/test/elf/ARM/rel-arm-call.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/rel-arm-call.test?rev=236841&r1=236840&r2=236841&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/rel-arm-call.test (original)
+++ lld/trunk/test/elf/ARM/rel-arm-call.test Fri May  8 07:36:40 2015
@@ -1,5 +1,5 @@
 # Check handling of R_ARM_CALL 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: llvm-objdump -s -t %t | FileCheck %s
@@ -13,6 +13,14 @@
 # CHECK: 00400074 g     F .text  {{[0-9a-f]+}} _Z1fv
 # CHECK: 00400088 g     F .text  {{[0-9a-f]+}} main
 
+# 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 %t-o.o -o %t 2> %t-error
+# RUN: FileCheck -check-prefix=OVERFLOW %s < %t-error
+
+# OVERFLOW: Relocation out of range {{.*}} (R_ARM_CALL)
+
+# good.o
 ---
 FileHeader:
   Class:           ELFCLASS32
@@ -29,6 +37,52 @@ Sections:
   - Name:            .rel.text
     Type:            SHT_REL
     Link:            .symtab
+    AddressAlign:    0x0000000000000004
+    Info:            .text
+    Relocations:
+      - Offset:          0x000000000000001C
+        Symbol:          _Z1fv
+        Type:            R_ARM_CALL
+        Addend:          0
+  - Name:            .data
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000001
+    Content:         ''
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000001
+    Content:         ''
+Symbols:
+  Global:
+    - Name:            _Z1fv
+      Type:            STT_FUNC
+      Section:         .text
+      Size:            0x0000000000000014
+    - Name:            main
+      Type:            STT_FUNC
+      Section:         .text
+      Value:           0x0000000000000014
+      Size:            0x0000000000000018
+
+# overflow.o
+---
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_ARM
+  Flags:           [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         04B02DE500B08DE200D04BE204B09DE41EFF2FE100482DE904B08DE2000080EB0030A0E30300A0E10088BDE8
+  - Name:            .rel.text
+    Type:            SHT_REL
+    Link:            .symtab
     AddressAlign:    0x0000000000000004
     Info:            .text
     Relocations:

Modified: lld/trunk/test/elf/ARM/rel-arm-jump24.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/rel-arm-jump24.test?rev=236841&r1=236840&r2=236841&view=diff
==============================================================================
--- lld/trunk/test/elf/ARM/rel-arm-jump24.test (original)
+++ lld/trunk/test/elf/ARM/rel-arm-jump24.test Fri May  8 07:36:40 2015
@@ -1,5 +1,5 @@
 # Check handling of R_ARM_JUMP24 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: llvm-objdump -s -t %t | FileCheck %s
@@ -13,6 +13,14 @@
 # CHECK: 00400074 g     F .text  {{[0-9a-f]+}} _Z1fv
 # CHECK: 00400090 g     F .text  {{[0-9a-f]+}} main
 
+# 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 %t-o.o -o %t 2> %t-error
+# RUN: FileCheck -check-prefix=OVERFLOW %s < %t-error
+
+# OVERFLOW: Relocation out of range {{.*}} (R_ARM_JUMP24)
+
+# good.o
 ---
 FileHeader:
   Class:           ELFCLASS32
@@ -29,6 +37,50 @@ Sections:
   - Name:            .rel.text
     Type:            SHT_REL
     Link:            .symtab
+    AddressAlign:    0x0000000000000004
+    Info:            .text
+    Relocations:
+      - Offset:          0x0000000000000024
+        Symbol:          _Z1fv
+        Type:            R_ARM_JUMP24
+        Addend:          0
+  - Name:            .data
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000001
+    Content:         ''
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x0000000000000001
+    Content:         ''
+Symbols:
+  Global:
+    - Name:            _Z1fv
+      Type:            STT_FUNC
+      Section:         .text
+    - Name:            main
+      Type:            STT_FUNC
+      Section:         .text
+      Value:           0x000000000000001C
+
+# overflow.o
+---
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_ARM
+  Flags:           [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE100482DE904B08DE2000080EA0030A0E10300A0E10088BDE8
+  - Name:            .rel.text
+    Type:            SHT_REL
+    Link:            .symtab
     AddressAlign:    0x0000000000000004
     Info:            .text
     Relocations:





More information about the llvm-commits mailing list