| 1 |
.. contents:: |
| 2 |
.. sectnum:: |
| 3 |
|
| 4 |
========================== |
| 5 |
Clang implementation notes |
| 6 |
========================== |
| 7 |
|
| 8 |
This document provides more details specific to the Clang/LLVM implementation of the eBPF instruction set. |
| 9 |
|
| 10 |
Versions |
| 11 |
======== |
| 12 |
|
| 13 |
Clang defined "CPU" versions, where a CPU version of 3 corresponds to the current eBPF ISA. |
| 14 |
|
| 15 |
Clang can select the eBPF ISA version using ``-mcpu=v3`` for example to select version 3. |
| 16 |
|
| 17 |
Arithmetic instructions |
| 18 |
======================= |
| 19 |
|
| 20 |
For CPU versions prior to 3, Clang v7.0 and later can enable ``BPF_ALU`` support with |
| 21 |
``-Xclang -target-feature -Xclang +alu32``. In CPU version 3, support is automatically included. |
| 22 |
|
| 23 |
Jump instructions |
| 24 |
================= |
| 25 |
|
| 26 |
If ``-O0`` is used, Clang will generate the ``BPF_CALL | BPF_X | BPF_JMP`` (0x8d) |
| 27 |
instruction, which is not supported by the Linux kernel verifier. |
| 28 |
|
| 29 |
Atomic operations |
| 30 |
================= |
| 31 |
|
| 32 |
Clang can generate atomic instructions by default when ``-mcpu=v3`` is |
| 33 |
enabled. If a lower version for ``-mcpu`` is set, the only atomic instruction |
| 34 |
Clang can generate is ``BPF_ADD`` *without* ``BPF_FETCH``. If you need to enable |
| 35 |
the atomics features, while keeping a lower ``-mcpu`` version, you can use |
| 36 |
``-Xclang -target-feature -Xclang +alu32``. |