Skip to content

Commit 100d938

Browse files
Daniel Kroeningpolgreen
authored andcommitted
goto-instrument: function pointer removal with value_set_fi
This adds a new option to goto-instrument for removing function pointers. The points-to analysis is done using flow-insensitive value sets, which is more precise than using the signature of the function to identify the points-to set.
1 parent af5bc99 commit 100d938

File tree

17 files changed

+957
-1
lines changed

17 files changed

+957
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f()
6+
{
7+
}
8+
9+
void g()
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
fp_t fp = f;
16+
fp();
17+
18+
// this would fool an analysis that looks for functions whose address is taken
19+
fp_t other_fp = g;
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: f$
7+
--
8+
^ function: g$
9+
--
10+
This test checks that the value-set-fi-based function pointer removal
11+
precisely identifies the function to call for a particular function pointer
12+
call.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
typedef void (*fp_t)(int, int);
3+
4+
void add(int a, int b)
5+
{
6+
7+
}
8+
void subtract(int a, int b)
9+
{
10+
11+
}
12+
void multiply(int a, int b)
13+
{
14+
15+
}
16+
17+
int main()
18+
{
19+
// fun_ptr_arr is an array of function pointers
20+
void (*fun_ptr_arr[])(int, int) = {add, subtract, add};
21+
22+
// Multiply should not be added into the value set
23+
fp_t other_fp = multiply;
24+
void (*fun_ptr_arr2[])(int, int) = {multiply, subtract, add};
25+
26+
// the fp removal over-approximates and assumes this could be any pointer in the array
27+
(*fun_ptr_arr[0])(1, 1);
28+
29+
return 0;
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: add$
7+
^ function: subtract$
8+
--
9+
^ function: multiply$
10+
--
11+
This test checks that the value-set-fi-based function pointer removal
12+
precisely identifies the function to call for a particular function pointer
13+
call.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
typedef void (*fp_t)(int, int);
2+
3+
void add(int a, int b)
4+
{
5+
6+
}
7+
void subtract(int a, int b)
8+
{
9+
10+
}
11+
void multiply(int a, int b)
12+
{
13+
14+
}
15+
16+
int main()
17+
{
18+
// fun_ptr_arr is an array of function pointers
19+
struct my_struct{
20+
fp_t first_pointer;
21+
fp_t second_pointer;
22+
} struct1;
23+
24+
struct1.first_pointer=add;
25+
26+
// Multiply and subtract should not be added into the value set
27+
fp_t other_fp = multiply;
28+
struct1.second_pointer=subtract;
29+
30+
// this pointer can only be "add"
31+
struct1.first_pointer(1,1);
32+
33+
return 0;
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: add$
7+
--
8+
^ function: multiply$
9+
^ function: subtract$
10+
--
11+
This test checks that the value-set-fi-based function pointer removal
12+
precisely identifies the function to call for a particular function pointer
13+
call.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f()
6+
{
7+
}
8+
9+
void g()
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
fp_t fp;
16+
fp();
17+
18+
// the value set is empty, defaults to standard function pointer removal behaviour
19+
fp_t other_fp = g;
20+
other_fp = f;
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^file test.c line 16 function main: replacing function pointer by 2 possible targets$
7+
--
8+
This test checks that the value-set-fi-based function pointer removal
9+
precisely identifies the function to call for a particular function pointer
10+
call.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f(int x)
6+
{
7+
}
8+
9+
void g(int y)
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
fp_t fp;
16+
fp();
17+
18+
// the value set is empty, defaults to standard function pointer removal behaviour
19+
fp_t other_fp = g;
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^file test.c line 16 function main: replacing function pointer by 0 possible targets$
7+
8+
--
9+
This test checks that the value-set-fi-based function pointer removal
10+
precisely identifies the function to call for a particular function pointer
11+
call.

0 commit comments

Comments
 (0)