malloc() alignment on 32 bit
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Sep 19 06:33:59 PDT 2022
On 19.09.22 13:37, Enrico Scholz wrote:
> Hello,
>
> on an iMX6ull I stumpled across
>
> | zstd_decomp_init:536 workspace=8ff1a004+161320
> | ERROR: initcall ubifs_init+0x1/0xc4 failed: Invalid argument
>
> which is caused by
>
> | static int zstd_decomp_init(void)
> | void *wksp = malloc(wksp_size);
> | ...
> | ZSTD_DCtx* ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
> | if ((size_t)workspace & 7) return NULL; /* 8-aligned */
>
>
> Trivial fix would be 'memalign(8, wksp_size)', but is it really ok that
> malloc() for 32 bit has only an alignment of 4?
>
> Relevant code seems to be in common/tlsf.c
>
> | enum tlsf_private
> | {
> | #if defined (TLSF_64BIT)
> | /* All allocation sizes and addresses are aligned to 8 bytes. */
> | ALIGN_SIZE_LOG2 = 3,
> | #else
> | /* All allocation sizes and addresses are aligned to 4 bytes. */
> | ALIGN_SIZE_LOG2 = 2,
> | #endif
>
> 'ldrd/strd' require 8 byte alignment which might break with such
> alignment.
I recently learnt too that on 32-bit TLSF only has 4 byte alignment.
I also think that this is too low. 8 byte alignment sounds good IMO.
Cheers,
Ahmad
>
>
> Enrico
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list