RISC-V: Emit R_RISCV_ALIGN in norelax code after relaxable code
Ensure RISC-V assembler emits R_RISCV_ALIGN relocations even in 'norelax' sections if relaxable code preceded them.
This patch modifies the RISC-V assembler to emit R_RISCV_ALIGN relocations even when the current section is marked as norelax (non-relaxable). This is crucial because if relaxable code appeared earlier in the same section, the linker might still shift the alignment point. Without this change, alignment directives like .balign 8 in norelax code following relaxable code could lead to misaligned labels or linker errors due to the unexpected movement of the alignment boundary.
- proposer
Proposes to emit R_RISCV_ALIGN in norelax code after relaxable code, to handle linker-shifted alignment points.
In Details
This patch modifies gas/config/tc-riscv.c to ensure that if riscv_opts.relax is true (meaning relaxation is enabled for the section) and the current fragment is last_relax, then an R_RISCV_ALIGN relocation is appended. This is done even if the .option norelax directive is active for the subsequent code. This addresses a scenario where relaxable code earlier in a section causes the linker to shift the alignment point, leading to incorrect padding or errors if the assembler doesn't account for this potential shift by emitting an R_RISCV_ALIGN relocation.
- R_RISCV_ALIGN
- A relocation type in RISC-V used by the assembler and linker to enforce alignment. It typically pads with no-operation (nop) instructions to meet a specified alignment boundary.
- norelax code
- Code segments where the assembler and linker are instructed not to perform relaxation, meaning their layout and addresses are fixed.
- Relaxable code
- Code segments or instructions that the linker can modify or adjust (e.g., change addresses, padding) to optimize for space or performance, or to satisfy alignment requirements.
- Alignment padding
- Extra bytes (often no-operation instructions) inserted by the assembler or linker to ensure that subsequent code or data starts at a memory address aligned to a specific boundary (e.g., 4-byte, 8-byte).