LWN: Comments on "BPF in GCC" https://lwn.net/Articles/831402/ This is a special feed containing comments posted to the individual LWN article titled "BPF in GCC". en-us Fri, 19 Sep 2025 09:09:10 +0000 Fri, 19 Sep 2025 09:09:10 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net BPF in GCC https://lwn.net/Articles/875466/ https://lwn.net/Articles/875466/ evanovan <div class="FormattedComment"> What are the requirements to debug BPF code as far as gdb / clang / llvm / gcc versions ?<br> <p> I tried and these are the results. <br> <p> getting latest GDB : <br> $ git clone git://sourceware.org/git/binutils-gdb.git<br> $ cd binutils-gdb<br> $ ./configure bpf<br> $ make<br> <p> -----------------------------------<br> <p> using gcc/g++ version (gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~18.04.1) )<br> command : gcc -ggdb -O2 -Wall -c hello_world.c -o hello_world.o ( debug symbols GETS generated )<br> <p> ./gdb/gdb &lt;hello_world.o&gt;<br> (gdb) target sim<br> (gdb) sim memory-size 4Mb<br> (gdb) load<br> (gdb) run<br> <p> setting breakpoints and hitting them work <br> you CAN&#x27;T step <br> you CAN&#x27;T print &quot;info registers&quot; or print variables <br> <p> continue or step crashes gdb and core dump<br> <p> ----------------------------------------------<br> <p> using clang / llvm ( clang version 10.0.0-4ubuntu1~18.04.2)<br> command : clang -g -O2 -target bpf -c hello_world.c ( no debug symbols gets generated )<br> <p> no debugging with no symbols <br> <p> <p> Please advise and share your experience <br> </div> Mon, 08 Nov 2021 23:37:55 +0000 The trials of the systems programmer https://lwn.net/Articles/831763/ https://lwn.net/Articles/831763/ mathstuf <div class="FormattedComment"> I&#x27;d be fine with calling it Mickensian.<br> <p> His talks (at least those I&#x27;ve seen) are also done with similar turns of phrase.<br> </div> Thu, 17 Sep 2020 22:33:56 +0000 The trials of the systems programmer https://lwn.net/Articles/831759/ https://lwn.net/Articles/831759/ pebolle <div class="FormattedComment"> Is there a name for this style of writing?<br> <p> It&#x27;s bizarre hyperbole from the get-go. The few articles I&#x27;ve read by Mickens suggests he can get away with it. Quite a feat!<br> </div> Thu, 17 Sep 2020 17:23:00 +0000 The trials of the systems programmer https://lwn.net/Articles/831754/ https://lwn.net/Articles/831754/ sdalley I'll say. There are months worth of QOTWs in it. E.g: <blockquote>You might ask, “Why would someone write code in a grotesque language that exposes raw memory addresses? Why not use a modern language with garbage collection and functional programming and free massages after lunch?” Here’s the answer: Pointers are real. They’re what the hardware understands. Somebody has to deal with them. You can’t just place a LISP book on top of an x86 chip and hope that the hardware learns about lambda calculus by osmosis.</blockquote> Thu, 17 Sep 2020 16:13:23 +0000 BPF in GCC https://lwn.net/Articles/831694/ https://lwn.net/Articles/831694/ matthias <div class="FormattedComment"> Many thanks for the link. This is really great.<br> </div> Thu, 17 Sep 2020 07:16:17 +0000 BPF in GCC https://lwn.net/Articles/831676/ https://lwn.net/Articles/831676/ ibukanov <div class="FormattedComment"> WebAssembly! Seriously it was designed to run in browsers and supports memory constrains and interrupting long-running code while the performance is about 50% of the native code with a good jit or 5% with a small interpreter.<br> </div> Wed, 16 Sep 2020 18:58:53 +0000 BPF in GCC https://lwn.net/Articles/831665/ https://lwn.net/Articles/831665/ NYKevin <div class="FormattedComment"> <font class="QuotedText">&gt; static __u32 (* bpf_get_prandom_u32)( void ) = ( void *) 7;</font><br> <p> This reminds me of something James Mickens wrote in 2013:<br> <p> <font class="QuotedText">&gt; What is despair? I have known it—hear my song. Despair is when you’re debugging a kernel driver and you look at a memory dump and you see that a pointer has a value of 7. THERE IS NO HARDWARE ARCHITECTURE THAT IS ALIGNED ON 7. Furthermore, 7 IS TOO SMALL AND ONLY EVIL CODE WOULD TRY TO ACCESS SMALL NUMBER MEMORY. </font><br> <p> See <a href="https://scholar.harvard.edu/files/mickens/files/thenightwatch.pdf">https://scholar.harvard.edu/files/mickens/files/thenightw...</a><br> </div> Wed, 16 Sep 2020 16:56:38 +0000 BPF in GCC https://lwn.net/Articles/831660/ https://lwn.net/Articles/831660/ nix <div class="FormattedComment"> FYI: people might be wondering what &quot;functions that need to do their own save and restore of the register values&quot; might be. The answer is varargs functions. GCC&#x27;s testsuite calls a *lot* of these: it has many thousands of calls to printf alone. Obviously you won&#x27;t want to use these in the kernel, but since the tests are not testing printf itself, it would be nice to be able to run them regardless.<br> </div> Wed, 16 Sep 2020 15:59:51 +0000 BPF in GCC https://lwn.net/Articles/831621/ https://lwn.net/Articles/831621/ wahern <div class="FormattedComment"> Classic BPF has fixed-width 64-bit instructions with a 16-bit opcode field: <a href="http://www.tcpdump.org/papers/bpf-usenix93.pdf">http://www.tcpdump.org/papers/bpf-usenix93.pdf</a> (see also <a href="https://www.kernel.org/doc/html/latest/networking/filter.html#bpf-engine-and-instruction-set">https://www.kernel.org/doc/html/latest/networking/filter....</a>).<br> <p> Linux eBPF instructions have only an 8-bit opcode field: <a href="https://www.kernel.org/doc/html/latest/networking/filter.html#bpf-kernel-internals">https://www.kernel.org/doc/html/latest/networking/filter....</a> (see end of section, just before <a href="https://www.kernel.org/doc/html/latest/networking/filter.html#ebpf-opcode-encoding">https://www.kernel.org/doc/html/latest/networking/filter....</a>). IIUC, eBPF is mostly fixed-width 64-bit, excepting a 128-bit double-word (64-bit) load immediate instruction. Judging by the source code at include/linux/filter.h:BPF_LD_IMM64_RAW the bottom 64 bits would have an opcode of 0 (top 32 bits cleared) if decoded alone, so would have to be consumed as part of the whole. As opposed to two well-formed instructions that implicitly fuse, e.g. left shift of and bitwise OR into a 64-bit register of a 32-bit immediate that could be executed serially to load a 64-bit value. (I don&#x27;t do assembly programming so probably not using correct jargon.)<br> <p> </div> Wed, 16 Sep 2020 06:50:19 +0000 BPF in GCC https://lwn.net/Articles/831620/ https://lwn.net/Articles/831620/ Cyberax <div class="FormattedComment"> Hmm... BPF is getting more and more complicated.<br> <p> Perhaps they should just switch to 16-bit x86 machine code? After all, the kernel already has an instruction emulator for it.<br> </div> Wed, 16 Sep 2020 05:14:54 +0000 BPF in GCC https://lwn.net/Articles/831619/ https://lwn.net/Articles/831619/ dxin <div class="FormattedComment"> I wonder how BPF is already running out of op codes. What&#x27;s the instruction size and opcode space size?<br> </div> Wed, 16 Sep 2020 04:49:11 +0000 BPF in GCC https://lwn.net/Articles/831616/ https://lwn.net/Articles/831616/ ncm <div class="FormattedComment"> I have liked that with LLVM you can generate eBPF from C++ or even niche things like Rust or D as easily as from C, given a Makefile. <br> <p> Here is hoping Gcc&#x27;s version has similar talents. eBPF from Ada?<br> </div> Wed, 16 Sep 2020 04:01:54 +0000 BPF in GCC https://lwn.net/Articles/831617/ https://lwn.net/Articles/831617/ alison <div class="FormattedComment"> &quot;The GDB support is basic; it only handles loading a BPF program, single stepping, setting breakpoints, examining BPF registers, and listing the assembler code. Similarly, the simulator support is basic; it is integrated with GDB and most of the BPF instructions are supported so programs can run on it. There are plans to add various kinds of kernel contexts to the simulator so that different BPF program types can be run; for example, a program to be attached to a kprobe would be provided with a kprobe context in the simulator.&quot;<br> <p> Presumably all the code in &quot;BPF programs&quot; here is userspace code. AFAIK, one must use kgdb to single-step, set breakpoints, etc. in the kernel itself. Is the intent to simulate the actual execution of the kernel in the simulator, or just to mock the returned contents from the bpf() syscall? Can the in-kernel execution of the BPF opcodes in the embedded VM can be single-stepped without kgdb? I looked at the slides, but they are much shorter than this excellent article.<br> </div> Wed, 16 Sep 2020 04:01:23 +0000