[PATCH 1/2] linker_lists: Fix end-marker alignment to prevent padding

Simon Glass sjg at chromium.org
Sun Apr 12 03:36:16 CEST 2026


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?

My test series depends on it, but I'll send it as it is for now.

Regards,
Simon


More information about the U-Boot mailing list