Index: llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp =================================================================== --- llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -62,7 +62,7 @@ // ARMFixupKinds.h. // // Name Offset (bits) Size (bits) Flags - {"fixup_arm_ldst_pcrel_12", 0, 32, IsPCRelConstant}, + {"fixup_arm_ldst_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_t2_ldst_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, @@ -77,7 +77,7 @@ {"fixup_thumb_adr_pcrel_10", 0, 8, MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, - {"fixup_arm_adr_pcrel_12", 0, 32, IsPCRelConstant}, + {"fixup_arm_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_t2_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, Index: llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp =================================================================== --- llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp +++ llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp @@ -137,6 +137,10 @@ default: return ELF::R_ARM_THM_CALL; } + case ARM::fixup_arm_adr_pcrel_12: + return ELF::R_ARM_ALU_PC_G0; + case ARM::fixup_arm_ldst_pcrel_12: + return ELF::R_ARM_LDR_PC_G0; case ARM::fixup_thumb_adr_pcrel_10: case ARM::fixup_arm_thumb_cp: return ELF::R_ARM_THM_PC8; Index: llvm/test/MC/ARM/arm-relax-adr.s =================================================================== --- /dev/null +++ llvm/test/MC/ARM/arm-relax-adr.s @@ -0,0 +1,8 @@ +@ RUN: not llvm-mc -triple armv5a-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s +@ RUN: llvm-mc -triple armv5a-none-eabi -filetype=obj %s -o - | llvm-readobj --relocs | FileCheck --check-prefix=CHECK-ELF %s + + .global func1 +_func1: + adr r0, _func2 +@ CHECK-ERROR: unsupported relocation on symbol +@ CHECK-ELF: 0x0 R_ARM_ALU_PC_G0 _func2 0x0 Index: llvm/test/MC/ARM/arm-relax-ldrlit.s =================================================================== --- /dev/null +++ llvm/test/MC/ARM/arm-relax-ldrlit.s @@ -0,0 +1,8 @@ +@ RUN: not llvm-mc -triple armv5a-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s +@ RUN: llvm-mc -triple armv5a-none-eabi -filetype=obj %s -o - | llvm-readobj --relocs | FileCheck --check-prefix=CHECK-ELF %s + + .global func1 +_func1: + ldr r0, _func2 +@ CHECK-ERROR: unsupported relocation on symbol +@ CHECK-ELF: 0x0 R_ARM_LDR_PC_G0 _func2 0x0 Index: llvm/test/MC/ARM/pcrel-global-rel.s =================================================================== --- llvm/test/MC/ARM/pcrel-global-rel.s +++ llvm/test/MC/ARM/pcrel-global-rel.s @@ -1,9 +1,15 @@ @ RUN: llvm-mc -filetype=obj -triple=armv7 %s -o %t -@ RUN: llvm-readobj -r %t +@ RUN: llvm-readobj -r %t | FileCheck %s @ Check that for ELF targets we generate a relocation for a within section @ pc-relative reference to a global symbol as it may be interposed and we won't @ know till link time whether this is possible. + +.globl foo +foo: +adr r2, foo @ arm_adr_pcrel_12 +ldr r0, foo @ arm_ldst_pcrel_12 + .thumb .thumb_func @@ -13,6 +19,8 @@ adr.w r0, bar @ t2_adr_pcrel_12 ldr.w pc, bar @ t2_ldst_pcrel_12 -@ CHECK: 0x0 R_ARM_THM_ALU_PREL_11_0 bar 0x0 -@ CHECK-NEXT: 0x4 R_ARM_THM_ALU_PREL_11_0 bar 0x0 -@ CHECK-NEXT: 0x8 R_ARM_THM_PC12 bar 0x0 +@ CHECK: 0x0 R_ARM_ALU_PC_G0 foo 0x0 +@ CHECK-NEXT: 0x4 R_ARM_LDR_PC_G0 foo 0x0 +@ CHECK-NEXT: 0x8 R_ARM_THM_ALU_PREL_11_0 bar 0x0 +@ CHECK-NEXT: 0xC R_ARM_THM_ALU_PREL_11_0 bar 0x0 +@ CHECK-NEXT: 0x10 R_ARM_THM_PC12 bar 0x0 Index: llvm/test/MC/ARM/pcrel-global.s =================================================================== --- llvm/test/MC/ARM/pcrel-global.s +++ llvm/test/MC/ARM/pcrel-global.s @@ -8,6 +8,4 @@ foo: ldrd r0, r1, foo @ arm_pcrel_10_unscaled vldr d0, foo @ arm_pcrel_10 -adr r2, foo @ arm_adr_pcrel_12 -ldr r0, foo @ arm_ldst_pcrel_12