Skip to content
Open
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
5 changes: 3 additions & 2 deletions c.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions c_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cbpfc

import (
"bytes"
"strings"
"testing"

"github.com/cilium/ebpf"
Expand Down Expand Up @@ -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},
Expand Down