16c7aaffbSDave Thaler.. contents:: 26c7aaffbSDave Thaler.. sectnum:: 36c7aaffbSDave Thaler 46c7aaffbSDave Thaler========================== 56c7aaffbSDave ThalerClang implementation notes 66c7aaffbSDave Thaler========================== 76c7aaffbSDave Thaler 86c7aaffbSDave ThalerThis document provides more details specific to the Clang/LLVM implementation of the eBPF instruction set. 96c7aaffbSDave Thaler 106c7aaffbSDave ThalerVersions 116c7aaffbSDave Thaler======== 126c7aaffbSDave Thaler 136c7aaffbSDave ThalerClang defined "CPU" versions, where a CPU version of 3 corresponds to the current eBPF ISA. 146c7aaffbSDave Thaler 156c7aaffbSDave ThalerClang can select the eBPF ISA version using ``-mcpu=v3`` for example to select version 3. 166c7aaffbSDave Thaler 17ee159bdbSDave ThalerArithmetic instructions 18ee159bdbSDave Thaler======================= 19ee159bdbSDave Thaler 20ee159bdbSDave ThalerFor CPU versions prior to 3, Clang v7.0 and later can enable ``BPF_ALU`` support with 21ee159bdbSDave Thaler``-Xclang -target-feature -Xclang +alu32``. In CPU version 3, support is automatically included. 22ee159bdbSDave Thaler 23*c1f9e14eSDave ThalerJump instructions 24*c1f9e14eSDave Thaler================= 25*c1f9e14eSDave Thaler 26*c1f9e14eSDave ThalerIf ``-O0`` is used, Clang will generate the ``BPF_CALL | BPF_X | BPF_JMP`` (0x8d) 27*c1f9e14eSDave Thalerinstruction, which is not supported by the Linux kernel verifier. 28*c1f9e14eSDave Thaler 296c7aaffbSDave ThalerAtomic operations 306c7aaffbSDave Thaler================= 316c7aaffbSDave Thaler 326c7aaffbSDave ThalerClang can generate atomic instructions by default when ``-mcpu=v3`` is 336c7aaffbSDave Thalerenabled. If a lower version for ``-mcpu`` is set, the only atomic instruction 346c7aaffbSDave ThalerClang can generate is ``BPF_ADD`` *without* ``BPF_FETCH``. If you need to enable 356c7aaffbSDave Thalerthe atomics features, while keeping a lower ``-mcpu`` version, you can use 366c7aaffbSDave Thaler``-Xclang -target-feature -Xclang +alu32``. 37