diff options
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 6 | ||||
-rw-r--r-- | lib/MC/WinCOFFObjectWriter.cpp | 21 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 972c64cc56..6a48d62c8e 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -720,6 +720,12 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm, MCSymbolData &SDB = Asm.getSymbolData(SymbolB); IsPCRel = true; + if (!SDB.getFragment()) + Asm.getContext().FatalError( + Fixup.getLoc(), + Twine("symbol '") + SymbolB.getName() + + "' can not be undefined in a subtraction expression"); + // Offset of the symbol in the section int64_t a = Layout.getSymbolOffset(&SDB); diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 6d270209b7..ed19b7ec69 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -648,14 +648,25 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm, COFFSection *coff_section = SectionMap[&SectionData->getSection()]; COFFSymbol *coff_symbol = SymbolMap[&A_SD.getSymbol()]; - const MCSymbolRefExpr *SymA = Target.getSymA(); const MCSymbolRefExpr *SymB = Target.getSymB(); - const bool CrossSection = SymB && - &SymA->getSymbol().getSection() != &SymB->getSymbol().getSection(); + bool CrossSection = false; - if (Target.getSymB()) { - const MCSymbol *B = &Target.getSymB()->getSymbol(); + if (SymB) { + const MCSymbol *B = &SymB->getSymbol(); MCSymbolData &B_SD = Asm.getSymbolData(*B); + if (!B_SD.getFragment()) + Asm.getContext().FatalError( + Fixup.getLoc(), + Twine("symbol '") + B->getName() + + "' can not be undefined in a subtraction expression"); + + if (!A_SD.getFragment()) + Asm.getContext().FatalError( + Fixup.getLoc(), + Twine("symbol '") + Symbol.getName() + + "' can not be undefined in a subtraction expression"); + + CrossSection = &Symbol.getSection() != &B->getSection(); // Offset of the symbol in the section int64_t a = Layout.getSymbolOffset(&B_SD); |