rust-embedded / discovery

Discover the world of microcontrollers through Rust!
https://docs.rust-embedded.org/discovery/
Apache License 2.0
1.45k stars 492 forks source link

Recommend other gcc toolchain other than the ARM GNU ARM Embedded Toolchain #34

Open therealprof opened 7 years ago

therealprof commented 7 years ago

On my mac I have the reproducible issue that the "official" ARM GNU ARM Embedded Toolchain (6-2016-q4-major) as installed by brew cask info gcc-arm-embedded mis-compiles/-links all Rust examples independent of the type of build (debug vs release).

For example for the led-roulette example from Japaric's f3 crate I get the following (non-working) binary code with the "official" toolchain:

Disassembly of section .text:

08000000 <_VECTOR_TABLE>:
 8000000:       10002000        .word   0x10002000
 8000004:       08000195        .word   0x08000195

08000008 <_EXCEPTIONS>:
 8000008:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000018:       08000323 00000000 00000000 00000000     #...............
 8000028:       00000000 08000323 00000000 00000000     ....#...........
 8000038:       08000323 08000323                       #...#...

08000040 <_INTERRUPTS>:
 8000040:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000050:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000060:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000070:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000080:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000090:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000a0:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000b0:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000c0:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000d0:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000e0:       08000323 08000323 08000323 08000323     #...#...#...#...
 80000f0:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000100:       08000323 00000000 00000000 08000323     #...........#...
 8000110:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000120:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000130:       08000323 08000323 00000000 00000000     #...#...........
 8000140:       08000323 08000323 08000323 00000000     #...#...#.......
        ...
 8000160:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000170:       08000323 08000323 08000323 08000323     #...#...#...#...
 8000180:       08000323 08000323 00000000 00000000     #...#...........
 8000190:       08000323                                #...

08000194 <_reset>:
 8000194:       b580            push    {r7, lr}
 8000196:       b098            sub     sp, #96 ; 0x60
 8000198:       f10d 0c04       add.w   ip, sp, #4
 800019c:       e88c 000f       stmia.w ip, {r0, r1, r2, r3}
...
 800020a:       f001 f8e4       bl      80013d6 <core::fmt::write>
 800020e:       be00            bkpt    0x0000
 8000210:       e7fe            b.n     8000210 <_reset+0x7c>

08000212 <<&'a T as core::fmt::Display>::fmt>:
 8000212:       e9d0 3200       ldrd    r3, r2, [r0]
 8000216:       4608            mov     r0, r1
 8000218:       4619            mov     r1, r3
 800021a:       f000 bcfc       b.w     8000c16 <core::fmt::Formatter::pad>
...

while I do get the following with another toolchain:

Disassembly of section .text:

08000000 <_VECTOR_TABLE>:
 8000000:       10002000        .word   0x10002000
 8000004:       08000195        .word   0x08000195

08000008 <_EXCEPTIONS>:
 8000008:       080007d9 080007d9 080007d9 080007d9     ................
 8000018:       080007d9 00000000 00000000 00000000     ................
 8000028:       00000000 080007d9 00000000 00000000     ................
 8000038:       080007d9 080007d9                       ........

08000040 <_INTERRUPTS>:
 8000040:       080007d9 080007d9 080007d9 080007d9     ................
 8000050:       080007d9 080007d9 080007d9 080007d9     ................
 8000060:       080007d9 080007d9 080007d9 080007d9     ................
 8000070:       080007d9 080007d9 080007d9 080007d9     ................
 8000080:       080007d9 080007d9 080007d9 080007d9     ................
 8000090:       080007d9 080007d9 080007d9 080007d9     ................
 80000a0:       080007d9 080007d9 080007d9 080007d9     ................
 80000b0:       080007d9 080007d9 080007d9 080007d9     ................
 80000c0:       080007d9 080007d9 080007d9 080007d9     ................
 80000d0:       080007d9 080007d9 080007d9 080007d9     ................
 80000e0:       080007d9 080007d9 080007d9 080007d9     ................
 80000f0:       080007d9 080007d9 080007d9 080007d9     ................
 8000100:       080007d9 00000000 00000000 080007d9     ................
 8000110:       080007d9 080007d9 080007d9 080007d9     ................
 8000120:       080007d9 080007d9 080007d9 080007d9     ................
 8000130:       080007d9 080007d9 00000000 00000000     ................
 8000140:       080007d9 080007d9 080007d9 00000000     ................
        ...
 8000160:       080007d9 080007d9 080007d9 080007d9     ................
 8000170:       080007d9 080007d9 080007d9 080007d9     ................
 8000180:       080007d9 080007d9 00000000 00000000     ................
 8000190:       080007d9                                ....

