From patchwork Sat Feb 10 13:42:17 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: 199266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1471860dyd; Sat, 10 Feb 2024 05:42:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUaOUr4af3/ixjk8bopjF0neqd5NLIISfBdFaGCanIctQBfLGhgVVZqMFfzOctngFZ1+x/SivJuoQncHRdjGkldddDFTQ== X-Google-Smtp-Source: AGHT+IExSm0nonQnSYPi78ElyUN1I6RelDLWvnvykUJCanduNHi3NTGwQ6jTl2Hi3b5IOQbN8FzD X-Received: by 2002:a05:620a:4153:b0:783:e9ba:7d4b with SMTP id k19-20020a05620a415300b00783e9ba7d4bmr2430496qko.49.1707572551578; Sat, 10 Feb 2024 05:42:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707572551; cv=pass; d=google.com; s=arc-20160816; b=Rf3Q6L21ChcnDVCH0AW9mVl9dkt2OYaN/99bDahBwUJf12iao64Y9eesaCggPTBE6w hscZIQgPDHwbC8zqbMM3N5S55ALBpM1Wr8WykST5uaySRLhGVJKMd2auLMxftfUVMfk4 htBbFjjsKx6lKFDoj+1YdDicbUbzXAv9mI3dWQIwTIet8l+9fHRZfEoPHCCns6J9AT8b GRw25vohSbam6l7q+G17rcUnG6IFl2r7YQeOtZMzCxQ0HC7L5Cv3/0VBaf1CHUH0biVG 2qip8vfyS2GmCZ3jLOWoaIEOD3ieBDNLPRIovEQou8fk5NRA6nzKrTARwHGHINCRgC8i oz+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=IfIHye5sxbsRtNamzP6t6c/6oflNdrsUyAE+qbAY4vo=; fh=JzSvL4lAjH/mrU34ufY+Sj/jhuAmu71waBYmNPyS/xY=; b=Lj2hDsI4IkAcWcatPZt2y3LVWclsezy6UD8i8xQISvXVpAr0NdpAbeTeGIBDjGPmsZ OY/GLR/NEcbn10jT1DNi63L1e5DVQD8auXDiVw6Hk9JffOCnafuEm6qINwLIQqds6QOx 0Oeeh3xti1XhkPNYKkg0AMvIy13pvQFCQNSaIr/6TLu0P2yuap0YhQNFij9yt4SMRaHw EWYi6rqMn2iq6VtwS3BlOp0Fygnqkn8yuMwpGx1eAOe78zfRZSyniAabVOTEiwhZwaBS d/8DJkMUU9dTfMlMpVN5NgZfv92btRsFbkJ2irV3PrhTn0ue+esaXu/ZQip4wmTN0ZPY pknA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fdnyQ92X; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCUcVRUfSZXOr3069kwXUSBiR3MZXt5ok6I8ZAXCQ+3uIMRHQ1ApnGnDoVby1+XXI30+HUc4GUQ4aTIVCi0yih1G3VgJYA== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id oo16-20020a05620a531000b00783e04e2ff0si1720373qkn.335.2024.02.10.05.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 05:42:31 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fdnyQ92X; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 452EE3858C78 for ; Sat, 10 Feb 2024 13:42:31 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 65E783858C2D for ; Sat, 10 Feb 2024 13:42:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65E783858C2D 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 65E783858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707572543; cv=none; b=UnyvpKIXEd0Xvp0UCoQ70mpBwlhGzja5F4/DvE2Uo7PCdQGaN3nGATBw+CUwkg8y/TDke3pG6qqh+wnLkHCkk077gG2b4F0rY/+eFoxEh9JLqCVBHucUZ00H7YjxBZWNx2cK1uUJA2qIVqpvAa0uMnMMRCfzUn6a1/QzaiaikOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707572543; c=relaxed/simple; bh=WZzXb8wye+9uqNlv2SiaorBL4rNt88sNX9Rv5CfNMcI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=D4iJ+dnoWoEV9QO1IODOFEYSiVXy7vdVt8pLT7cQh7SfCbhq1b6ain+znORaFXZf6yWJql+x8y/boNSJlz02+zhbOQgGxZkyB9NgARmf0kUx+UZUsFtU6UTQcwxZBzjDKNJFNv/tin7WAJT2YkSQ1zmLOfKfSSEFQ9cW3tkgKp8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5d42e7ab8a9so1214900a12.3 for ; Sat, 10 Feb 2024 05:42:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707572540; x=1708177340; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=IfIHye5sxbsRtNamzP6t6c/6oflNdrsUyAE+qbAY4vo=; b=fdnyQ92XbhBK4aazbDGo3WtzMbRqaiAkcdROW0ts0oIY8KMRaNcAFa7EWeGJEbiDgM jGPbusKwyVV9gse/mazKlkUtrGBs0okzynVkneljtWcyK9kYRcShovdukktR0o+cKp7Q z/zFsKM7Nbo1FkHoJ3DPldTASc/XlQhbij1Su1ITZtYfQGY4bqdin/Lzrgt8h1cA5wiJ kBP6E30ZaoqpkE7nRAvdf+FK8FsVvZQCsNsgJe/nrfzJHR9cOPpKDmJEEyIuuPKHjyZR Kgab40Ly/h/8yvynbioZBY9G3jImnN0SwYCPpbGNgqEpOJcQ95SYZDE+kAxLhzGhR0zG qYzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707572540; x=1708177340; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IfIHye5sxbsRtNamzP6t6c/6oflNdrsUyAE+qbAY4vo=; b=Wqiecr3k6dpgbX7pCsWJFPOO5DQamPz2WS7wBeSwcBsEhKyaDzOzOTEYdbVrLsiErh m6eWtEmS+iSTICxVS6s/vA4pTTDeF4bXwncoT6U4eHcCnfAVBhI+97rpAHSGBuUnhneg AzEWzeQoEbE9N6RhTm2NvEplA22CzOfnpHPXkdopZ0HJub/cIRrLSB19aGxMVlk/lRE3 uMU6v4afZqy9ustaulC68JUyI+Gu9kkrBcx5tjHgd/uzpBk+TVhNA3Sr5LETVGcMc9I7 UXQB1rsXxGozSi67vvevt6N/A0ek6EbfU5mvoJPar9jNbY2/lWa0qM4ZCCzgOjdSM0rG tbHA== X-Gm-Message-State: AOJu0YxzCKoN6fC6AMFJkVt0ah/LNRlC/9ZPFdMIy3zvCKCcqe8d148/ SVTU5g1bI3ZangGpGttsqihpDDf0jxYRLP8jsqHS50387x6AmYiszXmxzPul X-Received: by 2002:a05:6a20:9f05:b0:19e:bd3e:76e1 with SMTP id mk5-20020a056a209f0500b0019ebd3e76e1mr1774099pzb.48.1707572539955; Sat, 10 Feb 2024 05:42:19 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.168.224]) by smtp.gmail.com with ESMTPSA id g7-20020a62e307000000b006dd8985e7c6sm2286979pfh.1.2024.02.10.05.42.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 05:42:19 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id CB127740376 for ; Sat, 10 Feb 2024 05:42:17 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] ld: Add -plugin-save-temps Date: Sat, 10 Feb 2024 05:42:17 -0800 Message-ID: <20240210134217.108537-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3020.7 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: 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+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790519595669079284 X-GMAIL-MSGID: 1790519595669079284 Add -plugin-save-temps to store plugin intermediate files permanently. It can be used to exam the final input object files generated from IR inputs. * NEWS: Mention -plugin-save-temps. * ld.h (ld_config_type): Add plugin_save_temps. * ld.texi: Document -plugin-save-temps. * ldlex.h (option_values): Add OPTION_PLUGIN_SAVE_TEMPS. * lexsup.c (ld_options): Add -plugin-save-temps. (parse_args): Handle OPTION_PLUGIN_SAVE_TEMPS. * plugin.c (plugin_call_cleanup): Don't call plugin cleanup_handler for -plugin-save-temps. --- ld/NEWS | 2 ++ ld/ld.h | 3 +++ ld/ld.texi | 4 ++++ ld/ldlex.h | 1 + ld/lexsup.c | 6 ++++++ ld/plugin.c | 19 +++++++++++-------- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ld/NEWS b/ld/NEWS index f89ed8cae4a..8e3b3f1677c 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -4,6 +4,8 @@ linker scripts in ELF and PE COFF linker to specify the input text section order. +* Add -plugin-save-temps to store plugin intermediate files permanently. + Changes in 2.42: * Add -z mark-plt/-z nomark-plt options to x86-64 ELF linker to mark PLT diff --git a/ld/ld.h b/ld/ld.h index a80255a73ba..6e0e773e418 100644 --- a/ld/ld.h +++ b/ld/ld.h @@ -300,6 +300,9 @@ typedef struct /* The size of the hash table to use. */ unsigned long hash_table_size; + /* If set, store plugin intermediate files permanently. */ + bool plugin_save_temps; + /* If set, print discarded sections in map file output. */ bool print_map_discarded; diff --git a/ld/ld.texi b/ld/ld.texi index 2e715470ab6..4510905eee7 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -1140,6 +1140,10 @@ Omit debugger symbol information (but not all symbols) from the output file. Omit (or do not omit) global symbols defined in discarded sections. Enabled by default. +@kindex -plugin-save-temps +@item -plugin-save-temps +Store the plugin ``temporary'' intermediate files permanently. + @kindex -t @kindex --trace @cindex input files, displaying diff --git a/ld/ldlex.h b/ld/ldlex.h index a2c49656e1a..dd9e1b7e653 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -147,6 +147,7 @@ enum option_values #if BFD_SUPPORTS_PLUGINS OPTION_PLUGIN, OPTION_PLUGIN_OPT, + OPTION_PLUGIN_SAVE_TEMPS, #endif /* BFD_SUPPORTS_PLUGINS */ OPTION_DEFAULT_SCRIPT, OPTION_PRINT_OUTPUT_FORMAT, diff --git a/ld/lexsup.c b/ld/lexsup.c index 21385628020..d043bdc37ae 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -187,6 +187,9 @@ static const struct ld_option ld_options[] = '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH }, { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT}, '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH }, + { {"plugin-save-temps", no_argument, NULL, OPTION_PLUGIN_SAVE_TEMPS}, + '\0', NULL, N_("Store plugin intermediate files permanently"), + ONE_DASH }, { {"flto", optional_argument, NULL, OPTION_IGNORE}, '\0', NULL, N_("Ignored for GCC LTO option compatibility"), ONE_DASH }, @@ -1215,6 +1218,9 @@ parse_args (unsigned argc, char **argv) if (plugin_opt_plugin_arg (optarg)) einfo (_("%F%P: bad -plugin-opt option\n")); break; + case OPTION_PLUGIN_SAVE_TEMPS: + config.plugin_save_temps = true; + break; #endif /* BFD_SUPPORTS_PLUGINS */ case 'q': link_info.emitrelocations = true; diff --git a/ld/plugin.c b/ld/plugin.c index e982869072b..0d90dbc96e9 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -1363,14 +1363,17 @@ plugin_call_cleanup (void) { if (curplug->cleanup_handler && !curplug->cleanup_done) { - enum ld_plugin_status rv; - curplug->cleanup_done = true; - called_plugin = curplug; - rv = (*curplug->cleanup_handler) (); - called_plugin = NULL; - if (rv != LDPS_OK) - info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"), - curplug->name, rv); + if (!config.plugin_save_temps) + { + enum ld_plugin_status rv; + curplug->cleanup_done = true; + called_plugin = curplug; + rv = (*curplug->cleanup_handler) (); + called_plugin = NULL; + if (rv != LDPS_OK) + info_msg (_("%P: %s: error in plugin cleanup: %d (ignored)\n"), + curplug->name, rv); + } dlclose (curplug->dlhandle); } curplug = curplug->next;