qemu: Enable support for C++ usermodules. by agatti · Pull Request #19110 · micropython/micropython · GitHub
Skip to content

qemu: Enable support for C++ usermodules.#19110

Open
agatti wants to merge 7 commits intomicropython:masterfrom
agatti:qemu-arm-cpp-link
Open

qemu: Enable support for C++ usermodules.#19110
agatti wants to merge 7 commits intomicropython:masterfrom
agatti:qemu-arm-cpp-link

Conversation

@agatti
Copy link
Copy Markdown
Contributor

@agatti agatti commented Apr 15, 2026

Summary

This PR brings the QEMU port almost in line with the rest of the embedded targets as far as user module linking CI tests go. This is done just for one board (MPS_AN385) to not impact too much on CI build times.

To get there, however, a few issues with C++ code linking had to be sorted out. Unfortunately this only applies to Arm-based boards, since the toolchain provided by the Linux distribution in use by the CI image is incomplete as far as RISC-V goes (as in, only the C part of picolibc is provided).

Maybe when the CI image will be updated to Ubuntu 26.04 things would have improved on that front. On my Arch Linux machine VIRT_RV32 does not need any changes when built using GCC 15 provided by the Arch Linux folks themselves as the riscv64-elf-gcc package, whilst VIRT_RV64 needs some tweaking w.r.t. libgcc support. I'll leave the latter for later.

Testing

All boards in question were built with GCC 13 provided by Ubuntu 24.04 adding the example C/C++ user module as part of the build. The same process was then attempted again but with GCC 14 provided by Arch Linux.

The NETDUINO2 board variant was built after manually merging #19099 - unfortunately it wouldn't save it from running out of RAM when built with GCC 14 though.

Generative AI

I did not use generative AI tools when creating this PR.


I believe there's an opportunity here to refactor both Arm and RISC-V linkerscripts, since most sections are more or less the same across variants of the same architecture (or with very little differences that can be easily sorted out). Could be an interesting task for a first time contributor though!

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2026

Code size report:

Reference:  extmod/moductypes: Be more defensive with uctypes_struct_agg_size args. [8a56be6]
Comparison: tools/ci.sh: Let QEMU try to build with a user module. [merge of 9a6d32f]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@projectgus projectgus self-requested a review April 16, 2026 01:32
@dpgeorge
Copy link
Copy Markdown
Member

Comment thread tools/ci.sh Outdated
Copy link
Copy Markdown
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @agatti, apart from @dpgeorge's comments this looks good to me.

agatti added 7 commits April 22, 2026 22:52
This commit expands the linkerscript for i.MX6-series boards to let C++
code link with the interpreter core.

The linkerscript now contains all necessary sections for C++ code that
uses exceptions to be part of a user module inside the MicroPython
image.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit expands the linkerscript for MPS2-series boards to let C++
code link with the interpreter core.

The linkerscript now contains all necessary sections for C++ code that
uses exceptions to be part of a user module inside the MicroPython
image.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit expands the linkerscript for MPS3-series boards to let C++
code link with the interpreter core.

The linkerscript now contains all necessary sections for C++ code that
uses exceptions to be part of a user module inside the MicroPython
image.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit expands the linkerscript for nRF51-series boards to let C++
code link with the interpreter core.

The linkerscript now contains all necessary sections for C++ code that
uses exceptions to be part of a user module inside the MicroPython
image.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit expands the linkerscript for STM32-series boards to let C++
code link with the interpreter core.

The linkerscript now contains all necessary sections for C++ code that
uses exceptions to be part of a user module inside the MicroPython
image.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds a naive implementation of the "abort" standard C
library, that is needed by certain C++ runtimes let code link.

Although the Arm toolchain used in the CI image does not need this,
newer or different toolchains may actually need this (eg. the Arm EABI
toolchain provided by Arch Linux).  Given the limited scope of the QEMU
port, the function simply spins forever.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit brings the QEMU port in line with other ports when it comes
to making sure the port builds with a user module to be part of the main
interpreter.

To not impact too much on the build time, only the `MPS2_AN385` board
does this as there'd be just too many targets to test, for not much
gain.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@agatti agatti force-pushed the qemu-arm-cpp-link branch from 3ad0fc8 to 9a6d32f Compare April 22, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants