[D-runtime] druntime ModuleInfo discovery without bracketing segments

David Nadlinger code at klickverbot.at
Fri Jun 14 05:58:52 PDT 2013


Hi Martin,

I'm working on the LDC 2.063 merge right now, and it would obviosuly
be nice to finally support shared libraries in LDC as well (PIC/shared
object codegen works since ages ago, but runtime support was missing
so far).

However, I would like to avoid the use of bracketing sections/symbols
for locating the ModuleInfos of all the linked modules (we don't need
to handle EH tables anyway). While it is certainly possible to crack
open the default LLVM object file emission pipeline and directly write
out some custom data in an object file format dependent way, this
would also mean that we cannot use the standard LLVM tools for
generating object files from bitcode (LLVM IR) anymore, which would be
quite annoying for tooling.

Thus, I thought about using a scheme where there is one global (C
runtime) ctor per module just like there is in the old one. Instead of
setting up the _Dmodule_ref chain directly, it would call the
equivalent of _d_dso_registry. If a DSO info record (struct DSO in
sections_linux) has not been initialized for the given image yet, the
function would set it up, and in any case add the passed ModuleInfo*
to a pointer array in the record.

While I'm quite sure this would work for load-time bound shared
objects, I didn't really think about the dlopen() case yet. Do you
think this would be feasible, or do you have any better ideas?

Thanks,
David


More information about the D-runtime mailing list