Skip to content

Commit 5ae0a43

Browse files
authored
Merge pull request #1028 from goblint/libfuns-activated
Add option `lib.activated`
2 parents 3f6fbf2 + 9c17fdc commit 5ae0a43

File tree

10 files changed

+93
-24
lines changed

10 files changed

+93
-24
lines changed

conf/zstd-race.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
"lines": true
3232
}
3333
},
34+
"lib": {
35+
"activated": [
36+
"c",
37+
"posix",
38+
"pthread",
39+
"gcc",
40+
"glibc",
41+
"linux-userspace",
42+
"zstd"
43+
]
44+
},
3445
"sem": {
3546
"unknown_function": {
3647
"spawn": false,

src/analyses/libraryFunctions.ml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ let big_kernel_lock = AddrOf (Cil.var (Goblintutil.create_var (makeGlobalVar "[b
258258
let console_sem = AddrOf (Cil.var (Goblintutil.create_var (makeGlobalVar "[console semaphore]" intType)))
259259

260260
(** Linux kernel functions. *)
261-
(* TODO: conditional on kernel option *)
262-
let linux_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
261+
let linux_kernel_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
263262
("spin_lock_irqsave", special [__ "lock" []; drop "flags" []] @@ fun lock -> Lock { lock; try_ = get_bool "sem.lock.fail"; write = true; return_on_success = true });
264263
("spin_unlock_irqrestore", special [__ "lock" []; drop "flags" []] @@ fun lock -> Unlock lock);
265264
("_raw_spin_unlock_irqrestore", special [__ "lock" []; drop "flags" []] @@ fun lock -> Unlock lock);
@@ -396,7 +395,6 @@ let verifier_atomic = AddrOf (Cil.var (Goblintutil.create_var verifier_atomic_va
396395

397396
(** SV-COMP functions.
398397
Just the ones that require special handling and cannot be stubbed. *)
399-
(* TODO: conditional on ana.sv-comp.functions option *)
400398
let svcomp_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
401399
("__VERIFIER_atomic_begin", special [] @@ Lock { lock = verifier_atomic; try_ = false; write = true; return_on_success = true });
402400
("__VERIFIER_atomic_end", special [] @@ Unlock verifier_atomic);
@@ -427,22 +425,29 @@ let ncurses_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
427425
("wbkgd", unknown [drop "win" [r_deep; w_deep]; drop "ch" []]);
428426
]
429427

430-
(* TODO: allow selecting which lists to use *)
431-
let library_descs = Hashtbl.of_list (List.concat [
432-
c_descs_list;
433-
posix_descs_list;
434-
pthread_descs_list;
435-
gcc_descs_list;
436-
glibc_desc_list;
437-
linux_userspace_descs_list;
438-
linux_descs_list;
439-
goblint_descs_list;
440-
zstd_descs_list;
441-
math_descs_list;
442-
svcomp_descs_list;
443-
ncurses_descs_list;
444-
])
428+
let libraries = Hashtbl.of_list [
429+
("c", c_descs_list @ math_descs_list);
430+
("posix", posix_descs_list);
431+
("pthread", pthread_descs_list);
432+
("gcc", gcc_descs_list);
433+
("glibc", glibc_desc_list);
434+
("linux-userspace", linux_userspace_descs_list);
435+
("linux-kernel", linux_kernel_descs_list);
436+
("goblint", goblint_descs_list);
437+
("sv-comp", svcomp_descs_list);
438+
("ncurses", ncurses_descs_list);
439+
("zstd", zstd_descs_list);
440+
]
445441

442+
let activated_library_descs: (string, LibraryDesc.t) Hashtbl.t ResettableLazy.t =
443+
ResettableLazy.from_fun (fun () ->
444+
let activated = List.unique (GobConfig.get_string_list "lib.activated") in
445+
let desc_list = List.concat_map (Hashtbl.find libraries) activated in
446+
Hashtbl.of_list desc_list
447+
)
448+
449+
let reset_lazy () =
450+
ResettableLazy.reset activated_library_descs
446451

447452
type categories = [
448453
| `Malloc of exp
@@ -1149,7 +1154,7 @@ let unknown_desc ~f name = (* TODO: remove name argument, unknown function shoul
11491154

11501155
let find f =
11511156
let name = f.vname in
1152-
match Hashtbl.find_option library_descs name with
1157+
match Hashtbl.find_option (ResettableLazy.force activated_library_descs) name with
11531158
| Some desc -> desc
11541159
| None ->
11551160
match get_invalidate_action name with

src/analyses/libraryFunctions.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ val is_special: Cil.varinfo -> bool
1717

1818

1919
val verifier_atomic_var: Cil.varinfo
20+
21+
val reset_lazy: unit -> unit

src/maingoblint.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ let handle_flags () =
157157
if get_bool "dbg.debug" then
158158
set_bool "warn.debug" true;
159159

160+
if get_bool "ana.sv-comp.functions" then
161+
set_auto "lib.activated[+]" "sv-comp";
162+
163+
if get_bool "kernel" then
164+
set_auto "lib.activated[+]" "linux-kernel";
165+
160166
match get_string "dbg.dump" with
161167
| "" -> ()
162168
| path ->
@@ -356,9 +362,13 @@ let preprocess_files () =
356362

357363
let extra_files = ref [] in
358364

359-
extra_files := find_custom_include (Fpath.v "stdlib.c") :: find_custom_include (Fpath.v "pthread.c") :: !extra_files;
365+
if List.mem "c" (get_string_list "lib.activated") then
366+
extra_files := find_custom_include (Fpath.v "stdlib.c") :: !extra_files;
360367

361-
if get_bool "ana.sv-comp.functions" then
368+
if List.mem "pthread" (get_string_list "lib.activated") then
369+
extra_files := find_custom_include (Fpath.v "pthread.c") :: !extra_files;
370+
371+
if List.mem "sv-comp" (get_string_list "lib.activated") then
362372
extra_files := find_custom_include (Fpath.v "sv-comp.c") :: !extra_files;
363373

364374
let preprocessed = List.concat_map preprocess_arg_file (!extra_files @ List.map Fpath.v (get_string_list "files")) in

src/util/options.schema.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,45 @@
12251225
},
12261226
"additionalProperties": false
12271227
},
1228+
"lib": {
1229+
"title": "Library functions",
1230+
"description": "Options for library functions",
1231+
"type": "object",
1232+
"properties": {
1233+
"activated": {
1234+
"title": "lib.activated",
1235+
"description": "List of activated libraries.",
1236+
"type": "array",
1237+
"items": {
1238+
"type": "string",
1239+
"enum": [
1240+
"c",
1241+
"posix",
1242+
"pthread",
1243+
"gcc",
1244+
"glibc",
1245+
"linux-userspace",
1246+
"linux-kernel",
1247+
"goblint",
1248+
"sv-comp",
1249+
"ncurses",
1250+
"zstd"
1251+
]
1252+
},
1253+
"default": [
1254+
"c",
1255+
"posix",
1256+
"pthread",
1257+
"gcc",
1258+
"glibc",
1259+
"linux-userspace",
1260+
"goblint",
1261+
"ncurses"
1262+
]
1263+
}
1264+
},
1265+
"additionalProperties": false
1266+
},
12281267
"sem": {
12291268
"title": "Semantics",
12301269
"description": "Options for semantics",

src/util/server.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ let analyze ?(reset=false) (s: t) =
278278
PrecisionUtil.reset_lazy ();
279279
ApronDomain.reset_lazy ();
280280
AutoTune.reset_lazy ();
281+
LibraryFunctions.reset_lazy ();
281282
Access.reset ();
282283
s.file <- Some file;
283284
GobConfig.set_bool "incremental.load" (not fresh);

tests/regression/03-practical/25-zstd-customMem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// PARAM: --set lib.activated[+] zstd
12
// Extracted from zstd
23
#include <stddef.h>
34
#include <stdlib.h>

tests/regression/06-symbeq/31-zstd-thread-pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PARAM: --set ana.activated[+] symb_locks
1+
// PARAM: --set ana.activated[+] symb_locks --set lib.activated[+] zstd
22
/* SPDX-License-Identifier: BSD-3-Clause */
33
/*
44
* Copyright (c) Facebook, Inc.

tests/regression/06-symbeq/35-zstd-thread-pool-multi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PARAM: --set ana.activated[+] symb_locks --set ana.activated[+] mallocFresh
1+
// PARAM: --set ana.activated[+] symb_locks --set ana.activated[+] mallocFresh --set lib.activated[+] zstd
22
/* SPDX-License-Identifier: BSD-3-Clause */
33
/*
44
* Copyright (c) Facebook, Inc.

tests/regression/06-symbeq/36-zstd-thread-pool-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PARAM: --set ana.activated[+] symb_locks --set ana.activated[+] var_eq --set exp.extraspecials[+] ZSTD_customMalloc --set exp.extraspecials[+] ZSTD_customCalloc
1+
// PARAM: --set ana.activated[+] symb_locks --set ana.activated[+] var_eq --set lib.activated[+] zstd --set exp.extraspecials[+] ZSTD_customMalloc --set exp.extraspecials[+] ZSTD_customCalloc
22
/* SPDX-License-Identifier: BSD-3-Clause */
33
/*
44
* Copyright (c) Facebook, Inc.

0 commit comments

Comments
 (0)