Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 2 | |
| 3 | BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src)) |
| 4 | TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools |
| 5 | |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 6 | # List of programs to build |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 7 | tprogs-y := test_lru_dist |
| 8 | tprogs-y += sock_example |
| 9 | tprogs-y += fds_example |
| 10 | tprogs-y += sockex1 |
| 11 | tprogs-y += sockex2 |
| 12 | tprogs-y += sockex3 |
| 13 | tprogs-y += tracex1 |
| 14 | tprogs-y += tracex2 |
| 15 | tprogs-y += tracex3 |
| 16 | tprogs-y += tracex4 |
| 17 | tprogs-y += tracex5 |
| 18 | tprogs-y += tracex6 |
| 19 | tprogs-y += tracex7 |
| 20 | tprogs-y += test_probe_write_user |
| 21 | tprogs-y += trace_output |
| 22 | tprogs-y += lathist |
| 23 | tprogs-y += offwaketime |
| 24 | tprogs-y += spintest |
| 25 | tprogs-y += map_perf_test |
| 26 | tprogs-y += test_overhead |
| 27 | tprogs-y += test_cgrp2_array_pin |
| 28 | tprogs-y += test_cgrp2_attach |
| 29 | tprogs-y += test_cgrp2_sock |
| 30 | tprogs-y += test_cgrp2_sock2 |
| 31 | tprogs-y += xdp1 |
| 32 | tprogs-y += xdp2 |
| 33 | tprogs-y += xdp_router_ipv4 |
| 34 | tprogs-y += test_current_task_under_cgroup |
| 35 | tprogs-y += trace_event |
| 36 | tprogs-y += sampleip |
| 37 | tprogs-y += tc_l2_redirect |
| 38 | tprogs-y += lwt_len_hist |
| 39 | tprogs-y += xdp_tx_iptunnel |
| 40 | tprogs-y += test_map_in_map |
Prashant Bhole | 5984dc6 | 2019-12-16 16:16:19 +0900 | [diff] [blame] | 41 | tprogs-y += per_socket_stats_example |
| 42 | tprogs-y += xdp_redirect |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 43 | tprogs-y += xdp_redirect_map |
| 44 | tprogs-y += xdp_redirect_cpu |
| 45 | tprogs-y += xdp_monitor |
| 46 | tprogs-y += xdp_rxq_info |
| 47 | tprogs-y += syscall_tp |
| 48 | tprogs-y += cpustat |
| 49 | tprogs-y += xdp_adjust_tail |
| 50 | tprogs-y += xdpsock |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 51 | tprogs-y += xsk_fwd |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 52 | tprogs-y += xdp_fwd |
| 53 | tprogs-y += task_fd_query |
| 54 | tprogs-y += xdp_sample_pkts |
| 55 | tprogs-y += ibumad |
| 56 | tprogs-y += hbm |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 57 | |
Joe Stringer | 43371c8 | 2016-12-14 14:43:39 -0800 | [diff] [blame] | 58 | # Libbpf dependencies |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 59 | LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a |
| 60 | |
Roman Gushchin | 9d1f159 | 2017-11-05 08:15:33 -0500 | [diff] [blame] | 61 | CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o |
Yonghong Song | 28dbf86 | 2018-04-28 22:28:13 -0700 | [diff] [blame] | 62 | TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o |
Joe Stringer | 43371c8 | 2016-12-14 14:43:39 -0800 | [diff] [blame] | 63 | |
Jakub Kicinski | 1a9b268 | 2019-02-27 19:04:13 -0800 | [diff] [blame] | 64 | fds_example-objs := fds_example.o |
| 65 | sockex1-objs := sockex1_user.o |
| 66 | sockex2-objs := sockex2_user.o |
Daniel T. Lee | bc1a859 | 2020-05-16 13:06:06 +0900 | [diff] [blame] | 67 | sockex3-objs := sockex3_user.o |
Daniel T. Lee | 63841bc | 2020-05-16 13:06:05 +0900 | [diff] [blame] | 68 | tracex1-objs := tracex1_user.o $(TRACE_HELPERS) |
| 69 | tracex2-objs := tracex2_user.o |
| 70 | tracex3-objs := tracex3_user.o |
| 71 | tracex4-objs := tracex4_user.o |
Daniel T. Lee | bc1a859 | 2020-05-16 13:06:06 +0900 | [diff] [blame] | 72 | tracex5-objs := tracex5_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 63841bc | 2020-05-16 13:06:05 +0900 | [diff] [blame] | 73 | tracex6-objs := tracex6_user.o |
| 74 | tracex7-objs := tracex7_user.o |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 75 | test_probe_write_user-objs := test_probe_write_user_user.o |
| 76 | trace_output-objs := trace_output_user.o $(TRACE_HELPERS) |
| 77 | lathist-objs := lathist_user.o |
Daniel T. Lee | f0c328f | 2020-08-23 17:53:34 +0900 | [diff] [blame] | 78 | offwaketime-objs := offwaketime_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 79 | spintest-objs := spintest_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 35a8b6d | 2020-08-23 17:53:32 +0900 | [diff] [blame] | 80 | map_perf_test-objs := map_perf_test_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 81 | test_overhead-objs := bpf_load.o test_overhead_user.o |
| 82 | test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o |
| 83 | test_cgrp2_attach-objs := test_cgrp2_attach.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 84 | test_cgrp2_sock-objs := test_cgrp2_sock.o |
| 85 | test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o |
| 86 | xdp1-objs := xdp1_user.o |
Brenden Blanco | 764cbcce | 2016-07-19 12:16:57 -0700 | [diff] [blame] | 87 | # reuse xdp1 source intentionally |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 88 | xdp2-objs := xdp1_user.o |
Maciej Fijalkowski | bbaf602 | 2019-02-01 22:42:25 +0100 | [diff] [blame] | 89 | xdp_router_ipv4-objs := xdp_router_ipv4_user.o |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 90 | test_current_task_under_cgroup-objs := $(CGROUP_HELPERS) \ |
Sargun Dhillon | 9e6e60e | 2016-08-12 08:57:04 -0700 | [diff] [blame] | 91 | test_current_task_under_cgroup_user.o |
Daniel T. Lee | aa5e2af | 2020-03-21 19:04:24 +0900 | [diff] [blame] | 92 | trace_event-objs := trace_event_user.o $(TRACE_HELPERS) |
| 93 | sampleip-objs := sampleip_user.o $(TRACE_HELPERS) |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 94 | tc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o |
| 95 | lwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o |
Maciej Fijalkowski | bbaf602 | 2019-02-01 22:42:25 +0100 | [diff] [blame] | 96 | xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o |
Daniel T. Lee | 88795b4 | 2020-07-08 03:48:53 +0900 | [diff] [blame] | 97 | test_map_in_map-objs := test_map_in_map_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 98 | per_socket_stats_example-objs := cookie_uid_helper_example.o |
Maciej Fijalkowski | bbaf602 | 2019-02-01 22:42:25 +0100 | [diff] [blame] | 99 | xdp_redirect-objs := xdp_redirect_user.o |
| 100 | xdp_redirect_map-objs := xdp_redirect_map_user.o |
Daniel T. Lee | 151936b | 2020-10-11 03:17:33 +0900 | [diff] [blame] | 101 | xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o |
Daniel T. Lee | 8ac91df | 2020-10-11 03:17:32 +0900 | [diff] [blame] | 102 | xdp_monitor-objs := xdp_monitor_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 103 | xdp_rxq_info-objs := xdp_rxq_info_user.o |
Daniel T. Lee | f0c328f | 2020-08-23 17:53:34 +0900 | [diff] [blame] | 104 | syscall_tp-objs := syscall_tp_user.o |
| 105 | cpustat-objs := cpustat_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 106 | xdp_adjust_tail-objs := xdp_adjust_tail_user.o |
Jakub Kicinski | 6748182 | 2018-07-26 14:32:21 -0700 | [diff] [blame] | 107 | xdpsock-objs := xdpsock_user.o |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 108 | xsk_fwd-objs := xsk_fwd.o |
Jakub Kicinski | e1a40ef | 2018-07-26 14:32:20 -0700 | [diff] [blame] | 109 | xdp_fwd-objs := xdp_fwd_user.o |
Yonghong Song | ecb96f7 | 2018-05-24 11:21:56 -0700 | [diff] [blame] | 110 | task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS) |
Toke Høiland-Jørgensen | 1e54ad2 | 2018-06-25 14:25:02 +0200 | [diff] [blame] | 111 | xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS) |
Ira Weiny | 0ac01fe | 2019-03-19 14:11:49 -0700 | [diff] [blame] | 112 | ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS) |
brakmo | a1270fe | 2019-03-01 12:38:49 -0800 | [diff] [blame] | 113 | hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS) |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 114 | |
| 115 | # Tell kbuild to always build the programs |
Masahiro Yamada | 5f2fb52 | 2020-02-02 01:49:24 +0900 | [diff] [blame] | 116 | always-y := $(tprogs-y) |
| 117 | always-y += sockex1_kern.o |
| 118 | always-y += sockex2_kern.o |
| 119 | always-y += sockex3_kern.o |
| 120 | always-y += tracex1_kern.o |
| 121 | always-y += tracex2_kern.o |
| 122 | always-y += tracex3_kern.o |
| 123 | always-y += tracex4_kern.o |
| 124 | always-y += tracex5_kern.o |
| 125 | always-y += tracex6_kern.o |
| 126 | always-y += tracex7_kern.o |
| 127 | always-y += sock_flags_kern.o |
| 128 | always-y += test_probe_write_user_kern.o |
| 129 | always-y += trace_output_kern.o |
| 130 | always-y += tcbpf1_kern.o |
| 131 | always-y += tc_l2_redirect_kern.o |
| 132 | always-y += lathist_kern.o |
| 133 | always-y += offwaketime_kern.o |
| 134 | always-y += spintest_kern.o |
| 135 | always-y += map_perf_test_kern.o |
| 136 | always-y += test_overhead_tp_kern.o |
| 137 | always-y += test_overhead_raw_tp_kern.o |
| 138 | always-y += test_overhead_kprobe_kern.o |
| 139 | always-y += parse_varlen.o parse_simple.o parse_ldabs.o |
| 140 | always-y += test_cgrp2_tc_kern.o |
| 141 | always-y += xdp1_kern.o |
| 142 | always-y += xdp2_kern.o |
| 143 | always-y += xdp_router_ipv4_kern.o |
| 144 | always-y += test_current_task_under_cgroup_kern.o |
| 145 | always-y += trace_event_kern.o |
| 146 | always-y += sampleip_kern.o |
| 147 | always-y += lwt_len_hist_kern.o |
| 148 | always-y += xdp_tx_iptunnel_kern.o |
| 149 | always-y += test_map_in_map_kern.o |
| 150 | always-y += tcp_synrto_kern.o |
| 151 | always-y += tcp_rwnd_kern.o |
| 152 | always-y += tcp_bufs_kern.o |
| 153 | always-y += tcp_cong_kern.o |
| 154 | always-y += tcp_iw_kern.o |
| 155 | always-y += tcp_clamp_kern.o |
| 156 | always-y += tcp_basertt_kern.o |
| 157 | always-y += tcp_tos_reflect_kern.o |
| 158 | always-y += tcp_dumpstats_kern.o |
| 159 | always-y += xdp_redirect_kern.o |
| 160 | always-y += xdp_redirect_map_kern.o |
| 161 | always-y += xdp_redirect_cpu_kern.o |
| 162 | always-y += xdp_monitor_kern.o |
| 163 | always-y += xdp_rxq_info_kern.o |
| 164 | always-y += xdp2skb_meta_kern.o |
| 165 | always-y += syscall_tp_kern.o |
| 166 | always-y += cpustat_kern.o |
| 167 | always-y += xdp_adjust_tail_kern.o |
| 168 | always-y += xdp_fwd_kern.o |
| 169 | always-y += task_fd_query_kern.o |
| 170 | always-y += xdp_sample_pkts_kern.o |
| 171 | always-y += ibumad_kern.o |
| 172 | always-y += hbm_out_kern.o |
| 173 | always-y += hbm_edt_kern.o |
| 174 | always-y += xdpsock_kern.o |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 175 | |
Ivan Khoronzhuk | 0e865ae | 2019-10-11 03:27:58 +0300 | [diff] [blame] | 176 | ifeq ($(ARCH), arm) |
| 177 | # Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux |
| 178 | # headers when arm instruction set identification is requested. |
| 179 | ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS)) |
| 180 | BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR) |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 181 | TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR) |
Ivan Khoronzhuk | 0e865ae | 2019-10-11 03:27:58 +0300 | [diff] [blame] | 182 | endif |
| 183 | |
Ivan Khoronzhuk | 10cb3d8 | 2019-10-11 03:28:02 +0300 | [diff] [blame] | 184 | TPROGS_CFLAGS += -Wall -O2 |
| 185 | TPROGS_CFLAGS += -Wmissing-prototypes |
| 186 | TPROGS_CFLAGS += -Wstrict-prototypes |
| 187 | |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 188 | TPROGS_CFLAGS += -I$(objtree)/usr/include |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 189 | TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/ |
| 190 | TPROGS_CFLAGS += -I$(srctree)/tools/lib/ |
| 191 | TPROGS_CFLAGS += -I$(srctree)/tools/include |
| 192 | TPROGS_CFLAGS += -I$(srctree)/tools/perf |
David S. Miller | 14684b9 | 2019-11-09 11:04:37 -0800 | [diff] [blame] | 193 | TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0 |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 194 | |
Ivan Khoronzhuk | b2327c1 | 2019-10-11 03:28:07 +0300 | [diff] [blame] | 195 | ifdef SYSROOT |
| 196 | TPROGS_CFLAGS += --sysroot=$(SYSROOT) |
| 197 | TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib |
| 198 | endif |
| 199 | |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 200 | TPROGCFLAGS_bpf_load.o += -Wno-unused-variable |
| 201 | |
Toke Høiland-Jørgensen | 5615ed4 | 2019-12-16 11:24:05 +0100 | [diff] [blame] | 202 | TPROGS_LDLIBS += $(LIBBPF) -lelf -lz |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 203 | TPROGLDLIBS_tracex4 += -lrt |
| 204 | TPROGLDLIBS_trace_output += -lrt |
| 205 | TPROGLDLIBS_map_perf_test += -lrt |
| 206 | TPROGLDLIBS_test_overhead += -lrt |
| 207 | TPROGLDLIBS_xdpsock += -pthread |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 208 | TPROGLDLIBS_xsk_fwd += -pthread |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 209 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 210 | # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: |
Jesper Dangaard Brouer | 6cc2c87 | 2019-11-10 17:31:16 +0100 | [diff] [blame] | 211 | # make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang |
Jesper Dangaard Brouer | 6ccfba7 | 2016-04-28 14:20:53 +0200 | [diff] [blame] | 212 | LLC ?= llc |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 213 | CLANG ?= clang |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 214 | OPT ?= opt |
| 215 | LLVM_DIS ?= llvm-dis |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 216 | LLVM_OBJCOPY ?= llvm-objcopy |
| 217 | BTF_PAHOLE ?= pahole |
Jesper Dangaard Brouer | 6ccfba7 | 2016-04-28 14:20:53 +0200 | [diff] [blame] | 218 | |
Joel Fernandes | 876e88e | 2017-09-20 09:11:57 -0700 | [diff] [blame] | 219 | # Detect that we're cross compiling and use the cross compiler |
| 220 | ifdef CROSS_COMPILE |
Ivan Khoronzhuk | 518c134 | 2019-10-11 03:27:56 +0300 | [diff] [blame] | 221 | CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%)) |
Joel Fernandes | 876e88e | 2017-09-20 09:11:57 -0700 | [diff] [blame] | 222 | endif |
| 223 | |
Jakub Kicinski | 0ed3cc4 | 2019-06-07 10:11:16 -0700 | [diff] [blame] | 224 | # Don't evaluate probes and warnings if we need to run make recursively |
| 225 | ifneq ($(src),) |
Ivan Khoronzhuk | cdd5b2d | 2019-10-11 03:27:54 +0300 | [diff] [blame] | 226 | HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \ |
Ivan Khoronzhuk | a833eff | 2019-10-11 03:28:03 +0300 | [diff] [blame] | 227 | $(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \ |
| 228 | -o /dev/null 2>/dev/null && echo okay) |
Jakub Kicinski | 07c3bbd | 2019-06-05 16:47:22 -0700 | [diff] [blame] | 229 | |
| 230 | ifeq ($(HDR_PROBE),) |
| 231 | $(warning WARNING: Detected possible issues with include path.) |
| 232 | $(warning WARNING: Please install kernel headers locally (make headers_install).) |
| 233 | endif |
| 234 | |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 235 | BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) |
| 236 | BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) |
| 237 | BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 238 | BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ |
| 239 | $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ |
| 240 | readelf -S ./llvm_btf_verify.o | grep BTF; \ |
| 241 | /bin/rm -f ./llvm_btf_verify.o) |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 242 | |
Toke Høiland-Jørgensen | 4502789 | 2019-12-16 11:38:19 +0100 | [diff] [blame] | 243 | BPF_EXTRA_CFLAGS += -fno-stack-protector |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 244 | ifneq ($(BTF_LLVM_PROBE),) |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 245 | BPF_EXTRA_CFLAGS += -g |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 246 | else |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 247 | ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),) |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 248 | BPF_EXTRA_CFLAGS += -g |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 249 | LLC_FLAGS += -mattr=dwarfris |
| 250 | DWARF2BTF = y |
| 251 | endif |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 252 | endif |
Jakub Kicinski | 0ed3cc4 | 2019-06-07 10:11:16 -0700 | [diff] [blame] | 253 | endif |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 254 | |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 255 | # Trick to allow make to be run from this directory |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 256 | all: |
Jesper Dangaard Brouer | 6cc2c87 | 2019-11-10 17:31:16 +0100 | [diff] [blame] | 257 | $(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR) |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 258 | |
| 259 | clean: |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 260 | $(MAKE) -C ../../ M=$(CURDIR) clean |
Toke Høiland-Jørgensen | b2e5e93 | 2020-01-20 14:06:41 +0100 | [diff] [blame] | 261 | @find $(CURDIR) -type f -name '*~' -delete |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 262 | |
Mickaël Salaün | c25ef6a | 2018-01-26 01:39:30 +0100 | [diff] [blame] | 263 | $(LIBBPF): FORCE |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 264 | # Fix up variables inherited from Kbuild that tools/ build system won't like |
Ivan Khoronzhuk | d8ceae9 | 2019-10-11 03:28:06 +0300 | [diff] [blame] | 265 | $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \ |
| 266 | LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O= |
Mickaël Salaün | c25ef6a | 2018-01-26 01:39:30 +0100 | [diff] [blame] | 267 | |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 268 | $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE |
| 269 | $(call filechk,offsets,__SYSCALL_NRS_H__) |
| 270 | |
Masahiro Yamada | 2c667d7 | 2018-12-22 18:50:34 +0900 | [diff] [blame] | 271 | targets += syscall_nrs.s |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 272 | clean-files += syscall_nrs.h |
| 273 | |
| 274 | FORCE: |
| 275 | |
| 276 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 277 | # Verify LLVM compiler tools are available and bpf target is supported by llc |
| 278 | .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 279 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 280 | verify_cmds: $(CLANG) $(LLC) |
| 281 | @for TOOL in $^ ; do \ |
| 282 | if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \ |
| 283 | echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\ |
| 284 | exit 1; \ |
| 285 | else true; fi; \ |
| 286 | done |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 287 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 288 | verify_target_bpf: verify_cmds |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 289 | @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ |
| 290 | echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ |
| 291 | echo " NOTICE: LLVM version >= 3.7.1 required" ;\ |
| 292 | exit 2; \ |
| 293 | else true; fi |
| 294 | |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 295 | $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) |
| 296 | $(src)/*.c: verify_target_bpf $(LIBBPF) |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 297 | |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 298 | $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h |
brakmo | 187d073 | 2019-03-01 12:38:48 -0800 | [diff] [blame] | 299 | $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h |
brakmo | a1270fe | 2019-03-01 12:38:49 -0800 | [diff] [blame] | 300 | $(obj)/hbm.o: $(src)/hbm.h |
brakmo | 71634d7 | 2019-07-02 15:09:52 -0700 | [diff] [blame] | 301 | $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 302 | |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 303 | -include $(BPF_SAMPLES_PATH)/Makefile.target |
| 304 | |
Naveen N. Rao | 128d151 | 2016-04-04 22:31:33 +0530 | [diff] [blame] | 305 | # asm/sysreg.h - inline assembly used by it is incompatible with llvm. |
| 306 | # But, there is no easy way to fix it, so just exclude it since it is |
Yang Shi | 30b50aa | 2015-11-12 14:07:46 -0800 | [diff] [blame] | 307 | # useless for BPF samples. |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 308 | # below we use long chain of commands, clang | opt | llvm-dis | llc, |
| 309 | # to generate final object file. 'clang' compiles the source into IR |
| 310 | # with native target, e.g., x64, arm64, etc. 'opt' does bpf CORE IR builtin |
| 311 | # processing (llvm12) and IR optimizations. 'llvm-dis' converts |
| 312 | # 'opt' output to IR, and finally 'llc' generates bpf byte code. |
Brenden Blanco | b88c06e | 2015-05-11 21:25:51 -0700 | [diff] [blame] | 313 | $(obj)/%.o: $(src)/%.c |
Jakub Kicinski | 768759e | 2018-05-14 22:35:06 -0700 | [diff] [blame] | 314 | @echo " CLANG-bpf " $@ |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 315 | $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \ |
| 316 | -I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \ |
Toke Høiland-Jørgensen | 7cf245a | 2020-01-20 14:06:49 +0100 | [diff] [blame] | 317 | -I$(srctree)/tools/lib/ \ |
Alexei Starovoitov | b1ae32db | 2018-05-13 12:32:22 -0700 | [diff] [blame] | 318 | -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \ |
Ilya Leoshkevich | 81f522f | 2019-07-15 11:11:03 +0200 | [diff] [blame] | 319 | -D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \ |
Alexei Starovoitov | 69a9d09 | 2016-12-01 18:31:12 -0800 | [diff] [blame] | 320 | -Wno-gnu-variable-sized-type-not-at-end \ |
| 321 | -Wno-address-of-packed-member -Wno-tautological-compare \ |
Abhijit Ayarekar | 9db9583 | 2017-10-13 12:24:06 -0700 | [diff] [blame] | 322 | -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \ |
Yonghong Song | 6bf3bbe | 2019-01-12 15:04:30 -0800 | [diff] [blame] | 323 | -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \ |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 324 | -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \ |
| 325 | $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \ |
| 326 | $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@ |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 327 | ifeq ($(DWARF2BTF),y) |
| 328 | $(BTF_PAHOLE) -J $@ |
| 329 | endif |