162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright (c) 2021 Facebook */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include "vmlinux.h" 562306a36Sopenharmony_ci#include <bpf/bpf_helpers.h> 662306a36Sopenharmony_ci#include <bpf/bpf_tracing.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciextern int LINUX_KERNEL_VERSION __kconfig; 962306a36Sopenharmony_ci/* when an extern is defined as both strong and weak, resulting symbol will be strong */ 1062306a36Sopenharmony_ciextern bool CONFIG_BPF_SYSCALL __kconfig; 1162306a36Sopenharmony_ciextern const void __start_BTF __ksym; 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciint input_bss2; 1462306a36Sopenharmony_ciint input_data2 = 2; 1562306a36Sopenharmony_ciconst volatile int input_rodata2 = 22; 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ciint input_bss_weak __weak; 1862306a36Sopenharmony_ci/* these two weak variables should lose */ 1962306a36Sopenharmony_ciint input_data_weak __weak = 20; 2062306a36Sopenharmony_ciconst volatile int input_rodata_weak __weak = 200; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciextern int input_bss1; 2362306a36Sopenharmony_ciextern int input_data1; 2462306a36Sopenharmony_ciextern const int input_rodata1; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciint output_bss2; 2762306a36Sopenharmony_ciint output_data2; 2862306a36Sopenharmony_ciint output_rodata2; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciint output_sink2; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistatic __noinline int get_data_res(void) 3362306a36Sopenharmony_ci{ 3462306a36Sopenharmony_ci /* just make sure all the relocations work against .text as well */ 3562306a36Sopenharmony_ci return input_data1 + input_data2 + input_data_weak; 3662306a36Sopenharmony_ci} 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciSEC("raw_tp/sys_enter") 3962306a36Sopenharmony_ciint BPF_PROG(handler2) 4062306a36Sopenharmony_ci{ 4162306a36Sopenharmony_ci output_bss2 = input_bss1 + input_bss2 + input_bss_weak; 4262306a36Sopenharmony_ci output_data2 = get_data_res(); 4362306a36Sopenharmony_ci output_rodata2 = input_rodata1 + input_rodata2 + input_rodata_weak; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci /* make sure we actually use above special externs, otherwise compiler 4662306a36Sopenharmony_ci * will optimize them out 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci output_sink2 = LINUX_KERNEL_VERSION 4962306a36Sopenharmony_ci + CONFIG_BPF_SYSCALL 5062306a36Sopenharmony_ci + (long)&__start_BTF; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci return 0; 5362306a36Sopenharmony_ci} 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_cichar LICENSE[] SEC("license") = "GPL"; 56