Browse Source

* win/systhrd.inc: modified ThreadMain so it initializes RTL if not already done, allowing TLS callbacks to be optional.
* win/syswin.inc: added a workaround for buggy ld on win64, see comments in source for details.

git-svn-id: trunk@18019 -

sergei 14 years ago
parent
commit
ef48f93d85
2 changed files with 26 additions and 7 deletions
  1. 9 7
      rtl/win/systhrd.inc
  2. 17 0
      rtl/win/syswin.inc

+ 9 - 7
rtl/win/systhrd.inc

@@ -210,13 +210,15 @@ var
         { Copy parameter to local data }
         ti:=pthreadinfo(param)^;
 
-        { Allocate local thread vars, this must be the first thing,
-          because the exception management and io depends on threadvars }
-{$ifndef FPC_USE_TLS_DIRECTORY}
-        SysAllocateThreadVars;
-        { Initialize thread }
-        InitThread(ti.stklen);
-{$endif}
+        { Handle all possible threadvar models:
+          - dynamic threadvars: initialized either in DllMain,
+            or upon accessing the threadvar ThreadID;
+          - static threadvars+TLS callback: initialized in TLS callback;
+          - static threadvars, no callback: ThreadID remains 0 and
+            initialization happens here. }
+        if ThreadID=TThreadID(0) then
+          InitThread(ti.stklen);
+
         dispose(pthreadinfo(param));
 
         { Start thread function }

+ 17 - 0
rtl/win/syswin.inc

@@ -156,6 +156,23 @@ const
     flags : 0;
   ); cvar; public;
 
+{$ifdef win64}
+  { This is a hack to support external linking.
+    All released win64 versions of GNU binutils miss proper prefix handling
+    when searching for _tls_used and expect two leading underscores.
+    The issue has been fixed in binutils snapshots, but not released yet.
+
+    TODO: This should be removed as soon as next version of binutils (>2.21) is
+    released and we upgrade to it. }
+    __tls_used : TTlsDirectory = (
+      data_start : @tls_data_start;
+      data_end : @tls_data_end;
+      index_pointer : @_tls_index;
+      callbacks_pointer : @tls_callbacks;
+      zero_fill_size : 0;
+      flags : 0;
+    ); cvar; public;
+{$endif win64}
 {$endif FPC_USE_TLS_DIRECTORY}