Page MenuHomePhabricator

[BPF] Generate array dimension size properly for zero-size elements

Authored by yonghong-song on Sep 24 2019, 1:25 PM.



Currently, if an array element type size is 0, the number of
array elements will be set to 0, regardless of what user
specified. This implementation is done in the beginning where
BTF is mostly used to calculate the member offset.

For example,

struct s {}; 
struct s1 {
      int b;
      struct s a[2];
struct s1 s1;

The BTF will have struct "s1" member "a" with element count 0.

Now BTF types are used for compile-once and run-everywhere
relocations and we need more precise type representation
for type comparison. Andrii reported the issue as there
are differences between original structure and BTF-generated

This patch made the change to correctly assign "2"
as the number elements of member "a".
Some dead codes related to ElemSize compuation are also removed.

Diff Detail


Event Timeline

yonghong-song created this revision.Sep 24 2019, 1:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2019, 1:25 PM
anakryiko accepted this revision.Sep 24 2019, 2:26 PM

Looks good, thanks for fixing so fast!

This revision is now accepted and ready to land.Sep 24 2019, 2:26 PM
This revision was automatically updated to reflect the committed changes.