libbpf / libbpf-bootstrap

Scaffolding for BPF application development with libbpf and BPF CO-RE
BSD 3-Clause "New" or "Revised" License
1.09k stars 294 forks source link

make failed under `examples/c` with `gimli = "^0.28"` #269

Closed fujitatomoya closed 5 months ago

fujitatomoya commented 5 months ago

since I am new for libbpf, not really sure what went wrong so posting issue here. it just seems that required package version does not match from blazesym package.

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >uname -a
Linux tomoyafujita 5.15.0-102-generic #112~20.04.1-Ubuntu SMP Thu Mar 14 14:28:24 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >make
    Updating crates.io index
    Updating git repository `https://github.com/bheisler/criterion.rs.git`
error: failed to select a version for the requirement `gimli = "^0.28"`
candidate versions found which didn't match: 0.27.3, 0.27.2, 0.27.1, ...
location searched: crates.io index
required by package `blazesym v0.2.0-alpha.11 (/home/tomoyafujita/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/blazesym)`
make: *** [Makefile:98: /home/tomoyafujita/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/blazesym/target/release/libblazesym_c.a] Error 101

btw, examples seem to work.

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >sudo ./minimal
libbpf: loading object 'minimal_bpf' from buffer
libbpf: elf: section(2) .symtab, size 216, link 1, flags 0, type=2
libbpf: elf: section(3) tp/syscalls/sys_enter_write, size 104, link 0, flags 6, type=1
libbpf: sec 'tp/syscalls/sys_enter_write': found program 'handle_tp' at insn offset 0 (0 bytes), code size 13 insns (104 bytes)
libbpf: elf: section(4) license, size 13, link 0, flags 3, type=1
libbpf: license of minimal_bpf is Dual BSD/GPL
libbpf: elf: section(5) .bss, size 4, link 0, flags 3, type=8
libbpf: elf: section(6) .rodata, size 28, link 0, flags 2, type=1
libbpf: elf: section(7) .reltp/syscalls/sys_enter_write, size 32, link 2, flags 0, type=9
libbpf: elf: section(8) .BTF, size 629, link 0, flags 0, type=1
libbpf: elf: section(9) .BTF.ext, size 160, link 0, flags 0, type=1
libbpf: looking for externs among 9 symbols...
libbpf: collected 0 externs total
libbpf: map 'minimal_.bss' (global data): at sec_idx 5, offset 0, flags 400.
libbpf: map 0 is "minimal_.bss"
libbpf: map 'minimal_.rodata' (global data): at sec_idx 6, offset 0, flags 80.
libbpf: map 1 is "minimal_.rodata"
libbpf: sec '.reltp/syscalls/sys_enter_write': collecting relocation for section(3) 'tp/syscalls/sys_enter_write'
libbpf: sec '.reltp/syscalls/sys_enter_write': relo #0: insn #2 against 'my_pid'
libbpf: prog 'handle_tp': found data map 0 (minimal_.bss, sec 5, off 0) for insn 2
libbpf: sec '.reltp/syscalls/sys_enter_write': relo #1: insn #6 against '.rodata'
libbpf: prog 'handle_tp': found data map 1 (minimal_.rodata, sec 6, off 0) for insn 6
libbpf: object 'minimal_bpf': failed (-22) to create BPF token from '/sys/fs/bpf', skipping optional step...
libbpf: map 'minimal_.bss': created successfully, fd=3
libbpf: map 'minimal_.rodata': created successfully, fd=4
Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` to see output of the BPF programs.
.......
danielocfb commented 5 months ago

I think what could be happening is that you have an old Rust version installed. If it's too old it may not be able to build newer versions of gimli and I believe they may not even be listed as candidate versions (because they are no candidate). Can you try updating Rust and/or share what version you are using?

Edit: blazesym requires Rust 1.65 at a minimum.

fujitatomoya commented 5 months ago

thanks, it processed further then, but i can see the following error.

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >rustc -V
rustc 1.78.0 (9b00956e5 2024-04-29)

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >make
   Compiling blazesym-c v0.0.0 (/home/tomoyafujita/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/blazesym/capi)
error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
   --> capi/src/symbolize.rs:614:40
    |
587 |     let mut syms_last = unsafe { &mut (*result_ptr).syms as *mut blaze_sym };
    |                                  -----------------------------------------
    |                                  |    |
    |                                  |    backing allocation comes from here
    |                                  casting happend here
...
614 |                 let sym_ref = unsafe { &mut *syms_last };
    |                                        ^^^^^^^^^^^^^^^
    |
    = note: casting from `[blaze_sym; 0]` (0 bytes) to `blaze_sym` (80 bytes)
    = note: `#[deny(invalid_reference_casting)]` on by default

