void MCAsmLayout::ensureValid(const MCFragment *F) const {
MCSection *Sec = F->getParent();
- MCFragment *Cur = LastValidFragment[Sec];
- if (!Cur)
- Cur = Sec->begin();
+ MCSection::iterator I;
+ if (MCFragment *Cur = LastValidFragment[Sec])
+ I = ++MCSection::iterator(Cur);
else
- Cur = Cur->getNextNode();
+ I = Sec->begin();
// Advance the layout position until the fragment is valid.
while (!isFragmentValid(F)) {
- assert(Cur && "Layout bookkeeping error");
- const_cast<MCAsmLayout*>(this)->layoutFragment(Cur);
- Cur = Cur->getNextNode();
+ assert(I != Sec->end() && "Layout bookkeeping error");
+ const_cast<MCAsmLayout *>(this)->layoutFragment(&*I);
+ ++I;
}
}
const MCExpr *Expr = Symbol.getVariableValue();
MCValue Value;
- if (!Expr->evaluateAsValue(Value, *this))
- llvm_unreachable("Invalid Expression");
+ if (!Expr->evaluateAsValue(Value, *this)) {
+ Assembler.getContext().reportError(
+ SMLoc(), "expression could not be evaluated");
+ return nullptr;
+ }
const MCSymbolRefExpr *RefB = Value.getSymB();
- if (RefB)
- Assembler.getContext().reportFatalError(
+ if (RefB) {
+ Assembler.getContext().reportError(
SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() +
"' could not be evaluated in a subtraction expression");
+ return nullptr;
+ }
const MCSymbolRefExpr *A = Value.getSymA();
if (!A)
const MCAssembler &Asm = getAssembler();
if (ASym.isCommon()) {
// FIXME: we should probably add a SMLoc to MCExpr.
- Asm.getContext().reportFatalError(SMLoc(),
- "Common symbol " + ASym.getName() +
- " cannot be used in assignment expr");
+ Asm.getContext().reportError(SMLoc(),
+ "Common symbol '" + ASym.getName() +
+ "' cannot be used in assignment expr");
+ return nullptr;
}
return &ASym;
: Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false),
BundlePadding(BundlePadding), Parent(Parent), Atom(nullptr),
Offset(~UINT64_C(0)) {
- if (Parent)
+ if (Parent && !isDummy())
Parent->getFragmentList().push_back(this);
}
case FT_SafeSEH:
delete cast<MCSafeSEHFragment>(this);
return;
+ case FT_Dummy:
+ delete cast<MCDummyFragment>(this);
+ return;
}
}
return &S;
// Absolute and undefined symbols have no defining atom.
- if (!S.getFragment())
+ if (!S.isInSection())
return nullptr;
// Non-linker visible symbols in sections which can't be atomized have no
// probably merge the two into a single callback that tries to evaluate a
// fixup and records a relocation if one is needed.
const MCExpr *Expr = Fixup.getValue();
- if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup))
- getContext().reportFatalError(Fixup.getLoc(), "expected relocatable expression");
+ if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
+ getContext().reportError(Fixup.getLoc(), "expected relocatable expression");
+ // Claim to have completely evaluated the fixup, to prevent any further
+ // processing from being done.
+ Value = 0;
+ return true;
+ }
bool IsPCRel = Backend.getFixupKindInfo(
Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
case MCFragment::FT_Org: {
const MCOrgFragment &OF = cast<MCOrgFragment>(F);
- int64_t TargetLocation;
- if (!OF.getOffset().evaluateAsAbsolute(TargetLocation, Layout))
+ MCValue Value;
+ if (!OF.getOffset().evaluateAsValue(Value, Layout))
report_fatal_error("expected assembly-time absolute expression");
// 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");
+ TargetLocation += Val;
+ }
int64_t Size = TargetLocation - FragmentOffset;
if (Size < 0 || Size >= 0x40000000)
report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +
return cast<MCDwarfLineAddrFragment>(F).getContents().size();
case MCFragment::FT_DwarfFrame:
return cast<MCDwarfCallFrameFragment>(F).getContents().size();
+ case MCFragment::FT_Dummy:
+ llvm_unreachable("Should not have been added");
}
llvm_unreachable("invalid fragment kind");
OW->writeBytes(CF.getContents());
break;
}
+ case MCFragment::FT_Dummy:
+ llvm_unreachable("Should not have been added");
}
assert(OW->getStream().tell() - Start == FragmentSize &&
break;
}
if (RelaxedFrag && !FirstRelaxedFragment)
- FirstRelaxedFragment = I;
+ FirstRelaxedFragment = &*I;
}
if (FirstRelaxedFragment) {
Layout.invalidateFragmentsFrom(FirstRelaxedFragment);
case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
case MCFragment::FT_LEB: OS << "MCLEBFragment"; break;
case MCFragment::FT_SafeSEH: OS << "MCSafeSEHFragment"; break;
+ case MCFragment::FT_Dummy:
+ OS << "MCDummyFragment";
+ break;
}
OS << "<MCFragment " << (void*) this << " LayoutOrder:" << LayoutOrder
OS << " Sym:" << F->getSymbol();
break;
}
+ case MCFragment::FT_Dummy:
+ break;
}
OS << ">";
}