Skip to content

Commit

Permalink
tuples: Treat Type::timestamp as an array
Browse files Browse the repository at this point in the history
Previously, we were seeing issues like:

```
$ sudo bpftrace -e 'BEGIN {@A[pid]=(nsecs, strftime("%M:%S", nsecs)); }'
FATAL: BUG: Struct size mismatch: expected: 24, real: 32
Aborted (core dumped)
```

on certain LLVM versions. The issue most likely has to do with padding
and whether LLVM considers the 16 byte type as a single 128 bit integer
or two 64 bit integers. If considered as a single 128 bit integer, then
the padded struct size is indeed 32 bytes. If as two 64 bit integers,
then 24 bytes is correct.

Instead of trying to fight with LLVM on this, mark Type::timestamp as an
array so that codegen will tell LLVM that Type::timestamp types are an
array of 16 8-bit integers. This effectively packs the type. We know
this is safe to do b/c Type::timestamp types are accessed from userspace
as two 64-bit integers anyways (see `AsyncEvent::Strftime`) which is
naturally packed on both 32-bit and 64-bit machines.

Note that this is also how Type::Usym is implemented.
  • Loading branch information
danobi committed Dec 9, 2020
1 parent 9f7ee99 commit 8ffcd3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ bool SizedType::operator==(const SizedType &t) const
bool SizedType::IsArray() const
{
return type == Type::array || type == Type::string || type == Type::usym ||
type == Type::inet || type == Type::buffer || type == Type::record;
type == Type::inet || type == Type::buffer || type == Type::record ||
type == Type::timestamp;
}

bool SizedType::IsAggregate() const
Expand Down
5 changes: 5 additions & 0 deletions tests/runtime/tuples
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ NAME tuple print
RUN bpftrace -e 'BEGIN { @ = (1, 2, "string", (4, 5)); exit(); }'
EXPECT ^@: \(1, 2, string, \(4, 5\)\)$
TIMEOUT 5

NAME tuple strftime type is packed
RUN bpftrace -e 'BEGIN { @ = (nsecs, strftime("%M:%S", nsecs)); exit(); }'
EXPECT ^@: \(\d+, \d+:\d+\)$
TIMEOUT 5

0 comments on commit 8ffcd3b

Please sign in to comment.