error: could not compile `blazesym-c` (lib) due to 1 previous error
make: *** [Makefile:98: /home/tomoyafujita/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/blazesym/target/release/libblazesym_c.a] Error 101
danielocfb commented 5 months ago

Yeah, this was due to a change in the Rust compiler. It got addressed way back when, but we haven't had a release since then. Will update the snapshot some more.

danielocfb commented 5 months ago

Can you update libbpf-bootstrap to the most recent revision? I don't think your code is up-to-date, as https://github.com/libbpf/libbpf-bootstrap/commit/f189965c3c16f9219e7687c4333b733b375d33a8 should have included the fix.

fujitatomoya commented 5 months ago

@danielocfb thanks for checking.

https://github.com/libbpf/libbpf-bootstrap?tab=readme-ov-file#building failed with the following error, i used https://github.com/libbpf/libbpf-bootstrap/commit/087ff1ac047f40abad7eeb62def128b58453b2f1

...
libbpf: failed to find BTF info for global/extern symbol 'dev'
Error: failed to link '.output/minimal_ns.tmp.bpf.o': No such file or directory (2)
make: *** [Makefile:109: .output/minimal_ns.bpf.o] Error 254
make: *** Deleting file '.output/minimal_ns.bpf.o'
danielocfb commented 5 months ago

Hm, that seems to be a problem with minimal_ns now :-( You can move to the previous commit and the build will hopefully go through.

I don't know what this issue is about, exactly, and it works for me (tm). But it's conceivable that the incremental build is broken because of earlier build failures getting everything into an inconsistent state. So perhaps try cleaning everything and rebuilding.

fujitatomoya commented 5 months ago

as you mentioned, reverting https://github.com/libbpf/libbpf-bootstrap/commit/087ff1ac047f40abad7eeb62def128b58453b2f1 works okay.

danielocfb commented 5 months ago

What clang version do you have? Apparently BTF information for globals (which libbpf seems to require here) is a semi-recent addition (perhaps clang 15 time frame). So you can try upgrading that as well.

fujitatomoya commented 5 months ago

with https://github.com/libbpf/libbpf-bootstrap/commit/2dffae1fca82fd9ef4ba15df67606cbfd2eb5412

the followings are what i see with multiple ubuntu distro, clang is too old, and it already says v11 or later, sorry about that. so i will go ahead to close this one, thank you very much for iteration.

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >clang --version
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

tomoyafujita@~/DVT/03_OSS/github.com/libbpf/libbpf-bootstrap/examples/c >make
    Finished `release` profile [optimized + debuginfo] target(s) in 0.28s
  BPF      .output/minimal_ns.bpf.o
libbpf: failed to find BTF info for global/extern symbol 'dev'
Error: failed to link '.output/minimal_ns.tmp.bpf.o': No such file or directory (2)
make: *** [Makefile:109: .output/minimal_ns.bpf.o] Error 254
make: *** Deleting file '.output/minimal_ns.bpf.o'
root@tomoyafujita:~/docker_ws/WORK/libbpf-bootstrap/examples/c# clang --version
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
root@tomoyafujita:/# clang --version
Ubuntu clang version 18.1.3 (1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
fujitatomoya commented 5 months ago

@danielocfb appreciate your support, closing.