Skip to content

Commit

Permalink
Merge pull request #3749 from brauner/2021-03-29/fixes
Browse files Browse the repository at this point in the history
compiler: fix thread_local detection
  • Loading branch information
stgraber committed Mar 29, 2021
2 parents 86624ee + 4484397 commit d96134f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 35 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ AC_CHECK_DECLS([PR_SET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
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 threads.h])
AC_CHECK_HEADERS([pty.h sys/memfd.h sys/personality.h sys/resource.h sys/signalfd.h sys/timerfd.h utmpx.h])

AC_CHECK_HEADER([ifaddrs.h],
AM_CONDITIONAL(HAVE_IFADDRS_H, true)
Expand Down
23 changes: 7 additions & 16 deletions src/lxc/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@

#include "config.h"

#if defined(HAVE_THREADS_H)
#include <threads.h>
#define THREAD_LOCAL_STORAGE_SUPPORTED
#elif defined(thread_local)
#define THREAD_LOCAL_STORAGE_SUPPORTED
#ifndef thread_local
#if __STDC_VERSION__ >= 201112L && \
!(defined(__STDC_NO_THREADS__) || \
(defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
#define thread_local _Thread_local
#else
#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
#define thread_local __thread
#endif
#endif

#if __GNUC__ >= 7
Expand Down
6 changes: 0 additions & 6 deletions src/lxc/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ lxc_log_define(conf, lxc);
* The lxc_conf of the container currently being worked on in an API call.
* This is used in the error calls.
*/
#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

char *lxchook_names[NUM_LXC_HOOKS] = {
"pre-start",
Expand Down
6 changes: 0 additions & 6 deletions src/lxc/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,7 @@ struct lxc_conf {
__hidden extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size)
__access_r(3, 4);

#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
struct lxc_conf *current_config;
#endif

__hidden extern int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, char *argv[]);
__hidden extern struct lxc_conf *lxc_conf_init(void);
Expand Down
6 changes: 0 additions & 6 deletions src/lxc/initutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ const char *lxc_global_config_value(const char *option_name)
};

/* placed in the thread local storage pool for non-bionic targets */
#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

/* user_config_path is freed as soon as it is used */
char *user_config_path = NULL;
Expand Down

0 comments on commit d96134f

Please sign in to comment.