Skip to content

tools/mpy_ld.py: Ignore R_XTENSA_NDIFF32 relocations.#19286

Merged
dpgeorge merged 1 commit into
micropython:masterfrom
agatti:xtensa-add-more-relaxation-relocations
Jun 3, 2026
Merged

tools/mpy_ld.py: Ignore R_XTENSA_NDIFF32 relocations.#19286
dpgeorge merged 1 commit into
micropython:masterfrom
agatti:xtensa-add-more-relaxation-relocations

Conversation

@agatti
Copy link
Copy Markdown
Contributor

@agatti agatti commented May 31, 2026

Summary

This PR introduces support for the negative counterpart of R_XTENSA_PDIFF32, ignoring the relocation instead of aborting processing.

There are more relaxation relocations that could be ignored but so far R_XTENSA_NDIFF32 was the only one that was encountered in the wild. Others can be added at a later stage if updated Xtensa toolchains start emitting them or if users file bug reports about linking errors due to unsupported relocation types.

This addresses #8781.

Testing

In #8781 the relocation in question was encountered when linking a native module using the ESP32S3-specific binaries from ESP-IDF. However, I wasn't able to trigger the generation of that relocation when rebuilding all example natmods with CROSS=xtensa-esp32s3-elf-.

Still, the relocation was emitted via this small assembler file:

	.text
	.literal_position
	.literal .LC0, mp_fun_table
	.align 4
	.type fun, @function
fun:
	entry sp, 32
	l32r a0, .LC0
	.reloc fun, R_XTENSA_NDIFF32
	retw.n
	.size fun, .-fun
	.global mpy_init
	.type mpy_init, @function
mpy_init:
	entry sp, 32
	retw.n
	.size mpy_init, .-mpy_init
	.section .rodata
	.align 4
	.type fun_obj, @object
	.size fun_obj, 8
fun_obj:
	.word 0
	.word fun

Which was built with xtensa-esp32s3-elf-as -o reloc.o reloc.s, and then attempted to converted into a MPY file via tools/mpy_ld.py -o out.mpy -march=xtensawin reloc.o. Without this change, linking will fail due to an unknown relocation (of type R_XTENSA_NDIFF32).

Generative AI

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

This commit introduces support for the negative counterpart of
`R_XTENSA_PDIFF32`, ignoring the relocation instead of aborting
processing.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@agatti agatti added the tools Relates to tools/ directory in source, or other tooling label May 31, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (44a569b) to head (14660f6).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19286   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files         176      176           
  Lines       22845    22845           
=======================================
  Hits        22497    22497           
  Misses        348      348           

☔ 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.

@github-actions
Copy link
Copy Markdown

Code size report:

Reference:  rp2/CMakeLists.txt: Require boards to define PICO_FLASH_SIZE_BYTES. [44a569b]
Comparison: tools/mpy_ld.py: Ignore R_XTENSA_NDIFF32 relocations. [merge of 14660f6]
  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

Copy link
Copy Markdown
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.

Looks good, thanks!

@octoprobe-bot
Copy link
Copy Markdown

octoprobe-bot commented Jun 1, 2026

Octoprobe PR report

Summary

Test Groups
run
Groups
skipped
Groups
retried
Tests
passed
Tests
skipped
Tests
xfailed
Tests
failed
RUN-FLASH_FORMAT 18 10 8
RUN-NATMODTESTS 18 560 139 7
RUN-PERFBENCH 19 436 15 2
RUN-TESTS_EXTMOD_HARDWARE_NATIVE 18 58 80 24
RUN-TESTS_EXTMOD_HARDWARE 18 60 78 24
RUN-TESTS_STANDARD_NATIVE 18 15847 2722 30
RUN-TESTS_STANDARD_VIA_MPY 19 17484 2287 9
RUN-TESTS_STANDARD 18 16539 2199 8
Total 146 50994 7528 104

@dpgeorge dpgeorge merged commit 10d4018 into micropython:master Jun 3, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Relates to tools/ directory in source, or other tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants