Skip to content

Commit 70ca8a6

Browse files
authored
Merge pull request #5353 from azcwagner/export-local-sym-patch
Allow file-local symbol mangling for multi-file compilation
2 parents 830c302 + fcd1083 commit 70ca8a6

File tree

5 files changed

+86
-32
lines changed

5 files changed

+86
-32
lines changed

regression/goto-cc-file-local/chain.sh

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,61 @@ else
5454
export_flag="--export-file-local-symbols"
5555
fi
5656

57-
cnt=0
58-
for src in ${SRC}; do
59-
cnt=$((cnt + 1))
60-
out_suffix=""
61-
if is_in out-file-counter "$ALL_ARGS"; then
62-
out_suffix="_$cnt"
63-
if is_in suffix "$ALL_ARGS"; then
64-
suffix="--mangle-suffix custom_$cnt"
57+
OUT_FILE="main.gb"
58+
if is_in compile-and-link "$ALL_ARGS"; then
59+
if [[ "${is_windows}" == "true" ]]; then
60+
"${goto_cc}" \
61+
${export_flag} \
62+
--verbosity 10 \
63+
${wall} \
64+
${suffix} \
65+
${SRC} \
66+
/Fe"${OUT_FILE}"
67+
68+
else
69+
"${goto_cc}" \
70+
${export_flag} \
71+
--verbosity 10 \
72+
${wall} \
73+
${suffix} \
74+
${SRC} \
75+
-o "${OUT_FILE}"
6576
fi
66-
fi
67-
68-
base=${src%.c}
69-
OUT_FILE=$(basename "${base}${out_suffix}")".gb"
70-
71-
if [[ "${is_windows}" == "true" ]]; then
72-
"${goto_cc}" \
73-
${export_flag} \
74-
--verbosity 10 \
75-
${wall} \
76-
${suffix} \
77-
/c "${base}.c" \
78-
/Fo"${OUT_FILE}"
79-
80-
else
81-
"${goto_cc}" \
82-
${export_flag} \
83-
--verbosity 10 \
84-
${wall} \
85-
${suffix} \
86-
-c "${base}.c" \
87-
-o "${OUT_FILE}"
88-
fi
89-
done
77+
else
78+
cnt=0
79+
for src in ${SRC}; do
80+
cnt=$((cnt + 1))
81+
out_suffix=""
82+
if is_in out-file-counter "$ALL_ARGS"; then
83+
out_suffix="_$cnt"
84+
if is_in suffix "$ALL_ARGS"; then
85+
suffix="--mangle-suffix custom_$cnt"
86+
fi
87+
fi
88+
89+
base=${src%.c}
90+
OUT_FILE=$(basename "${base}${out_suffix}")".gb"
91+
92+
if [[ "${is_windows}" == "true" ]]; then
93+
"${goto_cc}" \
94+
${export_flag} \
95+
--verbosity 10 \
96+
${wall} \
97+
${suffix} \
98+
/c "${base}.c" \
99+
/Fo"${OUT_FILE}"
100+
101+
else
102+
"${goto_cc}" \
103+
${export_flag} \
104+
--verbosity 10 \
105+
${wall} \
106+
${suffix} \
107+
-c "${base}.c" \
108+
-o "${OUT_FILE}"
109+
fi
110+
done
111+
fi
90112

91113
if is_in final-link "$ALL_ARGS"; then
92114
OUT_FILE=final-link.gb
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
3+
static int foo()
4+
{
5+
assert(0);
6+
return 1;
7+
}
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+
return __CPROVER_file_local_foo_c_foo();
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
assertion-check compile-and-link
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
9+
^\*\*\*\* WARNING: no body for function
10+
--
11+
Check that when files are compiled together in a single invocation
12+
of goto-cc, exported function symbols are still mangled correctly.

src/goto-cc/compile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ bool compilet::link()
346346
convert_symbols(goto_model.goto_functions);
347347
}
348348

349+
if(keep_file_local)
350+
{
351+
function_name_manglert<file_name_manglert> mangler(
352+
get_message_handler(), goto_model, file_local_mangle_suffix);
353+
mangler.mangle();
354+
}
355+
349356
if(write_bin_object_file(output_file_executable, goto_model))
350357
return true;
351358

0 commit comments

Comments
 (0)