From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CE6A93858284; Sat, 24 Dec 2022 17:19:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE6A93858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671902358; bh=547RgiLkuh7JpFzEmGCGoFt1PIJ4VLEImj5q5qEmb6g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=W4nmfI0e0xLHgoUH8Sfh17RQBXg+m61Sb2pMZsekWqaIJeYuOs3p/e5mDijuGeKEY QgrN7AXjr0a7o0t/6qBRJimxzc/dMW9V6uLl5OAmTl6EEU3gPxTsGysQ0LG+HmrPZY aPvItFd6TlpJMs8rxp7ofZvZCmfZVaaBdQtibAdY= From: "iains at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug modula2/108183] wrong code generated in the modula2 scaffold mechanism Date: Sat, 24 Dec 2022 17:19:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: modula2 X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: assemble-failure X-Bugzilla-Severity: normal X-Bugzilla-Who: iains at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: gaius at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108183 --- Comment #14 from Iain Sandoe --- coming back to this code: =3D=3D=3D 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); } =3D=3D=3D=3D I think this is not currently doing what is expected (it's certainly inconsistent with the compiler's PoV .. from my debugging). ---- The declaration in the compiler thinks that _M2_termios_ctor is the symbol = for a function. Where (because of the way this shim is written) it's actually = the name of a static variable. Which means if it was ever called "boom".=20 However, my current understanding us that M2_link() is just a mechanism to ensure that all the library code is pulled in (so perhaps it would never be called). Actually, that should not be necessary if the decls are correctly marked as "used". Furthermore, the initialisation code for the static instance will be entered automatically into the startup (so it's out of your control). =3D=3D=3D=3D=3D What about, instead: 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) { } extern "C" void _M2_termios_ctor (void) { M2RTS_RegisterModule ("termios", _M2_termios_init, _M2_termios_fini, _M2_termios_dep); } =3D=3D now the symbol will indeed refer to the CTOR that causes the module = to be registered. As it is written that CTOR will not be called unless you do it. IFF you want it to be called "automatically" at program startup .. you can = mark it __attribute__((constructor))=