This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][KCFI] Move cfi-type lowering to TargetLowering
ClosedPublic

Authored by samitolvanen on May 4 2023, 3:50 PM.

Details

Summary

KCFI machine function passes transform indirect calls with a
cfi-type attribute into architecture-specific type checks bundled
together with the calls. Instead of having a separate pass for each
architecture, add a generic machine function pass for KCFI and
move the architecture-specific code that emits the actual check to
TargetLowering. This avoids unnecessary duplication and makes it
easier to add KCFI support to other architectures.

Diff Detail

Event Timeline

samitolvanen created this revision.May 4 2023, 3:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 3:50 PM
samitolvanen requested review of this revision.May 4 2023, 3:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 3:50 PM
nickdesaulniers accepted this revision.May 5 2023, 10:17 AM

Thanks for the patch! Nice refactoring.

llvm/include/llvm/LinkAllPasses.h
96

fix indentation

This revision is now accepted and ready to land.May 5 2023, 10:17 AM
barannikov88 added inline comments.
llvm/lib/CodeGen/KCFI.cpp
9

It is KFCI everywhere. At least in one place it should be explained what these four magical letters mean.
File comment would be a good place.
(I honestly have no idea about it, "kernel call frame information" is the first thing that comes to my mind.)

MaskRay added inline comments.May 9 2023, 1:00 PM
llvm/lib/CodeGen/KCFI.cpp
9

CFI here means Control-flow integrity. This is an implementation that is dedicated to the Linux kernel
https://maskray.me/blog/2022-12-18-control-flow-integrity#fsanitizekcfi

(I need to do some homework that why this has a lot to do with codegen.)

barannikov88 added inline comments.May 9 2023, 1:21 PM
llvm/lib/CodeGen/KCFI.cpp
9

Thanks. I'll check out the blog post, too (nice blog btw, very informative).
I still think the abbreviation needs to be explained in code. Or, better yet, what does this pass do.

samitolvanen added inline comments.May 9 2023, 1:45 PM
llvm/lib/CodeGen/KCFI.cpp
9

Good point. I'll expand this comment in a follow-up patch.

samitolvanen added inline comments.May 9 2023, 4:42 PM
barannikov88 added inline comments.May 9 2023, 9:05 PM
llvm/lib/CodeGen/KCFI.cpp
9

Awesome, thank you

llvm/lib/Target/X86/X86InstrInfo.cpp