Skip to content

[windows] Enable symbolic references in PE/COFF. #28547

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

Merged
merged 1 commit into from
Dec 5, 2019

Conversation

drodriguez
Copy link
Contributor

@drodriguez drodriguez commented Dec 4, 2019

In order for the cross-module optimization to work, it needs to generate
symbolic references, which were disabled in PE/COFF. This commit enables
them and marks some Reflection tests with XFAIL since
swift-reflection-dump still doesn't handle symbolic references.

Introduced in #28407 and first seen in https://ci-external.swift.org/job/oss-swift-windows-x86_64/2104/

@drodriguez
Copy link
Contributor Author

There's another Windows error at the moment, so this will not report a success anyway.

@swift-ci please test Windows platform

@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

@drodriguez
Copy link
Contributor Author

@swift-ci please clean test Windows platform

@eeckstein
Copy link
Contributor

Maybe metatype lookup by mangled name for private types is not working. The reason why it should work is because metaypes are now referenced by symbolic addresses in the mangled name. This was done recently by @jckarter. Maybe for some reason there is a problem with that on Windows.

If this is really the case, there are 2 possibilities to fix that:

  1. Support the PrivateDeclName mangling node in MetadataLookup.cpp in the runtime.

  2. Change the mangling scheme for private entities. This is more heavy weight and I would not recommend it. But if you want to try, I have a prototype patch here: eeckstein@b4b9f13
    It might be useful to check if it solves the problem.

The first thing what you could do is to debug the runtime and see if swift_getTypeByMangledName works or fails.
Unfortunately I don't have a possibility to debug this myself on windows.

@jckarter
Copy link
Contributor

jckarter commented Dec 4, 2019

Under no circumstances should we try to demangle private type names from strings. The issue with Windows is likely that always-use-symbolic-references is not enabled on Windows, because swift-reflection-dump does not yet support resolving indirect references across DLLs for PE object files. You can try removing the check here to confirm:

https://github.com/apple/swift/blob/master/lib/IRGen/IRGenMangler.cpp#L122

though this will in turn break some Reflection tests until swift-reflection-dump is updated for PE.

@drodriguez
Copy link
Contributor Author

Thanks for the answers. I will try to see if that change makes a difference. Breaking more tests is not the perfect solution, though. It seems that we are crashing into the same problem with swift-reflection-dump, but I don't know if I have the knowledge or the time to deal with it.

@jckarter
Copy link
Contributor

jckarter commented Dec 4, 2019

From an engineering tradeoffs point of view, my judgment would be that getting the performance, memory, and code size benefits of compacted mangled names and cross-module optimization is probably more important than swift-reflection-dump. It is hopefully straightforward to update swift-reflection-dump, though, since for PE you should hopefully be able to recognize indirect references into the import table and map those to import entries to extract the symbol name they're referring to.

@drodriguez
Copy link
Contributor Author

Thanks for the clue. Effectively removing that block makes the test pass in Windows. In exchange it breaks at least two tests in the Reflection folder. We will try to work on swift-reflection-dump, but I don't think we can promise any timeline. Would anyone have a problem XFAIL-ing this test for the time being?

@jckarter
Copy link
Contributor

jckarter commented Dec 5, 2019

XFAILing the affected reflection tests on Windows seems fine to me.

In order for the cross-module optimization to work, it needs to generate
symbolic references, which were disabled in PE/COFF. This commit enables
them and marks some Reflection tests with XFAIL since
swift-reflection-dump still doesn't handle symbolic references.
@drodriguez drodriguez changed the title [windows] XFAIL cross-module-optimization test in Windows [windows] Enable symbolic references in PE/COFF. Dec 5, 2019
@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

@drodriguez
Copy link
Contributor Author

Changed the implementation and disabled the two test that seems to fail because of this changes. Let's see if CI finds some other ones.

@swift-ci please clean test Windows platform

@drodriguez
Copy link
Contributor Author

@swift-ci please clean test Windows platform

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@drodriguez drodriguez merged commit 09444da into swiftlang:master Dec 5, 2019
@drodriguez drodriguez deleted the windows-xfail-cmo branch December 5, 2019 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants