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;
}
}
// If SD is a variable, evaluate it.
MCValue Target;
- if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Layout, nullptr))
+ if (!S.getVariableValue()->evaluateAsValue(Target, Layout))
report_fatal_error("unable to evaluate offset for variable '" +
S.getName() + "'");
: 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;
}
}
/* *** */
MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
- MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
- raw_ostream &OS_)
+ MCCodeEmitter &Emitter_, MCObjectWriter &Writer_)
: Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_),
- OS(OS_), BundleAlignSize(0), RelaxAll(false),
- SubsectionsViaSymbols(false), ELFHeaderEFlags(0) {
+ BundleAlignSize(0), RelaxAll(false), SubsectionsViaSymbols(false),
+ ELFHeaderEFlags(0) {
VersionMinInfo.Major = 0; // Major version == 0 for "none specified"
}
getLOHContainer().reset();
}
+bool MCAssembler::registerSection(MCSection &Section) {
+ if (Section.isRegistered())
+ return false;
+ Sections.push_back(&Section);
+ Section.setIsRegistered(true);
+ return true;
+}
+
bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
if (ThumbFuncs.count(Symbol))
return true;
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
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 &&
return std::make_pair(FixedValue, IsPCRel);
}
-void MCAssembler::Finish() {
+void MCAssembler::layout(MCAsmLayout &Layout) {
DEBUG_WITH_TYPE("mc-dump", {
llvm::errs() << "assembler backend - pre-layout\n--\n";
dump(); });
- // Create the layout object.
- MCAsmLayout Layout(*this);
-
// Create dummy fragments and assign section ordinals.
unsigned SectionIndex = 0;
for (MCSection &Sec : *this) {
llvm::errs() << "assembler backend - final-layout\n--\n";
dump(); });
- uint64_t StartOffset = OS.tell();
-
// Allow the object writer a chance to perform post-layout binding (for
// example, to set the index fields in the symbol data).
getWriter().executePostLayoutBinding(*this, Layout);
}
}
}
+}
+
+void MCAssembler::Finish() {
+ // Create the layout object.
+ MCAsmLayout Layout(*this);
+ layout(Layout);
+
+ raw_ostream &OS = getWriter().getStream();
+ uint64_t StartOffset = OS.tell();
// Write the object file.
getWriter().writeObject(*this, Layout);
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, F.getSubtargetInfo());
- VecOS.flush();
// Update the fragment.
F.setInst(Relaxed);
encodeSLEB128(Value, OSE);
else
encodeULEB128(Value, OSE);
- OSE.flush();
return OldSize != LF.getContents().size();
}
raw_svector_ostream OSE(Data);
MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta,
AddrDelta, OSE);
- OSE.flush();
return OldSize != Data.size();
}
Data.clear();
raw_svector_ostream OSE(Data);
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
- OSE.flush();
return OldSize != Data.size();
}
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 << ">";
}