-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[CFI][annotation] Leave alone function pointers in function annotations #80173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c91a3a6
[CFI][annotation] Leave alone function pointers in function annotations
a6fef79
Address review feedback
yozhu f8cfc2d
Address review feedback 2
yozhu b8e7d0a
Address review feedback 3
yozhu 083cb19
Address review feedback 4
yozhu 40eef6f
Remove unnecessary stuff from the test
yozhu 3ddede4
Address review feedback 5
yozhu 62eff41
Add REQUIRES to new test
yozhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yozhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| ; RUN: opt %s -o %t.bc | ||
| ; RUN: llvm-lto2 run %t.bc -r %t.bc,bar,px -r %t.bc,foo,px -r %t.bc,test,px \ | ||
| ; RUN: -r %t.bc,fptr1,px -r %t.bc,fptr2,px -save-temps -o %t.o | ||
| ; RUN: llvm-dis %t.*.opt.bc | ||
nikic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ; REM: Find the `llvm.global.annotations` symbol in `%t.*.opt.ll` and | ||
| ; REM: verify that no function annotation references CFI jump table entry. | ||
|
|
||
| ; RUN: grep llvm.global.annotations %t.*.opt.ll > %t.annotations | ||
| ; RUN: grep bar %t.annotations | ||
| ; RUN: grep foo %t.annotations | ||
| ; RUN: not grep cfi %t.annotations | ||
nikic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ; ModuleID = 'cfi-annotation' | ||
| source_filename = "ld-temp.o" | ||
| target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" | ||
| target triple = "aarch64-none-linux-gnu" | ||
yozhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @bar, ptr @.str, ptr @.str.1, i32 4, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @foo, ptr @.str.2, ptr @.str.1, i32 3, ptr null }], section "llvm.metadata" | ||
| @fptr1 = global ptr null, align 8 | ||
| @fptr2 = global ptr null, align 8 | ||
| @.str = private unnamed_addr constant [9 x i8] c"test_bar\00", section "llvm.metadata" | ||
| @.str.1 = private unnamed_addr constant [17 x i8] c"cfi-annotation.c\00", section "llvm.metadata" | ||
| @.str.2 = private unnamed_addr constant [9 x i8] c"test_foo\00", section "llvm.metadata" | ||
|
|
||
| ; Function Attrs: noinline nounwind optnone uwtable | ||
| define i32 @bar(i32 noundef %0) #0 !type !8 !type !9 { | ||
| %2 = alloca i32, align 4 | ||
| store i32 %0, ptr %2, align 4 | ||
| %3 = load i32, ptr %2, align 4 | ||
| %4 = add nsw i32 %3, -1 | ||
| store i32 %4, ptr %2, align 4 | ||
| %5 = call i32 @foo(i32 noundef %4) | ||
| %6 = load i32, ptr %2, align 4 | ||
| %7 = add nsw i32 %6, 1 | ||
| store i32 %7, ptr %2, align 4 | ||
| %8 = call i32 @foo(i32 noundef %7) | ||
| %9 = add nsw i32 %5, %8 | ||
| ret i32 %9 | ||
| } | ||
|
|
||
| declare !type !8 !type !9 i32 @foo(i32 noundef) #1 | ||
|
|
||
| ; Function Attrs: noinline nounwind optnone uwtable | ||
| define i32 @test(i32 noundef %0) #0 !type !8 !type !9 { | ||
| %2 = alloca i32, align 4 | ||
| store i32 %0, ptr %2, align 4 | ||
| %3 = load i32, ptr %2, align 4 | ||
| %4 = icmp sgt i32 %3, 0 | ||
| br i1 %4, label %5, label %6 | ||
|
|
||
| 5: ; preds = %1 | ||
| store ptr @bar, ptr @fptr1, align 8 | ||
| store ptr @foo, ptr @fptr2, align 8 | ||
| br label %7 | ||
|
|
||
| 6: ; preds = %1 | ||
| store ptr @bar, ptr @fptr1, align 8 | ||
| store ptr @foo, ptr @fptr2, align 8 | ||
| br label %7 | ||
|
|
||
| 7: ; preds = %6, %5 | ||
| %8 = load ptr, ptr @fptr1, align 8 | ||
| %9 = call i1 @llvm.type.test(ptr %8, metadata !"_ZTSFiiE"), !nosanitize !10 | ||
| br i1 %9, label %11, label %10, !nosanitize !10 | ||
|
|
||
| 10: ; preds = %7 | ||
| call void @llvm.ubsantrap(i8 2) #4, !nosanitize !10 | ||
| unreachable, !nosanitize !10 | ||
|
|
||
| 11: ; preds = %7 | ||
| %12 = load ptr, ptr @fptr2, align 8 | ||
| %13 = call i1 @llvm.type.test(ptr %12, metadata !"_ZTSFiiE"), !nosanitize !10 | ||
| br i1 %13, label %15, label %14, !nosanitize !10 | ||
|
|
||
| 14: ; preds = %11 | ||
| call void @llvm.ubsantrap(i8 2) #4, !nosanitize !10 | ||
| unreachable, !nosanitize !10 | ||
|
|
||
| 15: ; preds = %11 | ||
| %16 = load i32, ptr %2, align 4 | ||
| %17 = call i32 %12(i32 noundef %16) | ||
| %18 = call i32 %8(i32 noundef %17) | ||
| ret i32 %18 | ||
| } | ||
|
|
||
| ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) | ||
| declare i1 @llvm.type.test(ptr, metadata) #2 | ||
|
|
||
| ; Function Attrs: cold noreturn nounwind | ||
| declare void @llvm.ubsantrap(i8 immarg) #3 | ||
|
|
||
| attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+v8a,-fmv" } | ||
| attributes #1 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+v8a,-fmv" } | ||
| attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } | ||
| attributes #3 = { cold noreturn nounwind } | ||
| attributes #4 = { noreturn nounwind } | ||
|
|
||
| !llvm.ident = !{!0} | ||
| !llvm.module.flags = !{!1, !2, !3, !4, !5, !6, !7} | ||
|
|
||
| !0 = !{!"clang version 19.0.0git (https://github.com/yozhu/llvm-project.git a6fef79167066afdf715c6f1bb7834a9d04d575e)"} | ||
| !1 = !{i32 1, !"wchar_size", i32 4} | ||
| !2 = !{i32 4, !"CFI Canonical Jump Tables", i32 0} | ||
| !3 = !{i32 8, !"PIC Level", i32 2} | ||
| !4 = !{i32 7, !"uwtable", i32 2} | ||
| !5 = !{i32 7, !"frame-pointer", i32 1} | ||
| !6 = !{i32 1, !"ThinLTO", i32 0} | ||
| !7 = !{i32 1, !"EnableSplitLTOUnit", i32 1} | ||
| !8 = !{i64 0, !"_ZTSFiiE"} | ||
| !9 = !{i64 0, !"_ZTSFiiE.generalized"} | ||
| !10 = !{} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.