Skip to content
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

Fix Overlapping program Ids #1623

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ members = [
"programs/native/noop",
"programs/native/bpf_loader",
"programs/native/lua_loader",
"programs/bpf/noop_rust",
"programs/bpf/rust/noop_rust",
]
50 changes: 14 additions & 36 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,22 @@ fn main() {
let erasure = !env::var("CARGO_FEATURE_ERASURE").is_err();

if bpf_c {
let out_dir = "target/".to_string() + &env::var("PROFILE").unwrap();

println!("cargo:rerun-if-changed=programs/bpf/noop_c/build.sh");
println!("cargo:rerun-if-changed=programs/bpf/noop_c/src/noop.c");
println!("cargo:warning=(not a warning) Compiling noop_c");
let status = Command::new("programs/bpf/noop_c/build.sh")
.arg(&out_dir)
.status()
.expect("Failed to call noop_c build script");
assert!(status.success());

println!("cargo:rerun-if-changed=programs/bpf/move_funds_c/build.sh");
println!("cargo:rerun-if-changed=programs/bpf/move_funds_c/src/move_funds.c");
println!("cargo:warning=(not a warning) Compiling move_funds_c");
let status = Command::new("programs/bpf/move_funds_c/build.sh")
.arg(&out_dir)
.status()
.expect("Failed to call move_funds_c build script");
assert!(status.success());

println!("cargo:rerun-if-changed=programs/bpf/tictactoe_c/build.sh");
println!("cargo:rerun-if-changed=programs/bpf/tictactoe_c/src/tictactoe.c");
println!("cargo:warning=(not a warning) Compiling tictactoe_c");
let status = Command::new("programs/bpf/tictactoe_c/build.sh")
.arg(&out_dir)
.status()
.expect("Failed to call tictactoe_c build script");
assert!(status.success());

println!("cargo:rerun-if-changed=programs/bpf/tictactoe_dashboard_c/build.sh");
println!(
"cargo:rerun-if-changed=programs/bpf/tictactoe_dashboard_c/src/tictactoe_dashboard.c"
);
println!("cargo:warning=(not a warning) Compiling tictactoe_dashboard_c");
let status = Command::new("programs/bpf/tictactoe_dashboard_c/build.sh")
let out_dir = "OUT_DIR=../../../target/".to_string()
+ &env::var("PROFILE").unwrap()
+ &"/bpf".to_string();

println!("cargo:rerun-if-changed=programs/bpf/c/makefile");
println!("cargo:rerun-if-changed=programs/bpf/c/src/move_funds.c");
println!("cargo:rerun-if-changed=programs/bpf/c/src/noop.c");
println!("cargo:rerun-if-changed=programs/bpf/c/src/tictactoe.c");
println!("cargo:rerun-if-changed=programs/bpf/c/src/tictactoe_dashboard.c");
println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
let status = Command::new("make")
.current_dir("programs/bpf/c")
.arg("all")
.arg(&out_dir)
.status()
.expect("Failed to call tictactoe_dashboard_c build script");
.expect("Failed to build C-based BPF programs");
assert!(status.success());
}
if chacha || cuda || erasure {
Expand Down
96 changes: 96 additions & 0 deletions programs/bpf/c/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

_@ :=@
INC_DIRS := -I.
SRC_DIR := ./src
OUT_DIR := ./out
LLVM_DIR := /usr/local/opt/llvm/bin

CC = $(LLVM_DIR)/clang
CC_FLAGS = \
-Werror \
-target \
bpf -O2 \
-emit-llvm \
-fno-builtin

LD = $(LLVM_DIR)/llc
LD_FLAGS = \
-march=bpf \
-filetype=obj \
-function-sections

OBJ_DUMP = $(LLVM_DIR)/llvm-objdump
OBJ_DUMP_FLAGS = \
-color \
-source \
-disassemble

.PRECIOUS: $(OUT_DIR)/%.bc
$(OUT_DIR)/%.bc: $(SRC_DIR)/%.c
$(_@)mkdir -p $(OUT_DIR)
$(_@)$(CC) $(CC_FLAGS) $(INC_DIRS) -o $@ -c $< -MMD -MF $(@:.bc=.d)

.PRECIOUS: $(OUT_DIR)/%.o
$(OUT_DIR)/%.o: $(OUT_DIR)/%.bc
$(_@)$(LD) $(LD_FLAGS) -o $@ $<

-include $(wildcard $(OUT_DIR)/*.d)

PROGRAM_NAMES := $(notdir $(basename $(wildcard src/*.c)))

define \n


endef

help:
@echo 'BPF Program makefile'
@echo ''
@echo 'This makefile will build BPF Programs from C source files into ELFs'
@echo ''
@echo 'Assumptions:'
@echo ' - Programs are a single .c source file (may include headers)'
@echo ' - Programs are located in the source directory: $(SRC_DIR)'
@echo ' - Programs are named by their basename (eg. file name:foo.c -> program name:foo)'
@echo ' - Output files will be placed in the directory: $(OUT_DIR)'
@echo ''
@echo 'User settings'
@echo ' - The following setting are overridable on the command line, default values shown'
@echo ' - Verbosity, for verbose: '_@=':'
@echo ' - _@=$(_@)'
@echo ' - List of include dirs:'
@echo ' INC_DIRS=$(INC_DIRS)'
@echo ' - Location of source files:'
@echo ' SRC_DIR=$(SRC_DIR)'
@echo ' - Location to place output files:'
@echo ' OUT_DIR=$(OUT_DIR)'
@echo ' - Location of LLVM:'
@echo ' LLVM_DIR=$(LLVM_DIR)'
@echo ''
@echo 'Usage:'
@echo ' - make help - This help message'
@echo ' - make all - Builds all the programs in the directory: $(SRC_DIR)'
@echo ' - make clean - Cleans all programs'
@echo ' - make dump_<program name> - Dumps the contents of the program to stdout'
@echo ' - make <program name> - Build a single program by name'
@echo ''
@echo 'Available programs:'
$(foreach name, $(PROGRAM_NAMES), @echo ' - $(name)'$(\n))
@echo ''
@echo 'Example:'
@echo ' - Assuming a programed named foo (src/foo.c)'
@echo ' - make foo INC_DIRS='-I. -Isrc''
@echo ' - make dump_foo'

%: $(addprefix $(OUT_DIR)/, %.o)
@echo $@ up to date

.PHONY: help all dump clean

all: $(PROGRAM_NAMES)

dump_%: %
$(_@)$(OBJ_DUMP) $(OBJ_DUMP_FLAGS) $(addprefix $(OUT_DIR)/, $(addsuffix .o, $<))

clean:
$(_@)rm -rf $(OUT_DIR)
Loading