https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108261

--- Comment #9 from Gaius Mulley <gaius at gcc dot gnu.org> ---

I wonder if:

0.  change link array to contain elements of
    { char *name, (*fn) module_init, (*fn) module_fini }.

1.  add new option for gm2 -flibname=foo when creating libraries.
    libname is buried inside the object.
    So we can build:
    gm2 -o iso/Storage.o  ../iso/Storage.mod  -flibname=iso
    build libiso from iso/*

    gm2 -o pim/Storage.o  ../pim/Storage.mod  -flibname=pim
    build libpim from pim/*

2.  change the per module ctor to pass the libname in the call to
    M2RTS_RegisterModule (modname, libname: ADDRESS;
                          init, fini: ArgCVEnvP;
                          dependencies: PROC) ;

3.  change M2RTS.def/mod:
       ConstructModules (applicationmodule, flibs: ADDRESS;
                         argc: INTEGER; argv, envp: ADDRESS) ;

4.  driver passes -flibs=pim,iso,etc to cc1gm2
    cc1gm2 emeddeds this string into the main when constructing
    scaffold and call M2RTS_ConstructModules with the string
    -flibs=... as the extra parameter.

5.  M2RTS_ConstructModules uses (in order):

       (a)  contents of link array (if it exists) as a dictionary
            lookup based on name -> init function.
       (b)  if the module name does not exist in the link array then
            it chooses the module which has registered itself and
            whose libname is earliest on the flibs path.

    the driver will have to link the libraries in flibs order to
    choose the dialect specific module versions.


6.  I think we have to retain the m2pimlib.a m2isolib.a as there are
    a few modules with the same name but different interface
    (Storage).  However as you mentioned we could split them:
    -lm2pim -lm2iso -lm2common.  In part this is how they were
    designed (but never split up).  There are a number of rtName
    (runtime) modules:  rtCo, rtEntity etc and these could be expanded
    as required to provide a better layered approach.  The rt modules
    were never expected to be presented to users.

I'm encouraged that -fscaffold-static fixes the shared library usage.
-fscaffold-static is in effect a similar solution to (0) above.

Reply via email to