Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2021 Facebook */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <bpf/bpf_tracing.h>
0007 
0008 extern int LINUX_KERNEL_VERSION __kconfig;
0009 /* when an extern is defined as both strong and weak, resulting symbol will be strong */
0010 extern bool CONFIG_BPF_SYSCALL __kconfig;
0011 extern const void __start_BTF __ksym;
0012 
0013 int input_bss2;
0014 int input_data2 = 2;
0015 const volatile int input_rodata2 = 22;
0016 
0017 int input_bss_weak __weak;
0018 /* these two weak variables should lose */
0019 int input_data_weak __weak = 20;
0020 const volatile int input_rodata_weak __weak = 200;
0021 
0022 extern int input_bss1;
0023 extern int input_data1;
0024 extern const int input_rodata1;
0025 
0026 int output_bss2;
0027 int output_data2;
0028 int output_rodata2;
0029 
0030 int output_sink2;
0031 
0032 static __noinline int get_data_res(void)
0033 {
0034     /* just make sure all the relocations work against .text as well */
0035     return input_data1 + input_data2 + input_data_weak;
0036 }
0037 
0038 SEC("raw_tp/sys_enter")
0039 int BPF_PROG(handler2)
0040 {
0041     output_bss2 = input_bss1 + input_bss2 + input_bss_weak;
0042     output_data2 = get_data_res();
0043     output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak;
0044 
0045     /* make sure we actually use above special externs, otherwise compiler
0046      * will optimize them out
0047      */
0048     output_sink2 = LINUX_KERNEL_VERSION
0049                + CONFIG_BPF_SYSCALL
0050                + (long)&__start_BTF;
0051 
0052     return 0;
0053 }
0054 
0055 char LICENSE[] SEC("license") = "GPL";