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

Correct BPF memmove backward loop offset for larger chunks.

Fixes incorrect offset calculation in BPF's memmove backward loop when copying chunks larger than one byte.

A bug in the BPF backend’s expansion of memmove caused an incorrect offset calculation in its backward copy loop. This issue specifically affected cases where larger chunks of data were being moved. The fix ensures the offset correctly accounts for the increment size, and new test cases validate the correction on x86_64.

In Details

The bpf_expand_cpymem function in GCC's BPF backend, responsible for generating code for memmove operations, had an incorrect initial offset calculation for its backward copy loop. This error occurred when copying data in chunks larger than a single byte. The fix in gcc/config/bpf/bpf.cc properly accounts for the increment size within the offset calculation, ensuring correct memory region copying. Tests were run on x86_64-linux-gnu and validated against Linux kernel bpf-next selftests.

For Context
BPF
Berkeley Packet Filter, a technology that allows sandboxed programs to be run safely within the Linux kernel. In GCC, it refers to the backend that compiles C code for BPF execution.
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 correctly, unlike memcpy.
offset
A value that specifies a position relative to a starting point or base address in memory.
Filed Under: bpfmemmovebugfix