iovisor / iovisor/bcc

libbpf-tools not building because clang attribute error

Open
#2,855 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

Hi all, I'm taking a stab at the new CO-RE API. If these are successfully compiled, they should be able to run on kernels without BTF support? Is that correct?

Regardless, here's the issue. Running Ubuntu 18.04 I just compiled and installed kernel 5.4 with BTF support (which was successful according to ```bpftool```). I then built LLVM/Clang from source using:

```bash
apt-get install -y cmake gcc g++
git clone --depth 1 http://llvm.org/git/llvm.git
cd llvm/tools
git clone --depth 1 http://llvm.org/git/clang.git
cd ..; mkdir build; cd build;
cmake -DLLVM_TARGETS_TO_BUILD="X86;BPF" \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_ENABLE_RTTI=ON \
-DCMAKE_BUILD_TYPE=Release ..

make -j$(getconf _NPROCESSORS_ONLN)
make install
```

Demonstrating successful installation:
```
$ clang --version
clang version 10.0.0 (http://llvm.org/git/clang.git 65acf43270ea2894dffa0d0b292b92402f80c8cb) (http://llvm.org/git/llvm.git 2c4ca6832fa6b306ee6a7010bfb80a3f2596f824)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

$ llc --version
LLVM (http://llvm.org/):
LLVM version 10.0.0svn
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake

Registered Targets:
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
```

I clone the BCC repo and then:
```
$ cd libbpf-tools/
$ make
```

And got this error:
```
In file included from drsnoop.bpf.c:3:
./vmlinux.h:5:15: error: attribute 'preserve_access_index' is not supported by '#pragma clang attribute'
#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
^
./vmlinux.h:127438:15: error: '#pragma clang attribute pop' with no matching '#pragma clang attribute push'
#pragma clang attribute pop
^
2 errors generated.
Makefile:50: recipe for target '.output/drsnoop.bpf.o' failed
make: *** [.output/drsnoop.bpf.o] Error 1
```

I think the ```pop``` attribute issue will be solved when the ```push``` is solved. So, pulling on that thread, I went to the Clang docs since I thought the attribute issue was weird, and it looks like Clang10 does actually include ```preserve_access_index```. Since this is an issue with the vmlinux_505.h file, I'm not really sure where to proceed from here. I don't quite understand BTF yet although today or tomorrow I'm hoping to shore up my ignorance by looking at the Facebook microsite.

Have I done something wrong, or is this an issue with the vmlinux.h generation? What can I do to fix this error?

Edit: I just realized that I'm trying to use the libbpf-tools vmlinux_505.h for a 5.4 kernel. I'll don't know how to generate my own vmlinux_504.h file yet, but I'll see if I can figure it out. That could be the issue?

Edit (again, sorry): just tried using bpftool for vmlinux generation
```
$ bpftool btf dump file /sys/kernel/btf/vmlinux format c

#ifndef __VMLINUX_H__
#define __VMLINUX_H__

#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
#endif

#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
#pragma clang attribute pop
#endif

#endif /* __VMLINUX_H__ */
```
But I'm not sure how to populate the body of the vmlinux.h file.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with libbpf-tools/Makefile, drsnoop.bpf.c, and the generated vmlinux.h, then compare the reported bpftool BTF dump with the checked-in header and the installed Clang version. Reproduce the build on the stated Ubuntu 18.04 and kernel 5.4 setup. Done means the libbpf-tools targets compile without the preserve_access_index errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
operating-systems, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.