[llvm] r206906 - Fix the assembler to print a better relocatable expression error
Rafael EspĂndola
rafael.espindola at gmail.com
Fri Apr 25 05:12:58 PDT 2014
This is awesome :-)
On 22 April 2014 13:27, Kevin Enderby <enderby at apple.com> wrote:
> Author: enderby
> Date: Tue Apr 22 12:27:29 2014
> New Revision: 206906
>
> URL: http://llvm.org/viewvc/llvm-project?rev=206906&view=rev
> Log:
> Fix the assembler to print a better relocatable expression error
> diagnostic that includes location information.
>
> Currently if one has this assembly:
>
> .quad (0x1234 + (4 * SOME_VALUE))
>
> where SOME_VALUE is undefined ones gets the less than
> useful error message with no location information:
>
> % clang -c x.s
> clang -cc1as: fatal error: error in backend: expected relocatable expression
>
> With this fix one now gets a more useful error message
> with location information:
>
> % clang -c x.s
> x.s:5:8: error: expected relocatable expression
> .quad (0x1234 + (4 * SOME_VALUE))
> ^
>
> To do this I plumbed the SMLoc through the MCObjectStreamer
> EmitValue() and EmitValueImpl() interfaces so it could be used
> when creating the MCFixup.
>
> rdar://12391022
>
> Added:
> llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr.s
> Modified:
> llvm/trunk/include/llvm/MC/MCELFStreamer.h
> llvm/trunk/include/llvm/MC/MCObjectStreamer.h
> llvm/trunk/include/llvm/MC/MCStreamer.h
> llvm/trunk/lib/LTO/LTOModule.cpp
> llvm/trunk/lib/MC/MCAsmStreamer.cpp
> llvm/trunk/lib/MC/MCELFStreamer.cpp
> llvm/trunk/lib/MC/MCNullStreamer.cpp
> llvm/trunk/lib/MC/MCObjectStreamer.cpp
> llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> llvm/trunk/lib/MC/MCStreamer.cpp
> llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
> llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
> llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64ELFStreamer.cpp
>
> Modified: llvm/trunk/include/llvm/MC/MCELFStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCELFStreamer.h?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCELFStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCELFStreamer.h Tue Apr 22 12:27:29 2014
> @@ -72,7 +72,8 @@ public:
> uint64_t Size = 0, unsigned ByteAlignment = 0) override;
> void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size, unsigned ByteAlignment = 0) override;
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override;
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc()) override;
>
> void EmitFileDirective(StringRef Filename) override;
>
>
> Modified: llvm/trunk/include/llvm/MC/MCObjectStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectStreamer.h?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCObjectStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCObjectStreamer.h Tue Apr 22 12:27:29 2014
> @@ -81,7 +81,8 @@ public:
> void EmitLabel(MCSymbol *Symbol) override;
> void EmitDebugLabel(MCSymbol *Symbol) override;
> void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override;
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc()) override;
> void EmitULEB128Value(const MCExpr *Value) override;
> void EmitSLEB128Value(const MCExpr *Value) override;
> void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Apr 22 12:27:29 2014
> @@ -529,9 +529,12 @@ public:
> /// @param Value - The value to emit.
> /// @param Size - The size of the integer (in bytes) to emit. This must
> /// match a native machine width.
> - virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) = 0;
> + /// @param Loc - The location of the expression for error reporting.
> + virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc()) = 0;
>
> - void EmitValue(const MCExpr *Value, unsigned Size);
> + void EmitValue(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc());
>
> /// EmitIntValue - Special case of EmitValue that avoids the client having
> /// to pass in a MCExpr for constant integers.
>
> Modified: llvm/trunk/lib/LTO/LTOModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/LTO/LTOModule.cpp (original)
> +++ llvm/trunk/lib/LTO/LTOModule.cpp Tue Apr 22 12:27:29 2014
> @@ -698,7 +698,8 @@ namespace {
> void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
> uint64_t Size, unsigned ByteAlignment) override {}
> void EmitBytes(StringRef Data) override {}
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override {}
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) override {}
> void EmitULEB128Value(const MCExpr *Value) override {}
> void EmitSLEB128Value(const MCExpr *Value) override {}
> void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -175,7 +175,8 @@ public:
>
> void EmitBytes(StringRef Data) override;
>
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override;
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc()) override;
> void EmitIntValue(uint64_t Value, unsigned Size) override;
>
> void EmitULEB128Value(const MCExpr *Value) override;
> @@ -702,7 +703,8 @@ void MCAsmStreamer::EmitIntValue(uint64_
> EmitValue(MCConstantExpr::Create(Value, getContext()), Size);
> }
>
> -void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
> +void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> assert(Size <= 8 && "Invalid size");
> assert(getCurrentSection().first &&
> "Cannot emit contents before setting section!");
>
> Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCELFStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -275,11 +275,12 @@ void MCELFStreamer::EmitLocalCommonSymbo
> EmitCommonSymbol(Symbol, Size, ByteAlignment);
> }
>
> -void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
> +void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> if (getCurrentSectionData()->isBundleLocked())
> report_fatal_error("Emitting values inside a locked bundle is forbidden");
> fixSymbolsInTLSFixups(Value);
> - MCObjectStreamer::EmitValueImpl(Value, Size);
> + MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
> }
>
> void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
>
> Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCNullStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -70,7 +70,8 @@ namespace {
> uint64_t Size, unsigned ByteAlignment) override {}
> void EmitBytes(StringRef Data) override {}
>
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override {}
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc = SMLoc()) override {}
> void EmitULEB128Value(const MCExpr *Value) override {}
> void EmitSLEB128Value(const MCExpr *Value) override {}
> void EmitGPRel32Value(const MCExpr *Value) override {}
>
> Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -97,7 +97,8 @@ const MCExpr *MCObjectStreamer::AddValue
> return Value;
> }
>
> -void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
> +void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> MCDataFragment *DF = getOrCreateDataFragment();
>
> MCLineEntry::Make(this, getCurrentSection().first);
> @@ -110,7 +111,7 @@ void MCObjectStreamer::EmitValueImpl(con
> }
> DF->getFixups().push_back(
> MCFixup::Create(DF->getContents().size(), Value,
> - MCFixup::getKindForSize(Size, false)));
> + MCFixup::getKindForSize(Size, false), Loc));
> DF->getContents().resize(DF->getContents().size() + Size, 0);
> }
>
>
> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Apr 22 12:27:29 2014
> @@ -2364,7 +2364,7 @@ bool AsmParser::parseDirectiveValue(unsi
> return Error(ExprLoc, "literal value out of range for directive");
> getStreamer().EmitIntValue(IntValue, Size);
> } else
> - getStreamer().EmitValue(Value, Size);
> + getStreamer().EmitValue(Value, Size, ExprLoc);
>
> if (getLexer().is(AsmToken::EndOfStatement))
> break;
>
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -147,8 +147,9 @@ void MCStreamer::EmitAbsValue(const MCEx
> }
>
>
> -void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
> - EmitValueImpl(Value, Size);
> +void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> + EmitValueImpl(Value, Size, Loc);
> }
>
> void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size) {
>
> Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp (original)
> +++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -92,9 +92,10 @@ public:
> /// This is one of the functions used to emit data into an ELF section, so the
> /// AArch64 streamer overrides it to add the appropriate mapping symbol ($d)
> /// if necessary.
> - virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {
> + virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> EmitDataMappingSymbol();
> - MCELFStreamer::EmitValueImpl(Value, Size);
> + MCELFStreamer::EmitValueImpl(Value, Size, Loc);
> }
>
> private:
>
> Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -531,7 +531,8 @@ public:
> /// This is one of the functions used to emit data into an ELF section, so the
> /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
> /// necessary.
> - void EmitValueImpl(const MCExpr *Value, unsigned Size) override {
> + void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) override {
> EmitDataMappingSymbol();
> MCELFStreamer::EmitValueImpl(Value, Size);
> }
>
> Modified: llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64ELFStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64ELFStreamer.cpp?rev=206906&r1=206905&r2=206906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64ELFStreamer.cpp (original)
> +++ llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64ELFStreamer.cpp Tue Apr 22 12:27:29 2014
> @@ -92,7 +92,8 @@ public:
> /// This is one of the functions used to emit data into an ELF section, so the
> /// ARM64 streamer overrides it to add the appropriate mapping symbol ($d)
> /// if necessary.
> - virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {
> + virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
> + const SMLoc &Loc) {
> EmitDataMappingSymbol();
> MCELFStreamer::EmitValueImpl(Value, Size);
> }
>
> Added: llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr.s
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr.s?rev=206906&view=auto
> ==============================================================================
> --- llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr.s (added)
> +++ llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr.s Tue Apr 22 12:27:29 2014
> @@ -0,0 +1,6 @@
> +// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - 2> %t.err > %t
> +// RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
> +
> +.quad (0x1234 + (4 * SOME_VALUE))
> +// CHECK-ERROR: error: expected relocatable expression
> +// CHECK-ERROR: ^
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list