• Rong Tao's avatar
    selftests/bpf: Fix compilation errors: Assign a value to a constant · 11e456ca
    Rong Tao authored
    Commit bc292ab0("mm: introduce vma->vm_flags wrapper functions")
    turns the vm_flags into a const variable.
    
    Added bpf_find_vma test in commit f108662b("selftests/bpf: Add tests
    for bpf_find_vma") to assign values to variables that declare const in
    find_vma_fail1.c programs, which is an error to the compiler and does not
    test BPF verifiers. It is better to replace 'const vm_flags_t vm_flags'
    with 'unsigned long vm_start' for testing.
    
        $ make -C tools/testing/selftests/bpf/ -j8
        ...
        progs/find_vma_fail1.c:16:16: error: cannot assign to non-static data
        member 'vm_flags' with const-qualified type 'const vm_flags_t' (aka
        'const unsigned long')
                vma->vm_flags |= 0x55;
                ~~~~~~~~~~~~~ ^
        ../tools/testing/selftests/bpf/tools/include/vmlinux.h:1898:20:
        note: non-static data member 'vm_flags' declared const here
                        const vm_flags_t vm_flags;
                        ~~~~~~~~~~~`~~~~~~^~~~~~~~
    Signed-off-by: default avatarRong Tao <rongtao@cestc.cn>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/tencent_CB281722B3C1BD504C16CDE586CACC2BE706@qq.com
    11e456ca
find_vma_fail1.c 602 Bytes