Cleanup c programs (#1620)

Cleanup C programs
This commit is contained in:
jackcmay
2018-10-26 19:38:07 -07:00
committed by GitHub
parent 9a6a399a29
commit 3488ea7d1c
27 changed files with 629 additions and 786 deletions

View File

@ -0,0 +1,11 @@
[package]
name = "solana-bpf-noop"
version = "0.11.0"
description = "Solana BPF noop program"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
[dependencies]
rbpf = "0.1.0"
solana-sdk = { path = "../../../../sdk", version = "0.11.0" }

10
programs/bpf/rust/noop/build.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash -ex
# TODO building release flavor with rust produces a bunch of output .bc files
INTERDIR=../../../target/release
OUTDIR="${1:-../../../target/debug/}"
mkdir -p "$OUTDIR"
# cargo +nightly rustc --release -- -C panic=abort --emit=llvm-ir
cargo +nightly rustc --release -- -C panic=abort --emit=llvm-bc
cp "$INTERDIR"/deps/noop_rust-*.bc "$OUTDIR"/noop_rust.bc
/usr/local/opt/llvm/bin/llc -march=bpf -filetype=obj -o "$OUTDIR"/noop_rust.o "$OUTDIR"/noop_rust.bc

3
programs/bpf/rust/noop/dump.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
/usr/local/opt/llvm/bin/llvm-objdump -color -source -disassemble target/release/noop_rust.o

View File

@ -0,0 +1,15 @@
extern crate rbpf;
use std::mem::transmute;
#[no_mangle]
#[link_section = ".text,entrypoint"] // TODO platform independent needed
pub extern "C" fn entrypoint(_raw: *mut u8) {
let bpf_func_trace_printk = unsafe {
transmute::<u64, extern "C" fn(u64, u64, u64, u64, u64)>(
rbpf::helpers::BPF_TRACE_PRINTK_IDX as u64,
)
};
bpf_func_trace_printk(0, 0, 1, 2, 3);
}