[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 20 00:45:44 PDT 2025
================
@@ -992,7 +965,30 @@ void MCAssembler::layoutSection(MCSection &Sec) {
uint64_t Offset = 0;
for (MCFragment &F : Sec) {
F.Offset = Offset;
- Offset += computeFragmentSize(F);
+ if (F.getKind() == MCFragment::FT_Align) {
+ Offset += F.getFixedSize();
+ unsigned Size = offsetToAlignment(Offset, F.getAlignment());
+ // 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(F, 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 (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
+ Size = 0;
+ // Update the variable tail size. The content is ignored.
+ F.VarContentEnd = F.VarContentStart + Size;
----------------
MaskRay wrote:
Agree! Let me try `assert(F.VarContentStart == 0);`
https://github.com/llvm/llvm-project/pull/149465
More information about the llvm-branch-commits
mailing list