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

   ## Summary
   
   `libelf_elfsize()` takes `textalign` and `dataalign` from the section 
headers, which only the `ET_REL` path walks. An `ET_DYN` object is sized from 
its program headers instead, so both stay at zero, and the allocation a few 
lines later asks `lib_memalign()` for that alignment.
   
   Zero is not a valid alignment, and every path that receives it divides by 
it. `mm_memalign()` accepts zero as a power of two, because `0 & -0` is 0, then 
takes the `alignment <= MM_ALIGN` branch and evaluates `((uintptr_t)ptr) % 
alignment` in a `DEBUGASSERT`. With `CONFIG_MM_HEAP_MEMPOOL` and a pool that 
fits the request the object never reaches that branch and gets `ALIGN_UP(blk, 
0)` instead, which is `((blk - 1) / 0) * 0`.
   
   On Cortex-M this is usually invisible: `UDIV` returns zero for a division by 
zero unless `CCR.DIV_0_TRP` is set, which NuttX does not set. It is a SIGFPE on 
the simulator, and the mempool path returns a null pointer wherever the 
division yields zero, which the loader reports as `-ENOMEM`.
   
   Ask for a natural word when the program headers gave nothing. `p_align` is 
the linker's page granularity, not a section requirement, so honouring it would 
cost a page per module for no gain.
   
   This is the second of four independent pieces split out of #19673, so each 
can be reviewed on its own. The others are `[1/4]`, `[3/4]` and `[4/4]`. They 
do not depend on each other and can merge in any order.
   
   ## Impact
   
   Every `ET_DYN` module, which is every shared object opened with `dlopen()`, 
is allocated through an aligned path rather than a zero one.
   
   No configuration change, no size change beyond the alignment of one 
allocation.
   
   ## Testing
   
   Built for `mps3-an547:picostest`, which is `CONFIG_ELF` with `CONFIG_PIC`. 
`tools/checkpatch.sh` passes.
   
   Runtime evidence on real hardware follows tomorrow, on an RP2350.
   


-- 
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