================ @@ -230,22 +230,24 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const { case MCFragment::FT_Align: { unsigned Offset = F.Offset + F.getFixedSize(); unsigned Size = offsetToAlignment(Offset, F.getAlignment()); - - // Insert extra Nops for code alignment if the target define - // shouldInsertExtraNopBytesForCodeAlign target hook. - if (F.getParent()->useCodeAlign() && F.hasAlignEmitNops() && - getBackend().shouldInsertExtraNopBytesForCodeAlign(F, Size)) - return F.getFixedSize() + Size; - - // If we are padding with nops, force the padding to be larger than the - // minimum nop size. - if (Size > 0 && F.hasAlignEmitNops()) { - while (Size % getBackend().getMinimumNopSize()) - Size += F.getAlignment().value(); + auto &Frag = const_cast<MCFragment &>(F); + // In the nops mode, RISC-V style linker relaxation might adjust the size + // and add a fixup, even if `Size` is originally 0. + bool AlignFixup = false; + if (F.hasAlignEmitNops()) { + AlignFixup = getBackend().relaxAlign(Frag, Size); + // If the backend does not handle the fragment specially, pad with nops, + // but ensure that the padding is larger than the minimum nop size. + if (!AlignFixup) + while (Size % getBackend().getMinimumNopSize()) + Size += F.getAlignment().value(); } - if (Size > F.getAlignMaxBytesToEmit()) + if (!AlignFixup && Size > F.getAlignMaxBytesToEmit()) Size = 0; - return F.getFixedSize() + Size; + Frag.VarContentEnd = F.VarContentStart + Size; + if (Frag.VarContentEnd > Frag.getParent()->ContentStorage.size()) + Frag.getParent()->ContentStorage.resize(Frag.VarContentEnd); ---------------- aengelke wrote:
Also add comment here that actual content is ignored and that this is only for tracking the size? https://github.com/llvm/llvm-project/pull/149465 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits