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 | |
Quentin Monnet | 929bef4 | 2021-10-06 12:10:49 +0100 | [diff] [blame] | 6 | pound := \# |
| 7 | |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 8 | # List of programs to build |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 9 | tprogs-y := test_lru_dist |
| 10 | tprogs-y += sock_example |
| 11 | tprogs-y += fds_example |
| 12 | tprogs-y += sockex1 |
| 13 | tprogs-y += sockex2 |
| 14 | tprogs-y += sockex3 |
| 15 | tprogs-y += tracex1 |
| 16 | tprogs-y += tracex2 |
| 17 | tprogs-y += tracex3 |
| 18 | tprogs-y += tracex4 |
| 19 | tprogs-y += tracex5 |
| 20 | tprogs-y += tracex6 |
| 21 | tprogs-y += tracex7 |
| 22 | tprogs-y += test_probe_write_user |
| 23 | tprogs-y += trace_output |
| 24 | tprogs-y += lathist |
| 25 | tprogs-y += offwaketime |
| 26 | tprogs-y += spintest |
| 27 | tprogs-y += map_perf_test |
| 28 | tprogs-y += test_overhead |
| 29 | tprogs-y += test_cgrp2_array_pin |
| 30 | tprogs-y += test_cgrp2_attach |
| 31 | tprogs-y += test_cgrp2_sock |
| 32 | tprogs-y += test_cgrp2_sock2 |
| 33 | tprogs-y += xdp1 |
| 34 | tprogs-y += xdp2 |
| 35 | tprogs-y += xdp_router_ipv4 |
| 36 | tprogs-y += test_current_task_under_cgroup |
| 37 | tprogs-y += trace_event |
| 38 | tprogs-y += sampleip |
| 39 | tprogs-y += tc_l2_redirect |
| 40 | tprogs-y += lwt_len_hist |
| 41 | tprogs-y += xdp_tx_iptunnel |
| 42 | tprogs-y += test_map_in_map |
Prashant Bhole | 5984dc6 | 2019-12-16 16:16:19 +0900 | [diff] [blame] | 43 | tprogs-y += per_socket_stats_example |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 44 | tprogs-y += xdp_rxq_info |
| 45 | tprogs-y += syscall_tp |
| 46 | tprogs-y += cpustat |
| 47 | tprogs-y += xdp_adjust_tail |
| 48 | tprogs-y += xdpsock |
Mariusz Dudek | 3627d97 | 2020-12-03 10:05:46 +0100 | [diff] [blame] | 49 | tprogs-y += xdpsock_ctrl_proc |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 50 | tprogs-y += xsk_fwd |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 51 | tprogs-y += xdp_fwd |
| 52 | tprogs-y += task_fd_query |
| 53 | tprogs-y += xdp_sample_pkts |
| 54 | tprogs-y += ibumad |
| 55 | tprogs-y += hbm |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 56 | |
Kumar Kartikeya Dwivedi | e531a22 | 2021-08-21 05:50:06 +0530 | [diff] [blame] | 57 | tprogs-y += xdp_redirect_cpu |
Kumar Kartikeya Dwivedi | 594a116 | 2021-08-21 05:50:10 +0530 | [diff] [blame] | 58 | tprogs-y += xdp_redirect_map_multi |
Kumar Kartikeya Dwivedi | bbe6586 | 2021-08-21 05:50:08 +0530 | [diff] [blame] | 59 | tprogs-y += xdp_redirect_map |
Kumar Kartikeya Dwivedi | b926c55 | 2021-08-21 05:50:04 +0530 | [diff] [blame] | 60 | tprogs-y += xdp_redirect |
Kumar Kartikeya Dwivedi | 6e1051a | 2021-08-21 05:50:02 +0530 | [diff] [blame] | 61 | tprogs-y += xdp_monitor |
| 62 | |
Joe Stringer | 43371c8 | 2016-12-14 14:43:39 -0800 | [diff] [blame] | 63 | # Libbpf dependencies |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 64 | LIBBPF_SRC = $(TOOLS_PATH)/lib/bpf |
| 65 | LIBBPF_OUTPUT = $(abspath $(BPF_SAMPLES_PATH))/libbpf |
| 66 | LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) |
| 67 | LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include |
| 68 | LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 69 | |
Roman Gushchin | 9d1f159 | 2017-11-05 08:15:33 -0500 | [diff] [blame] | 70 | CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o |
Yonghong Song | 28dbf86 | 2018-04-28 22:28:13 -0700 | [diff] [blame] | 71 | TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o |
Kumar Kartikeya Dwivedi | 6e1051a | 2021-08-21 05:50:02 +0530 | [diff] [blame] | 72 | XDP_SAMPLE := xdp_sample_user.o |
Joe Stringer | 43371c8 | 2016-12-14 14:43:39 -0800 | [diff] [blame] | 73 | |
Jakub Kicinski | 1a9b268 | 2019-02-27 19:04:13 -0800 | [diff] [blame] | 74 | fds_example-objs := fds_example.o |
| 75 | sockex1-objs := sockex1_user.o |
| 76 | sockex2-objs := sockex2_user.o |
Daniel T. Lee | bc1a859 | 2020-05-16 13:06:06 +0900 | [diff] [blame] | 77 | sockex3-objs := sockex3_user.o |
Daniel T. Lee | 63841bc | 2020-05-16 13:06:05 +0900 | [diff] [blame] | 78 | tracex1-objs := tracex1_user.o $(TRACE_HELPERS) |
| 79 | tracex2-objs := tracex2_user.o |
| 80 | tracex3-objs := tracex3_user.o |
| 81 | tracex4-objs := tracex4_user.o |
Daniel T. Lee | bc1a859 | 2020-05-16 13:06:06 +0900 | [diff] [blame] | 82 | tracex5-objs := tracex5_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 63841bc | 2020-05-16 13:06:05 +0900 | [diff] [blame] | 83 | tracex6-objs := tracex6_user.o |
| 84 | tracex7-objs := tracex7_user.o |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 85 | test_probe_write_user-objs := test_probe_write_user_user.o |
Daniel T. Lee | ceb5dea | 2020-11-24 09:03:10 +0000 | [diff] [blame] | 86 | trace_output-objs := trace_output_user.o |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 87 | lathist-objs := lathist_user.o |
Daniel T. Lee | f0c328f | 2020-08-23 17:53:34 +0900 | [diff] [blame] | 88 | offwaketime-objs := offwaketime_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 89 | spintest-objs := spintest_user.o $(TRACE_HELPERS) |
Daniel T. Lee | 35a8b6d | 2020-08-23 17:53:32 +0900 | [diff] [blame] | 90 | map_perf_test-objs := map_perf_test_user.o |
Daniel T. Lee | c6497df | 2020-11-24 09:03:08 +0000 | [diff] [blame] | 91 | test_overhead-objs := test_overhead_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 92 | test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o |
| 93 | test_cgrp2_attach-objs := test_cgrp2_attach.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 94 | test_cgrp2_sock-objs := test_cgrp2_sock.o |
Daniel T. Lee | d89af13 | 2020-11-24 09:03:05 +0000 | [diff] [blame] | 95 | test_cgrp2_sock2-objs := test_cgrp2_sock2.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 96 | xdp1-objs := xdp1_user.o |
Brenden Blanco | 764cbcce | 2016-07-19 12:16:57 -0700 | [diff] [blame] | 97 | # reuse xdp1 source intentionally |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 98 | xdp2-objs := xdp1_user.o |
Maciej Fijalkowski | bbaf602 | 2019-02-01 22:42:25 +0100 | [diff] [blame] | 99 | xdp_router_ipv4-objs := xdp_router_ipv4_user.o |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 100 | test_current_task_under_cgroup-objs := $(CGROUP_HELPERS) \ |
Sargun Dhillon | 9e6e60e | 2016-08-12 08:57:04 -0700 | [diff] [blame] | 101 | test_current_task_under_cgroup_user.o |
Daniel T. Lee | aa5e2af | 2020-03-21 19:04:24 +0900 | [diff] [blame] | 102 | trace_event-objs := trace_event_user.o $(TRACE_HELPERS) |
| 103 | sampleip-objs := sampleip_user.o $(TRACE_HELPERS) |
Daniel T. Lee | ceb5dea | 2020-11-24 09:03:10 +0000 | [diff] [blame] | 104 | tc_l2_redirect-objs := tc_l2_redirect_user.o |
| 105 | lwt_len_hist-objs := lwt_len_hist_user.o |
Maciej Fijalkowski | bbaf602 | 2019-02-01 22:42:25 +0100 | [diff] [blame] | 106 | xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o |
Daniel T. Lee | 88795b4 | 2020-07-08 03:48:53 +0900 | [diff] [blame] | 107 | test_map_in_map-objs := test_map_in_map_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 108 | per_socket_stats_example-objs := cookie_uid_helper_example.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 109 | xdp_rxq_info-objs := xdp_rxq_info_user.o |
Daniel T. Lee | f0c328f | 2020-08-23 17:53:34 +0900 | [diff] [blame] | 110 | syscall_tp-objs := syscall_tp_user.o |
| 111 | cpustat-objs := cpustat_user.o |
Jakub Kicinski | 0cc54db | 2018-05-14 22:35:05 -0700 | [diff] [blame] | 112 | xdp_adjust_tail-objs := xdp_adjust_tail_user.o |
Jakub Kicinski | 6748182 | 2018-07-26 14:32:21 -0700 | [diff] [blame] | 113 | xdpsock-objs := xdpsock_user.o |
Mariusz Dudek | 3627d97 | 2020-12-03 10:05:46 +0100 | [diff] [blame] | 114 | xdpsock_ctrl_proc-objs := xdpsock_ctrl_proc.o |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 115 | xsk_fwd-objs := xsk_fwd.o |
Jakub Kicinski | e1a40ef | 2018-07-26 14:32:20 -0700 | [diff] [blame] | 116 | xdp_fwd-objs := xdp_fwd_user.o |
Daniel T. Lee | 4fe6641 | 2020-11-24 09:03:06 +0000 | [diff] [blame] | 117 | task_fd_query-objs := task_fd_query_user.o $(TRACE_HELPERS) |
Daniel T. Lee | ceb5dea | 2020-11-24 09:03:10 +0000 | [diff] [blame] | 118 | xdp_sample_pkts-objs := xdp_sample_pkts_user.o |
Daniel T. Lee | 763af20 | 2020-11-24 09:03:07 +0000 | [diff] [blame] | 119 | ibumad-objs := ibumad_user.o |
Daniel T. Lee | c5815ac | 2020-11-24 09:03:04 +0000 | [diff] [blame] | 120 | hbm-objs := hbm.o $(CGROUP_HELPERS) |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 121 | |
Kumar Kartikeya Dwivedi | 594a116 | 2021-08-21 05:50:10 +0530 | [diff] [blame] | 122 | xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o $(XDP_SAMPLE) |
Kumar Kartikeya Dwivedi | e531a22 | 2021-08-21 05:50:06 +0530 | [diff] [blame] | 123 | xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE) |
Kumar Kartikeya Dwivedi | bbe6586 | 2021-08-21 05:50:08 +0530 | [diff] [blame] | 124 | xdp_redirect_map-objs := xdp_redirect_map_user.o $(XDP_SAMPLE) |
Kumar Kartikeya Dwivedi | b926c55 | 2021-08-21 05:50:04 +0530 | [diff] [blame] | 125 | xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE) |
Kumar Kartikeya Dwivedi | 6e1051a | 2021-08-21 05:50:02 +0530 | [diff] [blame] | 126 | xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE) |
| 127 | |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 128 | # Tell kbuild to always build the programs |
Masahiro Yamada | 5f2fb52 | 2020-02-02 01:49:24 +0900 | [diff] [blame] | 129 | always-y := $(tprogs-y) |
| 130 | always-y += sockex1_kern.o |
| 131 | always-y += sockex2_kern.o |
| 132 | always-y += sockex3_kern.o |
| 133 | always-y += tracex1_kern.o |
| 134 | always-y += tracex2_kern.o |
| 135 | always-y += tracex3_kern.o |
| 136 | always-y += tracex4_kern.o |
| 137 | always-y += tracex5_kern.o |
| 138 | always-y += tracex6_kern.o |
| 139 | always-y += tracex7_kern.o |
| 140 | always-y += sock_flags_kern.o |
| 141 | always-y += test_probe_write_user_kern.o |
| 142 | always-y += trace_output_kern.o |
| 143 | always-y += tcbpf1_kern.o |
| 144 | always-y += tc_l2_redirect_kern.o |
| 145 | always-y += lathist_kern.o |
| 146 | always-y += offwaketime_kern.o |
| 147 | always-y += spintest_kern.o |
| 148 | always-y += map_perf_test_kern.o |
| 149 | always-y += test_overhead_tp_kern.o |
| 150 | always-y += test_overhead_raw_tp_kern.o |
| 151 | always-y += test_overhead_kprobe_kern.o |
| 152 | always-y += parse_varlen.o parse_simple.o parse_ldabs.o |
| 153 | always-y += test_cgrp2_tc_kern.o |
| 154 | always-y += xdp1_kern.o |
| 155 | always-y += xdp2_kern.o |
| 156 | always-y += xdp_router_ipv4_kern.o |
| 157 | always-y += test_current_task_under_cgroup_kern.o |
| 158 | always-y += trace_event_kern.o |
| 159 | always-y += sampleip_kern.o |
| 160 | always-y += lwt_len_hist_kern.o |
| 161 | always-y += xdp_tx_iptunnel_kern.o |
| 162 | always-y += test_map_in_map_kern.o |
| 163 | always-y += tcp_synrto_kern.o |
| 164 | always-y += tcp_rwnd_kern.o |
| 165 | always-y += tcp_bufs_kern.o |
| 166 | always-y += tcp_cong_kern.o |
| 167 | always-y += tcp_iw_kern.o |
| 168 | always-y += tcp_clamp_kern.o |
| 169 | always-y += tcp_basertt_kern.o |
| 170 | always-y += tcp_tos_reflect_kern.o |
| 171 | always-y += tcp_dumpstats_kern.o |
Masahiro Yamada | 5f2fb52 | 2020-02-02 01:49:24 +0900 | [diff] [blame] | 172 | always-y += xdp_rxq_info_kern.o |
| 173 | always-y += xdp2skb_meta_kern.o |
| 174 | always-y += syscall_tp_kern.o |
| 175 | always-y += cpustat_kern.o |
| 176 | always-y += xdp_adjust_tail_kern.o |
| 177 | always-y += xdp_fwd_kern.o |
| 178 | always-y += task_fd_query_kern.o |
| 179 | always-y += xdp_sample_pkts_kern.o |
| 180 | always-y += ibumad_kern.o |
| 181 | always-y += hbm_out_kern.o |
| 182 | always-y += hbm_edt_kern.o |
| 183 | always-y += xdpsock_kern.o |
Alexei Starovoitov | 3c731eb | 2014-09-26 00:17:07 -0700 | [diff] [blame] | 184 | |
Ivan Khoronzhuk | 0e865ae | 2019-10-11 03:27:58 +0300 | [diff] [blame] | 185 | ifeq ($(ARCH), arm) |
| 186 | # Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux |
| 187 | # headers when arm instruction set identification is requested. |
| 188 | ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS)) |
| 189 | BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR) |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 190 | TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR) |
Ivan Khoronzhuk | 0e865ae | 2019-10-11 03:27:58 +0300 | [diff] [blame] | 191 | endif |
| 192 | |
Tiezhu Yang | 190d1c9 | 2021-01-25 13:05:46 +0800 | [diff] [blame] | 193 | ifeq ($(ARCH), mips) |
| 194 | TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__ |
Tiezhu Yang | 058107a | 2021-01-26 22:05:25 +0800 | [diff] [blame] | 195 | ifdef CONFIG_MACH_LOONGSON64 |
| 196 | BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-loongson64 |
| 197 | BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-generic |
| 198 | endif |
Tiezhu Yang | 190d1c9 | 2021-01-25 13:05:46 +0800 | [diff] [blame] | 199 | endif |
| 200 | |
Ivan Khoronzhuk | 10cb3d8 | 2019-10-11 03:28:02 +0300 | [diff] [blame] | 201 | TPROGS_CFLAGS += -Wall -O2 |
| 202 | TPROGS_CFLAGS += -Wmissing-prototypes |
| 203 | TPROGS_CFLAGS += -Wstrict-prototypes |
| 204 | |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 205 | TPROGS_CFLAGS += -I$(objtree)/usr/include |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 206 | TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/ |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 207 | TPROGS_CFLAGS += -I$(LIBBPF_INCLUDE) |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 208 | TPROGS_CFLAGS += -I$(srctree)/tools/include |
| 209 | TPROGS_CFLAGS += -I$(srctree)/tools/perf |
David S. Miller | 14684b9 | 2019-11-09 11:04:37 -0800 | [diff] [blame] | 210 | TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0 |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 211 | |
Ivan Khoronzhuk | b2327c1 | 2019-10-11 03:28:07 +0300 | [diff] [blame] | 212 | ifdef SYSROOT |
| 213 | TPROGS_CFLAGS += --sysroot=$(SYSROOT) |
| 214 | TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib |
| 215 | endif |
| 216 | |
Toke Høiland-Jørgensen | 5615ed4 | 2019-12-16 11:24:05 +0100 | [diff] [blame] | 217 | TPROGS_LDLIBS += $(LIBBPF) -lelf -lz |
Alexander Lobakin | e64fbca | 2021-12-03 20:50:03 +0100 | [diff] [blame] | 218 | TPROGLDLIBS_xdp_monitor += -lm |
| 219 | TPROGLDLIBS_xdp_redirect += -lm |
| 220 | TPROGLDLIBS_xdp_redirect_cpu += -lm |
| 221 | TPROGLDLIBS_xdp_redirect_map += -lm |
| 222 | TPROGLDLIBS_xdp_redirect_map_multi += -lm |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 223 | TPROGLDLIBS_tracex4 += -lrt |
| 224 | TPROGLDLIBS_trace_output += -lrt |
| 225 | TPROGLDLIBS_map_perf_test += -lrt |
| 226 | TPROGLDLIBS_test_overhead += -lrt |
Mariusz Dudek | 3627d97 | 2020-12-03 10:05:46 +0100 | [diff] [blame] | 227 | TPROGLDLIBS_xdpsock += -pthread -lcap |
Cristian Dumitrescu | 35149b2 | 2020-08-28 10:26:28 +0200 | [diff] [blame] | 228 | TPROGLDLIBS_xsk_fwd += -pthread |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 229 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 230 | # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: |
Tiezhu Yang | 628add7 | 2021-01-22 09:39:44 +0800 | [diff] [blame] | 231 | # make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang |
Jesper Dangaard Brouer | 6ccfba7 | 2016-04-28 14:20:53 +0200 | [diff] [blame] | 232 | LLC ?= llc |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 233 | CLANG ?= clang |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 234 | OPT ?= opt |
| 235 | LLVM_DIS ?= llvm-dis |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 236 | LLVM_OBJCOPY ?= llvm-objcopy |
Pu Lehui | 44ce0ac | 2021-10-21 20:39:13 +0800 | [diff] [blame] | 237 | LLVM_READELF ?= llvm-readelf |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 238 | BTF_PAHOLE ?= pahole |
Jesper Dangaard Brouer | 6ccfba7 | 2016-04-28 14:20:53 +0200 | [diff] [blame] | 239 | |
Joel Fernandes | 876e88e | 2017-09-20 09:11:57 -0700 | [diff] [blame] | 240 | # Detect that we're cross compiling and use the cross compiler |
| 241 | ifdef CROSS_COMPILE |
Ivan Khoronzhuk | 518c134 | 2019-10-11 03:27:56 +0300 | [diff] [blame] | 242 | CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%)) |
Joel Fernandes | 876e88e | 2017-09-20 09:11:57 -0700 | [diff] [blame] | 243 | endif |
| 244 | |
Jakub Kicinski | 0ed3cc4 | 2019-06-07 10:11:16 -0700 | [diff] [blame] | 245 | # Don't evaluate probes and warnings if we need to run make recursively |
| 246 | ifneq ($(src),) |
Quentin Monnet | 929bef4 | 2021-10-06 12:10:49 +0100 | [diff] [blame] | 247 | HDR_PROBE := $(shell printf "$(pound)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] | 248 | $(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \ |
| 249 | -o /dev/null 2>/dev/null && echo okay) |
Jakub Kicinski | 07c3bbd | 2019-06-05 16:47:22 -0700 | [diff] [blame] | 250 | |
| 251 | ifeq ($(HDR_PROBE),) |
| 252 | $(warning WARNING: Detected possible issues with include path.) |
| 253 | $(warning WARNING: Please install kernel headers locally (make headers_install).) |
| 254 | endif |
| 255 | |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 256 | BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) |
| 257 | BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) |
| 258 | 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] | 259 | BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ |
| 260 | $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ |
Pu Lehui | 44ce0ac | 2021-10-21 20:39:13 +0800 | [diff] [blame] | 261 | $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \ |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 262 | /bin/rm -f ./llvm_btf_verify.o) |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 263 | |
Toke Høiland-Jørgensen | 4502789 | 2019-12-16 11:38:19 +0100 | [diff] [blame] | 264 | BPF_EXTRA_CFLAGS += -fno-stack-protector |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 265 | ifneq ($(BTF_LLVM_PROBE),) |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 266 | BPF_EXTRA_CFLAGS += -g |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 267 | else |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 268 | ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),) |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 269 | BPF_EXTRA_CFLAGS += -g |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 270 | LLC_FLAGS += -mattr=dwarfris |
| 271 | DWARF2BTF = y |
| 272 | endif |
Yonghong Song | 9ce6ae2 | 2018-11-19 15:29:17 -0800 | [diff] [blame] | 273 | endif |
Jakub Kicinski | 0ed3cc4 | 2019-06-07 10:11:16 -0700 | [diff] [blame] | 274 | endif |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 275 | |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 276 | # Trick to allow make to be run from this directory |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 277 | all: |
Jesper Dangaard Brouer | 6cc2c87 | 2019-11-10 17:31:16 +0100 | [diff] [blame] | 278 | $(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR) |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 279 | |
| 280 | clean: |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 281 | $(MAKE) -C ../../ M=$(CURDIR) clean |
Toke Høiland-Jørgensen | b2e5e93 | 2020-01-20 14:06:41 +0100 | [diff] [blame] | 282 | @find $(CURDIR) -type f -name '*~' -delete |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 283 | @$(RM) -r $(CURDIR)/libbpf $(CURDIR)/bpftool |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 284 | |
Quentin Monnet | a60d24e | 2021-10-07 20:44:36 +0100 | [diff] [blame] | 285 | $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUTPUT) |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 286 | # Fix up variables inherited from Kbuild that tools/ build system won't like |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 287 | $(MAKE) -C $(LIBBPF_SRC) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \ |
| 288 | LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ \ |
| 289 | O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ |
| 290 | $@ install_headers |
Mickaël Salaün | c25ef6a | 2018-01-26 01:39:30 +0100 | [diff] [blame] | 291 | |
Kumar Kartikeya Dwivedi | 384b6b3 | 2021-08-21 05:50:00 +0530 | [diff] [blame] | 292 | BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 293 | BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool |
| 294 | BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool |
| 295 | $(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT) |
| 296 | $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \ |
| 297 | OUTPUT=$(BPFTOOL_OUTPUT)/ \ |
| 298 | LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \ |
| 299 | LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/ |
| 300 | |
| 301 | $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT): |
| 302 | $(call msg,MKDIR,$@) |
| 303 | $(Q)mkdir -p $@ |
Kumar Kartikeya Dwivedi | 384b6b3 | 2021-08-21 05:50:00 +0530 | [diff] [blame] | 304 | |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 305 | $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE |
| 306 | $(call filechk,offsets,__SYSCALL_NRS_H__) |
| 307 | |
Masahiro Yamada | 2c667d7 | 2018-12-22 18:50:34 +0900 | [diff] [blame] | 308 | targets += syscall_nrs.s |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 309 | clean-files += syscall_nrs.h |
| 310 | |
| 311 | FORCE: |
| 312 | |
| 313 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 314 | # Verify LLVM compiler tools are available and bpf target is supported by llc |
| 315 | .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 316 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 317 | verify_cmds: $(CLANG) $(LLC) |
| 318 | @for TOOL in $^ ; do \ |
| 319 | if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \ |
| 320 | echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\ |
| 321 | exit 1; \ |
| 322 | else true; fi; \ |
| 323 | done |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 324 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 325 | verify_target_bpf: verify_cmds |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 326 | @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ |
| 327 | echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ |
| 328 | echo " NOTICE: LLVM version >= 3.7.1 required" ;\ |
| 329 | exit 2; \ |
| 330 | else true; fi |
| 331 | |
Jakub Kicinski | 787360f | 2018-05-14 22:35:04 -0700 | [diff] [blame] | 332 | $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) |
| 333 | $(src)/*.c: verify_target_bpf $(LIBBPF) |
Jesper Dangaard Brouer | 7b01dd5 | 2016-04-28 14:20:58 +0200 | [diff] [blame] | 334 | |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 335 | libbpf_hdrs: $(LIBBPF) |
Andrii Nakryiko | 527024f | 2021-12-01 15:28:22 -0800 | [diff] [blame] | 336 | $(obj)/$(TRACE_HELPERS) $(obj)/$(CGROUP_HELPERS) $(obj)/$(XDP_SAMPLE): | libbpf_hdrs |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 337 | |
| 338 | .PHONY: libbpf_hdrs |
| 339 | |
Kumar Kartikeya Dwivedi | e531a22 | 2021-08-21 05:50:06 +0530 | [diff] [blame] | 340 | $(obj)/xdp_redirect_cpu_user.o: $(obj)/xdp_redirect_cpu.skel.h |
Kumar Kartikeya Dwivedi | 594a116 | 2021-08-21 05:50:10 +0530 | [diff] [blame] | 341 | $(obj)/xdp_redirect_map_multi_user.o: $(obj)/xdp_redirect_map_multi.skel.h |
Kumar Kartikeya Dwivedi | bbe6586 | 2021-08-21 05:50:08 +0530 | [diff] [blame] | 342 | $(obj)/xdp_redirect_map_user.o: $(obj)/xdp_redirect_map.skel.h |
Kumar Kartikeya Dwivedi | b926c55 | 2021-08-21 05:50:04 +0530 | [diff] [blame] | 343 | $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h |
Kumar Kartikeya Dwivedi | 6e1051a | 2021-08-21 05:50:02 +0530 | [diff] [blame] | 344 | $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h |
| 345 | |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 346 | $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h |
brakmo | 187d073 | 2019-03-01 12:38:48 -0800 | [diff] [blame] | 347 | $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h |
brakmo | a1270fe | 2019-03-01 12:38:49 -0800 | [diff] [blame] | 348 | $(obj)/hbm.o: $(src)/hbm.h |
brakmo | 71634d7 | 2019-07-02 15:09:52 -0700 | [diff] [blame] | 349 | $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h |
David Daney | 4b7190e | 2017-06-13 16:49:38 -0700 | [diff] [blame] | 350 | |
Andrii Nakryiko | 527024f | 2021-12-01 15:28:22 -0800 | [diff] [blame] | 351 | # Override includes for xdp_sample_user.o because $(srctree)/usr/include in |
| 352 | # TPROGS_CFLAGS causes conflicts |
Alexander Lobakin | e64fbca | 2021-12-03 20:50:03 +0100 | [diff] [blame] | 353 | XDP_SAMPLE_CFLAGS += -Wall -O2 \ |
Andrii Nakryiko | 527024f | 2021-12-01 15:28:22 -0800 | [diff] [blame] | 354 | -I$(src)/../../tools/include \ |
| 355 | -I$(src)/../../tools/include/uapi \ |
| 356 | -I$(LIBBPF_INCLUDE) \ |
| 357 | -I$(src)/../../tools/testing/selftests/bpf |
| 358 | |
| 359 | $(obj)/$(XDP_SAMPLE): TPROGS_CFLAGS = $(XDP_SAMPLE_CFLAGS) |
| 360 | $(obj)/$(XDP_SAMPLE): $(src)/xdp_sample_user.h $(src)/xdp_sample_shared.h |
| 361 | |
Ivan Khoronzhuk | 1d97c6c | 2019-10-11 03:28:01 +0300 | [diff] [blame] | 362 | -include $(BPF_SAMPLES_PATH)/Makefile.target |
| 363 | |
Kumar Kartikeya Dwivedi | 571fa24 | 2021-09-28 11:16:08 +0530 | [diff] [blame] | 364 | VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux)) \ |
| 365 | $(abspath $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)) \ |
| 366 | $(abspath ./vmlinux) |
Kumar Kartikeya Dwivedi | 384b6b3 | 2021-08-21 05:50:00 +0530 | [diff] [blame] | 367 | VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) |
| 368 | |
Kumar Kartikeya Dwivedi | 384b6b3 | 2021-08-21 05:50:00 +0530 | [diff] [blame] | 369 | $(obj)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) |
| 370 | ifeq ($(VMLINUX_H),) |
| 371 | $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ |
| 372 | else |
| 373 | $(Q)cp "$(VMLINUX_H)" $@ |
| 374 | endif |
| 375 | |
Kumar Kartikeya Dwivedi | 571fa24 | 2021-09-28 11:16:08 +0530 | [diff] [blame] | 376 | ifeq ($(VMLINUX_BTF),) |
| 377 | $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)",\ |
| 378 | build the kernel or set VMLINUX_BTF variable) |
| 379 | endif |
| 380 | |
Kumar Kartikeya Dwivedi | 384b6b3 | 2021-08-21 05:50:00 +0530 | [diff] [blame] | 381 | clean-files += vmlinux.h |
| 382 | |
Kumar Kartikeya Dwivedi | 3f19956 | 2021-08-21 05:50:01 +0530 | [diff] [blame] | 383 | # Get Clang's default includes on this system, as opposed to those seen by |
| 384 | # '-target bpf'. This fixes "missing" files on some architectures/distros, |
| 385 | # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. |
| 386 | # |
| 387 | # Use '-idirafter': Don't interfere with include mechanics except where the |
| 388 | # build would have failed anyways. |
| 389 | define get_sys_includes |
| 390 | $(shell $(1) -v -E - </dev/null 2>&1 \ |
| 391 | | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ |
| 392 | $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/') |
| 393 | endef |
| 394 | |
| 395 | CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) |
| 396 | |
Kumar Kartikeya Dwivedi | 79ccf45 | 2021-08-21 05:50:05 +0530 | [diff] [blame] | 397 | $(obj)/xdp_redirect_cpu.bpf.o: $(obj)/xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | a29b3ca | 2021-08-21 05:50:09 +0530 | [diff] [blame] | 398 | $(obj)/xdp_redirect_map_multi.bpf.o: $(obj)/xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 54af769 | 2021-08-21 05:50:07 +0530 | [diff] [blame] | 399 | $(obj)/xdp_redirect_map.bpf.o: $(obj)/xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 66fc4ca | 2021-08-21 05:50:03 +0530 | [diff] [blame] | 400 | $(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 3f19956 | 2021-08-21 05:50:01 +0530 | [diff] [blame] | 401 | $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o |
| 402 | |
| 403 | $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h |
| 404 | @echo " CLANG-BPF " $@ |
| 405 | $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \ |
| 406 | -Wno-compare-distinct-pointer-types -I$(srctree)/include \ |
| 407 | -I$(srctree)/samples/bpf -I$(srctree)/tools/include \ |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 408 | -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \ |
Kumar Kartikeya Dwivedi | 3f19956 | 2021-08-21 05:50:01 +0530 | [diff] [blame] | 409 | -c $(filter %.bpf.c,$^) -o $@ |
| 410 | |
Kumar Kartikeya Dwivedi | a29b3ca | 2021-08-21 05:50:09 +0530 | [diff] [blame] | 411 | LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map_multi.skel.h \ |
| 412 | xdp_redirect_map.skel.h xdp_redirect.skel.h xdp_monitor.skel.h |
Kumar Kartikeya Dwivedi | 3f19956 | 2021-08-21 05:50:01 +0530 | [diff] [blame] | 413 | clean-files += $(LINKED_SKELS) |
| 414 | |
Kumar Kartikeya Dwivedi | 79ccf45 | 2021-08-21 05:50:05 +0530 | [diff] [blame] | 415 | xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | a29b3ca | 2021-08-21 05:50:09 +0530 | [diff] [blame] | 416 | xdp_redirect_map_multi.skel.h-deps := xdp_redirect_map_multi.bpf.o xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 54af769 | 2021-08-21 05:50:07 +0530 | [diff] [blame] | 417 | xdp_redirect_map.skel.h-deps := xdp_redirect_map.bpf.o xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 66fc4ca | 2021-08-21 05:50:03 +0530 | [diff] [blame] | 418 | xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o |
Kumar Kartikeya Dwivedi | 3f19956 | 2021-08-21 05:50:01 +0530 | [diff] [blame] | 419 | xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o |
| 420 | |
| 421 | LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps))) |
| 422 | |
| 423 | BPF_SRCS_LINKED := $(notdir $(wildcard $(src)/*.bpf.c)) |
| 424 | BPF_OBJS_LINKED := $(patsubst %.bpf.c,$(obj)/%.bpf.o, $(BPF_SRCS_LINKED)) |
| 425 | BPF_SKELS_LINKED := $(addprefix $(obj)/,$(LINKED_SKELS)) |
| 426 | |
| 427 | $(BPF_SKELS_LINKED): $(BPF_OBJS_LINKED) $(BPFTOOL) |
| 428 | @echo " BPF GEN-OBJ " $(@:.skel.h=) |
| 429 | $(Q)$(BPFTOOL) gen object $(@:.skel.h=.lbpf.o) $(addprefix $(obj)/,$($(@F)-deps)) |
| 430 | @echo " BPF GEN-SKEL" $(@:.skel.h=) |
| 431 | $(Q)$(BPFTOOL) gen skeleton $(@:.skel.h=.lbpf.o) name $(notdir $(@:.skel.h=)) > $@ |
| 432 | |
Naveen N. Rao | 128d151 | 2016-04-04 22:31:33 +0530 | [diff] [blame] | 433 | # asm/sysreg.h - inline assembly used by it is incompatible with llvm. |
| 434 | # 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] | 435 | # useless for BPF samples. |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 436 | # below we use long chain of commands, clang | opt | llvm-dis | llc, |
| 437 | # to generate final object file. 'clang' compiles the source into IR |
| 438 | # with native target, e.g., x64, arm64, etc. 'opt' does bpf CORE IR builtin |
| 439 | # processing (llvm12) and IR optimizations. 'llvm-dis' converts |
| 440 | # 'opt' output to IR, and finally 'llc' generates bpf byte code. |
Brenden Blanco | b88c06e | 2015-05-11 21:25:51 -0700 | [diff] [blame] | 441 | $(obj)/%.o: $(src)/%.c |
Jakub Kicinski | 768759e | 2018-05-14 22:35:06 -0700 | [diff] [blame] | 442 | @echo " CLANG-bpf " $@ |
Ivan Khoronzhuk | 2a560df | 2019-10-11 03:27:57 +0300 | [diff] [blame] | 443 | $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \ |
| 444 | -I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \ |
Quentin Monnet | 3f7a331 | 2021-10-07 20:44:35 +0100 | [diff] [blame] | 445 | -I$(LIBBPF_INCLUDE) \ |
Alexei Starovoitov | b1ae32d | 2018-05-13 12:32:22 -0700 | [diff] [blame] | 446 | -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \ |
Ilya Leoshkevich | 81f522f | 2019-07-15 11:11:03 +0200 | [diff] [blame] | 447 | -D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \ |
Alexei Starovoitov | 69a9d09 | 2016-12-01 18:31:12 -0800 | [diff] [blame] | 448 | -Wno-gnu-variable-sized-type-not-at-end \ |
| 449 | -Wno-address-of-packed-member -Wno-tautological-compare \ |
Abhijit Ayarekar | 9db9583 | 2017-10-13 12:24:06 -0700 | [diff] [blame] | 450 | -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \ |
Toke Høiland-Jørgensen | 5a0ae98 | 2021-07-05 12:38:41 +0200 | [diff] [blame] | 451 | -fno-asynchronous-unwind-tables \ |
Yonghong Song | 6bf3bbe | 2019-01-12 15:04:30 -0800 | [diff] [blame] | 452 | -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \ |
Yonghong Song | 9618bde | 2020-10-05 21:34:26 -0700 | [diff] [blame] | 453 | -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \ |
| 454 | $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \ |
| 455 | $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@ |
Taeung Song | 9778cfd | 2018-07-26 19:13:44 +0900 | [diff] [blame] | 456 | ifeq ($(DWARF2BTF),y) |
| 457 | $(BTF_PAHOLE) -J $@ |
| 458 | endif |