bpf: fix a compilation error when CONFIG_BPF_SYSCALL is not defined
authorYonghong Song <yhs@fb.com>
Tue, 20 Nov 2018 22:08:20 +0000 (14:08 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 20 Nov 2018 23:21:45 +0000 (15:21 -0800)
Kernel test robot (lkp@intel.com) reports a compilation error at
  https://www.spinics.net/lists/netdev/msg534913.html
introduced by commit 838e96904ff3 ("bpf: Introduce bpf_func_info").

If CONFIG_BPF is defined and CONFIG_BPF_SYSCALL is not defined,
the following error will appear:
  kernel/bpf/core.c:414: undefined reference to `btf_type_by_id'
  kernel/bpf/core.c:415: undefined reference to `btf_name_by_offset'

When CONFIG_BPF_SYSCALL is not defined,
let us define stub inline functions for btf_type_by_id()
and btf_name_by_offset() in include/linux/btf.h.
This way, the compilation failure can be avoided.

Fixes: 838e96904ff3 ("bpf: Introduce bpf_func_info")
Reported-by: kbuild test robot <lkp@intel.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/btf.h

index 7f2c0a4a45ea6cd42e18cce86abd60c407798d1c..8c2199b5d250337a7ea8b15efb427c1f3b9b15d0 100644 (file)
@@ -46,7 +46,21 @@ void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
                       struct seq_file *m);
 int btf_get_fd_by_id(u32 id);
 u32 btf_id(const struct btf *btf);
+
+#ifdef CONFIG_BPF_SYSCALL
 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
 const char *btf_name_by_offset(const struct btf *btf, u32 offset);
+#else
+static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
+                                                   u32 type_id)
+{
+       return NULL;
+}
+static inline const char *btf_name_by_offset(const struct btf *btf,
+                                            u32 offset)
+{
+       return NULL;
+}
+#endif
 
 #endif