btf : Fix union/anonymous struct resolution#4973
Merged
Merged
Conversation
When unstacking a nested BTF union or anonymous struct, we fail to store the position of the union/struct itself, only capturing the final element. This leads to incorrect offset resolution. To fix this, we introduce an accumulator mechanism that accumulates the union/anonymous struct offset only when the member.name matches the expected attribute. Signed-off-by: Tristan d'Audibert <tdaudibe@isovalent.com>
Attribute resolution for unions/anonymous struct has been broken since the Resolve algorithm's introduction. This commit aligns with the new logic by implementing the same accumulator mechanism, ensuring identical return values. Signed-off-by: Tristan d'Audibert <tdaudibe@isovalent.com>
Contributor
|
I tested this change with: And policy: And the event was as expected: I also tested another variant of that program, where pointers are used, and that works too: |
andrewstrohman
approved these changes
May 8, 2026
Contributor
|
Added a |
Contributor
Thanks, @andrewstrohman! Do you think we can add these tests in our go tests? |
Merged
Contributor
At least for 1.7, I had to backport #4900 as well. |
Contributor
Here is the PR to do it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4974
Description
Since the resolve algorithm was implemented, Union and anonymous struct types were incorrectly resolved. The reason for this is that the final element found offset were written on top on the union/anonymous struct.
With this fix, the offset of the union/anonymous struct is incremented only when the final element matches.
No test were added because one already exist for union/anonymous struct. Therefore I just updated the logic of the test because this one was also broken.
Example
With the following policy
Before
The event look like this
After