[PATCH] D67940: [BPF] Preserve and make bitfield access relocatable
Yonghong Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 23 16:19:09 PDT 2019
yonghong-song created this revision.
yonghong-song added reviewers: ast, eli.friedman.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, hiraditya.
Herald added projects: clang, LLVM.
Previous work for BPF CO-RE (compile once, run everywhere)
tries to record structure, union and array accesses
in order to make addresses relocatable. Bitfield is
not handled as you cannot really take an address of
a bitfield.
Internally, for any bitfield access, llvm will generate
a GEP to the first bitfield for a contiguous run of
bitfields, and then perform proper load and bit
manipulation from that address.
In this patch, a clang intrinsic is introduced:
void * __builtin_preserve_bitfield_info(expr, unsigned *buf)
Given a bitfield access, the builtin will return the
address of the first bitfield for the contiguous run
of bitfields. The "buf" will have
. the signness of the bitfield
. the size of bitfield
. the offset within the contiguous run of bitfields
These information will be sufficient for bpf program
to retrieve or assign the bitfield values.
The BPF backend will generate an offset relocation
for the leading bitfield and also record all bitfield
accesses happening in this group. So if structure changed
outside the bitfield group, relocation will handle it.
If the structure changes inside the bitfield group,
the bpf loader may reject the program if it deems previous
bitfield extraction might get the wrong result.
For the case of bitfield access without
__builtin_preserve_bitfield_info() to get an address,
__builtin_preserve_access_index() can be used to enclose
the code. The same offset relocation will be generated.
Please see added tests on how to use the new intrinsic and
what the new offset relocation looks like.
TODO: due to IR intrinsic __builtin_preserve_struct_access_index()
signature change, most existing CORE tests failed. Will fix it later.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67940
Files:
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtin-preserve-bitfield-info-2.c
clang/test/CodeGen/builtin-preserve-bitfield-info.c
llvm/docs/LangRef.rst
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
llvm/lib/Target/BPF/BPFCORE.h
llvm/lib/Target/BPF/BTF.h
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/lib/Target/BPF/BTFDebug.h
llvm/test/CodeGen/BPF/CORE/intrinsic-bitfield.ll
llvm/test/CodeGen/BPF/CORE/intrinsic-struct.ll
llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67940.221430.patch
Type: text/x-patch
Size: 43717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190923/87fcd43e/attachment-0001.bin>
More information about the cfe-commits
mailing list