Skip to content

LLVM Code Coverage Instrumentation #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d5fba30
added rustc_llvm to compiler workspace
corbanvilla Nov 26, 2023
d45a18a
revert to rustc version 1.64
corbanvilla Nov 29, 2023
9a92066
add llvm wrappers to cargo build
corbanvilla Nov 29, 2023
d533cfe
add llvm wrapper build settings
corbanvilla Nov 29, 2023
ff1a358
add readme.md
corbanvilla Nov 29, 2023
a77f589
import rustc_codegen_llvm
corbanvilla Nov 29, 2023
09ac739
add rustc_codegen_ssa
corbanvilla Nov 29, 2023
baaa94c
auto formatting
corbanvilla Dec 6, 2023
25a9eed
coverage interfaces in rust
corbanvilla Dec 6, 2023
20c5941
remove first attempt files
corbanvilla Dec 6, 2023
b991d8b
disable unused
corbanvilla Dec 6, 2023
5609edb
fix build depend issue
corbanvilla Dec 6, 2023
d588285
package updates
corbanvilla Dec 6, 2023
f415792
call from codegen
corbanvilla Dec 6, 2023
19d3024
temp updates to build scripts
corbanvilla Dec 6, 2023
c5b389d
disable lib.rs functions, moved to rustc_llvm_coverage
corbanvilla Dec 7, 2023
f4c8658
enable hashstring and writing to buffer
corbanvilla Dec 7, 2023
cdd8194
convenience auto build
corbanvilla Dec 7, 2023
b060f29
add buf write example
corbanvilla Dec 7, 2023
0106d69
update to inkwell fork
corbanvilla Dec 7, 2023
4d2ff28
pgo calls working
corbanvilla Dec 7, 2023
15784e7
cleanup pgo
corbanvilla Dec 14, 2023
bbcb66a
some changes
Dec 13, 2023
458e314
commit last modifications'
Dec 13, 2023
c66ec45
last changes
Dec 15, 2023
25a8a2c
get write func mod working
corbanvilla Dec 15, 2023
f86f141
start write func record
corbanvilla Dec 15, 2023
fb3dba4
commit to merge
Dec 20, 2023
87ccb4c
some changes
Dec 20, 2023
7fedb3f
update toml
Dec 20, 2023
e626910
Revert "update toml"
Dec 20, 2023
56664ec
update cargo.toml
Dec 20, 2023
1a64ecc
finalize save_func_record_to_mod
Dec 20, 2023
a826919
test
HaithemLamri Dec 21, 2023
356604f
add pass and cleanup functions
corbanvilla Jan 5, 2024
96f2012
working cov map header
corbanvilla Jan 11, 2024
33619f0
steps towards rusty integration
corbanvilla Jan 11, 2024
3d8488c
inkwell-level interface working
corbanvilla Jan 12, 2024
0b00d20
cleanup test features
corbanvilla Jan 12, 2024
25694e1
pass runs successfully
corbanvilla Jan 13, 2024
ecabe92
pass lowering works, with issue
corbanvilla Jan 15, 2024
a1980ca
working pass, before cleanup
corbanvilla Jan 15, 2024
0d79c1e
slight cleanup and rename
corbanvilla Jan 15, 2024
ff439d1
fix rename
corbanvilla Jan 15, 2024
1c0c35e
add python debugger scripts
corbanvilla Jan 15, 2024
872dd14
comments and fix source map
corbanvilla Jan 15, 2024
c505c8f
add used var calls
corbanvilla Jan 15, 2024
a0732ec
add profiling files
corbanvilla Jan 16, 2024
235e335
cleanup build files
corbanvilla Jan 16, 2024
31523d7
cleanup unused llvm-wrapper
corbanvilla Jan 16, 2024
faac5ce
remove old subrepo
corbanvilla Jan 16, 2024
3b986ff
restore old lock file
corbanvilla Jan 16, 2024
0303cd4
remove old package ref
corbanvilla Jan 16, 2024
e186cfe
cleanup interfaces
corbanvilla Jan 17, 2024
a54ce1f
added emit to interfaces
corbanvilla Jan 17, 2024
db0c56d
function level code coverage
corbanvilla Jan 18, 2024
6b38d51
only instrument defined functions
corbanvilla Jan 20, 2024
a6a31f0
debug information
corbanvilla Jan 22, 2024
07f1a9c
remove print
corbanvilla Jan 22, 2024
dc21616
log before fail
corbanvilla Jan 22, 2024
fdc32b9
soft fail
corbanvilla Jan 22, 2024
2b9bbea
working coverage gen for if statements
corbanvilla Jan 30, 2024
001ed97
added branch instrumentation
corbanvilla Jan 30, 2024
bd03a0a
pass for non registered ast
corbanvilla Jan 30, 2024
8aa8377
branching type
corbanvilla Jan 30, 2024
e80ce78
added branching support w/ loops and expressions
corbanvilla Jan 31, 2024
a292e7a
update examples
corbanvilla Jan 31, 2024
be1ec4e
address sanitizer and cleanup
corbanvilla Feb 10, 2024
f61b693
fix hardcoded paths
corbanvilla Apr 5, 2024
5cd15bf
Update build.sh
corbanvilla Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
*.a
*.elf
*.out
default.profraw
default.profexport
25 changes: 21 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plc_source = { path = "./compiler/plc_source" }
plc_ast = { path = "./compiler/plc_ast" }
plc_util = { path = "./compiler/plc_util" }
plc_diagnostics = { path = "./compiler/plc_diagnostics" }
rustc_llvm_coverage = { path = "./compiler/rustc_llvm_coverage" }
logos = "0.12.0"
thiserror = "1.0"
clap = { version = "3.0", features = ["derive"] }
Expand Down Expand Up @@ -69,11 +70,13 @@ members = [
"compiler/plc_util",
"compiler/plc_xml",
"compiler/plc_derive",
"compiler/rustc_llvm",
"compiler/rustc_llvm_coverage",
]
default-members = [".", "compiler/plc_driver", "compiler/plc_xml"]

