Skip to content

natmod: Allow linking static libraries. #16863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2025

Conversation

agatti
Copy link
Contributor

@agatti agatti commented Mar 5, 2025

Summary

This is an update to #15838 - as requested in #15838 (comment).

All the good stuff is from @vshymanskyy, the not-so-good stuff is mine:

  • Addressed the review points raised in the original PR (cache salt key, linker script detection logic, long argument for -l, some text changes, ESP-IDF CI caching)
  • Picolibc is now supported for RV32 via a rather nasty workaround
  • Xtensa natmods are now built as part of the CI process
  • Natmods have the appropriate platform exceptions in the CI build step to make it work out of the box for most platforms
  • The object cache directory is removed as part of make clean
  • The object cache directory now contains a CACHEDIR.TAG file, so most archival/backup programs will skip that directory (if rust can do it why can't we?)
  • Removed the assumption that there's a python executable in the CI environment (minor regression from 8b1ed44), blocking manual testing on my provisioned build VMs :)

Testing

All natmod-related CI jobs ran without issues on my own repo's branch.

@agatti
Copy link
Contributor Author

agatti commented Mar 5, 2025

For the ESP32 target, successful build run logs can be found here https://github.com/agatti/micropython/actions/runs/13666850878/job/38209736600 and here https://github.com/agatti/micropython/actions/runs/13666850878/job/38209737465

The commit checker fails to see the sign-off line, but I guess fixing that is its own PR.

Copy link

github-actions bot commented Mar 5, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     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

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (f187c77) to head (31a008c).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16863   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21877    21877           
=======================================
  Hits        21558    21558           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@agatti agatti force-pushed the mpy-ld-link-archives branch from 73fdab4 to ee0c65f Compare March 6, 2025 23:11
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Mar 13, 2025
@dpgeorge
Copy link
Member

I have cleared the ESP-IDF cache in GitHub Actions, and now the esp32 tests pass on this PR.

if not is_ld_script():
return [CachedArFile(fn)]
else:
return [CachedArFile(item) for item in expand_ld_script(fn)]
Copy link
Member

Choose a reason for hiding this comment

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

I see you inverted the logic here by swapping the if/else. But I think @projectgus had a different idea in mind in his comment #15838 (comment)

I think what was intended was:

ar_header = "!<arch>\012"
with open(fn, "rb") as f:
    is_ar_file = f.read(len(ar_header)) == ar_header

if is_ar_file:
    return [CachedArFile(fn)]
else:
    return [CachedArFile(item) for item in expand_ld_script(fn)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see that now - I'm on it. I was in a bit of a hurry back then to get the RV32 stuff working (I assumed it worked out of the box like when I tried it last time).

Copy link
Member

@dpgeorge dpgeorge 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 for putting this PR together and tidying up the final bits. I have just one comment above, but otherwise this looks ready to go in.

@agatti agatti force-pushed the mpy-ld-link-archives branch 3 times, most recently from 024bf70 to 06ead3e Compare March 16, 2025 19:53
@agatti
Copy link
Contributor Author

agatti commented Mar 16, 2025

This should be it - since last time you've looked at the code I've added the proper logic reversal for the magic bytes check, the platform name comparisons in the mpy build CI step now use explicit strings (as in quoted platform names), and I've added a message to the original PR's commit explaining the picolibc workaround and providing a bit more information about the change itself.

vshymanskyy and others added 3 commits March 17, 2025 13:03
This commit introduces an additional symbol resolution mechanism to the
natmod linking process.  This allows the build scripts to look for required
symbols into selected libraries that are provided by the compiler
installation (libgcc and libm at the moment).

For example, using soft-float code in natmods, whilst technically possible,
was not an easy process and required some additional work to pull it off.
With this addition all the manual (and error-prone) operations have been
automated and folded into `tools/mpy_ld.py`.

Both newlib and picolibc toolchains are supported, albeit the latter may
require a bit of extra configuration depending on the environment the build
process runs on.  Picolibc's soft-float functions aren't in libm - in fact
the shipped libm is nothing but a stub - but they are inside libc.  This is
usually not a problem as these changes cater for that configuration quirk,
but on certain compilers the include paths used to find libraries in may
not be updated to take Picolibc's library directory into account.  The bare
metal RISC-V compiler shipped with the CI OS image (GCC 10.2.0 on Ubuntu
22.04LTS) happens to exhibit this very problem.

To work around that for CI builds, the Picolibc libraries' path is
hardcoded in the Makefile directives used by the linker, but this can be
changed by setting the PICOLIBC_ROOT environment library when building
natmods.

Signed-off-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com>
Co-authored-by: Alessandro Gatti <a.gatti@frob.it>
This commit expands the CI tests by checking whether the example native
modules are able to be built for the Xtensa architecture.

This was made possible by the changes to mpy_ld that allow symbol
resolution across standard compiler-provided libraries.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit removes the assumption made by the CI scripts that the
system-provided python executable is simply named "python".  The scripts
will now look for a binary called "python3" first, and then fall back to
"python" if that is not found.

Whilst this is currently the case for the CI environment, there are no
guarantees for this going forward.  For example minimal CI environments
set up by some developers, using the same base OS, have their python
executable called "python3".

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@dpgeorge dpgeorge force-pushed the mpy-ld-link-archives branch from 06ead3e to 31a008c Compare March 17, 2025 02:07
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

Thanks for updating!

@dpgeorge dpgeorge merged commit 31a008c into micropython:master Mar 17, 2025
66 of 67 checks passed
@agatti agatti deleted the mpy-ld-link-archives branch March 17, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy