This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Local variables used inside an asm block are not recognized as used
- From: Daniel Kamil Kozar <dkk089 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 6 Oct 2014 00:16:28 +0200
- Subject: Re: Local variables used inside an asm block are not recognized as used
- Authentication-results: sourceware.org; auth=none
On 5 October 2014 23:08, David Wohlferd <dw@limegreensocks.com> 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