diff options
author | Oliver Stannard <oliver.stannard@arm.com> | 2016-12-14 10:43:58 +0000 |
---|---|---|
committer | Oliver Stannard <oliver.stannard@arm.com> | 2016-12-14 10:43:58 +0000 |
commit | 268f42f1cee049b37fe4f601c34d740384dbe88a (patch) | |
tree | eb9b3efc8beff9826b857e7b2531d9b314fd7ded /llvm/lib/MC/MCAssembler.cpp | |
parent | 532bc984f58ed66e7fe7b9c6493d6ad808a89772 (diff) | |
download | bcm5719-llvm-268f42f1cee049b37fe4f601c34d740384dbe88a.tar.gz bcm5719-llvm-268f42f1cee049b37fe4f601c34d740384dbe88a.zip |
[Assembler] Better error messages for .org directive
Currently, the error messages we emit for the .org directive when the
expression is not absolute or is out of range do not include the line
number of the directive, so it can be hard to track down the problem if
a file contains many .org directives.
This patch stores the source location in the MCOrgFragment, so that it
can be used for diagnostics emitted during layout.
Since layout is an iterative process, and the errors are detected during
each iteration, it would have been possible for errors to be reported
multiple times. To prevent this, I've made the assembler bail out after
each iteration if any errors have been reported. This will still allow
multiple unrelated errors to be reported in the common case where they
are all detected in the first round of layout.
Differential Revision: https://reviews.llvm.org/D27411
llvm-svn: 289643
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 4735f6c3c55..83fcec92e2b 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -278,22 +278,29 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, case MCFragment::FT_Org: { const MCOrgFragment &OF = cast<MCOrgFragment>(F); MCValue Value; - if (!OF.getOffset().evaluateAsValue(Value, Layout)) - report_fatal_error("expected assembly-time absolute expression"); + if (!OF.getOffset().evaluateAsValue(Value, Layout)) { + getContext().reportError(OF.getLoc(), + "expected assembly-time absolute expression"); + return 0; + } - // FIXME: We need a way to communicate this error. uint64_t FragmentOffset = Layout.getFragmentOffset(&OF); int64_t TargetLocation = Value.getConstant(); if (const MCSymbolRefExpr *A = Value.getSymA()) { uint64_t Val; - if (!Layout.getSymbolOffset(A->getSymbol(), Val)) - report_fatal_error("expected absolute expression"); + if (!Layout.getSymbolOffset(A->getSymbol(), Val)) { + getContext().reportError(OF.getLoc(), "expected absolute expression"); + return 0; + } TargetLocation += Val; } int64_t Size = TargetLocation - FragmentOffset; - if (Size < 0 || Size >= 0x40000000) - report_fatal_error("invalid .org offset '" + Twine(TargetLocation) + - "' (at offset '" + Twine(FragmentOffset) + "')"); + if (Size < 0 || Size >= 0x40000000) { + getContext().reportError( + OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) + + "' (at offset '" + Twine(FragmentOffset) + "')"); + return 0; + } return Size; } @@ -660,7 +667,8 @@ void MCAssembler::layout(MCAsmLayout &Layout) { // Layout until everything fits. while (layoutOnce(Layout)) - continue; + if (getContext().hadError()) + return; DEBUG_WITH_TYPE("mc-dump", { llvm::errs() << "assembler backend - post-relaxation\n--\n"; @@ -912,7 +920,9 @@ bool MCAssembler::layoutOnce(MCAsmLayout &Layout) { void MCAssembler::finishLayout(MCAsmLayout &Layout) { // The layout is done. Mark every fragment as valid. for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) { - Layout.getFragmentOffset(&*Layout.getSectionOrder()[i]->rbegin()); + MCSection &Section = *Layout.getSectionOrder()[i]; + Layout.getFragmentOffset(&*Section.rbegin()); + computeFragmentSize(Layout, *Section.rbegin()); } getBackend().finishLayout(*this, Layout); } |