This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
3.4 PATCH: Fix PCH build failure on IRIX 6 O32
- From: Rainer Orth <ro at TechFak dot Uni-Bielefeld dot DE>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 24 Jun 2003 21:39:08 +0200 (MEST)
- Subject: 3.4 PATCH: Fix PCH build failure on IRIX 6 O32
PCH generation during bootstrap on IRIX 6 O32 (mips-sgi-irix6.5o32) used to
fail:
/vol/gnu/src/gcc/gcc-dist/libstdc++-v3/include/stdc++.h:86: fatal error: error
writing to /var/tmp//cc1LwIHd.s: Bad file number
compilation terminated.
When using the native assembler (when debugging isn't supported), the
libstdc++-v3 configure test didn't detect this, but the actual generation
attempt failed nonetheless. Using gas, the configure test found the
problem. Once the result is used
(http://gcc.gnu.org/ml/gcc-patches/2003-06/msg00485.html), bootstrap
finished in this configuration.
Investigating the root cause, I found the following:
* The error message above is from toplev.c (finalize): the
ferror (asm_out_file) != 0
test fails
* Stripping down the libstdc++-v3 configure test for working pch support, I
found that with this pch.C
#include <math.h>
int main() {
(0);
; return 0; }
and first running the original command used there with -v -save-temps,
cc1plus pch.ii --output-pch=pch.C.gch
works ok, but adding -g produces the same `Bad file number' error as
above.
* The error indication in asm_out_file (_IOERR in the _flag member) is set
when some output function called from dwarf2out_frame_finish() first
calls __flsbuf to flush the output buffer. The EBADF error is actually
set by _wrtchk, which checks if the stream has been written to
immediately before.
After some digging around, it turned out that this happens because first
* c-pch.c (c_common_write_pch) copies asm_out_file to pch_outfile (thus the
whole asm_out_file is read)
* next dwarf2out_frame_finish writes to asm_out_file
This results in the EBADF error because asm_out_file has been opened for
update with "w+". The C90 standard (7.9.5.3, The fopen function) requires
that one must either fflush or position such a file when switching from
reading to writing. The IRIX 6 libc is obviously especially picky about
this. Adding the required fflush fixes the problem.
With this patch, mainline bootstrapped the mips-sgi-irix6.5o32
configuration successfully, PCH generation in libstdc++ worked, and a
couple of pch related testcases are fixed:
-FAIL: static-1.H (test for excess errors)
-FAIL: static-1.H (test for excess errors)
-FAIL: static-1.H (test for excess errors)
-FAIL: system-1.H (test for excess errors)
-FAIL: system-1.H (test for excess errors)
-FAIL: system-1.H (test for excess errors)
-FAIL: system-2.H (test for excess errors)
-FAIL: system-2.H (test for excess errors)
-FAIL: system-2.H (test for excess errors)
-FAIL: uninst.H (test for excess errors)
-FAIL: uninst.H (test for excess errors)
-FAIL: uninst.H (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: common-1.h (test for excess errors)
-FAIL: gcc.dg/pch/static-1.c -O0 -g assembly comparison
-FAIL: gcc.dg/pch/static-1.c -O0 assembly comparison
-FAIL: gcc.dg/pch/static-1.c -O1 assembly comparison
-FAIL: gcc.dg/pch/static-1.c -O2 assembly comparison
-FAIL: gcc.dg/pch/static-1.c -Os assembly comparison
-FAIL: gcc.dg/pch/static-2.c -O0 -g assembly comparison
-FAIL: gcc.dg/pch/static-2.c -O0 assembly comparison
-FAIL: gcc.dg/pch/static-2.c -O1 assembly comparison
-FAIL: gcc.dg/pch/static-2.c -O2 assembly comparison
-FAIL: gcc.dg/pch/static-2.c -Os assembly comparison
-FAIL: gcc.dg/pch/static-3.c -O0 -g assembly comparison
-FAIL: gcc.dg/pch/static-3.c -O0 assembly comparison
-FAIL: gcc.dg/pch/static-3.c -O1 assembly comparison
-FAIL: gcc.dg/pch/static-3.c -O2 assembly comparison
-FAIL: gcc.dg/pch/static-3.c -Os assembly comparison
On the other hand, the question remains if this is really the right fix: if
the assembly output is copied to the PCH file, this copy is now obviously
incomplete. Someone who really understands the PCH stuff needs to decide
this (and develop an appropriate fix if necessary).
Ok for mainline?
Rainer
-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University
Mon Jun 23 19:11:05 2003 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
* c-pch.c (c_common_write_pch): Flush asm_out_file to allow for
subsequent writes.
Index: gcc/c-pch.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pch.c,v
retrieving revision 1.11
diff -u -p -r1.11 c-pch.c
--- gcc/c-pch.c 22 Jun 2003 13:41:24 -0000 1.11
+++ gcc/c-pch.c 24 Jun 2003 19:08:42 -0000
@@ -146,6 +146,8 @@ c_common_write_pch (void)
written += size;
}
free (buf);
+ /* asm_out_file can be written afterwards, so must be flushed first. */
+ fflush (asm_out_file);
gt_pch_save (pch_outfile);
cpp_write_pch_state (parse_in, pch_outfile);