Fix issue 16423 - ModuleInfo missing when linking to static lib with classes#6076
Fix issue 16423 - ModuleInfo missing when linking to static lib with classes#6076jacob-carlborg wants to merge 3 commits intodlang:masterfrom
Conversation
|
1973c43 to
f020f83
Compare
|
@jacob-carlborg, thanks for your PR! By analyzing the annotation information on this pull request, we identified @MartinNowak, @yebblies and @WalterBright to be potential reviewers. @MartinNowak: The PR was automatically assigned to you, please reassign it if you were identified mistakenly. |
|
Awesome! Thanks for doing this so quickly |
f020f83 to
2b569ff
Compare
|
Hmm, not really sure how to solve the Windows test failure. |
|
It's possible Windows doesn't have the same problem. I have found several disturbing things while adding back correct cycle detection, and one of them was that Windows would find cycles that the other OSes did not. See: dlang/druntime#1602 (comment) |
|
I'm guessing the linkers behave differently. Perhaps the linkers on Posix remove/merge duplicated symbols. |
|
|
||
| if (m->doppelganger) | ||
| { | ||
| objc_Module_genmoduleinfo_classes(); |
There was a problem hiding this comment.
If I'm following the logic correctly, the only difference between the before and after for your patch (assuming betterC flag is not set) is that this call is now omitted. Is that right?
There was a problem hiding this comment.
No. The change is to always call genModuleInfo. objc_Module_genmoduleinfo_classes is called by genModuleInfo, I removed some of the duplications as well. Seems like the bigger if statement above didn't catch all cases where the module info needed to be generated. m->doppelganger is true if the -lib flag is passed. Before my change the function would return, if the -lib flag was passed, before the module info had been generated.
|
Auto-merge toggled on |
|
@andralex seems this doesn't work on Windows. |
|
@jacob-carlborg if you can fix this then the pull will be merged, if it's unsolvable on Windows please |
|
Ok, thanks. |
|
Auto-merge toggled off |
|
Turned autotester off until tests pass, so it does not consume testing resources. |
2b569ff to
255cc58
Compare
255cc58 to
fc44e75
Compare
|
Ok, I have no idea what to do with Win32, it doesn't work with the new behavior or the old behavior. |
|
So you are saying the test on the current compiler doesn't put the class info into the module info? Is there an issue here where we are expecting a design that doesn't exist? If so, I need to solve the original problem in a different way. |
The current compiler doesn't work for your test case for any platform. With my patch your test case works on all platforms except Windows. On Windows, with my patch, there's duplicated symbols when building Phobos. I tried to keep the old behavior on Windows, but then the new (your) test case doesn't work on Windows. |
|
OK, got it. This sucks. @WalterBright, @MartinNowak what is supposed to happen in terms of storage of moduleinfo with static library when all instantiations of the class are done either via Object.factory (or by doing a lookup of the classinfo by name to instantiate), or via extern(C) functions? See attached bug report. Am I expecting something that just isn't valid? This is related to dlang/phobos#4744 and std.encoding. |
|
My patch was kind of a guess. I was able to "fix" this so quickly because I had run into the same problem but for Objective-C module info. So I just guessed that always generating the module info would fix the problem. It did, but caused other problems on Windows. I think your use case is valid but I'm not sure if my patch is the correct fix. There's an instance variable, |
|
Well, this goes against much that we're trying to achieve, might result in huge binary increases, and tries to hack one purpose of static libraries and dmd's multilib (not dragging in everything). It's a shame that this didn't raise any red flags and that the PR description didn't contain any information about the PR's effect and trade-offs. I mentioned a couple of workarounds in the Bugzilla report Issue 16423 – ModuleInfo missing when linking to static lib with classes, and would like to leave it at that. |
No, I'm trying to fix a bug.
You're overreacting.
You mean like you did with #4638 which contains no description at all. I rather try to fix something instead of your approach of trying to sneak by another (possible) language breaking change without anyone noticing to remove a feature instead of fixing it. |
Um yes. The bug report explains everything. What is difficult to understand? I'm using obj.classinfo, but it's not being included in moduleinfo (in fact, module info is not included at all).
I think this is way over the top, and does not foster any goodwill towards would-be contributors. |
Yes sorry, that was a bit harsh.
Sure, I haven't always been as stringent w/ good PRs in the past.
Well, the references ModuleInfo -> imported ModuleInfo -> classes -> data&functions are one of the main reasons for fat binaries. |
The example is fairly complex, which is OK for a bug report if necessary, still takes a couple of minutes to grasp. |
|
Unfortunately, it is necessary. You need to use the -lib compiler flag, which means a simple setup is difficult. The original test case is Phobos, which is compiled similarly. I think the idea behind the PR is to include moduleinfo whenever classes are present. Yes, this can lead to fat binaries, but how does one expect Object.factory to work otherwise? Note that the current |
It's quite simple. Compile a module with the
The cause is that the compiler doesn't output module info/class info when it should do so when the
The fix is to always output the module info. |
I've given a few examples on the Bugzilla page, you need to include the ModuleInfo yourself.
That's not correct, the ModuleInfo containing all localClasses is generated with the first object for that module. But because it's not referenced, it doesn't end up in the executable.
But you're not outputting the ModuleInfo, you're generating additional fake ModuleInfos for multilib doppelgänger modules. Just try your patch, you'll find a new module Just to summarize the state.
I don't think that the fake ModuleInfos |
|
I think we should be fine with requiring people who want to use |
What are these fake module infos you're talking about? |
|
@MartinNowak I think there's a similar problem in std.process [1] as well. It's broken on macOS because module constructors are not run if compiled with |
Just calling genModuleInfo for doppelgänger modules creates stripped down doppelgänger ModuleInfos, instead of referencing the original ones. Try Thx for your good wrap-up Andrei. |
No description provided.