[llvm] r198590 - MC: Fatally error if subtraction operand is bad
David Majnemer
david.majnemer at gmail.com
Sun Jan 5 23:39:46 PST 2014
Author: majnemer
Date: Mon Jan 6 01:39:46 2014
New Revision: 198590
URL: http://llvm.org/viewvc/llvm-project?rev=198590&view=rev
Log:
MC: Fatally error if subtraction operand is bad
Instead of crashing, raise an error when a subtraction expression
involves an undefined symbol.
This fixes PR18375.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=198590&r1=198589&r2=198590&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Jan 6 01:39:46 2014
@@ -720,6 +720,12 @@ void ELFObjectWriter::RecordRelocation(c
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);
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=198590&r1=198589&r2=198590&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Mon Jan 6 01:39:46 2014
@@ -648,14 +648,25 @@ void WinCOFFObjectWriter::RecordRelocati
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);
More information about the llvm-commits
mailing list