The original compilation implementation has the following bugs:
More than one thread may execute InitializeNativeTarget in the same time
Each call to bpf_jit_context::compile() may lead to the creation of a new LLJIT instance, which obsoletes the previous one, and making functions jitted with the previous one being invalidated (the memory they used would be deallocated, causing SIGSEGV when calling them)
Multiple thread may call bpf_jit_context::compile() for the same program, which can cause data race and resource waste
Fixes are:
Use an atomic variable to indicate whether the llvm environment was initialized. Only initialize if not initialized previously
Use a spinlock to control the compilation process. A spin lock will ensure that only one thread could call bpf_jit_context::compile() of a certain bpf_jit_context (In fact, in out implementation, bpf_jit_context::compile() should only be called once per bpf_jit_context, since bpf_jit_context was connected to a unique ebpf_vm, which indicates a ebpf program). If the program was not compiled before, create a LLJIT instance, and compile it, then store the LLJIT instance into bpf_jit_context. Otherwise, directly lookup symbols from the previous stored LLJIT instance.
Besides, this PR updates test-examples workflow, make it enable to use llvm-jit as ebpf runtime
Closes #91
The original compilation implementation has the following bugs:
InitializeNativeTarget
in the same timebpf_jit_context::compile()
may lead to the creation of a new LLJIT instance, which obsoletes the previous one, and making functions jitted with the previous one being invalidated (the memory they used would be deallocated, causing SIGSEGV when calling them)Fixes are:
bpf_jit_context::compile()
of a certain bpf_jit_context (In fact, in out implementation, bpf_jit_context::compile() should only be called once per bpf_jit_context, since bpf_jit_context was connected to a unique ebpf_vm, which indicates a ebpf program). If the program was not compiled before, create a LLJIT instance, and compile it, then store the LLJIT instance into bpf_jit_context. Otherwise, directly lookup symbols from the previous stored LLJIT instance.Besides, this PR updates
test-examples
workflow, make it enable to use llvm-jit as ebpf runtime