tools/testing/selftests/bpf/progs/verifier_align.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_align.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/verifier_align.c
Extension
.c
Size
16977 bytes
Lines
582
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
/* Converted from tools/testing/selftests/bpf/prog_tests/align.c */

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

/* Four tests of known constants.  These aren't staggeringly
 * interesting since we track exact values now.
 */

SEC("tc")
__success __log_level(2)
__flag(BPF_F_ANY_ALIGNMENT)
__msg("0: R1=ctx() R10=fp0")
__msg("0: {{.*}} R3=2")
__msg("1: {{.*}} R3=4")
__msg("2: {{.*}} R3=8")
__msg("3: {{.*}} R3=16")
__msg("4: {{.*}} R3=32")
__naked void mov(void)
{
	asm volatile ("					\
	r3 = 2;						\
	r3 = 4;						\
	r3 = 8;						\
	r3 = 16;					\
	r3 = 32;					\
	r0 = 0;						\
	exit;						\
"	::: __clobber_all);
}

SEC("tc")
__success __log_level(2)
__flag(BPF_F_ANY_ALIGNMENT)
__msg("0: R1=ctx() R10=fp0")
__msg("0: {{.*}}R3=1")
__msg("1: {{.*}}R3=2")
__msg("2: {{.*}}R3=4")
__msg("3: {{.*}}R3=8")
__msg("4: {{.*}}R3=16")
__msg("5: {{.*}}R3=1")
__msg("6: {{.*}}R4=32")
__msg("7: {{.*}}R4=16")
__msg("8: {{.*}}R4=8")
__msg("9: {{.*}}R4=4")
__msg("10: {{.*}}R4=2")
__naked void shift(void)
{
	asm volatile ("					\
	r3 = 1;						\
	r3 <<= 1;					\
	r3 <<= 1;					\
	r3 <<= 1;					\
	r3 <<= 1;					\
	r3 >>= 4;					\
	r4 = 32;					\
	r4 >>= 1;					\
	r4 >>= 1;					\
	r4 >>= 1;					\
	r4 >>= 1;					\
	r0 = 0;						\
	exit;						\
"	::: __clobber_all);
}

SEC("tc")
__success __log_level(2)
__flag(BPF_F_ANY_ALIGNMENT)
__msg("0: R1=ctx() R10=fp0")
__msg("0: {{.*}}R3=4")
__msg("1: {{.*}}R3=8")
__msg("2: {{.*}}R3=10")
__msg("3: {{.*}}R4=8")
__msg("4: {{.*}}R4=12")
__msg("5: {{.*}}R4=14")
__naked void addsub(void)
{
	asm volatile ("					\
	r3 = 4;						\
	r3 += 4;					\
	r3 += 2;					\
	r4 = 8;						\
	r4 += 4;					\
	r4 += 2;					\
	r0 = 0;						\
	exit;						\
"	::: __clobber_all);

Annotation

Implementation Notes