Skip to content

Commit 5ecf2cf

Browse files
committed
Linking: update base name and pretty name of code-typed symbols
Name mangling via --export-file-local-symbols will introduce symbols the name of which does not match the base name. Forward declarations of the mangled name, however, do introduce a symbol where (mangled) name and base name match. When linking later finds the definition corresponding to such a forward declaration, the base name (and pretty name) need to be updated. Without these updates, the order of linking would produce two different final symbol tables.
1 parent 98bbe74 commit 5ecf2cf

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-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\.\.\.: foo$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
^Base name\.\.\.: __CPROVER_file_local_.*_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\.\.\.: foo$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
^Base name\.\.\.: __CPROVER_file_local_.*_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/linking/linking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ void linkingt::duplicate_code_symbol(
772772
// the one with body wins!
773773
rename_symbol(new_symbol.value);
774774
rename_symbol(new_symbol.type);
775+
old_symbol.base_name = new_symbol.base_name;
776+
old_symbol.pretty_name = new_symbol.pretty_name;
775777
old_symbol.value=new_symbol.value;
776778
old_symbol.type=new_symbol.type; // for parameter identifiers
777779
old_symbol.is_weak=new_symbol.is_weak;

0 commit comments

Comments
 (0)