This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] elf: dl-minimal malloc needs to respect fundamental alignment


On 06/21/2016 07:17 AM, Florian Weimer wrote:
> If malloc is used instead of memalign for small alignments,
> malloc needs to provide the ABI-required alignment.
> 
> 2016-06-21  Florian Weimer  <fweimer@redhat.com>
> 
> 	* elf/dl-minimal.c (malloc): Allocate with fundamental alignment.
> 
> diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
> index c8a8f8d..2d7d139 100644
> --- a/elf/dl-minimal.c
> +++ b/elf/dl-minimal.c
> @@ -27,6 +27,7 @@
>  #include <sys/types.h>
>  #include <ldsodefs.h>
>  #include <_itoa.h>
> +#include <stdalign.h>
>  
>  #include <assert.h>
>  
> @@ -90,7 +91,7 @@ __libc_memalign (size_t align, size_t n)
>  void * weak_function
>  malloc (size_t n)
>  {
> -  return __libc_memalign (sizeof (double), n);
> +  return __libc_memalign (_Alignof (max_align_t), n);
>  }
>  
>  /* We use this function occasionally since the real implementation may
> 

I agree with H.J. here, this should be MALLOC_ALIGNMENT, and if it's larger
then so be it. It should logically match the behaviour, as best it can, of
glibc's malloc since we're handing off most commonly to that malloc after
relocation. Thus I'd like to see the behaviours harmonized. 

Other mallocs may not have the same behaviour but that's not a reason to
avoid MALLOC_ALIGNMENT.

The discussions about fixing libc malloc's alignment are out of scope for
this change IMO. We should focus on fixing ld.so's behaviour.

Out of curiosity have you tried to assemble a unit test for these functions
based on linking directly with dl-minimal.os? It would be nice to run them
through similar testing as is done by malloc.

OK to checkin if you use MALLOC_ALIGMENT.

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]