summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/linked_vars2.c
blob: e4f5bd388a3c7af3da726f2a6f7d5d1739a213d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

extern int LINUX_KERNEL_VERSION __kconfig;
/* when an extern is defined as both strong and weak, resulting symbol will be strong */
extern bool CONFIG_BPF_SYSCALL __kconfig;
extern const void __start_BTF __ksym;

int input_bss2;
int input_data2 = 2;
const volatile int input_rodata2 = 22;

int input_bss_weak __weak;
/* these two weak variables should lose */
int input_data_weak __weak = 20;
const volatile int input_rodata_weak __weak = 200;

extern int input_bss1;
extern int input_data1;
extern const int input_rodata1;

int output_bss2;
int output_data2;
int output_rodata2;

int output_sink2;

static __noinline int get_data_res(void)
{
	/* just make sure all the relocations work against .text as well */
	return input_data1 + input_data2 + input_data_weak;
}

SEC("raw_tp/sys_enter")
int BPF_PROG(handler2)
{
	output_bss2 = input_bss1 + input_bss2 + input_bss_weak;
	output_data2 = get_data_res();
	output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak;

	/* make sure we actually use above special externs, otherwise compiler
	 * will optimize them out
	 */
	output_sink2 = LINUX_KERNEL_VERSION
		       + CONFIG_BPF_SYSCALL
		       + (long)&__start_BTF;

	return 0;
}

char LICENSE[] SEC("license") = "GPL";