From patchwork Wed Jun 21 23:28:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9803159 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 A4B7E600C5 for ; Wed, 21 Jun 2017 23:28:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79F892785D for ; Wed, 21 Jun 2017 23:28:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C66D28415; Wed, 21 Jun 2017 23:28:51 +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=ham 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 0FFEE2785D for ; Wed, 21 Jun 2017 23:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752167AbdFUX2Z (ORCPT ); Wed, 21 Jun 2017 19:28:25 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:36190 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751641AbdFUX2Y (ORCPT ); Wed, 21 Jun 2017 19:28:24 -0400 Received: by mail-pg0-f52.google.com with SMTP id u62so156210pgb.3 for ; Wed, 21 Jun 2017 16:28:23 -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=nAa8j8K6ih9wtznUZ3g4L+aCLYrPqyGplEWu8SHJidw=; b=ctsyOvkcaXONrXGz6/2AwgHN+rjagZdM0mFtAYYta8Zy9iUhO7R18sC1Vownvp68Qt KYbIUdbGO7wd6KErRqzREtrVlTpVfHNlTOdol0uYBgUubnSnZIPITC4BwcWUKkEmQBwK EwzKt5RJTXZ5UpXnznTVLSP+gHoCg7dGDXKBE+jnrbzehyp08JR8PLD+wGMZbjY5fkok qZgLAhFPQu7soIl3Do3BBcSAgz3kZIg8WR8j6Lrp44BUUAMeuOvu38itqrn1hctwdsZv 78G+tk3I9pVHy1B9INdC0RTG9YzdjYORYNBm+qDuqMM+MvSptVt+FdZToc4RUh1AmKtC 2KpQ== X-Gm-Message-State: AKS2vOyJqi1HeacnYjIOExCQUSAHfXQFLSvCAIT3L5jSsnp78oRa2Uq7 BzZXCF+QXMBhWUij X-Received: by 10.84.224.207 with SMTP id k15mr39002957pln.15.1498087703347; Wed, 21 Jun 2017 16:28:23 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id t4sm35618672pfa.68.2017.06.21.16.28.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 16:28:22 -0700 (PDT) From: Matthias Kaehlcke To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , "H . J . Lu" , David Woodhouse , Masahiro Yamada , Michal Marek Cc: x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Davidson , Greg Hackmann , Nick Desaulniers , Stephen Hines , Kees Cook , Arnd Bergmann , Bernhard.Rosenkranzer@linaro.org, Peter Foley , Behan Webster , Douglas Anderson , Matthias Kaehlcke Subject: [PATCH v5 2/3] x86/build: Use __cc-option for boot code compiler options Date: Wed, 21 Jun 2017 16:28:04 -0700 Message-Id: <20170621232805.149448-3-mka@chromium.org> X-Mailer: git-send-email 2.13.1.611.g7e3b11ae1-goog In-Reply-To: <20170621232805.149448-1-mka@chromium.org> References: <20170621232805.149448-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 cc-option is used to enable compiler options for the boot code if they are available. The macro uses KBUILD_CFLAGS and KBUILD_CPPFLAGS for the check, however these flags aren't used to build the boot code, in consequence cc-option can yield wrong results. For example -mpreferred-stack-boundary=2 is never set with a 64-bit compiler, since the setting is only valid for 16 and 32-bit binaries. This is also the case for 32-bit kernel builds, because the option -m32 is added to KBUILD_CFLAGS after the assignment of REALMODE_CFLAGS. Use __cc-option instead of cc-option for the boot mode options. The macro receives the compiler options as parameter instead of using KBUILD_C*FLAGS, for the boot code we pass REALMODE_CFLAGS. Also use separate statements for the __cc-option checks instead of performing them in the initial assignment of REALMODE_CFLAGS since the variable is an input of the macro. Signed-off-by: Matthias Kaehlcke --- arch/x86/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index bf240b920473..b2dae639f778 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -24,10 +24,11 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \ -DDISABLE_BRANCH_PROFILING \ -Wall -Wstrict-prototypes -march=i386 -mregparm=3 \ -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ - -mno-mmx -mno-sse \ - $(call cc-option, -ffreestanding) \ - $(call cc-option, -fno-stack-protector) \ - $(call cc-option, -mpreferred-stack-boundary=2) + -mno-mmx -mno-sse + +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) export REALMODE_CFLAGS # BITS is used as extension for files which are available in a 32 bit