diff --git a/llvm/include/llvm/MC/MCFixupKindInfo.h b/llvm/include/llvm/MC/MCFixupKindInfo.h --- a/llvm/include/llvm/MC/MCFixupKindInfo.h +++ b/llvm/include/llvm/MC/MCFixupKindInfo.h @@ -19,7 +19,10 @@ FKF_IsPCRel = (1 << 0), /// Should this fixup kind force a 4-byte aligned effective PC value? - FKF_IsAlignedDownTo32Bits = (1 << 1) + FKF_IsAlignedDownTo32Bits = (1 << 1), + + /// This fixup kind should be resolved if defined. + FKF_Constant = 1 << 2, }; /// A target specific name for the fixup kind. The names will be unique for diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -217,8 +217,8 @@ } assert(getBackendPtr() && "Expected assembler backend"); - bool IsPCRel = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags & - MCFixupKindInfo::FKF_IsPCRel; + unsigned FixupFlags = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags; + bool IsPCRel = FixupFlags & MCFixupKindInfo::FKF_IsPCRel; bool IsResolved = false; if (IsPCRel) { @@ -232,8 +232,9 @@ if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) { IsResolved = false; } else if (auto *Writer = getWriterPtr()) { - IsResolved = Writer->isSymbolRefDifferenceFullyResolvedImpl( - *this, SA, *DF, false, true); + IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) || + Writer->isSymbolRefDifferenceFullyResolvedImpl( + *this, SA, *DF, false, true); } } } else { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -76,10 +76,12 @@ {"fixup_thumb_adr_pcrel_10", 0, 8, MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, - {"fixup_arm_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, + {"fixup_arm_adr_pcrel_12", 0, 32, + MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_Constant}, {"fixup_t2_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel | - MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, + MCFixupKindInfo::FKF_IsAlignedDownTo32Bits | + MCFixupKindInfo::FKF_Constant}, {"fixup_arm_condbranch", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_arm_uncondbranch", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_t2_condbranch", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, @@ -111,8 +113,7 @@ {"fixup_bfc_target", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, {"fixup_bfcsel_else_target", 0, 32, 0}, {"fixup_wls", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, - {"fixup_le", 0, 32, MCFixupKindInfo::FKF_IsPCRel} - }; + {"fixup_le", 0, 32, MCFixupKindInfo::FKF_IsPCRel}}; const static MCFixupKindInfo InfosBE[ARM::NumTargetFixupKinds] = { // This table *must* be in the order that the fixup_* kinds are defined in // ARMFixupKinds.h. diff --git a/llvm/test/MC/ARM/Windows/invalid-relocation.s b/llvm/test/MC/ARM/Windows/invalid-relocation.s --- a/llvm/test/MC/ARM/Windows/invalid-relocation.s +++ b/llvm/test/MC/ARM/Windows/invalid-relocation.s @@ -7,7 +7,6 @@ .endef .global invalid_relocation .thumb_func -invalid_relocation: adr r0, invalid_relocation+1 # CHECK: LLVM ERROR: unsupported relocation type: fixup_t2_adr_pcrel_12 diff --git a/llvm/test/MC/ARM/adr-global.s b/llvm/test/MC/ARM/adr-global.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/ARM/adr-global.s @@ -0,0 +1,15 @@ +@ RUN: llvm-mc -filetype=obj -triple=armv7 %s -o %t +@ RUN: llvm-readelf -r %t | FileCheck %s + +@ CHECK: There are no relocations in this file. + +.globl foo +foo: +adr r2, foo + +.thumb +.thumb_func + +.globl bar +bar: +adr lr, bar