Current BTF only supports 32-bit value. For example,
enum T { VAL = 0xffffFFFF00000008 };
the generated BTF looks like
.long 16 # BTF_KIND_ENUM(id = 4)
.long 100663297 # 0x6000001
.long 8
.long 18
.long 8
The encoded value is 8 which equals to (uint32_t)0xffffFFFF00000008
and this is incorrect.
This patch introduced BTF_KIND_ENUM64 which permits to encode
64-bit value. The format for each enumerator looks like:
.long name_offset
.long (uint32_t)value # lower-32 bit value
.long value >> 32 # high-32 bit value
We use two 32-bit values to represent a 64-bit value as current
BTF type subsection has 4-byte alignment and gaps are not permitted
in the subsection.
This patch also added support for kflag (the bit 31 of CommonType.Info)
such that kflag = 1 implies the value is signed and kflag = 0
implies the value is unsigned. The kernel UAPI enumerator definition is
struct btf_enum {
__u32 name_off;
__s32 val;
};
so kflag = 0 with unsigned value provides backward compatability.
With this patch, for
enum T { VAL = 0xffffFFFF00000008 };
the generated BTF looks like
.long 16 # BTF_KIND_ENUM64(id = 4)
.long 3187671053 # 0x13000001
.long 8
.long 18
.long 8 # 0x8
.long 4294967295 # 0xffffffff
and the enumerator value and signedness are encoded correctly.
Differential Revision: https://reviews.llvm.org/D124641
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
//===- BTF.def - BTF definitions --------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Macros for BTF.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if !defined(HANDLE_BTF_KIND)
|
|
#error "Missing macro definition of HANDLE_BTF_*"
|
|
#endif
|
|
|
|
HANDLE_BTF_KIND(0, UNKN)
|
|
HANDLE_BTF_KIND(1, INT)
|
|
HANDLE_BTF_KIND(2, PTR)
|
|
HANDLE_BTF_KIND(3, ARRAY)
|
|
HANDLE_BTF_KIND(4, STRUCT)
|
|
HANDLE_BTF_KIND(5, UNION)
|
|
HANDLE_BTF_KIND(6, ENUM)
|
|
HANDLE_BTF_KIND(7, FWD)
|
|
HANDLE_BTF_KIND(8, TYPEDEF)
|
|
HANDLE_BTF_KIND(9, VOLATILE)
|
|
HANDLE_BTF_KIND(10, CONST)
|
|
HANDLE_BTF_KIND(11, RESTRICT)
|
|
HANDLE_BTF_KIND(12, FUNC)
|
|
HANDLE_BTF_KIND(13, FUNC_PROTO)
|
|
HANDLE_BTF_KIND(14, VAR)
|
|
HANDLE_BTF_KIND(15, DATASEC)
|
|
HANDLE_BTF_KIND(16, FLOAT)
|
|
HANDLE_BTF_KIND(17, DECL_TAG)
|
|
HANDLE_BTF_KIND(18, TYPE_TAG)
|
|
HANDLE_BTF_KIND(19, ENUM64)
|
|
|
|
#undef HANDLE_BTF_KIND
|