RISC-V: Treat R_RISCV_ALIGN as relaxable code for later alignment
Make R_RISCV_ALIGN relocations in RISC-V act as relaxable code to allow subsequent alignments.
This patch ensures that R_RISCV_ALIGN relocations are treated as relaxable code by the assembler. This is necessary because an R_RISCV_ALIGN relocation itself can alter the section size. Consequently, subsequent alignment directives in non-relaxable code may require their own R_RISCV_ALIGN relocation to maintain correct alignment, even if no instructions immediately preceding them are relaxable.
- proposer
Proposes to mark R_RISCV_ALIGN as relaxable code, so that subsequent alignment in norelax code is handled correctly.
In Details
This patch modifies gas/config/tc-riscv.c to set the last_relax flag on the segment information when an R_RISCV_ALIGN relocation is generated. This ensures that the assembler treats the R_RISCV_ALIGN as a relaxable point, allowing subsequent alignment directives in norelax code to be correctly handled by the linker, preventing misalignments that could occur if the linker adjusts the section size due to the R_RISCV_ALIGN itself.
- 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.
- 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.
- norelax code
- Code segments where the assembler and linker are instructed not to perform relaxation, meaning their layout and addresses are fixed.
- Section size
- The total number of bytes occupied by a section within an object file or executable. Alignment directives and relocations can affect this size.