Swatantra-66 opened a new pull request, #20981:
URL: https://github.com/apache/nuttx/pull/20981
## Summary
Fixes #18558.
The ARM Architecture Procedure Call Standard (AAPCS-32, ยง5.2.1.1) mandates:
- **SP mod 4 = 0**: The stack pointer must be word-aligned at all times.
- **SP mod 8 = 0**: The stack pointer must be **double-word (8-byte)
aligned** at each external interface (function entry and call boundary).
In NuttX on ARM architectures (`armv6-m`, `armv7-m`, `armv8-m`, `armv7-a`,
`armv7-r`, `armv8-r`), the idle thread stack pointer is defined relative to the
end of the BSS section:
```c
#define IDLE_STACK (_ebss + CONFIG_IDLETHREAD_STACKSIZE)
```
On Cortex-M cores, `IDLE_STACK` is placed at vector table index 0 and loaded
directly into the Main Stack Pointer (`MSP`) by hardware on reset. On Cortex-A
and Cortex-R cores, `SP` is loaded with `IDLE_STACK` in startup assembly
(`arm_head.S`).
Prior to this change, board linker scripts terminated `.bss` with:
```ld
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
```
If `.bss` ended on a 4-byte boundary that was not a multiple of 8, `_ebss`
and the initial idle stack pointer `IDLE_STACK` were only 4-byte aligned (`SP %
8 == 4`).
When the idle thread invokes functions with 64-bit varargs (such as
`syslog()` with `CONFIG_SYSLOG_TIMESTAMP` enabled or formatting 64-bit integers
with `vsprintf_internal`), GCC's `va_arg` forcibly 8-byte aligns the `ap`
pointer (`bic.w r9, r9, #7`). On a 4-byte aligned stack, this advances `ap` by
12 bytes instead of 8 bytes, corrupting the varargs stream and causing
subsequent parameter dereferences to fail with Data Abort / Bus Fault
exceptions (as documented in issue #18558).
Commit 8409599ae447 (PR #18569) addressed this specifically for
`boards/arm/stm32*/`. This commit extends the fix across all remaining ARM32
boards (and any missed/newly added STM32 scripts) by aligning `_ebss` to an
8-byte boundary (`. = ALIGN(8);`).
## Impact
- **Architecture**: ARM32 (`armv6-m`, `armv7-m`, `armv8-m`, `armv7-a`,
`armv7-r`, `armv8-r`).
- **Functionality**: Guarantees that the idle task stack is always strictly
8-byte aligned at reset and throughout execution, conforming to AAPCS-32 and
preventing bus faults when 64-bit varargs / syslog timestamps are accessed in
the idle thread.
- **Compatibility**: Safe drop-in alignment enhancement; aligns with
existing STM32 implementation in commit 8409599ae447.
## Testing
- **Repository Audit**: Performed an automated audit of all 558 linker
scripts in `boards/arm/` to confirm zero remaining 4-byte aligned or unaligned
`_ebss` definitions.
- **Diff Check**: Verified clean `git diff --check` across all 341 modified
linker scripts (0 whitespace / newline errors).
- **Prior Art**: Aligns directly with merged upstream commit 8409599ae447
(`boards/arm/stm32*/: Align ARM STM32 idle stack`).
--
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]