rust-lang / rust-lang/rust

[AVR] undefined reference to 'abort' on static mutable variable

Open
#139,737 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkage C-bug O-AVR T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

pub static mut STATMUT : Option<String> = None;

#[unsafe(no_mangle)]
fn main() -> (){
    unsafe {
        STATMUT = Some(String::from_str("hello").unwrap());
    }
    loop {}
}

I expected to see this happen: compile successfully

Instead, this happened: error because "undefined reference to `abort'"

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (9ffde4b08 2025-04-12)
binary: rustc
commit-hash: 9ffde4b089fe8e43d5891eb517001df27a8443ff
commit-date: 2025-04-12
host: x86_64-pc-windows-msvc
release: 1.88.0-nightly
LLVM version: 20.1.2
Backtrace

   Compiling avr_undefined_abort v0.1.0 (C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort)
warning: unused variable: `layout`
  --> src\main.rs:14:28
   |
14 |     unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
   |                            ^^^^^^ help: if this is intentional, prefix it with an underscore: `_layout`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `ptr`
  --> src\main.rs:18:30
   |
18 |     unsafe fn dealloc(&self, ptr: *mut u8, layout: core::alloc::Layout) {
   |                              ^^^ help: if this is intentional, prefix it with an underscore: `_ptr`

warning: unused variable: `layout`
  --> src\main.rs:18:44
   |
18 |     unsafe fn dealloc(&self, ptr: *mut u8, layout: core::alloc::Layout) {
   |                                            ^^^^^^ help: if this is intentional, prefix it with an underscore: `_layout`

error: linking with `avr-gcc` failed: exit code: 1
  |
  = note: "avr-gcc" "C:\\Users\\EVANSG~1\\AppData\\Local\\Temp\\rustcmeadZC\\symbols.o" "<2 object files omitted>" "-Wl,--as-needed" 
"-Wl,-Bstatic" "C:\\Users\\EvansGrace02\\Documents\\Workspace\\avr_undefined_abort\\target\\avr-none\\release\\deps/{liballoc-9c92b638956aedfc.rlib,librustc_std_workspace_core-1131ff51ed7f00cf.rlib,libcore-1cd83881e403c7a7.rlib,libcompiler_builtins-8c53ab747d5dc2e3.rlib}.rlib" "-L" "C:\\Users\\EVANSG~1\\AppData\\Local\\Temp\\rustcmeadZC\\raw-dylibs" "-Wl,-Bdynamic" "-lgcc" "-Wl,-z,noexecstack" "-o" "C:\\Users\\EvansGrace02\\Documents\\Workspace\\avr_undefined_abort\\target\\avr-none\\release\\deps\\avr_undefined_abort-99f447f01c535b46.elf" "-Wl,--gc-sections" "-no-pie" "-mmcu=atmega328p" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcore-1cd83881e403c7a7.rlib(core-1cd83881e403c7a7.core.d0224d2e180dad47-cgu.02.rcgu.o): In function `core::hint::unreachable_unchecked':␍
          core.d0224d2e180dad47-cgu.02:(.text._ZN4core4hint21unreachable_unchecked17hd73c2234e42a966eE+0xa): undefined reference to `abort'␍
          C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcore-1cd83881e403c7a7.rlib(core-1cd83881e403c7a7.core.d0224d2e180dad47-cgu.06.rcgu.o): In function `core::num::nonzero::NonZero<T>::new_unchecked':␍
          core.d0224d2e180dad47-cgu.06:(.text._ZN4core3num7nonzero16NonZero$LT$T$GT$13new_unchecked17h86576d22dcc7150bE+0x4c): undefined reference to `abort'␍
          C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcore-1cd83881e403c7a7.rlib(core-1cd83881e403c7a7.core.d0224d2e180dad47-cgu.06.rcgu.o): In function `core::fmt::FormattingOptions::align':␍
          core.d0224d2e180dad47-cgu.06:(.text._ZN4core3fmt17FormattingOptions5align17h25263cf3c1a26f6aE+0x96): undefined reference to `abort'␍
          C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcore-1cd83881e403c7a7.rlib(core-1cd83881e403c7a7.core.d0224d2e180dad47-cgu.06.rcgu.o): In function `core::fmt::getcount':␍
          core.d0224d2e180dad47-cgu.06:(.text._ZN4core3fmt8getcount17h7ca8f2ef5a49a849E+0x44): undefined reference to `abort'␍       
          C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcore-1cd83881e403c7a7.rlib(core-1cd83881e403c7a7.core.d0224d2e180dad47-cgu.06.rcgu.o): In function `core::fmt::Formatter::padding':␍
          core.d0224d2e180dad47-cgu.06:(.text._ZN4core3fmt9Formatter7padding17h725c8d0e59f6bf75E+0x72): undefined reference to `abort'␍
          C:\Users\EvansGrace02\Documents\Workspace\avr_undefined_abort\target\avr-none\release\deps\libcompiler_builtins-8c53ab747d5dc2e3.rlib(compiler_builtins-8c53ab747d5dc2e3.compiler_builtins.404ba4952ab58ac7-cgu.05.rcgu.o):compiler_builtins.404ba4952ab58ac7-cgu.05:(.text._ZN4core3ptr9const_ptr33_$LT$impl$u20$$BP$const$u20$T$GT$13is_aligned_to17h9342a87594a14351E+0xac): more undefined references to `abort' follow␍
          collect2.exe: 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)

warning: `avr_undefined_abort` (bin "avr_undefined_abort") generated 3 warnings
error: could not compile `avr_undefined_abort` (bin "avr_undefined_abort") due to 1 previous error; 3 warnings emitted

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test path is named. Start by reproducing the provided AVR example with the avr-gcc linker invocation and inspect the reported references from core and compiler_builtins to abort. Done means the reproducer's AVR build no longer fails with the undefined-reference error, with regression coverage if an appropriate test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.