[PATCH] D124641: [BPF] Add BTF 64bit enum value support
Yonghong Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 28 15:56:45 PDT 2022
yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added a subscriber: hiraditya.
Herald added a project: All.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 value >> 32 # high-32 bit value
.long (uint32_t)value # lower-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 unsigned and kflag = 0
implies the value is 0. The kernel UAPI enumerator definition is
struct btf_enum {
__u32 name_off;
__s32 val;
};
so kflag = 0 with signed 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 2466250753 # 0x93000001
.long 8
.long 18
.long 4294967295 # 0xffffffff
.long 8 # 0x8
and the enumerator value and signedness are encoded correctly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124641
Files:
llvm/lib/Target/BPF/BTF.def
llvm/lib/Target/BPF/BTF.h
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/lib/Target/BPF/BTFDebug.h
llvm/test/CodeGen/BPF/BTF/struct-enum.ll
llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-enum-value-opaque-pointer.ll
llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-enum-value.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124641.425918.patch
Type: text/x-patch
Size: 9220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220428/89b2c86d/attachment.bin>
More information about the llvm-commits
mailing list