[PATCH 1/2] linker_lists: Fix end-marker alignment to prevent padding
Tom Rini
trini at konsulko.com
Mon Apr 13 19:24:05 CEST 2026
On Sat, Apr 11, 2026 at 07:36:16PM -0600, Simon Glass wrote:
> Hi,
>
> On Sat, 21 Mar 2026 at 07:46, Simon Glass <sjg at chromium.org> wrote:
> >
> > From: Simon Glass <simon.glass at canonical.com>
> >
> > Change the alignment of end markers in ll_entry_end() and ll_end_decl()
> > from __aligned(4) and __aligned(CONFIG_LINKER_LIST_ALIGN) respectively
> > to __aligned(1).
> >
> > The linker places zero-size end markers at aligned boundaries based on
> > what follows them. When the next list's start marker has a high alignment
> > requirement (e.g., 32 bytes), padding gets inserted before the end
> > marker. This causes the byte span (end - start) to not be an exact
> > multiple of the struct size.
> >
> > The compiler optimises pointer subtraction (end - start) using
> > magic-number multiplication for division. This optimisation only produces
> > correct results when the byte span is an exact multiple of the struct
> > size. With padding, the result is garbage (e.g., -858993444 instead of
> > 15).
> >
> > By using __aligned(1), the end marker is placed immediately after the
> > last entry with no padding, ensuring (end - start) equals exactly
> > (n * sizeof) where n is the number of entries. This makes
> > ll_entry_count() and direct pointer arithmetic work correctly.
> >
> > Fixes: 0b2fa98aa5e5 ("linker_lists: Fix alignment issue")
> > Signed-off-by: Simon Glass <simon.glass at canonical.com>
> > ---
> >
> > include/linker_lists.h | 22 ++++++++++++++++++++--
> > 1 file changed, 20 insertions(+), 2 deletions(-)
> >
>
> Any thoughts on applying this one?
Yes, waiting for Rasmus to reply again to you or give some tags.
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20260413/9f79879e/attachment.sig>
More information about the U-Boot
mailing list