public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Kamil Kozar <dkk089@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Local variables used inside an asm block are not recognized as used
Date: Sun, 05 Oct 2014 18:13:00 -0000	[thread overview]
Message-ID: <CANMdSOyzEQbm8mgXSYYug54-17Z2aLifiTGf_m9H8iciiM4qJg@mail.gmail.com> (raw)

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

             reply	other threads:[~2014-10-05 18:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-05 18:13 Daniel Kamil Kozar [this message]
2014-10-05 21:08 ` David Wohlferd
2014-10-05 22:16 Daniel Kamil Kozar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANMdSOyzEQbm8mgXSYYug54-17Z2aLifiTGf_m9H8iciiM4qJg@mail.gmail.com \
    --to=dkk089@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).