GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
risc-v

Zicfilp landing pads are now consistently 4-byte aligned

The Zicfilp extension for RISC-V now correctly aligns non-local goto target labels and exception landing pads to 4 bytes, preventing runtime errors.

This commit fixes an alignment issue for Zicfilp, a RISC-V extension. The compiler now ensures that non-local goto target labels and exception landing pads are 4-byte aligned by introducing a LABEL_ALIGN macro and modifying how gpr_save emits CFI guards. This change prevents potential runtime failures due to misaligned jump targets in generated code.

In Details

The Zicfilp RISC-V extension introduces specific requirements for Control-Flow Integrity (CFI) and non-local exits. This patch addresses an issue where landing pads (LPADs), used for exceptions and non-local gotos, were not consistently 4-byte aligned. The LABEL_ALIGN macro is introduced in riscv.h to enforce alignment for specific labels, while riscv-zicfilp.cc and riscv.md are updated to ensure the gpr_save instruction pattern correctly generates CFI sequences, including proper LPAD alignment for p2align 2 directives.

For Context

Compilers translate human-readable code into low-level machine instructions. Sometimes, a program needs to jump to a different part of the code outside the normal flow, like when an error (exception) occurs or when using a goto statement in C. For certain processor architectures, like RISC-V with its Zicfilp extension, these 'jump targets' (called landing pads) need to be placed at specific memory addresses that are multiples of 4 bytes. If they aren't, the program can crash. This change ensures the compiler correctly aligns these jump targets, preventing crashes in programs that rely on the Zicfilp extension on RISC-V processors by modifying how the compiler generates code for these special jumps.

Filed Under: risc-vzicfilpalignmentcfibugfix