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

elfparser: Add method to load BPF from an io.ReaderAt #50

Closed
wants to merge 1 commit into from

Conversation

shun159
Copy link
Contributor

@shun159 shun159 commented Sep 21, 2023

This patch adds the LoadBpfFromReader to the bpfSDKClient to load an ELF file from an io.ReaderAt. With this patch, it becomes possible to load an ELF binary embedded in an application binary using go:embed as the following:

package main

import (
	"bytes"
	_ "embed"

	"github.com/aws/aws-ebpf-sdk-go/pkg/elfparser"
)

func main() {
	elfc := elfparser.New()
	reader := bytes.NewReader(_ElfFileBytes)
	elfc.LoadBpfFromReader(reader, "global")
}

//go:embed bpf/kprobe.bpf.elf
var _ElfFileBytes []byte

@shun159 shun159 requested a review from a team as a code owner September 21, 2023 15:14
@dims
Copy link
Member

dims commented Sep 21, 2023

I like it. do you want to add a test too?

func (b *bpfSDKClient) LoadBpfFile(path, customizedPinPath string) (map[string]BpfData, map[string]ebpf_maps.BpfMap, error) {
bpfFile, err := os.Open(path)
// LoadBpfFromReader loads ELF file from io.ReaderAt and parses an ELF file into BPF objects
func (b *bpfSDKClient) LoadBpfFromReader(r io.ReaderAt, customizedPinPath string) (
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add it to the - interface type BpfSDKClient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Thank you for pointing that out.
Indeed, we needed to add the interface. I've fixed to add.

@shun159
Copy link
Contributor Author

shun159 commented Sep 22, 2023

Hi @dims, Thank you for your review.
Sure! I've added the testcase.

@shun159
Copy link
Contributor Author

shun159 commented Sep 22, 2023

I've made fixes based on the feedback. Happy with these changes?

@shun159 shun159 force-pushed the feature/elf_ioreader branch 3 times, most recently from c9a6296 to a40bcd0 Compare September 22, 2023 09:26
- Introduce the `LoadBpfFromReader` method in the `bpfSDKClient`.
- This method enables loading ELF files directly from an io.ReaderAt.

Signed-off-by: shun159 <dreamdiagnosis@gmail.com>
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.

3 participants