cfgexpand: Protect arrays of any char-precision integer type
cfgexpand: Improves stack protector for arrays of char-like integer types, including those affected by LTO.
This change enhances the stack protector mechanism in cfgexpand to correctly guard arrays whose element types have the same precision as char. Previously, after Link-Time Optimization (LTO) processing, arrays of plain char and similar types (like char8_t, std::byte, etc.) were not reliably guarded, leaving functions vulnerable. The fix recursively checks the innermost element type, ensuring that arrays of any integral type with char precision are treated as character arrays for stack protection.
In Details
The stack_protect_classify_type function now recursively examines array element types to determine if they should be considered 'character arrays' for stack protection purposes. It identifies integral types with char precision, rather than relying solely on specific char-related type nodes. This addresses issues with LTO streaming and extends protection to types like char8_t, std::byte, _BitInt(8), and Ada's Boolean, while also correctly handling VLAs folded by CCP.
- cfgexpand
- A GCC pass responsible for expanding control flow graphs and performing various optimizations, including stack protection.
- stack protector
- A security feature that adds a 'canary' value to function stacks to detect buffer overflows. If the canary value is corrupted, the program is terminated.
- LTO
- Link-Time Optimization. A compilation technique where optimization occurs across multiple source files during the linking stage, allowing for more global optimizations.
- char
- A fundamental data type in C and C++ representing a single character, typically an 8-bit integer. It can be signed or unsigned depending on the platform or compiler.
- char8_t
- A distinct character type introduced in C++20 for UTF-8 string literals.
- std::byte
- A distinct type introduced in C++17, representing a byte of data rather than a character. It is an unsigned integral type.
- _BitInt(N)
- A GCC extension allowing for arbitrary-width integer types, where N specifies the number of bits.
- VLA
- Variable Length Array. An array whose size is determined at runtime.
- CCP
- Constant Propagation and Folding. A compiler optimization pass that replaces expressions with their constant values where possible.