Skip to content

rust_begin_unwind not emitted when crate-type = bin #51671

Description

@japaric

STR

$ cargo new --bin foo && cd $_

$ $EDITOR src/main.rs && cat $_
#![feature(panic_implementation)]
#![no_main]
#![no_std]

use core::panic::PanicInfo;

#[panic_implementation]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}
$ # linking will fail but that's unimportant
$ cargo build --target thumbv7m-none-eabi
error: linking with `arm-none-eabi-gcc` failed: exit code: 1
  |
  = note: "arm-none-eabi-gcc" "-L" "$SYSROOT/lib/rustlib/thumbv7m-none-eabi/lib" "target/thumbv7m-none-eabi/debug/deps/foo-7e5b7587bde453e1.1y16o1qfye96o7m0.rcgu.o" (..)

$ nm -C target/thumbv7m-none-eabi/debug/deps/foo-7e5b7587bde453e1.1y16o1qfye96o7m0.rcgu.o && echo EMPTY
EMPTY

However if the crate is turned into an rlib the rust_begin_unwind symbol will be emitted.

$ mv src/{main,lib}.rs

$ cargo build --target thumbv7m-none-eabi

$ nm -C target/thumbv7m-none-eabi/debug/deps/libfoo-e1e65e68106e26e1.rlib

foo-e1e65e68106e26e1.1qddbosld5q76e2k.rcgu.o:
(..)
00000001 T rust_begin_unwind
00000000 t $t.0

Metada

$ rustc -V
rustc 1.28.0-nightly (523097979 2018-06-18)

However this problem is also present in nightly-2018-06-03 before #[panic_implementation] landed: rust_begin_unwind is not emitted when the panic_fmt lang item is present in a binary crate.


This issue was found while analyzing #51342 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions