From patchwork Wed Jul 11 14:31:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 942524 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41QhMg46FBzB4MR for ; Thu, 12 Jul 2018 00:31:27 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B72A12654F; Wed, 11 Jul 2018 14:31:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eLJslqiqF9Dm; Wed, 11 Jul 2018 14:31:21 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id CA027265B8; Wed, 11 Jul 2018 14:31:21 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id F18161BFEBC for ; Wed, 11 Jul 2018 14:31:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EEDC48763C for ; Wed, 11 Jul 2018 14:31:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XBPo3B7FcS8w for ; Wed, 11 Jul 2018 14:31:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ch3vs02.rockwellcollins.com (ch3vs02.rockwellcollins.com [205.175.226.29]) by whitealder.osuosl.org (Postfix) with ESMTPS id 3D75A87658 for ; Wed, 11 Jul 2018 14:31:16 +0000 (UTC) Received: from ofwch3n02.rockwellcollins.com (HELO ciulimr02.rockwellcollins.com) ([205.175.226.14]) by ch3vs02.rockwellcollins.com with ESMTP; 11 Jul 2018 09:31:16 -0500 X-Received: from bacon.rockwellcollins.com (unknown [192.168.6.146]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 3FF27200A1; Wed, 11 Jul 2018 09:31:15 -0500 (CDT) From: Matt Weber To: buildroot@buildroot.org Date: Wed, 11 Jul 2018 09:31:10 -0500 Message-Id: <20180711143113.11927-4-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711143113.11927-1-matthew.weber@rockwellcollins.com> References: <20180711143113.11927-1-matthew.weber@rockwellcollins.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 3/6] package/Makefile.in: Use gcc spec files for PIE build flags X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Stefan Sørensen The PIE build flags are only intended for building executables and can not be used in relocateable links (-r), static builds and shared library build - including the flags here causes build errors. So instead of parsing the PIE flags directly on the command line to gcc, include them in a gcc spec file where it is possible to only apply the flags when other incompatible flags are not set. This method and the spec files are from the Fedora build system. Originally submitted as http://patchwork.ozlabs.org/patch/907093/ Signed-off-by: Stefan Sørensen Signed-off-by: Matt Weber --- package/Makefile.in | 4 ++-- toolchain/gcc-specs-pie-cc1 | 2 ++ toolchain/gcc-specs-pie-ld | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 toolchain/gcc-specs-pie-cc1 create mode 100644 toolchain/gcc-specs-pie-ld diff --git a/package/Makefile.in b/package/Makefile.in index 14b3bbd243..00ddf48c10 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -158,8 +158,8 @@ ifeq ($(BR2_RELRO_PARTIAL),y) TARGET_HARDENED += $(TARGET_CFLAGS_RELRO) TARGET_LDFLAGS += $(TARGET_CFLAGS_RELRO) else ifeq ($(BR2_RELRO_FULL),y) -TARGET_HARDENED += -fPIE $(TARGET_CFLAGS_RELRO_FULL) -TARGET_LDFLAGS += -pie $(TARGET_CFLAGS_RELRO_FULL) +TARGET_HARDENED += $(TARGET_CFLAGS_RELRO_FULL) -specs=$(TOPDIR)/toolchain/gcc-specs-pie-cc1 +TARGET_LDFLAGS += $(TARGET_CFLAGS_RELRO_FULL) -specs=$(TOPDIR)/toolchain/gcc-specs-pie-ld endif ifeq ($(BR2_FORTIFY_SOURCE_1),y) diff --git a/toolchain/gcc-specs-pie-cc1 b/toolchain/gcc-specs-pie-cc1 new file mode 100644 index 0000000000..fc54bcb510 --- /dev/null +++ b/toolchain/gcc-specs-pie-cc1 @@ -0,0 +1,2 @@ +*cc1_options: ++ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} diff --git a/toolchain/gcc-specs-pie-ld b/toolchain/gcc-specs-pie-ld new file mode 100644 index 0000000000..bd6b9071ff --- /dev/null +++ b/toolchain/gcc-specs-pie-ld @@ -0,0 +1,2 @@ +*self_spec: ++ %{!static:%{!shared:%{!r:-pie}}}