From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751882AbdGRKuO (ORCPT ); Tue, 18 Jul 2017 06:50:14 -0400 Received: from terminus.zytor.com ([65.50.211.136]:33233 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751823AbdGRKuL (ORCPT ); Tue, 18 Jul 2017 06:50:11 -0400 Date: Tue, 18 Jul 2017 03:44:08 -0700 From: tip-bot for Matthias Kaehlcke Message-ID: Cc: torvalds@linux-foundation.org, peterz@infradead.org, ghackmann@google.com, tglx@linutronix.de, mmarek@suse.com, mka@chromium.org, ndesaulniers@google.com, linux-kernel@vger.kernel.org, srhines@google.com, yamada.masahiro@socionext.com, keescook@chromium.org, arnd@arndb.de, hpa@zytor.com, mingo@kernel.org, md@google.com Reply-To: peterz@infradead.org, ghackmann@google.com, torvalds@linux-foundation.org, tglx@linutronix.de, mka@chromium.org, mmarek@suse.com, ndesaulniers@google.com, linux-kernel@vger.kernel.org, keescook@chromium.org, srhines@google.com, yamada.masahiro@socionext.com, arnd@arndb.de, md@google.com, mingo@kernel.org, hpa@zytor.com In-Reply-To: <20170711212940.101416-1-mka@chromium.org> References: <20170711212940.101416-1-mka@chromium.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/build: Fix stack alignment for CLang Git-Commit-ID: 79e6b917e69a34d45e83e72f1e9bb7487d5f5832 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 79e6b917e69a34d45e83e72f1e9bb7487d5f5832 Gitweb: http://git.kernel.org/tip/79e6b917e69a34d45e83e72f1e9bb7487d5f5832 Author: Matthias Kaehlcke AuthorDate: Tue, 11 Jul 2017 14:29:40 -0700 Committer: Ingo Molnar CommitDate: Tue, 18 Jul 2017 11:02:53 +0200 x86/build: Fix stack alignment for CLang Commit: d77698df39a5 ("x86/build: Specify stack alignment for clang") intended to use the same stack alignment for clang as with gcc. The two compilers use different options to configure the stack alignment (gcc: -mpreferred-stack-boundary=n, clang: -mstack-alignment=n). The above commit assumes that the clang option uses the same parameter type as gcc, i.e. that the alignment is specified as 2^n. However clang interprets the value of this option literally to use an alignment of n, in consequence the stack remains misaligned. Change the values used with -mstack-alignment to be the actual alignment instead of a power of two. Signed-off-by: Matthias Kaehlcke Cc: Arnd Bergmann Cc: Bernhard.Rosenkranzer@linaro.org Cc: Greg Hackmann Cc: Kees Cook Cc: Linus Torvalds Cc: Masahiro Yamada Cc: Michael Davidson Cc: Michal Marek Cc: Nick Desaulniers Cc: Peter Zijlstra Cc: Stephen Hines Cc: Thomas Gleixner Cc: dianders@chromium.org Cc: linux-kbuild@vger.kernel.org Link: http://lkml.kernel.org/r/20170711212940.101416-1-mka@chromium.org Signed-off-by: Ingo Molnar --- arch/x86/Makefile | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 1e902f9..9c6f11e 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -11,14 +11,6 @@ else KBUILD_DEFCONFIG := $(ARCH)_defconfig endif -# For gcc stack alignment is specified with -mpreferred-stack-boundary, -# clang has the option -mstack-alignment for that purpose. -ifneq ($(call cc-option, -mpreferred-stack-boundary=4),) - cc_stack_align_opt := -mpreferred-stack-boundary -else ifneq ($(call cc-option, -mstack-alignment=4),) - cc_stack_align_opt := -mstack-alignment -endif - # How to compile the 16-bit code. Note we always compile for -march=i386; # that way we can complain to the user if the CPU is insufficient. # @@ -36,7 +28,8 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \ REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding) REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector) -REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align_opt)=2) +REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS),\ + -mpreferred-stack-boundary=2,-mstack-alignment=4) export REALMODE_CFLAGS # BITS is used as extension for files which are available in a 32 bit @@ -76,7 +69,7 @@ ifeq ($(CONFIG_X86_32),y) # Align the stack to the register width instead of using the default # alignment of 16 bytes. This reduces stack usage and the number of # alignment instructions. - KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=2) + KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,-mstack-alignment=4) # Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use # a lot more stack due to the lack of sharing of stacklots: @@ -115,7 +108,7 @@ else # default alignment which keep the stack *mis*aligned. # Furthermore an alignment to the register width reduces stack usage # and the number of alignment instructions. - KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=3) + KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3,-mstack-alignment=8) # Use -mskip-rax-setup if supported. KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)