title: How to link .o and rust .rlib when targeting risc-v?
body: <p>I am experimenting writing a program that can run on risc v directly without os, and I have successfully run one with asm and c, and now am trying to replace c with rust.
  I created a cargo lib project and build it to .rlib, and when I want to link it with the .o generated from asm, it complains that core is not found.
  here is the error</p>
  <pre><code>clang --target=riscv32 -nostdlib -fno-builtin -march=rv32imac -mno-relax -mabi=ilp32 -g -Wall -c -o target/boot.o src/boot.S
  cargo build
  ld.lld -Ttext=0x80000000 -o os.elf target/boot.o target/riscv32imac-unknown-none-elf/debug/libriscv_rust.rlib 
  ld.lld: error: undefined symbol: core::panicking::panic::h2e965d6649af1d40
  &gt;&gt;&gt; referenced by lib.rs:7 (src/lib.rs:7)
  &gt;&gt;&gt;               riscv_rust-8a999958878e9ee1.55nghx2crt3be19z.rcgu.o:(riscv_rust::add::h34f9c59c399fd8ab) in archive target/riscv32imac-unknown-none-elf/debug/libriscv_rust.rlib
  </code></pre>
  <p>and the files <code>boot.S</code></p>
  <pre><code>.equ STACK_SIZE, 8192
  .equ MAXNUM_CPU, 8
  
  .global _start
  
  .text
  _start:
      csrr    t0, mhartid
      mv  tp, t0
      bnez    t0, park
      slli    t0, t0, 10
      la  sp, stacks + STACK_SIZE
      add sp, sp, t0
      j   start_kernel
  
  park:
      wfi
      j   park
  
  stacks:
      .skip   STACK_SIZE * MAXNUM_CPU
      .end
  </code></pre>
  <p>and <code>lib.rs</code></p>
  <pre><code>#![no_std]
  
  use core::panic::PanicInfo;
  
  #[no_mangle]
  extern &quot;C&quot; fn start_kernel() {
      loop { }
  }
  
  #[panic_handler]
  #[no_mangle]
  fn panic(_info: &amp;PanicInfo) -&gt; ! {
      loop { }
  }
  </code></pre>
  <p>and <code>.cargo/config.toml</code></p>
  <pre><code>[unstable]
  build-std = [&quot;core&quot;, &quot;compiler_builtins&quot;]
  build-std-features = [&quot;compiler-builtins-mem&quot;]
  
  [build]
  target = &quot;riscv32imac-unknown-none-elf&quot;
  </code></pre>
  <p>rust is compiled with nightly rustup</p>