Add cargo-build-bpf

This commit is contained in:
Michael Vines
2020-10-20 17:50:20 -07:00
parent e6b821c392
commit 07a853d6cc
15 changed files with 474 additions and 50 deletions

48
sdk/bpf/scripts/dump.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
# shellcheck source=sdk/bpf/env.sh
source "$bpf_sdk"/env.sh
so=$1
dump=$2
if [[ -z $so ]] || [[ -z $dump ]]; then
echo "Usage: $0 bpf-program.so dump.txt"
exit 1
fi
if [[ ! -r $so ]]; then
echo "Error: File not found or readable: $so"
exit 1
fi
if ! command -v rustfilt > /dev/null; then
echo "Error: rustfilt not found. It can be installed by running: cargo install rustfilt"
exit 1
fi
if ! command -v readelf > /dev/null; then
if [[ $(uname) = Darwin ]]; then
echo "Error: readelf not found. It can be installed by running: brew install binutils"
else
echo "Error: readelf not found."
fi
exit 1
fi
dump_mangled=$dump.mangled
(
set -ex
ls -la "$so" > "$dump_mangled"
readelf -aW "$so" >>"$dump_mangled"
"$OBJDUMP" -print-imm-hex --source --disassemble "$so" >> "$dump_mangled"
sed s/://g < "$dump_mangled" | rustfilt > "$dump"
)
rm -f "$dump_mangled"
if [[ ! -f "$dump" ]]; then
echo "Error: Failed to create $dump"
exit 1
fi
echo "Wrote $dump"

View File

@ -84,19 +84,24 @@ clone() {
}
# Install xargo
(
set -ex
# shellcheck disable=SC2154
if [[ -n $rust_stable ]]; then
cargo +"$rust_stable" install xargo
else
cargo install xargo
version=0.3.22
if [[ ! -e xargo-$version.md ]] || [[ ! -x bin/xargo ]]; then
(
args=()
# shellcheck disable=SC2154
if [[ -n $rust_stable ]]; then
args+=(+"$rust_stable")
fi
args+=(install xargo --version "$version" --root .)
set -ex
cargo "${args[@]}"
./bin/xargo --version >xargo-$version.md 2>&1
)
exitcode=$?
if [[ $exitcode -ne 0 ]]; then
rm -rf xargo-$version.md
exit 1
fi
xargo --version >xargo.md 2>&1
)
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
exit 1
fi
# Install Criterion

6
sdk/bpf/scripts/objcopy.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
# shellcheck source=sdk/bpf/env.sh
source "$bpf_sdk"/env.sh
exec "$bpf_sdk"/dependencies/llvm-native/bin/llvm-objcopy "$@"

17
sdk/bpf/scripts/strip.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
so=$1
if [[ ! -r $so ]]; then
echo "Error: file not found: $so"
exit 1
fi
so_stripped=$2
if [[ -z $so_stripped ]]; then
echo "Usage: $0 unstripped.so stripped.so"
exit 1
fi
bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
# shellcheck source=sdk/bpf/env.sh
source "$bpf_sdk"/env.sh
"$bpf_sdk"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so" "$so_stripped"