GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
bpf

BPF: Fix memmove backward loops with remainders

BPF memmove implementation corrected for backward copy loops with remainders.

A bug in the BPF backend’s memmove implementation has been fixed, specifically affecting backward copy loops that had a remainder after processing alignment-sized chunks. This caused incorrect bytes to be copied. The fix introduces a new function, emit_move_loop_back, to handle these backward moves correctly, reversing the order of alignment-sized chunks and remainders. Unnecessary code for updating remainders has also been removed.

In Details

This patch corrects an issue in the BPF target's memmove expansion, specifically for backward copy loops. When memmove generated a loop with a non-zero remainder after handling alignment-sized chunks, the order of operations was incorrect, leading to data corruption. The fix introduces emit_move_loop_back to properly handle the reversed order of chunk and remainder processing. It also cleans up dead code in emit_move_loop as per PR128440.

For Context
BPF
Berkeley Packet Filter. A technology that allows sandboxed programs to run in the Linux kernel, commonly used for networking, tracing, and security.
memmove
A C standard library function that copies a block of memory from a source location to a destination location. It handles overlapping memory regions safely.
backend
The part of a compiler that generates target-specific code from an intermediate representation. For GCC, the BPF backend generates BPF bytecode.
alignment-sized chunks
Blocks of data whose size is a multiple of the required memory alignment for the target architecture. Processing data in alignment-sized chunks can improve performance.
remainder
The portion of data that is left over after processing in fixed-size chunks. In this context, it's the bytes remaining after copying alignment-sized blocks during a memmove operation.
PR128440
A bug report identifier within the GCC bug tracking system, referencing a specific issue that this commit addresses.
Filed Under: bpfmemmovecorrectnessbugfix