$(DDOC $(DDOC_BLANKLINE ) $(DDOC_BLANKLINE ) $(SPEC_S Application Binary Interface, $(DDOC_BLANKLINE ) $(HEADERNAV_TOC $(HEADERNAV_ITEM c_abi, C ABI) $(HEADERNAV_ITEM endianness, Endianness) $(HEADERNAV_ITEM basic_types, Basic Types) $(HEADERNAV_ITEM delegates, Delegates) $(HEADERNAV_ITEM structs, Structs) $(HEADERNAV_ITEM classes, Classes) $(HEADERNAV_ITEM interfaces, Interfaces) $(HEADERNAV_ITEM arrays, Arrays) $(HEADERNAV_ITEM associative_arrays, Associative Arrays) $(HEADERNAV_ITEM references_types, Reference Types) $(HEADERNAV_SUBITEMS name_mangling, Name Mangling, $(HEADERNAV_ITEM back_ref, Back references) $(HEADERNAV_ITEM type_mangling, Type Mangling) ) $(HEADERNAV_SUBITEMS function_calling_conventions, Function Calling Conventions, $(HEADERNAV_ITEM register_conventions, Register Conventions) $(HEADERNAV_ITEM return_value, Return Value) $(HEADERNAV_ITEM parameters, Parameters) ) $(HEADERNAV_SUBITEMS exception_handling, Exception Handling, $(HEADERNAV_ITEM windows_eh, Windows 32 bit) $(HEADERNAV_ITEM ninux_fbsd_osx_eh, Linux, FreeBSD and OS X) $(HEADERNAV_ITEM win64_eh, Windows 64 bit) ) $(HEADERNAV_ITEM garbage_collection, Garbage Collection) $(HEADERNAV_SUBITEMS ModuleInfo, ModuleInfo Instance, $(HEADERNAV_ITEM module_init_and_fina, Module Initialization and Termination) $(HEADERNAV_ITEM unit_testing, Unit Testing) ) $(HEADERNAV_ITEM runtime_helper_functions, Runtime Helper Functions) $(HEADERNAV_SUBITEMS symbolic_debugging, Symbolic Debugging, $(HEADERNAV_ITEM codeview, Codeview Debugger Extensions) ) ) $(DDOC_BLANKLINE ) $(P A D implementation that conforms to the D ABI (Application Binary Interface) will be able to generate libraries, DLLs, etc., that can interoperate with D binaries built by other implementations. ) $(DDOC_BLANKLINE )

$(LNAME2 c_abi, C ABI)

$(DDOC_BLANKLINE ) $(P The C ABI referred to in this specification means the C Application Binary Interface of the target system. C and D code should be freely linkable together, in particular, D code shall have access to the entire C ABI runtime library. ) $(DDOC_BLANKLINE )

$(LNAME2 endianness, Endianness)

$(DDOC_BLANKLINE ) $(P The $(LINK2 https://en.wikipedia.org/wiki/Endianness, endianness) (byte order) of the layout of the data will conform to the endianness of the target machine. The Intel x86 CPUs are $(I little endian) meaning that the value 0x0A0B0C0D is stored in memory as: $(D 0D 0C 0B 0A). ) $(DDOC_BLANKLINE )

$(LNAME2 basic_types, Basic Types)

$(DDOC_BLANKLINE ) $(TABLE $(TROW bool, 8 bit byte with the values 0 for false and 1 for true) $(TROW byte, 8 bit signed value) $(TROW ubyte, 8 bit unsigned value) $(TROW short, 16 bit signed value) $(TROW ushort, 16 bit unsigned value) $(TROW int, 32 bit signed value) $(TROW uint, 32 bit unsigned value) $(TROW long, 64 bit signed value) $(TROW ulong, 64 bit unsigned value) $(TROW cent, 128 bit signed value) $(TROW ucent, 128 bit unsigned value) $(TROW float, 32 bit IEEE 754 floating point value) $(TROW double, 64 bit IEEE 754 floating point value) $(TROW real, implementation defined floating point value, for x86 it is 80 bit IEEE 754 extended real) $(TROW char, 8 bit unsigned value) $(TROW wchar, 16 bit unsigned value) $(TROW dchar, 32 bit unsigned value) ) $(DDOC_BLANKLINE )

$(LNAME2 delegates, Delegates)

$(DDOC_BLANKLINE ) $(P Delegates are $(I fat pointers) with two parts:) $(DDOC_BLANKLINE ) $(TABLE2 Delegate Layout, offset, property, contents $(TROW $(D 0), $(D .ptr), context pointer) $(TROW $(I ptrsize), $(D .funcptr), pointer to function) ) $(DDOC_BLANKLINE ) $(P The $(I context pointer) can be a class $(I this) reference, a struct $(I this) pointer, a pointer to a closure (nested functions) or a pointer to an enclosing function's stack frame (nested functions). ) $(DDOC_BLANKLINE )

$(LNAME2 structs, Structs)

$(DDOC_BLANKLINE ) $(P Conforms to the target's C ABI struct layout.) $(DDOC_BLANKLINE )

$(LNAME2 classes, Classes)

$(DDOC_BLANKLINE ) $(P An object consists of:) $(DDOC_BLANKLINE ) $(TABLE_3COLS Class Object Layout, size, property, contents $(TROW $(I ptrsize), $(D .__vptr), pointer to vtable) $(TROW $(I ptrsize), $(D .__monitor), monitor) $(TROW $(I ptrsize)..., $(NBSP ), $(ARGS vptrs for any interfaces implemented by this class in left to right, most to least derived, order)) $(TROW $(D ...), $(D ...), $(ARGS super's non-static fields and super's interface vptrs, from least to most derived)) $(TROW $(D ...), named fields, non-static fields) ) $(DDOC_BLANKLINE ) $(P The vtable consists of:) $(DDOC_BLANKLINE ) $(TABLE2 Virtual Function Pointer Table Layout, size, contents $(TROW $(I ptrsize), pointer to instance of TypeInfo) $(TROW $(I ptrsize)..., pointers to virtual member functions) ) $(DDOC_BLANKLINE ) $(P Casting a class object to an interface consists of adding the offset of the interface's corresponding vptr to the address of the base of the object. Casting an interface ptr back to the class type it came from involves getting the correct offset to subtract from it from the object.Interface entry at vtbl[0]. Adjustor thunks are created and pointers to them stored in the method entries in the vtbl[] in order to set the this pointer to the start of the object instance corresponding to the implementing method. ) $(DDOC_BLANKLINE ) $(P An adjustor thunk looks like:) $(DDOC_BLANKLINE ) $(CCODE ADD EAX,offset JMP method ) $(DDOC_BLANKLINE ) $(P The leftmost side of the inheritance graph of the interfaces all share their vptrs, this is the single inheritance model. Every time the inheritance graph forks (for multiple inheritance) a new vptr is created and stored in the class' instance. Every time a virtual method is overridden, a new vtbl[] must be created with the updated method pointers in it. ) $(DDOC_BLANKLINE ) $(P The class definition:) $(DDOC_BLANKLINE ) $(D_CODE $(D_KEYWORD class) XXXX { .... }; ) $(DDOC_BLANKLINE ) $(P Generates the following:) $(DDOC_BLANKLINE ) $(UL $(LI An instance of Class called ClassXXXX.) $(DDOC_BLANKLINE ) $(LI A type called StaticClassXXXX which defines all the static members.) $(DDOC_BLANKLINE ) $(LI An instance of StaticClassXXXX called StaticXXXX for the static members.) ) $(DDOC_BLANKLINE )

$(LNAME2 interfaces, Interfaces)

$(DDOC_BLANKLINE ) $(P An interface is a pointer to a pointer to a vtbl[]. The vtbl[0] entry is a pointer to the corresponding instance of the object.Interface class. The rest of the $(D vtbl[1..$]) entries are pointers to the virtual functions implemented by that interface, in the order that they were declared. ) $(DDOC_BLANKLINE ) $(P A COM interface differs from a regular interface in that there is no object.Interface entry in $(D vtbl[0]); the entries $(D vtbl[0..$]) are all the virtual function pointers, in the order that they were declared. This matches the COM object layout used by Windows. ) $(P A C++ interface differs from a regular interface in that it matches the layout of a C++ class using single inheritance on the target machine. ) $(DDOC_BLANKLINE )

$(LNAME2 arrays, Arrays)

$(DDOC_BLANKLINE ) $(P A dynamic array consists of:) $(DDOC_BLANKLINE ) $(TABLE2 Dynamic Array Layout, offset, property, contents $(TROW $(D 0), $(D .length), array dimension) $(TROW $(D size_t), $(D .ptr), pointer to array data) ) $(DDOC_BLANKLINE ) $(P A dynamic array is declared as:) $(DDOC_BLANKLINE ) $(D_CODE type[] array; ) $(DDOC_BLANKLINE ) whereas a static array is declared as: $(DDOC_BLANKLINE ) $(D_CODE type[dimension] array; ) $(DDOC_BLANKLINE ) $(P Thus, a static array always has the dimension statically available as part of the type, and so it is implemented like in C. Static arrays and Dynamic arrays can be easily converted back and forth to each other. ) $(DDOC_BLANKLINE )

$(LNAME2 associative_arrays, Associative Arrays)

$(DDOC_BLANKLINE ) $(P Associative arrays consist of a pointer to an opaque, implementation defined type.) $(DDOC_BLANKLINE ) $(P The current implementation is contained in and defined by $(DRUNTIMESRC rt/aaA.d). ) $(DDOC_BLANKLINE )

$(LNAME2 references_types, Reference Types)

$(DDOC_BLANKLINE ) $(P D has reference types, but they are implicit. For example, classes are always referred to by reference; this means that class instances can never reside on the stack or be passed as function parameters. ) $(DDOC_BLANKLINE ) $(DDOC_BLANKLINE )

$(LNAME2 name_mangling, Name Mangling)

$(DDOC_BLANKLINE ) $(P D accomplishes typesafe linking by $(I mangling) a D identifier to include scope and type information. ) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME MangledName): $(B _D) $(GLINK QualifiedName) $(GLINK Type) $(B _D) $(GLINK QualifiedName) $(B Z) $(GREEN // Internal) ) $(DDOC_BLANKLINE ) $(P The $(GLINK Type) above is the type of a variable or the return type of a function. This is never a $(GLINK TypeFunction), as the latter can only be bound to a value via a pointer to a function or a delegate.) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME QualifiedName): $(GLINK SymbolFunctionName) $(GLINK SymbolFunctionName) $(GSELF QualifiedName) $(DDOC_BLANKLINE ) $(GNAME SymbolFunctionName): $(GLINK SymbolName) $(GLINK SymbolName) $(GLINK TypeFunctionNoReturn) $(GLINK SymbolName) $(B M) $(GLINK TypeModifiers)$(OPT ) $(GLINK TypeFunctionNoReturn) ) $(DDOC_BLANKLINE ) $(P The $(B M) means that the symbol is a function that requires a $(D this) pointer. Class or struct fields are mangled without $(B M). To disambiguate $(B M) from being a $(GLINK Parameter) with modifier scope, the following type needs to be checked for being a $(GLINK TypeFunction).) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME SymbolName): $(GLINK LName) $(GLINK TemplateInstanceName) $(GLINK IdentifierBackRef) $(B 0) $(GREEN // anonymous symbols) ) $(DDOC_BLANKLINE ) $(P Template Instance Names have the types and values of its parameters encoded into it: ) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME TemplateInstanceName): $(GLINK TemplateID) $(GLINK LName) $(GLINK TemplateArgs) $(B Z) $(DDOC_BLANKLINE ) $(GNAME TemplateID): $(B __T) $(B __U) $(GREEN // for symbols declared inside template constraint) $(DDOC_BLANKLINE ) $(GNAME TemplateArgs): $(GLINK TemplateArg) $(GLINK TemplateArg) $(GSELF TemplateArgs) $(DDOC_BLANKLINE ) $(GNAME TemplateArg): $(GLINK TemplateArgX) $(B H) $(GLINK TemplateArgX) ) $(DDOC_BLANKLINE ) $(P If a template argument matches a specialized template parameter, the argument is mangled with prefix $(B H).) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME TemplateArgX): $(B T) $(GLINK Type) $(B V) $(GLINK Type) $(GLINK Value) $(B S) $(GLINK QualifiedName) $(B X) $(GLINK Number) $(I ExternallyMangledName) ) $(DDOC_BLANKLINE ) $(P $(I ExternallyMangledName) can be any series of characters allowed on the current platform, e.g. generated by functions with C++ linkage or annotated with pragma(mangle,...).) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME Values): $(GLINK Value) $(GLINK Value) $(GSELF Values) $(DDOC_BLANKLINE ) $(GNAME Value): $(B n) $(B i) $(GLINK Number) $(B N) $(GLINK Number) $(B e) $(GLINK HexFloat) $(B c) $(GLINK HexFloat) $(B c) $(GLINK HexFloat) $(GLINK CharWidth) $(GLINK Number) $(B _) $(GLINK HexDigits) $(B A) $(GLINK Number) $(GLINK Values) $(B S) $(GLINK Number) $(GLINK Values) $(B f) $(GLINK MangledName) $(DDOC_BLANKLINE ) $(GNAME HexFloat): $(B NAN) $(B INF) $(B NINF) $(B N) $(GLINK HexDigits) $(B P) $(GLINK Exponent) $(GLINK HexDigits) $(B P) $(GLINK Exponent) $(DDOC_BLANKLINE ) $(GNAME Exponent): $(B N) $(GLINK Number) $(GLINK Number) $(DDOC_BLANKLINE ) $(GNAME HexDigits): $(GLINK HexDigit) $(GLINK HexDigit) $(GLINK HexDigits) $(DDOC_BLANKLINE ) $(GNAME HexDigit): $(GLINK Digit) $(B A) $(B B) $(B C) $(B D) $(B E) $(B F) $(DDOC_BLANKLINE ) $(GNAME CharWidth): $(B a) $(B w) $(B d) ) $(DDOC_BLANKLINE ) $(DL $(DT $(B n)) $(DD is for $(B null) arguments.) $(DDOC_BLANKLINE ) $(DT $(B i) $(GLINK Number)) $(DD is for positive numeric literals (including character literals).) $(DDOC_BLANKLINE ) $(DT $(B N) $(GLINK Number)) $(DD is for negative numeric literals.) $(DDOC_BLANKLINE ) $(DT $(B e) $(GLINK HexFloat)) $(DD is for real and imaginary floating point literals.) $(DDOC_BLANKLINE ) $(DT $(B c) $(GLINK HexFloat) $(B c) $(GLINK HexFloat)) $(DD is for complex floating point literals.) $(DDOC_BLANKLINE ) $(DT $(GLINK CharWidth) $(GLINK Number) $(D _) $(GLINK HexDigits)) $(DD $(GLINK CharWidth) is whether the characters are 1 byte ($(B a)), 2 bytes ($(B w)) or 4 bytes ($(B d)) in size. $(GLINK Number) is the number of characters in the string. The $(GLINK HexDigits) are the hex data for the string. ) $(DDOC_BLANKLINE ) $(DT $(B A) $(GLINK Number) $(GLINK Values)) $(DD An array or asssociative array literal. $(GLINK Number) is the length of the array. $(GLINK Value) is repeated $(GLINK Number) times for a normal array, and 2 * $(GLINK Number) times for an associative array. ) $(DDOC_BLANKLINE ) $(DT $(B S) $(GLINK Number) $(GLINK Values)) $(DD A struct literal. $(GLINK Value) is repeated $(GLINK Number) times. ) ) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME Name): $(GLINK Namestart) $(GLINK Namestart) $(GLINK Namechars) $(DDOC_BLANKLINE ) $(GNAME Namestart): $(B _) $(I Alpha) $(DDOC_BLANKLINE ) $(GNAME Namechar): $(GLINK Namestart) $(GLINK Digit) $(DDOC_BLANKLINE ) $(GNAME Namechars): $(GLINK Namechar) $(GLINK Namechar) $(GSELF Namechars) ) $(DDOC_BLANKLINE ) $(P A $(GLINK Name) is a standard D $(DDSUBLINK spec/lex, identifiers, identifier).) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME LName): $(GLINK Number) $(GLINK Name) $(GLINK Number) $(B __S) $(GLINK Number) $(GREEN // function-local parent symbols) $(DDOC_BLANKLINE ) $(GNAME Number): $(GLINK Digit) $(GLINK Digit) $(GSELF Number) $(DDOC_BLANKLINE ) $(GNAME Digit): $(B 0) $(B 1) $(B 2) $(B 3) $(B 4) $(B 5) $(B 6) $(B 7) $(B 8) $(B 9) ) $(DDOC_BLANKLINE ) $(P An $(GLINK LName) is a name preceded by a $(GLINK Number) giving the number of characters in the $(GLINK Name). ) $(DDOC_BLANKLINE )

$(LNAME2 back_ref, Back references)

$(DDOC_BLANKLINE ) $(P Any $(GLINK LName) or non-basic $(GLINK Type) (i.e. any type that does not encode as a fixed one or two character sequence) that has been emitted to the mangled symbol before will not be emitted again, but is referenced by a special sequence encoding the relative position of the original occurrence in the mangled symbol name.) $(DDOC_BLANKLINE ) $(P Numbers in back references are encoded with base 26 by upper case letters $(B A) - $(B Z) for higher digits but lower case letters $(B a) - $(B z) for the last digit.) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME TypeBackRef): $(B Q) $(GLINK NumberBackRef) $(DDOC_BLANKLINE ) $(GNAME IdentifierBackRef): $(B Q) $(GLINK NumberBackRef) $(DDOC_BLANKLINE ) $(GNAME NumberBackRef): $(I lower-case-letter) $(I upper-case-letter) $(GLINK NumberBackRef) ) $(DDOC_BLANKLINE ) $(P To distinguish between the type of the back reference a look-up of the back referenced character is necessary: An identifier back reference always points to a digit $(B 0) to $(B 9), while a type back reference always points to a letter.) $(DDOC_BLANKLINE )

$(LNAME2 type_mangling, Type Mangling)

$(DDOC_BLANKLINE ) $(P Types are mangled using a simple linear scheme:) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME Type): $(GLINK TypeModifiers)$(OPT ) $(GLINK TypeX) $(GLINK TypeBackRef) $(DDOC_BLANKLINE ) $(GNAME TypeX): $(GLINK TypeArray) $(GLINK TypeStaticArray) $(GLINK TypeAssocArray) $(GLINK TypePointer) $(GLINK TypeFunction) $(GLINK TypeIdent) $(GLINK TypeClass) $(GLINK TypeStruct) $(GLINK TypeEnum) $(GLINK TypeTypedef) $(GLINK TypeDelegate) $(GLINK TypeVoid) $(GLINK TypeByte) $(GLINK TypeUbyte) $(GLINK TypeShort) $(GLINK TypeUshort) $(GLINK TypeInt) $(GLINK TypeUint) $(GLINK TypeLong) $(GLINK TypeUlong) $(GLINK TypeCent) $(GLINK TypeUcent) $(GLINK TypeFloat) $(GLINK TypeDouble) $(GLINK TypeReal) $(GLINK TypeIfloat) $(GLINK TypeIdouble) $(GLINK TypeIreal) $(GLINK TypeCfloat) $(GLINK TypeCdouble) $(GLINK TypeCreal) $(GLINK TypeBool) $(GLINK TypeChar) $(GLINK TypeWchar) $(GLINK TypeDchar) $(GLINK TypeNoreturn) $(GLINK TypeNull) $(GLINK TypeTuple) $(GLINK TypeVector) $(DDOC_BLANKLINE ) $(GNAME TypeModifiers): $(GLINK Const) $(GLINK Wild) $(GLINK Wild) $(GLINK Const) $(GLINK Shared) $(GLINK Shared) $(GLINK Const) $(GLINK Shared) $(GLINK Wild) $(GLINK Shared) $(GLINK Wild) $(GLINK Const) $(GLINK Immutable) $(DDOC_BLANKLINE ) $(GNAME Shared): $(B O) $(DDOC_BLANKLINE ) $(GNAME Const): $(B x) $(DDOC_BLANKLINE ) $(GNAME Immutable): $(B y) $(DDOC_BLANKLINE ) $(GNAME Wild): $(B Ng) $(DDOC_BLANKLINE ) $(GNAME TypeArray): $(B A) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypeStaticArray): $(B G) $(GLINK Number) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypeAssocArray): $(B H) $(GLINK Type) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypePointer): $(B P) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypeVector): $(B Nh) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypeFunction): $(GLINK TypeFunctionNoReturn) $(GLINK Type) $(DDOC_BLANKLINE ) $(GNAME TypeFunctionNoReturn): $(GLINK CallConvention) $(GLINK FuncAttrs)$(OPT ) $(GLINK Parameters)$(OPT ) $(GLINK ParamClose) $(DDOC_BLANKLINE ) $(GNAME CallConvention): $(B F) $(GREEN // D) $(B U) $(GREEN // C) $(B W) $(GREEN // Windows) $(B R) $(GREEN // C++) $(B Y) $(GREEN // Objective-C) $(DDOC_BLANKLINE ) $(GNAME FuncAttrs): $(GLINK FuncAttr) $(GLINK FuncAttr) $(GSELF FuncAttrs) $(DDOC_BLANKLINE ) $(GNAME FuncAttr): $(GLINK FuncAttrPure) $(GLINK FuncAttrNothrow) $(GLINK FuncAttrRef) $(GLINK FuncAttrProperty) $(GLINK FuncAttrNogc) $(GLINK FuncAttrReturn) $(GLINK FuncAttrScope) $(GLINK FuncAttrTrusted) $(GLINK FuncAttrSafe) $(GLINK FuncAttrLive) ) $(DDOC_BLANKLINE ) $(P Function attributes are emitted in the order as listed above, with the exception of return and scope. return comes before scope when this is a $(DDSUBLINK spec/function, return-scope-parameters, return scope) parameter, and after scope when this is a $(DDSUBLINK spec/function, scope-parameters, scope) and $(DDSUBLINK spec/function, return-ref-parameters, return ref) parameter. ) $(DDOC_BLANKLINE ) $(GRAMMAR $(GNAME FuncAttrPure): $(B Na) $(DDOC_BLANKLINE ) $(GNAME FuncAttrNogc): $(B Ni) $(DDOC_BLANKLINE ) $(GNAME FuncAttrNothrow): $(B Nb) $(DDOC_BLANKLINE ) $(GNAME FuncAttrProperty): $(B Nd) $(DDOC_BLANKLINE ) $(GNAME FuncAttrRef): $(B Nc) $(DDOC_BLANKLINE ) $(GNAME FuncAttrReturn): $(B Nj) $(DDOC_BLANKLINE ) $(GNAME FuncAttrScope): $(B Nl) $(DDOC_BLANKLINE ) $(GNAME FuncAttrTrusted): $(B Ne) $(DDOC_BLANKLINE ) $(GNAME FuncAttrSafe): $(B Nf) $(DDOC_BLANKLINE ) $(GNAME FuncAttrLive): $(B Nm) $(DDOC_BLANKLINE ) $(GNAME Parameters): $(GLINK Parameter) $(GLINK Parameter) $(GSELF Parameters) $(DDOC_BLANKLINE ) $(GNAME Parameter): $(GLINK Parameter2) $(B M) $(GLINK Parameter2) $(GREEN // scope) $(B Nk) $(GLINK Parameter2) $(GREEN // return) $(DDOC_BLANKLINE ) $(GNAME Parameter2): $(GLINK Type) $(B I) $(GLINK Type) $(GREEN // in) $(B J) $(GLINK Type) $(GREEN // out) $(B K) $(GLINK Type) $(GREEN // ref) $(B L) $(GLINK Type) $(GREEN // lazy) $(DDOC_BLANKLINE ) $(GNAME ParamClose): $(B X) $(GREEN // variadic T t...$(RPAREN ) style) $(B Y) $(GREEN // variadic T t,...$(RPAREN ) style) $(B Z) $(GREEN // not variadic) $(DDOC_BLANKLINE ) $(GNAME TypeIdent): $(B I) $(GLINK QualifiedName) $(DDOC_BLANKLINE ) $(GNAME TypeClass): $(B C) $(GLINK QualifiedName) $(DDOC_BLANKLINE ) $(GNAME TypeStruct): $(B S) $(GLINK QualifiedName) $(DDOC_BLANKLINE ) $(GNAME TypeEnum): $(B E) $(GLINK QualifiedName) $(DDOC_BLANKLINE ) $(GNAME TypeTypedef): $(B T) $(GLINK QualifiedName) $(DDOC_BLANKLINE ) $(GNAME TypeDelegate): $(B D) $(GLINK TypeModifiers)$(OPT ) $(GLINK TypeFunction) $(DDOC_BLANKLINE ) $(GNAME TypeVoid): $(B v) $(DDOC_BLANKLINE ) $(GNAME TypeByte): $(B g) $(DDOC_BLANKLINE ) $(GNAME TypeUbyte): $(B h) $(DDOC_BLANKLINE ) $(GNAME TypeShort): $(B s) $(DDOC_BLANKLINE ) $(GNAME TypeUshort): $(B t) $(DDOC_BLANKLINE ) $(GNAME TypeInt): $(B i) $(DDOC_BLANKLINE ) $(GNAME TypeUint): $(B k) $(DDOC_BLANKLINE ) $(GNAME TypeLong): $(B l) $(DDOC_BLANKLINE ) $(GNAME TypeUlong): $(B m) $(DDOC_BLANKLINE ) $(GNAME TypeCent): $(B zi) $(DDOC_BLANKLINE ) $(GNAME TypeUcent): $(B zk) $(DDOC_BLANKLINE ) $(GNAME TypeFloat): $(B f) $(DDOC_BLANKLINE ) $(GNAME TypeDouble): $(B d) $(DDOC_BLANKLINE ) $(GNAME TypeReal): $(B e) $(DDOC_BLANKLINE ) $(GNAME TypeIfloat): $(B o) $(DDOC_BLANKLINE ) $(GNAME TypeIdouble): $(B p) $(DDOC_BLANKLINE ) $(GNAME TypeIreal): $(B j) $(DDOC_BLANKLINE ) $(GNAME TypeCfloat): $(B q) $(DDOC_BLANKLINE ) $(GNAME TypeCdouble): $(B r) $(DDOC_BLANKLINE ) $(GNAME TypeCreal): $(B c) $(DDOC_BLANKLINE ) $(GNAME TypeBool): $(B b) $(DDOC_BLANKLINE ) $(GNAME TypeChar): $(B a) $(DDOC_BLANKLINE ) $(GNAME TypeWchar): $(B u) $(DDOC_BLANKLINE ) $(GNAME TypeDchar): $(B w) $(DDOC_BLANKLINE ) $(GNAME TypeNoreturn): $(B Nn) $(DDOC_BLANKLINE ) $(GNAME TypeNull): $(B n) $(DDOC_BLANKLINE ) $(GNAME TypeTuple): $(B B) $(GLINK Parameters) $(B Z) ) $(DDOC_BLANKLINE )

$(LNAME2 function_calling_conventions, Function Calling Conventions)

$(DDOC_BLANKLINE ) $(P The $(D extern (C)) and $(D extern (D)) calling convention matches the C calling convention used by the supported C compiler on the host system. Except that the extern (D) calling convention for Windows x86 is described here. ) $(DDOC_BLANKLINE )

$(LNAME2 register_conventions, Register Conventions)

$(DDOC_BLANKLINE ) $(UL $(DDOC_BLANKLINE ) $(LI EAX, ECX, EDX are scratch registers and can be destroyed by a function.) $(DDOC_BLANKLINE ) $(LI EBX, ESI, EDI, EBP must be preserved across function calls.) $(DDOC_BLANKLINE ) $(LI EFLAGS is assumed destroyed across function calls, except for the direction flag which must be forward.) $(DDOC_BLANKLINE ) $(LI The FPU stack must be empty when calling a function.) $(DDOC_BLANKLINE ) $(LI The FPU control word must be preserved across function calls.) $(DDOC_BLANKLINE ) $(LI Floating point return values are returned on the FPU stack. These must be cleaned off by the caller, even if they are not used.) $(DDOC_BLANKLINE ) ) $(DDOC_BLANKLINE )

$(LNAME2 return_value, Return Value)

$(DDOC_BLANKLINE ) $(UL $(DDOC_BLANKLINE ) $(LI The types bool, byte, ubyte, short, ushort, int, uint, pointer, Object, and interfaces are returned in EAX.) $(DDOC_BLANKLINE ) $(LI long and ulong are returned in EDX,EAX, where EDX gets the most significant half.) $(DDOC_BLANKLINE ) $(LI float, double, real, ifloat, idouble, ireal are returned in ST0.) $(DDOC_BLANKLINE ) $(LI cfloat, cdouble, creal are returned in ST1,ST0 where ST1 is the real part and ST0 is the imaginary part.) $(DDOC_BLANKLINE ) $(LI Dynamic arrays are returned with the pointer in EDX and the length in EAX.) $(DDOC_BLANKLINE ) $(LI Associative arrays are returned in EAX.) $(DDOC_BLANKLINE ) $(LI References are returned as pointers in EAX.) $(DDOC_BLANKLINE ) $(LI Delegates are returned with the pointer to the function in EDX and the context pointer in EAX.) $(DDOC_BLANKLINE ) $(LI 1, 2 and 4 byte structs and static arrays are returned in EAX.) $(DDOC_BLANKLINE ) $(LI 8 byte structs and static arrays are returned in EDX,EAX, where EDX gets the most significant half.) $(DDOC_BLANKLINE ) $(LI For other sized structs and static arrays, the return value is stored through a hidden pointer passed as an argument to the function.) $(DDOC_BLANKLINE ) $(LI Constructors return the this pointer in EAX.) $(DDOC_BLANKLINE ) ) $(DDOC_BLANKLINE )

$(LNAME2 parameters, Parameters)

$(DDOC_BLANKLINE ) $(P The parameters to the non-variadic function:) $(DDOC_BLANKLINE ) $(D_CODE foo(a1, a2, ..., an); ) $(DDOC_BLANKLINE ) are passed as follows: $(DDOC_BLANKLINE ) $(TABLE $(TR $(TD a1)) $(TR $(TD a2)) $(TR $(TD ...)) $(TR $(TD an)) $(TR $(TD hidden)) $(TR $(TD this)) ) $(DDOC_BLANKLINE ) $(P where $(I hidden) is present if needed to return a struct value, and $(I this) is present if needed as the this pointer for a member function or the context pointer for a nested function.) $(DDOC_BLANKLINE ) $(P The last parameter is passed in EAX rather than being pushed on the stack if the following conditions are met:) $(DDOC_BLANKLINE ) $(UL $(LI It fits in EAX.) $(LI It is not a 3 byte struct.) $(LI It is not a floating point type.) ) $(DDOC_BLANKLINE ) $(P Parameters are always pushed as multiples of 4 bytes, rounding upwards, so the stack is always aligned on 4 byte boundaries. They are pushed most significant first. $(B out) and $(B ref) are passed as pointers. Static arrays are passed as pointers to their first element. On Windows, a real is pushed as a 10 byte quantity, a creal is pushed as a 20 byte quantity. On Linux, a real is pushed as a 12 byte quantity, a creal is pushed as two 12 byte quantities. The extra two bytes of pad occupy the $(SINGLEQUOTE most significant) position. ) $(DDOC_BLANKLINE ) $(P The callee cleans the stack.) $(DDOC_BLANKLINE ) $(P The parameters to the variadic function:) $(DDOC_BLANKLINE ) $(D_CODE $(D_KEYWORD void) foo($(D_KEYWORD int) p1, $(D_KEYWORD int) p2, $(D_KEYWORD int)[] p3...) foo(a1, a2, ..., an); ) $(DDOC_BLANKLINE ) are passed as follows: $(DDOC_BLANKLINE ) $(TABLE $(TR $(TD p1)) $(TR $(TD p2)) $(TR $(TD a3)) $(TR $(TD hidden)) $(TR $(TD this)) ) $(DDOC_BLANKLINE ) $(P The variadic part is converted to a dynamic array and the rest is the same as for non-variadic functions.) $(DDOC_BLANKLINE ) $(P The parameters to the variadic function:) $(DDOC_BLANKLINE ) $(D_CODE $(D_KEYWORD void) foo($(D_KEYWORD int) p1, $(D_KEYWORD int) p2, ...) foo(a1, a2, a3, ..., an); ) $(DDOC_BLANKLINE ) are passed as follows: $(DDOC_BLANKLINE ) $(TABLE $(TR $(TD an)) $(TR $(TD ...)) $(TR $(TD a3)) $(TR $(TD a2)) $(TR $(TD a1)) $(TR $(TD $(D _)arguments)) $(TR $(TD hidden)) $(TR $(TD this)) ) $(DDOC_BLANKLINE ) $(P The caller is expected to clean the stack. $(D _argptr) is not passed, it is computed by the callee.) $(DDOC_BLANKLINE )

$(LNAME2 exception_handling, Exception Handling)

$(DDOC_BLANKLINE )

$(LNAME2 windows_eh, Windows 32 bit)

$(DDOC_BLANKLINE ) $(P Conforms to the Microsoft Windows Structured Exception Handling conventions. ) $(DDOC_BLANKLINE )

$(LNAME2 ninux_fbsd_osx_eh, Linux, FreeBSD and OS X)

$(DDOC_BLANKLINE ) $(P Conforms to the DWARF $(LPAREN)debugging with attributed record formats$(RPAREN ) Exception Handling conventions. ) $(DDOC_BLANKLINE )

$(LNAME2 win64_eh, Windows 64 bit)

$(DDOC_BLANKLINE ) $(P Uses static address range/handler tables. It is not compatible with the MSVC x64 exception handling tables. The stack is walked assuming it uses the EBP/RBP stack frame convention. The EBP/RBP convention must be used for every function that has an associated EH (Exception Handler) table. ) $(DDOC_BLANKLINE ) $(P For each function that has exception handlers, an EH table entry is generated. ) $(DDOC_BLANKLINE ) $(TABLE2 EH Table Entry, field, description $(TROW $(D void*), pointer to start of function) $(TROW $(D DHandlerTable*), pointer to corresponding EH data) $(TROW $(D uint), size in bytes of the function) ) $(DDOC_BLANKLINE ) $(P The EH table entries are placed into the following special segments, which are concatenated by the linker. ) $(DDOC_BLANKLINE ) $(TABLE2 EH Table Segment, Operating System, Segment Name $(TROW Win32, $(D FI)) $(TROW Win64, $(D ._deh$B)) $(TROW Linux, $(D .deh_eh)) $(TROW FreeBSD, $(D .deh_eh)) $(TROW OS X, $(ARGS $(D __deh_eh), $(D __DATA))) ) $(BR ) $(DDOC_BLANKLINE ) $(P The rest of the EH data can be placed anywhere, it is immutable.) $(DDOC_BLANKLINE ) $(TABLE2 DHandlerTable, field, description $(TROW $(D void*), pointer to start of function) $(TROW $(D uint), offset of ESP/RSP from EBP/RBP) $(TROW $(D uint), offset from start of function to return code) $(TROW $(D uint), number of entries in $(D DHandlerInfo[])) $(TROW $(D DHandlerInfo[]), array of handler information) ) $(BR ) $(DDOC_BLANKLINE ) $(TABLE2 DHandlerInfo, field, description $(TROW $(D uint), offset from function address to start of guarded section) $(TROW $(D uint), offset of end of guarded section) $(TROW $(D int), previous table index) $(TROW $(D uint), if != 0 offset to DCatchInfo data from start of table) $(TROW $(D void*), $(ARGS if not null, pointer to finally code to execute)) ) $(BR ) $(DDOC_BLANKLINE ) $(TABLE2 DCatchInfo, field, description $(TROW $(D uint), number of entries in $(D DCatchBlock[])) $(TROW $(D DCatchBlock[]), array of catch information) ) $(BR ) $(DDOC_BLANKLINE ) $(TABLE2 DCatchBlock, field, description $(TROW $(D ClassInfo), catch type) $(TROW $(D uint), offset from EBP/RBP to catch variable) $(TR $(D void*), catch handler code) ) $(DDOC_BLANKLINE )

$(LNAME2 garbage_collection, Garbage Collection)

$(DDOC_BLANKLINE ) $(P The interface to this is found in Druntime's $(DRUNTIMESRC core/gc/gcinterface.d).) $(DDOC_BLANKLINE )

$(LNAME2 ModuleInfo, ModuleInfo Instance)

$(DDOC_BLANKLINE ) $(P An instance of $(LINK2 https://dlang.org/phobos/object.html#.ModuleInfo, ModuleInfo) is generated by the compiler and inserted into the object file for every module. ModuleInfo contains information about the module that is useful to the D runtime library: ) $(DDOC_BLANKLINE ) $(UL $(LI If the module has a static constructor, static destructor, shared static constructor, or shared static destructor.) $(LI A reference to any unit tests defined by the module.) $(LI An array of references to any imported modules that have one or more of: $(OL $(LI static constructors) $(LI static destructors) $(LI shared static constructors) $(LI shared static destructors) $(LI unit tests) $(LI transitive imports of any module that contains one or more of 1..5) $(LI order independent constructors (currently needed for implementing $(DDSUBLINK dmd, switch-cov, $(TT -cov)))) ) This enables the runtime to run the unit tests, the module constructors in a depth-first order, and the module destructors in the reverse order. ) $(DDOC_BLANKLINE ) $(LI An array of references to ClassInfo for each class defined in the module. $(NOTE this feature may be removed.)) ) $(DDOC_BLANKLINE ) $(P ModuleInfo is defined in Druntime's $(DRUNTIMESRC object.d), which must match the compiler's output in both the values of flags and layout of fields.) $(DDOC_BLANKLINE ) $(P Modules compiled with $(DDSUBLINK dmd, switch-betterC, $(TT -betterC)) do not have a ModuleInfo instance generated, because such modules must work without the D runtime library. Similarly, $(DDLINK spec/importc, ImportC, ImportC) modules do not generate a ModuleInfo. ) $(DDOC_BLANKLINE )

$(LNAME2 module_init_and_fina, Module Initialization and Termination)

$(DDOC_BLANKLINE ) $(P All the static constructors for a module are aggregated into a single function, and a pointer to that function is inserted into the ctor member of the ModuleInfo instance for that module. ) $(DDOC_BLANKLINE ) $(P All the static destructors for a module are aggregated into a single function, and a pointer to that function is inserted into the dtor member of the ModuleInfo instance for that module. ) $(DDOC_BLANKLINE )

$(LNAME2 unit_testing, Unit Testing)

$(DDOC_BLANKLINE ) $(P All the unit tests for a module are aggregated into a single function, and a pointer to that function is inserted into the unitTest member of the ModuleInfo instance for that module. ) $(DDOC_BLANKLINE )

$(LNAME2 runtime_helper_functions, Runtime Helper Functions)

$(DDOC_BLANKLINE ) $(P These are found in Druntime's $(DRUNTIMESRC rt/).) $(DDOC_BLANKLINE )

$(LNAME2 symbolic_debugging, Symbolic Debugging)

$(DDOC_BLANKLINE ) $(P D has types that are not represented in existing C or C++ debuggers. These are dynamic arrays, associative arrays, and delegates. Representing these types as structs causes problems because function calling conventions for structs are often different than that for these types, which causes C/C++ debuggers to misrepresent things. For these debuggers, they are represented as a C type which does match the calling conventions for the type. ) $(DDOC_BLANKLINE ) $(TABLE2 Types for C Debuggers, D type, C representation $(TROW dynamic array, $(D unsigned long long)) $(TROW associative array, $(D void*)) $(TROW delegate, $(D long long)) $(TROW $(D dchar), $(D unsigned long)) ) $(DDOC_BLANKLINE ) $(P For debuggers that can be modified to accept new types, the following extensions help them fully support the types. ) $(DDOC_BLANKLINE )

$(LNAME2 codeview, Codeview Debugger Extensions)

$(DDOC_BLANKLINE ) $(P The D $(B dchar) type is represented by the special primitive type 0x78.) $(DDOC_BLANKLINE ) $(P D makes use of the Codeview OEM generic type record indicated by $(D LF_OEM) (0x0015). The format is:) $(DDOC_BLANKLINE ) $(TABLE2 Codeview OEM Extensions for D, $(TROW field size, 2, 2, 2, 2, 2, 2) D Type, Leaf Index, OEM Identifier, recOEM, num indices, type index, type index $(TROW dynamic array, $(D LF_OEM), $(I OEM), 1, 2, @$(I index), @$(I element)) $(TROW associative array, $(D LF_OEM), $(I OEM), 2, 2, @$(I key), @$(I element)) $(TROW delegate, $(D LF_OEM), $(I OEM), 3, 2, @$(I this), @$(I function))) $(DDOC_BLANKLINE ) where: $(DDOC_BLANKLINE ) $(TABLE_2COLS , $(TROW $(ARGS $(I OEM)), $(ARGS 0x42)) $(TROW $(ARGS $(I index)), $(ARGS type index of array index)) $(TROW $(ARGS $(I key)), $(ARGS type index of key)) $(TROW $(ARGS $(I element)), $(ARGS type index of array element)) $(TROW $(I this), $(ARGS type index of context pointer)) $(TROW $(I function), $(ARGS type index of function))) $(DDOC_BLANKLINE ) $(P These extensions can be pretty-printed by $(LINK2 http://www.digitalmars.com/ctg/obj2asm.html, obj2asm). The $(LINK2 http://ddbg.mainia.de/releases.html, Ddbg) debugger supports them.) $(SPEC_SUBNAV_PREV_NEXT memory-safe-d, Memory Safety, simd, Vector Extensions) ) )