This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[driver/11810] object file deletion


This is a patch of Mark's. It fixes an issue exposed by Eclipse where gcc fails to remove an explicitly named output file in the face of an error. The problem is that '-ofoo.o' records the output file as '-ofoo.o'[*], and hence attempts to delete the wrong file -- fortunately files beginning with '-' are rare, so this is unlikely to delete a real file!

The simplest solution is to default SWITCHES_NEED_SPACES to include 'o' and have the driver explicitly break apart '-ofoo.o'. Of course, this will break assemblers and linkers that require no space after the -o, but those would already not have worked if the user explictly passed in '-o foo.o' anyway. Furthermore, we (CodeSourcery) don't know of any such tools.

The only overriders of SWITCHES_NEED_SPACES set it to what this patch makes the default, so I've removed those overrides.

tested on i686-pc-linux-gnu and manually using -ofoo.o.

ok?

nathan

[*] all though I use object files in this example, it applies to any output file type specified with -o -- assembler, preprocessed, executable.
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery


2009-11-03  Mark Mitchell  <mark@codesourcery.com>

	PR driver/11810
	* gcc.c (SWITCHES_NEED_SPACES): Define to "o".
	* config/alpha/osf.h (SWITCHES_NEED_SPACES): Remove here.
	* config/mips/iris.h (SWITCHES_NEED_SPACES): Remove here.

Index: gcc.c
===================================================================
--- gcc.c	(revision 153803)
+++ gcc.c	(working copy)
@@ -684,9 +684,15 @@ proper position among the other output f
 #endif
 
 /* config.h can define SWITCHES_NEED_SPACES to control which options
-   require spaces between the option and the argument.  */
+   require spaces between the option and the argument.
+
+   We define SWITCHES_NEED_SPACES to include "o" by default.  This
+   causes "-ofoo.o" to be split into "-o foo.o" during the initial
+   processing of the command-line, before being seen by the specs
+   machinery.  This makes sure we record "foo.o" as the temporary file
+   to be deleted in the case of error, rather than "-ofoo.o".  */
 #ifndef SWITCHES_NEED_SPACES
-#define SWITCHES_NEED_SPACES ""
+#define SWITCHES_NEED_SPACES "o"
 #endif
 
 /* config.h can define ENDFILE_SPEC to override the default crtn files.  */
Index: config/alpha/osf.h
===================================================================
--- config/alpha/osf.h	(revision 153803)
+++ config/alpha/osf.h	(working copy)
@@ -167,10 +167,6 @@ __enable_execute_stack (void *addr)					
 #define LD_INIT_SWITCH "-init"
 #define LD_FINI_SWITCH "-fini"
 
-/* The linker needs a space after "-o".  This allows -oldstyle_liblookup to
-   be passed to ld.  */
-#define SWITCHES_NEED_SPACES "o"
-
 /* Select a format to encode pointers in exception handling data.  CODE
    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
    true if the symbol may be affected by dynamic relocations.
Index: config/mips/iris.h
===================================================================
--- config/mips/iris.h	(revision 153803)
+++ config/mips/iris.h	(working copy)
@@ -63,9 +63,6 @@ along with GCC; see the file COPYING3.  
 #undef ASM_FINISH_DECLARE_OBJECT
 #define ASM_FINISH_DECLARE_OBJECT mips_finish_declare_object
 
-/* The linker needs a space after "-o".  */
-#define SWITCHES_NEED_SPACES "o"
-
 /* Specify wchar_t types.  */
 #undef WCHAR_TYPE
 #define WCHAR_TYPE (Pmode == DImode ? "int" : "long int")

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]