Win64 TLS section_threadvars implementation
Original Reporter info from Mantis: Sergey Larin @sergy.larin
-
Reporter name: Sergey Larin
Original Reporter info from Mantis: Sergey Larin @sergy.larin
- Reporter name: Sergey Larin
Description:
This patch offers native threadvar implementation for Windows x64 with partial use of the existing "section_threadvars" functionality.
Additional information:
Using SECTION_THREADVAR for Win64 is enabled if you define TEST_WIN64_SECTION_THREADVAR and do not define SUPPORT_WINXP.
Later, if necessary, it will be possible to rename TEST_WIN64_SECTION_THREADVARS to tls_threadvars as in i_linux.pas and i_bsd.pas
On Windows Vista and later, dynamically-loaded DLLs via LoadLibrary also full support Thread Local Storage.
Therefore, if someone still needs support for Windows XP (x64), then you need to define SUPPORT_WINXP and the old threadvars implementation will be used.
The unfinished and probably never used previous "native threadvar implementation" added in rev. 23359 has been completely removed.
SECREL32 relocation support is added in both AT&T asmoutput and Internal assembler.
In TDebugInfoDwarf.appendsym_var_with_name_type_offset, the target_info.system in [system_x86_64_win64]
check is added, otherwise an internalerror(200905071) occurs in TCoffObjOutput.section_write_relocs.
In node_complexity, the estimation of the complexity of using threadvar has been changed. If the helper call is required, then the estimate is greatly increased (offhand 10 times), because the previous value was clearly underestimated.
If you specify that you need to use old binutils (cs_asm_re_binutils_2_25), then using SECREL32 relocation fails. Erroneous offsets are generated. Tested on version 2.21
It turned out that the Internal linker cannot be used in its current state. Offsets for $threadvar@secrel32
,_tls_index(%rip)
are generated incorrectly, and an "Incompatible section options" error occurs in TExeSection.AddObjSection.
The presented patch did not fix problems with the Internal linker.
In this regard, an External linker was used (ld.exe)
There was also a problem that the tls callback FreePascal_TLS_callback is not called if an external linker (ld.exe) is used. This error apparently was always regardless of this patch.
A workaround is provided in the tls_callback-ld-workaround.patch
Mantis conversion info:
- Mantis ID: 37469
- OS: Windows
- OS Build: 10
- Platform: x86_64
- Version: 3.3.1
- Monitored by: » trx (Svetozar Belic), » Cyrax (Cyrax)