From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id 7C0A33858292 for ; Fri, 16 Feb 2024 12:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C0A33858292 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 7C0A33858292 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708085890; cv=none; b=Xan6TCJ6INwpq8XRiU1lGbo58xJ3FJz7kCajgGTzdZTa3cIzhAaew6NBULWQ//ZXYrIY/W70B3DePvFz2wy3LywjqotUH8FvvdqZzsx5+X6EM+AWZCWuo6kTOIv8St4te2ebAPJTfRoZNQhQ4QhhcjtNPg/wWmzmx4Oryj7pKXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708085890; c=relaxed/simple; bh=BTdTb9dXgITf3LtZGHNxeBQBom+INkq5pSAJSdncVvw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=odnRYRZMsifhPrKdCDgZYX6deVK0I+0pXNYwWuk7OuffQmV4m/RIiJo0i5hsF9b1mGqstWUHQmbRWgS7ptBD7BJWqvTd729KQO8yqhUnLPTIl9rEzpqzUnn6JiQnEBZ3fAzxRw9xcpGz52ewDv8+GgGlfeNf32MMvKndXWT7NpE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-dc6d9a8815fso2066212276.3 for ; Fri, 16 Feb 2024 04:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708085879; x=1708690679; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=M0Ey4Fstz+TFooyqHyRQGGqaH0qgkd/qwCn7KfRxFfs=; b=N/r4XhkH7sG/EHHXGgWNNwGWVGF9rXXDR6Th1UtwFF01XgTRK63CSEoWRH6946aNp8 +txCxovLlaeTCPo0rEwRDQKPR/jbny9XA5fVxRfx0EcPwgCc7u0Y60RAC9QH3Va7qTUY /UNaGjnD3j8Uf9VykEcGu5Bhcv4/MBMvCIkdkRK+pi2NGLTBF4BI4c05vib9nZp/6oiM DerNva1DMsMHZZrrRH0Rh3AryGNH6Eukn9+5eKy/gDbDoNrAHRVfgAXPU28eAya5jOp9 ozrPDjE+YeNNjTMGY99xpkZJcZqQ7Q7nxlLVrhUb83GsIreAO8iZPYccVde967kQs5G4 a+uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708085879; x=1708690679; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M0Ey4Fstz+TFooyqHyRQGGqaH0qgkd/qwCn7KfRxFfs=; b=VCjMQ40o/1go4/V0CVuN3IMlA0QcSOEudrrrVt17slOa2fHfG+PnmXnoDlnx4hS1jF 8nzVGBFLbuWOAoyINEbZKWdsTJ0tdVWtopfCUOvXEkjLUeoBIMVDIQakRbSt/fnQ1PGY JSexEt7KperBVCODqCYGPUq4rzyuGYD0ibbEoEMOm54wz/d8DFeL87m+fbn1YlSIUYaT 4jYu2a/c+9c9GhiyzI0KEVlf72aYNvNVDwSlCfJTEi9xqPRYegdPAO2vTfvIe76htL73 u/76MUgJMoMH4HAGQ8OQu0990rR8+8VPeDSC5bye4yUIUuCxveWJp1t2dFsYe3P807ML P4Rg== X-Gm-Message-State: AOJu0YzH1UhRGeflaafEGI+5hgLANHXMjZaqRIm4eo6V1e94RJ1IFBd7 BOwNd7i/8dyDj6IPkpLlXcT2qw2VZwZMA++J7VebmUACUwqtqfTD5CPKFkPBYCq/1CeYy9NCewg +j7bBmpbWUU5JABvZp1QNHrEReRU/RBWE X-Google-Smtp-Source: AGHT+IGArNeADeFRau29pxDnu4RZnxka6cP/SlDwZiqP5n13RT7KwtiHjqRBmjdqn6InEB+coSKjZrjXCrk7E5HQisQ= X-Received: by 2002:a25:d388:0:b0:dc6:4062:1341 with SMTP id e130-20020a25d388000000b00dc640621341mr4780941ybf.16.1708085879537; Fri, 16 Feb 2024 04:17:59 -0800 (PST) MIME-Version: 1.0 References: <20240210134217.108537-1-hjl.tools@gmail.com> In-Reply-To: <20240210134217.108537-1-hjl.tools@gmail.com> From: "H.J. Lu" Date: Fri, 16 Feb 2024 04:17:23 -0800 Message-ID: Subject: Re: [PATCH] ld: Add -plugin-save-temps To: binutils@sourceware.org, Noah Goldstein Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3020.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 Sat, Feb 10, 2024 at 5:42=E2=80=AFAM 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 symb= ols) 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[] =3D > '\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 =3D true; > + break; > #endif /* BFD_SUPPORTS_PLUGINS */ > case 'q': > link_info.emitrelocations =3D 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 =3D true; > - called_plugin =3D curplug; > - rv =3D (*curplug->cleanup_handler) (); > - called_plugin =3D NULL; > - if (rv !=3D 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 =3D true; > + called_plugin =3D curplug; > + rv =3D (*curplug->cleanup_handler) (); > + called_plugin =3D NULL; > + if (rv !=3D LDPS_OK) > + info_msg (_("%P: %s: error in plugin cleanup: %d (ignored= )\n"), > + curplug->name, rv); > + } > dlclose (curplug->dlhandle); > } > curplug =3D curplug->next; > -- > 2.43.0 > This simple change can be very useful. Any comments and feedback? Thanks. --=20 H.J.