Skip to content

Commit 56d8346

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 176abd7 commit 56d8346

File tree

12 files changed

+121
-40
lines changed

12 files changed

+121
-40
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-06/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ CORE
22
main.c
33

44
function 'memcpy' is not declared
5-
parameter "memcpy::dst" type mismatch
6-
^EXIT=6$
5+
Linking library function 'memcpy' failed
6+
^EXIT=0$
77
^SIGNAL=0$
88
--
99
^warning: ignoring

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/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
strcpy-no-decl.c
33
--string-abstraction --validate-goto-model
4-
Condition: strlen type inconsistency
4+
^Condition: fct_type.parameters\(\).size\(\) == parameter_identifiers.size\(\)$
55
^EXIT=(127|134)$
66
^SIGNAL=0$
77
--

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
@@ -94,7 +94,8 @@ std::string get_cprover_library_text(
9494

9595
void cprover_c_library_factory(
9696
const std::set<irep_idt> &functions,
97-
symbol_tablet &symbol_table,
97+
const symbol_tablet &symbol_table,
98+
symbol_tablet &dest_symbol_table,
9899
message_handlert &message_handler)
99100
{
100101
if(config.ansi_c.lib==configt::ansi_ct::libt::LIB_NONE)
@@ -104,7 +105,7 @@ void cprover_c_library_factory(
104105

105106
library_text=get_cprover_library_text(functions, symbol_table);
106107

107-
add_library(library_text, symbol_table, message_handler);
108+
add_library(library_text, dest_symbol_table, message_handler);
108109
}
109110

110111
void add_library(

src/ansi-c/cprover_library.h

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

3737
void cprover_c_library_factory(
3838
const std::set<irep_idt> &functions,
39+
const symbol_tablet &,
3940
symbol_tablet &,
4041
message_handlert &);
4142

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_tablet &symbol_table,
40+
const symbol_tablet &symbol_table,
41+
symbol_tablet &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_tablet;
1818

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

0 commit comments

Comments
 (0)