08000194 <_reset>:
 8000194:       b570            push    {r4, r5, r6, lr}
 8000196:       f240 0000       movw    r0, #0
 800019a:       f240 0110       movw    r1, #16
 800019e:       f2c2 0000       movt    r0, #8192       ; 0x2000
 80001a2:       f2c2 0100       movt    r1, #8192       ; 0x2000
 80001a6:       1a09            subs    r1, r1, r0
 80001a8:       f021 0103       bic.w   r1, r1, #3
 80001ac:       f001 fed3       bl      8001f56 <__aeabi_memclr4>
 80001b0:       f240 0010       movw    r0, #16
 80001b4:       f240 0110       movw    r1, #16
 80001b8:       f2c2 0000       movt    r0, #8192       ; 0x2000
 80001bc:       f2c2 0100       movt    r1, #8192       ; 0x2000
 80001c0:       1a09            subs    r1, r1, r0
...
 8000476:       f04f 4390       mov.w   r3, #1207959552 ; 0x48000000
 800047a:       250a            movs    r5, #10
 800047c:       681e            ldr     r6, [r3, #0]
 800047e:       f365 4695       bfi     r6, r5, #18, #4
 8000482:       601e            str     r6, [r3, #0]
 8000484:       f643 0304       movw    r3, #14340      ; 0x3804
 8000488:       f2c4 0301       movt    r3, #16385      ; 0x4001
 800048c:       6019            str     r1, [r3, #0]
 800048e:       6059            str     r1, [r3, #4]
 8000490:       2145            movs    r1, #69 ; 0x45
 8000492:       6099            str     r1, [r3, #8]
 8000494:       210d            movs    r1, #13
 8000496:       f8c2 17f8       str.w   r1, [r2, #2040] ; 0x7f8
 800049a:       6881            ldr     r1, [r0, #8]
 800049c:       f041 0101       orr.w   r1, r1, #1
 80004a0:       6081            str     r1, [r0, #8]
 80004a2:       f04f 4080       mov.w   r0, #1073741824 ; 0x40000000
 80004a6:       2101            movs    r1, #1
 80004a8:       6001            str     r1, [r0, #0]
 80004aa:       f000 f801       bl      80004b0 <main>
        ...

080004b0 <main>:
 80004b0:       e92d 4ff0       stmdb   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
 80004b4:       f641 7086       movw    r0, #8070       ; 0x1f86
 80004b8:       f241 0118       movw    r1, #4120       ; 0x1018
 80004bc:       f241 4310       movw    r3, #5136       ; 0x1410
 80004c0:       2400            movs    r4, #0
 80004c2:       f6c0 0000       movt    r0, #2048       ; 0x800
 80004c6:       f6c4 0100       movt    r1, #18432      ; 0x4800
 80004ca:       f2c4 0300       movt    r3, #16384      ; 0x4000
 80004ce:       f100 0e08       add.w   lr, r0, #8
 80004d2:       2001            movs    r0, #1
 80004d4:       f641 7686       movw    r6, #8070       ; 0x1f86
 80004d8:       f04f 0801       mov.w   r8, #1
 80004dc:       2700            movs    r7, #0
 80004de:       f6c0 0600       movt    r6, #2048       ; 0x800
...

Most obviously (although I shortened it quite a bit above) is the much shorter _reset () and the total omission of the main function with the broken compiler. Also the included arm-none-eabi-gdb in the cask version crashes all the time with the simplest activities, like:

# arm-none-eabi-gdb f3/target/thumbv7em-none-eabihf/release/examples/led-roulette
GNU gdb (GNU Tools for ARM Embedded Processors) 7.12.0.20161204-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from f3/target/thumbv7em-none-eabihf/release/examples/led-roulette...(no debugging symbols found)...done.
(gdb) list
Abort trap: 6

For the working compiler I'm using the brew package gcc-arm-none-eabi from the px4/px4 tap.

adamgreen commented 5 years ago

Is this still an issue? It seems like only GDB is probably used from this toolchain now that the default llvm linker is used. I didn't encounter any issues running this tutorial on macOS recently but I download my GNU tools from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm