OSDN Git Service

ralloc: Make sure ralloc() allocations match malloc()'s alignment.
authorJonas Pfeil <pfeiljonas@gmx.de>
Wed, 1 Mar 2017 17:11:10 +0000 (18:11 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 16 Mar 2017 01:33:52 +0000 (01:33 +0000)
commitfbaf5955eee6b028e7f301dd0609a413f5aa2f3e
tree76bd95d57f055ea1f080bb2799c6deeb79beb084
parente13a41d91e75df7a5527a60b4c3c8ee2976dad14
ralloc: Make sure ralloc() allocations match malloc()'s alignment.

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 <pfeiljonas@gmx.de>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Cc: mesa-stable@lists.freedesktop.org
(cherry picked from commit cd2b55e536dc806f9358f71db438dd9c246cdb14)

Squashed with

ralloc: don't leave out the alignment factor

Experimentation shows that without alignment factor gcc and clang choose
a factor of 16 even on IA-32, which doesn't match what malloc() uses (8).
The problem is it makes gcc assume the pointer is 16 byte aligned, so
with -O3 it starts using aligned SSE instructions that later fault,
so always specify a suitable alignment factor.

Cc: Jonas Pfeil <pfeiljonas@gmx.de>
Fixes: cd2b55e5 "ralloc: Make sure ralloc() allocations match malloc()'s alignment."
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100049
Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Tested by: Mike Lothian <mike@fireburn.co.uk>
Tested by: Jonas Pfeil <pfeiljonas@gmx.de>

(cherry picked from commit ff494fe999510ea40e3ed5827e7818550b6de126)
src/util/ralloc.c