This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
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: Sun, 5 Oct 2014 20:13:46 +0200
- Subject: Local variables used inside an asm block are not recognized as used
- Authentication-results: sourceware.org; auth=none
Hello,
Long time ago, I wrote the following code snippet in order to
demonstrate how to call system calls directly from gcc via inline
assembly in amd64 systems, as opposed to using the libc wrapper
functions.
#include <unistd.h>
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