[PATCH] D110116: [Clang] Ignore BTFTag attr if used as a type attribute
Yonghong Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 20 17:03:46 PDT 2021
yonghong-song created this revision.
yonghong-song added a reviewer: aaron.ballman.
yonghong-song requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Currently, linux kernel has a __user attribute ([1]) defined as
__attribute__((noderef, address_space(__user)))
which is used by sparse tool ([2]) to do some
type checking of pointers to user space memory.
During normal compilation, __user will be defined
to nothing so it won't have an impact on compilation.
The btf_tag attribute, which is motivated by
carrying linux kernel annotations into dwarf/BTF,
is introduced in [3]. We intended to define __user as
__attribute__((btf_tag("user")))
so such information will be encoded in dwarf/BTF
and can be used later by bpf verification or other
tracing tools.
But linux kernel __user attribute is also used during
type conversion which btf_tag doesn't support ([4]) since
such type conversion is only used for compiler analysis
and not encoded in dwarf/btf. Theoretically, it is
possible for clang to understand these tags and
do a sparse-like type checking work. But I would like
to leave that to future work and for now suggest simply
ignore these btf_tag attributes if they are used
as type attributes.
[1] https://github.com/torvalds/linux/blob/master/include/linux/compiler_types.h#L10
[2] https://sparse.docs.kernel.org/en/latest/
[3] https://reviews.llvm.org/D106614
[4] https://github.com/torvalds/linux/blob/master/fs/binfmt_flat.c#L135
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110116
Files:
clang/lib/Sema/SemaType.cpp
clang/test/Sema/attr-btf_tag.c
Index: clang/test/Sema/attr-btf_tag.c
===================================================================
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,7 @@
int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
return arg->a + arg2->a;
}
+
+void __tag1 * convert(long arg) {
+ return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8129,6 +8129,12 @@
case ParsedAttr::IgnoredAttribute:
break;
+ case ParsedAttr::AT_BTFTag:
+ // FIXME: Linux kernel may also use this attribute for type casting check,
+ // which clang doesn's support for now. Let us ignore them so linux kernel
+ // build won't break.
+ attr.setUsedAsTypeAttr();
+ break;
case ParsedAttr::AT_MayAlias:
// FIXME: This attribute needs to actually be handled, but if we ignore
// it it breaks large amounts of Linux software.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110116.373749.patch
Type: text/x-patch
Size: 1042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210921/00b84cfa/attachment.bin>
More information about the cfe-commits
mailing list