From patchwork Wed Aug 14 13:13:27 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: 95826 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6220B3858283 for ; Wed, 14 Aug 2024 13:14:04 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 907903858D34 for ; Wed, 14 Aug 2024 13:13:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 907903858D34 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 907903858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::536 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723641212; cv=none; b=NSWQsVdlUiscpqEfn4ctaFnWYg5a3uo7haSRigByPXSlEScFq8penRmBUzr/1vW/x7d6qfL84UHOWGfcSxnoQ+6Nlm3Ux4TJiE1xnQL2u21p85UH2fDag/Y9ct4goaMpvcmJG+/DXD/0URoHoPu+nvlRbYAMTlwPsCVtG0cEslU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723641212; c=relaxed/simple; bh=9EPP5OevoIvVFb+lALPjk5sVxTcXiMg0JTKiZo94aXk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=c1cq9FGhC8yN1PG0x6vmItA65IFqSQweIdzBwkf5GEoVSeOepY3u2mASZEyBmMdmOCzm57oVRWKDps8hZIUXsmnH9VifXKXnfQcadaEo9oHPhw7bleg4MMd8zCkKUQGSNG7lLsjpqiZu44CEsgcKUVwoqIfJXGBrQdSyG1RLOjI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-76cb5b6b3e4so4366241a12.1 for ; Wed, 14 Aug 2024 06:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723641209; x=1724246009; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dtYodcSXQANdaY2PosEWZ6sF8p3WGhEOSwVq8VMxsqY=; b=auLk4wl/Nqx7qWk1ZtGa5gbeX52qcwfINa+fvp2/yCSWn+Zd6mkRg+K0ekBzWr+8Na rOTvseWLlSld3a5e17KLRaIe1rtOygtQtEFnn8uzpqACHzWA95vzmmmyCdvrMPg1g4Ny ENo5ck/cDQH4Obxb9odImW4hPhcfakOjWjk6uA4tHfTi4KSjutw+KADrr/nFoDio0kB2 mCjFM5+OWEfcY5SMORWCmd6ZTasLezpQnK9RkH3O94Mc3FoodOEsZQDTUYSNaAMNNcxm YMeDgfh9XiLYzaXuefpeaEsKB1V2RcC2uFmPy7h3cBhgz493lDn66LJ+Opfr41QLZ3GJ 93yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723641209; x=1724246009; 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=dtYodcSXQANdaY2PosEWZ6sF8p3WGhEOSwVq8VMxsqY=; b=BdpbRK6kRX9GnchVCqDmA05YJiqh2lQjOOjJ77umF6ZOO8FdkpeGgH/1/nFt8NNXyl x/HeD6jLGEiW66BONnO6KEAOMOmF72zzFbivOfSO0S4fk+jdEtuiCraUWvRZWzyozO/X IeeqL3r+KyV37+L01MKV6cS6VlJSKZW+FIxic2ZQYWxdY5ZyzQCmi5w82nqukuHR7bX4 a+67dD7dO/0iEhC128f2taSofzjVzZTwETGXjSsOQsN83+njwx01AX+ecCedVqOiCZkd dseeep13qjtkfuI+As4Bpr92ukYOISCUMiZ+oMsgjyc1jWlpeFcGdCnE5Nb2iy8s1i8w Bwjg== X-Gm-Message-State: AOJu0YwrsADf41xvUVygLxO0ZI7ziOX9ECxAUs01ELTKcVd2qyR/JKdH uOdYoucsy85/ulOsHE2yKDb7vEACpfFBBDBmBFE+vXJvi+WPI73OsIWIfpB5 X-Google-Smtp-Source: AGHT+IFbMxik2pAHeWw1uO3fQeSYPzWFDuCRfdi9AoffpLXluNhitbhl3bIXtnzmDB8bITc2g4uwew== X-Received: by 2002:a05:6a20:6f89:b0:1c4:b843:fa25 with SMTP id adf61e73a8af0-1c8eae900d5mr3806891637.26.1723641209198; Wed, 14 Aug 2024 06:13:29 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.56.169.70]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710e5a93b20sm7292663b3a.167.2024.08.14.06.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 06:13:28 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 6104D740330; Wed, 14 Aug 2024 06:13:27 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Cc: josmyers@redhat.com Subject: [PATCH] lto: Don't include unused LTO archive members in output Date: Wed, 14 Aug 2024 06:13:27 -0700 Message-ID: <20240814131327.3217603-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, KAM_SHORT, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org When plugin_object_p is called by elf_link_is_defined_archive_symbol to check if a symbol in archive is a real definition, don't set archive member plugin_format to bfd_plugin_yes to avoid including the unused LTO archive members in linker output. To get the proper support for archives with LTO common symbols with GCC, the GCC fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116361 is needed. PR ld/32083 * plugin.c (plugin_call_claim_file): Add an argument to return if LDPT_REGISTER_CLAIM_FILE_HOOK_V2 is used. (plugin_object_p): Set plugin_format to bfd_plugin_yes only if it is known to be used. Signed-off-by: H.J. Lu --- ld/plugin.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ld/plugin.c b/ld/plugin.c index 51c4765cc5b..3dd67d67efb 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -1174,10 +1174,11 @@ plugin_load_plugins (void) /* Call 'claim file' hook for all plugins. */ static int plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed, - bool known_used) + int *claim_file_handler_v2, bool known_used) { plugin_t *curplug = plugins_list; *claimed = false; + *claim_file_handler_v2 = false; while (curplug && !*claimed) { if (curplug->claim_file_handler) @@ -1186,7 +1187,11 @@ plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed, called_plugin = curplug; if (curplug->claim_file_handler_v2) - rv = (*curplug->claim_file_handler_v2) (file, claimed, known_used); + { + rv = (*curplug->claim_file_handler_v2) (file, claimed, + known_used); + *claim_file_handler_v2 = true; + } else rv = (*curplug->claim_file_handler) (file, claimed); called_plugin = NULL; @@ -1222,7 +1227,7 @@ plugin_cleanup (bfd *abfd ATTRIBUTE_UNUSED) static bfd_cleanup plugin_object_p (bfd *ibfd, bool known_used) { - int claimed; + int claimed, claim_file_handler_v2; plugin_input_file_t *input; struct ld_plugin_input_file file; bfd *abfd; @@ -1272,7 +1277,8 @@ plugin_object_p (bfd *ibfd, bool known_used) claimed = 0; - if (plugin_call_claim_file (&file, &claimed, known_used)) + if (plugin_call_claim_file (&file, &claimed, &claim_file_handler_v2, + known_used)) einfo (_("%F%P: %s: plugin reported error claiming file\n"), plugin_error_plugin ()); @@ -1292,7 +1298,11 @@ plugin_object_p (bfd *ibfd, bool known_used) if (claimed) { - ibfd->plugin_format = bfd_plugin_yes; + /* Set plugin_format to bfd_plugin_yes only if it is known to + be used to avoid including the unused LTO archive members in + linker output. */ + if (known_used || !claim_file_handler_v2) + ibfd->plugin_format = bfd_plugin_yes; ibfd->plugin_dummy_bfd = abfd; bfd_make_readable (abfd); abfd->no_export = ibfd->no_export;