| Ticket UUID: | 3579001 | ||
| Title: | Allow user choice for RTLD_GLOBAL / RTLD_LOCAL | ||
| Type: | RFE | Created on: | 2012-10-22 00:51:23 |
| Submitter: | Assigned to: | nijtmans | |
| Subsystem: | 40. Dynamic Loading | Severity: | |
| Priority: | 5 Medium | Last modified: | 2012-11-15 17:53:42 |
| Status: | Closed | Closed by: | nijtmans |
| Resolution: | Fixed | Closed on: | 2012-11-15 10:53:42 |
| Version: | None | ||
| Description: | ||||
This is similar to the feature request artifact id 3159088.
It would be very useful to allow users to control the flags passed to dlopen() when calling Tcl's load command.
One suggestion would be to add an optional -flags argument that accepts a list of values similar to the open command. Ex.
load myextension.so -flags { RTLD_GLOBAL RTLD_LAZY }
| ||||
| User Comments: | ||||
dkf added on 2012-10-22 19:26:23:
I'm not necessarily opposed to this, but I would note that this requires care because of the differences between different [load] implementations (if only it was always libdl…) nijtmans added on 2012-10-22 19:28:32:
1) Those flags are only available on UNIX, how should it be implemented on Windows/AIX/HP/....?? 2) The Tcl "load" command is only meant to load Tcl extensions, which typically export only Xxx_Init and maybe one or two more. I don't see that advantage that RTLD_GLOBAL/RTLD_LAZY would provide there. added on 2012-10-23 07:41:48:
This feature is very important for extensions that provide Tcl bindings to C++ interfaces. The extension links with the underlying C++ shared libs, and can behave badly if it is loaded with local symbol scoping (two copies of the same static variable in two different extensions). Other multi-platform scripting languages provide users with a way to control the flags passed to dlopen() on Unix platforms. For example: python (ctypes module) perl (sub dl_load_flags) ruby (DL module) Since some extensions behave badly with local symbol scoping and some behave badly with global, it makes sense to give the programmer the opportunity to choose between the two, depending on the application. It's fine if this is a Unix-only feature, as long as the documentation describes it as such. nijtmans added on 2012-10-23 15:04:02:
Understood. So it's really a -global flag you are after. added on 2012-10-24 00:15:00:
Thank you for your consideration. Yes, my primary concern is the ability to specify -global. However, RTLD_LAZY is also very useful for similar applications that provide C++ scripting bindings for Tcl. By being able to speciy lazy loadng, packages can work correctly with multiple versions of the underlying C++ shared libs. A user could use a newer build of the scripting API with an older version of the C++ shared libs, but would not run into missing symbol errors unless he or she actually tried invoking code belonging to the new API. Of course, this is also very application specific and would not be desirable in all situations. So, it makes sense to keep the default as-is now and provide an option for the programmer to select what is best for the application. Since these two features are closely related, I thought it would make sense to combine them into one request. But of course, my main concern is the ability to control global / local. nijtmans added on 2012-10-24 05:02:56:
I did some preparation for this on the Tcl trunk. See:
http://core.tcl.tk/tcl/info/4d417791c9
This makes it trivial to implement this Feature request, on
top of TIP #357: Export TclLoadFile. The only things
that is left to do is define the meaning of the "flags"
parameter, and translate that as needed in the
various tclLoad*.c implementations.
Still another TIP is needed to complete it, because
it modifies the "load" command. It could be integrated
with TIP #239: "Enhance the 'load' Command"
<http://www.tcl.tk/cgi-bin/tct/tip/239.html>
as well.
I don't think this will make Tcl 8.6, it certainly
should not delay the Tcl 8.6 release.......
nijtmans added on 2012-10-24 20:11:40:
experimental implementation in branch "frq-3579001)". See:
<http://core.tcl.tk/tcl/info/0895bccd51>
test-cases are updated, but nothing has been done on documentation yet.
New syntax:
load fileName ?-global? ?-lazy? ?packageName? ?interp?
added on 2012-10-24 20:43:05:
Thank you very much for your work here. Is there anything that I can do to help? nijtmans added on 2012-10-25 04:31:53:
Changed syntax in "frq-3579001" branch: It's more logical to expect the options before the filename. cdelbaere, what is your email address? Please mail it privately to me. nijtmans added on 2012-11-02 20:32:32:
Test report from Christian: Hi Jan, I performed some manual testing on the new implementation of the load command using a set of loadable modules in a software package that I am working on. I can tell by the behavior of some of my internal testcases which flags are passed to dlopen(). All of the following combinations work as expected: load module.so load -global module.so load -lazy module.so load -global -lazy module.so load -lazy -global module.so Also, load -- module.so load -global -- module.so load -lazy -- module.so load -lazy -global -- module.so The default is still local + now symbol loading (correct) The -global flag loads the libraries symbols with global scoping (correct) The -lazy flag correctly ignores missing symbols until the code is actually called (correct) Regards, Christian nijtmans added on 2012-11-15 17:53:42:
allow_comments - 1 Implementation is on trunk now, to be released with Tcl 8.6.0 | ||||
