[lld] [lld] lld::makeThreadLocal: omit `thread_local` when threads disabled (PR #72057)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 12 09:31:53 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Keith Winstein (keithw)

<details>
<summary>Changes</summary>

This PR lets lld be used as a library in single-threaded environments without TLS.

---
Full diff: https://github.com/llvm/llvm-project/pull/72057.diff


1 Files Affected:

- (modified) lld/include/lld/Common/Memory.h (+4) 


``````````diff
diff --git a/lld/include/lld/Common/Memory.h b/lld/include/lld/Common/Memory.h
index c7612a08c6b00db..23e8737bcc207be 100644
--- a/lld/include/lld/Common/Memory.h
+++ b/lld/include/lld/Common/Memory.h
@@ -65,7 +65,11 @@ template <typename T, typename... U> T *make(U &&... args) {
 template <typename T>
 inline llvm::SpecificBumpPtrAllocator<T> &
 getSpecificAllocSingletonThreadLocal() {
+  #if LLVM_ENABLE_THREADS
   thread_local SpecificAlloc<T> instance;
+  #else
+  static SpecificAlloc<T> instance;
+  #endif
   return instance.alloc;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/72057


More information about the llvm-commits mailing list