OLD | NEW |
(Empty) | |
| 1 ; RUN: opt < %s -sandbox-indirect-calls -S | FileCheck %s |
| 2 |
| 3 @addr_taker_var1 = global i32 ptrtoint (void ()* @target_func1 to i32) |
| 4 @addr_taker_var2 = global i32 ptrtoint (i32 (i32)* @target_func2 to i32) |
| 5 |
| 6 ; CHECK: @addr_taker_var1 = global i32 1 |
| 7 ; CHECK: @addr_taker_var2 = global i32 2 |
| 8 |
| 9 ; CHECK: @__sfi_function_table = internal constant [3 x i8*] [i8* null, i8* bitc
ast (void ()* @target_func1 to i8*), i8* bitcast (i32 (i32)* @target_func2 to i8
*)] |
| 10 |
| 11 |
| 12 define void @target_func1() { |
| 13 ret void |
| 14 } |
| 15 |
| 16 define i32 @target_func2(i32 %arg) { |
| 17 ret i32 %arg |
| 18 } |
| 19 |
| 20 ; Direct calls should be left alone. |
| 21 define void @direct_call() { |
| 22 call void @target_func1() |
| 23 call i32 @target_func2(i32 123) |
| 24 ret void |
| 25 } |
| 26 ; CHECK: define void @direct_call() { |
| 27 ; CHECK: call void @target_func1() |
| 28 ; CHECK: call i32 @target_func2(i32 123) |
| 29 |
| 30 define i32 @addr_taker_func() { |
| 31 %func = ptrtoint void ()* @target_func1 to i32 |
| 32 ret i32 %func |
| 33 } |
| 34 ; CHECK: define i32 @addr_taker_func() |
| 35 ; CHECK-NEXT: ret i32 1 |
| 36 |
| 37 define void @caller(i32 %func) { |
| 38 %func2 = inttoptr i32 %func to void ()* |
| 39 call void %func2() |
| 40 ret void |
| 41 } |
| 42 ; CHECK: define void @caller(i32 %func) { |
| 43 ; CHECK-NEXT: %func_gep = getelementptr {{.*}} @__sfi_function_table, i32 0, i32
%func |
| 44 ; CHECK-NEXT: %func1 = load i8** %func_gep |
| 45 ; CHECK-NEXT: %func_bc = bitcast i8* %func1 to void ()* |
| 46 ; CHECK-NEXT: call void %func_bc() |
| 47 |
| 48 |
| 49 ; Example of a function which doesn't follow the normal form, and |
| 50 ; which isn't handled. |
| 51 ; |
| 52 ; declare void @f(...) |
| 53 ; |
| 54 ; define void @use_as_arg() { |
| 55 ; call void (...)* @f(void ()* @target_func) |
| 56 ; ret void |
| 57 ; } |
OLD | NEW |