Skip to content

Commit 37fcd4a

Browse files
committed
export-file-local_symbols:: update base name and pretty name
Name mangling via --export-file-local-symbols used to introduce symbols the name of which did not match the base name. Forward declarations of the mangled name, however, did introduce a symbol where (mangled) name and base name match. When linking later found the definition corresponding to such a forward declaration, the base name (and pretty name) were not updated. As a consequence the order of linking produced two different final symbol tables. Note that Crangler may be a superior alternative avoiding such problems, but there is ample code that still uses `--export-file-local-symbols`.
1 parent b08632a commit 37fcd4a

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int __CPROVER_file_local_file2_c_foo(int x);
2+
3+
int main()
4+
{
5+
int x = __CPROVER_file_local_file2_c_foo(1);
6+
__CPROVER_assert(x == 2, "x == 2");
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
file1.c
3+
final-link show-symbol-table assertion-check
4+
^Base name\.\.\.: __CPROVER_file_local_.*_foo$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
^Base name\.\.\.: foo$
10+
--
11+
The linking order must not affect the base name of the mangled symbol. See
12+
base-name-2 for a test that will yield a different linking order (while still
13+
producing the same base name).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int __CPROVER_file_local_file1_c_foo(int x);
2+
3+
int main()
4+
{
5+
int x = __CPROVER_file_local_file1_c_foo(1);
6+
__CPROVER_assert(x == 2, "x == 2");
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
file1.c
3+
final-link show-symbol-table assertion-check
4+
^Base name\.\.\.: __CPROVER_file_local_.*_foo$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
^Base name\.\.\.: foo$
10+
--
11+
The linking order must not affect the base name of the mangled symbol. See
12+
base-name-1 for a test that will yield a different linking order (while still
13+
producing the same base name).

src/goto-programs/name_mangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class function_name_manglert
7070
symbolt new_sym;
7171
new_sym = sym;
7272
new_sym.name = mangled;
73+
new_sym.base_name = mangled;
74+
if(new_sym.pretty_name.empty())
75+
new_sym.pretty_name = sym.base_name;
7376
new_sym.is_file_local = false;
7477

7578
new_syms.push_back(new_sym);

0 commit comments

Comments
 (0)