This is an archive of the discontinued LLVM Phabricator instance.

[BPF] add proper multi-dimensional array support
ClosedPublic

Authored by yonghong-song on Mar 28 2019, 9:01 AM.

Details

Summary
For multi-dimensional array like below
  int a[2][3];
the previous implementation generates BTF_KIND_ARRAY type
like below:
  . element_type: int
  . index_type: unsigned int
  . number of elements: 6

This is not the best way to represent arrays, esp.,
when converting BTF back to headers and users will see
  int a[6];
instead.

This patch generates proper support for multi-dimensional arrays.
For "int a[2][3]", the two BTF_KIND_ARRAY types will be
generated:
  Type #n:
    . element_type: int
    . index_type: unsigned int
    . number of elements: 3
  Type #(n+1):
    . element_type: #n
    . index_type: unsigned int
    . number of elements: 2

The linux kernel already supports such a multi-dimensional
array representation properly.

Diff Detail

Repository
rL LLVM

Event Timeline

yonghong-song created this revision.Mar 28 2019, 9:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2019, 9:01 AM
ast accepted this revision.Mar 28 2019, 9:20 AM
This revision is now accepted and ready to land.Mar 28 2019, 9:20 AM
This revision was automatically updated to reflect the committed changes.