Skip to content

Commit 7f1cc0f

Browse files
Use the linker when adding library functions
This enables type checking of missing functions vs library-provided functions, and also enables type sanitisation as done by the linker. Co-authored-by: Peter Schrammel <[email protected]>
1 parent 7065034 commit 7f1cc0f

File tree

12 files changed

+133
-44
lines changed

12 files changed

+133
-44
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <assert.h>
22
#include <errno.h>
33

4-
int main()
4+
int main(int arc, char *argv[])
55
{
6-
__errno_location();
7-
assert(0);
6+
// errno expands to use of __errno_location() with glibc
7+
assert(errno == 0);
88
return 0;
99
}

regression/cbmc-library/__errno_location-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/memcpy-07/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// #include <string.h> intentionally omitted
2+
void *memcpy();
23

34
struct c
45
{

regression/cbmc/String_Abstraction17/strcpy-no-decl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
void *malloc(unsigned);
1+
#include <stdlib.h>
2+
// string.h intentionally omitted
23

34
char *make_str()
45
{
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
CORE
22
strcpy-no-decl.c
33
--string-abstraction --validate-goto-model
4-
Condition: strlen type inconsistency
5-
^EXIT=(127|134)$
4+
^EXIT=10$
65
^SIGNAL=0$
76
--
87
^warning: ignoring
98
--
10-
While this test currently passes when omitting --validate-goto-model, we should
11-
expect a report of type inconsistencies as no forward declarations are present.
9+
The linker is able to fix up type inconsistencies of the missing function
10+
declarations, but the absence of a declaration of strlen results in not picking
11+
up the library model. Consequently the assumption does not work as intended, and
12+
verification fails. Adding #include <string.h> makes verification pass as
13+
expected.

regression/goto-cc-goto-analyzer/instrument_preconditions_locations/s2n_hash_inlined.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdlib.h>
2+
13
// This file is highly reduced from some open source projects.
24
// The following four lines are adapted from the openssl library
35
// Full repository here:

src/ansi-c/cprover_library.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ std::string get_cprover_library_text(
9898

9999
void cprover_c_library_factory(
100100
const std::set<irep_idt> &functions,
101-
symbol_table_baset &symbol_table,
101+
const symbol_table_baset &symbol_table,
102+
symbol_table_baset &dest_symbol_table,
102103
message_handlert &message_handler)
103104
{
104105
if(config.ansi_c.lib==configt::ansi_ct::libt::LIB_NONE)
@@ -107,7 +108,7 @@ void cprover_c_library_factory(
107108
std::string library_text =
108109
get_cprover_library_text(functions, symbol_table, false);
109110

110-
add_library(library_text, symbol_table, message_handler);
111+
add_library(library_text, dest_symbol_table, message_handler);
111112
}
112113

113114
void add_library(

src/ansi-c/cprover_library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void add_library(
4141

4242
void cprover_c_library_factory(
4343
const std::set<irep_idt> &functions,
44+
const symbol_table_baset &,
4445
symbol_table_baset &,
4546
message_handlert &);
4647

src/cpp/cprover_library.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static std::string get_cprover_library_text(
3737

3838
void cprover_cpp_library_factory(
3939
const std::set<irep_idt> &functions,
40-
symbol_table_baset &symbol_table,
40+
const symbol_table_baset &symbol_table,
41+
symbol_table_baset &dest_symbol_table,
4142
message_handlert &message_handler)
4243
{
4344
if(config.ansi_c.lib == configt::ansi_ct::libt::LIB_NONE)
@@ -46,5 +47,5 @@ void cprover_cpp_library_factory(
4647
const std::string library_text =
4748
get_cprover_library_text(functions, symbol_table);
4849

49-
add_library(library_text, symbol_table, message_handler);
50+
add_library(library_text, dest_symbol_table, message_handler);
5051
}

src/cpp/cprover_library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class symbol_table_baset;
1818

1919
void cprover_cpp_library_factory(
2020
const std::set<irep_idt> &functions,
21+
const symbol_table_baset &,
2122
symbol_table_baset &,
2223
message_handlert &);
2324

0 commit comments

Comments
 (0)