From patchwork Thu Aug 15 16:11:28 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: 1972849 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=f8Gw1auk; 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 4Wl99l2f7jz1yNr for ; Fri, 16 Aug 2024 02:11:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AA1013858C52 for ; Thu, 15 Aug 2024 16:11:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id C08EA3858D29 for ; Thu, 15 Aug 2024 16:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C08EA3858D29 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 C08EA3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723738293; cv=none; b=edVQkfa3GYci2WD75Z0WlzrzaWGoDYJdECaTU9UGAwlwjreTgXfVGvVzNnqiZSwLvfSz8xk239QUEtyutCjTjSsJGwElpGi7/oxCauPNTggGCwt2UMXrmKZyzc8HvECeACJmoD+/p6qn8CY19l/vavcGdI/i+xok8IBxdDStAm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723738293; c=relaxed/simple; bh=UuBiFnGrDL12j/ezpbf+Zcs7jgONQnyFqa6y14Bqla4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l9xkckKWSs6VlR/LzZFFPf1DEHW0ebITY7pOu2lFD0iQ2G8UHjygTj0t4RBQy4J9VNWtzmWwIyrWJM9OfkkeiqgrrxFXedS4N3yYU2v/OICpzlUNGQ3EVB4m9XsG6gubTgZKdiX3YM9u21uIjUUafrV0/8uK7qe0m0E+F5zZqvE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70d2ae44790so848156b3a.2 for ; Thu, 15 Aug 2024 09:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723738290; x=1724343090; 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=PIFStYM0RW6vk6vlfRIoPH0DVDQ67nUaP6868za7Wrk=; b=f8Gw1auk11kweihadicfOndr5UXrtxqDr42k36ZWJdA9lqy5jN1zbwX3ZhDILGDUC2 oADQQnUvlMOZFiakxkjen2kU9K1kWhqO2ut+QnAouPQwu1NCdEyofh3k4ZsGn+zXj7pg SFa6WqwEg4BUajXfb5MWiZHIgMq+16wUPDAzseVzpoH8xPNq1DbGKHnAWLVTowYw/kLL 1DVKjHlSoW0+DcWySAzPx3h9Ofd8G0jHhHsYsx9T0bXbppEc7a1ScGMbZmwQshwFbDYV nGJMMR/Pf+7CrYPkn4j36HrFM3FnE2beVAMNIt34d+mHnfeenso6xESKCFCxNO+Jt3tV SOkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723738290; x=1724343090; 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=PIFStYM0RW6vk6vlfRIoPH0DVDQ67nUaP6868za7Wrk=; b=JxVjQSSAauyYeemKf4s9GKP3xqKyW9QUFtc2CQfA6YSaAenjky7FCCnFa80Y87OATn U3+5hvAkDXhS2w6j+rtR5iqGrtbkJmd3yQXAKJ2L0KVmaL2EiSijrJsgQItbDXKBRvMA YtTUnDZUbwDy9L/PKTiHP5XOXsxuIdyTl4WM+6T/QBIVH1ox9x9P6oEiOVWQxOBkFAua tKug3FrSEn5w7gv3zVJiQMEurkzBTGc6pfBhKTzvS3dINvsb09G8O8cUorWTvihYnEDh PUXucDKJv18tTnf/orwqG7jlhH+7XfEW4N8/AwVOjOZAQNrvpsbntOmtm+UvdhrgjJlQ LzPg== X-Gm-Message-State: AOJu0YwR0o/18UJwotnvztWrcpHpdMQ0MsbXP9B8Wed+EMmrboLBU5RZ eG+J4a5SuP8iKgxjpOG535yaAH9R1fsPyEjAxtPvs01cQhG5cukIaii6S5HS X-Google-Smtp-Source: AGHT+IHBobLRq1wwXvzQE3TB0OGzi+1Ir8H1cXgV4oi5F+GwEWdJpT8UMIaeVQF9puoaBoC8b/D+Og== X-Received: by 2002:a05:6a00:6f02:b0:710:6f54:bcac with SMTP id d2e1a72fcca58-713c4d8aeaemr264791b3a.1.1723738290424; Thu, 15 Aug 2024 09:11:30 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.56.169.70]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127ae0e8cfsm1161628b3a.80.2024.08.15.09.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 09:11:29 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 541A27401A3; Thu, 15 Aug 2024 09:11:28 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: josmyers@redhat.com, rguenther@suse.de Subject: [PATCH v2] Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook Date: Thu, 15 Aug 2024 09:11:28 -0700 Message-ID: <20240815161128.601324-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3017.2 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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 152648338b9..453561daece 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; }