diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp --- a/lld/ELF/Arch/ARM.cpp +++ b/lld/ELF/Arch/ARM.cpp @@ -90,6 +90,7 @@ case R_ARM_THM_MOVW_ABS_NC: case R_ARM_THM_MOVT_ABS: return R_ABS; + case R_ARM_THM_JUMP8: case R_ARM_THM_JUMP11: return R_PC; case R_ARM_CALL: @@ -520,7 +521,13 @@ checkInt(loc, val, 26, rel); write32le(loc, (read32le(loc) & ~0x00ffffff) | ((val >> 2) & 0x00ffffff)); break; + case R_ARM_THM_JUMP8: + // We do a 9 bit check because val is right-shifted by 1 bit. + checkInt(loc, val, 9, rel); + write16le(loc, (read32le(loc) & 0xff00) | ((val >> 1) & 0x00ff)); + break; case R_ARM_THM_JUMP11: + // We do a 12 bit check because val is right-shifted by 1 bit. checkInt(loc, val, 12, rel); write16le(loc, (read32le(loc) & 0xf800) | ((val >> 1) & 0x07ff)); break; @@ -748,6 +755,8 @@ case R_ARM_PC24: case R_ARM_PLT32: return SignExtend64<26>(read32le(buf) << 2); + case R_ARM_THM_JUMP8: + return SignExtend64<9>(read16le(buf) << 1); case R_ARM_THM_JUMP11: return SignExtend64<12>(read16le(buf) << 1); case R_ARM_THM_JUMP19: { diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -495,6 +495,7 @@ switch (type) { // Unresolved branch relocations to weak references resolve to next // instruction, this will be either 2 or 4 bytes on from P. + case R_ARM_THM_JUMP8: case R_ARM_THM_JUMP11: return p + 2 + a; case R_ARM_CALL: diff --git a/lld/test/ELF/arm-thumb-undefined-weak-narrow.test b/lld/test/ELF/arm-thumb-undefined-weak-narrow.test --- a/lld/test/ELF/arm-thumb-undefined-weak-narrow.test +++ b/lld/test/ELF/arm-thumb-undefined-weak-narrow.test @@ -7,11 +7,12 @@ # CHECK-EMPTY: # CHECK-NEXT: <_start>: # CHECK-NEXT: ff e7 b 0x200b6 <_start+0x2> @ imm = #-2 +# CHECK-NEXT: ff e7 b 0x200b8 <_start+0x4> @ imm = #-2 -# Test the R_ARM_THM_JUMP11 relocation (102) to an undefined weak reference -# It should resolve to the next instruction, which is an offset of -2 which -# when added to the Thumb PC-bias of 4 is +2. We can't use llvm-mc to construct -# the object as it relaxes b.n to b.w (R_ARM_JUMP24). +# Test the R_ARM_THM_JUMP11 (102) and R_ARM_THM_JUMP8 (103) relocations to an +# undefined weak reference. It should resolve to the next instruction, which +# is an offset of -2 which when added to the Thumb PC-bias of 4 is +2. We can't +# use llvm-mc to construct the object as it relaxes b.n to b.w (R_ARM_JUMP24). !ELF FileHeader: @@ -23,7 +24,7 @@ - Type: SHT_PROGBITS Name: .text Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Content: "fee7" + Content: "fee7ffe7" - Type: SHT_REL Name: .rel.text Link: .symtab @@ -31,6 +32,8 @@ Relocations: - Symbol: undefined_weak Type: R_ARM_THM_JUMP11 + - Symbol: undefined_weak + Type: R_ARM_THM_JUMP8 Symbols: - Type: STT_NOTYPE