summaryrefslogtreecommitdiffstats
path: root/lto-plugin
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2019-05-15 09:12:21 +0000
committerIain Sandoe <iains@gcc.gnu.org>2019-05-15 09:12:21 +0000
commitc101cff86ea770fe29f18e5c955e85ce9830b029 (patch)
tree4933779deed5857c82376f5f285e54de1998ce29 /lto-plugin
parentadd missing Changelog for last commit. (diff)
downloadgcc-c101cff86ea770fe29f18e5c955e85ce9830b029.tar.gz
gcc-c101cff86ea770fe29f18e5c955e85ce9830b029.tar.bz2
gcc-c101cff86ea770fe29f18e5c955e85ce9830b029.tar.xz
lto-plugin - support -save-temps, -v, --version.
This patch makes the lto-plugin follow the same approach to save-temps as collect2. -save-temps causes the temp file to be named meaningfully, and for the relevant input files to be saved in CWD. -v, —version causes the save actions to be output to stderr. one can get this to happen by just putting -save-temps, -v on the regular link line or (for compatibility with the way the -debug flag works) by appending -plugin-opt=-save-temps, etc. lto-plugin/ 2019-05-15 Iain Sandoe <iain@sandoe.co.uk> * lto-plugin.c (exec_lto_wrapper): Make the wrapper arguments filename more user-friendly. (file_exists, maybe_unlink): New. (cleanup_handler): Use maybe unlink to handle the case when temps should be saved. (process_option): Look for -v, —-version, -save-temps. (onload): Record the linker output file name. Check for -v, —-version, -save-temps in the GCC collect options environment. From-SVN: r271202
Diffstat (limited to 'lto-plugin')
-rw-r--r--lto-plugin/ChangeLog12
-rw-r--r--lto-plugin/lto-plugin.c97
2 files changed, 88 insertions, 21 deletions
diff --git a/lto-plugin/ChangeLog b/lto-plugin/ChangeLog
index 8ddccbecf38..16faa56a4fa 100644
--- a/lto-plugin/ChangeLog
+++ b/lto-plugin/ChangeLog
@@ -1,3 +1,15 @@
12019-05-15 Iain Sandoe <iain@sandoe.co.uk>
2
3 * lto-plugin.c (exec_lto_wrapper): Make the wrapper
4 arguments filename more user-friendly.
5 (file_exists, maybe_unlink): New.
6 (cleanup_handler): Use maybe unlink to handle the
7 case when temps should be saved.
8 (process_option): Look for -v, —-version, -save-temps.
9 (onload): Record the linker output file name.
10 Check for -v, —-version, -save-temps in the GCC collect
11 options environment.
12
12019-02-26 Martin Liska <mliska@suse.cz> 132019-02-26 Martin Liska <mliska@suse.cz>
2 14
3 * lto-symtab.c: Remove. 15 * lto-symtab.c: Remove.
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 3788fdbb64c..92bca50b094 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -41,6 +41,7 @@ along with this program; see the file COPYING3. If not see
41#if HAVE_STDINT_H 41#if HAVE_STDINT_H
42#include <stdint.h> 42#include <stdint.h>
43#endif 43#endif
44#include <stdbool.h>
44#include <assert.h> 45#include <assert.h>
45#include <errno.h> 46#include <errno.h>
46#include <string.h> 47#include <string.h>
@@ -184,12 +185,15 @@ static int lto_wrapper_num_args;
184static char **pass_through_items = NULL; 185static char **pass_through_items = NULL;
185static unsigned int num_pass_through_items; 186static unsigned int num_pass_through_items;
186 187
187static char debug; 188static bool debug;
189static bool save_temps;
190static bool verbose;
188static char nop; 191static char nop;
189static char *resolution_file = NULL; 192static char *resolution_file = NULL;
190static enum ld_plugin_output_file_type linker_output; 193static enum ld_plugin_output_file_type linker_output;
191static int linker_output_set; 194static int linker_output_set;
192static int linker_output_known; 195static int linker_output_known;
196static const char *link_output_name = NULL;
193 197
194/* The version of gold being used, or -1 if not gold. The number is 198/* The version of gold being used, or -1 if not gold. The number is
195 MAJOR * 100 + MINOR. */ 199 MAJOR * 100 + MINOR. */
@@ -560,8 +564,17 @@ exec_lto_wrapper (char *argv[])
560 struct pex_obj *pex; 564 struct pex_obj *pex;
561 const char *errmsg; 565 const char *errmsg;
562 566
563 /* Write argv to a file to avoid a command line that is too long. */ 567 /* Write argv to a file to avoid a command line that is too long
564 arguments_file_name = make_temp_file (""); 568 Save the file locally on save-temps. */
569 if (save_temps && link_output_name)
570 {
571 arguments_file_name = (char *) xmalloc (strlen (link_output_name)
572 + sizeof (".lto_wrapper_args") + 1);
573 strcpy (arguments_file_name, link_output_name);
574 strcat (arguments_file_name, ".lto_wrapper_args");
575 }
576 else
577 arguments_file_name = make_temp_file (".lto_wrapper_args");
565 check (arguments_file_name, LDPL_FATAL, 578 check (arguments_file_name, LDPL_FATAL,
566 "Failed to generate a temorary file name"); 579 "Failed to generate a temorary file name");
567 580
@@ -579,15 +592,21 @@ exec_lto_wrapper (char *argv[])
579 for (i = 1; argv[i]; i++) 592 for (i = 1; argv[i]; i++)
580 { 593 {
581 char *a = argv[i]; 594 char *a = argv[i];
595 /* Check the input argument list for a verbose marker too. */
582 if (a[0] == '-' && a[1] == 'v' && a[2] == '\0') 596 if (a[0] == '-' && a[1] == 'v' && a[2] == '\0')
583 { 597 {
584 for (i = 0; argv[i]; i++) 598 verbose = true;
585 fprintf (stderr, "%s ", argv[i]);
586 fprintf (stderr, "\n");
587 break; 599 break;
588 } 600 }
589 } 601 }
590 602
603 if (verbose)
604 {
605 for (i = 0; argv[i]; i++)
606 fprintf (stderr, "%s ", argv[i]);
607 fprintf (stderr, "\n");
608 }
609
591 new_argv[0] = argv[0]; 610 new_argv[0] = argv[0];
592 new_argv[1] = at_args; 611 new_argv[1] = at_args;
593 new_argv[2] = NULL; 612 new_argv[2] = NULL;
@@ -599,7 +618,6 @@ exec_lto_wrapper (char *argv[])
599 fprintf (stderr, "\n"); 618 fprintf (stderr, "\n");
600 } 619 }
601 620
602
603 pex = pex_init (PEX_USE_PIPES, "lto-wrapper", NULL); 621 pex = pex_init (PEX_USE_PIPES, "lto-wrapper", NULL);
604 check (pex != NULL, LDPL_FATAL, "could not pex_init lto-wrapper"); 622 check (pex != NULL, LDPL_FATAL, "could not pex_init lto-wrapper");
605 623
@@ -759,6 +777,29 @@ all_symbols_read_handler (void)
759 return LDPS_OK; 777 return LDPS_OK;
760} 778}
761 779
780/* Helper, as used in collect2. */
781static int
782file_exists (const char *name)
783{
784 return access (name, R_OK) == 0;
785}
786
787/* Unlink FILE unless we have save-temps set.
788 Note that we're saving files if verbose output is set. */
789
790static void
791maybe_unlink (const char *file)
792{
793 if (save_temps && file_exists (file))
794 {
795 if (verbose)
796 fprintf (stderr, "[Leaving %s]\n", file);
797 return;
798 }
799
800 unlink_if_ordinary (file);
801}
802
762/* Remove temporary files at the end of the link. */ 803/* Remove temporary files at the end of the link. */
763 804
764static enum ld_plugin_status 805static enum ld_plugin_status
@@ -771,16 +812,10 @@ cleanup_handler (void)
771 return LDPS_OK; 812 return LDPS_OK;
772 813
773 if (arguments_file_name) 814 if (arguments_file_name)
774 { 815 maybe_unlink (arguments_file_name);
775 t = unlink (arguments_file_name);
776 check (t == 0, LDPL_FATAL, "could not unlink arguments file");
777 }
778 816
779 for (i = 0; i < num_output_files; i++) 817 for (i = 0; i < num_output_files; i++)
780 { 818 maybe_unlink (output_files[i]);
781 t = unlink (output_files[i]);
782 check (t == 0, LDPL_FATAL, "could not unlink output file");
783 }
784 819
785 free_2 (); 820 free_2 ();
786 return LDPS_OK; 821 return LDPS_OK;
@@ -1143,7 +1178,12 @@ process_option (const char *option)
1143 if (strcmp (option, "-linker-output-known") == 0) 1178 if (strcmp (option, "-linker-output-known") == 0)
1144 linker_output_known = 1; 1179 linker_output_known = 1;
1145 if (strcmp (option, "-debug") == 0) 1180 if (strcmp (option, "-debug") == 0)
1146 debug = 1; 1181 debug = true;
1182 else if ((strcmp (option, "-v") == 0)
1183 || (strcmp (option, "--verbose") == 0))
1184 verbose = true;
1185 else if (strcmp (option, "-save-temps") == 0)
1186 save_temps = true;
1147 else if (strcmp (option, "-nop") == 0) 1187 else if (strcmp (option, "-nop") == 0)
1148 nop = 1; 1188 nop = 1;
1149 else if (!strncmp (option, "-pass-through=", strlen("-pass-through="))) 1189 else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
@@ -1180,6 +1220,8 @@ process_option (const char *option)
1180 if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0) 1220 if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
1181 resolution_file = opt + sizeof ("-fresolution=") - 1; 1221 resolution_file = opt + sizeof ("-fresolution=") - 1;
1182 } 1222 }
1223 save_temps = save_temps || debug;
1224 verbose = verbose || debug;
1183} 1225}
1184 1226
1185/* Called by gold after loading the plugin. TV is the transfer vector. */ 1227/* Called by gold after loading the plugin. TV is the transfer vector. */
@@ -1232,6 +1274,10 @@ onload (struct ld_plugin_tv *tv)
1232 linker_output = (enum ld_plugin_output_file_type) p->tv_u.tv_val; 1274 linker_output = (enum ld_plugin_output_file_type) p->tv_u.tv_val;
1233 linker_output_set = 1; 1275 linker_output_set = 1;
1234 break; 1276 break;
1277 case LDPT_OUTPUT_NAME:
1278 /* We only use this to make user-friendly temp file names. */
1279 link_output_name = p->tv_u.tv_string;
1280 break;
1235 default: 1281 default:
1236 break; 1282 break;
1237 } 1283 }
@@ -1259,12 +1305,21 @@ onload (struct ld_plugin_tv *tv)
1259 "could not register the all_symbols_read callback"); 1305 "could not register the all_symbols_read callback");
1260 } 1306 }
1261 1307
1262 /* Support -fno-use-linker-plugin by failing to load the plugin
1263 for the case where it is auto-loaded by BFD. */
1264 char *collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS"); 1308 char *collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS");
1265 if (collect_gcc_options 1309 if (collect_gcc_options)
1266 && strstr (collect_gcc_options, "'-fno-use-linker-plugin'")) 1310 {
1267 return LDPS_ERR; 1311 /* Support -fno-use-linker-plugin by failing to load the plugin
1312 for the case where it is auto-loaded by BFD. */
1313 if (strstr (collect_gcc_options, "'-fno-use-linker-plugin'"))
1314 return LDPS_ERR;
1315
1316 if ( strstr (collect_gcc_options, "'-save-temps'"))
1317 save_temps = true;
1318
1319 if (strstr (collect_gcc_options, "'-v'")
1320 || strstr (collect_gcc_options, "'--verbose'"))
1321 verbose = true;
1322 }
1268 1323
1269 return LDPS_OK; 1324 return LDPS_OK;
1270} 1325}