This is an archive of the discontinued LLVM Phabricator instance.

[GCOV] Set !kcfi_type metadata for indirectly called functions
ClosedPublic

Authored by samitolvanen on Jan 10 2023, 4:26 PM.

Details

Summary

With CONFIG_GCOV_KERNEL, the Linux kernel indirectly calls the
__llvm_gcov_* functions generated by LLVM. With -fsanitize=kcfi,
these calls are made from instrumented code and fail indirect
call checks as they don't have !kcfi_type metadata. Similarly
to D138945, set type metadata for these functions to allow GCOV
and KCFI to be both enabled.

Link: https://github.com/ClangBuiltLinux/linux/issues/1778

Diff Detail

Event Timeline

samitolvanen created this revision.Jan 10 2023, 4:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 4:26 PM
samitolvanen requested review of this revision.Jan 10 2023, 4:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 4:26 PM

Ensuring that every instrumentation works with kcfi is a lot of work on the compiler side (think that another instrumentation technique comes up, we need to update O(n) existing instrumentation passes) and I don't quite agree that it's compiler's responsibility.
But if sanitizers and gcov are all, I think it's fine...

llvm/include/llvm/Transforms/Utils/ModuleUtils.h
45

Used

llvm/test/Transforms/GCOVProfiling/kcfi.ll
26

This comment should be moved to the top.

samitolvanen marked 2 inline comments as done.

Addressed comments.

Ensuring that every instrumentation works with kcfi is a lot of work on the compiler side (think that another instrumentation technique comes up, we need to update O(n) existing instrumentation passes) and I don't quite agree that it's compiler's responsibility.
But if sanitizers and gcov are all, I think it's fine...

I agree, and yes, ASAN and GCOV are the only uses of global constructors in Linux.

MaskRay accepted this revision.Jan 11 2023, 11:16 AM

LGTM.

llvm/test/Transforms/GCOVProfiling/kcfi.ll
2
5

Line one would be better. (I know that many tests place the comment after all RUN lines.)

This revision is now accepted and ready to land.Jan 11 2023, 11:16 AM
This revision was landed with ongoing or failed builds.Jan 11 2023, 3:05 PM
This revision was automatically updated to reflect the committed changes.