On Thu, Sep 27, 2012 at 3:01 PM, Meador Inge <mead...@codesourcery.com> wrote:
> Hi All,
>
> The gcc-[ar|nm|ranlib] LTO utils use 'pex_one' to spawn the wrapped binutils
> program.  However, currently it is blindly returning the value of the 'err'
> parameter for the exit code.  According the documentation [1] 'err' is only
> set for an error return and 'status' is only set for a successful return.
>
> This patch fixes the bug by appropriately checking the returned status
> and extracting the exit code when needed.  Tested on GNU/Linux and Windows.
>
> OK?

Ok.  Also for the branches (where applicable).

Thanks,
Richard.

> 2012-09-27  Meador Inge  <mead...@codesourcery.com>
>
>         * gcc-ar.c (main): Handle the returning of the sub-process error
>         code correctly.
>
> [1] http://gcc.gnu.org/onlinedocs/libiberty/Functions.html#Functions
>
> Index: gcc/gcc-ar.c
> ===================================================================
> --- gcc/gcc-ar.c        (revision 191792)
> +++ gcc/gcc-ar.c        (working copy)
> @@ -42,6 +42,7 @@
>    const char *err_msg;
>    const char **nargv;
>    bool is_ar = !strcmp (PERSONALITY, "ar");
> +  int exit_code = FATAL_EXIT_CODE;
>
>    exe_name = PERSONALITY;
>  #ifdef CROSS_DIRECTORY_STRUCTURE
> @@ -96,6 +97,20 @@
>                      NULL,NULL,  &status, &err);
>    if (err_msg)
>      fprintf(stderr, "Error running %s: %s\n", exe_name, err_msg);
> +  else if (status)
> +    {
> +      if (WIFSIGNALED (status))
> +       {
> +         int sig = WTERMSIG (status);
> +         fprintf (stderr, "%s terminated with signal %d [%s]%s\n",
> +                  exe_name, sig, strsignal(sig),
> +                  WCOREDUMP(status) ? ", core dumped" : "");
> +       }
> +      else if (WIFEXITED (status))
> +       exit_code = WEXITSTATUS (status);
> +    }
> +  else
> +    exit_code = SUCCESS_EXIT_CODE;
>
> -  return err;
> +  return exit_code;
>  }

Reply via email to