Bug 1066 – Variadic arguments being passed in registers
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-03-16T20:02:00Z
Last change time
2015-06-09T05:15:20Z
Keywords
spec
Assigned to
ibuclaw
Creator
madou
Comments
Comment #0 by madou — 2007-03-16T20:02:19Z
On several architectures, optional arguments to variadic functions get passed in registers, just like regular arguments. This prevents the use of _argptr, among others. In our opinion (my own and that of several Tango library developers), even if the platform ABI dictates the use of registers for variadic arguments, this approach should only ever be taken for extern (C) functions. D functions are better off using stack-borne varargs, for the reason mentioned above, and also since register based varargs incur a heavy performance penalty due to most platforms' inability to dynamically index their register files.
Comment #1 by fvbommel — 2007-03-18T17:41:14Z
I just found out that gphobos also suffers because of this.
std/format.d, line 897+:
---
else version(X86_64)
{
throw new FormatError("cannot portably format a struct on this target");
}
---
This seems to be because it can't obtain a pointer to the struct to pass to TypeInfo_Struct.xtoString(void*)...
This _really_ needs to be fixed. Neither of gphobos and tango can fully support their respective formatted text output facilities on amd64 (and any similar platforms, presumably) because of this.
(workaround for gphobos: explicitly calling .toString on arguments)
Comment #2 by ibuclaw — 2011-01-31T09:33:28Z
The spec does not dictate that variadic functions must be passed on the stack. This does not prevent the use of _argptr, to protect against the vagaries of stack layouts on different CPU architectures, use std.stdarg (or core.vararg on D2) to access the variadic arguments.
Regards