On 2/20/25 7:16 AM, Julian Waters wrote:
Patch with the amendments to the commit message as requested.
best regards,
Julian
From e8e742b1f809af2c1a9697c31335e184738b258a Mon Sep 17 00:00:00 2001
From: Julian Waters <tanksherma...@gmail.com>
Date: Tue, 15 Oct 2024 20:56:22 +0800
Subject: [PATCH] Implement Windows TLS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This patch implements native Thread Local Storage access on Windows, as
motivated by
PR80881. Currently, Thread Local Storage accesses on Windows relies on
emulation, which
is detrimental to performance in certain applications, notably the Python
Interpreter
and the gcc port of the Java Virtual Machine. This patch was heavily inspired
by Daniel
Green's original work on native Windows Thread Local Storage from over a decade
ago, which
can be found at
https://github.com/venix1/MinGW-GDC/blob/master/patches/mingw-tls-gcc-4.8.patch
as a reference.
gcc/ChangeLog:
* config/i386/i386.cc (ix86_legitimate_constant_p): Handle new UNSPEC.
(legitimate_pic_operand_p): Handle new UNSPEC.
(legitimate_pic_address_disp_p): Handle new UNSPEC.
(ix86_legitimate_address_p): Handle new UNSPEC.
(ix86_tls_index_symbol): New symbol for _tls_index.
(ix86_tls_index): Handle creation of _tls_index symbol.
(legitimize_tls_address): Create thread local access sequence.
(output_pic_addr_const): Handle new UNSPEC.
(i386_output_dwarf_dtprel): Handle new UNSPEC.
(i386_asm_output_addr_const_extra): Handle new UNSPEC.
* config/i386/i386.h (TARGET_WIN32_TLS): Define.
* config/i386/i386.md: New UNSPEC.
* config/i386/predicates.md: Handle new UNSPEC.
* config/mingw/mingw32.h (TARGET_WIN32_TLS): Define.
(TARGET_ASM_SELECT_SECTION): Define.
(DEFAULT_TLS_SEG_REG): Define.
* config/mingw/winnt.cc (mingw_pe_select_section): Select proper TLS
section.
(mingw_pe_unique_section): Handle TLS section.
* config/mingw/winnt.h (mingw_pe_select_section): Declare.
* configure: Regenerate.
* configure.ac: New check for broken linker thread local support
Co-authored-by: Eric Botcazou <botca...@adacore.com>
Co-authored-by: Uroš Bizjak <ubiz...@gmail.com>
Co-authored-by: Liu Hao <lh_mo...@126.com>
Signed-off-by: Julian Waters <tanksherma...@gmail.com>
diff --git a/gcc/configure.ac b/gcc/configure.ac
index bdb22d53e2c..00bfa452691 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -4166,6 +4166,35 @@ else
[$tls_as_opt], [$conftest_s],,
[set_have_as_tls=yes])
fi
+case $target_os in
+ win32 | pe | cygwin* | mingw32*)
+ if test $set_have_as_tls = yes; then
+ # Hack to check whether ld breaks on @secrel32 for Windows
+ if test $in_tree_ld = yes; then
+ if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 44
-o "$gcc_cv_gld_major_version" -gt 2; then
+ : # ld support for @secrel32 was fixed in this version
+ else
+ AC_MSG_ERROR([ld version is known to have broken secrel32
relocations, configure without --enable-tls or with --disable-tls to remove
this error])
+ fi
+ elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x;
then
+ echo '.text' > conftest.s
+ echo 'foo: nop' >> conftest.s
+ echo '.data' >> conftest.s
+ echo '.secrel32 foo' >> conftest.s
+ if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1 && $gcc_cv_ld -o
conftest.exe conftest.o > /dev/null; then
+ if $gcc_cv_objdump -h conftest.exe | grep '\.reloc\>' > /dev/null;
then
+ AC_MSG_ERROR([ld has broken secrel32 relocations, configure without
--enable-tls or with --disable-tls to remove this error])
+ fi
+ else
+ AC_MSG_ERROR([Error occurred while checking for broken secrel32
relocations])
+ fi
+ rm -f conftest.s conftest.o conftest.exe
+ else
+ AC_MSG_ERROR([Cannot check for broken secrel32 relocations to determine
support for --enable-tls])
+ fi
+ fi
+ ;;
+esac
if test $set_have_as_tls = yes ; then
AC_DEFINE(HAVE_AS_TLS, 1,
[Define if your assembler and linker support thread-local storage.])
Please also include a reference to the bugzilla ticket (or any link) for
the ld broken secrel32 issue in the error message, thanks.