Skip to content

Commit 0808ffb

Browse files
committed
export-file-local-symbol A,B: selective export of file-local symbols
Previously, --export-file-local-symbols would mark (and mangle) all file-local symbols. With --export-file-local-symbol A (or --export-file-local-symbol A,B), only A (or A and B) will be mangled and exported.
1 parent 38d945a commit 0808ffb

File tree

19 files changed

+91
-33
lines changed

19 files changed

+91
-33
lines changed

doc/architectural/static-functions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ We should now also write a harness for `private_function`. However,
9292
since that function is marked `static`, it is not possible for functions
9393
in external files to call it. We can write and link a harness by
9494
stripping the `static` attribute from `private_function` using goto-cc's
95-
`--export-file-local-symbols` flag.
95+
`--export-file-local-symbols` or `--export-file-local-symbol private_function`
96+
flag.
9697

9798
\code{.sh}
9899
> goto-cc -c -o --export-file-local-symbols library_with_static.o library.c

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ fi
5050
export_flag=""
5151
if is_in old-flag "$ALL_ARGS"; then
5252
export_flag="--export-function-local-symbols"
53+
elif is_in "export-[a-zA-Z0-9_,]*-only" "$ALL_ARGS"; then
54+
suffix=${ALL_ARGS#*export-}
55+
export_flag="--export-file-local-symbol ${suffix%-only*}"
5356
else
5457
export_flag="--export-file-local-symbols"
5558
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
static int foo(int x)
2+
{
3+
return x + 1;
4+
}
5+
6+
static int bar(int x)
7+
{
8+
return x + 2;
9+
}
10+
11+
static int baz(int x)
12+
{
13+
return x + 2;
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
export-foo,bar-only show-symbol-table
4+
^Symbol\.\.\.\.\.\.: __CPROVER_file_local_main_c_foo$
5+
^Symbol\.\.\.\.\.\.: __CPROVER_file_local_main_c_bar$
6+
^Symbol\.\.\.\.\.\.: baz$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
^Symbol\.\.\.\.\.\.: __CPROVER_file_local_main_c_baz$

src/ansi-c/ansi_c_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bool ansi_c_languaget::parse(
103103
bool ansi_c_languaget::typecheck(
104104
symbol_tablet &symbol_table,
105105
const std::string &module,
106-
const bool keep_file_local)
106+
const std::string &keep_file_local)
107107
{
108108
symbol_tablet new_symbol_table;
109109

src/ansi-c/ansi_c_language.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ansi_c_languaget:public languaget
5454
bool typecheck(
5555
symbol_tablet &symbol_table,
5656
const std::string &module,
57-
const bool keep_file_local) override;
57+
const std::string &keep_file_local) override;
5858

5959
bool can_keep_file_local() override
6060
{
@@ -64,7 +64,7 @@ class ansi_c_languaget:public languaget
6464
bool
6565
typecheck(symbol_tablet &symbol_table, const std::string &module) override
6666
{
67-
return typecheck(symbol_table, module, true);
67+
return typecheck(symbol_table, module, ".*");
6868
}
6969

7070
void show_parse(std::ostream &out) override;

src/cpp/cpp_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ bool cpp_languaget::typecheck(
131131
cpp_parse_tree, new_symbol_table, module, get_message_handler()))
132132
return true;
133133

134-
remove_internal_symbols(new_symbol_table, get_message_handler(), false);
134+
remove_internal_symbols(new_symbol_table, get_message_handler(), "");
135135

136136
return linking(symbol_table, new_symbol_table, get_message_handler());
137137
}

src/goto-cc/compile.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,13 @@ bool compilet::link(optionalt<symbol_tablet> &&symbol_table)
353353
convert_symbols(goto_model);
354354
}
355355

356-
if(keep_file_local)
356+
if(!keep_file_local.empty())
357357
{
358358
function_name_manglert<file_name_manglert> mangler(
359-
log.get_message_handler(), goto_model, file_local_mangle_suffix);
359+
log.get_message_handler(),
360+
goto_model,
361+
file_local_mangle_suffix,
362+
keep_file_local);
360363
mangler.mangle();
361364
}
362365

@@ -424,10 +427,13 @@ optionalt<symbol_tablet> compilet::compile()
424427
else
425428
cfn = output_file_object;
426429

427-
if(keep_file_local)
430+
if(!keep_file_local.empty())
428431
{
429432
function_name_manglert<file_name_manglert> mangler(
430-
log.get_message_handler(), file_goto_model, file_local_mangle_suffix);
433+
log.get_message_handler(),
434+
file_goto_model,
435+
file_local_mangle_suffix,
436+
keep_file_local);
431437
mangler.mangle();
432438
}
433439

@@ -652,8 +658,12 @@ compilet::compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
652658
warning_is_fatal(Werror),
653659
keep_file_local(
654660
// function-local is the old name and is still in use, but is misleading
655-
cmdline.isset("export-function-local-symbols") ||
656-
cmdline.isset("export-file-local-symbols")),
661+
(cmdline.isset("export-function-local-symbols") ||
662+
cmdline.isset("export-file-local-symbols"))
663+
? ".*"
664+
: (cmdline.isset("export-file-local-symbol")
665+
? cmdline.get_value("export-file-local-symbol")
666+
: "")),
657667
file_local_mangle_suffix(
658668
cmdline.isset("mangle-suffix") ? cmdline.get_value("mangle-suffix") : "")
659669
{

src/goto-cc/compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class compilet
111111
bool warning_is_fatal;
112112

113113
/// \brief Whether to keep implementations of file-local symbols
114-
const bool keep_file_local;
114+
const std::string keep_file_local;
115115

116116
/// \brief String to include in all mangled names
117117
const std::string file_local_mangle_suffix;

src/goto-cc/gcc_cmdline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const char *goto_cc_options_with_separated_argument[]=
2828
"--print-rejected-preprocessed-source",
2929
"--mangle-suffix",
3030
"--object-bits",
31+
"--export-file-local-symbol",
3132
nullptr
3233
};
3334

0 commit comments

Comments
 (0)