[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

gcc -pipe -ox.o -c x.c still writes x.o on error



>Submitter-Id:	net
>Originator:	John DeWeese
>Organization:	USC ICT
>Confidential:	no
>Synopsis:	gcc -pipe -ox.o -c x.c  writes erroneous x.o on compile error
>Severity:	serious
>Priority:	medium
>Category:	c c++
>Class:		wrong-code
>Release:	3.2.3 20030415 (Debian prerelease) (Debian testing/unstable)
>Environment:
System: Linux elmo.ict.usc.edu 2.4.18 #1 SMP Wed Jun 19 16:35:10 PDT 2002 i686 unknown unknown GNU/Linux
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
GCC incorrectly generates an output .o file even if there is a compiler
error under the following conditions:
    -pipe is enabled, -c is enabled, and -o<objname>.o is specified.

The output object file is slightly different than an object file generated from a C file without a minor compiler error, for example if the word ERROR is added arbitrarily to the end of the C file. Under some error conditions,
some symbols would be missing from the output object file.

I have verified that the error occurs on gcc 2.95, 3.0.4, 3.2.3, and 3.3.1.

	<precise description of the problem (multiple lines)>
>How-To-Repeat:
Create a file "foo.c" with the following content, sans angle brackets:
>>>>
#include <stdio.h>
int main(int argc, char** argv) {
  ERROR
  printf("Hello World.\n");
  return 0;
}
<<<<

Execute the following command with any version of gcc:
gcc -pipe -ofoo.o -c foo.c

The output is as follows:
foo.c: In function main':
foo.c:4: error: ERROR' undeclared (first use in this function)
foo.c:4: error: (Each undeclared identifier is reported only once
foo.c:4: error: for each function it appears in.)
foo.c:4: error: syntax error before "printf"

However, a foo.o is written out. Subsequently, linking it causes an error:

gcc test.o

The output is:
/usr/lib/gcc-lib/i386-linux/3.3.1/../../../crt1.o(.text+0x18): In function
_start':
: undefined reference to main'
collect2: ld returned 1 exit status

<When reporting a compiler error, preprocessor output must be included>
>Fix:
	<how to correct or work around the problem, if known (multiple lines)>

It is possible that the pipe exit status is not correctly checked after the
processes associated with all pipes have exited. Even if the compiler
dies with an error condition, the assembler may be writing to the -o output
file regardless. Not sure.

BTW thanks for gcc, I really appreciate it!

  - John DeWeese



Reply to: