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

Fix issues when porting alloy/pyroscope to android #3582

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
23 changes: 13 additions & 10 deletions ebpf/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,19 @@ func (s *session) Start() error {
}

_, nsIno, err := getPIDNamespace()
if err != nil {
return fmt.Errorf("unable to get pid namespace %w", err)
}
err = spec.RewriteConstants(map[string]interface{}{
"global_config": pyrobpf.ProfileGlobalConfigT{
NsPidIno: nsIno,
},
})
if err != nil {
return fmt.Errorf("pyrobpf rewrite constants %w", err)
// if the file does not exist, CONFIG_PID_NS is not supported, so we just ignore the error
if !os.IsNotExist(err) {
if err != nil {
return fmt.Errorf("unable to get pid namespace %w", err)
}
err = spec.RewriteConstants(map[string]interface{}{
"global_config": pyrobpf.ProfileGlobalConfigT{
NsPidIno: nsIno,
},
})
if err != nil {
return fmt.Errorf("pyrobpf rewrite constants %w", err)
}
}
err = spec.LoadAndAssign(&s.bpf, opts)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions ebpf/symtab/kallsyms.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"sort"
"strconv"
)

Expand Down Expand Up @@ -94,5 +95,9 @@ func NewKallsymsFromData(kallsyms []byte) (*SymbolTab, error) {
if allZeros {
return NewSymbolTab(nil), nil
}
// kallsyms maybe unsorted when bpf/modules are loaded from userspace after kernel boot.
sort.Slice(syms, func(i, j int) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: It would be nice to add a test, but it is is not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR Updated. I add 2 unordered symbols in testdata. I tested it and it will fail without this patch and success with this patch.

return syms[i].Start < syms[j].Start
})
return NewSymbolTab(syms), nil
}
4 changes: 3 additions & 1 deletion ebpf/symtab/kallsyms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ ffffffff81001750 T memblock_find
ffffffff81001780 T __memblock_alloc_base
ffffffff810017d0 T memblock_alloc
ffffffff81001820 T early_memtest
ffffffff810018a0 T early_memtest_report`
ffffffff810018a0 T early_memtest_report
ffffffff81000800 T unordered_symbol_0
ffffffff81000100 T unordered_symbol_1`

func TestKallsyms(t *testing.T) {
kallsyms, err := NewKallsymsFromData([]byte(testdata))
Expand Down
Loading