Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

BTF load error #7

Closed
KfreeZ opened this issue Nov 17, 2020 · 1 comment
Closed

BTF load error #7

KfreeZ opened this issue Nov 17, 2020 · 1 comment

Comments

@KfreeZ
Copy link

KfreeZ commented Nov 17, 2020

hi,
I am trying your code, but encounter an error like below:

+ sudo bpftool prog load bpf_sockops_v4.o /sys/fs/bpf/bpf_sockops
libbpf: Error loading BTF: Invalid argument(22)
libbpf: magic: 0xeb9f
version: 1
flags: 0x0
hdr_len: 24
type_off: 0
type_len: 952
str_off: 952
str_len: 1192
btf_total_size: 2168
[1] PTR (anon) type_id=2
[2] STRUCT bpf_sock_ops size=192 vlen=36
        op type_id=3 bits_offset=0
        (anon) type_id=5 bits_offset=32
        family type_id=3 bits_offset=160
        remote_ip4 type_id=3 bits_offset=192
        local_ip4 type_id=3 bits_offset=224
        remote_ip6 type_id=6 bits_offset=256
        local_ip6 type_id=6 bits_offset=384
        remote_port type_id=3 bits_offset=512
        local_port type_id=3 bits_offset=544
        is_fullsock type_id=3 bits_offset=576
        snd_cwnd type_id=3 bits_offset=608
        srtt_us type_id=3 bits_offset=640
        bpf_sock_ops_cb_flags type_id=3 bits_offset=672
        state type_id=3 bits_offset=704
        rtt_min type_id=3 bits_offset=736
        snd_ssthresh type_id=3 bits_offset=768
        rcv_nxt type_id=3 bits_offset=800
        snd_nxt type_id=3 bits_offset=832
        snd_una type_id=3 bits_offset=864
        mss_cache type_id=3 bits_offset=896
        ecn_flags type_id=3 bits_offset=928
        rate_delivered type_id=3 bits_offset=960
        rate_interval_us type_id=3 bits_offset=992
        packets_out type_id=3 bits_offset=1024
        retrans_out type_id=3 bits_offset=1056
        total_retrans type_id=3 bits_offset=1088
        segs_in type_id=3 bits_offset=1120
        data_segs_in type_id=3 bits_offset=1152
        segs_out type_id=3 bits_offset=1184
        data_segs_out type_id=3 bits_offset=1216
        lost_out type_id=3 bits_offset=1248
        sacked_out type_id=3 bits_offset=1280
        sk_txhash type_id=3 bits_offset=1312
        bytes_received type_id=8 bits_offset=1344
        bytes_acked type_id=8 bits_offset=1408
        (anon) type_id=10 bits_offset=1472
[3] TYPEDEF __u32 type_id=4
[4] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none)
[5] UNION (anon) size=16 vlen=3
        args type_id=6 bits_offset=0
        reply type_id=3 bits_offset=0
        replylong type_id=6 bits_offset=0
[6] ARRAY (anon) type_id=3 index_type_id=7 nr_elems=4
[7] INT __ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none)
[8] TYPEDEF __u64 type_id=9
[9] INT long long unsigned int size=8 bits_offset=0 nr_bits=64 encoding=(none)
[10] UNION (anon) size=8 vlen=1
        sk type_id=11 bits_offset=0
[11] PTR (anon) type_id=26
[12] FUNC_PROTO (anon) return=13 args=(1 skops)
[13] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[14] FUNC bpf_sockops_v4 type_id=12 vlen != 0

libbpf: Error loading .BTF into kernel: -22.
libbpf: bad map relo against section 5
Error: failed to open object file

I have debugged for days, but still don't pass the BTF load, I have checked below conditions, can you help to see where is wrong? Thanks in advance.

[root@centos8-worker3 sockredir]# clang --version
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 176249bd6732a8044d457092ed932768724a6f06)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin


