Now that libbpf is a submodule, we don't need to copy/paste btf.h header with BTF type definitions. This is a first step in migrating parts of libbtf, btf_encoder and btf_loader to use libbpf and starting to use btf__dedup(). Signed-off-by: Andrii Nakryiko <andriin@xxxxxx> --- btf.h | 140 -------------------------------------------------- btf_encoder.c | 2 +- btf_loader.c | 2 +- libbtf.c | 2 +- 4 files changed, 3 insertions(+), 143 deletions(-) delete mode 100644 btf.h diff --git a/btf.h b/btf.h deleted file mode 100644 index d7ca45c..0000000 --- a/btf.h +++ /dev/null @@ -1,140 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -/* Copyright (c) 2018 Facebook */ -#ifndef _UAPI__LINUX_BTF_H__ -#define _UAPI__LINUX_BTF_H__ - -#include <linux/types.h> - -#define BTF_MAGIC 0xeB9F -#define BTF_VERSION 1 - -struct btf_header { - __u16 magic; - __u8 version; - __u8 flags; - __u32 hdr_len; - - /* All offsets are in bytes relative to the end of this header */ - __u32 type_off; /* offset of type section */ - __u32 type_len; /* length of type section */ - __u32 str_off; /* offset of string section */ - __u32 str_len; /* length of string section */ -}; - -/* Max # of type identifier */ -#define BTF_MAX_TYPE 0x0000ffff -/* Max offset into the string section */ -#define BTF_MAX_NAME_OFFSET 0x0000ffff -/* Max # of struct/union/enum members or func args */ -#define BTF_MAX_VLEN 0xffff - -struct btf_type { - __u32 name_off; - /* "info" bits arrangement - * bits 0-15: vlen (e.g. # of struct's members) - * bits 16-23: unused - * bits 24-27: kind (e.g. int, ptr, array...etc) - * bits 28-30: unused - * bit 31: kind_flag, currently used by - * struct, union and fwd - */ - __u32 info; - /* "size" is used by INT, ENUM, STRUCT and UNION. - * "size" tells the size of the type it is describing. - * - * "type" is used by PTR, TYPEDEF, VOLATILE, CONST and RESTRICT. - * "type" is a type_id referring to another type. - */ - union { - __u32 size; - __u32 type; - }; -}; - -#define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f) -#define BTF_INFO_VLEN(info) ((info) & 0xffff) -#define BTF_INFO_KFLAG(info) ((info) >> 31) - -#define BTF_KIND_UNKN 0 /* Unknown */ -#define BTF_KIND_INT 1 /* Integer */ -#define BTF_KIND_PTR 2 /* Pointer */ -#define BTF_KIND_ARRAY 3 /* Array */ -#define BTF_KIND_STRUCT 4 /* Struct */ -#define BTF_KIND_UNION 5 /* Union */ -#define BTF_KIND_ENUM 6 /* Enumeration */ -#define BTF_KIND_FWD 7 /* Forward */ -#define BTF_KIND_TYPEDEF 8 /* Typedef */ -#define BTF_KIND_VOLATILE 9 /* Volatile */ -#define BTF_KIND_CONST 10 /* Const */ -#define BTF_KIND_RESTRICT 11 /* Restrict */ -#define BTF_KIND_FUNC 12 /* Function */ -#define BTF_KIND_FUNC_PROTO 13 /* Function Proto */ -#define BTF_KIND_MAX 13 -#define NR_BTF_KINDS 14 - -/* For some specific BTF_KIND, "struct btf_type" is immediately - * followed by extra data. - */ - -/* BTF_KIND_INT is followed by a u32 and the following - * is the 32 bits arrangement: - */ -#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) -#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) -#define BTF_INT_BITS(VAL) ((VAL) & 0x0000ffff) - -/* Attributes stored in the BTF_INT_ENCODING */ -#define BTF_INT_SIGNED (1 << 0) -#define BTF_INT_CHAR (1 << 1) -#define BTF_INT_BOOL (1 << 2) - -/* BTF_KIND_ENUM is followed by multiple "struct btf_enum". - * The exact number of btf_enum is stored in the vlen (of the - * info in "struct btf_type"). - */ -struct btf_enum { - __u32 name_off; - __s32 val; -}; - -/* BTF_KIND_ARRAY is followed by one "struct btf_array" */ -struct btf_array { - __u32 type; - __u32 index_type; - __u32 nelems; -}; - -/* BTF_KIND_STRUCT and BTF_KIND_UNION are followed - * by multiple "struct btf_member". The exact number - * of btf_member is stored in the vlen (of the info in - * "struct btf_type"). - */ -struct btf_member { - __u32 name_off; - __u32 type; - /* If the type info kind_flag is set, the btf_member offset - * contains both member bitfield size and bit offset. The - * bitfield size is set for bitfield members. If the type - * info kind_flag is not set, the offset contains only bit - * offset. - */ - __u32 offset; -}; - -/* If the struct/union type info kind_flag is set, the - * following two macros are used to access bitfield_size - * and bit_offset from btf_member.offset. - */ -#define BTF_MEMBER_BITFIELD_SIZE(val) ((val) >> 24) -#define BTF_MEMBER_BIT_OFFSET(val) ((val) & 0xffffff) - -/* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param". - * The exact number of btf_param is stored in the vlen (of the - * info in "struct btf_type"). - */ -struct btf_param { - __u32 name_off; - __u32 type; -}; - -#endif /* _UAPI__LINUX_BTF_H__ */ diff --git a/btf_encoder.c b/btf_encoder.c index 7aed9b4..362c9ca 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -11,7 +11,7 @@ #include "dwarves.h" #include "libbtf.h" -#include "btf.h" +#include "lib/bpf/include/uapi/linux/btf.h" #include "hash.h" #include "elf_symtab.h" #include "btf_encoder.h" diff --git a/btf_loader.c b/btf_loader.c index bcf84c9..8583cc8 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -25,7 +25,7 @@ #include <gelf.h> #include "libbtf.h" -#include "btf.h" +#include "lib/bpf/include/uapi/linux/btf.h" #include "dutil.h" #include "dwarves.h" diff --git a/libbtf.c b/libbtf.c index c6ece9d..42da6a3 100644 --- a/libbtf.c +++ b/libbtf.c @@ -16,7 +16,7 @@ #include <stdarg.h> #include "libbtf.h" -#include "btf.h" +#include "lib/bpf/include/uapi/linux/btf.h" #include "dutil.h" #include "gobuffer.h" #include "dwarves.h" -- 2.17.1