Thread overview
[Issue 22651] undefined reference to ModuleInfo when using imported
Apr 28, 2022
duser@neet.fi
Apr 28, 2022
duser@neet.fi
Nov 16, 2022
RazvanN
April 28, 2022
https://issues.dlang.org/show_bug.cgi?id=22651

duser@neet.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |duser@neet.fi

--- Comment #1 from duser@neet.fi ---
Created attachment 1850
  --> https://issues.dlang.org/attachment.cgi?id=1850&action=edit
fix

--
April 28, 2022
https://issues.dlang.org/show_bug.cgi?id=22651

duser@neet.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
          Component|phobos                      |dmd
           Hardware|x86_64                      |All
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=17181
                 OS|Linux                       |All

--- Comment #2 from duser@neet.fi ---
smaller reproducer:

/// common.d
template myimported() { import myctor; }
/// myctor.d
shared static this(){}
/// empty.d
import common;
/// main.d
import common;
alias x = myimported!();
import empty;
void main(){}

compile: "dmd main.d common.d myctor.d", gives an undefined symbol error for _D5empty12__ModuleInfoZ

i'm not 1000% familiar with this stuff but i think what happens in the original example is

1. using imported!"", a module is imported that has a module constructor - this
causes the "needmoduleinfo" flag to be set for a bunch of modules including
"object" (it's not normally set for object)
2. a module is imported that doesn't have a ModuleInfo symbol and isn't
included in compilation - it inherits the needmoduleinfo flag from object
(which it implicitly imports) and linking fails because there's no ModuleInfo
symbol for it

the thing the patch does to fix this is copied from here: https://github.com/dlang/dmd/blob/375ed51/src/dmd/dsymbolsem.d#L1283-L1292 - it causes "needmoduleinfo" to be set for the module that uses imported!"" instead of the module that defines it

the link error in the original example is for std.internal.memory which indeed doesn't have a ModuleInfo symbol inside libphobos2.so

--
November 16, 2022
https://issues.dlang.org/show_bug.cgi?id=22651

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
I cannot reproduce this with the latest version of the compiler: neither the initial test case, nor the reduction.

--