libc - Fix malloc() alignment for small allocations
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 3 Sep 2016 17:24:56 +0000 (10:24 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 3 Sep 2016 17:32:04 +0000 (10:32 -0700)
commit322960dc2f43c50a9116ea9ecdca6e231e6e77f7
tree2a78b32c4658451ce7f78b38c01d54b7d4f0aee0
parentf9ad7012b5a1519091049f84669090b5f3d24f1f
libc - Fix malloc() alignment for small allocations

* malloc()'s slab allocator was set to use 8-byte alignment
  for any allocation < 128 bytes that was not otherwise on
  an integral alignment boundary.  This breaks GCC-7 which assumes
  16-byte alignment for non-16-integral sizes < 128 bytes.  e.g.
  if 18 bytes is allocated, GCC-7 assumes the resulting pointer will
  be 16-byte-aligned.

* The standard is somewhat deficient in its characterization of what the
  required alignment should be, because there are already instructions
  which prefer 32 and 64 byte alignments, but are relaxed on Intel to
  only require 16-byte alignments (aka %ymm and %zmm registers in the
  vector extensions), and its stupid to enforce even larger alignments
  for tiny allocations.

* But generally speaking it makes sense to enforce a 16-byte alignment
  for any allocations >= 16 bytes, regardless of the size being passed-in
  not being 16-byte aligned, and this change does that.  Allocations of
  less than 16 bytes will still be 8-byte aligned because it is phenominally
  wasteful for them not to be.

Reported-by: marino
lib/libc/stdlib/nmalloc.c