Binding rust with C: undefined function reference __aeabi

I am working on a project using Rust on an embedded device, where I am trying to write functions in Rust that can be called from C. I am compiling a project without the standard library, more or less following this tutorial: Nested rust right now!

My Rust code only compiles .o files, but I'm having problems when trying to link C and Rust object objects together using arm-none-eabi-ld. I am getting several errors like these:

rustfunc.o: In function `func':
rustfunc.0.rs:(.text.hash+0x18): undefined reference to `__aeabi_memclr8'
...
/rust/src/libcore/slice.rs:1446: undefined reference to `__aeabi_memcpy'
/rust/src/libcore/fmt/num.rs:196: undefined reference to `__aeabi_memclr4'

      

What turns me on the most is that while I'm just linking the object files together, the errors reference both my Rust code and the code from libcore.

Does anyone have any ideas what these errors mean and why the linker can't solve these problems? Thank!

+3


source to share


1 answer


The problem is that the LLVM that your rustc

(and possibly yours cc

) is built on refers to the compiler's built-in compilers, or sometimes the internal system, which are small helper routines that the compiler thinks will be optimized for the target platform.

They usually come with the compiler, so you'll see a lot of comments on the topic "Clean phrase", why don't you link with libgcc.a

"This seems useless for white metal projects, and it won't actually work because LLVM calls several different built-in functions than gcc.

You can provide an implementation of these routines, and a real bare metal OS should probably take about five minutes to review it. You can write them in assembly or Rust:

// Use this at your peril
#[no_mangle]
pub unsafe extern fn __aeabi_memclr4(s: *mut u8, n: usize) -> *mut u8 {
    let mut i = 0;
    while i < n {
        *s.offset(i as isize) = 0u8;
        i += 1;
    }
    return s;
} 

      



After you're done dreaming, you decide to compile llvmcompiler-rt

(which is the equivalent of libgcc.a) for your purpose, and link to that.

So far, rustc

and multirust

will not increase support for setting additional targets for cross-compiling , you need to download the source Rust and try to create a cross-compiler and libraries (including compiler-rt

) on their own.

Currently arm-none-eabi

not supported, and the build is crude for a list of reasons, including arm-none-eabi-gcc

not linking an executable that Rust's jemalloc insists on. My workaround is to collect the source files from compiler-rt

and build and link them separately.

+3


source







All Articles