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

Add user function call support #3068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 19, 2024

  1. Add user function call support

    Function defined by the user can now be called in the same ways as built-in
    functions, for example:
    
    fn add($a: int64, $b: int64): int64 {
      return $a + $b;
    }
    
    BEGIN {
      print(add(5, 9));
    }
    
    If a function of the same name as an existing built-in is defined, it
    overrides the built-in and a warning is printed.
    
    Implementation-wise, the functionality depends on existing relocations
    against subprogs implemented in commit d345d06 ("Implement relocations
    against .text for subprogs"). Those are extended to also support R_BPF_64_32
    relocations used for direct calls in addition to R_BPF_64_64 used for
    indirect calls.
    
    Functions are generated as separate LLVM IR functions and translated into
    BPF subprogs via the LLVM bpf backend. Inlining of those function is
    disabled to prevent aggressive LLVM optimizations turning recursion into
    iteration, which could be rejected by the verifier.
    lenticularis39 committed May 19, 2024
    Configuration menu
    Copy the full SHA
    d1d1322 View commit details
    Browse the repository at this point in the history