From patchwork Mon Aug 4 18:36:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 4673041 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9C9579F3B4 for ; Mon, 4 Aug 2014 18:37:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC3FD200E8 for ; Mon, 4 Aug 2014 18:37:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B7A720149 for ; Mon, 4 Aug 2014 18:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751428AbaHDShJ (ORCPT ); Mon, 4 Aug 2014 14:37:09 -0400 Received: from mdfmta010.mxout.tbr.inty.net ([91.221.168.51]:36018 "EHLO smtp.demon.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751919AbaHDShH (ORCPT ); Mon, 4 Aug 2014 14:37:07 -0400 X-Greylist: delayed 306 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 Aug 2014 14:37:07 EDT Received: from smtp.demon.co.uk (unknown [127.0.0.1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mdfmta010.tbr.inty.net (Postfix) with ESMTP id 558886F8C76 for ; Mon, 4 Aug 2014 18:00:26 +0100 (BST) Received: from mdfmta009.tbr.inty.net (unknown [127.0.0.1]) by mdfmta009.tbr.inty.net (Postfix) with ESMTP id A976C384082; Mon, 4 Aug 2014 17:58:28 +0100 (BST) Received: from mdfmta009.tbr.inty.net (unknown [127.0.0.1]) by mdfmta009.tbr.inty.net (Postfix) with ESMTP id 6B9AC384081; Mon, 4 Aug 2014 17:58:28 +0100 (BST) Received: from [192.168.254.10] (unknown [80.176.147.220]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mdfmta009.tbr.inty.net (Postfix) with ESMTP; Mon, 4 Aug 2014 17:58:28 +0100 (BST) Message-ID: <53DFD2B7.7080801@ramsay1.demon.co.uk> Date: Mon, 04 Aug 2014 19:36:39 +0100 From: Ramsay Jones User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Christopher Li CC: Sparse Mailing-list Subject: [PATCH 04/10] compile-i386.c: don't mix calls to write(2) with stdio X-MDF-HostID: 4 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some versions of gcc (e.g. v4.8.2) complain about ignoring the return value of a call to 'write(2)' on line 735, since it is marked with the warn_unused_result attribute. (see also lines 745-747). Note that this code is mixing calls to 'write' on STDOUT_FILENO with calls to stdio functions on the stdout file handle. So, in order to suppress the compiler warnings, we replace both calls to 'write' with equivalent calls to stdio functions. Signed-off-by: Ramsay Jones --- Hi Chris, Since there are no tests for the compile program, I ran the old version (from commit 748b856) and this version over all of the .c files in the sparse directory, saving the output to file and diff-ing the result. Unfortunately, compile segfaults on most files and the diff shows that this patch leads to a change in behaviour, caused by the lack of I/O buffer flushing prior to the segfault (all of the diffs showed missing text at the end of each new output file). Just to confirm, I added back the 'fflush(stdout); ...' line that I removed in the third hunk below _and_ duplicated that line and placed it after the call to 'emit_atom_list(f);'. This version of compile produced (almost) exactly the same output as the original. The reason for the almost is that three files showed a non-empty diff which seemed to indicate (a possible bug?) that a label name was being generated from a memory address. The actual addresses/label name generated in each file was different, but they were used consistently in each file. For example, the complete diff for sort.c is: --- sort.c.out-old 2014-08-04 17:32:32.399744973 +0100 +++ sort.c.out-new 2014-08-04 17:37:04.189092702 +0100 @@ -742,7 +742,7 @@ addl $744, %esp ret .size merge_block_seqs, .-merge_block_seqs -.L0xb740550c: +.L0xb748068c: .globl sort_list .type sort_list, @function sort_list: @@ -837,7 +837,7 @@ movl %eax, 68(%esp) # .... end copy jmp .L72 .L87: # end if - jmp .LS0xb740550c + jmp .LS0xb748068c .L86: # end if movl 44(%esp), %eax # begin copy .. movl %eax, 72(%esp) # .... end copy ATB, Ramsay Jones compile-i386.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compile-i386.c b/compile-i386.c index 88169ec..f89b6ca 100644 --- a/compile-i386.c +++ b/compile-i386.c @@ -732,7 +732,7 @@ static void emit_insn_atom(struct function *f, struct atom *atom) atom->insn, comment[0] ? "\t\t" : "", comment); - write(STDOUT_FILENO, s, strlen(s)); + printf("%s", s); } static void emit_atom_list(struct function *f) @@ -742,9 +742,7 @@ static void emit_atom_list(struct function *f) FOR_EACH_PTR(f->atom_list, atom) { switch (atom->type) { case ATOM_TEXT: { - ssize_t rc = write(STDOUT_FILENO, atom->text, - atom->text_len); - (void) rc; /* FIXME */ + printf("%.*s", (int)atom->text_len, atom->text); break; } case ATOM_INSN: @@ -886,7 +884,6 @@ static void emit_func_post(struct symbol *sym) insn("ret", NULL, NULL, NULL); /* output everything to stdout */ - fflush(stdout); /* paranoia; needed? */ emit_atom_list(f); /* function footer */