Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5644542imu; Mon, 26 Nov 2018 03:27:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xnf08PDeQG4BwzBinTksQvLKKc+o/B2lOdwptT4S645gbQZYbMtqrAPgbAP9CZTw3E21nW X-Received: by 2002:a62:1a8e:: with SMTP id a136mr12836706pfa.76.1543231629590; Mon, 26 Nov 2018 03:27:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543231629; cv=none; d=google.com; s=arc-20160816; b=RapzI1VQGi8Dk0dvS4pXIjLDhXtflB+eaoNZ4mCLHC5AYs9cSY4L57CrIc+uFRN1si Oc6HUYXJoVynidQNFUlNs6jvrV1NirdmcGWPdK7txfGQydKzn5nfRuJAIL5P3vyw0bjB +BFCrFnHrpuXcso1H965HXo/MAfmr8/tmZu1Fvyy8YsNvPsBvtvhQOt39kX0Nq2RbJ72 m35RkausbW7piTwyR+F2CMPrXgSqJ3lCWQMEVRQjeTQXwUegE2fUUQ+qZmQbcK2EPZZb 7dDnto2cARPBpMjbur+EizZ9+LPbZj7DfLmyrymhmlASsDaEv5ccduy6smlDXiQ+RjXK DRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DdZRlQD5uVQwzfjI0Qyn45MbX6iz08ODOpNqrxzcCwA=; b=ObQbXhaaT+2ttLGZB92RLC1oGRO18COuZXCZ5K57H93f+gm0chibfUpLi9IEzFWPWy Yax8a4fjhDlmx09kT7LJifYEHA0L7+IRlO1SVzEltiO/B2B+GFzqVCl0IBWNDMTX/lPs FMSknbgb65th7H2cog6Bf6En4IBmhUknUgj4CCFHexfp8YQRZeylaUh3q5pWWj/hreiB yQdybhmRIw7odHSRjMHEmZ8iuMBWtKcfqVF8bJF4QtJkpU76vaPagkmTv9yw5X+hOpLa gRfWfERxijPY8PrdOyzUSXOokALs1hceHHOfmTLyuHesRZFc0G6JVMuvp53d7luxRMjB PnmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qcc4QG07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 193si14058pgc.220.2018.11.26.03.26.45; Mon, 26 Nov 2018 03:27:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qcc4QG07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727638AbeKZVse (ORCPT + 99 others); Mon, 26 Nov 2018 16:48:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:57140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbeKZVsd (ORCPT ); Mon, 26 Nov 2018 16:48:33 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A87A52089F; Mon, 26 Nov 2018 10:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543229689; bh=wXR5OY3d2wpKSPu4/C9+/cViUuiNTlMfyxjAClR0HhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qcc4QG07NTNg7a650StKb9LX4B76TS2qUhbXOcwMB99SxAvOsUtrQ3q2AiWmA0pjI Nl8DLuYkrcolrI/9Dyqx/7CMkNxxwRoVor7q3kJZoCc2gvMde42mJYyaeT5vhLvKxB qmK0+y4vqjJPpXU5Q83M4Kc92iSBaxWJVZe6g5eA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthias Kaehlcke , Ingo Molnar , Masahiro Yamada , Nathan Chancellor Subject: [PATCH 4.4 34/70] x86/build: Specify stack alignment for clang Date: Mon, 26 Nov 2018 11:50:49 +0100 Message-Id: <20181126105050.030657011@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105046.722096341@linuxfoundation.org> References: <20181126105046.722096341@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthias Kaehlcke commit d77698df39a512911586834d303275ea5fda74d0 upstream. For gcc stack alignment is configured with -mpreferred-stack-boundary=N, clang has the option -mstack-alignment=N for that purpose. Use the same alignment as with gcc. If the alignment is not specified clang assumes an alignment of 16 bytes, as required by the standard ABI. However as mentioned in d9b0cde91c60 ("x86-64, gcc: Use -mpreferred-stack-boundary=3 if supported") the standard kernel entry on x86-64 leaves the stack on an 8-byte boundary, as a consequence clang will keep the stack misaligned. Signed-off-by: Matthias Kaehlcke Acked-by: Ingo Molnar Signed-off-by: Masahiro Yamada Signed-off-by: Nathan Chancellor Signed-off-by: Greg Kroah-Hartman --- arch/x86/Makefile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -11,6 +11,14 @@ 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. # @@ -28,7 +36,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os 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), -mpreferred-stack-boundary=2) +REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align_opt)=2) export REALMODE_CFLAGS # BITS is used as extension for files which are available in a 32 bit @@ -65,8 +73,10 @@ ifeq ($(CONFIG_X86_32),y) # with nonstandard options KBUILD_CFLAGS += -fno-pic - # prevent gcc from keeping the stack 16 byte aligned - KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2) + # 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) # 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: @@ -98,8 +108,14 @@ else KBUILD_CFLAGS += $(call cc-option,-mno-80387) KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387) - # Use -mpreferred-stack-boundary=3 if supported. - KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3) + # By default gcc and clang use a stack alignment of 16 bytes for x86. + # However the standard kernel entry on x86-64 leaves the stack on an + # 8-byte boundary. If the compiler isn't informed about the actual + # alignment it will generate extra alignment instructions for the + # 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) # Use -mskip-rax-setup if supported. KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)