llvm-project
llvm-project copied to clipboard
Functions with different KCFI types merged by MergeFunctions pass
In kernel we have a case where functions with different KCFI types being merged: https://lore.kernel.org/rust-for-linux/[email protected]/
Here's the minimized reproduction (https://godbolt.org/z/PhhcGh4W5):
source_filename = "example.7017d62d67f0b67e-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define noundef i32 @a() unnamed_addr #0 !kcfi_type !4 {
start:
ret i32 0
}
define noundef i32 @b() unnamed_addr #0 !kcfi_type !5 {
start:
ret i32 0
}
attributes #0 = { nounwind nonlazybind uwtable "probe-stack"="inline-asm" "target-cpu"="x86-64" }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 8, !"PIC Level", i32 2}
!1 = !{i32 2, !"RtLibUseGOT", i32 1}
!2 = !{i32 4, !"kcfi", i32 1}
!3 = !{!"rustc version 1.86.0 (05f9846f8 2025-03-31)"}
!4 = !{i32 1234}
!5 = !{i32 6789}
The functions are merged despite having different KCFI type.
Hello, I’m working on it.
The fix is to make FunctionComparator consider function-level !kcfi_type metadata, preventing MergeFunctions from merging functions with different KCFI IDs, and add regression tests.