lancaster-university / microbit-v2-samples

CODAL build tools and sample programs for the micro:bit v2.x
MIT License
64 stars 83 forks source link

Does not compile with GCC 10.3 #33

Closed microbit-carlos closed 2 years ago

microbit-carlos commented 2 years ago

Released last July.

Right now the CI in this repo fails on the macOS build, this is because brew tap we use has updated the arm gcc formula with v10.3:

[ 18%] Building CXX object libraries/codal-core/CMakeFiles/codal-core.dir/source/drivers/MAG3110.cpp.o
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s: Assembler messages:
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s:124: Warning: ignoring changed section attributes for .data
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s:136: Warning: dwarf line number information for .data ignored
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s:141: Warning: dwarf line number information for .data ignored
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s:151: Warning: dwarf line number information for .data ignored
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//ccCCqnhY.s:15751: Error: leb128 operand is an undefined symbol: .LVU24
make[2]: *** [libraries/codal-core/CMakeFiles/codal-core.dir/source/driver-models/Timer.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [libraries/codal-core/CMakeFiles/codal-core.dir/all] Error 2
make: *** [all] Error 2
Error: Process completed with exit code 1.

I've tested this in my fork testing in Ubuntu with version 10.2.1 (10-2020-q4) and that works, then on version 10.3.1 (10.3-2021.07) and it throws the same error.

caemor commented 2 years ago

The same error still exists with even newer versions:

-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0

Is there an alternative for building for microbit v2 that is currently working?

microbit-carlos commented 2 years ago

It should work with GCC 10.2 or lower at the moment.

carlosperate commented 2 years ago

Can confirm it doesn't compile with the latest Arm GCC release either: 10.3-2021.10

robyoung commented 2 years ago

can confirm that it does compile with the 10-2020-q4-major release from the GNU Arm Embedded Toolchain from the Arm Developer site.

JohnVidler commented 2 years ago

Looking into this now, and it seems like the assembler is generating debug code inside the .data block rather than the .text block for some parts of CODAL, which causes confusion for the linker when it cant find the corresponding support labels (which are still in .text elsewhere) and presents as the error we're seeing here.

Continuing to investigate

finneyj commented 2 years ago

Perfect - thanks John. Great to have you on board!

JohnVidler commented 2 years ago

Upon further investigation it does seem that the newer compiler is just pickier about where symbols get looked up at the link phase.

Moving the timing functions to .data.ramfuncs does seem to fix it for now, although this was added in the first place to support the rp2040, so before pushing a fix I'll be testing on there as well.

microbit-carlos commented 2 years ago

Does that mean those functions will be copied to RAM to be executed from there? I assume that will increase the memory footprint?

JohnVidler commented 2 years ago

The fallback op-counting timer was already running in RAM to begin with, although it is extremely small.

This change would still do this, but simply place it in the correct ELF section to make the linker happy, it'll still be in the final .data block either way.

microbit-carlos commented 2 years ago

Does the micro:bit platform need REAL_TIME_FUNC to be enabled? Can't it be disabled with an empty macro and just execute from flash?

finneyj commented 2 years ago

Most targets run off a timer @microbit-carlos, including microbit... I'm slightly surprised it isn't optimised out...

I would like to see us do a good audit of RAM/FLASH usage for micro:bit though. I suspect we can make savings in lots of places. So perhaps one for another day?

JohnVidler commented 2 years ago

Tested the patch on an rp2040 and a Micro:bit, both seem happy, so tentatively placed the patch in a new branch over on the codal-core repo; https://github.com/lancaster-university/codal-core/tree/compiler/gcc-10.3.x

If you git checkout the compiler/gcc-10.3.x branch in your local libraries/codal-core path, it should now compile with gcc 10.3.x +

JohnVidler commented 2 years ago

Pull request created over in codal-core to merge these into master, if folks are happy its not breaking anything I might have missed: https://github.com/lancaster-university/codal-core/pull/144

JohnVidler commented 2 years ago

Merged into master, (see https://github.com/lancaster-university/codal-core/pull/144 ) so this should all be fixed 👍

Closing this for now, but feel free to reopen if anyone finds issues.

microbit-carlos commented 2 years ago

Awesome, thanks @JohnVidler!