Issue 23177 - ModuleInfo is not exported on Windows
Summary: ModuleInfo is not exported on Windows
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P1 blocker
Assignee: No Owner
URL:
Keywords: dll, pull
Depends on:
Blocks:
 
Reported: 2022-06-11 17:16 UTC by Richard (Rikki) Andrew Cattermole
Modified: 2023-06-05 22:05 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard (Rikki) Andrew Cattermole 2022-06-11 17:16:48 UTC
When ModuleInfo is generated it is not added to the export tables.

This can lead to linker errors with shared libraries.

This should hopefully be a fairly simple fix, a one-liner and I'll be attempting it. If not I'll add a test case.
Comment 1 Dlang Bot 2022-06-11 17:54:02 UTC
@rikkimax updated dlang/dmd pull request #14200 "Fix Issue 23177 - ModuleInfo is not exported on Windows" fixing this issue:

- Fix issue 23177

https://github.com/dlang/dmd/pull/14200
Comment 2 Richard (Rikki) Andrew Cattermole 2022-06-11 21:09:26 UTC
It was indeed as simple as adding:

```d
objmod.export_symbol(m.csym, 0);
```

to ``genModuleInfo``.

However I ran into a lot of issues in the test suite (mostly fixable, since it just needed to know about the fact that import + export libraries were being generated).

For the test it was as simple as adding a new module ``test/dshell/extra-files/dll/issue23177.d`` and importing it to ``mydll.d`` and ``testdll.d``.

I managed to get it down to only one test failing. Unicode symbols are part of it ``runnable/testmodule.d``. I have no idea how to fix this particular issue, so unfortunately my fix is on hold until that can be resolved.
Comment 3 Dlang Bot 2022-06-12 09:47:10 UTC
dlang/dmd pull request #14200 "Fix Issue 23177 - ModuleInfo is not exported on Windows" was merged into stable:

- 6b93e00b535fc020794c50010e1b9040fa6e2476 by richard andrew cattermole:
  Fix Issue 23177 - ModuleInfo is not exported on Windows

https://github.com/dlang/dmd/pull/14200
Comment 4 Richard (Rikki) Andrew Cattermole 2022-06-12 18:32:20 UTC
Unfortunately, my fix is nowhere near good enough.

Here is a code snippet that will fail, it will need to be added to dshell/dll test in its main function (in some form).

```d
void main() {
    import std.stdio;
    foreach (m; ModuleInfo) {
        writeln(m.name);
        if (auto i = m.importedModules()) {
            writeln(i);
            stdout.flush;
            foreach (j; i) {
                writeln("  - ", j.name.ptr);
                stdout.flush;
            }
        }
    }
}

```
Comment 5 Dlang Bot 2022-06-13 00:04:28 UTC
dlang/dmd pull request #14206 "Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows"" was merged into stable:

- aa10936019c4b68ffef39fff6af605e067f0e9e2 by Martin Kinkelin:
  Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows"
  
  This reverts commit 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae.

https://github.com/dlang/dmd/pull/14206
Comment 6 Dlang Bot 2022-06-17 10:18:06 UTC
@BorisCarvajal updated dlang/dmd pull request #14226 "Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums" fixing this issue:

- Fix Issue 23177 - ModuleInfo is not exported on Windows

- Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows"
  
  This reverts commit 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae.

https://github.com/dlang/dmd/pull/14226
Comment 7 Dlang Bot 2022-07-09 15:07:21 UTC
@ibuclaw created dlang/dmd pull request #14280 "merge stable" fixing this issue:

- Fix Issue 23177 - ModuleInfo is not exported on Windows

- Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows"
  
  This reverts commit 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae.

https://github.com/dlang/dmd/pull/14280
Comment 8 Dlang Bot 2022-07-09 16:32:06 UTC
dlang/dmd pull request #14280 "merge stable" was merged into master:

- 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae by richard andrew cattermole:
  Fix Issue 23177 - ModuleInfo is not exported on Windows

- 4ee3ac43f5235d3798c0c0cd9f317f5e1aa07ce4 by Martin Kinkelin:
  Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows"
  
  This reverts commit 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae.

https://github.com/dlang/dmd/pull/14280
Comment 9 Dlang Bot 2022-11-19 06:01:58 UTC
@rikkimax created dlang/dmd pull request #14647 "Fix issue 23177 - ModuleInfo is not exported on Windows" fixing this issue:

- Fix issue 23177 - ModuleInfo is not exported on Windows

https://github.com/dlang/dmd/pull/14647
Comment 10 Walter Bright 2023-01-29 08:55:08 UTC
The ModuleInfo is necessary for static construction. For a DLL, the static construction is handled by DllMain. If the ModuleInfo is exported, the user of the dll will run the static constructors again.
Comment 11 Richard (Rikki) Andrew Cattermole 2023-01-29 10:44:39 UTC
(In reply to Walter Bright from comment #10)
> The ModuleInfo is necessary for static construction. For a DLL, the static
> construction is handled by DllMain. If the ModuleInfo is exported, the user
> of the dll will run the static constructors again.

This is already handled, we're good to go, it will only do what is in the binary.

https://github.com/dlang/dmd/blob/master/druntime/src/rt/minfo.d#L264
Comment 12 Walter Bright 2023-06-05 22:05:19 UTC
For another take on this, see: https://issues.dlang.org/show_bug.cgi?id=23974