[workspace.dependencies]
inkwell = { version = "0.2", features = ["llvm14-0"] }
inkwell = { git = "https://github.com/corbanvilla/inkwell.git", branch = "v2.0", version = "0.2", features = ["llvm14-0"] }
encoding_rs = "0.8"
encoding_rs_io = "0.1"
log = "0.4"
Expand Down
13 changes: 13 additions & 0 deletions compiler/plc_source/src/source_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ impl SourceLocation {
true
}
}

// TOOD - there's probably a better way to do this
pub fn get_start_end(&self) -> (usize, usize, usize, usize) {
let span = self.get_span();
if let CodeSpan::Range(range) = span {
let (start_line, start_col, end_line, end_col) =
// TODO - rusty devs will understand what needs to be done here w/ line + 1
(range.start.line + 1, range.start.column + 1, range.end.line + 1, range.end.column + 1);
(start_line, start_col, end_line, end_col)
} else {
panic!("Error: expected CodeSpan::Range, found {:?}", span);
}
}
}

/**
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rustc_llvm"
version = "0.0.0"
edition = "2021"

[features]
static-libstdcpp = []
emscripten = []

[dependencies]
libc = "0.2.73"

[build-dependencies]
cc = "1.0.69"
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `rustc-llvm`

This package serves to wrap some of the LLVM functions which are not natively exposed as part of the LLVM C-API, in a Rust-friendly way.

This code is taken directly from the [Rust compiler source code (version 1.64.0)](https://github.com/rust-lang/rust/tree/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52), which is the last version of the Rust compiler to use LLVM 14 (which is currently the version used by `ruSTy`). The Rust compiler uses this code to interface with LLVM in order to add code coverage instrumentation to Rust binaries, among other features.
Loading