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

btf: export API to create BTF from scratch #859

Merged
merged 4 commits into from
Jan 25, 2023
Merged

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Nov 18, 2022

Add Spec.Add, which allows creating BTF on the fly from outside of the btf package.

@lmb lmb force-pushed the btf-spec-add branch 3 times, most recently from f6e716d to 575c5e9 Compare November 20, 2022 15:49
@lmb lmb requested review from ti-mo December 6, 2022 06:42
@lmb lmb marked this pull request as ready for review December 6, 2022 06:42
@lmb lmb force-pushed the btf-spec-add branch 3 times, most recently from 4db9fb3 to 1859ea6 Compare December 6, 2022 20:05
btf/btf_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@ti-mo ti-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nits, awesome stuff!

btf/btf.go Outdated Show resolved Hide resolved
btf/btf.go Outdated Show resolved Hide resolved
btf/btf.go Outdated Show resolved Hide resolved
btf/btf.go Show resolved Hide resolved
btf/btf_test.go Outdated Show resolved Hide resolved
btf/marshal.go Outdated Show resolved Hide resolved
btf/marshal.go Show resolved Hide resolved
btf/marshal_test.go Outdated Show resolved Hide resolved
btf/marshal_test.go Show resolved Hide resolved
btf/strings.go Outdated Show resolved Hide resolved
@lmb lmb force-pushed the btf-spec-add branch 2 times, most recently from ddd087a to cdaa93d Compare December 17, 2022 11:02
@lmb lmb requested a review from ti-mo December 22, 2022 16:40
@lmb lmb force-pushed the btf-spec-add branch 3 times, most recently from 2e537f2 to 9bf579e Compare January 13, 2023 20:01
We want to allow creating Spec from scratch, without starting from an ELF.
In such cases it's a waste to maintaing a string table. Return an error
in code paths that rely on Spec.strings to not be nil.

Signed-off-by: Lorenz Bauer <[email protected]>
Export Spec.Add which adds a Type to a Spec. It's then possible to create
BTF on-the-fly like so:

    spec := NewSpec()
    id, err := spec.Add(...)
    handle, err := NewHandle(&spec)

Spec.Add is responsible for allocating type IDs, which makes the BTF
encoder a lot simpler.

Attempting to create a Handle from a Spec that doesn't contain all
types will return an error. This can happen if a Type is modified
after it has been added to a Spec.

Signed-off-by: Lorenz Bauer <[email protected]>
Replace the bare-bones marshalBTF with marshalTypes, but avoid calling
NewHandle to prevent circular dependencies.

Signed-off-by: Lorenz Bauer <[email protected]>
btf/btf.go Show resolved Hide resolved
@lmb lmb requested a review from ti-mo January 13, 2023 20:28
@ti-mo ti-mo merged commit dc0c822 into cilium:master Jan 25, 2023
tpapagian added a commit to cilium/tetragon that referenced this pull request Apr 6, 2023
Want to include cilium/ebpf#859

Signed-off-by: Anastasios Papagiannis <[email protected]>
tpapagian added a commit to cilium/tetragon that referenced this pull request Apr 7, 2023
Want to include cilium/ebpf#859

go get github.com/cilium/ebpf@master

Signed-off-by: Anastasios Papagiannis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants