summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
authorDenis Protivensky <dprotivensky@accesssoftek.com>2015-05-08 12:34:43 +0000
committerDenis Protivensky <dprotivensky@accesssoftek.com>2015-05-08 12:34:43 +0000
commita0cffffcfab362d9a3c192b8b73ae3da098e8ac5 (patch)
tree47bd6fa154831819f2d67b95044aa322b35c0490 /lld
parent159a49e5d6bd0f7a53732ee511830835f65fdae9 (diff)
downloadbcm5719-llvm-a0cffffcfab362d9a3c192b8b73ae3da098e8ac5.tar.gz
bcm5719-llvm-a0cffffcfab362d9a3c192b8b73ae3da098e8ac5.zip
[ARM] Check overflow of R_ARM_THM_CALL/JUMP24
llvm-svn: 236839
Diffstat (limited to 'lld')
-rw-r--r--lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp4
-rw-r--r--lld/test/elf/ARM/rel-thm-call.test57
-rw-r--r--lld/test/elf/ARM/rel-thm-jump24.test55
3 files changed, 114 insertions, 2 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
index 0c8d3591d3c..665fcdd7213 100644
--- a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
+++ b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
@@ -200,6 +200,10 @@ static std::error_code relocR_ARM_PREL31(uint8_t *location, uint64_t P,
/// \brief Relocate B/BL instructions. useJs defines whether J1 & J2 are used
static std::error_code relocR_ARM_THM_B_L(uint8_t *location, uint32_t result,
bool useJs) {
+ if ((useJs && !llvm::isInt<25>((int32_t)result)) ||
+ (!useJs && !llvm::isInt<23>((int32_t)result)))
+ return make_out_of_range_reloc_error();
+
result = (result & 0x01FFFFFE) >> 1;
const uint16_t imm10 = (result >> 11) & 0x3FF;
diff --git a/lld/test/elf/ARM/rel-thm-call.test b/lld/test/elf/ARM/rel-thm-call.test
index b9bf8cefc0b..b0e15e713f5 100644
--- a/lld/test/elf/ARM/rel-thm-call.test
+++ b/lld/test/elf/ARM/rel-thm-call.test
@@ -1,5 +1,5 @@
# Check handling of R_ARM_THM_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: 00400080 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_THM_CALL)
+
+# good.o
---
FileHeader:
Class: ELFCLASS32
@@ -58,4 +66,51 @@ Symbols:
Section: .text
Value: 0x000000000000000D
Size: 0x000000000000000E
+
+# 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: 80B400AFBD465DF8047B704780B500AF00F400D00023184680BD00BF
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000010
+ Symbol: _Z1fv
+ Type: R_ARM_THM_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
+ Value: 0x0000000000000001
+ Size: 0x000000000000000C
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x000000000000000D
+ Size: 0x000000000000000E
...
diff --git a/lld/test/elf/ARM/rel-thm-jump24.test b/lld/test/elf/ARM/rel-thm-jump24.test
index 6c9b63447c9..2d8f03a7e0f 100644
--- a/lld/test/elf/ARM/rel-thm-jump24.test
+++ b/lld/test/elf/ARM/rel-thm-jump24.test
@@ -1,5 +1,5 @@
# Check handling of R_ARM_THM_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: 00400084 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_THM_JUMP24)
+
+# good.o
---
FileHeader:
Class: ELFCLASS32
@@ -56,4 +64,49 @@ Symbols:
Type: STT_FUNC
Section: .text
Value: 0x0000000000000011
+
+# 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: 80B400AF00231846BD465DF8047B704780B500AF00F400900346184680BD00BF
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000014
+ Symbol: _Z1fv
+ Type: R_ARM_THM_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
+ Value: 0x0000000000000001
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000011
...
OpenPOWER on IntegriCloud