diff options
author | Derek Schuff <dschuff@google.com> | 2013-01-31 17:00:03 +0000 |
---|---|---|
committer | Derek Schuff <dschuff@google.com> | 2013-01-31 17:00:03 +0000 |
commit | b76ec3bb5eefcd7f8eb0b33d16f2b065e5b31b31 (patch) | |
tree | 88757b0a37c2fb209d56aab350c0a238416c40e9 /llvm/lib/MC/MCAssembler.cpp | |
parent | fb8565a9c6f43b57ab1c646986c52ddbacfad7b4 (diff) | |
download | bcm5719-llvm-b76ec3bb5eefcd7f8eb0b33d16f2b065e5b31b31.tar.gz bcm5719-llvm-b76ec3bb5eefcd7f8eb0b33d16f2b065e5b31b31.zip |
[MC] bundle alignment: prevent padding instructions from crossing bundle boundaries
llvm-svn: 174067
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 983de1a115a..498fbf77ad5 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -467,7 +467,7 @@ void MCAsmLayout::layoutFragment(MCFragment *F) { // // // BundlePadding - // ||| + // ||| // ------------------------------------- // Prev |##########| F | // ------------------------------------- @@ -506,6 +506,9 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F) { MCObjectWriter *OW = &Asm.getWriter(); + // FIXME: Embed in fragments instead? + uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F); + // Should NOP padding be written out before this fragment? unsigned BundlePadding = F.getBundlePadding(); if (BundlePadding > 0) { @@ -514,6 +517,22 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, assert(F.hasInstructions() && "Writing bundle padding for a fragment without instructions"); + unsigned TotalLength = BundlePadding + static_cast<unsigned>(FragmentSize); + if (F.alignToBundleEnd() && TotalLength > Asm.getBundleAlignSize()) { + // If the padding itself crosses a bundle boundary, it must be emitted + // in 2 pieces, since even nop instructions must not cross boundaries. + // v--------------v <- BundleAlignSize + // v---------v <- BundlePadding + // ---------------------------- + // | Prev |####|####| F | + // ---------------------------- + // ^-------------------^ <- TotalLength + unsigned DistanceToBoundary = TotalLength - Asm.getBundleAlignSize(); + if (!Asm.getBackend().writeNopData(DistanceToBoundary, OW)) + report_fatal_error("unable to write NOP sequence of " + + Twine(DistanceToBoundary) + " bytes"); + BundlePadding -= DistanceToBoundary; + } if (!Asm.getBackend().writeNopData(BundlePadding, OW)) report_fatal_error("unable to write NOP sequence of " + Twine(BundlePadding) + " bytes"); @@ -526,8 +545,6 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, ++stats::EmittedFragments; - // FIXME: Embed in fragments instead? - uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F); switch (F.getKind()) { case MCFragment::FT_Align: { ++stats::EmittedAlignFragments; @@ -1134,4 +1151,3 @@ void MCOrgFragment::anchor() { } void MCLEBFragment::anchor() { } void MCDwarfLineAddrFragment::anchor() { } void MCDwarfCallFrameFragment::anchor() { } - |