diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -434,7 +434,7 @@ "not yet implemented"); } else { // Resolve constant variables. - if (A->isVariable()) { + if (A && A->isVariable()) { int64_t Res; if (A->getVariableValue()->evaluateAsAbsolute( Res, Layout, Writer->getSectionAddressMap())) { @@ -444,20 +444,22 @@ } // Check whether we need an external or internal relocation. - if (requiresExternRelocation(Writer, Asm, *Fragment, RelocType, *A, - FixedValue)) { - RelSymbol = A; - - // For external relocations, make sure to offset the fixup value to - // compensate for the addend of the symbol address, if it was - // undefined. This occurs with weak definitions, for example. - if (!A->isUndefined()) - FixedValue -= Layout.getSymbolOffset(*A); - } else { - // The index is the section ordinal (1-based). - const MCSection &Sec = A->getSection(); - Index = Sec.getOrdinal() + 1; - FixedValue += Writer->getSectionAddress(&Sec); + if (A) { + if (requiresExternRelocation(Writer, Asm, *Fragment, RelocType, *A, + FixedValue)) { + RelSymbol = A; + + // For external relocations, make sure to offset the fixup value to + // compensate for the addend of the symbol address, if it was + // undefined. This occurs with weak definitions, for example. + if (!A->isUndefined()) + FixedValue -= Layout.getSymbolOffset(*A); + } else { + // The index is the section ordinal (1-based). + const MCSection &Sec = A->getSection(); + Index = Sec.getOrdinal() + 1; + FixedValue += Writer->getSectionAddress(&Sec); + } } if (IsPCRel) FixedValue -= Writer->getSectionAddress(Fragment->getParent());