Warn about non-power-of-2 stack-align attribute in RISC-V
RISC-V linker now warns about and ignores non-power-of-2 stack-align attributes.
The RISC-V BFD linker now issues a warning and ignores stack_align attributes that are not a power of two. Alignment values must be powers of two to be meaningful. This change ensures that the linker handles invalid alignment attributes gracefully, preventing potential misconfigurations.
In Details
The riscv_merge_attributes function in bfd/elfxx-riscv.c is updated to validate the Tag_RISCV_stack_align attribute. It now checks if the provided value is a power of two using (value & (value - 1)) == 0. If not, a warning is issued, and the attribute is ignored by setting it to 0. This enforces correct usage of the attribute, as non-power-of-two values are nonsensical for alignment.
- RISC-V
- An open-source instruction set architecture (ISA) that is modular and extensible.
- BFD
- Binary File Descriptor library. A layer in GNU Binutils that provides a common interface to various object file formats.
- stack-align attribute
- A RISC-V specific attribute that specifies the alignment requirement for the stack pointer. This affects how function calls and stack frame management are handled.
- power-of-2
- A number that can be expressed as 2 raised to an integer exponent (e.g., 2, 4, 8, 16, 32, 64).