Skip to content

Commit 00b1797

Browse files
committed
Add --export-function-local-symbols to goto-cc
This switch makes goto-cc do three things: - retain the implementations of all static functions. - mangle the names of all static functions. - unset the file_local flag on all static function symbols. This feature is intended to help users writing CBMC checks for file-local functions (i.e., those declared as `static` in the C language). The intended workflow is: compile the code under test with the -fkeep-static-functions flag. Then link the code under test with the 'harness' file, again using the flag. This allows the harness to call into static functions in the codebase under test.
1 parent 7282cfc commit 00b1797

File tree

32 files changed

+505
-6
lines changed

32 files changed

+505
-6
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ add_subdirectory(goto-cc-goto-analyzer)
5050
add_subdirectory(systemc)
5151
add_subdirectory(contracts)
5252
add_subdirectory(goto-harness)
53+
add_subdirectory(goto-cc-file-local)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument> $<TARGET_FILE:cbmc> ${is_windows}"
9+
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Invoke one or more CPROVER tools depending on arguments
4+
#
5+
# Author: Kareem Khazem <[email protected]>
6+
7+
is_in()
8+
{
9+
[[ "$2" =~ $1 ]] && return 0 || return 1
10+
}
11+
12+
ALL_ARGS="$@"
13+
OUT_FILE=""
14+
15+
if is_in suffix "$ALL_ARGS"; then
16+
suffix="--mangle-suffix custom_suffix"
17+
else
18+
suffix=""
19+
fi
20+
21+
goto_cc=$1
22+
goto_instrument=$2
23+
cbmc=$3
24+
is_windows=$4
25+
26+
for src in *.c; do
27+
base=${src%.c}
28+
OUT_FILE="${base}.gb"
29+
30+
if [[ "${is_windows}" == "true" ]]; then
31+
"${goto_cc}" \
32+
/export-function-local-symbols \
33+
/verbosity 10 \
34+
${suffix} \
35+
/c"${base}.c" \
36+
/Fo"${OUT_FILE}"
37+
38+
elif [[ "${is_windows}" == "false" ]]; then
39+
"${goto_cc}" \
40+
--export-function-local-symbols \
41+
--verbosity 10 \
42+
${suffix} \
43+
-c "${base}.c" \
44+
-o "${OUT_FILE}"
45+
else
46+
(>&2 echo "\$is_windows should be true or false (got '" "${is_windows}" "')")
47+
exit 1
48+
fi
49+
done
50+
51+
if is_in final-link "$ALL_ARGS"; then
52+
OUT_FILE=final-link.gb
53+
if [[ "${is_windows}" == "true" ]]; then
54+
"${goto_cc}" \
55+
/export-function-local-symbols \
56+
/verbosity 10 \
57+
${suffix} \
58+
./*.gb \
59+
/Fe "${OUT_FILE}"
60+
61+
elif [[ "${is_windows}" == "false" ]]; then
62+
"${goto_cc}" \
63+
--export-function-local-symbols \
64+
--verbosity 10 \
65+
${suffix} \
66+
./*.gb \
67+
-o "${OUT_FILE}"
68+
fi
69+
fi
70+
71+
if is_in show-symbol-table "$ALL_ARGS"; then
72+
"${goto_instrument}" --show-symbol-table "${OUT_FILE}"
73+
fi
74+
75+
if is_in assertion-check "$ALL_ARGS"; then
76+
"${cbmc}" "${OUT_FILE}"
77+
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
static int foo()
2+
{
3+
assert(0);
4+
return 1;
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int __CPROVER_file_local_foo_c_foo();
2+
3+
int main()
4+
{
5+
int x = __CPROVER_file_local_foo_c_foo();
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
final-link assertion-check
4+
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
10+
^\*\*\*\* WARNING: no body for function
11+
--
12+
Check that CBMC symbolically executes a static function in a different
13+
file
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
static int foo()
2+
{
3+
return 1;
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int __CPROVER_file_local_foo_c_foo();
2+
3+
int main()
4+
{
5+
int x = __CPROVER_file_local_foo_c_foo();
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
final-link assertion-check
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring
10+
^\*\*\*\* WARNING: no body for function
11+
--
12+
Check that CBMC symbolically executes a static function in a different
13+
file
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
static int bar()
2+
{
3+
assert(0);
4+
return 1;
5+
}
6+
7+
static int foo()
8+
{
9+
return bar();
10+
}

0 commit comments

Comments
 (0)