From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30946 invoked by alias); 5 Oct 2014 21:08:48 -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 30935 invoked by uid 89); 5 Oct 2014 21:08:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,LOTS_OF_MONEY,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: limegreensocks.com Received: from limegreensocks.com (HELO limegreensocks.com) (207.118.20.56) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (DES-CBC3-SHA encrypted) ESMTPS; Sun, 05 Oct 2014 21:08:46 +0000 Received: from [192.168.1.44] ([192.168.1.44]) by limegreensocks.com via TCP with ESMTPSA; Sun, 05 Oct 2014 14:08:48 -0700 Message-ID: <5431B357.9080503@LimeGreenSocks.com> Date: Sun, 05 Oct 2014 21:08:00 -0000 From: David Wohlferd User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Re: Local variables used inside an asm block are not recognized as used References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00028.txt.bz2 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" ); 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. dw On 10/5/2014 11:13 AM, Daniel Kamil Kozar wrote: > #include > > int main(void) > { > const char hello[] = "Hello World!\n"; > const size_t hello_size = sizeof(hello); > ssize_t ret; > asm > ( > "movl $1, %%eax\n\t" > "movl $1, %%edi\n\t" > "movq %1, %%rsi\n\t" > "movl %2, %%edx\n\t" > "syscall" > : "=a"(ret) > : "g"(hello), "g"(hello_size) > : "%rdi", "%rsi", "%rdx", "%rcx", "%r11" > ); > return 0; > } > > Unfortunately, this snippet does not work anymore with gcc 4.9.1. An > inspection of gcc's result when run with -S shows that the "hello" > variable is not even created. Adding "static" to the variable's > declaration fixes the issue, however I'm still wondering what's wrong > with the original code and why gcc does not seem to see that the local > variable is actually used by the asm block. > > Thanks, > -dkk