Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlopen: cannot load any more object with static TLS #19225

Open
dlangBugzillaToGithub opened this issue Jan 5, 2017 · 2 comments
Open

dlopen: cannot load any more object with static TLS #19225

dlangBugzillaToGithub opened this issue Jan 5, 2017 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Timothee Cour (@timotheecour) reported this on 2017-01-05T18:21:01Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=17061

CC List

  • Timothee Cour

Description

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?
@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 2017-01-05T18:36:37Z

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?

@dlangBugzillaToGithub
Copy link
Author

timothee.cour2 commented on 2017-01-05T19:34:19Z

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant