www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5485] New: TLS sections handled incorrectly

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485

           Summary: TLS sections handled incorrectly
           Product: D
           Version: D2
          Platform: Other
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



Created an attachment (id=879)
git format-patch

In src/core/thread.d:
_tlsstart/_tlsend should be handled same as for linux elf.

-                    extern void* _tlsstart;
-                    extern void* _tlsend;
+                    extern __thread int _tlsstart;
+                    extern __thread int _tlsend;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



17:09:58 PST ---
__thread is the default for D2, so this patch doesn't do anything.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |braddr puremagic.com
         Resolution|INVALID                     |



---
So, the obvious follow up here is that the existing __thread parts from the
other _tlsstart and _tlsend declarations should be yanked as pointless:

diff --git a/src/core/thread.d b/src/core/thread.d
index a317306..911efb3 100644
--- a/src/core/thread.d
+++ b/src/core/thread.d
   -130,8 +130,8    version( Windows )
             //       these are defined in dm\src\win32\tlsseg.asm by DMC.
             extern (C)
             {
-                extern __thread int _tlsstart;
-                extern __thread int _tlsend;
+                extern int _tlsstart;
+                extern int _tlsend;
             }
         }
         else
   -251,8 +251,8    else version( Posix )
             {
                 extern (C)
                 {
-                    extern __thread int _tlsstart;
-                    extern __thread int _tlsend;
+                    extern int _tlsstart;
+                    extern int _tlsend;
                 }
             }
             else version( OSX )

Also, how about the int vs void* difference?  From the look of the usage
pattern, it probably doesn't matter, but it does stand out as a difference.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485




Sorry, shouldn't have cited only part of the patch.
The important difference is in "void[] thread_getTLSBlock()".
_tlsstart/_tlsend are used directly as pointers to the TLS section.
But instead the address of the symbols should be taken.
Please have a look at the attachment and things should be clear.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



07:08:53 PST ---
Sorry, that thread_getTLSBlock function was mine (used to prune the LRU cache
for array appending during a collection cycle).  I misinterpreted the
difference between _tlsstart/_tlsend in FreeBSD being a pointer meaning that it
points to where tls starts/ends.  I never tested it, since I don't have a
FreeBSD system.

I think the patch should be applied.  It won't affect anything other than the
thread_getTLSBlock function, as the code that assigns the Thread.m_tls member
already correctly uses the address of the _tlsstart and _tlsend to determine
the block, not the values as I have done.

I'd apply the patch, but I have yet to take the time to learn git.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

          mime type|                            |

              patch|                            |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 20 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5485


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED



---
https://github.com/D-Programming-Language/druntime/commit/7d46be0ee4ba4a59a39f99d92756685c7452bcc8

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 20 2011