title: libbpf: failed to find BTF for extern 'unlikely': -2
body: <p>I am trying to compile and run the <code>sockex3</code> example (<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/bpf/sockex3_user.c" rel="nofollow noreferrer">sockex3_user.c</a> and <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/bpf/sockex3_kern.c" rel="nofollow noreferrer">sockex3_kern.c</a> from v5.10) in a new project (out of the kernel tree) with <a href="https://github.com/libbpf/libbpf" rel="nofollow noreferrer">libbpf</a> v0.3 as submodule of my repository. I have compiled the code with the following flags:</p>
  <p>kernel (ebpf program)</p>
  <pre><code>set(CMAKE_C_COMPILER clang)
  set(CMAKE_C_FLAGS &quot;${CMAKE_C_FLAGS} -Wall -g -target bpf&quot;)
  </code></pre>
  <p>user</p>
  <pre><code>set(CMAKE_C_COMPILER clang)
  set(CMAKE_C_FLAGS &quot;${CMAKE_C_FLAGS} -Wall -g&quot;)
  </code></pre>
  <p>clang</p>
  <pre><code>$ clang -v
  clang version 11.0.0
  </code></pre>
  <p>So, when I run the binary, I have faced the following error:</p>
  <pre><code>$ sudo ./build/samples/sockex3                                                                             
  [sudo] password for navarro:                                                                                                                                                                  
  libbpf: loading ./build/samples/bpf/CMakeFiles/sockex3_kern.dir/sockex3_kern.c.o                                                                                                              
  libbpf: elf: section(3) socket/3, size 1264, link 0, flags 6, type=1                                                                                                                          
  libbpf: sec 'socket/3': found program 'bpf_func_PARSE_IP' at insn offset 0 (0 bytes), code size 158 insns (1264 bytes)
  libbpf: elf: section(4) .relsocket/3, size 128, link 31, flags 0, type=9
  libbpf: elf: section(5) socket/4, size 1360, link 0, flags 6, type=1
  libbpf: sec 'socket/4': found program 'bpf_func_PARSE_IPV6' at insn offset 0 (0 bytes), code size 170 insns (1360 bytes)
  libbpf: elf: section(6) .relsocket/4, size 112, link 31, flags 0, type=9
  libbpf: elf: section(7) socket/1, size 256, link 0, flags 6, type=1
  libbpf: sec 'socket/1': found program 'bpf_func_PARSE_VLAN' at insn offset 0 (0 bytes), code size 32 insns (256 bytes)
  libbpf: elf: section(8) .relsocket/1, size 16, link 31, flags 0, type=9
  libbpf: elf: section(9) socket/2, size 120, link 0, flags 6, type=1
  libbpf: sec 'socket/2': found program 'bpf_func_PARSE_MPLS' at insn offset 0 (0 bytes), code size 15 insns (120 bytes)
  libbpf: elf: section(10) .relsocket/2, size 16, link 31, flags 0, type=9
  libbpf: elf: section(11) socket/0, size 32, link 0, flags 6, type=1
  libbpf: sec 'socket/0': found program 'main_prog' at insn offset 0 (0 bytes), code size 4 insns (32 bytes)
  libbpf: elf: section(12) license, size 4, link 0, flags 3, type=1
  libbpf: license of ./build/samples/bpf/CMakeFiles/sockex3_kern.dir/sockex3_kern.c.o is GPL
  libbpf: elf: section(13) .maps, size 96, link 0, flags 3, type=1
  libbpf: elf: section(22) .BTF, size 4807, link 0, flags 0, type=1
  libbpf: elf: section(24) .BTF.ext, size 2704, link 0, flags 0, type=1
  libbpf: elf: section(31) .symtab, size 5904, link 1, flags 0, type=2
  libbpf: looking for externs among 246 symbols...
  libbpf: failed to find BTF for extern 'unlikely': -2
  ERROR: opening BPF object file failed
  
  </code></pre>
  <p>I am trying to understand how/when this symbol is define. I found the symbol <a href="https://github.com/libbpf/libbpf/blob/master/include/linux/compiler.h" rel="nofollow noreferrer">here</a>.
  Why libbpf is not finding it? Am I missing anything? FYI, I removed the <code>uapi</code> from the kernel file (<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/bpf/sockex3_kern.c" rel="nofollow noreferrer">sockex3_kern.c</a>) and copied the dependencies (i.e. <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/bpf_legacy.h" rel="nofollow noreferrer">bpf_legacy.h</a>) to my repository.</p>
  <p>Another thing that I cant understand is why the sections (below) of the object file (out of the kernel tree) are different</p>
  <pre><code>31 .llvm_addrsig     00000012 0000000000000000 &lt;--- Available in the object out of the tree
  </code></pre>
  <p>when comparing to the object file generated in the kernel tree.</p>
  <p>Out-of-tree</p>
  <pre><code>$ llvm-objdump -h build/samples/bpf/CMakeFiles/sockex3_kern.dir/sockex3_kern.c.o 
  
  build/samples/bpf/CMakeFiles/sockex3_kern.dir/sockex3_kern.c.o: file format elf64-bpf
  
  Sections:
  Idx Name              Size     VMA              Type
    0                   00000000 0000000000000000 
    1 .strtab           000002c2 0000000000000000 
    2 .text             00000000 0000000000000000 TEXT
    3 socket/3          000004d0 0000000000000000 TEXT
    4 .relsocket/3      00000070 0000000000000000 
    5 socket/4          00000550 0000000000000000 TEXT
    6 .relsocket/4      00000070 0000000000000000 
    7 socket/1          00000100 0000000000000000 TEXT
    8 .relsocket/1      00000010 0000000000000000 
    9 socket/2          00000078 0000000000000000 TEXT
   10 .relsocket/2      00000010 0000000000000000 
   11 socket/0          000000e8 0000000000000000 TEXT
   12 .relsocket/0      00000010 0000000000000000 
   13 license           00000004 0000000000000000 DATA
   14 .maps             00000060 0000000000000000 DATA
   15 .debug_loc        00000ef1 0000000000000000 
   16 .rel.debug_loc    00000370 0000000000000000 
   17 .debug_abbrev     000002b9 0000000000000000 
   18 .debug_info       00000f1b 0000000000000000 
   19 .rel.debug_info   000013c0 0000000000000000 
   20 .debug_ranges     000002e0 0000000000000000 
   21 .rel.debug_ranges 00000420 0000000000000000 
   22 .debug_str        000007c2 0000000000000000 
   23 .BTF              000012e1 0000000000000000 
   24 .rel.BTF          00000040 0000000000000000 
   25 .BTF.ext          00000ac0 0000000000000000 
   26 .rel.BTF.ext      00000a70 0000000000000000 
   27 .debug_frame      00000088 0000000000000000 
   28 .rel.debug_frame  000000a0 0000000000000000 
   29 .debug_line       0000049e 0000000000000000 
   30 .rel.debug_line   00000050 0000000000000000 
   31 .llvm_addrsig     00000012 0000000000000000 
   32 .symtab           00001788 0000000000000000 
  </code></pre>
  <p>Kernel tree</p>
  <pre><code>$ llvm-objdump -h sockex3_kern.o 
  
  sockex3_kern.o: file format elf64-bpf
  
  Sections:
  Idx Name              Size     VMA              Type
    0                   00000000 0000000000000000 
    1 .strtab           000002b1 0000000000000000 
    2 .text             00000000 0000000000000000 TEXT
    3 socket/3          000004d8 0000000000000000 TEXT
    4 .relsocket/3      00000070 0000000000000000 
    5 socket/4          00000558 0000000000000000 TEXT
    6 .relsocket/4      00000070 0000000000000000 
    7 socket/1          00000100 0000000000000000 TEXT
    8 .relsocket/1      00000010 0000000000000000 
    9 socket/2          00000078 0000000000000000 TEXT
   10 .relsocket/2      00000010 0000000000000000 
   11 socket/0          000000e8 0000000000000000 TEXT
   12 .relsocket/0      00000010 0000000000000000 
   13 license           00000004 0000000000000000 DATA
   14 .maps             00000060 0000000000000000 DATA
   15 .debug_loc        00000ef1 0000000000000000 
   16 .rel.debug_loc    00000370 0000000000000000 
   17 .debug_abbrev     0000029f 0000000000000000 
   18 .debug_info       00000d4b 0000000000000000 
   19 .rel.debug_info   000011b0 0000000000000000 
   20 .debug_ranges     000002e0 0000000000000000 
   21 .rel.debug_ranges 00000420 0000000000000000 
   22 .debug_str        0000067d 0000000000000000 
   23 .BTF              000012c2 0000000000000000 
   24 .rel.BTF          00000040 0000000000000000 
   25 .BTF.ext          00000ac0 0000000000000000 
   26 .rel.BTF.ext      00000a70 0000000000000000 
   27 .eh_frame         000000b0 0000000000000000 DATA
   28 .rel.eh_frame     00000050 0000000000000000 
   29 .debug_line       0000046b 0000000000000000 
   30 .rel.debug_line   00000050 0000000000000000 
   31 .symtab           00001500 0000000000000000 
  </code></pre>
  <p>Thank you in advance!</p>