Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp190392imu; Wed, 21 Nov 2018 17:56:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/WQB1e6497XuLxsJdVlKP6UOP6jg0TDLWEShHgdUK0ooIBU9eU1Huwy/F8cmP3OidsCFzUW X-Received: by 2002:a63:d5e:: with SMTP id 30mr8248534pgn.54.1542851784432; Wed, 21 Nov 2018 17:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542851784; cv=none; d=google.com; s=arc-20160816; b=vCoIFL2UlIb0YArjU91M72I4tELrVkA/eX5sQp5JJKjf/iveKw0Th3ybz0GfXmS8Vv v6xX8EhrmQqc02W09IkuavMDHVpLclkxXooqXgKJYHd8qvbmt14ISWeSmn9Axmg81U4t RCDJawFKx5fQWM02WogPF8S0KIongPFj025R+2lJH+SZjxpHbilFt+/s+x03esU0hPkA MQAzkOuRpPuIeBhzKxgwBtW2ApFyv72XXMoFQejgk5nqP2bE0kF3ZG/zNvDl9senzM6m onZK9rO1aX9ylwjwWhu7IlvfYJm7hLyOdgnM2zZEnZSnIzYIT9jDKXzeaDZ2rvR5+KSj TRlg== 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=w5f98TGAmXI5PSHdx5CiMvFZ/FG3IkBjX2RqyXC1940=; b=BpU4oxsrzHzY4OlsFYSSpn+2uSOnJd0zLOAVqAqXX3RCvxTiPVdVqXSA/Vvj8QUBrQ ssjVyEQOcSi4b+MD21OB/yxogmP8Y1yfO7ZJUyluo0HCrrTKvSKMgdU5pzoFAaSdh98C dwSv6Tk7ds5Q6AthesfEwJOWQ2Wj89GnKVM2XnhJVoZqDYtMoFr9sWccsW4A9OaLiy2Y savF4+4XWcwOmJ/HynXILbQ70aNhb7PjslpwnjTRSHoLeCjU9YAY88IbLfR5FSFkuwLH TZso5rVEYLiJPnzJlXIDfARESt4R3PBl0W9Fx7WKw17w3EF4f+4AQO/6snLcm4yuP52X QbYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kNNfODqt; 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 f13si20237719pln.368.2018.11.21.17.56.09; Wed, 21 Nov 2018 17:56:24 -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=kNNfODqt; 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 S2389125AbeKVFr2 (ORCPT + 99 others); Thu, 22 Nov 2018 00:47:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:42944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731945AbeKVFr1 (ORCPT ); Thu, 22 Nov 2018 00:47:27 -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 4F16D214DB; Wed, 21 Nov 2018 19:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542827513; bh=Dan1WhXZLXGQGfy3CxKnXM4oTxRorMpK8VjC8NF4qeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNNfODqtgOO+zim/pVhQYmcfv/ZWRO6vd7jZ+jCtVGXQi+hq/Tl7lZ1OhRkjCnyVE jhzjDwJgxmjLar6c1U22w4b8bZ3Z7ejzviuJY7/T/y0d2A0uO0fq1ivKbPRgYj31Ky DnblJyPRIASF6Ggutvu4+SkYUlqubN3P0RpBOznk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthias Kaehlcke , Arnd Bergmann , Bernhard.Rosenkranzer@linaro.org, Greg Hackmann , Kees Cook , Linus Torvalds , Masahiro Yamada , Michael Davidson , Nick Desaulniers , Peter Zijlstra , Stephen Hines , Thomas Gleixner , dianders@chromium.org, Ingo Molnar Subject: [PATCH 4.9 32/59] x86/build: Fix stack alignment for CLang Date: Wed, 21 Nov 2018 20:06:47 +0100 Message-Id: <20181121183509.507990211@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121183508.262873520@linuxfoundation.org> References: <20181121183508.262873520@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthias Kaehlcke commit 8f91869766c00622b2eaa8ee567db4f333b78c1a upstream. 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. cc-option isn't used here with the typical pattern of KBUILD_CFLAGS += $(call cc-option ...). The reason is that older gcc versions don't support the -mpreferred-stack-boundary option, since cc-option doesn't verify whether the alternative option is valid it would incorrectly select the clang option -mstack-alignment.. 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: Nick Desaulniers Cc: Peter Zijlstra Cc: Stephen Hines Cc: Thomas Gleixner Cc: dianders@chromium.org Link: http://lkml.kernel.org/r/20170817004740.170588-1-mka@chromium.org Signed-off-by: Ingo Molnar Signed-off-by: Nick Desaulniers Signed-off-by: Greg Kroah-Hartman --- arch/x86/Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -14,9 +14,11 @@ 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 + cc_stack_align4 := -mpreferred-stack-boundary=2 + cc_stack_align8 := -mpreferred-stack-boundary=3 +else ifneq ($(call cc-option, -mstack-alignment=16),) + cc_stack_align4 := -mstack-alignment=4 + cc_stack_align8 := -mstack-alignment=8 endif # How to compile the 16-bit code. Note we always compile for -march=i386; @@ -36,7 +38,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), $(cc_stack_align_opt)=2) +REALMODE_CFLAGS += $(cc_stack_align4) export REALMODE_CFLAGS # BITS is used as extension for files which are available in a 32 bit @@ -76,7 +78,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 += $(cc_stack_align4) # 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 +117,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 += $(cc_stack_align8) # Use -mskip-rax-setup if supported. KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)