From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by sourceware.org (Postfix) with ESMTPS id A2C94385829E for ; Fri, 16 Feb 2024 13:00:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2C94385829E 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 A2C94385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708088420; cv=none; b=kMifjlTX1QUSfOE0OGZYiSM28yHFO/a2VlMvPr/L4fhWjMkhoDBULH81pgLsnkkJTLWUpkuA03o1cZROwbwxLiceU4F99hHFlqLD/1ejE5wtPgoTk/d1Hj9/fVMYuy9d/gXRcYeFIsgPcmUOUghAyRt8J1KL2lWNtqv395jRxn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708088420; c=relaxed/simple; bh=xb4TySqIKEbC3LMCSe6fZtsvBfbaRdX4gG3ud4LlaPQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=k6uDYfG+fjWK+KE3t16LirTgLtG8KbxDEOZLM4pTD5Vuil586UmGEngfyjFctJY2TeEZHgpxIfZW1hOaEfEMMTfjZGKDT47mbct3P06XS73uHPt/ECiUn50YlVZNlYHf1f9N/DsBtAnNKaj/7ymqjCyFfiOP3U1rW963sbWc9GI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-dcd7c526cc0so2133754276.1 for ; Fri, 16 Feb 2024 05:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708088418; x=1708693218; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rJGY57F8rbaiZE3amrmJ9KYlu7XPhf8Kdy4MUVTLw70=; b=lZKz84SV8sarTJcOfMLDm09GLOO3EAuDwuetlfBbl8eblurTRT0aZM+UFhybcCnP83 8bM7uXRp9q+azosY/EPc/M4zqyH2Uu0M286rBcc9g1k85kGmsdFqYelDecxsLwbKFOks v09HnXDO9xiq2LGTYMH5pe3vGW+zZ7PWzeOJ7l0Ubz3j6kvyy3+jFyMJdjUhDSJbSNRD /8b2O19dwU5gGDC5cohM/QRVSNGVjslziJO4t39LTTJqxKdhQ01Y2OlBCIua24EfqMcJ uXs0vO/kuAWlDRr5Yjj/LhLQi2nGZjHomMoi3Kz/DikJ3s3mFdWlHsVp/a/I+6QyfAhD Ww1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708088418; x=1708693218; h=content-transfer-encoding:cc: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=rJGY57F8rbaiZE3amrmJ9KYlu7XPhf8Kdy4MUVTLw70=; b=W0DBN7PCikDo3oTCKYoMCAywEdKkykTOfYoOYck/YQtkifVGE0juomQYGWpvlCEfEV g9VwQ0TA/eViZy07VDVZPEVlS9RDB8FQ6u9zrivDi3cwOMGaw4FGySobJ1hNwlL4UbKe PX/kj25YI3/vFu0Jef7pjId/ruHSbClMiZ234Ke58Kcc9K1u/3DKgOoCkLF8JUslrR6D rSgZWUxQ9IpWcrxhamqve2shJSYvohvRamATMEAZsrMaScW98gUuMAGglGo5JrFBiSwE A9pwQeVHOtRE3NtdlprbZNMbYAuSdlgBpX6gYJ47kscgOaW3GkLvA11SLgbbPHNhoVl5 D/7g== X-Gm-Message-State: AOJu0YzuGTKdtH2CiDKb/6NIicq4rui3c8mAOabyho7heOE/6PKRH54c efjlyAcbqsvafpD8yY9T3hDlGv0y4Rl0dwRtMP/LV8wy03LJWE0RC8ADKEbai3NPsjLNK1rnoTG UwgmELvadtOCx8CSuO3VGOar5eT9swuKd X-Google-Smtp-Source: AGHT+IFoejFcaf9yieprDBET0braztpROXoV4XeuZYMVJFFIXHh0zUh8107GYpm9iRQz1SoLM8qMsZAc+EyX9PAekmM= X-Received: by 2002:a25:d6c4:0:b0:dc2:5553:ca12 with SMTP id n187-20020a25d6c4000000b00dc25553ca12mr4803691ybg.14.1708088416862; Fri, 16 Feb 2024 05:00:16 -0800 (PST) MIME-Version: 1.0 References: <20240210134217.108537-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Fri, 16 Feb 2024 04:59:41 -0800 Message-ID: Subject: Re: [PATCH] ld: Add -plugin-save-temps To: Alan Modra Cc: binutils@sourceware.org, Noah Goldstein Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3020.2 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 4:42=E2=80=AFAM Alan Modra wrote= : > > On Fri, Feb 16, 2024 at 04:17:23AM -0800, H.J. Lu wrote: > > On Sat, Feb 10, 2024 at 5:42=E2=80=AFAM H.J. Lu w= rote: > > > > > > 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 permanen= tly. > > > + > > > 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[] =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_TEMP= S}, > > > + '\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 (ign= ored)\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? > > It certainly beats running the linker under gdb and putting a > breakpoint at the appropriate place. I like it. > > I am checking it in. Thanks. --=20 H.J.