diff --git a/rtl/linux/i386/si_prc.inc b/rtl/linux/i386/si_prc.inc index ae0531dd9e..1639445a70 100644 --- a/rtl/linux/i386/si_prc.inc +++ b/rtl/linux/i386/si_prc.inc @@ -45,7 +45,9 @@ var procedure fpc_geteipasebxlocal; [external name 'fpc_geteipasebx']; {$endif} +{$ifndef FPC_USE_LIBC} procedure InitTLS; [external name 'FPC_INITTLS']; +{$endif} procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; asm @@ -95,9 +97,9 @@ asm movl %esp,initialstkptr {$endif FPC_PIC} -{$if FPC_FULLVERSION>30200} +{$if (FPC_FULLVERSION>30200) and not defined(FPC_USE_LIBC)} call InitTLS -{$endif FPC_FULLVERSION>30200} +{$endif FPC_FULLVERSION>30200 and not FPC_USE_LIBC} xorl %ebp,%ebp call PASCALMAIN diff --git a/rtl/linux/si_impl.inc b/rtl/linux/si_impl.inc index a727310551..2b19deaf10 100644 --- a/rtl/linux/si_impl.inc +++ b/rtl/linux/si_impl.inc @@ -16,7 +16,9 @@ procedure PascalMain; external name 'PASCALMAIN'; {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION} procedure SysEntry(constref info: TEntryInformation); external name 'FPC_SysEntry'; +{$ifndef FPC_USE_LIBC} procedure SysEntry_InitTLS(constref info: TEntryInformation); external name 'FPC_SysEntry_InitTLS'; +{$endif FPC_USE_LIBC} var InitFinalTable : record end; external name 'INITFINAL'; diff --git a/rtl/linux/system.pp b/rtl/linux/system.pp index caa4e116c7..4303c61147 100644 --- a/rtl/linux/system.pp +++ b/rtl/linux/system.pp @@ -125,6 +125,9 @@ procedure OsSetupEntryInformation(constref info: TEntryInformation); forward; TLS handling *****************************************************************************} +{ TLS initialization is not required if linking against libc } +{$if not defined(FPC_USE_LIBC)} + {$if defined(CPUARM)} {$define INITTLS} Function fpset_tls(p : pointer;size : SizeUInt):cint; @@ -185,6 +188,8 @@ begin end; {$endif defined(CPUX86_64)} +{$endif not FPC_USE_LIBC} + {$ifdef INITTLS} { This code initialized the TLS segment for single threaded and static programs. @@ -323,6 +328,8 @@ begin info.PascalMain(); end; + +{$ifndef FPC_USE_LIBC} procedure SysEntry_InitTLS(constref info: TEntryInformation);[public,alias:'FPC_SysEntry_InitTLS']; begin SetupEntryInformation(info); @@ -334,6 +341,7 @@ begin {$endif cpui386} info.PascalMain(); end; +{$endif FPC_USE_LIBC} {$else} var @@ -361,6 +369,7 @@ begin end; +{$ifdef FPC_USE_LIBC} procedure SysEntry_InitTLS(constref info: TEntryInformation);[public,alias:'FPC_SysEntry_InitTLS']; begin initialstkptr := info.OS.stkptr; @@ -375,6 +384,7 @@ begin {$endif cpui386} info.PascalMain(); end; +{$endif FPC_USE_LIBC} {$endif FPC_BOOTSTRAP_INDIRECT_ENTRY} diff --git a/rtl/linux/x86_64/si_prc.inc b/rtl/linux/x86_64/si_prc.inc index 1864e9d559..71804c1343 100644 --- a/rtl/linux/x86_64/si_prc.inc +++ b/rtl/linux/x86_64/si_prc.inc @@ -35,7 +35,9 @@ {$L abitag.o} +{$ifndef FPC_USE_LIBC} procedure InitTLS; [external name 'FPC_INITTLS']; +{$endif} {****************************************************************************** Process start/halt @@ -73,7 +75,11 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; movq %r10,%rdi xorq %rbp, %rbp +{$ifdef FPC_USE_LIBC} + call SysEntry +{$else} call SysEntry_InitTLS +{$endif} {$else FPC_HAS_INDIRECT_ENTRY_INFORMATION} popq %rsi { Pop the argument count. } movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rax @@ -90,9 +96,9 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; movq initialstkptr@GOTPCREL(%rip),%rax movq %rsp,(%rax) -{$if FPC_FULLVERSION>30200} +{$if (FPC_FULLVERSION>30200) and not defined(FPC_USE_LIBC)} call InitTLS -{$endif FPC_FULLVERSION>30200} +{$endif FPC_FULLVERSION>30200 and not FPC_USE_LIBC} xorq %rbp, %rbp call PASCALMAIN