forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abi.dd
1100 lines (873 loc) · 23.3 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
990
991
992
993
994
995
996
997
998
999
1000
Ddoc
$(SPEC_S D 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:
$(CODE 0D 0C 0B 0A).
)
)
$(SECTION3 Basic Types,
$(DL
$(DT bool)
$(DD 8 bit byte with the values 0 for false and 1 for true)
$(DT byte)
$(DD 8 bit signed value)
$(DT ubyte)
$(DD 8 bit unsigned value)
$(DT short)
$(DD 16 bit signed value)
$(DT ushort)
$(DD 16 bit unsigned value)
$(DT int)
$(DD 32 bit signed value)
$(DT uint)
$(DD 32 bit unsigned value)
$(DT long)
$(DD 64 bit signed value)
$(DT ulong)
$(DD 64 bit unsigned value)
$(DT cent)
$(DD 128 bit signed value)
$(DT ucent)
$(DD 128 bit unsigned value)
$(DT float)
$(DD 32 bit IEEE 754 floating point value)
$(DT double)
$(DD 64 bit IEEE 754 floating point value)
$(DT real)
$(DD implementation defined floating point value, for x86 it is
80 bit IEEE 754 extended real)
)
)
$(SECTION3 Delegates,
$(P Delegates are $(I fat pointers) with two parts:)
$(TABLE2 Delegate Layout,
$(TR $(TH offset) $(TH property) $(TH contents))
$(TR $(TD 0) $(TD $(CODE .ptr)) $(TD context pointer))
$(TR $(TD $(I ptrsize)) $(TD $(CODE .funcptr)) $(TD 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:)
$(TABLE2 Class Object Layout,
$(TR $(TH size) $(TH property) $(TH contents))
$(TR $(TD $(I ptrsize)) $(TD $(CODE .__vptr)) $(TD pointer to vtable))
$(TR $(TD $(I ptrsize)) $(TD $(CODE .__monitor)) $(TD monitor))
$(TR $(TD ...) $(TD ...) $(TD super's non-static fields and super's interface vptrs, from least to most derived))
$(TR $(TD ...) $(TD named fields) $(TD non-static fields))
$(TR $(TD $(I ptrsize)...) $(TD ) $(TD 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,
$(TR $(TH size) $(TH contents))
$(TR $(TD $(I ptrsize)) $(TD pointer to instance of $(V1 ClassInfo)$(V2 TypeInfo)))
$(TR $(TD $(I ptrsize)...) $(TD 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 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 vtbl[0]; the entries
vtbl[0..$] are all the virtual function pointers, in the order
that they were declared.
This matches the COM object layout used by Windows.
)
$(V2
$(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,
$(TR $(TH offset) $(TH property) $(TH contents))
$(TR $(TD 0) $(TD $(CODE .length)) $(TD array dimension))
$(TR $(TD $(I size_t)) $(TD $(CODE .ptr)) $(TD 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.
$(V1 The current implementation is contained in and defined by
$(PHOBOSSRC internal/aaA.d).)
$(V2 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.
)
$(P When passing a static array to a function, the result, although declared as a static array, will
actually be a reference to a static array. For example:
)
---------
int[3] abc;
---------
$(P Passing abc to functions results in these implicit conversions:)
---------
void func(int[3] array); // actually <reference to><array[3] of><int>
void func(int* p); // abc is converted to a pointer
// to the first element
void func(int[] array); // abc is converted to a dynamic array
---------
)
$(SECTION3 Name Mangling,
$(P D accomplishes typesafe linking by $(I mangling) a D identifier
to include scope and type information.
)
$(GRAMMAR
$(I MangledName):
$(B _D) $(I QualifiedName) $(I Type)
$(B _D) $(I QualifiedName) $(B M) $(I Type)
$(I QualifiedName):
$(I SymbolName)
$(I SymbolName) $(I QualifiedName)
$(I SymbolName):
$(I LName)
$(I TemplateInstanceName)
)
$(P The $(B M) means that the symbol is a function that requires
a $(TT this) pointer.)
$(P Template Instance Names have the types and values of its parameters
encoded into it:
)
$(GRAMMAR
$(I TemplateInstanceName):
$(Number) $(B __T) $(I LName) $(I TemplateArgs) $(B Z)
$(I TemplateArgs):
$(I TemplateArg)
$(I TemplateArg) $(I TemplateArgs)
$(I TemplateArg):
$(B T) $(I Type)
$(B V) $(I Type) $(I Value)
$(B S) $(I LName)
$(I Value):
$(B n)
$(I Number)
$(B i) $(I Number)
$(B N) $(I Number)
$(B e) $(I HexFloat)
$(B c) $(I HexFloat) $(B c) $(I HexFloat)
$(B A) $(I Number) $(I Value)...
$(I HexFloat):
$(B NAN)
$(B INF)
$(B NINF)
$(B N) $(I HexDigits) $(B P) $(I Exponent)
$(I HexDigits) $(B P) $(I Exponent)
$(I Exponent):
$(B N) $(I Number)
$(I Number)
$(I HexDigits):
$(I HexDigit)
$(I HexDigit) $(I HexDigits)
$(I HexDigit):
$(I Digit)
$(B A)
$(B B)
$(B C)
$(B D)
$(B E)
$(B F)
)
$(DL
$(DT $(I n))
$(DD is for $(B null) arguments.)
$(DT $(I Number))
$(DD is for positive numeric literals (including
character literals).)
$(DT $(B N) $(I Number))
$(DD is for negative numeric literals.)
$(DT $(B e) $(I HexFloat))
$(DD is for real and imaginary floating point literals.)
$(DT $(B c) $(I HexFloat) $(B c) $(I HexFloat))
$(DD is for complex floating point literals.)
$(DT $(I Width) $(I Number) $(B _) $(I HexDigits))
$(DD $(I Width) is whether the characters
are 1 byte ($(B a)), 2 bytes ($(B w)) or 4 bytes ($(B d)) in size.
$(I Number) is the number of characters in the string.
The $(I HexDigits) are the hex data for the string.
)
$(DT $(B A) $(I Number) $(I Value)...)
$(DD An array literal. $(I Value) is repeated $(I Number) times.
)
)
$(GRAMMAR
$(I Name):
$(I Namestart)
$(I Namestart) $(I Namechars)
$(I Namestart):
$(B _)
$(I Alpha)
$(I Namechar):
$(I Namestart)
$(I Digit)
$(I Namechars):
$(I Namechar)
$(I Namechar) $(I Namechars)
)
$(P A $(I Name) is a standard D identifier.)
$(GRAMMAR
$(I LName):
$(I Number) $(I Name)
$(I Number):
$(I Digit)
$(I Digit) $(I Number)
$(I Digit):
$(B 0)
$(B 1)
$(B 2)
$(B 3)
$(B 4)
$(B 5)
$(B 6)
$(B 7)
$(B 8)
$(B 9)
)
$(P An $(I LName) is a name preceded by a $(I Number) giving
the number of characters in the $(I Name).
)
)
$(SECTION3 Type Mangling,
$(P Types are mangled using a simple linear scheme:)
$(GRAMMAR
$(I Type):
$(I Shared)
$(I Const)
$(I Immutable)
$(I Wild)
$(I TypeArray)
$(V2 $(I TypeNewArray)
) $(I TypeStaticArray)
$(I TypeAssocArray)
$(I TypePointer)
$(I TypeFunction)
$(I TypeIdent)
$(I TypeClass)
$(I TypeStruct)
$(I TypeEnum)
$(I TypeTypedef)
$(I TypeDelegate)
$(I TypeNone)
$(I TypeVoid)
$(I TypeByte)
$(I TypeUbyte)
$(I TypeShort)
$(I TypeUshort)
$(I TypeInt)
$(I TypeUint)
$(I TypeLong)
$(I TypeUlong)
$(I TypeFloat)
$(I TypeDouble)
$(I TypeReal)
$(I TypeIfloat)
$(I TypeIdouble)
$(I TypeIreal)
$(I TypeCfloat)
$(I TypeCdouble)
$(I TypeCreal)
$(I TypeBool)
$(I TypeChar)
$(I TypeWchar)
$(I TypeDchar)
$(I TypeTuple)
$(I Shared):
$(B O) $(I Type)
$(I Const):
$(B x) $(I Type)
$(I Immutable):
$(B y) $(I Type)
$(I Wild):
$(B Ng) $(I Type)
$(I TypeArray):
$(B A) $(I Type)
$(V2 $(I TypeNewArray):
$(B Ne) $(I Type)
)
$(I TypeStaticArray):
$(B G) $(I Number) $(I Type)
$(I TypeAssocArray):
$(B H) $(I Type) $(I Type)
$(I TypePointer):
$(B P) $(I Type)
$(I TypeFunction):
$(I CallConvention) $(V2 $(I FuncAttrs) )$(I Arguments) $(I ArgClose) $(I Type)
$(I CallConvention):
$(B F) $(GREEN // D)
$(B U) $(GREEN // C)
$(B W) $(GREEN // Windows)
$(B V) $(GREEN // Pascal)
$(B R) $(GREEN // C++)
$(V2 $(I FuncAttrs):
$(I FuncAttr)
$(I FuncAttr) $(I FuncAttrs)
$(I FuncAttr):
$(I empty)
$(I FuncAttrPure)
$(I FuncAttrNothrow)
$(I FuncAttrProperty)
$(I FuncAttrRef)
$(I FuncAttrTrusted)
$(I FuncAttrSafe)
$(I FuncAttrPure):
$(B Na)
$(I FuncAttrNothrow):
$(B Nb)
$(I FuncAttrRef):
$(B Nc)
$(I FuncAttrProperty):
$(B Nd)
$(I FuncAttrTrusted):
$(B Ne)
$(I FuncAttrSafe):
$(B Nf)
)
$(I Arguments):
$(I Argument)
$(I Argument) $(I Arguments)
$(I Argument:)
$(V2
$(I Argument2)
$(B M) $(I Argument2) $(GREEN // scope)
$(I Argument2:)
) $(I Type)
$(B J) $(I Type) $(GREEN // out)
$(B K) $(I Type) $(GREEN // ref)
$(B L) $(I Type) $(GREEN // lazy)
$(I ArgClose)
$(B X) $(GREEN // variadic T t,...$(RPAREN) style)
$(B Y) $(GREEN // variadic T t...$(RPAREN) style)
$(B Z) $(GREEN // not variadic)
$(I TypeIdent):
$(B I) $(I LName)
$(I TypeClass):
$(B C) $(I LName)
$(I TypeStruct):
$(B S) $(I LName)
$(I TypeEnum):
$(B E) $(I LName)
$(I TypeTypedef):
$(B T) $(I LName)
$(I TypeDelegate):
$(B D) $(I TypeFunction)
$(I TypeNone):
$(B n)
$(I TypeVoid):
$(B v)
$(I TypeByte):
$(B g)
$(I TypeUbyte):
$(B h)
$(I TypeShort):
$(B s)
$(I TypeUshort):
$(B t)
$(I TypeInt):
$(B i)
$(I TypeUint):
$(B k)
$(I TypeLong):
$(B l)
$(I TypeUlong):
$(B m)
$(I TypeFloat):
$(B f)
$(I TypeDouble):
$(B d)
$(I TypeReal):
$(B e)
$(I TypeIfloat):
$(B o)
$(I TypeIdouble):
$(B p)
$(I TypeIreal):
$(B j)
$(I TypeCfloat):
$(B q)
$(I TypeCdouble):
$(B r)
$(I TypeCreal):
$(B c)
$(I TypeBool):
$(B b)
$(I TypeChar):
$(B a)
$(I TypeWchar):
$(B u)
$(I TypeDchar):
$(B w)
$(I TypeTuple):
$(B B) $(I Number) $(I Arguments)
)
)
$(SECTION3 Function Calling Conventions,
$(P The extern (C) calling convention matches the C calling convention
used by the supported C compiler on the host system.
The extern (D) calling convention for 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 with garbage
returned in EDX. The EDX value will probably be removed in
the future; it's there for backwards compatibility with
an earlier implementation of AA's.)
$(V2 $(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 are returned in EAX.)
$(LI 8 byte structs are returned in EDX,EAX, where
EDX gets the most significant half.)
$(LI For other struct sizes,
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 _arguments))
$(TR $(TD hidden))
$(TR $(TD this))
)
$(P The caller is expected to clean the stack.
$(B _argptr) is not
passed, it is computed by the callee.)
)
$(SECTION4 Function Attributes,
$(DL
$(DT $(B Na)
$(DD pure)
)
$(DT $(B Nb)
$(DD nothrow)
)
)
)
)
$(SECTION3 Exception Handling,
$(SECTION4 Windows,
$(P Conforms to the Microsoft Windows Structured Exception Handling
conventions.
)
)
$(SECTION4 Linux and OSX,
$(P Uses static address range/handler tables.
It is not compatible with the ELF exception handling tables.
The stack is walked assuming it uses the EBP stack frame
convention. The EBP convention must be used for every
function that has an associated EH table.
)
$(P For each function that has exception handlers,
an EH table entry is generated.
)
$(TABLE1
<caption>EH Table Entry</caption>
$(TR $(TH field) $(TH description))
$(TR $(TD void*) $(TD pointer to start of function))
$(TR $(TD DHandlerTable*) $(TD pointer to corresponding EH data))
$(TR $(TD uint) $(TD size in bytes of the function))
)
$(BR)
$(P The EH table entries are placed into the following special
segments, which are concatenated by the linker.
)
$(TABLE1
<caption>EH Table Segment</caption>
$(TR $(TH Operating System) $(TH Segment Name))
$(TR $(TD Windows) $(TD FI))
$(TR $(TD Linux) $(TD .deh_eh))
$(TR $(TD OSX) $(TD __deh_eh, __DATA))
)
$(BR)
$(P The rest of the EH data can be placed anywhere,
it is immutable.)
$(TABLE1
<caption>DHandlerTable</caption>
$(TR $(TH field) $(TH description))
$(TR $(TD void*) $(TD pointer to start of function))
$(TR $(TD uint) $(TD offset of ESP from EBP))
$(TR $(TD uint) $(TD offset from start of function to return code))
$(TR $(TD uint) $(TD number of entries in DHandlerInfo[]))
$(TR $(TD DHandlerInfo[]) $(TD array of handler information))
)
$(BR)
$(TABLE1
<caption>DHandlerInfo</caption>
$(TR $(TH field) $(TH description))
$(TR $(TD uint) $(TD offset from function address to start of guarded section))
$(TR $(TD uint) $(TD offset of end of guarded section))
$(TR $(TD int) $(TD previous table index))
$(TR $(TD uint) $(TD if != 0 offset to DCatchInfo data from start of table))
$(TR $(TD void*) $(TD if not null, pointer to finally code to execute))
)
$(BR)
$(TABLE1
<caption>DCatchInfo</caption>
$(TR $(TH field) $(TH description))
$(TR $(TD uint) $(TD number of entries in DCatchBlock[]))
$(TR $(TD DCatchBlock[]) $(TD array of catch information))
)
$(BR)
$(TABLE1
<caption>DCatchBlock</caption>
$(TR $(TH field) $(TH description))
$(TR $(TD ClassInfo) $(TD catch type))
$(TR $(TD uint) $(TD offset from EBP to catch variable))
$(TR $(TD void*) $(TD catch handler code))
)
)
)
$(SECTION3 Garbage Collection,
$(P The interface to this is found in $(TT phobos/internal/gc).)
)
$(SECTION3 Runtime Helper Functions,
$(P These are found in $(TT 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,
$(TR
$(TH D type)
$(TH C representation)
)
$(TR
$(TD dynamic array)
$(TD unsigned long long)
)
$(TR
$(TD associative array)
$(TD void*)
)
$(TR
$(TD delegate)
$(TD long long)
)
$(TR
$(TD dchar)
$(TD unsigned long)
)
)
$(P For debuggers that can be modified to accept new types, the
following extensions help them fully support the types.
)
$(SECTION3 <a name="codeview">Codeview Debugger Extensions</a>,
$(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 $(B LF_OEM) (0x0015). The format is:)
$(TABLE2 Codeview OEM Extensions for D,
$(TR
$(TD field size)
$(TD 2)
$(TD 2)
$(TD 2)
$(TD 2)
$(TD 2)
$(TD 2)
)
$(TR
$(TH D Type)
$(TH Leaf Index)
$(TH OEM Identifier)
$(TH recOEM)
$(TH num indices)
$(TH type index)
$(TH type index)
)
$(TR
$(TD dynamic array)
$(TD LF_OEM)
$(TD $(I OEM))
$(TD 1)
$(TD 2)
$(TD @$(I index))
$(TD @$(I element))
)
$(TR
$(TD associative array)
$(TD LF_OEM)
$(TD $(I OEM))
$(TD 2)