export symbols: support macos/windows(32/64)#155535
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Could someone pls give me permission to test whether the current modifications will work correctly on Windows and macOS? |
|
@bors delegate=try |
|
✌️ @cezarbbb, you can now perform try builds on this pull request! You can now post |
Thanks!!! It helps me a lot:> |
|
@bors try jobs=x86_64-msvc-* |
export symbols: support macos/windows(32/64) try-job: x86_64-msvc-*
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
💔 Test for 22e628f failed: CI. Failed job:
|
|
@bors try jobs=x86_64-msvc-* |
This comment has been minimized.
This comment has been minimized.
export symbols: support macos/windows(32/64) try-job: x86_64-msvc-*
|
💔 Test for 71d836c failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
|
@bors try jobs=x86_64-msvc-* |
This comment has been minimized.
This comment has been minimized.
export symbols: support macos/windows(32/64) try-job: x86_64-msvc-*
|
@bors try jobs=aarch64-* |
This comment has been minimized.
This comment has been minimized.
export symbols: support macos/windows(32/64) try-job: aarch64-*
|
@bors try jobs=x86_64-msvc-* |
This comment has been minimized.
This comment has been minimized.
export symbols: support macos/windows(32/64) try-job: x86_64-msvc-*
3171abe to
1431f40
Compare
1431f40 to
4332ade
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Thanks @bjorn3 for taking the time to review this PR. I've made some optimizations and rebased onto the latest main. Several weeks have passed since the last review, could you please take a look? I look forward to receiving your valuable advice:> |
This comment was marked as resolved.
This comment was marked as resolved.
1 similar comment
This comment was marked as resolved.
This comment was marked as resolved.
| // Accept both on Windows. | ||
| let scope = symbol.scope(); | ||
| if scope != object::SymbolScope::Dynamic | ||
| && !(sess.target.is_like_windows && scope == object::SymbolScope::Linkage) |
There was a problem hiding this comment.
This should probably check sess.target.binary_format rather than Windows. UEFI also uses COFF.
| // Mach-O: strip the leading underscore that all external symbols have. | ||
| // The Darwin linker's export_symbols will add it back. | ||
| name.strip_prefix('_').map(|s| Cow::Owned(s.to_string())).unwrap_or(Cow::Borrowed(name)) | ||
| } else if sess.target.is_like_windows { |
There was a problem hiding this comment.
These two should also check sess.target.binary_format.
| if sess.target.is_like_darwin { | ||
| // Mach-O: strip the leading underscore that all external symbols have. | ||
| // The Darwin linker's export_symbols will add it back. | ||
| name.strip_prefix('_').map(|s| Cow::Owned(s.to_string())).unwrap_or(Cow::Borrowed(name)) |
There was a problem hiding this comment.
If the name doesn't start with an _, I believe it will not be exported by the linker. In either case returning the original name is wrong as the linker will look for format!("_{name}"), which likely doesn't exist.
There was a problem hiding this comment.
The return type of undecorate_c_symbol has been changed to Option<Cow<str>>. Symbols without the _ prefix now return None and are skipped instead of incorrectly returning the original name.
| // COFF 32-bit: strip calling-convention decorations. | ||
| if let Some(rest) = name.strip_prefix('@') { | ||
| // fastcall: @foo@N -> foo | ||
| rest.split_once('@') |
There was a problem hiding this comment.
Should these use rsplit_once?
|
Reminder, once the PR becomes ready for a review, use |
Co-authored-by: Jesus Checa <101630491+jchecahi@users.noreply.github.com>
4332ade to
a46ffc1
Compare
|
@bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
export symbols: support macos/windows(32/64) try-job: aarch64-apple
|
@rustbot ready |
| fallback: &'a str, | ||
| ) -> Cow<'a, str> { | ||
| if suffix.as_ref().parse::<u32>().is_ok() { | ||
| Cow::Owned(base.to_string()) |
There was a problem hiding this comment.
| Cow::Owned(base.to_string()) | |
| Cow::Borrowed(base) |
would work too, right? Then strip_numeric_suffix can return &'a str instead.
| strip_numeric_suffix(base, suffix, stripped) | ||
| } else { | ||
| // cdecl: _foo -> foo | ||
| Cow::Owned(stripped.to_string()) |
There was a problem hiding this comment.
| Cow::Owned(stripped.to_string()) | |
| Cow::Borrowed(stripped) |
would work, right?
| BinaryFormat::MachO => { | ||
| // Mach-O: strip the leading underscore that all external symbols have. | ||
| // The Darwin linker's export_symbols will add it back. | ||
| name.strip_prefix('_').map(|s| Cow::Owned(s.to_string())) |
There was a problem hiding this comment.
and this, allowing you to remove Cow entirely.
| name.strip_prefix('_').map(|s| Cow::Owned(s.to_string())) | |
| name.strip_prefix('_').map(|s| Cow::Borrowed(s)) |
View all comments
Previously, in the pr #150992 , export symbols only supported Linux. The special prefix and suffix rules for some symbols in macOS and Windows were not fully supported. This pull request attempts to clarify these rules and add corresponding support.
Currently, the
undecorate_c_symbol()function has been added to handle macOS_prefixes, Windows x86 calling convention modifiers (cdecl/stdcall/fastcall/vectorcall), and Arm64EC#prefixes.*Update: Handling of Windows C++ mangled symbols has now been added(Linux/macOS don't need).
r? @bjorn3 @petrochenkov