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

修复了内核uprobe绑定接口不一致的问题,使libbpf代码测试通过 #487

Merged
merged 34 commits into from
Aug 11, 2023

Conversation

GorilaMond
Copy link
Contributor

libbpf项目实现在GitHub测试时报出很多错误,但在本地没有报错。

经过在本地与GitHub测试镜像相同版本Ubuntu22.04的docker中进行预处理、头文件查找,发现是uprobe的跟踪方式变了

在22.04中,uprobe跟踪函数bpf_program__attach_uprobe_opts的参数struct bpf_uprobe_opts的定义为:

struct bpf_uprobe_opts {
    size_t sz;
    size_t ref_ctr_offset;
    __u64 bpf_cookie;
    bool retprobe;
    size_t :0;
};

而本地新版系统的struct bpf_uprobe_opts中多了一个字段const char *func_name,方便设置uprobe回调函数的跟踪点。

解决方法:加入版本控制宏,将不同版本内核的接口封装为同一个宏接口

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0)
#define __ATTACH_UPROBE(skel, sym_name, prog_name, is_retprobe)  \
    do                                                           \
    {                                                            \
        DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts,        \
                            .retprobe = is_retprobe);            \
        /*...*/                                                  \
    } while (false)
#else
#define __ATTACH_UPROBE(skel, sym_name, prog_name, is_retprobe)  \
    do                                                           \
    {                                                            \
        LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts,                \
                    .retprobe = is_retprobe,                     \
                    .func_name = #sym_name);                     \
        /*...*/                                                  \
    } while (false)
#endif

LinkinPF
LinkinPF previously approved these changes Aug 5, 2023
Copy link
Member

@helight helight left a comment

Choose a reason for hiding this comment

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

不错,readme 和开发记录都是挺好的做法,可以在周例会上展示一下

@chenamy2017 chenamy2017 merged commit 4cfcad5 into linuxkerneltravel:develop Aug 11, 2023
3 checks passed
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.

4 participants