From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29651 invoked by alias); 5 Oct 2014 22:16:44 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 29636 invoked by uid 89); 5 Oct 2014 22:16:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,LOTS_OF_MONEY,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-la0-f52.google.com Received: from mail-la0-f52.google.com (HELO mail-la0-f52.google.com) (209.85.215.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 05 Oct 2014 22:16:32 +0000 Received: by mail-la0-f52.google.com with SMTP id hz20so3468526lab.11 for ; Sun, 05 Oct 2014 15:16:28 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.134.101 with SMTP id pj5mr19696186lbb.47.1412547388508; Sun, 05 Oct 2014 15:16:28 -0700 (PDT) Received: by 10.112.236.3 with HTTP; Sun, 5 Oct 2014 15:16:28 -0700 (PDT) Date: Sun, 05 Oct 2014 22:16:00 -0000 Message-ID: Subject: Re: Local variables used inside an asm block are not recognized as used From: Daniel Kamil Kozar To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00029.txt.bz2 On 5 October 2014 23:08, David Wohlferd wrote: > Well, as written, gcc discards the whole asm statement as unneeded when > using any optimization since none of the outputs (ie ret) get used and the > statement is not volatile. > > I believe that adding "m" (hello) as an input will resolve your other > problem. Note that you may not easily see the string in the asm output > since gcc may encode this using something like this: > > movabsq $8022916924116329800, %rax > movq %rax, 32(%rsp) > movl $10, %eax > movw %ax, 44(%rsp) > > Also, I'd probably write this statement as something more like this > (untested): > > asm volatile > ( > "syscall" > : "=a" (ret) > : "0" (1), "S" (hello), "d" (hello_size), "D" (1), "m" (hello) > : "rcx", "r11", "memory", "cc" > ); > Thanks a lot! This version is certainly much better. > This lets gcc do as much of the work as possible, which generally produces > better code. And are you sure rcx and r11 get clobbered? Seems odd. Agreed. I'm positive about rcx and r11, since the ABI for Linux amd64 systems specifies that "The kernel destroys registers %rcx and %r11.". Thus, I guess it's safer to put them on the clobber list. > > dw Thanks again, dkk