Skip to content

Cannot define abort() in bare-metal no-std environment #883

Description

@techmetx11

Code

#![no_std]
#![no_main]

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

// This should let me define abort(), even if it doesn't exist
#[unsafe(no_mangle)]
pub extern "C" fn abort() -> ! {
    loop {}
}

#[unsafe(no_mangle)]
fn _start() {
    unreachable!("This makes the process abort()");
}

Compiler log

$ RUSTFLAGS="-Zcodegen-backend=/opt/rustc_codegen_gcc/librustc_codegen_gcc.so -Clink-args=-T../../md.ld -Clink-args=-Wl,--oformat=binary" cargo build -Zjson-target-spec --target /opt/rustc_codegen_gcc/m68k-sega-genesis.json --release -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
   Compiling testtest v0.1.0 (/m68k/examples/testtest)
libgccjit.so: error: : gcc_jit_function_new_block: cannot add block to an imported function
gcc_jit_block_get_function: NULL block
gcc_jit_block_get_function: NULL block
libgccjit.so: error: : gcc_jit_function_new_block: cannot add block to an imported function
gcc_jit_block_end_with_jump: NULL block
gcc_jit_block_get_function: NULL block
gcc_jit_block_end_with_jump: NULL block
error: linking with `m68k-unknown-elf-cc` failed: exit status: 1
  |
  = note:  "m68k-unknown-elf-cc" "/m68k/examples/testtest/target/m68k-sega-genesis/release/deps/rustcjxEhMT/symbols.o" "<1 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/m68k/examples/testtest/target/m68k-sega-genesis/release/deps/{libcore-15668d62f4574fe9,libcompiler_builtins-8254a514a64b84ed}.rlib" "-L" "/m68k/examples/testtest/target/m68k-sega-genesis/release/deps/rustcjxEhMT/raw-dylibs" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-o" "/m68k/examples/testtest/target/m68k-sega-genesis/release/deps/testtest-bb2f26fa27bb51e5" "-Wl,--gc-sections" "-no-pie" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-T../../md.ld" "-Wl,--oformat=binary"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o): in function `compiler_builtins::math::libm_math::cbrt::cbrt':
          fake.c:(.text._RNvNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math4cbrt4cbrt+0x878): undefined reference to `abort'
          /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o): in function `<i128 as compiler_builtins::math::libm_math::support::int_traits::HInt>::widen_mul':
          fake.c:(.text.unlikely._RNvXs3_NtNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math7support3bignNtNtB7_10int_traits4HInt9widen_mul+0x2): undefined reference to `abort'
          /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o): in function `<compiler_builtins::math::libm_math::support::big::u256 as core::fmt::Debug>::fmt':
          fake.c:(.text.unlikely._RNvXs6_NtNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math7support3bigNtB5_4u256NtNtCs6bVXZla6OZW_4core3fmt5Debug3fmt+0x2): undefined reference to `abort'
          /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o): in function `<compiler_builtins::math::libm_math::support::big::i256 as core::fmt::Debug>::fmt':
          fake.c:(.text.unlikely._RNvXs7_NtNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math7support3bigNtB5_4i256NtNtCs6bVXZla6OZW_4core3fmt5Debug3fmt+0x2): undefined reference to `abort'
          /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o): in function `<compiler_builtins::math::libm_math::support::big::u256 as core::fmt::LowerHex>::fmt':
          fake.c:(.text.unlikely._RNvXs8_NtNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math7support3bigNtB5_4u256NtNtCs6bVXZla6OZW_4core3fmt8LowerHex3fmt+0x2): undefined reference to `abort'
          /gcc/lib/gcc/m68k-unknown-elf/16.0.1/../../../../m68k-unknown-elf/bin/ld: /m68k/examples/testtest/target/m68k-sega-genesis/release/deps/libcompiler_builtins-8254a514a64b84ed.rlib(compiler_builtins-8254a514a64b84ed.compiler_builtins.e29bae6411254326-cgu.1.rcgu.o):fake.c:(.text.unlikely._RNvXs9_NtNtNtNtCsjsefbAxuTTm_17compiler_builtins4math9libm_math7support3bigNtB5_4i256NtNtCs6bVXZla6OZW_4core3fmt8LowerHex3fmt+0x2): more undefined references to `abort' follow
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

error: could not compile `testtest` (bin "testtest") due to 1 previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions