summaryrefslogtreecommitdiff
path: root/gcc34/gcc-3.4.6-unlink-if-ordinary.patch
blob: 4bd25f2e3e6f58bb4f6ca17c8b2350595e136fb6 (plain)
    1 Following the logic of the binutils change upstream (the addition of the 
    2 new unlink_if_ordinary() function), we update collect2 so that it will 
    3 only unlink files if they are 'ordinary' (in other words, a regular file 
    4 or a symlink).
    5 
    6 This allows us to do fun things like `gcc test.c -o /dev/null` and not 
    7 have to worry about the toolchain doing unlink(/dev/null) on us (cause 
    8 that sucks huge wang).  For example, this is common on a parisc/mips 
    9 machine:
   10 # gcc test.c -o /dev/null
   11 /usr/hppa2.0-unknown-linux-gnu/bin/ld: final link failed: Nonrepresentable section on output
   12 collect2: ld returned 1 exit status
   13 # ls /dev/null
   14 ls: /dev/null: No such file or directory
   15 
   16 http://bugs.gentoo.org/show_bug.cgi?id=79836
   17 
   18 --- gcc/gcc/collect2.c
   19 +++ gcc/gcc/collect2.c
   20 @@ -34,6 +34,12 @@
   21  #if ! defined( SIGCHLD ) && defined( SIGCLD )
   22  #  define SIGCHLD SIGCLD
   23  #endif
   24 +#ifdef HAVE_UNISTD_H
   25 +#include <unistd.h>
   26 +#endif
   27 +#if HAVE_SYS_STAT_H
   28 +#include <sys/stat.h>
   29 +#endif
   30  
   31  #ifdef vfork /* Autoconf may define this to fork for us.  */
   32  # define VFORK_STRING "fork"
   33 @@ -1574,14 +1603,24 @@
   34    do_wait (prog);
   35  }
   36  
   37 -/* Unlink a file unless we are debugging.  */
   38 -
   39 +/* Unlink a file unless we are debugging or file is not normal.  */
   40 +#ifndef S_ISLNK
   41 +#ifdef S_IFLNK
   42 +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
   43 +#else
   44 +#define S_ISLNK(m) 0
   45 +#define lstat stat
   46 +#endif
   47 +#endif
   48  static void
   49  maybe_unlink (const char *file)
   50  {
   51 -  if (!debug)
   52 -    unlink (file);
   53 -  else
   54 +  if (!debug) {
   55 +    struct stat st;
   56 +    if (lstat (file, &st) == 0
   57 +        && (S_ISREG (st.st_mode) || S_ISLNK (st.st_mode)))
   58 +      unlink (file);
   59 +  } else
   60      notice ("[Leaving %s]\n", file);
   61  }
   62  

Generated by cgit