X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FMC%2FMCAssembler.cpp;h=10c35be83828e1e4c9720be6e70c378c167734ac;hb=60e425e99ba7ef05b7a52c7068a67c6baa25da38;hp=8970e18a2ce77e2819e00ea0abc8b404b55fda71;hpb=27554ee1d8348d06741b9e697be173c5514dac0d;p=oota-llvm.git diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 8970e18a2ce..10c35be8382 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -214,7 +214,8 @@ MCFragment::~MCFragment() { MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent) : Kind(_Kind), Parent(_Parent), Atom(0), Offset(~UINT64_C(0)) { - Parent->getFragmentList().push_back(this); + if (Parent) + Parent->getFragmentList().push_back(this); } /* *** */ @@ -242,6 +243,36 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A) A->getSectionList().push_back(this); } +MCSectionData::iterator +MCSectionData::getSubsectionInsertionPoint(unsigned Subsection) { + if (Subsection == 0 && SubsectionFragmentMap.empty()) + return end(); + + SmallVectorImpl >::iterator MI = + std::lower_bound(SubsectionFragmentMap.begin(), SubsectionFragmentMap.end(), + std::make_pair(Subsection, (MCFragment *)0)); + bool ExactMatch = false; + if (MI != SubsectionFragmentMap.end()) { + ExactMatch = MI->first == Subsection; + if (ExactMatch) + ++MI; + } + iterator IP; + if (MI == SubsectionFragmentMap.end()) + IP = end(); + else + IP = MI->second; + if (!ExactMatch && Subsection != 0) { + // The GNU as documentation claims that subsections have an alignment of 4, + // although this appears not to be the case. + MCFragment *F = new MCDataFragment(); + SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F)); + getFragmentList().insert(IP, F); + F->setParent(this); + } + return IP; +} + /* *** */ MCSymbolData::MCSymbolData() : Symbol(0) {} @@ -549,10 +580,10 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, case MCFragment::FT_Align: { ++stats::EmittedAlignFragments; const MCAlignFragment &AF = cast(F); - uint64_t Count = FragmentSize / AF.getValueSize(); - assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!"); + uint64_t Count = FragmentSize / AF.getValueSize(); + // FIXME: This error shouldn't actually occur (the front end should emit // multiple .align directives to enforce the semantics it wants), but is // severe enough that we want to report it. How to handle this? @@ -677,12 +708,13 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, case MCFragment::FT_Align: // Check that we aren't trying to write a non-zero value into a virtual // section. - assert((!cast(it)->getValueSize() || - !cast(it)->getValue()) && + assert((cast(it)->getValueSize() == 0 || + cast(it)->getValue() == 0) && "Invalid align in virtual section!"); break; case MCFragment::FT_Fill: - assert(!cast(it)->getValueSize() && + assert((cast(it)->getValueSize() == 0 || + cast(it)->getValue() == 0) && "Invalid fill in virtual section!"); break; } @@ -706,17 +738,17 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, uint64_t MCAssembler::handleFixup(const MCAsmLayout &Layout, MCFragment &F, const MCFixup &Fixup) { - // Evaluate the fixup. - MCValue Target; - uint64_t FixedValue; - if (!evaluateFixup(Layout, Fixup, &F, Target, FixedValue)) { - // The fixup was unresolved, we need a relocation. Inform the object - // writer of the relocation, and give it an opportunity to adjust the - // fixup value if need be. - getWriter().RecordRelocation(*this, Layout, &F, Fixup, Target, FixedValue); - } - return FixedValue; - } + // Evaluate the fixup. + MCValue Target; + uint64_t FixedValue; + if (!evaluateFixup(Layout, Fixup, &F, Target, FixedValue)) { + // The fixup was unresolved, we need a relocation. Inform the object + // writer of the relocation, and give it an opportunity to adjust the + // fixup value if need be. + getWriter().RecordRelocation(*this, Layout, &F, Fixup, Target, FixedValue); + } + return FixedValue; +} void MCAssembler::Finish() { DEBUG_WITH_TYPE("mc-dump", { @@ -873,6 +905,7 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) { bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF) { + MCContext &Context = Layout.getAssembler().getContext(); int64_t AddrDelta = 0; uint64_t OldSize = DF.getContents().size(); bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout); @@ -883,13 +916,14 @@ bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout, SmallString<8> &Data = DF.getContents(); Data.clear(); raw_svector_ostream OSE(Data); - MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OSE); + MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OSE); OSE.flush(); return OldSize != Data.size(); } bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, MCDwarfCallFrameFragment &DF) { + MCContext &Context = Layout.getAssembler().getContext(); int64_t AddrDelta = 0; uint64_t OldSize = DF.getContents().size(); bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout); @@ -898,7 +932,7 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, SmallString<8> &Data = DF.getContents(); Data.clear(); raw_svector_ostream OSE(Data); - MCDwarfFrameEmitter::EncodeAdvanceLoc(AddrDelta, OSE); + MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE); OSE.flush(); return OldSize != Data.size(); }