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

Fixups for debug_info (to generate BTF acceptable by the kernel) #26

Closed
vadorovsky opened this issue Oct 21, 2022 · 3 comments
Closed
Assignees

Comments

@vadorovsky
Copy link
Member

vadorovsky commented Oct 21, 2022

Related to aya-rs/aya#351

Related project: https://github.com/vadorovsky/aya-btf-maps

When generating debug_info is enabled in bpf-linker, the produced BTF is not accepted by the kernel. That's because debug_info (and therefore BTF generated from it) is different between the eBPF objects produced by rustc and clang. The long term solution would be getting rid of those differences by making appropriate changes in rustc and LLVM. But for now, we need to do fixups in bpf-linker, to fix the issue faster.

Known differences:

DW_tag_pointer_type (in DWARF) / PTR (in BTF)

DW_tag_pointer_type produced by rustc:

0x00000369:   DW_TAG_pointer_type
                DW_AT_type      (0x00000376 "i32[1]")
                DW_AT_name      ("*const [i32; 1]")
                DW_AT_address_class     (0x00000000)
[...]
0x00000391:   DW_TAG_pointer_type
                DW_AT_type      (0x0000039e "u32")
                DW_AT_name      ("*const u32")
                DW_AT_address_class     (0x00000000)
[...]
0x000003a5:   DW_TAG_pointer_type
                DW_AT_type      (0x000003b2 "i32[1024]")
                DW_AT_name      ("*const [i32; 1024]")
                DW_AT_address_class     (0x00000000)

PTR BTF produced by rustc:

[1] PTR '*const [i32; 1]' type_id=3
[...]
[5] PTR '*const u32' type_id=6
[...]
[7] PTR '*const [i32; 1024]' type_id=8

DW_tag_pointer_type produced by clang:

0x000000ca:   DW_TAG_pointer_type
                DW_AT_type      (0x000000cf "int[1]")
[...]
0x000000df:   DW_TAG_pointer_type
                DW_AT_type      (0x000000e4 "unsigned int")
[...]
0x000000e8:   DW_TAG_pointer_type
                DW_AT_type      (0x000000ed "int[1024]")

PTR BTF produced by clang:

[1] PTR '(anon)' type_id=3
[...]
[5] PTR '(anon)' type_id=6
[...]
[7] PTR '(anon)' type_id=8

In clang, DW_TAG_pointer_type has only DW_AT_type field, we should probably strip all the others.

DW_TAG_structure_type for maps

Not 100% sure if that matters, but in C, maps are defined as anon structs. In Rust, it's impossible to define anon structs, so struct definitions always end up with DW_AT_name.

DWARF produced by rustc:

0x0000002f:     DW_TAG_variable
                  DW_AT_name    ("PID_MAP")
                  DW_AT_type    (0x00000045 "fork::_ty_PID_MAP")
                  DW_AT_external        (true)
                  DW_AT_decl_file       ("/home/vadorovsky/repos/aya-btf-maps/ebpf/fork-ebpf-aya/src/main.rs")
                  DW_AT_decl_line       (12)
                  DW_AT_alignment       (8)
                  DW_AT_location        (DW_OP_addr 0x0)

0x00000045:     DW_TAG_structure_type
                  DW_AT_name    ("_ty_PID_MAP")
                  DW_AT_byte_size       (0x28)
                  DW_AT_alignment       (8)

BTF produced by rustc:

[11] STRUCT '_ty_PID_MAP' size=40 vlen=5
        'type' type_id=1 bits_offset=0
        'key' type_id=5 bits_offset=64
        'value' type_id=5 bits_offset=128
        'max_entries' type_id=7 bits_offset=192
        'map_flags' type_id=9 bits_offset=256

DWARF produced by clang:

0x00000096:   DW_TAG_variable
                DW_AT_name      ("pid_map")
                DW_AT_type      (0x000000a1 "structure ")
                DW_AT_external  (true)
                DW_AT_decl_file ("/home/vadorovsky/repos/aya-btf-maps/ebpf/fork-ebpf-libbpf/fork.bpf.c")
                DW_AT_decl_line (11)
                DW_AT_location  (DW_OP_addrx 0x2)

0x000000a1:   DW_TAG_structure_type
                DW_AT_byte_size (0x20)
                DW_AT_decl_file ("/home/vadorovsky/repos/aya-btf-maps/ebpf/fork-ebpf-libbpf/fork.bpf.c")
                DW_AT_decl_line (6)

BTF produced by clang:

[9] STRUCT '(anon)' size=32 vlen=4
        'type' type_id=1 bits_offset=0
        'key' type_id=5 bits_offset=64
        'value' type_id=5 bits_offset=128
        'max_entries' type_id=7 bits_offset=192
@vadorovsky
Copy link
Member Author

@davibe Since you said you started work on that, let me know if you want me to assign you.

@davibe
Copy link
Contributor

davibe commented Oct 21, 2022

definitely

@vadorovsky
Copy link
Member Author

Done on #182

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

No branches or pull requests

2 participants