-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
runtime: can't atomic access of first word of tiny-allocated struct on 32-bit architecture #37262
Comments
Maybe I'm missing something, but this looks like a malloc issue, not a compiler issue. |
@aclements Looks like the tiny allocator doesn't uphold the guarantee in the spec. The lines are:
In this case Maybe the fix is to just align to |
@mknyszek would that make the tiny allocator much less efficient, by increasing the number and size of gaps? And if so, are there mitigations? |
Maybe, but given that we don't have atomic types and instead have atomic operations, it's impossible to know whether we really need the full alignment, and so we must conservatively always assume we need it. In that sense, I can't think of any mitigations besides waiting for #36606 which may allow users to set a custom alignment (thereby signaling the alignment they actually need). It might also be slower because we have to touch the type whereas we didn't have to before. |
typ.align doesn't help in the current way. On 32-bit architectures it is 4 for int64. This is what #36606 is for. |
I think this can only happen for a size 9-15 object on a 32-bit architecture. Maybe we round up for only this case. I don't think it is too bad. |
Since a type's size is rounded up to its alignment, I think this specific case with a 12 byte struct on 32-bit is really the only way that this can happen, and it's a direct consequence of the underalignment of uint64. /cc @danscales for an interesting consequence of the current alignment rules |
@aclements @cherrymui Got it. I missed the fact that the size is rounded up. That makes sense, and I was surprised that this wasn't more broken... @josharian It looks like what I was proposing is already there, so there shouldn't be any packing problems. It looks like this problem is wholly #36606 as @cherrymui mentioned, so we might want to just close this as a duplicate? |
Not exactly. Fixing #36606 will make this go away, but we can also fix this separately. This issue is specific to the first word of an allocation, which we try to make it still 8-byte aligned, as mentioned in https://golang.org/pkg/sync/atomic/#pkg-note-BUG . Currently it is mostly aligned, except for tinyalloc (and sbrk mode). |
This didn't get fixed. Rolling forward to 1.16, and marking as release blocker since it does seem like a serious bug, albeit one that is hard to hit. |
Given that #36606 is stalled, I think we need to revisit this. It seems like we need to special-case 12 byte allocations on 32-bit to by 8-byte aligned. Are there any other solutions on the table? |
I think we should just special case these 12-byte allocations as you and @cherrymui suggested. I can work on this now. |
Change https://golang.org/cl/254057 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Not sure
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
This issue about test the spec below, but got panic:
I use code below to test, and will panic occasionally
(Test it on my 64-bit mac:
GOARCH=386 go build -ldflags=-compressdwarf=false -o test test.go
)But if i remove the
fmt.Println()
inside of the test function, it will pass.I also debug it use gdb (append info below),
x
escape to heap, and use tinyallocs to alloc itAnd i notice that
c.tinyoffset
is 2.But when no
fmt.Println()
it will be 0 or 16, Or just nextFreeFast to get a new object.So i am confused, is that spec work in this situation?
Or maybe i misunderstand with this spec?
Or a issue cross compile under macOS?
May related with this issue: #599
Code:
gdb info
What did you expect to see?
go run successfully
What did you see instead?
Panic sometimes:
The text was updated successfully, but these errors were encountered: