From patchwork Wed Aug 14 13:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1972429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=d+SbdnxG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WkTJ73DsHz1yYl for ; Wed, 14 Aug 2024 23:15:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 914143858C52 for ; Wed, 14 Aug 2024 13:15:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id C95543858D3C for ; Wed, 14 Aug 2024 13:13:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C95543858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C95543858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1033 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723641222; cv=none; b=wEQtF0AQOa8e3cXSC9raDNyrYjdx0rkSiNTKKouCPT0ilJUDKkj7a4m2Y2l/9cIfMzTItkiJICR4xQ60FnWm6TJt1O6vuZPHtXtsFu49QJ4caZFtT9QUl1cCEXR0cninf0usV6GXiG5Re6fsJk3kJVS9hx7+AtP6pln+NdiWs+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723641222; c=relaxed/simple; bh=Pcuh7DuulA/WWql2gj7LR76C+NITgoWSAapeXhzBH+U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YjKfHOuLu1NQd6o5PgOOkuvE/qiXbFXUoA+fC1sEj6W94gD08hqOdehpfkalBF9scuNfqfyFNW4Chw6JjG/Z1DqoKoXDX55DQ+Z5gxLtEaqD40uHDR7ccWHdtBzFqG8ugyOUoCobnSsSqBZwXSd5iUwZ/5FUOd7OORZWbpJPkB8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2cf213128a1so4466252a91.2 for ; Wed, 14 Aug 2024 06:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723641216; x=1724246016; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GeKHauWwU/IzehF7Vv/d9mJdeje5AVQE5oO4xjO4HXg=; b=d+SbdnxGnrBWveopEDkwBzIzHav7Nd4ush70I7mhyCzJ1GTKT+bGs5qEeuMWJvb4uI 5fNrE/Pk48mnmkYzRWVtq+oRiqEPOeROGRBhyGQHWy+gx0xIzeCq1YPZEkA3/ykXI6hp K4INiHKo93O1O24ku6FIcPbIAHXIVIfYYe46+TjjL43eJyxuuE/zhzhoBlUCHQbg3PUy RTW2MJ1nGnXZxGb1f8C0w/e40K4ccc+H62Vcabof3ZCc2LJLCZBw1uFPBL+RTZIh75UJ IB3du+ovlJ/rISr4bwHdu+8yMS/5QlaJlNxwMIGwbZRaY8wUwOg56NsfA8qGlwdPUHOu 8C6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723641216; x=1724246016; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GeKHauWwU/IzehF7Vv/d9mJdeje5AVQE5oO4xjO4HXg=; b=tUckw52MfdtH7vnGUznBMk8AtjjEXAKnzAC2OHCj/uP4eOalmu45iB5l/T6ZB/h9DN rx2nV2ypd5+hWIErRJKmZVUFiidacGHBwGqmQScduTxKvpNzz82xh1Z7BSsMoppDRZK2 Mr38OWHF/RJlKHpvZM0nq71xfbT9kvIWOdxNLHWFfjC+mHdiWNggwa5Fm7+DjMcHBZSt qc2kUAAuVOPz0YRPRAqDBZCSpKPn6KJTbQ7I8irQSVjrY4kBU9HrB59nK2G0Q4OFb8JE Sqzw8imQ7pkhKYShQOA+Pe/27Ii7lSNFSC9ibgR4rrFSpFpUnh9Y6oXg/px0YHAZbwMT iyQA== X-Gm-Message-State: AOJu0YzM7x5zLbcjMyW3Ol0o7iPD+KlT4STf0vdqX/TLswmFSz1nwWJ6 vAF7z0yFwdYZYzTavgVrTSZLS57vs5tkjyCbEqOh63bqpSj9ecCGT8231Nkv X-Google-Smtp-Source: AGHT+IGQOYXvCjYTFlLOkSqc2d/BHsU+AMFqBRJklA+TMr1zaq7ZaZmfvYHno0JxHZC3tFPkxXR9ww== X-Received: by 2002:a17:90b:1949:b0:2c9:9ad5:7ca2 with SMTP id 98e67ed59e1d1-2d3aaa8d177mr3214653a91.13.1723641216258; Wed, 14 Aug 2024 06:13:36 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.56.169.70]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3ac7cf227sm1683214a91.3.2024.08.14.06.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 06:13:35 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 9ED47740330; Wed, 14 Aug 2024 06:13:34 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: josmyers@redhat.com Subject: [PATCH] Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook Date: Wed, 14 Aug 2024 06:13:34 -0700 Message-ID: <20240814131334.3217622-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3017.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The new hook allows the linker plugin to distinguish calls to claim_file_handler that know the object is being used by the linker (from ldmain.c:add_archive_element), from calls that don't know it's being used by the linker (from elf_link_is_defined_archive_symbol); in the latter case, the plugin should avoid including the unused LTO archive members in linker output. To get the proper support for archives with LTO common symbols, the linker fix for https://sourceware.org/bugzilla/show_bug.cgi?id=32083 is required. PR lto/116361 * lto-plugin.c (claim_file_handler_v2): Include the LTO object only if it is known to be used for link output. Signed-off-by: H.J. Lu --- lto-plugin/lto-plugin.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 152648338b9..2d2bfa60d42 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -1286,13 +1286,17 @@ claim_file_handler_v2 (const struct ld_plugin_input_file *file, int *claimed, lto_file.symtab.syms); check (status == LDPS_OK, LDPL_FATAL, "could not add symbols"); - LOCK_SECTION; - num_claimed_files++; - claimed_files = - xrealloc (claimed_files, - num_claimed_files * sizeof (struct plugin_file_info)); - claimed_files[num_claimed_files - 1] = lto_file; - UNLOCK_SECTION; + /* Include it only if it is known to be used for link output. */ + if (known_used) + { + LOCK_SECTION; + num_claimed_files++; + claimed_files = + xrealloc (claimed_files, + num_claimed_files * sizeof (struct plugin_file_info)); + claimed_files[num_claimed_files - 1] = lto_file; + UNLOCK_SECTION; + } *claimed = 1; } @@ -1313,7 +1317,7 @@ claim_file_handler_v2 (const struct ld_plugin_input_file *file, int *claimed, if (*claimed && !obj.offload && offload_files_last_lto == NULL) offload_files_last_lto = offload_files_last; - if (obj.offload && (known_used || obj.found > 0)) + if (obj.offload && known_used && obj.found > 0) { /* Add file to the list. The order must be exactly the same as the final order after recompilation and linking, otherwise host and target tables