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


##########
libs/libc/tls/CMakeLists.txt:
##########
@@ -20,7 +20,20 @@
 #
 # 
##############################################################################
 
-set(SRCS task_getinfo.c tls_getinfo.c)
+set(SRCS task_getinfo.c tls_getinfo.c tls_emutls.c)
+
+# Take the emutls functions from libc, not from libgcc: the apps refer to them
+# only after the linker has scanned libc (see tools/Config.mk).
+
+if(CONFIG_ARCH_TOOLCHAIN_GCC AND NOT CONFIG_ARCH_SIM)
+  set(EMUTLS_LDFLAGS "SHELL:-u __emutls_get_address"

Review Comment:
   Done.



##########
libs/libc/libc.h:
##########
@@ -332,6 +332,13 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct 
hostent *host,
 int lib_restoredir(void);
 #endif
 
+/* Defined in tls/tls_emutls.c.  exit() and pthread_exit() call
+ * tls_emutls_destruct() through g_tls_emutls_destruct (tls/tls_getinfo.c).
+ */
+
+extern CODE void (*g_tls_emutls_destruct)(void);

Review Comment:
   A direct call links `tls_emutls.c` (about 600 bytes with `malloc()`) into 
every program: `lm3s6965-ek:qemu-protected` then overflows its flash by 628 
bytes.



##########
libs/libc/tls/tls_getinfo.c:
##########
@@ -32,6 +32,16 @@
 #include <nuttx/tls.h>
 #include <nuttx/sched.h>
 
+#include "libc.h"
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* tls_emutls.c sets it on its first use, so exit() does not link it */
+
+CODE void (*g_tls_emutls_destruct)(void);

Review Comment:
   A kernel-build program is relocatable, and the loader sets an undefined weak 
symbol to 0: the `bl` to 0 is out of range and `/system/bin/init` does not load 
on `qemu-armv8a:knsh`.



##########
libs/libc/libc.h:
##########
@@ -332,12 +332,15 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct 
hostent *host,
 int lib_restoredir(void);
 #endif
 
-/* Defined in tls/tls_emutls.c.  exit() and pthread_exit() call
- * tls_emutls_destruct() through g_tls_emutls_destruct (tls/tls_getinfo.c).
+/* Defined in tls/tls_emutls.c.  exit(), pthread_exit() and the loader call
+ * them through these pointers (tls/tls_getinfo.c).
  */
 
 extern CODE void (*g_tls_emutls_destruct)(void);
+extern CODE void (*g_tls_emutls_release)(FAR const void *start,

Review Comment:
   A direct call links the emutls code into every image with ELF support: 
`lm3s6965-ek:qemu-protected` then overflows its flash by 628 bytes.



##########
libs/libc/libc.h:
##########
@@ -332,12 +332,15 @@ ssize_t lib_parse_hostfile(FAR FILE *stream, FAR struct 
hostent *host,
 int lib_restoredir(void);
 #endif
 
-/* Defined in tls/tls_emutls.c.  exit() and pthread_exit() call
- * tls_emutls_destruct() through g_tls_emutls_destruct (tls/tls_getinfo.c).
+/* Defined in tls/tls_emutls.c.  exit(), pthread_exit() and the loader call
+ * them through these pointers (tls/tls_getinfo.c).
  */
 
 extern CODE void (*g_tls_emutls_destruct)(void);
+extern CODE void (*g_tls_emutls_release)(FAR const void *start,

Review Comment:
   gcc still emits a direct `bl` to the weak function; the null check only adds 
a load. A relocatable kernel-build program then fails to load: `up_relocateadd: 
ERROR: overflow in relocation type 283 val 0`.



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