public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thutt at vmware dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/16331] x86-64 inline asm register constraints insufficient WRT ABI
Date: Tue, 10 Feb 2009 14:35:00 -0000	[thread overview]
Message-ID: <20090210143449.4751.qmail@sourceware.org> (raw)
In-Reply-To: <bug-16331-1331@http.gcc.gnu.org/bugzilla/>



------- Comment #13 from thutt at vmware dot com  2009-02-10 14:34 -------
(In reply to comment #12)
> (In reply to comment #11)
> > Uros, how hard to support this in x86 backend?
>

<snip>

> OTOH, constraints should be used to support correct register
> allocation for machine instructions, not to emulate ABI in order to
> support calls from inside asm statements.

Please indulge me for a moment.

What exactly is a call?

Are you considering the only method of transferring control to be the
standard 'near call' & 'near ret' instructions on the x86?

What about the following modes of transferring control to another
address?

   int
   iret
   ret
   sysenter
   sysexit
   syscall
   sysret
   ud2
   int3
   jmp

Then, what of these?

   lcall
   lret
   ljmp

Every one of these is a method to transfer control to another address
with a programmer-defined set of input register.  More importantly,
none of these are directly supported by gcc to invoke functions
without resorting to inline assembly.

If you're working on an operating system, a virtualization engine or
some other embedded device you might need to transfer control using
one of these methods.

As a really simple example, consider a handler for a timer interrupt.
Let's say that the prologue for the interrupt (written in assembly)
handler storing all the machine registers into a data structure
accessible from C.  Then, the prologue transfers to the handler which is
conveniently written in C.  Wouldn't it be really nice if one could
restore all the saved registers in C code using only inline assembly
instruction?

    __asm__("iret"
            :
            : force restoring registers saved in data structure);

I'm confident you can see the advantage of doing this in C and letting
the compiler deal with the bookkeeping details, rather than resorting
to another assembly language function which does such a simple feat.

I think I pretty clearly demonstrate here that calling other functions
using the x86 architecture isn't as simple as assuming it's going only
to be done with 'call', 'jmp' and 'ret', and many of those methods are
not possible with straight C, even with gcc's helpful extensions.

Should gcc prevent the developer from using the ABI just because the
inline assembly wasn't meant to 'support calls from inside assembly
statements'?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16331


  parent reply	other threads:[~2009-02-10 14:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-16331-1331@http.gcc.gnu.org/bugzilla/>
2009-02-09 20:46 ` hjl dot tools at gmail dot com
2009-02-09 20:47 ` hjl dot tools at gmail dot com
2009-02-09 20:47 ` hjl dot tools at gmail dot com
2009-02-09 20:50 ` hjl dot tools at gmail dot com
2009-02-09 22:43 ` ubizjak at gmail dot com
2009-02-10 14:35 ` thutt at vmware dot com [this message]
2009-02-10 15:20 ` ubizjak at gmail dot com
2009-02-10 15:35 ` thutt at vmware dot com
     [not found] <bug-16331-4@http.gcc.gnu.org/bugzilla/>
2012-06-21 17:11 ` gcc at kalvdans dot no-ip.org
2014-06-25 23:48 ` gerald at pfeifer dot com
2004-07-02 16:51 [Bug c/16331] New: " thutt at vmware dot com
2004-08-03  7:06 ` [Bug target/16331] " pinskia at gcc dot gnu dot org
2005-07-02  1:27 ` pinskia at gcc dot gnu dot org
2005-07-02 10:17 ` falk at debian dot org
2005-09-04 19:05 ` pinskia at gcc dot gnu dot org

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=20090210143449.4751.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).