From patchwork Sun Jan 6 15:52:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1021077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493471-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HB3LAIFy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43XjjL1S99z9sCX for ; Mon, 7 Jan 2019 02:53:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=VP7ijQrtNo5p72yr/kw7SZuuTlIwYt356W/MGhL57BqJ5XKyohXYK h+7+vmrTsn72HbAmLk9Wwm9WtSWz2P4wK1w39+oMDE9bFip6YRYMW73D8jr5t1Qf Gf0tCEy4VLYCYFzNFc6Ge2jSC0HLoN2HJullJ50P2KPRqT7PMNCB6w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=OPLhcBJl/PJUvg0i2gir50feIPo=; b=HB3LAIFyrOQMDyjRkWhe xhG9tWGAPWvFM0aX6qOIKWLLqU/nDr9Bw5HSVW9M5Fh60sE56HglW66/eu2ISuo0 6aTbH5+7S+bFrcwaobY16xC/YZUJ/GrMUOWQMqZwq5sCb7/3BQbLA8AQ00BpVR7Z RxFarQJnnZeFdqTX0WKzV7o= Received: (qmail 24258 invoked by alias); 6 Jan 2019 15:53:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24238 invoked by uid 89); 6 Jan 2019 15:52:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=backport, honza, implies X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 06 Jan 2019 15:52:57 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 39702281E56; Sun, 6 Jan 2019 16:52:55 +0100 (CET) Date: Sun, 6 Jan 2019 16:52:55 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Backport to GCC 8 branch fix for PIC LTO option merging Message-ID: <20190106155255.sxyaqrxr6jun24vz@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, I have backported the following patch to merge PIC/PIE options in LTO wrapper. Bootstrapped/regtested x86_64-linux Honza 2019-01-03 Jan Hubicka Backport from mainline 2018-08-29 Jan Hubicka PR lto/86517 PR lto/88185 * lto-opts.c (lto_write_options): Always stream PIC/PIE mode. * lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE. Index: lto-opts.c =================================================================== --- lto-opts.c (revision 267609) +++ lto-opts.c (working copy) @@ -78,6 +78,21 @@ lto_write_options (void) && !global_options.x_flag_openacc) append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openacc"); + /* Append PIC/PIE mode because its default depends on target and it is + subject of merging in lto-wrapper. */ + if (!global_options_set.x_flag_pic && !global_options_set.x_flag_pie) + { + append_to_collect_gcc_options (&temporary_obstack, &first_p, + global_options.x_flag_pic == 2 + ? "-fPIC" + : global_options.x_flag_pic == 1 + ? "-fpic" + : global_options.x_flag_pie == 2 + ? "-fPIE" + : global_options.x_flag_pie == 1 + ? "-fpie" + : "-fno-pie"); + } /* Append options from target hook and store them to offload_lto section. */ if (lto_stream_offload_p) Index: lto-wrapper.c =================================================================== --- lto-wrapper.c (revision 267609) +++ lto-wrapper.c (working copy) @@ -408,6 +408,11 @@ merge_and_complain (struct cl_decoded_op It is a common mistake to mix few -fPIC compiled objects into otherwise non-PIC code. We do not want to build everything with PIC then. + Similarly we merge PIE options, however in addition we keep + -fPIC + -fPIE = -fPIE + -fpic + -fPIE = -fpie + -fPIC/-fpic + -fpie = -fpie + It would be good to warn on mismatches, but it is bit hard to do as we do not know what nothing translates to. */ @@ -415,11 +420,38 @@ merge_and_complain (struct cl_decoded_op if ((*decoded_options)[j].opt_index == OPT_fPIC || (*decoded_options)[j].opt_index == OPT_fpic) { - if (!pic_option - || (pic_option->value > 0) != ((*decoded_options)[j].value > 0)) - remove_option (decoded_options, j, decoded_options_count); - else if (pic_option->opt_index == OPT_fPIC - && (*decoded_options)[j].opt_index == OPT_fpic) + /* -fno-pic in one unit implies -fno-pic everywhere. */ + if ((*decoded_options)[j].value == 0) + j++; + /* If we have no pic option or merge in -fno-pic, we still may turn + existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present. */ + else if ((pic_option && pic_option->value == 0) + || !pic_option) + { + if (pie_option) + { + bool big = (*decoded_options)[j].opt_index == OPT_fPIC + && pie_option->opt_index == OPT_fPIE; + (*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie; + if (pie_option->value) + (*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie"; + else + (*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie"; + (*decoded_options)[j].value = pie_option->value; + j++; + } + else if (pic_option) + { + (*decoded_options)[j] = *pic_option; + j++; + } + /* We do not know if target defaults to pic or not, so just remove + option if it is missing in one unit but enabled in other. */ + else + remove_option (decoded_options, j, decoded_options_count); + } + else if (pic_option->opt_index == OPT_fpic + && (*decoded_options)[j].opt_index == OPT_fPIC) { (*decoded_options)[j] = *pic_option; j++; @@ -430,11 +462,42 @@ merge_and_complain (struct cl_decoded_op else if ((*decoded_options)[j].opt_index == OPT_fPIE || (*decoded_options)[j].opt_index == OPT_fpie) { - if (!pie_option - || pie_option->value != (*decoded_options)[j].value) - remove_option (decoded_options, j, decoded_options_count); - else if (pie_option->opt_index == OPT_fPIE - && (*decoded_options)[j].opt_index == OPT_fpie) + /* -fno-pie in one unit implies -fno-pie everywhere. */ + if ((*decoded_options)[j].value == 0) + j++; + /* If we have no pie option or merge in -fno-pie, we still preserve + PIE/pie if pic/PIC is present. */ + else if ((pie_option && pie_option->value == 0) + || !pie_option) + { + /* If -fPIC/-fpic is given, merge it with -fPIE/-fpie. */ + if (pic_option) + { + if (pic_option->opt_index == OPT_fpic + && (*decoded_options)[j].opt_index == OPT_fPIE) + { + (*decoded_options)[j].opt_index = OPT_fpie; + (*decoded_options)[j].canonical_option[0] + = pic_option->value ? "-fpie" : "-fno-pie"; + } + else if (!pic_option->value) + (*decoded_options)[j].canonical_option[0] = "-fno-pie"; + (*decoded_options)[j].value = pic_option->value; + j++; + } + else if (pie_option) + { + (*decoded_options)[j] = *pie_option; + j++; + } + /* Because we always append pic/PIE options this code path should + not happen unless the LTO object was built by old lto1 which + did not contain that logic yet. */ + else + remove_option (decoded_options, j, decoded_options_count); + } + else if (pie_option->opt_index == OPT_fpie + && (*decoded_options)[j].opt_index == OPT_fPIE) { (*decoded_options)[j] = *pie_option; j++;