From patchwork Mon Nov 14 20:45:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 9428341 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 C7E55602F0 for ; Mon, 14 Nov 2016 20:45:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B84FF28ADE for ; Mon, 14 Nov 2016 20:45:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD14728AE0; Mon, 14 Nov 2016 20:45:34 +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 242B328ADE for ; Mon, 14 Nov 2016 20:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932462AbcKNUpd (ORCPT ); Mon, 14 Nov 2016 15:45:33 -0500 Received: from mail.skyhub.de ([78.46.96.112]:59497 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932297AbcKNUpc (ORCPT ); Mon, 14 Nov 2016 15:45:32 -0500 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (door.skyhub.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eO8kLy33HChi; Mon, 14 Nov 2016 21:45:30 +0100 (CET) Received: from pd.tnic (p200300454B38C40054CCB436F1385B45.dip0.t-ipconnect.de [IPv6:2003:45:4b38:c400:54cc:b436:f138:5b45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 92CC51DA23C; Mon, 14 Nov 2016 21:45:30 +0100 (CET) Received: by pd.tnic (Postfix, from userid 1000) id 4C4F5161F54; Mon, 14 Nov 2016 21:45:29 +0100 (CET) Date: Mon, 14 Nov 2016 21:45:29 +0100 From: Borislav Petkov To: Sebastian Andrzej Siewior Cc: linux-kbuild@vger.kernel.org, Ben Hutchings , Michal Marek , x86-ml , lkml , +@pd.tnic Subject: [PATCH -v1.1] kbuild: Steal gcc's pie from the very beginning Message-ID: <20161114204529.sqn6z2bockmhxpfz@pd.tnic> References: <20161114185130.30641-1-bp@alien8.de> <20161114201457.qsevfvn465otwfvz@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161114201457.qsevfvn465otwfvz@linutronix.de> User-Agent: NeoMutt/20161014 (1.7.1) 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 On Mon, Nov 14, 2016 at 09:14:57PM +0100, Sebastian Andrzej Siewior wrote: > This also means that all feature tests fail unless the -fno-PIE is > there. > > Acked-by: Sebastian Andrzej Siewior > > This thing gcc v3.4 only but I intend to update the min requirement to > alteast gcc v3.4 to cover this. As per hpa gcc v3.4 is the lowest > version should be used for x86… Ah yes, here's a v1.1. Let's leave the cc-option check until we sort out the min supported gcc version. CC: stable too. Thanks! --- From: Borislav Petkov Date: Mon, 14 Nov 2016 19:41:31 +0100 Subject: [PATCH] kbuild: Steal gcc's pie from the very beginning So Sebastian turned off the PIE for kernel builds but that was too late - Kbuild.include already uses KBUILD_CFLAGS and trying to disable gcc options with, say cc-disable-warning, fails: gcc -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs ... -Wno-sign-compare -fno-asynchronous-unwind-tables -Wframe-address -c -x c /dev/null -o .31392.tmp /dev/null:1:0: error: code model kernel does not support PIC mode because that returns an error and we can't disable the warning. For example in this case: KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) which leads to gcc issuing all those warnings again. So let's turn off PIE/PIC at the earliest possible moment, when we declare KBUILD_CFLAGS so that cc-disable-warning picks it up too. Also, we need the $(call cc-option ...) because -fno-PIE is supported since gcc v3.4 and our lowest supported gcc version is 3.2 right now. Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Cc: Ben Hutchings Cc: Michal Marek Cc: Sebastian Andrzej Siewior --- Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3ff1fb26d8b2..9bc877d073d7 100644 --- a/Makefile +++ b/Makefile @@ -399,11 +399,12 @@ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ -Wno-format-security \ - -std=gnu89 + -std=gnu89 $(call cc-option,-fno-PIE) + KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := -KBUILD_AFLAGS := -D__ASSEMBLY__ +KBUILD_AFLAGS := -D__ASSEMBLY__ $(call cc-option,-fno-PIE) KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds @@ -621,8 +622,6 @@ include arch/$(SRCARCH)/Makefile KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,) -KBUILD_CFLAGS += $(call cc-option,-fno-PIE) -KBUILD_AFLAGS += $(call cc-option,-fno-PIE) ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,)