From 6e56711a412109816364187e9ffedc9138b557c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Palim=C4=85ka?= <25018671+tatry@users.noreply.github.com> Date: Wed, 27 Apr 2022 12:15:22 +0200 Subject: [PATCH] Improve padding calculation in eBPF parser --- backends/ebpf/ebpfParser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backends/ebpf/ebpfParser.cpp b/backends/ebpf/ebpfParser.cpp index fe526464de..eebdf6c931 100644 --- a/backends/ebpf/ebpfParser.cpp +++ b/backends/ebpf/ebpfParser.cpp @@ -401,7 +401,11 @@ StateTranslationVisitor::compileExtract(const IR::Expression* destination) { auto etype = EBPFTypeFactory::instance->create(ftype); if (etype->is()) { auto scalarType = etype->to(); - unsigned padding = scalarType->alignment() * 8 - scalarType->widthInBits(); + unsigned readWordSize = scalarType->alignment() * 8; + unsigned unaligned = scalarType->widthInBits() % readWordSize; + unsigned padding = readWordSize - unaligned; + if (padding == readWordSize) + padding = 0; if (scalarType->widthInBits() + padding >= curr_padding) { curr_padding = padding; }