malloc: Compile with -fno-strict-aliasing

Message ID 87y39xjjem.fsf@oldenburg.str.redhat.com
State New, archived
Headers

Commit Message

Florian Weimer Nov. 13, 2018, 11:39 a.m. UTC
  Not sure what the performance impact will be.  I think this will be
quite nasty for the heap protector.  But I don't see a way around this
with the current malloc.

Thanks,
Florian

malloc does this, among other things:

    To simplify use in double-linked lists, each bin header acts
    as a malloc_chunk. This avoids special-casing for headers.
    But to conserve space and improve locality, we allocate
    only the fd/bk pointers of bins, and then use repositioning tricks
    to treat these as the fields of a malloc_chunk*.

This violates GCC's strict aliasing rules.

2018-11-13  Florian Weimer  <fweimer@redhat.com>

	* malloc/Makefile (CFLAGS-malloc.c): Compile malloc.c if
	-fno-strict-aliasing due to aliasing violations.
  

Patch

diff --git a/malloc/Makefile b/malloc/Makefile
index 7d54bad866..a8cca0a4d6 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -171,6 +171,9 @@  include ../Rules
 CFLAGS-mcheck-init.c += $(PIC-ccflag)
 CFLAGS-obstack.c += $(uses-callbacks)
 
+# malloc.c contains many aliasing violations.
+CFLAGS-malloc.c += -fno-strict-aliasing
+
 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
 	-rm -f $@
 	$(patsubst %/,cd % &&,$(objpfx)) \