[root@centos8-worker3 sockredir]# llc --version
LLVM (http://llvm.org/):
  LLVM version 11.0.0
  DEBUG build with assertions.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: cascadelake

[root@centos8-worker3 sockredir]# ip -V
ip utility, iproute2-5.8.0

[root@centos8-worker3 sockredir]# uname -r
4.18.0-193.19.1.el8_2.x86_64

// also tried built a new kernel 5.4.77, same result

the built object's sections is like below:

[root@centos8-worker3 sockredir]# readelf -S bpf_sockops_v4.o
There are 25 section headers, starting at offset 0x3200:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .strtab           STRTAB           0000000000000000  000030e1
       000000000000011f  0000000000000000           0     0     1
  [ 2] .text             PROGBITS         0000000000000000  00000040
       0000000000000000  0000000000000000  AX       0     0     4
  [ 3] "sockops"         PROGBITS         0000000000000000  00000040
       0000000000000268  0000000000000000  AX       0     0     8
  [ 4] .rel"sockops"     REL              0000000000000000  00002720
       0000000000000010  0000000000000010          24     3     8
  [ 5] "maps"            PROGBITS         0000000000000000  000002a8
       0000000000000014  0000000000000000  WA       0     0     4
  [ 6] "license"         PROGBITS         0000000000000000  000002bc
       0000000000000004  0000000000000000  WA       0     0     1
  [ 7] "version"         PROGBITS         0000000000000000  000002c0
       0000000000000004  0000000000000000  WA       0     0     4
  [ 8] .rodata.str1.1    PROGBITS         0000000000000000  000002c4
       0000000000000044  0000000000000001 AMS       0     0     1
  [ 9] .debug_loc        PROGBITS         0000000000000000  00000308
       00000000000000c2  0000000000000000           0     0     1
  [10] .debug_abbrev     PROGBITS         0000000000000000  000003ca
       00000000000001b4  0000000000000000           0     0     1
  [11] .debug_info       PROGBITS         0000000000000000  0000057e
       0000000000000649  0000000000000000           0     0     1
  [12] .rel.debug_info   REL              0000000000000000  00002730
       00000000000007c0  0000000000000010          24    11     8
  [13] .debug_ranges     PROGBITS         0000000000000000  00000bc7
       0000000000000030  0000000000000000           0     0     1
  [14] .debug_str        PROGBITS         0000000000000000  00000bf7
       0000000000000428  0000000000000001  MS       0     0     1
  [15] .BTF              PROGBITS         0000000000000000  0000101f
       0000000000000878  0000000000000000           0     0     1
  [16] .rel.BTF          REL              0000000000000000  00002ef0
       0000000000000030  0000000000000010          24    15     8
  [17] .BTF.ext          PROGBITS         0000000000000000  00001897
       00000000000001c0  0000000000000000           0     0     1
  [18] .rel.BTF.ext      REL              0000000000000000  00002f20
       0000000000000190  0000000000000010          24    17     8
  [19] .debug_frame      PROGBITS         0000000000000000  00001a58
       0000000000000028  0000000000000000           0     0     8
  [20] .rel.debug_frame  REL              0000000000000000  000030b0
       0000000000000020  0000000000000010          24    19     8
  [21] .debug_line       PROGBITS         0000000000000000  00001a80
       000000000000021a  0000000000000000           0     0     1
  [22] .rel.debug_line   REL              0000000000000000  000030d0
       0000000000000010  0000000000000010          24    21     8
  [23] .llvm_addrsig     LOOS+0xfff4c03   0000000000000000  000030e0
       0000000000000001  0000000000000000   E      24     0     1
  [24] .symtab           SYMTAB           0000000000000000  00001ca0
       0000000000000a80  0000000000000018           1   108     8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)
@KfreeZ
Copy link
Author

KfreeZ commented Nov 17, 2020

I install all these things on an ubuntu20.10 and without bcc/libbpf, the code works well, close this issue

@KfreeZ KfreeZ closed this as completed Nov 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant