[PATCH] Fix PR driver/79181 (and others), not deleting some /tmp/cc* files for LTO.

Richard Biener richard.guenther@gmail.com
Tue Aug 31 06:12:58 GMT 2021


On Tue, Aug 31, 2021 at 4:17 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> So the main issue here is that some signals are not setup unlike collect2.
> So this merges the setting up of the signal handlers to one function in
> collect-utils and has collect2 and lto-wrapper call that function.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

OK.

> gcc/ChangeLog:
>
>         PR driver/79181
>         * collect-utils.c (setup_signals): New declaration.
>         * collect-utils.h (setup_signals): New function.
>         * collect2.c (handler): Delete.
>         (main): Instead of manually setting up the signals,
>         just call setup_signals.
>         * lto-wrapper.c (main): Likewise.
> ---
>  gcc/collect-utils.c | 37 +++++++++++++++++++++++++++++++++++++
>  gcc/collect-utils.h |  1 +
>  gcc/collect2.c      | 36 +-----------------------------------
>  gcc/lto-wrapper.c   | 18 +-----------------
>  4 files changed, 40 insertions(+), 52 deletions(-)
>
> diff --git a/gcc/collect-utils.c b/gcc/collect-utils.c
> index 6b5d61d5162..19423d31885 100644
> --- a/gcc/collect-utils.c
> +++ b/gcc/collect-utils.c
> @@ -57,6 +57,43 @@ fatal_signal (int signum)
>       so its normal effect occurs.  */
>    kill (getpid (), signum);
>  }
> +
> +/* Setup the signal handlers for the utils. */
> +void
> +setup_signals (void)
> +{
> +#ifdef SIGQUIT
> +  if (signal (SIGQUIT, SIG_IGN) != SIG_IGN)
> +    signal (SIGQUIT, fatal_signal);
> +#endif
> +  if (signal (SIGINT, SIG_IGN) != SIG_IGN)
> +    signal (SIGINT, fatal_signal);
> +#ifdef SIGALRM
> +  if (signal (SIGALRM, SIG_IGN) != SIG_IGN)
> +    signal (SIGALRM, fatal_signal);
> +#endif
> +#ifdef SIGHUP
> +  if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
> +    signal (SIGHUP, fatal_signal);
> +#endif
> +  if (signal (SIGSEGV, SIG_IGN) != SIG_IGN)
> +    signal (SIGSEGV, fatal_signal);
> +  if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
> +    signal (SIGTERM, fatal_signal);
> +#ifdef SIGPIPE
> +  if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
> +    signal (SIGPIPE, fatal_signal);
> +#endif
> +#ifdef SIGBUS
> +  if (signal (SIGBUS, SIG_IGN) != SIG_IGN)
> +    signal (SIGBUS, fatal_signal);
> +#endif
> +#ifdef SIGCHLD
> +  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
> +     receive the signal.  A different setting is inheritable */
> +  signal (SIGCHLD, SIG_DFL);
> +#endif
> +}
>
>  /* Wait for a process to finish, and exit if a nonzero status is found.  */
>
> diff --git a/gcc/collect-utils.h b/gcc/collect-utils.h
> index 4f0e3ce9832..15f831d778a 100644
> --- a/gcc/collect-utils.h
> +++ b/gcc/collect-utils.h
> @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
>  extern void notice (const char *, ...)
>    __attribute__ ((format (printf, 1, 2)));
>  extern void fatal_signal (int);
> +extern void setup_signals (void);
>
>  extern struct pex_obj *collect_execute (const char *, char **,
>                                         const char *, const char *,
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index 07092c2733a..cf04a58ba4d 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -301,7 +301,6 @@ const char tool_name[] = "collect2";
>
>  static symkind is_ctor_dtor (const char *);
>
> -static void handler (int);
>  static void maybe_unlink_list (char **);
>  static void add_to_list (struct head *, const char *);
>  static int extract_init_priority (const char *);
> @@ -408,14 +407,6 @@ collect_atexit (void)
>    tool_cleanup (false);
>  }
>
> -static void
> -handler (int signo)
> -{
> -  tool_cleanup (true);
> -
> -  signal (signo, SIG_DFL);
> -  raise (signo);
> -}
>  /* Notify user of a non-error, without translating the format string.  */
>  void
>  notice_translated (const char *cmsgid, ...)
> @@ -907,11 +898,7 @@ main (int argc, char **argv)
>    COLLECT2_HOST_INITIALIZATION;
>  #endif
>
> -#ifdef SIGCHLD
> -  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
> -     receive the signal.  A different setting is inheritable */
> -  signal (SIGCHLD, SIG_DFL);
> -#endif
> +  setup_signals ();
>
>    /* Unlock the stdio streams.  */
>    unlock_std_streams ();
> @@ -1051,27 +1038,6 @@ main (int argc, char **argv)
>    if (argc < 2)
>      fatal_error (input_location, "no arguments");
>
> -#ifdef SIGQUIT
> -  if (signal (SIGQUIT, SIG_IGN) != SIG_IGN)
> -    signal (SIGQUIT, handler);
> -#endif
> -  if (signal (SIGINT, SIG_IGN) != SIG_IGN)
> -    signal (SIGINT, handler);
> -#ifdef SIGALRM
> -  if (signal (SIGALRM, SIG_IGN) != SIG_IGN)
> -    signal (SIGALRM, handler);
> -#endif
> -#ifdef SIGHUP
> -  if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
> -    signal (SIGHUP, handler);
> -#endif
> -  if (signal (SIGSEGV, SIG_IGN) != SIG_IGN)
> -    signal (SIGSEGV, handler);
> -#ifdef SIGBUS
> -  if (signal (SIGBUS, SIG_IGN) != SIG_IGN)
> -    signal (SIGBUS, handler);
> -#endif
> -
>    /* Extract COMPILER_PATH and PATH into our prefix list.  */
>    prefix_from_env ("COMPILER_PATH", &cpath);
>    prefix_from_env ("PATH", &path);
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index aae48aff100..903c258a03a 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -2125,23 +2125,7 @@ main (int argc, char *argv[])
>    if (atexit (lto_wrapper_cleanup) != 0)
>      fatal_error (input_location, "%<atexit%> failed");
>
> -  if (signal (SIGINT, SIG_IGN) != SIG_IGN)
> -    signal (SIGINT, fatal_signal);
> -#ifdef SIGHUP
> -  if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
> -    signal (SIGHUP, fatal_signal);
> -#endif
> -  if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
> -    signal (SIGTERM, fatal_signal);
> -#ifdef SIGPIPE
> -  if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
> -    signal (SIGPIPE, fatal_signal);
> -#endif
> -#ifdef SIGCHLD
> -  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
> -     receive the signal.  A different setting is inheritable */
> -  signal (SIGCHLD, SIG_DFL);
> -#endif
> +  setup_signals ();
>
>    /* We may be called with all the arguments stored in some file and
>       passed with @file.  Expand them into argv before processing.  */
> --
> 2.17.1
>


More information about the Gcc-patches mailing list