Skip to content

arch/mips: Add support for loadable ELF modules - #19778

Merged
acassis merged 1 commit into
apache:masterfrom
ldube:mti
Aug 11, 2026
Merged

arch/mips: Add support for loadable ELF modules#19778
acassis merged 1 commit into
apache:masterfrom
ldube:mti

Conversation

@ldube

@ldube ldube commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Implement architecture-specific ELF header definitions and relocation handling for the MIPS architecture to enable loadable modules.

Fixes #19178.

Changes include:

  • Add arch/mips/include/elf.h with MIPS ELF relocation types and architecture-specific ELF data structures (arch_elfdata_s).
  • Implement libs/libc/machine/mips/arch_elf.c containing up_checkarch, up_relocate, and up_relocateadd functions handling R_MIPS_NONE, R_MIPS_32, R_MIPS_26, R_MIPS_HI16, and R_MIPS_LO16 relocations.
  • Integrate MIPS machine-specific C library support in libs/libc/machine/mips/Make.defs.
  • Update LDMODULEFLAGS in arch/mips/src/mips32/Toolchain.defs to include the little-endian (-EL) flag.
  • Update up_coherent_dcache for proper cache synchronization on JZ4780.

Note: Please adhere to Contributing Guidelines.

Testing

Enable the Module Example and set /dev/sda as the Block driver device path
Build nuttx. (Build used to fail before this change)
Copy ./apps/bin/chardev formated USB stick (chardev is created when nuttx is built)
Plug stick into CI20 USB port

Boot the nuttx image on the CI20 and run "module" to test.

NuttShell (NSH) NuttX-13.0.0
nsh> module
Mounting vfat filesystem at target=/mnt/vfat
module_initialize
chardev_read: Returning 36 bytes
chardev_read: Returning (0x8008fe48):
0000  48 69 20 74 68 65 72 65 2c 20 61 70 70 73 2f 65  Hi there, apps/e
0010  78 61 6d 70 6c 65 73 2f 6d 6f 64 75 6c 65 20 74  xamples/module t
0020  65 73 74 0a                                      est.            
main: Bytes read (0x8008fe48):
0000  48 69 20 74 68 65 72 65 2c 20 61 70 70 73 2f 65  Hi there, apps/e
0010  78 61 6d 70 6c 65 73 2f 6d 6f 64 75 6c 65 20 74  xamples/module t
0020  65 73 74 0a                                      est.            
chardev_write: Writing 26 bytes
chardev_write: Writing (0x80082030):
0000  48 69 20 74 68 65 72 65 20 69 6e 73 74 61 6c 6c  Hi there install
0010  65 64 20 64 72 69 76 65 72 0a                    ed driver.      
main: Bytes written (0x80082030):
0000  48 69 20 74 68 65 72 65 20 69 6e 73 74 61 6c 6c  Hi there install
0010  65 64 20 64 72 69 76 65 72 0a                    ed driver.      
module_uninitialize
main: Read 36 bytes
main: Wrote 26 bytes
nsh> 

Implement architecture-specific ELF header definitions and relocation handling
for the MIPS architecture to enable loadable modules.

Fixes apache#19178.

Changes include:
- Add `arch/mips/include/elf.h` with MIPS ELF relocation types and
  architecture-specific ELF data structures (`arch_elfdata_s`).
- Implement `libs/libc/machine/mips/arch_elf.c` containing `up_checkarch`,
  `up_relocate`, and `up_relocateadd` functions handling `R_MIPS_NONE`,
  `R_MIPS_32`, `R_MIPS_26`, `R_MIPS_HI16`, and `R_MIPS_LO16` relocations.
- Integrate MIPS machine-specific C library support in
  `libs/libc/machine/mips/Make.defs`.
- Update `LDMODULEFLAGS` in `arch/mips/src/mips32/Toolchain.defs` to include the
  little-endian (`-EL`) flag.
- Update `up_coherent_dcache` for proper cache synchronization on JZ4780.

Signed-off-by: Lwazi Dube <lwazeh@gmail.com>
@github-actions github-actions Bot added Arch: mips Issues related to the MIPS architecture Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Aug 10, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit 30a3769 into apache:master Aug 11, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: mips Issues related to the MIPS architecture Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HELP] Failed to build module example with mips-linux-gnu- toolchain.

3 participants