[PATCH] D12001: Implement __emutls_get_address

Joerg Sonnenberger via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 04:29:22 PDT 2015


joerg added inline comments.

================
Comment at: compiler-rt/lib/builtins/emutls.c:18
@@ +17,3 @@
+ * can use thread local data without heavier POSIX memory allocators.
+ */
+#ifndef EMUTLS_USE_POSIX_MEMALIGN
----------------
IMO it would still be cleaner to provide two inline functions at the start and
#undef posix_memalign / free and redefine them to map to those two functions. It leaves the complications of the Android issue out of the rest of the file.

================
Comment at: compiler-rt/lib/builtins/emutls.c:143
@@ +142,3 @@
+    if (array == NULL) {
+        uintptr_t size = index + 16;  /* allocate 16 extra slots */
+        array = calloc(size + 1, sizeof(void*));
----------------
Just round up to next multiple of 16.  No need to allocate some strange number depending on which TLS variable was access first.

================
Comment at: compiler-rt/lib/builtins/emutls.c:150
@@ +149,3 @@
+        if (index > size)
+            size = index + 16;  /* allocate 16 extra slots */
+        array = realloc(array, (size + 1) * sizeof(void*));
----------------
I still think it would make sense to try to remember the current maximum index. It doesn't have to be thread-safe, just a global variable. Essentially, use something like roundup16(max(index, max_index)) here.


http://reviews.llvm.org/D12001





More information about the llvm-commits mailing list