Skip to content

Commit

Permalink
Bug 1880420 - Move __thread detection to moz.configure r=glandium
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Feb 28, 2024
1 parent a00a559 commit d5721c6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 64 deletions.
32 changes: 32 additions & 0 deletions build/moz.configure/toolchain.configure
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,38 @@ set_config("WRAP_SYSTEM_INCLUDES", wrap_system_includes)
set_config("VISIBILITY_FLAGS", visibility_flags)


# try harder, when checking for __thread support, see bug 521750 comment #33 and below
# We pass linker_optimize_flags to the linker because if dead_strip is
# enabled, the linker in xcode 4.1 will crash. Without this it would crash when
# linking XUL.


@depends(target, c_compiler)
def check_thread(target, c_compiler):
if target.cpu in ("mips32", "mips64"):
# mips builds fail with TLS variables because of a binutils bug.
# See bug 528687
return False
if target.os == "Android":
# The custom dynamic linker doesn't support TLS variables
return False
if target.kernel == "OpenBSD":
# OpenBSD doesn't have TLS support, and the test succeeds with clang++
return False
return c_compiler.type != "clang-cl"


set_define(
"HAVE_THREAD_TLS_KEYWORD",
try_link(
body="static __thread bool tlsIsMainThread = false; return tlsIsMainThread;",
flags=linker_optimize_flags.ldflags,
check_msg="for __thread keyword for TLS variables",
when=check_thread,
),
)


@template
def depend_cflags(host_or_target_c_compiler):
@depends(host_or_target_c_compiler)
Expand Down
29 changes: 0 additions & 29 deletions js/src/old-configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -697,35 +697,6 @@ if test "$GNU_CC"; then
TARGET_COMPILER_ABI="${TARGET_COMPILER_ABI-${ARM_ABI_PREFIX}gcc3}"
fi

# try harder, when checking for __thread support, see bug 521750 comment #33 and below
# We pass MOZ_OPTIMIZE_LDFLAGS to the linker because if dead_strip is
# enabled, the linker in xcode 4.1 will crash. Without this it would crash when
# linking XUL.
_SAVE_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
AC_CACHE_CHECK(for __thread keyword for TLS variables,
ac_cv_thread_keyword,
[AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
[return tlsIsMainThread;],
ac_cv_thread_keyword=yes,
ac_cv_thread_keyword=no)])
LDFLAGS=$_SAVE_LDFLAGS
if test "$ac_cv_thread_keyword" = yes; then
# mips builds fail with TLS variables because of a binutils bug.
# See bug 528687
case "${target}" in
mips*-*)
:
;;
*-android*|*-linuxandroid*)
:
;;
*)
AC_DEFINE(HAVE_THREAD_TLS_KEYWORD)
;;
esac
fi

dnl End of C++ language/feature checks
AC_LANG_C

Expand Down
2 changes: 1 addition & 1 deletion mfbt/ThreadLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ inline void ThreadLocal<T, Storage>::set(const T aValue) {
# define MOZ_THREAD_LOCAL(TYPE) \
thread_local ::mozilla::detail::ThreadLocal< \
TYPE, ::mozilla::detail::ThreadLocalNativeStorage>
#elif defined(HAVE_THREAD_TLS_KEYWORD)
#elif defined(HAVE_THREAD_TLS_KEYWORD) && !defined(MOZ_LINKER)
# define MOZ_THREAD_LOCAL(TYPE) \
__thread ::mozilla::detail::ThreadLocal< \
TYPE, ::mozilla::detail::ThreadLocalNativeStorage>
Expand Down
1 change: 1 addition & 0 deletions moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ include("build/moz.configure/flags.configure", when="--enable-compile-environmen
include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
# rust.configure is included by js/moz.configure.


option("--enable-valgrind", help="Enable Valgrind integration hooks")

valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
Expand Down
34 changes: 0 additions & 34 deletions old-configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -724,40 +724,6 @@ if test "$GNU_CC"; then
TARGET_COMPILER_ABI="${TARGET_COMPILER_ABI-${ARM_ABI_PREFIX}gcc3}"
fi

# try harder, when checking for __thread support, see bug 521750 comment #33 and below
# We pass MOZ_OPTIMIZE_LDFLAGS to the linker because if dead_strip is
# enabled, the linker in xcode 4.1 will crash. Without this it would crash when
# linking XUL.
_SAVE_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $DSO_LDOPTS $MOZ_OPTIMIZE_LDFLAGS"
AC_CACHE_CHECK(for __thread keyword for TLS variables,
ac_cv_thread_keyword,
[AC_TRY_LINK([__thread bool tlsIsMainThread = false;],
[return tlsIsMainThread;],
ac_cv_thread_keyword=yes,
ac_cv_thread_keyword=no)])
LDFLAGS=$_SAVE_LDFLAGS
# The custom dynamic linker doesn't support TLS variables
if test "$ac_cv_thread_keyword" = yes -a "$MOZ_LINKER" != 1; then
# mips builds fail with TLS variables because of a binutils bug.
# See bug 528687
# OpenBSD doesn't have TLS support, and the test succeeds with clang++
case "${target}" in
mips*-*)
:
;;
*-android*|*-linuxandroid*)
:
;;
*-openbsd*)
:
;;
*)
AC_DEFINE(HAVE_THREAD_TLS_KEYWORD)
;;
esac
fi

if test -n "$MOZ_LINKER"; then
dnl gold emits wrong sysv-style elf hash tables when building both sysv and
dnl style tables. https://sourceware.org/bugzilla/show_bug.cgi?id=13597
Expand Down

0 comments on commit d5721c6

Please sign in to comment.