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

ProgramInfo.Instructions fails on parsing BTF line info #1168

Closed
aibor opened this issue Oct 17, 2023 · 2 comments · Fixed by #1169
Closed

ProgramInfo.Instructions fails on parsing BTF line info #1168

aibor opened this issue Oct 17, 2023 · 2 comments · Fixed by #1169
Labels
bug Something isn't working

Comments

@aibor
Copy link
Contributor

aibor commented Oct 17, 2023

Describe the bug

With version 0.12.0 calling ProgramInfo.Instructions returns:

parse line info: parsing BTF line info: offset 1 is not aligned with instruction size

With 0.11.0 the method returns the Instructions as expected.

To Reproduce

Given a simple XDP program in src/src.c, that doesn't do much, but more than just returning:

__attribute__((section("xdp"), used))
int test(void *ctx) {
  return ctx == 0;
}

And a simple go test program:

package main

import (
	"testing"
)

//go:generate ./gobin/bpf2go -target bpfel test src/src.c

func TestInstructions(t *testing.T) {
	var objs testObjects
	err := loadTestObjects(&objs, nil)
	if err != nil {
		t.Fatalf("load: %v", err)
	}

	info, err := objs.Test.Info()
	if err != nil {
		t.Fatalf("info: %v", err)
	}

	ins, err := info.Instructions()
	if err != nil {
		t.Fatalf("instructions: %v", err)
	}

	t.Log(ins)
}

The test fails with:

=== RUN   TestInstructions
    main_test.go:29: instructions: parse line info: parsing BTF line info: offset 1 is not aligned with instruction size
--- FAIL: TestInstructions (0.00s)

Expected behavior

With version 0.11.0 the method does not fail and produces the output:

=== RUN   TestInstructions
    main_test.go:32: test:
        	0: MovImm dst: r0 imm: 1
        	1: JEqImm dst: r1 off: 1 imm: 0
        	2: MovImm dst: r0 imm: 0
        	3: Exit

--- PASS: TestInstructions (0.00s)
@aibor aibor added the bug Something isn't working label Oct 17, 2023
@lmb
Copy link
Collaborator

lmb commented Oct 17, 2023

cc @dylandreimerink can you take a look?

@dylandreimerink
Copy link
Member

Thanks for the report! I have it locally reproduced.

When we parse the offsets from ELF we divide the instruction offset of the line info to go from a byte offset to an instruction offset here

However, when we use the same logic to parse from the kernel we should do the reverse. Same goes for the parse functions of funcInfo and CORERelo as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants