test_subskeleton_lib.c (1144B)
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) Meta Platforms, Inc. and affiliates. */ 3 4#include <stdbool.h> 5#include <linux/bpf.h> 6#include <bpf/bpf_helpers.h> 7 8/* volatile to force a read */ 9const volatile int var1; 10volatile int var2 = 1; 11struct { 12 int var3_1; 13 __s64 var3_2; 14} var3; 15int libout1; 16 17extern volatile bool CONFIG_BPF_SYSCALL __kconfig; 18 19int var4[4]; 20 21__weak int var5 SEC(".data"); 22 23/* Fully contained within library extern-and-definition */ 24extern int var6; 25 26int var7 SEC(".data.custom"); 27 28int (*fn_ptr)(void); 29 30struct { 31 __uint(type, BPF_MAP_TYPE_HASH); 32 __type(key, __u32); 33 __type(value, __u32); 34 __uint(max_entries, 16); 35} map1 SEC(".maps"); 36 37extern struct { 38 __uint(type, BPF_MAP_TYPE_HASH); 39 __type(key, __u32); 40 __type(value, __u32); 41 __uint(max_entries, 16); 42} map2 SEC(".maps"); 43 44int lib_routine(void) 45{ 46 __u32 key = 1, value = 2; 47 48 (void) CONFIG_BPF_SYSCALL; 49 bpf_map_update_elem(&map2, &key, &value, BPF_ANY); 50 51 libout1 = var1 + var2 + var3.var3_1 + var3.var3_2 + var5 + var6; 52 return libout1; 53} 54 55SEC("perf_event") 56int lib_perf_handler(struct pt_regs *ctx) 57{ 58 return 0; 59} 60 61char LICENSE[] SEC("license") = "GPL";