tinygo
tinygo copied to clipboard
builder: protect against unsupported concurrency in lld
LLD does not support concurrency, and cannot be run at the same time as compiles. Therefore, use a RWMutex to read-lock compiles and write-lock links.
This commit moves the locking from the full program tests to the builder package itself, to provide a cleaner API boundary: users of builder.Build do not have to think about concurrency. This move also makes the above mentioned compile concurrency possible.
On my system, this results in about 36% faster tests.
Note: I've been busy with allowing packages to be compiled independently. When that is ready, lldLock will probably be locked per package.
Hopefully this will fix the Windows issue.
It appears to have fixed Windows. However it broke macOS.
It was a "too many open files" problem, which seems spurious to me. Fixed it by retrying the build.
However, I did find a file that wasn't closed here: https://github.com/tinygo-org/tinygo/pull/799 (that should reduce the chances of this happening).
I did another update. I don't see why LLD and Clang would interfere with each other or with regular LLVM building/linking so I switched to more fine grained locks instead (for just Clang and LLD, and Clang only on Windows).
Seems to still be broken on macOS.
Ugh, builder/ar.go is really bad at properly closing files when there is an error. That may have triggered it.
We invoke lld in a separate process now so this is no longer an issue.