[llvm] MC: Refine ALIGN relocation conditions (PR #150816)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 23:37:09 PDT 2025


MaskRay wrote:

The relax-align-3.s test is interesting. I've updated the description:

> When the alignment exceeds 2, we insert $alignment-2 bytes of NOPs, even in non-RVC code. This enables non-RVC code following RVC code to handle a 2-byte adjustment without requiring an additional state in MCSection or AsmParser.
> 
> ```
> .globl _start
> _start:
> // GNU ld can relax this to  6505          lui     a0, 0x1
> // LLD hasn't implemented this transformation.
>   lui a0, %hi(foo)
> 
> .option push
> .option norelax
> .option norvc
> // Now we generate R_RISCV_ALIGN with addend 2, even if this is a norvc region.
> .balign 4
> b0:
>   .word 0x3a393837
> .option pop
> foo:
> ```

`-riscv-align-rvc=0` can be used to restore the R_RISCV_ALIGN `$alignment-4` behavior for norvc code, perhaps only useful for lld testing to ensure that it works with GNU Assembler.

All tests should pass now.

https://github.com/llvm/llvm-project/pull/150816


More information about the llvm-commits mailing list