[PATCH] D131012: No longer place const volatile global variables in a read only section

Andrii Nakryiko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 09:39:41 PDT 2022

anakryiko added a comment.

In D131012#3696327 <https://reviews.llvm.org/D131012#3696327>, @aaron.ballman wrote:

> In D131012#3695110 <https://reviews.llvm.org/D131012#3695110>, @anakryiko wrote:
>> This will severly break BPF users, as we have a heavy reliance on `const volatile` variables being allocated to `.rodata`, which are passed to BPF verifier in Linux kernel as read-only values. This is critical for BPF Complie Once - Run Everywhere approach of writing portable BPF applications. We've been relying on this behavior for years now and changes this will break many existing BPF applications.
> Thank you for this feedback! I guess I'm a bit surprised given the contents from the issue seem to imply that BPF needed Clang's behavior to change: `Note that this is causing practical difficulties: the kernel's bpftool is generating different skeleton headers for BPF code compiled from LLVM and GCC, because the names of the containing sections get reflected.`

GCC folks are trying to make their BPF backend usable. But instead of working with community to make sure they do things the same way that Clang does (which for years now if de facto standard for compiling BPF code and we rely on this behavior heavily in libbpf and other BPF loader libraries), they instead work against BPF community and try to modify/adjust/break the world around them, instead of working with us to make GCC-BPF compatible with Clang.

> That said, I'm asking on the WG14 reflectors whether there's a normative requirement here or not, so I'm marking this as having planned changes until I hear back from WG14 and until we've resolved whether the changes will fix code vs break code (or both!) so we don't accidentally land this.

Thanks! But note that `const volatile` being in `.rodata` is a very explicit expectation in BPF world, so changing that to `.data` will immediately break a bunch of different BPF applications that rely on this for BPF CO-RE (Compile Once - Run Everywhere) for guarding BPF code that shouldn't work on old kernels. .rodata is reported to BPF verifier as fixed, read-only, known values and BPF verifier is using those values for control flow analysis and dead code elimination. This is crucial feature.



More information about the cfe-commits mailing list