tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: must use gcc builtin?



On Fri, 24 Feb 2012 07:38:42 +0200
Alan Barrett <apb%cequrux.com@localhost> wrote:

> On Thu, 23 Feb 2012, James K. Lowden wrote:
> > #ifdef __GNUC__
> > #define _BSD_VA_LIST_    __builtin_va_list /* GCC built-in type */
> > #else
> > #define _BSD_VA_LIST_    char *    /* XXXfvdl should be ok? */
> > #endif
> >
> > That code doesn't depend on x86.  It depends on GNU.  All I need 
> > is another C compiler for x86, and my va_list is magically char* 
> > again.
> 
> That's a bug, because it means that compiling the caller with one 
> compiler and the callee with another compiler, will give results 
> that don't work (assuming an ABI in which __buitin_va_list is not 
> really compatible with char *).  Both compilers should implement 
> the same ABI.

Yes.  It presents a problem for e.g. pcc.  

That said, I now understand why __buitin_va_list is needed, see
below.    My thanks for everyone's patience.  

On Fri, 24 Feb 2012 03:55:33 +0000
David Holland <dholland-tech%netbsd.org@localhost> wrote:

> calling conventions aren't going to change and the extra behavioral
> guarantees you're asking for aren't possible on most platforms.

It's easy to confuse "platform" with "compiler".  C makes no demand for
any particular calling convention, nor does hardware.  It's a
choice made by an implementation.  Compilers that share a calling
convention have the advantage of being interchangeable; libraries can
be compiled with one compiler and the application another, and it all
works, including stdargs.  That's a powerful motivation for compilers
to use one convention (and basically what Christos pointed out).  

I always think of the pre-processor as separate and independent of the
compiler.  I didn't fully understand the intimate connection between
the compiler's choice and the stdargs implementation.  The stdargs
macros can only work if they know how the compiler put the arguments on
the stack. *That* is why the gcc builtin is mandatory, or practically
mandatory, for code compiled with gcc.  

[much agreement and helpful clarification omitted]

> Perhaps a va_list_to_sequential_memory() conversion interface 
> could be provided.  

Thanks, that is an interesting idea.  It wouldn't be hard, and it would
permit compilation of the code I pointed to.  

--jkl


Home | Main Index | Thread Index | Old Index