summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/WinCOFFObjectWriter.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-01-06 07:39:46 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-01-06 07:39:46 +0000
commita45a176ebc1b87acd4eadc7c632062b3f6caa598 (patch)
tree6f217967f5afb5c106f83c00ab7a9a59a10f0442 /llvm/lib/MC/WinCOFFObjectWriter.cpp
parent2ea87dad77a9616c890f8c251b286376608d3863 (diff)
downloadbcm5719-llvm-a45a176ebc1b87acd4eadc7c632062b3f6caa598.tar.gz
bcm5719-llvm-a45a176ebc1b87acd4eadc7c632062b3f6caa598.zip
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. llvm-svn: 198590
Diffstat (limited to 'llvm/lib/MC/WinCOFFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 6d270209b74..ed19b7ec69d 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud