Skip to contentSkip to conversation

lib/{cobalt,copperplate}: Use valid addresses for pthread_setspecific

PATCH New Jan Kiszka 1 participant 1 message Oct 16, 2021

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 lib/{cobalt,copperplate}: Use valid addresses for pthread_setspecific

From: Jan Kiszka <[email protected]>

glibx 2.34 and newer annotated pthread_setspecific in a way that gcc-11 complains about non-NULL pointers that are outside of what is considered valid. So use dummy addresses instead. namely the related pthread keys. Those pointers will never be dereferenced in both use cases.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=28458.

---
 include/copperplate/threadobj.h | 6 +++++-
 lib/cobalt/printf.c             | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
include/copperplate/threadobj.h +5 -1
index 7e6904f4c8..c8363415b4 100644
@@ -173,7 +173,11 @@ void threadobj_save_timeout(struct threadobj_corespec *corespec,
 #define __THREAD_M_SPARE6	(1 << 22)
 #define __THREAD_M_SPARE7	(1 << 23)
 
-#define THREADOBJ_IRQCONTEXT    ((struct threadobj *)-2UL)
+/*
+ * We need to use a valid address here. The object will never be dereferenced
+ * when it is identified as IRQ context, so the pthread key itself is fine.
+ */
+#define THREADOBJ_IRQCONTEXT	((struct threadobj *)&threadobj_tskey)
 
 struct traceobj;
 struct syncobj;
lib/cobalt/printf.c +1 -1
index 8982ddc937..0aa5940c67 100644
@@ -729,7 +729,7 @@ done:
 	pthread_cond_init(&printer_wakeup, NULL);
 	spawn_printer_thread();
 	/* We just need a non-zero TSD to trigger the dtor upon unwinding. */
-	pthread_setspecific(cleanup_key, (void *)1);
+	pthread_setspecific(cleanup_key, &cleanup_key);
 
 	atexit(rt_print_flush_buffers);
 }
Signature · 1 line
2.31.1