From patchwork Fri Jul 21 21:56:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9857725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D9C460392 for ; Fri, 21 Jul 2017 21:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B25B285B6 for ; Fri, 21 Jul 2017 21:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F71C285BB; Fri, 21 Jul 2017 21:57:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00747285B6 for ; Fri, 21 Jul 2017 21:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753527AbdGUV5z (ORCPT ); Fri, 21 Jul 2017 17:57:55 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:33691 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753516AbdGUV53 (ORCPT ); Fri, 21 Jul 2017 17:57:29 -0400 Received: by mail-pg0-f42.google.com with SMTP id k14so33701073pgr.0 for ; Fri, 21 Jul 2017 14:57:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EtAPfvazeBl1TJc5KWJGjfsyQo3QeYy6E6mK8RhgbOk=; b=PoBomnazylfGBGgcbzDOhT8X424Epsgm3ojisnnTxDvMb9dNt96kPhwQF+ZuoC+B+h KxsXcf8vyUoWDNlGKKYLbOZ5SVgcc+qBT+2kZHL/hkAOBhOlEnp7uHaZVaAVBrSHFzIr 1abJBPsD08Zuw15OqrnpTjUulXtkkWpLHjHK0moh8+Iq6gMAO1UcYbmlCqUH/vDnyYzr rGNtK9PntWIu9GYo0wPi6J6m3hRVtOFbJuaaoyGcNq8t8ThtU2JxBay9FyqcnpuXJZp0 Yu72tMW0MUkzH9qCI08qEAUtYbKy20ufys/Fi1BurBDEDPLsCxSGbaDTKYdM72DhACb4 qHYA== X-Gm-Message-State: AIVw110uT3LT7ypGjNwsBLeGxLDBvmbNbZesYEXQhohywNtFSMCFVB9G T3vPgpBow+9CG1Qg X-Received: by 10.101.70.70 with SMTP id k6mr8750693pgr.39.1500674249246; Fri, 21 Jul 2017 14:57:29 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id z16sm10303463pgc.90.2017.07.21.14.57.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Jul 2017 14:57:28 -0700 (PDT) From: Matthias Kaehlcke To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Masahiro Yamada , Michal Marek Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, dianders@chromium.org, Michael Davidson , Greg Hackmann , Nick Desaulniers , Stephen Hines , Kees Cook , Arnd Bergmann , Bernhard.Rosenkranzer@linaro.org, Matthias Kaehlcke Subject: [PATCH 2/2] x86/build: Fix stack alignment for CLang Date: Fri, 21 Jul 2017 14:56:57 -0700 Message-Id: <20170721215657.81631-2-mka@chromium.org> X-Mailer: git-send-email 2.14.0.rc0.284.gd933b75aa4-goog In-Reply-To: <20170721215657.81631-1-mka@chromium.org> References: <20170721215657.81631-1-mka@chromium.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- arch/x86/Makefile | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 1e902f926be3..2b2f59c1a5f0 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,9 @@ 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-3, $(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 +70,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-3,-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 +109,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-3,-mpreferred-stack-boundary=3,-mstack-alignment=8,) # Use -mskip-rax-setup if supported. KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)