From a9d4281cc0557ef679b7917e0741ddb01651dab1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 23 Nov 2010 08:08:33 +0000 Subject: [PATCH] Invalidate the layout on any relaxation, not just Instructions. Bug found by David Meyer. While here, remove unused argument and rename UpdateForSlide to Invalidate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120009 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAsmLayout.h | 7 +++---- lib/MC/MCAssembler.cpp | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/llvm/MC/MCAsmLayout.h b/include/llvm/MC/MCAsmLayout.h index 6feacf56e4d..2cde06b4ede 100644 --- a/include/llvm/MC/MCAsmLayout.h +++ b/include/llvm/MC/MCAsmLayout.h @@ -54,10 +54,9 @@ public: /// Get the assembler object this is a layout for. MCAssembler &getAssembler() const { return Assembler; } - /// \brief Update the layout because a fragment has been resized. The - /// fragments size should have already been updated, the \arg SlideAmount is - /// the delta from the old size. - void UpdateForSlide(MCFragment *F, int SlideAmount); + /// \brief Invalidate all following fragments because a fragment has been resized. The + /// fragments size should have already been updated. + void Invalidate(MCFragment *F); /// \brief Update the layout, replacing Src with Dst. The contents /// of Src and Dst are not modified, and must be copied by the caller. diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index a38aa8d8e07..434683868cc 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -78,7 +78,7 @@ bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const { F->getLayoutOrder() <= LastValidFragment->getLayoutOrder()); } -void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) { +void MCAsmLayout::Invalidate(MCFragment *F) { // If this fragment wasn't already up-to-date, we don't need to do anything. if (!isFragmentUpToDate(F)) return; @@ -143,7 +143,7 @@ void MCAsmLayout::CoalesceFragments(MCFragment *Src, MCFragment *Dst) { Dst->EffectiveSize += Src->EffectiveSize; } else { // We don't know the effective size of Src, so we have to invalidate Dst. - UpdateForSlide(Dst, 0); + Invalidate(Dst); } // Remove Src, but don't delete it yet. Src->getParent()->getFragmentList().remove(Src); @@ -819,7 +819,6 @@ bool MCAssembler::RelaxInstruction(const MCObjectWriter &Writer, VecOS.flush(); // Update the instruction fragment. - int SlideAmount = Code.size() - IF.getInstSize(); IF.setInst(Relaxed); IF.getCode() = Code; IF.getFixups().clear(); @@ -827,8 +826,6 @@ bool MCAssembler::RelaxInstruction(const MCObjectWriter &Writer, for (unsigned i = 0, e = Fixups.size(); i != e; ++i) IF.getFixups().push_back(Fixups[i]); - // Update the layout, and remember that we relaxed. - Layout.UpdateForSlide(&IF, SlideAmount); return true; } @@ -894,24 +891,29 @@ bool MCAssembler::LayoutOnce(const MCObjectWriter &Writer, for (MCSectionData::iterator it2 = SD.begin(), ie2 = SD.end(); it2 != ie2; ++it2) { // Check if this is an fragment that needs relaxation. + bool relaxedFrag = false; switch(it2->getKind()) { default: break; case MCFragment::FT_Inst: - WasRelaxed |= RelaxInstruction(Writer, Layout, + relaxedFrag = RelaxInstruction(Writer, Layout, *cast(it2)); break; case MCFragment::FT_Org: - WasRelaxed |= RelaxOrg(Writer, Layout, *cast(it2)); + relaxedFrag = RelaxOrg(Writer, Layout, *cast(it2)); break; case MCFragment::FT_Dwarf: - WasRelaxed |= RelaxDwarfLineAddr(Writer, Layout, + relaxedFrag = RelaxDwarfLineAddr(Writer, Layout, *cast(it2)); break; case MCFragment::FT_LEB: - WasRelaxed |= RelaxLEB(Writer, Layout, *cast(it2)); + relaxedFrag = RelaxLEB(Writer, Layout, *cast(it2)); break; } + // Update the layout, and remember that we relaxed. + if (relaxedFrag) + Layout.Invalidate(it2); + WasRelaxed |= relaxedFrag; } }