Accessing non-existing varargs argument

Andrew Haley aph@redhat.com
Fri Dec 12 11:57:00 GMT 2014


On 12/12/2014 11:51 AM, Florian Weimer wrote:
> On 12/12/2014 12:30 PM, Andrew Haley wrote:
>> On 12/12/2014 10:20 AM, Florian Weimer wrote:
>>> open is declared as:
>>>
>>>     int open(const char *pathname, int flags, ...);
>>>
>>> The intent is to have two overloaded variants:
>>>
>>>     int open(const char *pathname, int flags);
>>>     int open(const char *pathname, int flags, mode_t mode);
>>>
>>> The presence of the mode argument depends on the flags specified.  The
>>> set of such flags is known by the kernel.  I wish to avoid to maintain
>>> this implementation detail in libc as well, so I want to always read the
>>> mode argument, possibly passing a garbage value to the kernel.
>>>
>>> Is there GCC-portable way to achieve this?
>>
>> You're assuming that for all targets the varargs calling convention is
>> the same as the non-varargs calling convention, at least for integer
>> registers.  I don't think this is true for all targets, although it
>> might be true for the targets GCC supports today.
> 
> No, I would be perfectly satisfied with calling va_arg unconditionally 
> to read a garbage argument if that can be made GCC-portable in some way. 
>   The implementation can still be vararg.

Hmmm.  That's probably possible today, but I don't think you can say
anything about future calling conventions.  I'd have to ask why this is
so important.

> (And I think we had a related conversation about this in the context of 
> the ppc64le bring-up, with the result that we practically need matching 
> calling conventions. :-/)

Yes.

Andrew.




More information about the Gcc-help mailing list