Our detection for TLS wasn't working. Fix it.
Fixes: https://github.com/lxc/lxd/issues/8327
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
AC_CHECK_DECLS([PR_GET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
# Check for some headers
-AC_CHECK_HEADERS([pty.h sys/memfd.h sys/personality.h sys/resource.h sys/signalfd.h sys/timerfd.h utmpx.h])
+AC_CHECK_HEADERS([pty.h sys/memfd.h sys/personality.h sys/resource.h sys/signalfd.h sys/timerfd.h utmpx.h threads.h])
AC_CHECK_HEADER([ifaddrs.h],
AM_CONDITIONAL(HAVE_IFADDRS_H, true)
#include "config.h"
-#ifndef thread_local
-#if __STDC_VERSION__ >= 201112L && \
- !(defined(__STDC_NO_THREADS__) || \
- (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
-#define thread_local _Thread_local
+#if defined(HAVE_THREADS_H)
+ #include <threads.h>
+ #define THREAD_LOCAL_STORAGE_SUPPORTED
+#elif defined(thread_local)
+ #define THREAD_LOCAL_STORAGE_SUPPORTED
#else
-#define thread_local __thread
-#endif
+ #if __STDC_VERSION__ >= 201112L && \
+ !(defined(__STDC_NO_THREADS__) || \
+ (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+ #define thread_local _Thread_local
+
+ #define THREAD_LOCAL_STORAGE_SUPPORTED
+ #else
+ #define thread_local __thread
+
+ #define THREAD_LOCAL_STORAGE_SUPPORTED
+ #endif
#endif
#if __GNUC__ >= 7
#include "af_unix.h"
#include "caps.h"
#include "cgroups/cgroup.h"
+#include "compiler.h"
#include "conf.h"
#include "config.h"
#include "confile.h"
lxc_log_define(conf, lxc);
-/* The lxc_conf of the container currently being worked on in an API call.
+/*
+ * The lxc_conf of the container currently being worked on in an API call.
* This is used in the error calls.
*/
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
thread_local struct lxc_conf *current_config;
+#elif defined(ENFORCE_THREAD_SAFETY)
+#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
#else
struct lxc_conf *current_config;
#endif
__hidden extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size)
__access_r(3, 4);
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
extern thread_local struct lxc_conf *current_config;
+#elif defined(ENFORCE_THREAD_SAFETY)
+#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
#else
-extern struct lxc_conf *current_config;
+struct lxc_conf *current_config;
#endif
__hidden extern int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, char *argv[]);
};
/* placed in the thread local storage pool for non-bionic targets */
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
static thread_local const char *values[sizeof(options) / sizeof(options[0])] = {0};
+#elif defined(ENFORCE_THREAD_SAFETY)
+ #error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
#else
static const char *values[sizeof(options) / sizeof(options[0])] = {0};
#endif