Artifacts Associated With Ticket 1967630fff
Ticket change [804746f45f] (rid 97713) by georgeps on 2008-05-20 04:15:19:
- assignee initialized to: "kennykb"
- cmimetype initialized to: "text/plain"
- comment initialized 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.
- foundin initialized to: "obsolete: 8.6a0"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "georgeps"
- subsystem initialized to: "40. Dynamic Loading"
- title initialized to: "tclLoadDl.c dlerror() is not thread safe"
- type initialized to: "Bug"
Ticket change [e7ab4b0185] (rid 104506) by georgeps on 2008-05-20 11:15:19:
- icomment:
File Added - 278384: tclLoadDl-2.patch
- login: "georgeps"
- mimetype: "text/plain"
- username: "georgeps"
- icomment:
Add attachment "tclLoadDl-2.patch" [d513c36499] (rid 123553) by georgeps on 2008-05-20 11:15:19.
Ticket change [5357e64dab] (rid 93740) by nijtmans on 2008-05-20 14:59:00:
- icomment:
Logged In: YES user_id=61031 Originator: NO In functions like TclLoadFile and TclpLoadFile, TclpFindSymbol() is used multiple times and is not expected to modify the interp result. At least those functions need to be modified to reset the interp result after the last TclpFindSymbol() call. Further on, the same modification will be needed in tclLoadDyld.c as well (if the Mac-implementation is not thread-safe), and the TclpFindSymbol change is needed in tclLoadNext.c, tclLoadOSF.c, tclLoadShl.c and tclWinLoad.c as well. In practice, I doubt that this ever will be a practical problem, because normally all libraries are loaded in a single thread at start-up. But - strictly speaking - yes, I agree that the mutex should be there and TclpFindSymbol should leave an error-message in interp result as documented. Regards, Jan Nijtmans - login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment:
Ticket change [f7caeb8c52] (rid 260426) by serhiy.storchaka on 2026-10-25 11:49:46:
- foundin changed to: "9.1.0"
- icomment:
Reproduced on NetBSD 10.1 and OpenBSD 7.9, where the dlerror() state is process-wide: a failing [load] concurrent with a successful [load] in another thread gets the other thread's message or NULL, and NULL crashes in Tcl_ObjPrintf(). Linux, FreeBSD and macOS keep it per thread. Proposed fix in branch [/timeline?r=unix-dlerror-mutex|unix-dlerror-mutex], based on the attached patch: a mutex from dlopen()/dlsym() until dlerror() has been read, and "unknown" for a NULL message. It only covers Tcl's own calls, not dlopen() by other code in the process.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [b497022b33] (rid 260751) by jan.nijtmans on 2026-10-28 21:07:40:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461342.3803275349"
- closer changed to: "jan.nijtmans"
- 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.
- icomment:
Fixed in [e0e0341124|trunk], core-9-0-branch and core-8-6-branch Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- severity changed to: "Minor"
- status changed to: "Closed"