-
Notifications
You must be signed in to change notification settings - Fork 13k
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
panic_implementation: no_mangle attribute needed? #51342
Comments
I'm seeing this as well. Additionally, adding
but it still works. This implies to me that |
I'm seeing the exact same behavior. I'm using arm-none-eabi-ld (2.28.0.20170620) to link. |
Can we get more details (steps to reproduce)? Are you all using an allocator? I know there's a linker regression caused by the new-ish oom lang item, which I have reported in #51647. It could be that you are experiencing that bug and that this isn't related to the EDIT: I have been using #[panic_implementation] since it landed and have not run into any linker issue but I'm not using an allocator. |
https://github.com/intermezzos/kernel is pretty small; download it, remove https://github.com/intermezzOS/kernel/blob/e6508a00ec0bc9ffa417d003d81ae63eceac2cf9/src/panic.rs#L5, and It pretty much happens on 'hello world'; you could strip even more out of the above, if it doesn't warn for you for some reason, I can minimize even further. Not using an allocator or anything. |
@steveklabnik thanks for the sample code. I see at least one bug there: |
see rust-lang#51671 for details fixes rust-lang#51671 fixes rust-lang#51342
translate / export weak lang items see #51671 for details fixes #51671 fixes #51342 r? @michaelwoerister or @alexcrichton
So I tried it with the latest nightly [1] and the issue still exists for me. To reproduce, try the I also still get the error for intermezzOS. [1]: rustc 1.29.0-nightly (960f604 2018-07-08) |
Ah, thanks for reminding me to verify the fix. I tried removing |
This might be related to #52795. |
I believe this is fixed in #52993, where the answer is "no" you shouldn't need |
This commit tweaks the linker-level visibility of some lang items that rustc uses and defines. Notably this means that `#[panic_implementation]` and `#[alloc_error_handler]` functions are never marked as `internal`. It's up to the linker to eliminate these, not rustc. Additionally `#[global_allocator]` generated symbols are no longer forced to `Default` visibility (fully exported), but rather they're relaxed to `Hidden` visibility). This symbols are *not* needed across DLL boundaries, only as a local implementation detail of the compiler-injected allocator symbols, so `Hidden` should suffice. Closes rust-lang#51342 Closes rust-lang#52795
rustc: Tweak visibility of some lang items This commit tweaks the linker-level visibility of some lang items that rustc uses and defines. Notably this means that `#[panic_implementation]` and `#[alloc_error_handler]` functions are never marked as `internal`. It's up to the linker to eliminate these, not rustc. Additionally `#[global_allocator]` generated symbols are no longer forced to `Default` visibility (fully exported), but rather they're relaxed to `Hidden` visibility). This symbols are *not* needed across DLL boundaries, only as a local implementation detail of the compiler-injected allocator symbols, so `Hidden` should suffice. Closes #51342 Closes #52795
I can confirm that it now works without |
Seems like
It works fine in debug mode and in release mode with LTO. When I add no_mangle, it also works in release mode without LTO. I'm using |
@phil-opp oh dear! Is it possible to get an example I could poke around with? |
I created a minimal embedded project here: https://github.com/phil-opp/rust-issue-51342-example
|
Oops, thanks for the report! That should be fixed in #53640 |
In investigating [an issue][1] with `panic_implementation` defined in an executable that's optimized I once again got to rethinking a bit about the `rustc_std_internal_symbol` attribute as well as weak lang items. We've sort of been non-stop tweaking these items ever since their inception, and this continues to the trend. The crux of the bug was that in the reachability we have a [different branch][2] for non-library builds which meant that weak lang items (and std internal symbols) weren't considered reachable, causing them to get eliminiated by ThinLTO passes. The fix was to basically tweak that branch to consider these symbols to ensure that they're propagated all the way to the linker. Along the way I've attempted to erode the distinction between std internal symbols and weak lang items by having weak lang items automatically configure fields of `CodegenFnAttrs`. That way most code no longer even considers weak lang items and they're simply considered normal functions with attributes about the ABI. In the end this fixes the final comment of rust-lang#51342 [1]: rust-lang#51342 (comment) [2]: https://github.com/rust-lang/rust/blob/35bf1ae25799a4e62131159f052e0a3cbd27c960/src/librustc/middle/reachable.rs#L225-L238
…ister rustc: Continue to tweak "std internal symbols" In investigating [an issue][1] with `panic_implementation` defined in an executable that's optimized I once again got to rethinking a bit about the `rustc_std_internal_symbol` attribute as well as weak lang items. We've sort of been non-stop tweaking these items ever since their inception, and this continues to the trend. The crux of the bug was that in the reachability we have a [different branch][2] for non-library builds which meant that weak lang items (and std internal symbols) weren't considered reachable, causing them to get eliminiated by ThinLTO passes. The fix was to basically tweak that branch to consider these symbols to ensure that they're propagated all the way to the linker. Along the way I've attempted to erode the distinction between std internal symbols and weak lang items by having weak lang items automatically configure fields of `CodegenFnAttrs`. That way most code no longer even considers weak lang items and they're simply considered normal functions with attributes about the ABI. In the end this fixes the final comment of #51342 [1]: #51342 (comment) [2]: https://github.com/rust-lang/rust/blob/35bf1ae25799a4e62131159f052e0a3cbd27c960/src/librustc/middle/reachable.rs#L225-L238
When using the new
panic_implementation
attribute I get a linker error:(I'm linking with LLD)
Adding the
#[no_mangle]
attribute seems to fix this linker error.Is
no_mangle
required for the panic function or is this a bug?The text was updated successfully, but these errors were encountered: