-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add unsafe.Alignof() tests for code that depends on 64-bit atomics #341
Comments
Assign to @MrAlias. |
Looking into building some tests for structures with fields that support 64-bit atomic operations and ensuring they are arrange for 64-bit alignment looks to be a bit more complicated than just checking the The To find this offset the
This seems viable, but it still requires prior knowledge (i.e. a static list) of what types need to support 64-bit atomic operation. Which means it would still act on some level as a change indicator test and possibly have gaps when new structures are created that are passed to 64-bit atomic functions. I guess we could try parsing the AST for the project code to try and make this determination more dynamic, but that sounded a bit extreme. Alternatively, I was wondering if refactoring the
Obviously, there would be downside to this (i.e. potential waste of 7 bytes for @jmacd I'm interested to hear what you think the best path forward would be here. |
I definitely like the first half -- the proposal to use the Another idea is to auto-detect for a list of known types in the test -- |
I spent some time investigating how we could auto-detect structs that need alignment and I have come to the conclusion that it is not going to be easily achievable. To dynamically generate a list of all Without dynamically determining Going to think a bit more about ways to solve this. @jmacd I'm interested to hear what your thoughts are on this. |
One idea, although some might call it overkill, is to use https://godoc.org/golang.org/x/tools/go/loader to load a program that depends on all OTel packages. Then it's relatively simple to iterate over all types and identify the structs. We can't use the reflect package in this case, we'll be handling a parsed program object--it's not looking very easy, but it's do-able. I'm not sure it's worth the effort -- depends on how much of an experience you want :) |
From the description:
|
@jmacd thanks for the link, I wasn't aware of that package. Taking a look at it and the replacement @bogdandrutu pointed out (https://godoc.org/golang.org/x/tools/go/packages) I think this replaces the part of the code that does discovery. Seems like it could be a good maintained replacement for the PoC I built to test the idea locally. As for introspecting the structs once they are identified, I was thinking a bit more about that last night and think it is worth trying to get a working example using Eval to use the reflect package and find offsets. I'll give that a go (hopefully today or early next week). It's definitely been an interesting experience so far, might as well see it through 😄 . |
Looking further into using At this point I don't think it is going to be viable to dynamically check declared
My guess is (1) is viable, but the rest seem like bad ideas (2) or challenging/controversial (3)(4). I'll plan to sync about this next week. |
From the last SIG meeting (2020-01-02), the consensus was to go with (1) and (2) from the last comment. The thinking being that comments and test would help capture at least part of the knowledge gained from this investigation. If these comments or tests become more of a problem than a help the problem can be readdressed in the future. |
This ensures 8-byte (64-bit) alignment on 32-bit machines. See https://go101.org/article/memory-layout.html and open-telemetry/opentelemetry-go#341
…aws (#341) * Bump github.com/aws/aws-sdk-go from 1.34.18 to 1.34.22 in /detectors/aws Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.34.18 to 1.34.22. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/master/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.34.18...v1.34.22) Signed-off-by: dependabot[bot] <[email protected]> * Auto-fix go.sum changes in dependent modules Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
This includes several metric aggregators and the Meter implementation. Adding simple tests that for alignment will avoid confusing test errors when changes lead to improperly aligned struct fields.
This was noted in #335. See https://go101.org/article/memory-layout.html.
The text was updated successfully, but these errors were encountered: