diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-12 16:55:59 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-12 16:55:59 +0000 |
commit | 3b8cc2299ba497e7c774622f6770403a0e970494 (patch) | |
tree | 74a59aed8ee9a743ddc1c02f2914525469a11083 /lib | |
parent | a3802ac246e2637f47c4a87292783ad00184dcef (diff) | |
download | llvm-3b8cc2299ba497e7c774622f6770403a0e970494.tar.gz llvm-3b8cc2299ba497e7c774622f6770403a0e970494.tar.bz2 llvm-3b8cc2299ba497e7c774622f6770403a0e970494.tar.xz |
Try harder to evaluate expressions when printing assembly.
When printing assembly we don't have a Layout object, but we can still
try to fold some constants.
Testcase by Ulrich Weigand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203677 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCAssembler.cpp | 4 | ||||
-rw-r--r-- | lib/MC/MCExpr.cpp | 6 | ||||
-rw-r--r-- | lib/MC/MachObjectWriter.cpp | 4 | ||||
-rw-r--r-- | lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp | 2 | ||||
-rw-r--r-- | lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp | 4 | ||||
-rw-r--r-- | lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp | 5 | ||||
-rw-r--r-- | lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp | 4 |
7 files changed, 14 insertions, 15 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index b8a4b438f6..89d7d19016 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -122,7 +122,7 @@ uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const { // If this is a variable, then recursively evaluate now. if (S.isVariable()) { MCValue Target; - if (!S.getVariableValue()->EvaluateAsRelocatable(Target, *this)) + if (!S.getVariableValue()->EvaluateAsRelocatable(Target, this)) report_fatal_error("unable to evaluate offset for variable '" + S.getName() + "'"); @@ -357,7 +357,7 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout, MCValue &Target, uint64_t &Value) const { ++stats::evaluateFixup; - if (!Fixup.getValue()->EvaluateAsRelocatable(Target, Layout)) + if (!Fixup.getValue()->EvaluateAsRelocatable(Target, &Layout)) getContext().FatalError(Fixup.getLoc(), "expected relocatable expression"); bool IsPCRel = Backend.getFixupKindInfo( diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index 75bde8ed36..9a4c41699e 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -607,9 +607,9 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm, } bool MCExpr::EvaluateAsRelocatable(MCValue &Res, - const MCAsmLayout &Layout) const { - return EvaluateAsRelocatableImpl(Res, &Layout.getAssembler(), &Layout, - 0, false); + const MCAsmLayout *Layout) const { + MCAssembler *Assembler = Layout ? &Layout->getAssembler() : 0; + return EvaluateAsRelocatableImpl(Res, Assembler, Layout, 0, false); } bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index edbd2b98b2..b3b593d315 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -82,7 +82,7 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbolData* SD, MCValue Target; - if (!S.getVariableValue()->EvaluateAsRelocatable(Target, Layout)) + if (!S.getVariableValue()->EvaluateAsRelocatable(Target, &Layout)) report_fatal_error("unable to evaluate offset for variable '" + S.getName() + "'"); @@ -631,7 +631,7 @@ void MachObjectWriter::markAbsoluteVariableSymbols(MCAssembler &Asm, // and neither symbol is external, mark the variable as absolute. const MCExpr *Expr = SD.getSymbol().getVariableValue(); MCValue Value; - if (Expr->EvaluateAsRelocatable(Value, Layout)) { + if (Expr->EvaluateAsRelocatable(Value, &Layout)) { if (Value.getSymA() && Value.getSymB()) const_cast<MCSymbol*>(&SD.getSymbol())->setAbsolute(); } diff --git a/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp b/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp index 66ce92d7b9..c7ccaee865 100644 --- a/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp +++ b/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp @@ -79,7 +79,7 @@ void AArch64MCExpr::PrintImpl(raw_ostream &OS) const { bool AArch64MCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout) const { - return getSubExpr()->EvaluateAsRelocatable(Res, *Layout); + return getSubExpr()->EvaluateAsRelocatable(Res, Layout); } static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { diff --git a/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp b/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp index e470fea165..22ce41100a 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp @@ -36,9 +36,7 @@ void MipsMCExpr::PrintImpl(raw_ostream &OS) const { bool MipsMCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout) const { - if (!Layout) - return false; - return getSubExpr()->EvaluateAsRelocatable(Res, *Layout); + return getSubExpr()->EvaluateAsRelocatable(Res, Layout); } // FIXME: This basically copies MCObjectStreamer::AddValueSymbols. Perhaps diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp index 562badfd59..c181e03fe6 100644 --- a/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp +++ b/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp @@ -54,7 +54,7 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout) const { MCValue Value; - if (!Layout || !getSubExpr()->EvaluateAsRelocatable(Value, *Layout)) + if (!getSubExpr()->EvaluateAsRelocatable(Value, Layout)) return false; if (Value.isAbsolute()) { @@ -86,6 +86,9 @@ PPCMCExpr::EvaluateAsRelocatableImpl(MCValue &Res, } Res = MCValue::get(Result); } else { + if (!Layout) + return false; + MCContext &Context = Layout->getAssembler().getContext(); const MCSymbolRefExpr *Sym = Value.getSymA(); MCSymbolRefExpr::VariantKind Modifier = Sym->getKind(); diff --git a/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp b/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp index 7f2b25e408..e6b2acab9d 100644 --- a/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp +++ b/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp @@ -160,9 +160,7 @@ Sparc::Fixups SparcMCExpr::getFixupKind(SparcMCExpr::VariantKind Kind) { bool SparcMCExpr::EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout) const { - if (!Layout) - return false; - return getSubExpr()->EvaluateAsRelocatable(Res, *Layout); + return getSubExpr()->EvaluateAsRelocatable(Res, Layout); } static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { |