[Bug modula2/108183] wrong code generated in the modula2 scaffold mechanism

iains at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 20 09:36:05 GMT 2022


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

--- Comment #4 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Gaius Mulley from comment #3)
> The scaffold array (referencing each module ctor) is generated
> gcc/m2/gm2-compiler/M2Quads.mod:2402 and ctors are created in: 
> gcc/m2/gm2-gcc/m2decl.cc

terms was one example (of several cases)

I had already found the code in M2Quads & Scaffold and m2decl.cc.

However, not being familiar with m2 (or the design here) .. that was not
leading me to the right code.

It seems that m2decl_DeclareModuleCtor is only called for the module that *is*
in the current TU (so Hello, in the case of a hello world example).  I've tried
putting breakpoints on m2decl_BuildEndFunctionDeclaration() [which seems to be
called for some of the actors, but I do not (for example) see a call for
_M2_termios_ctor).

In the termios.cc file:

struct _M2_termios_ctor { _M2_termios_ctor (); } _M2_termios_ctor;

the symbol '_M2_termios_ctor' does not seem to refer to a function, but to a
static instance of struct _M2_termios_ctor .. so I'm still confused about what
is supposed to happen.

===

extern "C" void
_M2_termios_init (int, char *[], char *[])
{
}

extern "C" void
_M2_termios_fini (int, char *[], char *[])
{
}

extern "C" void
_M2_termios_dep (void)
{
}

struct _M2_termios_ctor { _M2_termios_ctor (); } _M2_termios_ctor;

_M2_termios_ctor::_M2_termios_ctor (void)
{
//  M2RTS_RegisterModule ("termios", _M2_termios_init, _M2_termios_fini,
//                      _M2_termios_dep);
}

===

        .globl __M2_termios_fini
__M2_termios_fini:
        ret

        .globl __M2_termios_dep
__M2_termios_dep:
        ret

// here are the CTORs...

        .align 1,0x90
        .globl __ZN16_M2_termios_ctorC2Ev
__ZN16_M2_termios_ctorC2Ev:
        ret

        .align 1,0x90
        .globl __ZN16_M2_termios_ctorC1Ev
__ZN16_M2_termios_ctorC1Ev:
        ret:

// and here is the external symbol __M2_termios_ctor
// (ignore the extra leading '_' that's an ABI thing)

        .globl __M2_termios_ctor
        .zerofill __DATA,__common,__M2_termios_ctor,1,0


More information about the Gcc-bugs mailing list