Bug 48467 - [LTO] Anomalous behavior of -save-temps
Summary: [LTO] Anomalous behavior of -save-temps
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.7.0
: P3 minor
Target Milestone: 4.7.0
Assignee: Richard Biener
URL:
Keywords: lto
Depends on:
Blocks:
 
Reported: 2011-04-05 18:45 UTC by Dmitry Gorbachev
Modified: 2011-04-19 18:53 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-06 10:01:51


Attachments
DIFF file with 4 tests (296 bytes, text/plain)
2011-04-05 18:45 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2011-04-05 18:45:38 UTC
Created attachment 23884 [details]
DIFF file with 4 tests

1. After running the 1st test, notice the absence of one generated assembler file (1.s), which is deleted by lto1. In toplev.c,

1851  if (flag_wpa)
1852    unlink_if_ordinary (asm_file_name);

2. As the 2nd and 3rd tests show, it can also be misused as an output file for lto1, so its original, written by cc1, content gets lost.

3. The 4th test gives good, expected results.
Comment 1 Richard Biener 2011-04-06 10:01:51 UTC
Confirmed.

What we could do is try to arrange for the WPA lto1 stage to receive
-o /dev/null, as it will not produce regular output.  Or to simply
avoid calling init_asm_output () for -fwpa.  So, sth like

Index: toplev.c
===================================================================
--- toplev.c    (revision 172023)
+++ toplev.c    (working copy)
@@ -1743,7 +1743,8 @@ lang_dependent_init (const char *name)
     return 0;
   input_location = save_loc;
 
-  init_asm_output (name);
+  if (!flag_wpa)
+    init_asm_output (name);
 
   /* If stack usage information is desired, open the output file.  */
   if (flag_stack_usage)
@@ -1848,8 +1849,6 @@ finalize (bool no_backend)
        fatal_error ("error writing to %s: %m", asm_file_name);
       if (fclose (asm_out_file) != 0)
        fatal_error ("error closing %s: %m", asm_file_name);
-      if (flag_wpa)
-       unlink_if_ordinary (asm_file_name);
     }
 
   if (stack_usage_file)


which likely needs fixups throughout the compiler in case of
missing asm_out_file checks.
Comment 2 Richard Biener 2011-04-08 13:10:31 UTC
Author: rguenth
Date: Fri Apr  8 13:10:27 2011
New Revision: 172181

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172181
Log:
2011-04-08  Richard Guenther  <rguenther@suse.de>

	PR lto/48467
	* toplev.c (lang_dependent_init): Do not open asm_out_file
	in WPA mode, nor perform debug machinery initialization.
	(finalize): Do not unlink asm_out_file in WPA mode.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/toplev.c
Comment 3 Richard Biener 2011-04-08 13:10:51 UTC
Fixed for 4.7.
Comment 4 Dmitry Gorbachev 2011-04-19 18:53:51 UTC
Second bug is now bug 48691.