i386 emits ENDBR for cf_check functions
GCC now correctly emits the ENDBR instruction for cf_check functions, even when they are only called directly.
GCC’s i386 backend now correctly emits the ENDBR instruction at the entry of functions marked with the cf_check attribute, even if those functions are exclusively called directly. Previously, the rest_of_insert_endbr_and_patchable_area function would skip emitting ENDBR if only_called_directly_p was true. This change ensures that control-flow integrity protection is consistently applied as intended by the cf_check attribute, while respecting the nocf_check precedence.
In Details
The i386 backend's rest_of_insert_endbr_and_patchable_area function is updated to unconditionally emit the ENDBR instruction for functions with the cf_check attribute. Previously, it would skip this if only_called_directly_p was true. This commit rectifies a bug where control-flow integrity protection was bypassed in certain call scenarios, aligning the implementation with the attribute's intent. It does not affect functions with nocf_check.
- ENDBR
- End-Branch, a control-flow integrity (CFI) instruction that marks a valid indirect branch target. It helps protect against return-oriented programming (ROP) and jump-oriented programming (JOP) attacks.
- cf_check
- A GCC attribute that indicates a function should have the ENDBR instruction emitted at its entry, enforcing control-flow integrity.