Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 23177 - ModuleInfo is not exported on Windows #14647

Closed
wants to merge 12 commits into from

Conversation

rikkimax
Copy link
Contributor

@rikkimax rikkimax commented Nov 19, 2022

This doesn't include any tests, right now I want to know if this breaks anything existing.

If it doesn't, I'll re-add them.

Assuming this works, the patching can be done a different way in the future allowing ModuleInfo.importedModules to be @nogc and in doing so simplifying it back to how it was.

@dlang-bot
Copy link
Contributor

dlang-bot commented Nov 19, 2022

Thanks for your pull request and interest in making D better, @rikkimax! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
23177 blocker ModuleInfo is not exported on Windows

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

To target stable perform these two steps:

  1. Rebase your branch to upstream/stable:
git rebase --onto upstream/stable upstream/master
  1. Change the base branch of your PR to stable

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#14647"

@rikkimax
Copy link
Contributor Author

Okay the non-Windows behavior looks unchanged, excellent, so nothing there was broken. Windows has however.

Two sets of errors I'm seeing:

core.exception.AssertError@src\rt\minfo.d(746): imported ctor => ordered ctors (2)

and

druntime64.lib(dbghelp.obj) : error LNK2001: unresolved external symbol __imp__D6object12__ModuleInfoZ

The first may be a red haring, the second on the other hand looks a bit more worrisome. I'll try being a bit more eager on the adding of DllImport to see if that helps.

@rikkimax
Copy link
Contributor Author

Any ideas of what I'm messing up @kinke?

@rikkimax
Copy link
Contributor Author

Okay I understand why core.exception.AssertError@src\rt\minfo.d(746): imported ctor => ordered ctors (2) is failing. I'll need to copy the version logic as part of mocking and do the referencing there too.

@@ -361,6 +361,7 @@ extern (C++) final class Module : Package
int needmoduleinfo;
int selfimports; // 0: don't know, 1: does not, 2: does
Dsymbol[void*] tagSymTab; /// ImportC: tag symbols that conflict with other symbols used as the index
Symbol* isym; /// Import version of csym used for DllImport on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to stop accepting dmd-specific back end symbols in the front-end. There are plenty of ways to keep compiler-specific information contained to the code generator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the existing solution for toImport for a different node and it is aligned with msym that is defined in a parent.

If there is a way to solve this assuming I can get this to go green, please do tell me what to do.

@rikkimax
Copy link
Contributor Author

Ohhhh kay I think I know why the others are failing.

D:\a\1\s\generated\windows\release\64\dmd.exe -conf= -m64 -Irunnable -odD:\a\1\s\compiler\test\test_results\runnable -ofD:\a\1\s\compiler\test\test_results\runnable\test20855_0.exe runnable\test20855.d
Creating library D:\a\1\s\compiler\test\test_results\runnable\test20855_0.lib and object D:\a\1\s\compiler\test\test_results\runnable\test20855_0.exp

This is a problem we had in dub. It's generating an import library, which it is attempting to link against rather than the static library.

@rikkimax
Copy link
Contributor Author

The file src/dmd/frontend.h seems to be out of sync. This is likely because

Easy fix, which I have locally.

Looks like OMF is passing, so the problem is certainly centered around MSVC link/PE-COFF. Still unsure of how to proceed, will need to leave it here for now I think.

@rikkimax
Copy link
Contributor Author

Okay not a sporadic dependency at link time issue. Welp I'm all out of ideas.

else
{
return cast(typeof(return))embeddedImportedModules;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hack won't do. The manual dllimport relocation necessary at runtime affects all imported data symbols; ModuleInfos are just a tiny share of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is calling toImport which does the dllimport on importedModules member (and only there), affect other symbols?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that you need a general solution for all data symbols, not a hack which might work for ModuleInfos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

That is super out of what I can do and unfortunately, I seem to be the only one willing to even give it a go ;)

@rikkimax rikkimax closed this Dec 6, 2022
@rikkimax rikkimax deleted the fix23177-attempt2.5 branch June 3, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants