Skip to content

[8/10] binfmt/elf: Load FDPIC modules through the ELF loader - #20131

Draft
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fdpic-exec
Draft

[8/10] binfmt/elf: Load FDPIC modules through the ELF loader#20131
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fdpic-exec

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

depends-on: [/pull/20089 /pull/20130]

Summary

[5/10] #19942 places and binds an FDPIC object; [6/10] #20089 relocates it; [7/10] #20130 lets the firmware call back into it. This makes exec() of one work.

The task needs the module's data base in its PIC base register. binfmt builds a D-Space for any object with a GOT, taking the base from the .got address; an FDPIC object names it in DT_PLTGOT instead, which the loader has already translated. The two are the same idea reached by different routes, and both are what up_initial_state() installs.

Constructors are not binfmt's business. A module carries its own crt0, which walks .init_array on the task that runs the module and then calls main, so they run in the module's own context with its own data base. For a module arriving through dlopen(), libelf_insert() walks the array instead, entering each entry through fdpic_invoke(), because a descriptor resolved on the calling task carries the wrong base.

The read-only segment of a module that executes in place is held by a filesystem pin. The load takes it, and the module owns it from the point where nothing can fail any more; it is given back when the task exits. The pin is held through a reference to the file rather than a descriptor, because the descriptor belongs to the task that called the loader while the release happens on another.

libelf_remove() and libelf_uninit() give back what an FDPIC module holds: the pin, and the writable segment. The read-only one is media rather than an allocation and must not be freed.

Impact

Behind CONFIG_FDPIC, which defaults off. With it off, binfmt is what it was.

Testing

mps3-an547:picostest builds with CONFIG_FDPIC off and on, standing alone on master.

tools/checkpatch.sh -c -u -m -g passes.

Draft

Draft until [6/10] and [7/10] are reviewed, since this is the point where they first have to work together.

exec() of an FDPIC module now works.  The loader already places such an
object and binds it; what was missing is everything binfmt has to carry
across from the load to the running task.

The task needs the module's data base in its PIC base register.  binfmt
builds a D-Space for any object with a GOT, taking the base from the .got
section address; an FDPIC object names it in DT_PLTGOT instead, which the
loader has already translated, so the two are the same idea reached by
different routes and both are what up_initial_state() installs.

Constructors are not binfmt's business.  A module carries its own crt0,
which walks .init_array on the task that runs the module and then calls
main, so they run in the module's own context and with its own data base.
For a module that arrives through dlopen(), libelf_insert() walks the array
instead, and it enters each entry through fdpic_invoke() because a
descriptor resolved on the calling task carries the wrong base.

The read-only segment of a module that executes in place is held by a
filesystem pin.  The load takes it, and the module owns it from the point
where nothing can fail any more; it is given back when the task that runs
the module exits.  The pin is held through a reference to the file rather
than a descriptor, because the descriptor belongs to the task that called
the loader and the release happens on another one.

libelf_remove() and libelf_uninit() give back what an FDPIC module holds:
the pin, and the writable segment, while the read-only one is media rather
than an allocation and must not be freed.

Built for mps3-an547:picostest with CONFIG_FDPIC both ways.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

s698pm-dkit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT 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.

1 participant