nuttx/fs
Marco Casaroli 1aa32bbc07 libs/libc/elf: Place an FDPIC object's segments independently.
An ET_DYN object is loaded into one allocation with its data behind its
text, because its data references sit at a fixed distance from the code
that makes them.  An FDPIC object does not work that way: it reaches its
data through a base register, so the two segments can be placed wherever
suits, and the point of the format is that the read-only one is left on
the media and executed there while only the writable one is copied.  One
copy of the text then serves every instance.

So libelf_load() grows a second case.  The object announces itself in the
OS/ABI byte, which is noted once in libelf_loadhdrs() rather than
re-derived; e_flags cannot be used for this, as an FDPIC object's are an
unremarkable EABI version and testing them would reject every valid
module.  Text is taken from the media address plus the segment's own file
offset -- the same arithmetic the ET_REL path already does with
sh_offset -- and libelf_loadfile() does not read it.  If the filesystem
cannot show its media, the loader copies the text to RAM instead.  The
module then loses the shared text and the flash saving, but it runs.

Obtaining that address needs two mechanisms, and they are not
interchangeable.  A compacting filesystem can move a file's blocks, so it
hands out an address only with a pin that holds them still and expects
the pin back; xipfs is the one in tree.  A filesystem whose layout never
changes has nothing to hold and answers FIOC_XIPBASE with a bare address;
romfs and tmpfs are those.  libelf_xipacquire() asks for the pin first,
because a filesystem that needs one is not safe without it, and
libelf_unload() gives it back.  The loader asks for a pin only if it can
hold one, or the pin would stay for ever.

The pin is thus not specific to FDPIC.  Any module that executes in place
from a compacting filesystem takes one, and gives it back at unload.

mmap() is not used, though both filesystems implement it.  The mapping
would be recorded against whichever task called the loader, while the
release happens when the module's own task exits, which is a different
group -- so the pin would outlive the module and the extent would never
become movable again.

Unloading has to change with placement: the existing path frees only
textalloc because ET_DYN had a single allocation, which would leak an
FDPIC object's data and free media the filesystem only lent us.

Nothing here runs for a non-FDPIC object; every branch is behind the flag
and the single-allocation path is untouched.  Built and booted
mps3-an547:picostest, which is CONFIG_ELF with CONFIG_PIC, with no change
in behaviour.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-09-08 16:31:16 -03:00
..
aio !include/fcntl.h: align open flags with Linux values 2026-06-30 13:43:44 +08:00
binfs sched,fs,docs: support setuid sudo helper 2026-08-18 15:57:52 +08:00
cromfs fs/cromfs: Fix stale cache read in read() fast path. 2026-08-12 12:12:46 -03:00
driver libs/libc: Fix divide-by-zero in stat() with large filesystem block sizes 2026-07-16 23:37:22 +08:00
event nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
fat fs/fat: Restore the no-short-name marker when the name will not shorten. 2026-08-08 10:05:43 +02:00
hostfs fs: remove redundant ".." handling after VFS canonicalization 2026-08-28 23:07:24 +08:00
inode fs/inode: propagate inode search errors 2026-09-04 13:50:54 -03:00
littlefs cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR) 2026-08-09 11:13:08 -03:00
mmap !include/fcntl.h: align open flags with Linux values 2026-06-30 13:43:44 +08:00
mnemofs fs/mnemofs: Add mnemofs version 1 support. 2026-05-19 10:29:11 +08:00
mount fs/procfs: fix buffer overflow in mount_sprintf 2026-09-06 12:16:02 -03:00
mqueue nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
nfs !include/fcntl.h: align open flags with Linux values 2026-06-30 13:43:44 +08:00
nxffs fs/vfs: Add ioctldir for volume ioctls via the mountpoint directory. 2026-07-25 07:28:22 -03:00
partition fs/partition: bound TXTABLE partition names 2026-07-06 07:51:46 +02:00
procfs fs/procfs: fix incorrect environ read for another task under CONFIG_ARCH_ADDRENV 2026-07-11 12:43:10 -03:00
romfs fs/romfs: reject negative resulting position in romfs_seek() 2026-08-21 02:20:33 +08:00
rpmsgfs fs: remove redundant ".." handling after VFS canonicalization 2026-08-28 23:07:24 +08:00
semaphore nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
shm nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
smartfs fs: fix pre-existing nxstyle issues in touched files 2026-08-28 23:07:24 +08:00
socket include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
spiffs !include/fcntl.h: align open flags with Linux values 2026-06-30 13:43:44 +08:00
tmpfs fs: enforce path search and unify inode permission helpers 2026-08-02 18:48:40 -03:00
unionfs include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
userfs include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
v9fs include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
vfs fs/vfs: fix link() returning EXDEV instead of ENAMETOOLONG 2026-08-28 23:07:24 +08:00
xipfs libs/libc/elf: Place an FDPIC object's segments independently. 2026-09-08 16:31:16 -03:00
zipfs
CMakeLists.txt
fs_heap.c mm/mm_heap: use struct mm_heap_config_s to init the memory heap 2026-01-19 14:18:27 +08:00
fs_heap.h
fs_initialize.c
Kconfig libs/libc/elf: Place an FDPIC object's segments independently. 2026-09-08 16:31:16 -03:00
Makefile fs/xipfs: Add a contiguous execute-in-place file system. 2026-07-29 07:49:03 -03:00