Add build script to extract a list of registered syscalls
The list is used in cargo-build-bpf to check generated .so modules for undefined symbols that are not known run-time syscalls.
This commit is contained in:
parent
76bb403318
commit
32742df1b4
|
@ -4314,6 +4314,7 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"rand_core 0.6.2",
|
"rand_core 0.6.2",
|
||||||
|
"regex",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"sha3",
|
"sha3",
|
||||||
"solana-measure",
|
"solana-measure",
|
||||||
|
|
|
@ -2792,6 +2792,7 @@ dependencies = [
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"rand_core 0.6.2",
|
"rand_core 0.6.2",
|
||||||
|
"regex",
|
||||||
"sha3",
|
"sha3",
|
||||||
"solana-measure",
|
"solana-measure",
|
||||||
"solana-runtime",
|
"solana-runtime",
|
||||||
|
|
|
@ -9,6 +9,9 @@ homepage = "https://solana.com/"
|
||||||
documentation = "https://docs.rs/solana-bpf-loader-program"
|
documentation = "https://docs.rs/solana-bpf-loader-program"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
regex = "1.5.4"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode = "1.3.1"
|
bincode = "1.3.1"
|
||||||
byteorder = "1.3.4"
|
byteorder = "1.3.4"
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
use regex::Regex;
|
||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::{prelude::*, BufWriter, Read},
|
||||||
|
path::PathBuf,
|
||||||
|
process::exit,
|
||||||
|
str,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a list of registered syscall names and save it in a file
|
||||||
|
* for distribution with the SDK. This file is read by cargo-build-bpf
|
||||||
|
* to verify undefined symbols in a .so module that cargo-build-bpf has built.
|
||||||
|
*/
|
||||||
|
fn main() {
|
||||||
|
let path = PathBuf::from("src/syscalls.rs");
|
||||||
|
let mut file = match File::open(&path) {
|
||||||
|
Ok(x) => x,
|
||||||
|
_ => exit(1),
|
||||||
|
};
|
||||||
|
let mut text = vec![];
|
||||||
|
file.read_to_end(&mut text).unwrap();
|
||||||
|
let text = str::from_utf8(&text).unwrap();
|
||||||
|
let path = PathBuf::from("../../sdk/bpf/syscalls.txt");
|
||||||
|
let file = match File::create(&path) {
|
||||||
|
Ok(x) => x,
|
||||||
|
_ => exit(1),
|
||||||
|
};
|
||||||
|
let mut out = BufWriter::new(file);
|
||||||
|
let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
|
||||||
|
for caps in sysc_re.captures_iter(&text) {
|
||||||
|
writeln!(out, "{}", caps[1].to_string()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,3 +7,4 @@
|
||||||
/dependencies/bin*
|
/dependencies/bin*
|
||||||
/dependencies/.crates.toml
|
/dependencies/.crates.toml
|
||||||
/dependencies/.crates2.json
|
/dependencies/.crates2.json
|
||||||
|
/syscalls.txt
|
||||||
|
|
|
@ -250,32 +250,17 @@ fn postprocess_dump(program_dump: &Path) {
|
||||||
// Check whether the built .so file contains undefined symbols that are
|
// Check whether the built .so file contains undefined symbols that are
|
||||||
// not known to the runtime and warn about them if any.
|
// not known to the runtime and warn about them if any.
|
||||||
fn check_undefined_symbols(config: &Config, program: &Path) {
|
fn check_undefined_symbols(config: &Config, program: &Path) {
|
||||||
let syscalls: HashSet<String> = [
|
let syscalls_txt = config.bpf_sdk.join("syscalls.txt");
|
||||||
"abort",
|
let file = match File::open(syscalls_txt) {
|
||||||
"sol_panic_",
|
Ok(x) => x,
|
||||||
"sol_log_",
|
_ => return,
|
||||||
"sol_log_64_",
|
};
|
||||||
"sol_log_compute_units_",
|
let mut syscalls = HashSet::new();
|
||||||
"sol_log_pubkey",
|
for line_result in BufReader::new(file).lines() {
|
||||||
"sol_create_program_address",
|
let line = line_result.unwrap();
|
||||||
"sol_try_find_program_address",
|
let line = line.trim_end();
|
||||||
"sol_sha256",
|
syscalls.insert(line.to_string());
|
||||||
"sol_keccak256",
|
}
|
||||||
"sol_get_clock_sysvar",
|
|
||||||
"sol_get_epoch_schedule_sysvar",
|
|
||||||
"sol_get_fees_sysvar",
|
|
||||||
"sol_get_rent_sysvar",
|
|
||||||
"sol_memcpy_",
|
|
||||||
"sol_memmove_",
|
|
||||||
"sol_memcmp_",
|
|
||||||
"sol_memset_",
|
|
||||||
"sol_invoke_signed_c",
|
|
||||||
"sol_invoke_signed_rust",
|
|
||||||
"sol_alloc_free_",
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
.map(|&symbol| symbol.to_owned())
|
|
||||||
.collect();
|
|
||||||
let entry =
|
let entry =
|
||||||
Regex::new(r"^ *[0-9]+: [0-9a-f]{16} +[0-9a-f]+ +NOTYPE +GLOBAL +DEFAULT +UND +(.+)")
|
Regex::new(r"^ *[0-9]+: [0-9a-f]{16} +[0-9a-f]+ +NOTYPE +GLOBAL +DEFAULT +UND +(.+)")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue