casaroli opened a new pull request, #20089:
URL: https://github.com/apache/nuttx/pull/20089

   depends-on: [apache/nuttx/pull/19942]
   
   ## Summary
   
   `[5/10]` #19942 places an FDPIC object's segments and reads its dynamic 
tags. This relocates it.
   
   A function pointer under FDPIC is not a code address. The two `PT_LOAD` 
segments are placed independently, so a pointer has to carry the data base its 
callee needs: a two word descriptor of entry point and base. 
`R_ARM_FUNCDESC_VALUE` says the word being patched is such a descriptor; 
`R_ARM_FUNCDESC` says to manufacture one and store its address.
   
   Both need state a relocation cannot carry. The second word is the object's 
own data base, from `DT_PLTGOT`, and `R_ARM_FUNCDESC` takes descriptors from a 
pool whose cursor must survive from one relocation to the next. `up_relocate()` 
gets only a relocation, a symbol and an address.
   
   `arch_data` is the existing channel for that; RISC-V already uses it to hold 
a HI20 relocation while its LO12 partner is processed. Nothing has ever seeded 
it from the loader, so `ARCH_ELFDATA_INIT` and `ARCH_ELFDATA_FINI` are added. 
Both default to nothing.
   
   The GOT written into a descriptor is always the loading object's own, even 
for an imported function. That is what makes a callback work: when the 
firmware's `qsort()` calls into a module's comparison function, the module 
needs its own base in the PIC register.
   
   ## Impact
   
   Nothing changes without `CONFIG_FDPIC`. `ARCH_ELFDATA_INIT`/`FINI` are empty 
when an architecture does not define them, and RISC-V's use of `arch_data` is 
untouched.
   
   An FDPIC relocation in an object whose OS/ABI byte does not say FDPIC is now 
refused rather than mis-applied.
   
   Implemented for armv7-m and armv8-m, the profiles FDPIC targets. Other ARM 
variants gain the `arch_elfdata_t` fields but no new relocations.
   
   ## Testing
   
   `mps3-an547:picostest` on QEMU, which is the ELF PIC user of this code: it 
loads PIC ELF modules from a romfs, `hello` prints and `ostest` runs through 
the timed mutex test, the same as without this patch.
   
   `pimoroni-pico-2-plus:xipfs-fdpic` builds with `CONFIG_FDPIC` on and off.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to