Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuples: Treat Type::timestamp as an array #1658

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

danobi
Copy link
Member

@danobi danobi commented Dec 9, 2020

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.

Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@danobi
Copy link
Member Author

danobi commented Dec 9, 2020

I think this is technically supposed to be correct:

diff --git a/src/types.cpp b/src/types.cpp
index 0c86bbc1..56a6fa8c 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -488,8 +488,10 @@ ssize_t SizedType::GetAlignment() const
     return GetSize();
   else if (GetSize() <= 4)
     return 4;
-  else
+  else if (GetSize() <= 8)
     return 8;
+  else
+    return 16;
 }

@danobi danobi changed the title XXX: tuples: Add test for strftime in tuple tuples: Treat Type::timestamp as an array Dec 9, 2020
@danobi danobi force-pushed the tuple_strftime branch 2 times, most recently from e8ae10a to aea9052 Compare December 9, 2020 23:37
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.
@danobi danobi marked this pull request as ready for review December 9, 2020 23:49
@danobi
Copy link
Member Author

danobi commented Jan 5, 2021

Chatted about this on IRC

@danobi danobi merged commit a087cc9 into bpftrace:master Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant