[PATCH] D69759: [RFC][BPF] Add preserve_access_index attribute to record definition

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 2 20:41:46 PDT 2019


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

This patch introduced a new bpf specific attribute which can
be added to struct or union definition. For example,

  struct s { ... } __attribute__((preserve_access_index));

The goal is to simplify user codes for cases
where preserve access index happens for certain struct/union,
so user does not need to use clang __builtin_preserve_access_index
for every members.

The attribute has no effect if -g is not specified.

When the attribute is specified and -g is specified, any member
access to that structure or union will be preserved through
__builtin_preserve_{struct,union}_access_index() IR intrinsics.
For bpf target, relocation will be generated.
Any access beyond member access is not preserved.

The following is an example to illustrate the usage:

  -bash-4.4$ cat t.c
  union s {
    int a;
    struct {
      int used1; 
      int b;
    } __attribute__((preserve_access_index));
    struct {
      int used2;
      int c;
    };
    int d[3];
  } __attribute__((preserve_access_index));
  
  int test1(union s *arg) { return arg->a; }
  int test2(union s *arg) { return arg->b; }
  int test3(union s *arg) { return arg->c; }
  int test4(union s *arg) { return arg->d[1]; }
  int test5(union s *arg) { return __builtin_preserve_access_index(arg->d[1]); }
  -bash-4.4$ clang -target bpf -O2 -S -g t.c

test1() generates a relocation for &s->a.
test2() generates a relocation for &s->b.
test3() generates a relocation for the anonymous
 struct which includes member "c", but no
 relocation is generated for anonymous structure
 member "c" access.
test4() generates a relocation for &s->d, but
 no relocation is generated for array acceess
 with index 1.
test5() generates a relocation for &s->d[1].


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69759

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69759.227598.patch
Type: text/x-patch
Size: 5542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191103/f4790124/attachment.bin>


More information about the cfe-commits mailing list