Reviewed-by: Marek Olšák <marek.ol...@amd.com> Marek
On Wed, Mar 1, 2017 at 8:21 PM, Eric Anholt <e...@anholt.net> wrote: > From: Jonas Pfeil <pfeiljo...@gmx.de> > > The header of ralloc needs to be aligned, because the compiler assumes > that malloc returns will be aligned to 8/16 bytes depending on the > platform, leading to degraded performance or alignment faults with ralloc. > > Fixes SIGBUS on Raspberry Pi at high optimization levels. > > This patch is not perfect for MSVC, as maybe in the future the alignment > for the most demanding data type might change to more than 8. > > v2: Commit message reword/typo fix, and add a bigger explanation in the > code (by anholt) > > Signed-off-by: Jonas Pfeil <pfeiljo...@gmx.de> > Cc: mesa-sta...@lists.freedesktop.org > --- > src/util/ralloc.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/src/util/ralloc.c b/src/util/ralloc.c > index d5cc16766b10..03283de71802 100644 > --- a/src/util/ralloc.c > +++ b/src/util/ralloc.c > @@ -51,7 +51,18 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr); > > #define CANARY 0x5A1106 > > -struct ralloc_header > +/* Align the header's size so that ralloc() allocations will return with the > + * same alignment as a libc malloc would have (8 on 32-bit GLIBC, 16 on > + * 64-bit), avoiding performance penalities on x86 and alignment faults on > + * ARM. > + */ > +struct > +#ifdef _MSC_VER > + __declspec(align(8)) > +#else > + __attribute__((aligned)) > +#endif > + ralloc_header > { > #ifdef DEBUG > /* A canary value used to determine whether a pointer is ralloc'd. */ > -- > 2.11.0 > > _______________________________________________ > mesa-stable mailing list > mesa-sta...@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-stable _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev