This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] elf: dl-minimal malloc needs to respect fundamental alignment
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 21 Jun 2016 06:00:13 -0700
- Subject: Re: [PATCH] elf: dl-minimal malloc needs to respect fundamental alignment
- Authentication-results: sourceware.org; auth=none
- References: <20160621111702 dot 39A5B402F6E95 at oldenburg dot str dot redhat dot com> <CAMe9rOpx1Vbr6_n8+SvGCe92TO5e+KdC3hNcNAN3LvfXhd79Ow at mail dot gmail dot com> <6ca009d9-433e-31f5-c3c0-c84ecc587059 at redhat dot com>
On Tue, Jun 21, 2016 at 5:57 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 06/21/2016 02:54 PM, H.J. Lu wrote:
>>
>> On Tue, Jun 21, 2016 at 4:17 AM, Florian Weimer <fweimer@redhat.com>
>> 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
>>
>>
>> We also have MALLOC_ALIGNMENT in malloc. Should they be consistent?
>
>
> MALLOC_ALIGNMENT is potentially larger. malloc/tst-malloc-thread-fail tests
> for alignment. To my knowledge, it passes on all regularly tested
> architectures after commit dea39b13e2958a7f0e75b5594a06d97d61cc439f.
>
MALLOC_ALIGNMENT is kind of mapped to the malloc alignment of
a psABI. Shouldn't ld.so malloc have the same alignment of libc malloc?
--
H.J.