Skip to content

Commit ee87ce8

Browse files
Standardise on C17 with GNU extensions (#890)
1 parent 14d05df commit ee87ce8

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DEPENDENCIES_DOCKERFILE=./dependencies.Dockerfile
3535

3636
# BPF code generator dependencies
3737
CLANG ?= clang
38-
CFLAGS := -O2 -g -Wunaligned-access -Wpacked -Wpadded -Wall -Werror $(CFLAGS)
38+
CFLAGS := -std=gnu17 -O2 -g -Wunaligned-access -Wpacked -Wpadded -Wall -Werror $(CFLAGS)
3939

4040
CLANG_TIDY ?= clang-tidy
4141

bpf/.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Checks:
2222
WarningsAsErrors: '*'
2323
HeaderFilterRegex: ''
2424
FormatStyle: none
25-
ExtraArgs: ['--target=bpf', '-I.', '-D__TARGET_ARCH_x86', '-DBPF_DEBUG', '-DBPF_TRACEPARENT']
25+
ExtraArgs: ['-std=gnu17', '--target=bpf', '-I.', '-D__TARGET_ARCH_x86', '-DBPF_DEBUG', '-DBPF_TRACEPARENT']

bpf/.clangd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CompileFlags:
2+
Add:
3+
- -std=gnu17
4+
- --target=bpf
5+
- -I.
6+
- -D__TARGET_ARCH_x86
7+
- -DBPF_DEBUG
8+
- -DBPF_TRACEPARENT
9+
Diagnostics:
10+
ClangTidy:
11+
FastCheckFilter: None

bpf/compile_flags.txt

Whitespace-only changes.

devdocs/vscode.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Working with C Code for eBPF in VS Code
2+
3+
This repository already includes the configuration needed for working on the eBPF C sources:
4+
5+
- `.clangd`
6+
7+
You do not need to configure this file. You only need to set up VS Code to use it correctly.
8+
9+
## What You Need To Do
10+
11+
### 1. Install clangd and disable IntelliSense
12+
13+
Install the clangd extension.
14+
Disable the Microsoft C/C++ extension (or at least disable its IntelliSense engine).
15+
If IntelliSense is active, clangd never runs.
16+
17+
IntelliSense uses the EDG front end, which does not match how clang handles GNU17 or the kernel-style extensions used in eBPF code. It often produces incorrect parsing and diagnostics. clangd uses the same frontend as the actual compiler, so its behavior matches how the code is really built.
18+
19+
### 2. Why clangd is the correct backend
20+
21+
The eBPF C code in this repository is written for clang in GNU17 mode.
22+
clangd uses the same parser and semantics, and the `.clangd` file in the repo already defines the expected rules and mode.
23+
This gives consistent, accurate diagnostics and correct behavior for the kernel and BPF headers.
24+
25+
### 3. What you get when clangd is active
26+
27+
- Correct GNU17 parsing
28+
- Proper handling of GNU extensions used by kernel and eBPF code
29+
- No IntelliSense inconsistencies
30+
- Diagnostics that reflect real compiler behavior
31+
32+
### 4. Verify that clangd is active
33+
34+
Look at the bottom-right of VS Code. It should show "clangd".
35+
If it shows "C/C++", IntelliSense is still running and needs to be disabled.
36+
37+
### Optional: Make VS Code Treat .h Files as C
38+
39+
VS Code treats `.h` files as C++ by default. If you want the bottom-right language mode to show "C" and keep the editor consistent with the C-only eBPF code in this repo, add this to your VS Code settings:
40+
41+
```json
42+
"files.associations": {
43+
"*.h": "c"
44+
}

0 commit comments

Comments
 (0)