Skip to content

Commit

Permalink
Merge pull request iovisor#1484 from iovisor/yhs_dev
Browse files Browse the repository at this point in the history
add padding to the end of structure
  • Loading branch information
4ast committed Dec 12, 2017
2 parents b384b76 + b32b4a5 commit e5db52b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/cc/json_map_decl_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ bool BMapDeclVisitor::VisitRecordDecl(RecordDecl *D) {
Offset = FieldOffset + FieldSize;
genJSONForField(F);
}

/* Additional Padding after the last field so that the Record Size matches */
CharUnits RecordSize = Layout.getSize();
if (RecordSize > Offset) {
result_ += "[\"__pad_end\",\"char\",["
+ to_string((RecordSize - Offset).getQuantity()) + "]], ";
}
}

if (!D->getDefinition()->field_empty())
Expand Down
5 changes: 3 additions & 2 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ def test_padding_types(self):
};
u8 f1_3; /* offset 48 */
unsigned __int128 f1_4; /* offset 64 */
char f1_5; /* offset 80 */
};
struct value_t {
u8 src[4] __attribute__ ((aligned (8))); /* offset 0 */
Expand All @@ -694,8 +695,8 @@ def test_padding_types(self):
"""
b = BPF(text=text)
table = b['table1']
self.assertEqual(ct.sizeof(table.Key), 80)
self.assertEqual(ct.sizeof(table.Leaf), 12)
self.assertEqual(ct.sizeof(table.Key), 96)
self.assertEqual(ct.sizeof(table.Leaf), 16)


if __name__ == "__main__":
Expand Down

0 comments on commit e5db52b

Please sign in to comment.