diff --git a/c.go b/c.go index 80534e6..68f7533 100644 --- a/c.go +++ b/c.go @@ -106,8 +106,9 @@ func ToC(filter []bpf.Instruction, opts COpts) (string, error) { } fun := cFunction{ - Name: opts.FunctionName, - Blocks: make([]cBlock, len(blocks)), + Name: opts.FunctionName, + NoInline: opts.NoInline, + Blocks: make([]cBlock, len(blocks)), } // Compile blocks to C diff --git a/c_test.go b/c_test.go index 023e822..bb968df 100644 --- a/c_test.go +++ b/c_test.go @@ -2,6 +2,7 @@ package cbpfc import ( "bytes" + "strings" "testing" "github.com/cilium/ebpf" @@ -30,6 +31,22 @@ func TestFunctionName(t *testing.T) { checkName(t, "a2", true) } +func TestToCNoInline(t *testing.T) { + elf, err := ToC([]bpf.Instruction{ + bpf.RetConstant{Val: 1}, + }, COpts{ + FunctionName: "filter", + NoInline: true, + }) + if err != nil { + t.Fatal(err) + } + + if strings.Contains(elf, "__always_inline__") { + t.Fatal("generated C source should not contain __always_inline__ when NoInline is true") + } +} + func TestNoInline(t *testing.T) { elf, err := buildC([]bpf.Instruction{ bpf.RetConstant{Val: 1},