Page MenuHomePhabricator

[Clang][BPF] implement __builtin_btf_type_id() builtin function

Authored by yonghong-song on Feb 15 2020, 8:41 AM.



Such a builtin function is mostly useful to preserve btf type id
for non-global data. For example,

extern void foo(..., void *data, int size);
int test(...) {
  struct t { int a; int b; int c; } d;
  d.a = ...; d.b = ...; d.c = ...;
  foo(..., &d, sizeof(d));

The function "foo" in the above only see raw data and does not
know what type of the data is. In certain cases, e.g., logging,
the additional type information will help pretty print.

This patch implemented a BPF specific builtin

u32 btf_type_id = __builtin_btf_type_id(param)

which will return a btf type id for the "param".

Diff Detail

Event Timeline

yonghong-song created this revision.Feb 15 2020, 8:41 AM

The corresponding LLVM side of change is

ast accepted this revision.Feb 19 2020, 6:28 PM

lgtm. Thanks for explaining lvalue/value trick.

This revision is now accepted and ready to land.Feb 19 2020, 6:28 PM