Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b497022b334f22ea223762a4acaeddf60fce2bf84dd1adc21f520ea9928c073e
Ticket: 1967630fffffffffffffffffffffffffffffffff
tclLoadDl.c dlerror() is not thread safe
User & Date: jan.nijtmans on 2026-10-28 21:07:40
Changes

  1. assignee changed to: "jan.nijtmans"
  2. closedate changed to: "2461342.3803275349"
  3. closer changed to: "jan.nijtmans"
  4. comment changed to:
    According to the standard for dlerror(), it's not required to be thread-safe.  
    http://www.opengroup.org/onlinepubs/009695399/functions/dlerror.html
    
    I also checked several open source libc.  NetBSD and OpenBSD don't use thread-specific storage for dlerror messages, but the GNU/Linux glibc does.
    
    Attached is a patch to fix the problem.  It drains the dlerror() first after entering the critical region.
    
    The Linux usage suggested is slightly different than what BSD seems to suggest.  The glibc dlsym manual suggests using dlerror to indicate the success or failure of a dlsym(), rather than NULL from the return of dlsym(), because apparently dlsym() can return 0/NULL and still have succeeded (with some symbols).  So the logic should probably be changed further based on what the glibc docs say.
    
    This is the example taken from the manual for dlsym:
     dlerror();    /* Clear any existing error */
     cosine = dlsym(handle, "cos");
     if ((error = dlerror()) != NULL)
       ...
      
    
    I also added error handling to TclpFindSymbol().  It appears to be unfinished prior to this, or the usage expectations of it have changed, because in the HEAD it doesn't use the interp argument to report an error like the (outdated?) comments state.
    
  5. icomment:
    Fixed in [e0e0341124|trunk], core-9-0-branch and core-8-6-branch
    
    Many thanks!
    
  6. login: "jan.nijtmans"
  7. mimetype: "text/x-fossil-wiki"
  8. resolution changed to: "Fixed"
  9. severity changed to: "Minor"
  10. status changed to: "Closed"