public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: binutils@sourceware.org, Noah Goldstein <goldstein.w.n@gmail.com>
Subject: Re: [PATCH] ld: Add -plugin-save-temps
Date: Fri, 16 Feb 2024 23:12:03 +1030	[thread overview]
Message-ID: <Zc9YG9wcHWaoLDz8@squeak.grove.modra.org> (raw)
In-Reply-To: <CAMe9rOoC40V6ecwd7rR6e+SbE3C1Y1nJb+oEC9_0+kzfbZDLBw@mail.gmail.com>

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 <hjl.tools@gmail.com> 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

  reply	other threads:[~2024-02-16 12:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-10 13:42 H.J. Lu
2024-02-16 12:17 ` H.J. Lu
2024-02-16 12:42   ` Alan Modra [this message]
2024-02-16 12:59     ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zc9YG9wcHWaoLDz8@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=goldstein.w.n@gmail.com \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).