stdlib/sync: Match Mutex size with upstream Go
People are trying to build stuff that uses modernc.org/memory package. There is one assumption made by this package- it requires a size of 8 for sync.Mutex.
The current implementation of sync.Mutex is based on the task.Mutex which is composed of a bool and a Stack (pointer). This gives the Mutex a size of 16 bytes on 64-bit aligned systems while in upstream Go it is 8 bytes.
TinyGo data structures
Go data structures
To be honest, this is a bug in modernc.org/memory, not in TinyGo. They have written non-portable code. If they want to extend portability to TinyGo they could use a build tag. But it's also possible we're going to break this at some point - for example, -scheduler=threads and -scheduler=tasks may have a different sync.Mutex size.
I don't think there's anything to fix on our side.
As it happens, https://github.com/tinygo-org/tinygo/pull/4559 will make sync.Mutex 8 bytes on a 64-bit system on Linux. It's still no guarantee, but for those looking for a bit more compatibility that PR happens to provide it as a side effect.
@soypat In the commit for libc_issues#43, the allocated memory has been expanded in an attempt to make it compatible with the current tinygo's sync.Mutex. If it works, then this issue seems to have been resolved.
However, after fixing this issue, a new problem has emerged:
i64 add (i64 ptrtoint (ptr @"modernc.org/libc._table" to i64), i64 256)
Closing since I don't believe this is a TinyGo bug.
@Tryanks can you make a separate issue with steps to reproduce the problem you encountered?
@Tryanks can you make a separate issue with steps to reproduce the problem you encountered?
Sorry, I cannot reproduce this error alone because the discrepancies seem to be increasing:
~/GolandProjects/TinySQLiteTest via go v1.25.4
x tinygo run .
# modernc.org/sqlite
../../go/pkg/mod/modernc.org/[email protected]/fcntl.go:27:16: undefined: runtime.Pinner