From patchwork Tue Nov 13 11:39:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 30132 Received: (qmail 4207 invoked by alias); 13 Nov 2018 11:39:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3773 invoked by uid 89); 13 Nov 2018 11:39:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Compile with -fno-strict-aliasing Date: Tue, 13 Nov 2018 12:39:45 +0100 Message-ID: <87y39xjjem.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 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 * malloc/Makefile (CFLAGS-malloc.c): Compile malloc.c if -fno-strict-aliasing due to aliasing violations. 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)) \