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 /* this weak extern will be strict due to the other file's strong extern */
0010 extern bool CONFIG_BPF_SYSCALL __kconfig __weak;
0011 extern const void bpf_link_fops __ksym __weak;
0012 
0013 int input_bss1;
0014 int input_data1 = 1;
0015 const volatile int input_rodata1 = 11;
0016 
0017 int input_bss_weak __weak;
0018 /* these two definitions should win */
0019 int input_data_weak __weak = 10;
0020 const volatile int input_rodata_weak __weak = 100;
0021 
0022 extern int input_bss2;
0023 extern int input_data2;
0024 extern const int input_rodata2;
0025 
0026 int output_bss1;
0027 int output_data1;
0028 int output_rodata1;
0029 
0030 long output_sink1;
0031 
0032 static __noinline int get_bss_res(void)
0033 {
0034     /* just make sure all the relocations work against .text as well */
0035     return input_bss1 + input_bss2 + input_bss_weak;
0036 }
0037 
0038 SEC("raw_tp/sys_enter")
0039 int BPF_PROG(handler1)
0040 {
0041     output_bss1 = get_bss_res();
0042     output_data1 = input_data1 + input_data2 + input_data_weak;
0043     output_rodata1 = 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_sink1 = LINUX_KERNEL_VERSION
0049                + CONFIG_BPF_SYSCALL
0050                + (long)&bpf_link_fops;
0051     return 0;
0052 }
0053 
0054 char LICENSE[] SEC("license") = "GPL";