Skip to content
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

Rust sometimes emits calls to _Unwind_Resume on opt-level = 0 with panic = abort #53301

Closed
CryZe opened this issue Aug 13, 2018 · 8 comments
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CryZe
Copy link
Contributor

CryZe commented Aug 13, 2018

I don't think this is intentional. I'm working on a no_std project and for the first time tried to compile with the debug profile and there seem to be undefined references to _Unwind_Resume even though panic = "abort" is specified. opt-level = 1 seems to get rid of those calls.

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@glandium
Copy link
Contributor

As of #67502, this happens at any opt-level because of libstd itself containing these symbols.

@glandium
Copy link
Contributor

(and libbacktrace)

@Enselic
Copy link
Member

Enselic commented Dec 16, 2023

Triage: Please provide a minimal way to reproduce the problem (if this still is a problem). Thanks!

@Enselic Enselic added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Dec 16, 2023
@jackh726
Copy link
Member

Closing since there is no reproduction.

@bjorn3
Copy link
Member

bjorn3 commented Dec 25, 2023

I'm fairly certain this is still an issue as the standard library is still compiled with panic=unwind. The default -Clink-dead-code=no may mask this in most cases, but that is not the solution.

@jackh726 jackh726 reopened this Dec 25, 2023
@jackh726 jackh726 added S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Dec 25, 2023
@RalfJung
Copy link
Member

We ran into this #134299, so here's a reproduction that works only on the x86_64-gnu-nopt CI runner:

//@ run-pass
//@ compile-flags: -Cpanic=abort
//@ ignore-emscripten no no_std executables

#![feature(lang_items, rustc_private)]
#![no_std]
#![no_main]

#[macro_use] extern crate alloc;

use core::alloc::{GlobalAlloc, Layout};
use alloc::string::ToString;

extern crate libc;

struct MyAllocator;

unsafe impl GlobalAlloc for MyAllocator {
    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
        // This is unsound because we ignore alignment, but good enough for this test.
        libc::malloc(layout.size()) as _
    }
    unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
        libc::free(ptr as _);
    }
}

#[global_allocator]
static A: MyAllocator = MyAllocator;

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

#[no_mangle]
extern "C" fn rust_eh_personality() {
    loop {}
}

#[no_mangle]
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
    let s = format!("{}", 1_isize);
    assert_eq!(s, "1".to_string());

    let s = format!("test");
    assert_eq!(s, "test".to_string());

    let s = format!("{test}", test=3_isize);
    assert_eq!(s, "3".to_string());

    let s = format!("hello {}", "world");
    assert_eq!(s, "hello world".to_string());

    0
}

@RalfJung
Copy link
Member

Also, this is a duplicate of #47493.

@jieyouxu jieyouxu removed the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label Jan 20, 2025
@jieyouxu
Copy link
Member

Closing in favor of #47493 as that has a lot more existing analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants