SushiHangover

PowerShell, Learn it or Perish ;-)

master nix
Gitter

Cortex-M0 vs. M3 : LLVM and LD

"ARM Cortex-M instruction set" One of the issues that you run into using Clang/LLVM as your compiler for bare-metal ARM Cortex cores is you have to directly use arm-none-eabi-ld to do your linking.

Directly using ld can be a bit nerve wrecking at times to get the options correct (and the order of options does matter) as normally you are just let gcc use collect2 and have it internally execute ld to perform your linking.

One of the areas using it directly that can bite you is not linking to the proper libgcc.a for the Cortex-M that you are targeting. Looking into your arm-none-eabi/lib/gcc/arm-none-eabi/X.X.X tool-chain directory and you will find multiple directories. One for each ARM architecture; armv6-m, armv7-ar, armv7-m, thumb, thumb2, etc…

Add a library include for architecture directory that matches the core that you compiled against and everything will be fine:

Cortex M3 example:

1
arm-none-eabi-ld -Map bin/main.axf.map -T src/cortex_M3.ld --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/newlib-syscalls/arm-none-eabi/lib/thumb/thumb2 --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/newlib-syscalls/arm-none-eabi/lib/thumb  --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/newlib-syscalls/arm-none-eabi/lib  --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/lib/gcc/arm-none-eabi/4.8.3/armv7-m -g   obj/printf_with_malloc.o obj/startup.o --start-group -lgcc -lc --end-group -o bin/main.axf

Cortex M0+ example:

1
arm-none-eabi-ld -Map bin/main.axf.map -T src/cortex_M0.ld --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/newlib-syscalls/arm-none-eabi/lib/thumb/thumb2 --library-path /Users/administrator/Code/llvm_superproject/install/arm-none-eabi/lib/gcc/arm-none-eabi/4.8.3/armv6-m  --gc-sections --print-gc-sections  obj/printf_with_malloc.o obj/startup.o --start-group -lgcc -lc --end-group -o bin/main.axf

ARM Cortex-M instruction sets

ARM
Cortex-M
Thumb Thumb-2 Hardware
multiply
Hardware
divide
Saturated
math
DSP
extensions
Floating-point ARM
architecture
Core
architecture
Cortex-M0[1]
Most
Subset
1 or 32 cycle
No No No No
ARMv6-M[6]
Von Neumann
Cortex-M0+[2]
Most
Subset
1 or 32 cycle
No No No No
ARMv6-M[6]
Von Neumann
Cortex-M1[3]
Most
Subset
3 or 33 cycle
No No No No
ARMv6-M[6]
Von Neumann
Cortex-M3[4]
Entire Entire 1 cycle Yes Yes No No
ARMv7-M[7]
Harvard
Cortex-M4[5]
Entire Entire 1 cycle Yes Yes Yes
Optional
ARMv7E-M[7]
Harvard

Comments