Cargo nm - Example from Embedicon book

Hi,

I've started giving the Embedonomicon book a read. In the first chapter the book executes:

cargo nm -- target/thumbv7m-none-eabi/debug/deps/app-*.o | grep '[0-9]* [^N] '

which should show the symbol in the pre-linking generated binary. For me though this command is not working it keeps throwing this error:

cargo nm -- target/thumbv7m-none-eabi/debug/deps/appp-c3289b33bf0c1392.o | grep '[0-9]* [^N] '
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
/home/****/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-nm: error: target/thumbv7m-none-eabi/debug/deps/appp-c3289b33bf0c1392.o: No such file or directory

but I can definitely see the file is there in that directory..

I've checked the preface page and all dependencies are already installed and update..
Any clues!!

Regards,

Are you sure it's appp and not app?

Yea, sorry, I already had an app in that directory, so used appp in cargo new, just to be able to do that inspection.
But yep that is the correct name in this case

Try using the full absolute path of the file. The relative path may not work if you are not in the correct directory. Try copying or tab-completing the file path, too – don't rely on being able to correctly type in a long, meaningless hash.

I started following along the next section on memory layout, and then the

cargo objdump --bin app -- -d --no-show-raw-insn

and I think there is a typo in the guide here, the guide has only used a single hyphen for the no show raw option

Works as the guide says and shows exactly that is on there.
At this point if I do

cargo nm -- target/thumbv7m-none-eabi/debug/deps/app-*.o | grep '[0-9]* [^N] '
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-nm: error: target/thumbv7m-none-eabi/debug/deps/app-3eed94f9633ebc30.o: No such file or directory
00000004 R RESET_VECTOR
00000008 T Reset

so the same error as before and the reset vector....

and If at this point I do the full path as you suggested

00000004 R RESET_VECTOR
00000008 T Reset
00000000 T rust_begin_unwind

the unwind that I should've seen before, but it doesnt show up till after I've made changes as per memory layout in the guide and used the full path

Also, as per the guide on first chapter, at the point when the guide says to execute cargo nm, I get the error

error: could not compile `app` due to 2 previous errors
error: Failed to parse crate metadata

I changed the name to app, it was just lazy to create appp

I got rid of this message by including in cargo.toml

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

which is actually the next step in the guide, doesnt work still, only starts to work with full path after memory layout lesson on the guide.

Well if the crate doesn't compile in the first place, then that's a problem obviously. What's the exact error if you run cargo build?

If I follow the guide then

  • Create project.
  • Make changes to main.rs

And then execute

cargo size --target thumbv7m-none-eabi --bin app
   Compiling app v0.1.0 (/home/xxxxx/Development/labs/app)
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s
   text	   data	    bss	    dec	    hex	filename
      0	      0	      0	      0	      0	app

$ cargo rustc --target thumbv7m-none-eabi -- --emit=obj
   Compiling app v0.1.0 (/home/xxxx/Development/labs/app)
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s


$ cargo nm -- target/thumbv7m-none-eabi/debug/deps/app-*.o | grep '[0-9]* [^N] '
   Compiling app v0.1.0 (/home/xxxx/Development/labs/app)
error: could not compile `app` due to 2 previous errors
error: Failed to parse crate metadata

$ cargo build
   Compiling app v0.1.0 (/home/xxxx/Development/labs/app)
error: language item required, but not found: `eh_personality`
  |
  = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
  = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`

error: could not compile `app` due to previous error

If I now jump to the next instruction in the guide, that is to include the panic strategy in Cargo.toml

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

and then do a cargo build

$ cargo build
   Compiling app v0.1.0 (/home/xxxx/Development/labs/app)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/home/xxxx/Development/labs/app/target/debug/deps/app-ee4d4a0dc5eb1c2b.app.b3ab5e28-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/xxxx/Development/labs/app/target/debug/deps" "-L" "/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-bad7ed93fdd31371.rlib" "/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-98b4d121af2b7335.rlib" "/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1d9f7e5920635d15.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/xxxx/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/xxxx/Development/labs/app/target/debug/deps/app-ee4d4a0dc5eb1c2b" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
          (.text+0x16): undefined reference to `__libc_csu_fini'
          /usr/bin/ld: (.text+0x1d): undefined reference to `__libc_csu_init'
          /usr/bin/ld: (.text+0x24): undefined reference to `main'
          /usr/bin/ld: (.text+0x2a): undefined reference to `__libc_start_main'
          collect2: error: ld returned 1 exit status
          
  = help: 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#cargorustc-link-libkindname)

error: could not compile `app` due to previous error

It looks like your C cross-toolchain is incomplete. It is not enough to install a cross-compiler; you also need to install the libraries native to the platform you are compling for.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.