forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abi.dd
989 lines (761 loc) · 23.6 KB
/
abi.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
Ddoc
$(SPEC_S Application Binary Interface,
$(P A D implementation that conforms to the D ABI (Application Binary
Interface)
will be able to generate libraries, DLL's, etc., that can interoperate
with
D binaries built by other implementations.
)
$(SECTION3 C ABI,
$(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.
)
)
$(SECTION3 Endianness,
$(P The $(LINK2 http://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).
)
)
$(SECTION3 Basic Types,
$(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$(COMMA) for x86 it is
80 bit IEEE 754 extended real)
)
)
$(SECTION3 Delegates,
$(P Delegates are $(I fat pointers) with two parts:)
$(TABLE2 Delegate Layout,
$(THEAD offset, property, contents)
$(TROW $(D 0), $(D .ptr), context pointer)
$(TROW $(I ptrsize), $(D .funcptr), pointer to function)
)
$(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).
)
)
$(SECTION3 Structs,
$(P Conforms to the target's C ABI struct layout.)
)
$(SECTION3 Classes,
$(P An object consists of:)
$(TABLE_3COLS Class Object Layout,
$(THEAD size, property, contents)
$(TROW $(I ptrsize), $(D .__vptr), pointer to vtable)
$(TROW $(I ptrsize), $(D .__monitor), monitor)
$(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)
$(TROW $(I ptrsize)..., $(NBSP), $(ARGS vptr's for any interfaces implemented by this class in left to right, most to least derived, order))
)
$(P The vtable consists of:)
$(TABLE2 Virtual Function Pointer Table Layout,
$(THEAD size, contents)
$(TROW $(I ptrsize), pointer to instance of TypeInfo)
$(TROW $(I ptrsize)..., pointers to virtual member functions)
)
$(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.
)
$(P An adjustor thunk looks like:)
$(CCODE
ADD EAX,offset
JMP method
)
$(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.
)
$(P The class definition:)
---------
class XXXX
{
....
};
---------
$(P Generates the following:)
$(UL
$(LI An instance of Class called ClassXXXX.)
$(LI A type called StaticClassXXXX which defines all the static members.)
$(LI An instance of StaticClassXXXX called StaticXXXX for the static members.)
)
)
$(SECTION3 Interfaces,
$(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.
)
$(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.
)
)
$(SECTION3 Arrays,
$(P A dynamic array consists of:)
$(TABLE2 Dynamic Array Layout,
$(THEAD offset, property, contents)
$(TROW $(D 0), $(D .length), array dimension)
$(TROW $(D size_t), $(D .ptr), pointer to array data)
)
$(P A dynamic array is declared as:)
---------
type[] array;
---------
$(P whereas a static array is declared as:)
---------
type[dimension] array;
---------
$(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 array's and Dynamic arrays can be easily converted back
and forth to each other.
)
)
$(SECTION3 Associative Arrays,
$(P Associative arrays consist of a pointer to an opaque, implementation
defined type.
The current implementation is contained in and defined by
$(DRUNTIMESRC rt/aaA.d).
)
)
$(SECTION3 Reference Types,
$(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.
)
)
$(SECTION3 Name Mangling,
$(P D accomplishes typesafe linking by $(I mangling) a D identifier
to include scope and type information.
)
$(GRAMMAR
$(GNAME MangledName):
$(B _D) $(GLINK QualifiedName) $(GLINK Type)
$(B _D) $(GLINK QualifiedName) $(B M) $(GLINK Type)
$(GNAME QualifiedName):
$(GLINK SymbolName)
$(GLINK SymbolName) $(I QualifiedName)
$(GNAME SymbolName):
$(GLINK LName)
$(GLINK TemplateInstanceName)
)
$(P The $(B M) means that the symbol is a function that requires
a $(D this) pointer.)
$(P Template Instance Names have the types and values of its parameters
encoded into it:
)
$(GRAMMAR
$(GNAME TemplateInstanceName):
$(GLINK Number) $(B __T) $(GLINK LName) $(GLINK TemplateArgs) $(B Z)
$(GNAME TemplateArgs):
$(GLINK TemplateArg)
$(GLINK TemplateArg) $(I TemplateArgs)
$(GNAME TemplateArg):
$(GLINK TemplateArgX)
$(B H) $(GLINK TemplateArgX)
$(GNAME TemplateArgX):
$(B T) $(GLINK Type)
$(B V) $(GLINK Type) $(GLINK Value)
$(B S) $(GLINK LName)
$(GNAME Value):
$(B n)
$(GLINK Number)
$(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 Value)...
$(B S) $(GLINK Number) $(GLINK Value)...
$(GNAME HexFloat):
$(B NAN)
$(B INF)
$(B NINF)
$(B N) $(GLINK HexDigits) $(B P) $(GLINK Exponent)
$(GLINK HexDigits) $(B P) $(GLINK Exponent)
$(GNAME Exponent):
$(B N) $(GLINK Number)
$(GLINK Number)
$(GNAME HexDigits):
$(GLINK HexDigit)
$(GLINK HexDigit) $(GLINK HexDigits)
$(GNAME HexDigit):
$(GLINK Digit)
$(B A)
$(B B)
$(B C)
$(B D)
$(B E)
$(B F)
$(GNAME CharWidth):
$(B a)
$(B w)
$(B d)
)
$(DL
$(DT $(B n))
$(DD is for $(B null) arguments.)
$(DT $(GLINK Number))
$(DD is for positive numeric literals (including
character literals).)
$(DT $(B N) $(GLINK Number))
$(DD is for negative numeric literals.)
$(DT $(B e) $(GLINK HexFloat))
$(DD is for real and imaginary floating point literals.)
$(DT $(B c) $(GLINK HexFloat) $(B c) $(GLINK HexFloat))
$(DD is for complex floating point literals.)
$(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.
)
$(DT $(B A) $(GLINK Number) $(GLINK Value)...)
$(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.
)
$(DT $(B S) $(GLINK Number) $(GLINK Value)...)
$(DD A struct literal. $(GLINK Value) is repeated $(GLINK Number) times.
)
)
$(GRAMMAR
$(GNAME Name):
$(GLINK Namestart)
$(GLINK Namestart) $(GLINK Namechars)
$(GNAME Namestart):
$(B _)
$(I Alpha)
$(GNAME Namechar):
$(GLINK Namestart)
$(GLINK Digit)
$(GNAME Namechars):
$(GLINK Namechar)
$(GLINK Namechar) $(I Namechars)
)
$(P A $(GLINK Name) is a standard D identifier.)
$(GRAMMAR
$(GNAME LName):
$(GLINK Number) $(GLINK Name)
$(GNAME Number):
$(GLINK Digit)
$(GLINK Digit) $(I Number)
$(GNAME Digit):
$(B 0)
$(B 1)
$(B 2)
$(B 3)
$(B 4)
$(B 5)
$(B 6)
$(B 7)
$(B 8)
$(B 9)
)
$(P An $(GLINK LName) is a name preceded by a $(GLINK Number) giving
the number of characters in the $(GLINK Name).
)
)
$(SECTION3 Type Mangling,
$(P Types are mangled using a simple linear scheme:)
$(GRAMMAR
$(GNAME Type):
$(GLINK Shared)
$(GLINK Const)
$(GLINK Immutable)
$(GLINK Wild)
$(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 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 TypeNull)
$(GLINK TypeTuple)
$(GLINK TypeVector)
$(GLINK Internal)
$(GNAME Shared):
$(B O) $(GLINK Type)
$(GNAME Const):
$(B x) $(GLINK Type)
$(GNAME Immutable):
$(B y) $(GLINK Type)
$(GNAME Wild):
$(B Ng) $(GLINK Type)
$(GNAME TypeArray):
$(B A) $(GLINK Type)
$(GNAME TypeStaticArray):
$(B G) $(GLINK Number) $(GLINK Type)
$(GNAME TypeAssocArray):
$(B H) $(GLINK Type) $(GLINK Type)
$(GNAME TypePointer):
$(B P) $(GLINK Type)
$(GNAME TypeVector):
$(B Nh) $(GLINK Type)
$(GNAME TypeFunction):
$(GLINK CallConvention) $(GLINK FuncAttrs) $(GLINK Parameters) $(GLINK ParamClose) $(GLINK Type)
$(GNAME CallConvention):
$(B F) $(GREEN // D)
$(B U) $(GREEN // C)
$(B W) $(GREEN // Windows)
$(B V) $(GREEN // Pascal)
$(B R) $(GREEN // C++)
$(GNAME FuncAttrs):
$(GLINK FuncAttr)
$(GLINK FuncAttr) $(I FuncAttrs)
$(GNAME FuncAttr):
$(I empty)
$(GLINK FuncAttrPure)
$(GLINK FuncAttrNothrow)
$(GLINK FuncAttrProperty)
$(GLINK FuncAttrRef)
$(GLINK FuncAttrTrusted)
$(GLINK FuncAttrSafe)
$(GLINK FuncAttrNogc)
$(GNAME FuncAttrPure):
$(B Na)
$(GNAME FuncAttrNothrow):
$(B Nb)
$(GNAME FuncAttrRef):
$(B Nc)
$(GNAME FuncAttrProperty):
$(B Nd)
$(GNAME FuncAttrTrusted):
$(B Ne)
$(GNAME FuncAttrSafe):
$(B Nf)
$(GNAME FuncAttrNogc):
$(B Ni)
$(GNAME Parameters):
$(GLINK Parameter)
$(GLINK Parameter) $(I Parameters)
$(GNAME Parameter):
$(GLINK Parameter2)
$(B M) $(GLINK Parameter2) $(GREEN // scope)
$(GNAME Parameter2):
$(GLINK Type)
$(B J) $(GLINK Type) $(GREEN // out)
$(B K) $(GLINK Type) $(GREEN // ref)
$(B L) $(GLINK Type) $(GREEN // lazy)
$(GNAME ParamClose)
$(B X) $(GREEN // variadic T t...$(RPAREN) style)
$(B Y) $(GREEN // variadic T t,...$(RPAREN) style)
$(B Z) $(GREEN // not variadic)
$(GNAME TypeIdent):
$(B I) $(GLINK QualifiedName)
$(GNAME TypeClass):
$(B C) $(GLINK QualifiedName)
$(GNAME TypeStruct):
$(B S) $(GLINK QualifiedName)
$(GNAME TypeEnum):
$(B E) $(GLINK QualifiedName)
$(GNAME TypeTypedef):
$(B T) $(GLINK QualifiedName)
$(GNAME TypeDelegate):
$(B D) $(GLINK TypeFunction)
$(GNAME TypeVoid):
$(B v)
$(GNAME TypeByte):
$(B g)
$(GNAME TypeUbyte):
$(B h)
$(GNAME TypeShort):
$(B s)
$(GNAME TypeUshort):
$(B t)
$(GNAME TypeInt):
$(B i)
$(GNAME TypeUint):
$(B k)
$(GNAME TypeLong):
$(B l)
$(GNAME TypeUlong):
$(B m)
$(GNAME TypeFloat):
$(B f)
$(GNAME TypeDouble):
$(B d)
$(GNAME TypeReal):
$(B e)
$(GNAME TypeIfloat):
$(B o)
$(GNAME TypeIdouble):
$(B p)
$(GNAME TypeIreal):
$(B j)
$(GNAME TypeCfloat):
$(B q)
$(GNAME TypeCdouble):
$(B r)
$(GNAME TypeCreal):
$(B c)
$(GNAME TypeBool):
$(B b)
$(GNAME TypeChar):
$(B a)
$(GNAME TypeWchar):
$(B u)
$(GNAME TypeDchar):
$(B w)
$(GNAME TypeNull):
$(B n)
$(GNAME TypeTuple):
$(B B) $(GLINK Number) $(GLINK Parameters)
$(GNAME Internal):
$(B Z)
)
)
$(SECTION3 Function Calling Conventions,
$(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.
)
$(SECTION4 Register Conventions,
$(UL
$(LI EAX, ECX, EDX are scratch registers and can be destroyed
by a function.)
$(LI EBX, ESI, EDI, EBP must be preserved across function calls.)
$(LI EFLAGS is assumed destroyed across function calls, except
for the direction flag which must be forward.)
$(LI The FPU stack must be empty when calling a function.)
$(LI The FPU control word must be preserved across function calls.)
$(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.)
)
)
$(SECTION4 Return Value,
$(UL
$(LI The types bool, byte, ubyte, short, ushort, int, uint,
pointer, Object, and interfaces
are returned in EAX.)
$(LI long and ulong
are returned in EDX,EAX, where EDX gets the most significant
half.)
$(LI float, double, real, ifloat, idouble, ireal are returned
in ST0.)
$(LI cfloat, cdouble, creal are returned in ST1,ST0 where ST1
is the real part and ST0 is the imaginary part.)
$(LI Dynamic arrays are returned with the pointer in EDX
and the length in EAX.)
$(LI Associative arrays are returned in EAX.)
$(LI References are returned as pointers in EAX.)
$(LI Delegates are returned with the pointer to the function
in EDX and the context pointer in EAX.)
$(LI 1, 2 and 4 byte structs and static arrays are returned in EAX.)
$(LI 8 byte structs and static arrays are returned in EDX,EAX, where
EDX gets the most significant half.)
$(LI For other sized structs and static arrays,
the return value is stored through a hidden pointer passed as
an argument to the function.)
$(LI Constructors return the this pointer in EAX.)
)
)
$(SECTION4 Parameters,
$(P The parameters to the non-variadic function:)
---
foo(a1, a2, ..., an);
---
$(P are passed as follows:)
$(TABLE
$(TR $(TD a1))
$(TR $(TD a2))
$(TR $(TD ...))
$(TR $(TD an))
$(TR $(TD hidden))
$(TR $(TD this))
)
$(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.)
$(P The last parameter is passed in EAX rather than being pushed
on the stack if the following conditions are met:)
$(UL
$(LI It fits in EAX.)
$(LI It is not a 3 byte struct.)
$(LI It is not a floating point type.)
)
$(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.
)
$(P The callee cleans the stack.)
$(P The parameters to the variadic function:)
---
void foo(int p1, int p2, int[] p3...)
foo(a1, a2, ..., an);
---
$(P are passed as follows:)
$(TABLE
$(TR $(TD p1))
$(TR $(TD p2))
$(TR $(TD a3))
$(TR $(TD hidden))
$(TR $(TD this))
)
$(P The variadic part is converted to a dynamic array and the
rest is the same as for non-variadic functions.)
$(P The parameters to the variadic function:)
---
void foo(int p1, int p2, ...)
foo(a1, a2, a3, ..., an);
---
$(P are passed as follows:)
$(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))
)
$(P The caller is expected to clean the stack.
$(D _argptr) is not
passed, it is computed by the callee.)
)
)
$(SECTION3 Exception Handling,
$(SECTION4 Windows,
$(P Conforms to the Microsoft Windows Structured Exception Handling
conventions.
)
)
$(SECTION4 Linux$(COMMA) FreeBSD and OS X,
$(P Uses static address range/handler tables.
It is not compatible with the ELF/Mach-O 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.
)
$(P For each function that has exception handlers,
an EH table entry is generated.
)
$(TABLE2 EH Table Entry,
$(THEAD 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)
)
$(P The EH table entries are placed into the following special
segments, which are concatenated by the linker.
)
$(TABLE2 EH Table Segment,
$(THEAD Operating System, Segment Name)
$(TROW Windows, $(D FI))
$(TROW Linux, $(D .deh_eh))
$(TROW FreeBSD, $(D .deh_eh))
$(TROW OS X, $(ARGS $(D __deh_eh), $(D __DATA)))
)
$(BR)
$(P The rest of the EH data can be placed anywhere,
it is immutable.)
$(TABLE2 DHandlerTable,
$(THEAD 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)
$(TABLE2 DHandlerInfo,
$(THEAD 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)
$(TABLE2 DCatchInfo,
$(THEAD field, description)
$(TROW $(D uint), number of entries in $(D DCatchBlock[]))
$(TROW $(D DCatchBlock[]), array of catch information)
)
$(BR)
$(TABLE2 DCatchBlock,
$(THEAD field, description)
$(TROW $(D ClassInfo), catch type)
$(TROW $(D uint), offset from EBP/RBP to catch variable)
$(TR $(D void*), catch handler code)
)
)
)
$(SECTION3 Garbage Collection,
$(P The interface to this is found in $(D phobos/internal/gc).)
)
$(SECTION3 Runtime Helper Functions,
$(P These are found in $(D phobos/internal).)
)
$(SECTION3 Module Initialization and Termination,
$(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.
)
$(P All the static denstructors 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.
)
)
$(SECTION3 Unit Testing,
$(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.
)
)
$(SECTION2 Symbolic Debugging,
$(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.
The $(B dmd) compiler will generate only C symbolic type info with the
$(B -gc) compiler switch.
)
$(TABLE2 Types for C Debuggers,
$(THEAD 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))
)
$(P For debuggers that can be modified to accept new types, the
following extensions help them fully support the types.
)
$(SECTION3 $(LNAME2 codeview, Codeview Debugger Extensions),
$(P The D $(B dchar) type is represented by the special
primitive type 0x78.)
$(P D makes use of the Codeview OEM generic type record
indicated by $(D LF_OEM) (0x0015). The format is:)
$(TABLE2 Codeview OEM Extensions for D,
$(TROW field size, 2, 2, 2, 2, 2, 2)
$(THEAD 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)))
$(P Where:)
$(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)))
$(P These extensions can be pretty-printed
by $(LINK2 http://www.digitalmars.com/ctg/obj2asm.html, obj2asm).
$(P The $(LINK2 http://ddbg.mainia.de/releases.html, Ddbg) debugger
supports them.)
)
)
$(SECTION3 $(LNAME2 dwarf, Dwarf Debugger Extensions),
$(P The following leaf types are added:)
$(TABLE2 Dwarf Extensions for D,
$(THEAD D type, ID, Value, Format)
$(TROW $(ARGS dynamic array)
, $(ARGS $(D DW_TAG_darray_type))
, $(ARGS 0x41)
, $(ARGS $(D DW_AT_type) is element type))
$(TROW
$(ARGS associative array)
, $(ARGS $(D DW_TAG_aarray_type))
, $(ARGS 0x42)
, $(ARGS $(D DW_AT_type) is element type, $(D DW_AT_containing_type) key type))
$(TROW $(ARGS delegate)
, $(ARGS $(D DW_TAG_delegate_type))
, $(ARGS 0x43)
, $(ARGS $(D DW_AT_type) is function type, $(D DW_AT_containing_type) is $(SINGLEQUOTE this) type)))
$(P These extensions can be pretty-printed
by $(LINK2 http://www.digitalmars.com/ctg/dumpobj.html, dumpobj).
$(P The $(LINK2 https://zerobugs.codeplex.com, ZeroBUGS)
debugger supports them.)
)
$(P Note that these Dwarf extensions have been removed as they conflict with
recent gcc additions.
)
)
)
)
Macros:
TITLE=Application Binary Interface
WIKI=ABI
CATEGORY_SPEC=$0