Skip to content

/checkout/src/libcore/num/mod.rs:920: undefined reference to `__muloti4' when using core::num methods in a no-std staticlib #48339

Closed
@glandium

Description

@glandium

STR:

$ cargo new foo
$ cd foo
$ cat <<EOF >> Cargo.toml
[lib]
crate-type = ["staticlib"]
[profile.release]
panic = "abort"
EOF
$ cat <<EOF > src/lib.rs
#![feature(lang_items)]
#![no_std]
#[lang="panic_fmt"]
#[no_mangle]
extern fn panic_fmt(_: ::core::fmt::Arguments, _: &'static str, _: u32, _: u32) -> ! {
    loop {}
}

#[no_mangle]
pub extern "C" fn foo(a: u32, b: u32) -> u32 {
    a.checked_add(b).unwrap()
}
EOF
$ cat <<EOF > test.c
extern unsigned foo(unsigned, unsigned);

int main() {
    foo(1, 2);
    return 0;
}
EOF
$ cargo +nightly build --release
$ gcc -o test test.c target/release/libfoo.a
target/release/libfoo.a(core-963c548171e08e13.core0.rcgu.o): In function `core::num::<impl i128>::overflowing_mul':
/checkout/src/libcore/num/mod.rs:920: undefined reference to `__muloti4'
/checkout/src/libcore/num/mod.rs:920: undefined reference to `__muloti4'

Note this happens whether you actually use overflowing_mul or not: anything that uses a function from core::num triggers this because of how the linker works.

The following also appears:

target/release/libfoo.a(core-963c548171e08e13.core0.rcgu.o): In function `core::panicking::panic_fmt':
/checkout/src/libcore/panicking.rs:71: undefined reference to `rust_begin_unwind'

which is surprising when building with panic=abort.

Somehow, building without --release (but adding panic=abort to profile.dev) adds another error:

target/debug/libfoo.a(foo-4ef191f9b3780723.4ypvbwho0bu5tnww.rcgu.o):(.data.DW.ref.rust_eh_personality[DW.ref.rust_eh_personality]+0x0): undefined reference to `rust_eh_personality'

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions