[8/10] binfmt/elf: Load FDPIC modules through the ELF loader - #20131
Draft
casaroli wants to merge 1 commit into
Draft
[8/10] binfmt/elf: Load FDPIC modules through the ELF loader#20131casaroli wants to merge 1 commit into
casaroli wants to merge 1 commit into
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 makesexec()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
.gotaddress; an FDPIC object names it inDT_PLTGOTinstead, which the loader has already translated. The two are the same idea reached by different routes, and both are whatup_initial_state()installs.Constructors are not binfmt's business. A module carries its own crt0, which walks
.init_arrayon the task that runs the module and then callsmain, so they run in the module's own context with its own data base. For a module arriving throughdlopen(),libelf_insert()walks the array instead, entering each entry throughfdpic_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()andlibelf_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:picostestbuilds withCONFIG_FDPICoff and on, standing alone on master.tools/checkpatch.sh -c -u -m -gpasses.Draft
Draft until
[6/10]and[7/10]are reviewed, since this is the point where they first have to work together.