Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: test/Transforms/NaCl/sandbox-indirect-calls.ll

Issue 29743003: Add passes for applying SFI sandboxing at the LLVM IR level Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Retry upload Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/Transforms/NaCl/flatten-globals.ll ('k') | test/Transforms/NaCl/sandbox-memory-accesses.ll » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Transforms/NaCl/sandbox-indirect-calls.ll
diff --git a/test/Transforms/NaCl/sandbox-indirect-calls.ll b/test/Transforms/NaCl/sandbox-indirect-calls.ll
new file mode 100644
index 0000000000000000000000000000000000000000..a858de6fad9d7b89e1cbe533867daec6830395ff
--- /dev/null
+++ b/test/Transforms/NaCl/sandbox-indirect-calls.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -sandbox-indirect-calls -S | FileCheck %s
+
+@addr_taker_var1 = global i32 ptrtoint (void ()* @target_func1 to i32)
+@addr_taker_var2 = global i32 ptrtoint (i32 (i32)* @target_func2 to i32)
+
+; CHECK: @addr_taker_var1 = global i32 1
+; CHECK: @addr_taker_var2 = global i32 2
+
+; CHECK: @__sfi_function_table = internal constant [3 x i8*] [i8* null, i8* bitcast (void ()* @target_func1 to i8*), i8* bitcast (i32 (i32)* @target_func2 to i8*)]
+
+
+define void @target_func1() {
+ ret void
+}
+
+define i32 @target_func2(i32 %arg) {
+ ret i32 %arg
+}
+
+; Direct calls should be left alone.
+define void @direct_call() {
+ call void @target_func1()
+ call i32 @target_func2(i32 123)
+ ret void
+}
+; CHECK: define void @direct_call() {
+; CHECK: call void @target_func1()
+; CHECK: call i32 @target_func2(i32 123)
+
+define i32 @addr_taker_func() {
+ %func = ptrtoint void ()* @target_func1 to i32
+ ret i32 %func
+}
+; CHECK: define i32 @addr_taker_func()
+; CHECK-NEXT: ret i32 1
+
+define void @caller(i32 %func) {
+ %func2 = inttoptr i32 %func to void ()*
+ call void %func2()
+ ret void
+}
+; CHECK: define void @caller(i32 %func) {
+; CHECK-NEXT: %func_gep = getelementptr {{.*}} @__sfi_function_table, i32 0, i32 %func
+; CHECK-NEXT: %func1 = load i8** %func_gep
+; CHECK-NEXT: %func_bc = bitcast i8* %func1 to void ()*
+; CHECK-NEXT: call void %func_bc()
+
+
+; Example of a function which doesn't follow the normal form, and
+; which isn't handled.
+;
+; declare void @f(...)
+;
+; define void @use_as_arg() {
+; call void (...)* @f(void ()* @target_func)
+; ret void
+; }
« no previous file with comments | « test/Transforms/NaCl/flatten-globals.ll ('k') | test/Transforms/NaCl/sandbox-memory-accesses.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698