Linker sections missing in Cortex-M3 binary

Hi! I'm trying to play with embedded Rust. However, I'm running into a problem when trying to run the example QEMU - The Embedded Rust Book on qemu. Qemu crashes with the following output:

qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)

R00=00000000 R01=00000000 R02=00000000 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=00000000 R13=ffffffe0 R14=fffffff9 R15=00000000
XPSR=40000003 -Z-- A handler
FPSCR: 00000000
Aborted (core dumped)

Output from cargo objdump:

hello_mcu_world:        file format elf32-littlearm

Output from cargo size:

hello_mcu_world  :
section             size   addr
.debug_loc           556    0x0
.debug_abbrev        583    0x0
.debug_info         2334    0x0
.debug_aranges       336    0x0
.debug_ranges        312    0x0
.debug_str          2806    0x0
.debug_pubnames     1576    0x0
.debug_pubtypes      637    0x0
.ARM.attributes       50    0x0
.debug_frame         488    0x0
.debug_line         2254    0x0
.comment              19    0x0
Total              11951

Output from cargo readobj:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          52 (bytes into file)
  Start of section headers:          2904 (bytes into file)
  Flags:                             0x5000200
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         15
  Section header string table index: 13

It seems as if there's no .text, .data, .rodata, .bss or .vector_table sections, which are in the book's example output. Also, my entry point address is 0x0. That would kind of explain why qemu crashes. However, I'm not sure how to debug this. What is a good strategy to find out why my toolchain produces such a lopsided binary?

Should probably state this: OS: Ubuntu 20.04.1 LTS
Rustc: rustc 1.51.0-nightly (e22670468 2020-12-30)

This usually happens when you forget to pass -Tlink.x to the linker through .cargo/config.

Ah. It seems like Ubuntu doesn't copy hidden directories by default, so my .cargo/config didn't update with the file from GitHub - rust-embedded/cortex-m-quickstart: Template to develop bare metal applications for Cortex-M microcontrollers. Will update my .cargo/config and see what it does, but it does have a lot more options and settings than my one I created, so I think it will solve my issue. Thanks!

Also had the same error.

Resetting the memory.x file resolved the issue.

(I had the foolhardy idea of skipping the emulator and go straight to hardware - hence it was out of sync and took a while to twig.)

1 Like

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.