Index: lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp =================================================================== --- lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp +++ lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp @@ -652,6 +652,9 @@ case R_ARM_IRELATIVE: // Runtime only relocations. Ignore here. break; + case R_ARM_V4BX: + // TODO implement + break; default: return make_unhandled_reloc_error(); } Index: lib/ReaderWriter/ELF/ELFFile.cpp =================================================================== --- lib/ReaderWriter/ELF/ELFFile.cpp +++ lib/ReaderWriter/ELF/ELFFile.cpp @@ -38,6 +38,11 @@ const Elf_Sym *targetSym) { // Return the atom for targetSym if we can do so. Atom *target = _symbolToAtomMapping.lookup(targetSym); + if (!target) + // Some realocations (R_ARM_V4BX) do not have a defined + // target. For this cases make it points to itself. + target = _symbolToAtomMapping.lookup(sourceSym); + if (target->definition() != Atom::definitionRegular) return target; Atom::Scope scope = llvm::cast(target)->scope(); Index: test/elf/ARM/rel-v4bx.test =================================================================== --- /dev/null +++ test/elf/ARM/rel-v4bx.test @@ -0,0 +1,72 @@ +# REQUIRES: arm + +# Check handling of R_ARM_V4BX relocation. +# RUN: yaml2obj -format=elf %s > %t-o.o +# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi \ +# RUN: --noinhibit-exec %t-o.o -o %t +# RUN: llvm-objdump -d -triple=armv4t %t | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: main: +# The following instruction creates a RM_ARM_V4BX relocation that +# allows the linker to replace the bx instruction to a ARMv4 +# compatible one. Currently lld does not change it. +# CHECK: 400114: 1e ff 2f 01 bxeq lr + +--- +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: 1EFF2F01 + - Name: .rel.text + Type: SHT_REL + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x0000000000000004 + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_ARM_V4BX + - 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: '' + - Name: .ARM.attributes + Type: SHT_ARM_ATTRIBUTES + AddressAlign: 0x0000000000000001 + Content: 4115000000616561626900010B000000060208010901 +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: '$a' + Section: .text + - Name: .ARM.attributes + Type: STT_SECTION + Section: .ARM.attributes + Global: + - Name: main + Type: STT_FUNC + Section: .text