From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 01098385800C for ; Fri, 16 Feb 2024 12:42:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01098385800C 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 01098385800C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708087330; cv=none; b=O1ZHAD2MmvVBzOIAF/PwT2ntrYKX8LLq47OsmecK2z0mJFYXTwiwVHmSanEp7uPk6jozFK94GN4nCUTpwEbknkH/JKMn6wC3aDf58uR8+UQAeGPbOabnnCLW+RAYjt7Nw8WBuGIWvAELb0BZVkHPPbi476bWs5OSy3ddblF3DPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708087330; c=relaxed/simple; bh=uMOGRsWP1rjeKFnI06YBmnjttnd2xZ7YKD1QImqIez0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=LVkTAzlIz7q24uvatQvU4dyvaWtAf/t94MZtfZHS8NfyYi3RUtKVnme4elvT9uLwXKp7uOoEe8bSRpOFXn5FfO4eKnAy0s1BLoKHNrrBtExDxQfQhWuZywoL5N87dELiBrXyRR/PiGpz2xxkD3P7O0bonA0o9Fk0ybO95OA3P6w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-296db7e258dso1485018a91.0 for ; Fri, 16 Feb 2024 04:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708087327; x=1708692127; darn=sourceware.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=X4uV5srAy22rhy/wNMb9ScN00CoJdeCreeV55TyRZio=; b=J2xoPX+vHHOL08IQvanAmzNKRI3q0heUJsZs3bgqee11/gvIZF2cdZ3qv+ij/7U+J7 eKMkObjLhc0YKVMSChzx6u1Tp63EsWHMr6RxPjlfD9JBhTFyH39EYzLsGQ5xibMQE35e uR7EUByNmb/oTpPJYb3sEHBYqGg9uGtzLN2+Dj8yWEOb9lFl0fx4vZn6GZYfExuSY9Ri anNkTPTWo01NZoT2IiUVywkjFpYlBJFBH0i7NoeOTuVK/pmbMjj+AK09diIpb6sThVaj r+I2bq1ZzGr/zz7EQvv1f9J/8eKswtzHA36Jf/mG7BbyTAZR8PjhgnR9XdnF/9N29GDL x3Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708087327; x=1708692127; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X4uV5srAy22rhy/wNMb9ScN00CoJdeCreeV55TyRZio=; b=AjGAu1AxDFrWvj6lNWAFh3tfZhkVX1I/IvplF/bSbGHFN1Gkw1D3/bLnl0p9OU7B5N SMfq+GiI3sZn5RlLdCES0Re87qFpYgjAQU82FW7KRwTh1sDtEJXBjGZdiIkvzbsclomC PnurKcYjVhGUYmRGi+D1ceOulvM4SgIUdARHm9WRS60kpVnR8y7p+EWq71p+V94UEbts 2uBCXwR2rLFinZqd9BaGRCZn4E37ZTDEkZRSOCSdHPkDtcb/pH2SvarHQ3IoJEEENXBq i5f9PItMRmGkRSWR39XpG9XqZomeevVCsTvjHNA0+dobjGemQ0b7L+R3VUMX388WZyMo cQLA== X-Gm-Message-State: AOJu0YyJgW+yn4P43zA/PBqTSVnBpvvraEUajBoxg6Ao2+JIw4rtzpSB U3typpsBf3Gahm+mfsiNbTU5qi1z/hfDKHvSxBrwqUPociGPdCeuw3uqdjjZ X-Google-Smtp-Source: AGHT+IGCpdgLWoiHKuWMAEFHZAw3KomEO9xhrmGaNnFkwkbqdr3ir7J9XAEjzHmA11ZZtWLdVH37VA== X-Received: by 2002:a17:90a:df93:b0:299:3bff:4e55 with SMTP id p19-20020a17090adf9300b002993bff4e55mr1344688pjv.20.1708087326890; Fri, 16 Feb 2024 04:42:06 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:40d0:4922:dff1:9d41]) by smtp.gmail.com with ESMTPSA id ta11-20020a17090b4ecb00b00298b3e058fcsm5332374pjb.57.2024.02.16.04.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 04:42:06 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 01A2B114033C; Fri, 16 Feb 2024 23:12:03 +1030 (ACDT) Date: Fri, 16 Feb 2024 23:12:03 +1030 From: Alan Modra To: "H.J. Lu" Cc: binutils@sourceware.org, Noah Goldstein Subject: Re: [PATCH] ld: Add -plugin-save-temps Message-ID: References: <20240210134217.108537-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-3033.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Fri, Feb 16, 2024 at 04:17:23AM -0800, H.J. Lu wrote: > On Sat, Feb 10, 2024 at 5:42 AM H.J. Lu wrote: > > > > 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; > > -- > > 2.43.0 > > > > This simple change can be very useful. Any comments and feedback? It certainly beats running the linker under gdb and putting a breakpoint at the appropriate place. I like it. -- Alan Modra Australia Development Lab, IBM