Commit 2320c70c authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Disable TLS optimization in PIC mode for SingletonThreadLocal

Summary:
[Folly] Disable TLS optimization in PIC mode for `SingletonThreadLocal`.

In PIC mode, TLS offsets must be translated to addresses at runtime via calls to `__tls_get_addr`. Since there is not much of a small inline path or a fast inline fast path anymore anyway in PIC mode, might as well skip the bulky slow caching.

Also, some versions of gcc do not properly support this code in shared libraries. Details in #1135 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90562.

Fixes #1135.

Reviewed By: andriigrynenko

Differential Revision: D15468086

fbshipit-source-id: 038e13f900fe56205c1333a620ea3bfa468c47ad
parent 41ed69c4
......@@ -25,6 +25,12 @@
#include <folly/detail/UniqueInstance.h>
#include <folly/functional/Invoke.h>
#if defined(FOLLY_TLS) && !(__GNUC__ && __PIC__)
#define FOLLY_DETAIL_SINGLETON_THREAD_LOCAL_USE_TLS 1
#else
#define FOLLY_DETAIL_SINGLETON_THREAD_LOCAL_USE_TLS 0
#endif
namespace folly {
/// SingletonThreadLocal
......@@ -129,7 +135,7 @@ class SingletonThreadLocal {
return *getWrapperTL();
}
#ifdef FOLLY_TLS
#if FOLLY_DETAIL_SINGLETON_THREAD_LOCAL_USE_TLS
FOLLY_NOINLINE static T& getSlow(Wrapper*& cache) {
static thread_local Wrapper** check = &cache;
CHECK_EQ(check, &cache) << "inline function static thread_local merging";
......@@ -141,7 +147,7 @@ class SingletonThreadLocal {
public:
FOLLY_EXPORT FOLLY_ALWAYS_INLINE static T& get() {
#ifdef FOLLY_TLS
#if FOLLY_DETAIL_SINGLETON_THREAD_LOCAL_USE_TLS
static thread_local Wrapper* cache;
return FOLLY_LIKELY(!!cache) ? *cache : getSlow(cache);
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment