-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Use the .drectve section for exporting symbols from dlls on Windows #142568
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
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred in compiler/rustc_codegen_ssa |
e63c76b
to
94ec88c
Compare
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
💔 Test failed
|
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
One overall design question: is it supported for folks to run the linker themselves AND specify their own def file? A couple of my changes broke the Chromium and Fuschia folks, so I'm a little paranoid now about changing anything to do with linking that may affect them.
@@ -1116,10 +1122,6 @@ impl<'a> Linker for MsvcLinker<'a> { | |||
// straight to exports. | |||
writeln!(f, "LIBRARY")?; | |||
writeln!(f, "EXPORTS")?; | |||
for symbol in symbols { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that we need the def file any more, we should be able to get away with passing /DLL
to the linker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the mingw docs I read something about the presence of a .DEF file disabling auto-export of certain symbols. I don't know if the same applies to MSVC, so I added it here just to be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think link.exe has "default exports" like the mingw linker does so this doesn't seem necessary but it also shouldn't hurt anything either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is an ld.bfd (and LLD in MinGW mode) feature to ease porting of Unix code, but it is not only .DEF that disables it. Any supported ld.bfd way to explicitly export symbols would suffice, and there is a CLI flag for that as well.
None of that matters here because link.exe doesn't export everything by default.
This PR on it's own has no effect at all on people running the linker themself. Both the .DEF file and the symbols.o file are only generated when rustc itself runs the linker. As for a future PR that will use weak definitions, those symbols are not meant to be exported from a staticlib anyway. The only case that could break is if someone (Chromium) tries to link rlibs together into a dll and wants to export all symbols, which we don't officially support anyway. The Chromium people have had to adaot their build system for rustc changes anyway and I expect it to not all that hard to adapt to said future weak symbol usage too. |
💔 Test failed
|
The test executable failed with Looks like this is a test for shaking out unused functions: is the compiler supposed to do that, or is it relying on the linker? |
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2 |
Use the .drectve section for exporting symbols from dlls on Windows While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used. Necessary for and extracted out of #142366. Thanks `@dpaoliello` for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
8c88ff4
to
fc88eae
Compare
fc88eae
to
e6aa201
Compare
Squashed everything and reverted some now unnecessary changes. @rustbot ready |
@bors r+ |
Should we be testing for weak symbol behavior somehow? |
Right. Will add a test and fix #142568 (comment) at the same time. @bors r- |
While at it, have you confirmed that LLD behaves the same way? Or is it tested on the CI? This is not a blocker, but it could cause a surprise later. |
fb67d22
to
809b270
Compare
Removed the needless .DEF file generation for MSVC and added a test with tests with both link.exe and lld. @rustbot ready |
While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.
809b270
to
d40bee8
Compare
While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.
Necessary for and extracted out of #142366.
Thanks @dpaoliello for figuring out this weird quirk of link.exe!