Details:
Provide thread-safe StringSaver and bAlloc by assigning each thread its own StringSaver and allocator. Usage: code that might be run in different threads should call the new perThreadSaver() or makePerThread() instead of the current util (saver() and make()) User can enable this unconditionally at compile time by setting -DTHREAD_SAFE_MEMORY
Some considerations:
- This might have some perf/memroy impact.
- TLS support might not be available on all archs. (Darwin?)
Benchmarks done on linking envoy and chromium for darwins showed no perf different when using the new allocators
I'm generally not a fan of adding compile-time options as I think it increases the number of potentially poorly-tested code paths. Maybe we could just use LLD_ENABLE_THREADS to gate the code currently protected by LLVM_THREAD_SAFE_MEMORY.
But I guess having things behind a compile-time flag for now will make this diff easier to land. It's conceivable that some buildbots may be unhappy with this depending on e.g. the target-specific support for TLS. Can we follow up with a diff that makes the thread-safe behavior the default? If that passes all the buildbots, I think we should make it the default behavior.