162306a36Sopenharmony_ci.. contents:: 262306a36Sopenharmony_ci.. sectnum:: 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci========================== 562306a36Sopenharmony_ciClang implementation notes 662306a36Sopenharmony_ci========================== 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciThis document provides more details specific to the Clang/LLVM implementation of the eBPF instruction set. 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciVersions 1162306a36Sopenharmony_ci======== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciClang defined "CPU" versions, where a CPU version of 3 corresponds to the current eBPF ISA. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciClang can select the eBPF ISA version using ``-mcpu=v3`` for example to select version 3. 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciArithmetic instructions 1862306a36Sopenharmony_ci======================= 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciFor CPU versions prior to 3, Clang v7.0 and later can enable ``BPF_ALU`` support with 2162306a36Sopenharmony_ci``-Xclang -target-feature -Xclang +alu32``. In CPU version 3, support is automatically included. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciJump instructions 2462306a36Sopenharmony_ci================= 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciIf ``-O0`` is used, Clang will generate the ``BPF_CALL | BPF_X | BPF_JMP`` (0x8d) 2762306a36Sopenharmony_ciinstruction, which is not supported by the Linux kernel verifier. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciAtomic operations 3062306a36Sopenharmony_ci================= 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciClang can generate atomic instructions by default when ``-mcpu=v3`` is 3362306a36Sopenharmony_cienabled. If a lower version for ``-mcpu`` is set, the only atomic instruction 3462306a36Sopenharmony_ciClang can generate is ``BPF_ADD`` *without* ``BPF_FETCH``. If you need to enable 3562306a36Sopenharmony_cithe atomics features, while keeping a lower ``-mcpu`` version, you can use 3662306a36Sopenharmony_ci``-Xclang -target-feature -Xclang +alu32``. 37