tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

builder: protect against unsupported concurrency in lld

Open aykevl opened this issue 5 years ago • 6 comments
trafficstars

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.

aykevl avatar Dec 21 '19 13:12 aykevl

Hopefully this will fix the Windows issue.

aykevl avatar Dec 21 '19 18:12 aykevl

It appears to have fixed Windows. However it broke macOS.

deadprogram avatar Dec 21 '19 18:12 deadprogram

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).

aykevl avatar Dec 21 '19 19:12 aykevl

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).

aykevl avatar Dec 30 '19 18:12 aykevl

Seems to still be broken on macOS.

deadprogram avatar Dec 30 '19 18:12 deadprogram

Ugh, builder/ar.go is really bad at properly closing files when there is an error. That may have triggered it.

aykevl avatar Dec 30 '19 19:12 aykevl

We invoke lld in a separate process now so this is no longer an issue.

aykevl avatar Sep 02 '22 00:09 aykevl