diff options
-rw-r--r-- | lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp | 5 | ||||
-rw-r--r-- | lld/test/elf/ARM/rel-thm-jump11.test | 130 |
2 files changed, 104 insertions, 31 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp index 746934adba9..e16379f631f 100644 --- a/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp @@ -76,7 +76,7 @@ static Reference::Addend readAddend_THM_JUMP11(const uint8_t *location) { const auto value = read16le(location); const uint16_t imm11 = value & 0x7FF; - return llvm::SignExtend32<12>(imm11 << 1); + return llvm::SignExtend64<12>(imm11 << 1); } static Reference::Addend readAddend(const uint8_t *location, @@ -275,6 +275,9 @@ static std::error_code relocR_ARM_THM_JUMP11(uint8_t *location, uint64_t P, llvm::dbgs() << " P: 0x" << Twine::utohexstr(P); llvm::dbgs() << " result: 0x" << Twine::utohexstr(result) << "\n"); + if (!llvm::isInt<12>((int32_t)result)) + return make_out_of_range_reloc_error(); + // we cut off first bit because it is always 1 according to p. 4.5.3 result = (result & 0x0FFE) >> 1; return applyThumb16Reloc(location, result, 0x7FF); diff --git a/lld/test/elf/ARM/rel-thm-jump11.test b/lld/test/elf/ARM/rel-thm-jump11.test index 4998c2b96c9..f2e8b337c7d 100644 --- a/lld/test/elf/ARM/rel-thm-jump11.test +++ b/lld/test/elf/ARM/rel-thm-jump11.test @@ -1,5 +1,5 @@ # Check handling of R_ARM_THM_JUMP11 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 @@ -10,6 +10,14 @@ # CHECK: 00400138 g F .text 00000060 __gnu_h2f_internal # CHECK: 004001a4 g F .text 00000004 __gnu_h2f_alternative +# 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_JUMP11) + +# good.o --- FileHeader: Class: ELFCLASS32 @@ -59,42 +67,104 @@ Sections: Flags: [ SHF_WRITE, SHF_ALLOC ] AddressAlign: 0x0000000000000001 Content: '' - - Name: .comment +Symbols: + Local: + - Name: '$t' + Section: .text + - Name: __gnu_f2h_internal + Type: STT_FUNC + Section: .text + Value: 0x0000000000000001 + Size: 0x00000000000000C2 + Global: + - Name: __gnu_f2h_alternative + Type: STT_FUNC + Section: .text + Value: 0x000000000000012D + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_alternative + Type: STT_FUNC + Section: .text + Value: 0x0000000000000131 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_ieee + Type: STT_FUNC + Section: .text + Value: 0x0000000000000129 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: main + Type: STT_FUNC + Section: .text.startup + Value: 0x0000000000000001 + Size: 0x0000000000000006 + - Name: __gnu_f2h_ieee + Type: STT_FUNC + Section: .text + Value: 0x0000000000000125 + Size: 0x0000000000000004 + Visibility: STV_HIDDEN + - Name: __gnu_h2f_internal + Type: STT_FUNC + Section: .text + Value: 0x00000000000000C5 + Size: 0x000000000000005E + Visibility: STV_HIDDEN + +# 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_MERGE, SHF_STRINGS ] - AddressAlign: 0x0000000000000001 - Content: 004743433A202863726F7373746F6F6C2D4E47206C696E61726F2D312E31332E312D342E392D323031342E3039202D204C696E61726F2047434320342E392D323031342E30392920342E392E32203230313430393034202870726572656C656173652900 - - Name: .note.GNU-stack + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 70B4020CC0F3C754FF2CC0F3160302F4004080B241D0002C08BF002B3BD0A4F17F0543F4000315F10E0FA8BF41F6FF7209DA15F1190FA3BFA4F166066FF07F42F2406FF07F4212EA03060CD001325208964208BF03EA42021344B3F1807F24BF5B08A4F17E0501B30F2D26DC15F1180F11DB15F10E0FB5BF4FF6F2710E35CFF6FF71AD02B7BF491BAAB2CB40002202EB5333034398B270BC70470029FBD040EA533370BC43F4FC407047102DDEDD6FEAD0336FEAC33398B2EDE740F4F84398B2E9E700BFC0F3842310B4A3F11F040029B4FA84F400F400424FEA541408BF0024C0F309002146140481B943B14203703302EBC35343EA04005DF8044B704760B1B0FA80F3153B98405B42EFE744EA40305DF8044B40F0FF40704720465DF8044B704700BF01216BE70121FEE7002167E7002100E4 + - Name: .rel.text + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x000000000000012A + Symbol: __gnu_h2f_internal + Type: R_ARM_THM_JUMP11 + - Offset: 0x0000000000000132 + Symbol: __gnu_h2f_internal + Type: R_ARM_THM_JUMP11 + - Name: .text.startup Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: 0020FFF7FEBF00BF + - Name: .rel.text.startup + Type: SHT_REL + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text.startup + Relocations: + - Offset: 0x0000000000000002 + Symbol: __gnu_h2f_alternative + Type: R_ARM_THM_JUMP24 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] AddressAlign: 0x0000000000000001 Content: '' - - Name: .ARM.attributes - Type: SHT_ARM_ATTRIBUTES + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] AddressAlign: 0x0000000000000001 - Content: 4134000000616561626900012A00000005372D4100060A0741080109020A041204140115011703180119011A021B031C011E022201 + Content: '' Symbols: Local: - - Name: .text - Type: STT_SECTION - Section: .text - - Name: .text.startup - Type: STT_SECTION - Section: .text.startup - - Name: .data - Type: STT_SECTION - Section: .data - - Name: .bss - Type: STT_SECTION - Section: .bss - - Name: .comment - Type: STT_SECTION - Section: .comment - - Name: .note.GNU-stack - Type: STT_SECTION - Section: .note.GNU-stack - - Name: .ARM.attributes - Type: STT_SECTION - Section: .ARM.attributes - Name: '$t' Section: .text - Name: __gnu_f2h_internal |