Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
klee
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
klee
Commits
75e5fea6
Commit
75e5fea6
authored
6 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
cargo-klee
parent
222e0169
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-1
1 addition, 1 deletion
.gitignore
cargo-klee/Cargo.lock
+14
-0
14 additions, 0 deletions
cargo-klee/Cargo.lock
cargo-klee/Cargo.toml
+7
-0
7 additions, 0 deletions
cargo-klee/Cargo.toml
cargo-klee/src/main.rs
+125
-0
125 additions, 0 deletions
cargo-klee/src/main.rs
with
147 additions
and
1 deletion
.gitignore
+
1
−
1
View file @
75e5fea6
/
target
target
**/*.rs.bk
This diff is collapsed.
Click to expand it.
cargo-klee/Cargo.lock
0 → 100644
+
14
−
0
View file @
75e5fea6
[[package]]
name = "cargo-klee"
version = "0.1.0"
dependencies = [
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
This diff is collapsed.
Click to expand it.
cargo-klee/Cargo.toml
0 → 100644
+
7
−
0
View file @
75e5fea6
[package]
authors
=
[
"Jorge Aparicio <jorge@japaric.io>"
]
name
=
"cargo-klee"
version
=
"0.1.0"
[dependencies]
libc
=
"0.2.33"
This diff is collapsed.
Click to expand it.
cargo-klee/src/main.rs
0 → 100644
+
125
−
0
View file @
75e5fea6
extern
crate
libc
;
use
std
::
io
::{
self
,
Read
,
Write
};
use
std
::
process
::{
Command
,
Stdio
};
use
std
::{
env
,
str
};
fn
main
()
{
// first argument is the path to this binary; the second argument is always "klee" -- both can
// be ignored
let
args
=
env
::
args
()
.skip
(
2
)
.collect
::
<
Vec
<
_
>>
();
// turn `cargo klee --example foo` into `xargo rustc --example foo -- (..)`
let
mut
c
=
Command
::
new
(
"xargo"
);
c
.arg
(
"rustc"
)
.args
(
&
args
)
// verbose output for debugging purposes
.arg
(
"-v"
)
.arg
(
"--color=always"
)
.arg
(
"--"
)
// ignore linking
.args
(
&
[
"-C"
,
"linker=true"
])
// force LTO
.args
(
&
[
"-C"
,
"lto"
])
// also output the LLVM-IR (.ll file) for debugging purposes
.arg
(
"--emit=llvm-bc,llvm-ir"
)
// force panic=abort in all crates
.env
(
"RUSTFLAGS"
,
"-C panic=abort"
)
// collect stderr
.stderr
(
Stdio
::
piped
());
// print full command for debugging purposes
eprintln!
(
"{:?}"
,
c
);
// spawn process and drive it completion while replicating its stderr in ours
let
mut
p
=
c
.spawn
()
.unwrap
();
let
mut
pstderr
=
p
.stderr
.take
()
.unwrap
();
let
mut
buf
=
[
0
;
1024
];
let
mut
output
=
vec!
[];
let
stderr
=
io
::
stderr
();
let
mut
stderr
=
stderr
.lock
();
loop
{
if
let
Ok
(
n
)
=
pstderr
.read
(
&
mut
buf
)
{
stderr
.write
(
&
buf
[
..
n
])
.unwrap
();
output
.extend_from_slice
(
&
buf
[
..
n
]);
}
if
let
Some
(
status
)
=
p
.try_wait
()
.unwrap
()
{
assert!
(
status
.success
());
break
;
}
}
// next we are going to try to run the .bc file using klee inside a docker container
// FIXME the way we find out which .bc file we have to use is pretty hacky; using Cargo as a
// library would be cleaner, I suppose
// find out the argument passed to `--example`, if used at all
let
mut
example
=
None
;
let
mut
iargs
=
args
.iter
();
while
let
Some
(
arg
)
=
iargs
.next
()
{
if
arg
==
"--example"
{
example
=
iargs
.next
();
break
;
}
}
// get the suffix of the example
let
(
example
,
suffix
)
=
if
let
Some
(
example
)
=
example
{
let
mut
suffix
=
None
;
let
output
=
str
::
from_utf8
(
&
output
)
.unwrap
();
for
line
in
output
.lines
()
{
if
line
.contains
(
&
format!
(
"examples/{}.rs"
,
example
))
{
for
part
in
line
.split
(
' '
)
{
if
part
.starts_with
(
"extra-filename="
)
{
suffix
=
part
.split
(
'='
)
.nth
(
1
);
}
}
}
}
(
example
,
suffix
.unwrap
())
}
else
{
// nothing to do if the user didn't use `--example`
return
;
};
let
profile
=
if
args
.iter
()
.any
(|
a
|
a
==
"--release"
)
{
"release"
}
else
{
"debug"
};
let
mut
docker
=
Command
::
new
(
"docker"
);
docker
.arg
(
"run"
)
.arg
(
"--rm"
)
.args
(
&
[
"--user"
,
&
format!
(
"{}:{}"
,
uid
(),
gid
())])
.args
(
&
[
"-v"
,
&
format!
(
"{}:/mnt"
,
env
::
current_dir
()
.unwrap
()
.display
()),
])
.args
(
&
[
"-w"
,
"/mnt"
])
.arg
(
"-it"
)
.arg
(
"afoht/llvm-klee-4"
)
.args
(
&
[
"/usr/bin/klee"
,
&
format!
(
"target/{}/examples/{}{}.bc"
,
profile
,
example
,
suffix
),
]);
// print full command for debugging purposes
eprintln!
(
"{:?}"
,
docker
);
assert!
(
docker
.status
()
.unwrap
()
.success
());
}
// NOTE from cross
fn
gid
()
->
u32
{
unsafe
{
libc
::
getgid
()
}
}
// NOTE from cross
fn
uid
()
->
u32
{
unsafe
{
libc
::
getuid
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment