casaroli commented on code in PR #20723:
URL: https://github.com/apache/nuttx/pull/20723#discussion_r4313534057


##########
libs/libc/tls/Make.defs:
##########
@@ -28,6 +28,9 @@ endif
 
 ifneq ($(CONFIG_TLS_NELEM),0)
 CSRCS += tls_destruct.c
+ifneq ($(CONFIG_DISABLE_PTHREAD),y)
+CSRCS += tls_emutls.c

Review Comment:
   Thank you. I tried #20803 on master. It solves one thing that this PR did 
not: in a flat image, libc's `__emutls_get_address()` must win over the one in 
libgcc. I added that here with `-u __emutls_get_address -u 
__emutls_register_common` on the image link (Make and CMake). This also works 
when the link goes through gcc (LTO).
   
   I also found some problems in #20803:
   - A kernel build does not compile, because `CONFIG_TLS_TASK_NELEM` is not 
defined there.
   - Each variable takes one task TLS slot for the whole system, and the slots 
are not given back. With `CONFIG_TLS_TASK_NELEM=4`, the fifth program with one 
`__thread` variable stops at an assertion.
   - Each variable also takes one pthread key in each task group.
   
   This PR now has no fixed limit, and it does not use pthread keys or 
`CONFIG_TLS_NELEM`. The TLS info of each thread points to the array of its 
copies, and `exit()` and `pthread_exit()` free it. When a module is unloaded, 
libc frees its copies and reuses the indexes. The tests are in the PR 
description.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to