D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17061 - dlopen: cannot load any more object with static TLS
Summary: dlopen: cannot load any more object with static TLS
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-05 18:21 UTC by Timothee Cour
Modified: 2024-12-13 18:51 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timothee Cour 2017-01-05 18:21:01 UTC
pseudo-code:

```
main.cpp:
dlopen(dlib.so)
dlsym(fun)

dlib.d:
fun(){
  dlopen(dlib2.so);
  // dlopen: cannot load any more object with static TLS
}

dlib2.d:
void fun2(){}
```

Is there a workaround?
Comment 1 Timothee Cour 2017-01-05 18:36:37 UTC
found workaround here in a different context:

http://stackoverflow.com/questions/19268293/matlab-error-cannot-open-with-static-tls/36769074#36769074

the workaround is to add `LD_PRELOAD=dlib2.so` before calling the binary

LD_PRELOAD=dlib2.so main

Is there anything better?
Comment 2 Timothee Cour 2017-01-05 19:34:19 UTC
obviously LD_PRELOAD trick doesn't work if the lib2.so needs to be recompiled while code is running;

LINKS:
http://stackoverflow.com/questions/22983986/is-there-a-way-to-determine-thread-local-storage-model-used-by-a-library-on-linu
https://lists.freebsd.org/pipermail/freebsd-arch/2016-February/017699.html
https://gcc.gnu.org/ml/gcc-help/2007-08/msg00014.html
https://www.cygwin.com/ml/libc-help/2013-11/msg00033.html

1) Rebuild glibc with more default static TLS storage. e.g. Increase DTV_SURPLUS until it works.

2) Rebuild your dependent libraries so that they don't use initial-exec
TLS model. It's a good optimization but it makes those DSOs unloadable
when you run out of surplus slots to load them into (and no you can't
expand the number of slots because of the way initial-exec optimizes
the TLS accesses).

How would we do option 2?

SCRATCH:
-ftls-model=initial-exec
Comment 3 dlangBugzillaToGithub 2024-12-13 18:51:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19225

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB