From patchwork Wed Dec 21 11:42:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 35346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3475327wrn; Wed, 21 Dec 2022 03:43:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXt1H/peWJhQ03SdyIRwxZ8sWqTPNWSowZWtI8tE901uY8UedMBPVZZtMUBfpln579F/Eq5J X-Received: by 2002:a05:6402:d5c:b0:46b:444b:ec40 with SMTP id ec28-20020a0564020d5c00b0046b444bec40mr1124681edb.15.1671623023335; Wed, 21 Dec 2022 03:43:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671623023; cv=none; d=google.com; s=arc-20160816; b=kEzDC2W23IBtTmwzCipi1S/Z+Q7dwXpsEKw6Y9by/3TlasIhrmIlW69PezKZAvJX0K /K+raNl+pc6Rc7uayrCPbcf8gM1WEec5d4TEN6/Etpd3yTyIdbKEP9T4ZEGCl+PhrEJ9 dKTLU1pm+5wXvxoXBvf1vn+oJAqJYA31N9E0+KF4ckAjz/giaCD0QxvRhvcg4DAJqrD1 mxtbJSbodiO8DkR/1wQVVZBckP/1LXqpF1GIN5gFuWDSu5KAWcWGRq5ypw99gZVcBNY8 DvbtVqNoS9Kbg2MvjbBcst6toHPMHQz9GVwBpvBri6YW8n3pox7MJ8O4PC5ERee1nmqK p5og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=inZ14AN58Jt5+zasbf80LfAxdx99xq3Bqc/MtO+6Vlk=; b=nNo0Wng6Sxjt4U44k8Q2KyBMzeURtpjQ7+EncdKT6unYNpt6EGk+AaaFDmNmyvgo6K NlZZtTP3iKxLg5sQgWo6QvgvwnYHR1ZnAemN8VsNNxnNPfThrQtJr+gaaexdj9DBZVul RQ777VqzM32d/XnOqOgYDOuN58xxEntL59B9/rVSpGQ3KkOp5GQRVr2JSMXgjUIcLXqM PfDD7sRTOnysabtxceVKGrIm3Qchl+pmm9YVhtYuJSnt/TXodjVKzXlk84cS6po1IhNA QgdFFH67TB3i5igakXV/7WmCu/1d4k6enMDm+pOSWlNBIybquL3ut16L8h6fLf4kZFIN toWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=omluR2VA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fj27-20020a0564022b9b00b0046ffcd4df07si3033359edb.569.2022.12.21.03.43.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 03:43:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=omluR2VA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 319B13857C44 for ; Wed, 21 Dec 2022 11:43:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 319B13857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671623017; bh=inZ14AN58Jt5+zasbf80LfAxdx99xq3Bqc/MtO+6Vlk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=omluR2VACv2V8LUhUVW+w3eyix9g9MDNJWUQ+7EIe2lsJ4KT1oEAN2UmZQPKT7lmU yuf3X1YqhRGfMZ3jBBvA0ugMAUSQxRt0NAzk0cRWADnql/gXCQpHkkAzbvPDhigQwf OnXYxqqc5YfpeTq1MefG5EnvQU1SVOxOIOBemhJU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id A8483385842C for ; Wed, 21 Dec 2022 11:42:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A8483385842C Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 3C7F3280891; Wed, 21 Dec 2022 12:42:53 +0100 (CET) Date: Wed, 21 Dec 2022 12:42:53 +0100 To: gcc-patches@gcc.gnu.org, mliska@suse.cz Subject: Make -fwhole-program to work with incremental LTO linking Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752823783129411584?= X-GMAIL-MSGID: =?utf-8?q?1752823783129411584?= Hi, this patches updates documentation of -fwhole-program which was wrongly claiming that it is useless with LTO whole it is useful for LTO without plugin and extends -fwhole-program to also work with incremental linking when non-LTO code is produced. This is useful when building kernel where the incremental link is de-facto fina binary and only some explicitly marked symbols needs to remain. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: 2022-12-21 Jan Hubicka * doc/invoke.texi: Fix documentation of -fwhole-program with LTO and document behaviour for incremental linking. gcc/lto/ChangeLog: 2022-12-21 Jan Hubicka * lto-common.cc (lto_resolution_read): With incremental linking and whole program ignore turn LDPR_PREVAILING_DEF_IRONLY to LDPR_PREVAILING_DEF_IRONLY_EXP * lto-lang.cc (lto_post_options): Do not clear flag_whole_program for incremental link diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 330da6eb5d4..8c01160e2bb 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -13648,9 +13648,12 @@ compiled. All public functions and variables with the exception of @code{main} and those merged by attribute @code{externally_visible} become static functions and in effect are optimized more aggressively by interprocedural optimizers. -This option should not be used in combination with @option{-flto}. -Instead relying on a linker plugin should provide safer and more precise -information. +With @option{-flto} this option has a limited use. In most cases the +precise list of symbols used or exported from the binary is known the +resolution info passed to the link-time optimizer by the linker plugin. It is +still useful if no linker plugin is used or during incremental link step when +final code is produced (with @option{-flto} +@option{-flinker-output=nolto-rel}). @item -flto[=@var{n}] @opindex flto diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc index f64309731fa..125064ba47e 100644 --- a/gcc/lto/lto-common.cc +++ b/gcc/lto/lto-common.cc @@ -2118,6 +2118,17 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file) if (strcmp (lto_resolution_str[j], r_str) == 0) { r = (enum ld_plugin_symbol_resolution) j; + /* Incremental linking together with -fwhole-program may seem + somewhat contradictionary (as the point of incremental linking + is to allow re-linking with more symbols later) but it is + used to build LTO kernel. We want to hide all symbols that + are not explicitely marked as exported and thus turn + LDPR_PREVAILING_DEF_IRONLY_EXP + to LDPR_PREVAILING_DEF_IRONLY. */ + if (flag_whole_program + && flag_incremental_link == INCREMENTAL_LINK_NOLTO + && r == LDPR_PREVAILING_DEF_IRONLY_EXP) + r = LDPR_PREVAILING_DEF_IRONLY; break; } } diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc index d36453ba25d..7018dfae4a5 100644 --- a/gcc/lto/lto-lang.cc +++ b/gcc/lto/lto-lang.cc @@ -901,7 +901,6 @@ lto_post_options (const char **pfilename ATTRIBUTE_UNUSED) break; case LTO_LINKER_OUTPUT_NOLTOREL: /* .o: incremental link producing asm */ - flag_whole_program = 0; flag_incremental_link = INCREMENTAL_LINK_NOLTO; break;