From patchwork Thu Sep 27 13:01:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meador Inge X-Patchwork-Id: 187351 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 95BBE2C00A3 for ; Thu, 27 Sep 2012 23:01:37 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349355698; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:Message-ID:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=13SzHld SppIVPMxISiFosZLLWp4=; b=VDfU3Uw+xqDwzLi6R3BzXvvD+DcXXr5PKKMS/q0 SIAXFWBF3VB4w8pDx0HRuT5uIhpC+UgXnz2suXAR3BQ1dXkSPm3dlL6qFthcouOy j1tqe0VlroUAQ+9iOfXpPr+xn0/pvR4Iqf3LdO/yB9PdzYADtFcc2F+PqnOSgHxa h7ho= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=az5kHlQnupOXL/I0rtFIsTToZBqX0dr0NGgXC5wVqXipTB5FBkRLT58mrpxEKr T6f/+IE5sufXK/4MagdDso5D/FzkGGsCSEwhDfBg8siCepaoUJMscSw6DPUVXbyx uIarjJ+/ZdkLruuHLc8nLQSslIbb8jAl5fO+DVf9QZul8=; Received: (qmail 29640 invoked by alias); 27 Sep 2012 13:01:34 -0000 Received: (qmail 29632 invoked by uid 22791); 27 Sep 2012 13:01:33 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 27 Sep 2012 13:01:29 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1THDiZ-00057S-Ro from meador_inge@mentor.com for gcc-patches@gcc.gnu.org; Thu, 27 Sep 2012 06:01:27 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 27 Sep 2012 06:01:27 -0700 Received: from dhalsim.mgc.mentorg.com (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.1.289.1; Thu, 27 Sep 2012 06:01:26 -0700 From: Meador Inge To: Subject: [PATCH] Correct handling of gcc-[ar|nm|ranlib] exit codes Date: Thu, 27 Sep 2012 08:01:26 -0500 Message-ID: <1348750886-20673-1-git-send-email-meadori@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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? 2012-09-27 Meador Inge * 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; }