llvm-project
901520fb - [RISCV][Zicfilp] fix KCFI clobbering x7 when cf-protection=branch is enabled (#240347)

Commit
7 hours ago
[RISCV][Zicfilp] fix KCFI clobbering x7 when cf-protection=branch is enabled (#240347) When enabling KCFI and cf-protection=branch (-fcf-branch-label-scheme=unlabeled, -riscv-landing-pad-label=<some-non-0-value>), the KCFI check sequence lands between the cf-protection=branch Label loading (`lui t2, Label`) instruction and the indirect call `jalr a2`. KCFI may clobber x7/t2 because it is one of its default scratch registers; at the time of the indirect jump it may no longer contain the correct value for the landing pad label. KCFI now avoids x7/t2 when cf-protection=branch is enabled, causing it to select one of its fallback scratch registers (x28-x31) instead. In the test example it falls back to x28/t3. This patch is a prerequisite for the zicfilp func-sig label scheme implementation https://github.com/llvm/llvm-project/pull/240344 because the func-sig label scheme working correctly also depends on this bug being fixed. The patch contains a corresponding regression test.
Author
Parents
Loading