RISC-V/bfd: warn about non-power-of-2 stack-align attribute
Warn about and ignore non-power-of-2 values for the RISC-V stack_align attribute.
This patch introduces a warning for non-power-of-2 values used with the RISC-V stack_align attribute, enforcing sensible alignment. It also refactors some conditional logic for clarity. The change ensures that only power-of-2 alignment values are accepted, promoting correct code generation.
- proposer
Proposes to warn about and ignore non-power-of-2 values for the RISC-V stack_align attribute, ensuring sensible alignment.
“Only power-of-2 values are sensible for alignment. Reject other values. While there also drop a redundant part of a related conditional.”
- reviewer
Reviewed the patch, suggesting adding an underscore to the diagnostic message in version 4.
Technical Tradeoffs
- Enforces stricter validation of the stack_align attribute, potentially rejecting some previously accepted code.
- Improves robustness by preventing the use of non-sensical alignment values.
In Details
This patch modifies the BFD library's ELF handling for RISC-V to validate the Tag_RISCV_stack_align attribute. It ensures that only power-of-2 values are accepted for stack alignment, aligning with hardware capabilities and preventing incorrect interpretations of alignment specifications that could impact performance or correctness.
- BFD
- Binary File Descriptor library, a GNU component that abstracts different object file formats.
- ELF
- Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps.
- RISC-V
- An open-source instruction set architecture (ISA) that is gaining popularity for its modularity and extensibility.
- tag_RISCV_stack_align
- An ELF tag specific to RISC-V that specifies the required stack alignment.