Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers > Re: x86-64 and ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 17 Topic 2419 of 2534
Post > Topic >>

Re: x86-64 and calling conventions

by Vidar Hokstad <vidar.hokstad@[EMAIL PROTECTED] > May 12, 2008 at 05:48 AM

On May 12, 12:44 am, "cr88192" <cr88...@[EMAIL PROTECTED]
> wrote:
> Well, I have my own compiler, however, I don't as of yet target x86-64.
>
> one of the main reasons:
> the calling conventions used in Linux and friends are, scary...
>
> Short Description:
> arguments are passed in registers, meanwhile, others may be left on the
> stack, and there is no particular relation between the registers and the
> stack layout.

Ouch. This is hideous. Since I didn't know what you were talking
about, but is in the process of writing a compiler in Ruby (currently
targeting 386, but I want to add x86_64 later) I did a search and came
up with this: http://www.x86-64.org/do***entation/abi-0.99.pdf

I can see why you consider it scary. My compiler is taking a lot of
ideas from Ruby, and that includes being able to take all arguments as
an array, which is trivial on 32 bit x86, but a real pain here..

There are a number of callee saved registers, so you can do some forms
of extension of the calling convention without losing the ability for
your code to call out to C without interface stubs, but you'd lose the
ability for C to call back in, of course (I made that sacrifice in my
compiler for varargs, where I pass the count of varargs provided in a
register, in which case you'll need a wrapper to safely call it from
C, but if my code calls varargs C functions, the value of that
register will just be ignored).

Apart from that, I'd strongly suggest you stick with the calling
convention, even though it's painful. To handle higher order argument
lists you could always synthesize an anonymous conversion function if
needed, to turn it into an array or iterate over the arguments.

As for "hidden arguments", presumably they won't be hidden to the C
code anyway, or the values would be lost when crossing the barrier, so
there I'd consider just treating them as normal arguments with respect
to the calling convention and just hiding them to the users of your
language.

There's in practice nothing outright stopping you from defining your
function signatures in a way which will force all the arguments onto
the stack and still comply with this calling convention, either, as
far as I can see, but it'd result in function signatures that would be
extremely inconvenient to work with on the C side, and you'd still
have a problem calling C code unless your compiler explicitly knows
when it needs to resort to the C calling convention.

I'd bite the bullet...

Vidar
 




 17 Posts in Topic:
x86-64 and calling conventions
"cr88192" <c  2008-05-12 09:44:42 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-12 20:10:59 
Re: x86-64 and calling conventions
Bart <bc@[EMAIL PROTEC  2008-05-14 19:22:59 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-15 15:44:11 
Re: x86-64 and calling conventions
James Harris <james.ha  2008-05-12 04:12:03 
Re: x86-64 and calling conventions
James Harris <james.ha  2008-05-14 03:38:42 
Re: x86-64 and calling conventions
James Harris <james.ha  2008-05-14 11:37:05 
Re: x86-64 and calling conventions
Vidar Hokstad <vidar.h  2008-05-12 05:48:02 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-13 18:19:29 
Re: x86-64 and calling conventions
Dave Parker <daveparke  2008-05-12 20:10:58 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-13 17:51:07 
Re: x86-64 and calling conventions
glen herrmannsfeldt <g  2008-05-13 01:28:57 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-15 07:44:35 
Re: x86-64 and calling conventions
Boleslaw Ciesielski <b  2008-05-23 12:05:14 
Re: x86-64 and calling conventions
glen herrmannsfeldt <g  2008-05-29 13:56:05 
Re: x86-64 and calling conventions
Vidar Hokstad <vidar.h  2008-05-14 08:20:27 
Re: x86-64 and calling conventions
"cr88192" <c  2008-05-15 06:46:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:28:13 CDT 2008.