-
-
Notifications
You must be signed in to change notification settings - Fork 416
Shared runtime #395
Shared runtime #395
Conversation
Woohooo! @dawgfoto thank you very much for this gift :) 👍 |
yes this is amazing tanks |
This is a good news, but what exatly now is supported and what not? |
AFAIK it's for link-time shared libraries. dlang/dmd#1043 was pulled before to make this happen. I guess @dawgfoto plans were to first implement link-time shared libraries and then pick up the runtime plugin-like loading See: http://forum.dlang.org/thread/hmhaldyfziejrplgzazt@forum.dlang.org?page=3#post-50EF5875.1060009:40dawg.eu |
I suspect that this would be made easier by have druntime be a shared library/DLL itself. That way, the gc and the thread management is automatically shared. |
That's really a necessity for any further shared library support and is addressed by this pull request. |
- core.sys.posix.dlfcn - fix linux-MIPS constants - deprecate non-POSIX function
- Store thread local list of self-registering libraries. The compiler provides ModuleInfos and EH tables. - Use dl_iterate_phdr to get further information from the runtime linker. - Iterate over program headers to find writeable segments, i.e. the one with GC roots. The program header also provides TLS module indices and the TLS segment size.
...to support weak linkage of compiler when using a multilib archive. Weak linking allows to incrementally introduce _d_dso_registry in the compiler and the runtime.
- they will contain all writeable PT_LOAD segments
- Create a small TLS helper in rt.dso of which each thread object contains one instance. Update TLS ranges in the GC signal handler because the TLS ranges might change while the thread is running. Some room for optimization: - Using TLS architecture dependent knowledge we might preserve the lazy allocation of TLS blocks.
- iterate over all shared libraries during function lookup
- This is needed to guarantee correct initialization of modules and identify library dependencies. - Abort the program with a detailed error message. Symbol collision bugs are hard to find so it's better to error out early.
- if set builds a shared libdruntime.so
- Use a modified unit test handler which allows to selectively run unit tests. This is necessary because a shared library contains the code for all compiled modules, thus the default unit tester would run everything at once.
|
Ideally this would apply to the runtime initialization itself too. It's a major refactoring though (main, rt_init, rt_term, rt_module...). |
I just looked at the newly committed that added the
Does that mean that |
It's the same on linux, thre compiler generates an init function that gets called for every shared library and executable. We will be able to distinguish these, the onAddImage comment is a rough hint about what needs to be done. |
How can you distinguish if a shared library is loaded using |
Because the initializer/finalizers of a linked shared library run before/after main. |
The current roadmap is link-time support for linux then FreeBSD (simple) then OSX then the init refactoring then we need to extend the GC so it can finalize memory regions (shared mem unloading, shared library unloading) then we can look into runtime loading. TLS might become difficult on OSX, has anyone tried to implement native support? AFAIK it is only available since 10.6. |
Aha, I see. Is that before/after the C main or the D main function? The |
No, not that I know. I created a ticket for it: 9476.
Unfortunately it's only available since 10.7. That means we would need to drop the support for 10.6. Although I think it's technically possible to do what the dynamic linker does in 10.7 in the D runtime. Then we could still support 10.6. If we actually want to do that is a different question. It seems Walter don't want to do that. |
What is the status of this?
|
My current status:
This currently does not work with 32 bit linux since LDIV trashes EBX, which violates PIC protocol. But I'll deal with that later. The main goal for the moment is to get 64 bit linux .so's to work. |
I'm ok with abandoning support for OSX 10.5 and less in order to support shared libraries with TLS. 10.6 appeared in Aug, 2009. That's nearly 4 years ago, an eternity in internet time. |
Ah, 10.7 is july 2011. Not so old. Hmmm. |
Unittests: I suggest simply building a special druntime.so with -unittest and running them all at once. |
I'll have to rebase/rewrite the last parts of this because of the changes done in the already pulled parts.
Yes, by passing SHARED=1 to make, but this has now been replaced by the dll target (#429).
Yes.
No. |
This is great progress. But we do need to make dll's dynamically loadable and unloadable. A major, major use case for dll's is to provide rapid development turnaround by being able to hot load/unload them while not needing to shut down and restart the whole thing. |
Let's get this pull request done. Then we can:
|
There is already a better solution. Building a druntime.so with -unittest and use an executable that only run the test passed as command-line argument, here 80950b8. That way we can keep makefile parallelism and reproducing bugs remains simple. |
What remains on this pull request to be merged? |
Everything that's not ticked in the task list above. (This pull request shouldn't be merged itself; it's a meta pull request.) |
That's not correct, some unticked ones have been merged, like the EH tables thing. |
A check of the commits shows that these are not merged:
Should they be merged? Where are we on this? I'd like to get this pull request resolved ASAP. |
I haven't rebased this for quite a while because the implementation changed a lot during reviewing/recoding/merging. |
a - none this already worked, create a b - same as (a) but inefficient because it uses multiple GCs and might easily cause ODR violations c - this pull request is the ground work to make it possible, we still need to implement static initialization |
This already bitrots for about a year and it's still very big.
Piecewise merging caused delays for several months and
I also lack an idea how to further split it down.
I thought we might try something different to make this reviewable.
This serves as Meta Pull Request, please don't pull it.
I'll create subsequent pull requests for each commit
which should get discussed and merged separately.
I'll regularly rebase this one until hopefully nothing is left.