tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c- Extension
.c- Size
- 17560 bytes
- Lines
- 570
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hbpf/btf.hbtf_helpers.h
Detected Declarations
struct s1struct s1struct s1___2struct s2struct s1struct s2function test_split_simplefunction test_split_fwd_resolvefunction test_split_struct_dupedfunction btf_add_dup_struct_in_cufunction test_split_dup_struct_in_cufunction test_split_modulefunction test_btf_dedup_split
Annotated Snippet
struct s1 {\n\
int f1;\n\
};\n\
\n\
typedef int t1;\n\n", "c_dump");
btf2 = btf__new_empty_split(btf1);
if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
goto cleanup;
/* pointer size should be "inherited" from main BTF */
ASSERT_EQ(btf__pointer_size(btf2), 8, "inherit_ptr_sz");
str_off = btf__find_str(btf2, "int");
ASSERT_NEQ(str_off, -ENOENT, "str_int_missing");
t = btf__type_by_id(btf2, 1);
if (!ASSERT_OK_PTR(t, "int_type"))
goto cleanup;
ASSERT_EQ(btf_is_int(t), true, "int_kind");
ASSERT_STREQ(btf__str_by_offset(btf2, t->name_off), "int", "int_name");
btf__add_struct(btf2, "s2", 16); /* [5] struct s2 { */
btf__add_field(btf2, "f1", 7, 0, 0); /* struct s1 f1; */
btf__add_field(btf2, "f2", 6, 32, 0); /* int f2; */
btf__add_field(btf2, "f3", 2, 64, 0); /* int *f3; */
/* } */
/* duplicated int */
btf__add_int(btf2, "int", 4, BTF_INT_SIGNED); /* [6] int */
/* duplicated struct s1 */
btf__add_struct(btf2, "s1", 4); /* [7] struct s1 { */
btf__add_field(btf2, "f1", 6, 0, 0); /* int f1; */
/* } */
/* duplicated typedef t1 */
btf__add_typedef(btf2, "t1", 6); /* [8] typedef int */
VALIDATE_RAW_BTF(
btf2,
"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
"[2] PTR '(anon)' type_id=1",
"[3] STRUCT 's1' size=4 vlen=1\n"
"\t'f1' type_id=1 bits_offset=0",
"[4] TYPEDEF 't1' type_id=1",
"[5] STRUCT 's2' size=16 vlen=3\n"
"\t'f1' type_id=7 bits_offset=0\n"
"\t'f2' type_id=6 bits_offset=32\n"
"\t'f3' type_id=2 bits_offset=64",
"[6] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
"[7] STRUCT 's1' size=4 vlen=1\n"
"\t'f1' type_id=6 bits_offset=0",
"[8] TYPEDEF 't1' type_id=6");
ASSERT_STREQ(btf_type_c_dump(btf2), "\
struct s1 {\n\
int f1;\n\
};\n\
\n\
typedef int t1;\n\
\n\
struct s1___2 {\n\
int f1;\n\
};\n\
\n\
struct s2 {\n\
struct s1___2 f1;\n\
int f2;\n\
int *f3;\n\
};\n\
\n\
typedef int t1___2;\n\n", "c_dump");
err = btf__dedup(btf2, NULL);
if (!ASSERT_OK(err, "btf_dedup"))
goto cleanup;
VALIDATE_RAW_BTF(
btf2,
"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
"[2] PTR '(anon)' type_id=1",
"[3] STRUCT 's1' size=4 vlen=1\n"
"\t'f1' type_id=1 bits_offset=0",
"[4] TYPEDEF 't1' type_id=1",
"[5] STRUCT 's2' size=16 vlen=3\n"
"\t'f1' type_id=3 bits_offset=0\n"
"\t'f2' type_id=1 bits_offset=32\n"
"\t'f3' type_id=2 bits_offset=64");
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`, `btf_helpers.h`.
- Detected declarations: `struct s1`, `struct s1`, `struct s1___2`, `struct s2`, `struct s1`, `struct s2`, `function test_split_simple`, `function test_split_fwd_resolve`, `function test_split_struct_duped`, `function btf_add_dup_struct_in_cu`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.