Commit 47f3137
[Linux] WinAdapter: Remove virtual dtors from IUnknown to fix vtable ABI (#3793)
* WinAdapter: Remove virtual dtors from IUnknown to fix vtable ABI
The vtable for `IUnknown` and its subclasses contain two deletion
pointers when compiled on non-Windows systems with `IUnknown` from
`WinAdapter.h`:
vtable for 'DxcLibrary' @ 0x7ffff7cbc5f8 (subobject @ 0x5555556bb9e0):
[0]: 0x7ffff6a56d40 <DxcLibrary::QueryInterface(_GUID const&, void**)>
[1]: 0x7ffff6a56d20 <DxcLibrary::AddRef()>
[2]: 0x7ffff6a56d30 <DxcLibrary::Release()>
[3]: 0x7ffff6b36bc0 <IUnknown::~IUnknown()> // Complete object destructor
[4]: 0x7ffff6a57130 <DxcLibrary::~DxcLibrary()> // Deleting destructor
[5]: 0x7ffff6a56d50 <DxcLibrary::SetMalloc(IMalloc*)>
[6]: 0x7ffff6a56d60 <DxcLibrary::CreateBlobFromBlob(IDxcBlob*, unsigned int, unsigned int, IDxcBlob**)>
... More DxcLibrary virtual functions
This shifts the the pointers for functions for all subclasses, and is
[annoying] to deal with in otherwise cross-platform applications using
DirectXShaderCompiler as library. `dxcompiler.dll` compiled on/for
Windows without `WinAdapter.h` does not suffer this problem, and only
has three function pointers for `IUnknown`.
Fortunately, it is easily solved by removing the virtual destructor from
`IUnknown`. LLVM enables `-Wnon-virtual-dtor` that warns against
classes with virtual methods but no virtual destructor, though this
warning is best not enabled akin to Windows builds where `IUnknown` from
`windows.h` (`unknwn.h`) results in the same warning on MSVC ([1]/[2]).
[annoying]: https://github.com/Traverse-Research/hassle-rs/blob/1e624792fc3a252ac7788e3c1c5feda52887272f/src/unknown.rs
[1]: #3783 (comment)
[2]: https://godbolt.org/z/hKPT6ThEf
* WinAdapter: Make `IUnknown` and `IMalloc` pure-virtual classes
`IUnknown` in Windows' `unknwn.h` and `IMalloc` in `ObjIdl.h` are marked
as pure virtual, and are best marked as such in `WinAdapter` for
non-Windows platforms too [1]. Only the shim for `IMalloc` was relying
on the default refcounting implementation, all other subclasses either
contain pure-virtual methods themselves or provide an implementation for
`AddRef`/`Release` as required. Likewise the default implementation for
`IMalloc` was only instantiated once by `CoGetMalloc`, and has been
moved into a local class implementing the `IMalloc` interface instead.
[1]: #3793 (comment)
* WinAdapter: Add three missing virtual functions to `IMalloc` interface
To prevent unexpected vtable breakage, add the missing functions from
the [documentation]. Note that they are listed in the wrong order, the
right order is retrieved from the `ObjIdl.h` header and implementations
for `IMalloc` in DirectXShaderCompiler. All implementations are now
properly using the `override` keyword too, to enforce virtual method
existence in the base class.
[documentation]: https://docs.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-imalloc
* Make all WinAdapter destructions explicit
This prevents warnings about non-virtual destructor usage that trip up
the Linux build. It represents status quo on Windows.
Co-authored-by: Greg Roth <grroth@microsoft.com>1 parent 9975a80 commit 47f3137
File tree
9 files changed
+96
-91
lines changed- cmake/modules
- include/dxc
- Support
- Test
- lib/DxcSupport
- tools/clang
- tools/libclang
- unittests/HLSL
9 files changed
+96
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
| 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 | + | |
428 | 440 | | |
429 | 441 | | |
430 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
617 | | - | |
| 617 | + | |
618 | 618 | | |
619 | | - | |
620 | | - | |
621 | | - | |
| 619 | + | |
| 620 | + | |
622 | 621 | | |
623 | 622 | | |
624 | 623 | | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | 624 | | |
629 | 625 | | |
630 | 626 | | |
631 | 627 | | |
632 | 628 | | |
633 | 629 | | |
634 | 630 | | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
639 | 637 | | |
640 | 638 | | |
641 | 639 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
89 | | - | |
90 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| |||
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 73 | + | |
| 74 | + | |
78 | 75 | | |
79 | 76 | | |
80 | 77 | | |
| |||
88 | 85 | | |
89 | 86 | | |
90 | 87 | | |
91 | | - | |
| 88 | + | |
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
95 | 92 | | |
96 | 93 | | |
97 | | - | |
| 94 | + | |
98 | 95 | | |
99 | 96 | | |
100 | 97 | | |
101 | 98 | | |
102 | 99 | | |
103 | | - | |
| 100 | + | |
104 | 101 | | |
105 | 102 | | |
106 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
71 | 70 | | |
72 | | - | |
| 71 | + | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
| 76 | + | |
78 | 77 | | |
79 | | - | |
| 78 | + | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | | - | |
| 83 | + | |
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
| |||
321 | 319 | | |
322 | 320 | | |
323 | 321 | | |
324 | | - | |
| 322 | + | |
325 | 323 | | |
326 | 324 | | |
327 | 325 | | |
| |||
1138 | 1136 | | |
1139 | 1137 | | |
1140 | 1138 | | |
1141 | | - | |
| 1139 | + | |
1142 | 1140 | | |
1143 | 1141 | | |
1144 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 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 | 15 | | |
41 | 16 | | |
42 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
157 | 178 | | |
158 | | - | |
| 179 | + | |
159 | 180 | | |
160 | 181 | | |
161 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
584 | | - | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
585 | 587 | | |
586 | 588 | | |
587 | 589 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3038 | 3038 | | |
3039 | 3039 | | |
3040 | 3040 | | |
3041 | | - | |
| 3041 | + | |
3042 | 3042 | | |
3043 | 3043 | | |
3044 | | - | |
| 3044 | + | |
3045 | 3045 | | |
3046 | 3046 | | |
3047 | 3047 | | |
3048 | | - | |
| 3048 | + | |
3049 | 3049 | | |
3050 | 3050 | | |
3051 | | - | |
| 3051 | + | |
3052 | 3052 | | |
3053 | 3053 | | |
3054 | 3054 | | |
| |||
3072 | 3072 | | |
3073 | 3073 | | |
3074 | 3074 | | |
3075 | | - | |
| 3075 | + | |
3076 | 3076 | | |
3077 | 3077 | | |
3078 | 3078 | | |
| |||
3083 | 3083 | | |
3084 | 3084 | | |
3085 | 3085 | | |
3086 | | - | |
| 3086 | + | |
3087 | 3087 | | |
3088 | 3088 | | |
3089 | 3089 | | |
| |||
3101 | 3101 | | |
3102 | 3102 | | |
3103 | 3103 | | |
3104 | | - | |
| 3104 | + | |
3105 | 3105 | | |
3106 | 3106 | | |
3107 | 3107 | | |
3108 | 3108 | | |
3109 | 3109 | | |
3110 | 3110 | | |
3111 | | - | |
| 3111 | + | |
3112 | 3112 | | |
3113 | 3113 | | |
3114 | 3114 | | |
3115 | | - | |
| 3115 | + | |
3116 | 3116 | | |
3117 | 3117 | | |
3118 | 3118 | | |
| |||
0 commit comments