Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Support BUILD_SHARED_LIBS for Windows too #3704

Merged
merged 18 commits into from
May 23, 2021

Conversation

kinke
Copy link
Member

@kinke kinke commented Apr 24, 2021

By compiling druntime/Phobos with -fvisibility=public for the new DLLs (=> #3703 included as prerequisite for now).

Compiling and linking druntime works fine:

> ls -lh lib/druntime-ldc*
-rwxr-xr-x 1 Martin 197121 1.9M Apr 26 21:35 lib/druntime-ldc-debug-shared.dll
-rw-r--r-- 1 Martin 197121 3.0M Apr 26 18:51 lib/druntime-ldc-debug-shared.lib
-rw-r--r-- 1 Martin 197121 6.0M Apr 26 21:35 lib/druntime-ldc-debug-shared.pdb
-rw-r--r-- 1 Martin 197121 8.6M Apr 26 21:35 lib/druntime-ldc-debug.lib
-rw-r--r-- 1 Martin 197121 4.7M Apr 26 21:35 lib/druntime-ldc-lto.lib
-rwxr-xr-x 1 Martin 197121 1.7M Apr 26 22:10 lib/druntime-ldc-shared.dll
-rw-r--r-- 1 Martin 197121 2.9M Apr 26 21:59 lib/druntime-ldc-shared.lib
-rw-r--r-- 1 Martin 197121 2.5M Apr 26 22:10 lib/druntime-ldc-shared.pdb
-rw-r--r-- 1 Martin 197121 4.4M Apr 26 21:35 lib/druntime-ldc.lib

The druntime DLL exports more than 10k symbols. The MS C runtime is linked statically; that should probably be changed to the MS DLLs too. Edit: done.

Linking a non-Phobos hello-world app against the druntime DLL works; it unsurprisingly crashes at runtime though.

The Phobos DLL can be compiled too, but linking fails (builtin TypeInfo init symbols and vtables etc.).

@kinke
Copy link
Member Author

kinke commented Apr 26, 2021

The remaining Phobos linking errors aren't looking that bad:

lld-link: error: undefined symbol: _D14TypeInfo_Array6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D12TypeInfo_Axm6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D32TypeInfo_AS3std11concurrency3Tid6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D60TypeInfo_AS3std8datetime8timezone13PosixTimeZone10Transition6__initZ)
>>> referenced 78 more times

lld-link: error: undefined symbol: _D14TypeInfo_Const6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_xm6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D32TypeInfo_xS3std11concurrency3Tid6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D60TypeInfo_xS3std11concurrency__T4ListTSQBbQBa7MessageZQw4Node6__initZ)
>>> referenced 190 more times

lld-link: error: undefined symbol: _D10TypeInfo_m6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_xm6__initZ)
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj
>>> referenced 6 more times

lld-link: error: undefined symbol: _D15TypeInfo_Struct6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D31TypeInfo_S3std11concurrency3Tid6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D59TypeInfo_S3std11concurrency__T4ListTSQBbQBa7MessageZQw4Node6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D59TypeInfo_S3std8datetime8timezone13PosixTimeZone10Transition6__initZ)
>>> referenced 114 more times

lld-link: error: undefined symbol: _D9Exception7__ClassZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D9Exception@TypeDescriptor)
>>> referenced by runtime\objects-shared\std\base64.obj:(_D3std6base6415Base64Exception7__ClassZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency15MessageMismatch7__ClassZ)
>>> referenced 27 more times

lld-link: error: undefined symbol: _D12TypeInfo_Aya6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D13TypeInfo_AAya6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D13TypeInfo_xAya6__initZ)
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj
>>> referenced 12 more times

lld-link: error: undefined symbol: _D10TypeInfo_u6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_xu6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_yu6__initZ)
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj
>>> referenced 1 more times

lld-link: error: undefined symbol: _D10TypeInfo_k6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_xk6__initZ)
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D119TypeInfo_E3std3uni__T16UnicodeSetParserTSQBf5regex8internal6parser__T6ParserTAyaTSQCuQBpQBmQBg7CodeGenZQBiZQDi8Operator6__initZ)
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj
>>> referenced 2 more times

lld-link: error: undefined symbol: _D13TypeInfo_Enum6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D119TypeInfo_E3std3uni__T16UnicodeSetParserTSQBf5regex8internal6parser__T6ParserTAyaTSQCuQBpQBmQBg7CodeGenZQBiZQDi8Operator6__initZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D35TypeInfo_E3std11concurrency7MsgType6__initZ)
>>> referenced by runtime\objects-shared\std\encoding.obj:(_D33TypeInfo_E3std8encoding9AsciiChar6__initZ)
>>> referenced 14 more times

lld-link: error: undefined symbol: _D10TypeInfo_h6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_xh6__initZ)
>>> referenced by runtime\objects-shared\std\encoding.obj:(_D33TypeInfo_E3std8encoding9AsciiChar6__initZ)
>>> referenced by runtime\objects-shared\std\encoding.obj:(_D35TypeInfo_E3std8encoding10Latin1Char6__initZ)
>>> referenced 5 more times

lld-link: error: undefined symbol: _D18TypeInfo_Invariant6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D11TypeInfo_yu6__initZ)
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj:(_D57TypeInfo_yS3std8internal14unicode_tables15UnicodeProperty6__initZ)
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj:(_D50TypeInfo_yS3std8internal14unicode_tables9CompEntry6__initZ)
>>> referenced 6 more times

lld-link: error: undefined symbol: _D11TypeInfo_Au6__initZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D12TypeInfo_AAu6__initZ)

lld-link: error: undefined symbol: _D6Object7__ClassZ
>>> referenced by runtime\objects-shared\etc\c\curl.obj:(_D18TypeInfo_xC6Object6__initZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency10MessageBox7__ClassZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency15ThreadScheduler7__ClassZ)
>>> referenced 48 more times

lld-link: error: undefined symbol: _D10TypeInfo_i6__initZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D11TypeInfo_xi6__initZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D35TypeInfo_E3std11concurrency7MsgType6__initZ)
>>> referenced by runtime\objects-shared\std\datetime\timezone.obj:(_D11TypeInfo_yi6__initZ)
>>> referenced 6 more times

lld-link: error: undefined symbol: _D16TypeInfo_Pointer6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D72TypeInfo_PxS3etc1c7sqlite318sqlite3_index_info24sqlite3_index_constraint6__initZ)
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D69TypeInfo_PxS3etc1c7sqlite318sqlite3_index_info21sqlite3_index_orderby6__initZ)
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D78TypeInfo_PxS3etc1c7sqlite318sqlite3_index_info30sqlite3_index_constraint_usage6__initZ)
>>> referenced 17 more times

lld-link: error: undefined symbol: _D10TypeInfo_a6__initZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D11TypeInfo_xa6__initZ)
>>> referenced by runtime\objects-shared\std\format\package.obj
>>> referenced by runtime\objects-shared\std\path.obj
>>> referenced 2 more times

lld-link: error: undefined symbol: _D10TypeInfo_d6__initZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D11TypeInfo_xd6__initZ)

lld-link: error: undefined symbol: _D10TypeInfo_l6__initZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D11TypeInfo_xl6__initZ)

lld-link: error: undefined symbol: _D10TypeInfo_v6__initZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D11TypeInfo_xv6__initZ)
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D14TypeInfo_UPvZv6__initZ)
>>> referenced by runtime\objects-shared\std\file.obj
>>> referenced 4 more times

lld-link: error: undefined symbol: _D17TypeInfo_Function6__vtblZ
>>> referenced by runtime\objects-shared\etc\c\sqlite3.obj:(_D14TypeInfo_UPvZv6__initZ)
>>> referenced by runtime\objects-shared\std\encoding.obj:(_D41TypeInfo_FZC3std8encoding14EncodingScheme6__initZ)
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D14TypeInfo_FPvZv6__initZ)

lld-link: error: undefined symbol: _D12TypeInfo_Axa6__initZ
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj:(_D12TypeInfo_xAa6__initZ)
>>> referenced by runtime\objects-shared\std\array.obj
>>> referenced by runtime\objects-shared\std\format\package.obj

lld-link: error: undefined symbol: _D10TypeInfo_b6__initZ
>>> referenced by runtime\objects-shared\std\algorithm\iteration.obj:(_D11TypeInfo_xb6__initZ)
>>> referenced by runtime\objects-shared\std\array.obj
>>> referenced by runtime\objects-shared\std\concurrency.obj
>>> referenced 2 more times

lld-link: error: undefined symbol: _D10TypeInfo_w6__initZ
>>> referenced by runtime\objects-shared\std\array.obj:(_D11TypeInfo_xw6__initZ)
>>> referenced by runtime\objects-shared\std\format\package.obj
>>> referenced by runtime\objects-shared\std\regex\internal\parser.obj

lld-link: error: undefined symbol: _D14TypeInfo_Class6__vtblZ
>>> referenced by runtime\objects-shared\std\base64.obj:(_D3std6base6415Base64Exception7__ClassZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency15MessageMismatch7__ClassZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency15OwnerTerminated7__ClassZ)
>>> referenced 152 more times

lld-link: error: undefined symbol: _D4core6memory12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\bigint.obj:(_D3std6bigint12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\datetime\timezone.obj:(_D3std8datetime8timezone12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\encoding.obj:(_D3std8encoding12__ModuleInfoZ)
>>> referenced 21 more times

lld-link: error: undefined symbol: _D4core5bitop12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\bitmanip.obj:(_D3std8bitmanip12__ModuleInfoZ)

lld-link: error: undefined symbol: _D4core8internal5array5utils12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\bitmanip.obj:(_D3std8bitmanip12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\conv.obj:(_D3std4conv12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\datetime\timezone.obj:(_D3std8datetime8timezone12__ModuleInfoZ)
>>> referenced 16 more times

lld-link: error: undefined symbol: _D10TypeInfo_e6__initZ
>>> referenced by runtime\objects-shared\std\complex.obj:(_D11TypeInfo_xe6__initZ)
>>> referenced by runtime\objects-shared\std\variant.obj

lld-link: error: undefined symbol: _D25TypeInfo_AssociativeArray6__vtblZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D36TypeInfo_HS3std11concurrency3TidAAya6__initZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D35TypeInfo_HAyaS3std11concurrency3Tid6__initZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D34TypeInfo_HS3std11concurrency3Tidxb6__initZ)
>>> referenced 13 more times

lld-link: error: undefined symbol: _D4core6thread5fiber5Fiber7__ClassZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency14FiberScheduler9InfoFiber7__ClassZ)
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D35TypeInfo_AC4core6thread5fiber5Fiber6__initZ)

lld-link: error: undefined symbol: _D4core4sync9condition9Condition7__ClassZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency14FiberScheduler14FiberCondition7__ClassZ)

lld-link: error: undefined symbol: _D4core4sync9condition12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D3std11parallelism12__ModuleInfoZ)

lld-link: error: undefined symbol: _D4core6thread12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D3std11parallelism12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\process.obj:(_D3std7process12__ModuleInfoZ)
>>> referenced 1 more times

lld-link: error: undefined symbol: _D4core4time12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\concurrency.obj:(_D3std11concurrency12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\datetime\date.obj:(_D3std8datetime4date12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\datetime\interval.obj:(_D3std8datetime8interval12__ModuleInfoZ)
>>> referenced 8 more times

lld-link: error: undefined symbol: _D6object9Throwable7__ClassZ
>>> referenced by runtime\objects-shared\std\conv.obj:(_D6object9Throwable@TypeDescriptor)
>>> referenced by runtime\objects-shared\std\file.obj
>>> referenced by runtime\objects-shared\std\internal\cstring.obj

lld-link: error: undefined symbol: _D4core4time13TimeException7__ClassZ
>>> referenced by runtime\objects-shared\std\datetime\systime.obj:(_D4core4time13TimeException@TypeDescriptor)
>>> referenced by runtime\objects-shared\std\datetime\timezone.obj

lld-link: error: undefined symbol: _D4core5cpuid12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\digest\sha.obj:(_D3std6digest3sha12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\internal\math\biguintcore.obj:(_D3std8internal4math11biguintcore12__ModuleInfoZ)
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D3std11parallelism12__ModuleInfoZ)
>>> referenced 1 more times

lld-link: error: undefined symbol: _D4core8internal8spinlock12__ModuleInfoZ
>>> referenced by runtime\objects-shared\std\experimental\allocator\building_blocks\ascending_page_allocator.obj:(_D3std12experimental9allocator15building_blocks24ascending_page_allocator12__ModuleInfoZ)

lld-link: error: undefined symbol: _D4core9exception16OutOfMemoryError7__ClassZ
>>> referenced by runtime\objects-shared\std\experimental\allocator\gc_allocator.obj:(_D4core9exception16OutOfMemoryError@TypeDescriptor)

lld-link: error: undefined symbol: _D18TypeInfo_Interface6__vtblZ
>>> referenced by runtime\objects-shared\std\experimental\allocator\package.obj:(_D50TypeInfo_C3std12experimental9allocator10IAllocator6__initZ)
>>> referenced by runtime\objects-shared\std\experimental\allocator\package.obj:(_D56TypeInfo_C3std12experimental9allocator16ISharedAllocator6__initZ)
>>> referenced by runtime\objects-shared\std\regex\internal\ir.obj:(_D56TypeInfo_C3std5regex8internal2ir__T14MatcherFactoryTaZQt6__initZ)

lld-link: error: undefined symbol: _D15TypeInfo_Shared6__vtblZ
>>> referenced by runtime\objects-shared\std\experimental\allocator\package.obj:(_D58TypeInfo_OxC3std12experimental9allocator16ISharedAllocator6__initZ)

lld-link: error: undefined symbol: _D17TypeInfo_Delegate6__vtblZ
>>> referenced by runtime\objects-shared\std\net\curl.obj:(_D44TypeInfo_DFS3std3net4curl4HTTP10StatusLineZv6__initZ)
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D13TypeInfo_DFZv6__initZ)
>>> referenced by runtime\objects-shared\std\xml.obj:(_D37TypeInfo_DFC3std3xml13ElementParserZv6__initZ)

lld-link: error: undefined symbol: _D10TypeInfo_t6__initZ
>>> referenced by runtime\objects-shared\std\net\curl.obj:(_D11TypeInfo_xt6__initZ)
>>> referenced by runtime\objects-shared\std\socket.obj:(_D36TypeInfo_E3std6socket13AddressFamily6__initZ)
>>> referenced by runtime\objects-shared\std\uni\package.obj

lld-link: error: undefined symbol: _D11TypeInfo_Af6__initZ
>>> referenced by runtime\objects-shared\std\numeric.obj:(_D12TypeInfo_AAf6__initZ)

lld-link: error: undefined symbol: _D10TypeInfo_f6__initZ
>>> referenced by runtime\objects-shared\std\numeric.obj:(_D11TypeInfo_xf6__initZ)

lld-link: error: undefined symbol: _D4core6thread8osthread6Thread7__ClassZ
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D3std11parallelism17ParallelismThread7__ClassZ)

lld-link: error: undefined symbol: _D6object5Error7__ClassZ
>>> referenced by runtime\objects-shared\std\parallelism.obj:(_D3std11parallelism20ParallelForeachError7__ClassZ)
>>> referenced by runtime\objects-shared\std\typecons.obj:(_D3std8typecons19NotImplementedError7__ClassZ)

lld-link: error: undefined symbol: _D4core3sys7windows7winbase12STARTUPINFOW6__initZ
>>> referenced by runtime\objects-shared\std\process.obj:(_D3std7process15spawnProcessWinFNeMAxaMQeSQBo5stdio4FileQpQrMxHAyaAyaEQCqQCp6ConfigMQBxZCQDjQDi3Pid)
>>> referenced by runtime\objects-shared\std\process.obj:(_D3std7process15spawnProcessWinFNeMAxaMQeSQBo5stdio4FileQpQrMxHAyaAyaEQCqQCp6ConfigMQBxZCQDjQDi3Pid)
>>> referenced by runtime\objects-shared\std\process.obj:(_D3std7process15spawnProcessWinFNeMAxaMQeSQBo5stdio4FileQpQrMxHAyaAyaEQCqQCp6ConfigMQBxZCQDjQDi3Pid)
>>> referenced 4 more times

lld-link: error: undefined symbol: _D20TypeInfo_StaticArray6__vtblZ
>>> referenced by runtime\objects-shared\std\stdio.obj:(_D12TypeInfo_G4a6__initZ)
>>> referenced by runtime\objects-shared\std\uni\package.obj:(_D12TypeInfo_G2m6__initZ)
>>> referenced by runtime\objects-shared\std\uni\package.obj:(_D129TypeInfo_G2S3std3uni__T11TrieBuilderTbTwVii1114112TSQBoQBn__T9sliceBitsVmi8Vmi21ZQuTSQCvQCu__TQBhVmi0Vmi8ZQBtZQDj14ConstructState6__initZ)
>>> referenced 11 more times

lld-link: error: undefined symbol: _D4core9exception16UnicodeException7__ClassZ
>>> referenced by runtime\objects-shared\std\utf.obj:(_D3std3utf12UTFException7__ClassZ)

Edit: Updated.

@kinke kinke force-pushed the dll2 branch 3 times, most recently from 0ba11e5 to e97c87e Compare April 30, 2021 15:37
@kinke
Copy link
Member Author

kinke commented Apr 30, 2021

Okay, all linking errors are gone:

>ls -lh lib/druntime* lib/phobos* runtime/*.exe
-rwxr-xr-x 1 Martin 197121 1.9M May  1 01:01 lib/druntime-ldc-debug-shared.dll
-rw-r--r-- 1 Martin 197121 3.0M May  1 01:01 lib/druntime-ldc-debug-shared.lib
-rw-r--r-- 1 Martin 197121 6.0M May  1 01:01 lib/druntime-ldc-debug-shared.pdb
-rw-r--r-- 1 Martin 197121 8.6M May  1 01:13 lib/druntime-ldc-debug.lib
-rw-r--r-- 1 Martin 197121 4.7M May  1 01:13 lib/druntime-ldc-lto.lib
-rwxr-xr-x 1 Martin 197121 1.7M May  1 01:04 lib/druntime-ldc-shared.dll
-rw-r--r-- 1 Martin 197121 2.9M May  1 01:04 lib/druntime-ldc-shared.lib
-rw-r--r-- 1 Martin 197121 2.5M May  1 01:04 lib/druntime-ldc-shared.pdb
-rwxr-xr-x 1 Martin 197121 3.6M May  1 00:58 lib/druntime-ldc-unittest-debug-shared.dll
-rw-r--r-- 1 Martin 197121 2.8M May  1 00:58 lib/druntime-ldc-unittest-debug-shared.lib
-rw-r--r-- 1 Martin 197121  11M May  1 00:58 lib/druntime-ldc-unittest-debug-shared.pdb
-rw-r--r-- 1 Martin 197121  20M May  1 01:19 lib/druntime-ldc-unittest-debug.lib
-rwxr-xr-x 1 Martin 197121 2.4M May  1 01:01 lib/druntime-ldc-unittest-shared.dll
-rw-r--r-- 1 Martin 197121 2.7M May  1 01:01 lib/druntime-ldc-unittest-shared.lib
-rw-r--r-- 1 Martin 197121 2.8M May  1 01:01 lib/druntime-ldc-unittest-shared.pdb
-rw-r--r-- 1 Martin 197121 6.3M May  1 01:14 lib/druntime-ldc-unittest.lib
-rw-r--r-- 1 Martin 197121 4.4M May  1 01:13 lib/druntime-ldc.lib
-rwxr-xr-x 1 Martin 197121 4.5M May  1 01:13 lib/phobos2-ldc-debug-shared.dll
-rw-r--r-- 1 Martin 197121 4.6M May  1 01:13 lib/phobos2-ldc-debug-shared.lib
-rw-r--r-- 1 Martin 197121 9.7M May  1 01:13 lib/phobos2-ldc-debug-shared.pdb
-rw-r--r-- 1 Martin 197121  18M May  1 01:13 lib/phobos2-ldc-debug.lib
-rw-r--r-- 1 Martin 197121 9.7M May  1 01:14 lib/phobos2-ldc-lto.lib
-rwxr-xr-x 1 Martin 197121 3.7M May  1 01:14 lib/phobos2-ldc-shared.dll
-rw-r--r-- 1 Martin 197121 4.6M May  1 01:14 lib/phobos2-ldc-shared.lib
-rw-r--r-- 1 Martin 197121 3.4M May  1 01:14 lib/phobos2-ldc-shared.pdb
-rwxr-xr-x 1 Martin 197121  39M May  1 01:03 lib/phobos2-ldc-unittest-debug-shared.dll
-rw-r--r-- 1 Martin 197121 3.6M May  1 01:03 lib/phobos2-ldc-unittest-debug-shared.lib
-rw-r--r-- 1 Martin 197121 116M May  1 01:03 lib/phobos2-ldc-unittest-debug-shared.pdb
-rw-r--r-- 1 Martin 197121 351M May  1 01:22 lib/phobos2-ldc-unittest-debug.lib
-rwxr-xr-x 1 Martin 197121  25M May  1 01:09 lib/phobos2-ldc-unittest-shared.dll
-rw-r--r-- 1 Martin 197121 3.5M May  1 01:09 lib/phobos2-ldc-unittest-shared.lib
-rw-r--r-- 1 Martin 197121 9.7M May  1 01:09 lib/phobos2-ldc-unittest-shared.pdb
-rw-r--r-- 1 Martin 197121  71M May  1 01:19 lib/phobos2-ldc-unittest.lib
-rw-r--r-- 1 Martin 197121 8.6M May  1 01:14 lib/phobos2-ldc.lib
-rwxr-xr-x 1 Martin 197121  41K May  1 01:13 runtime/druntime-test-runner-debug-shared.exe
-rwxr-xr-x 1 Martin 197121 3.4M May  1 01:21 runtime/druntime-test-runner-debug.exe
-rwxr-xr-x 1 Martin 197121  39K May  1 01:01 runtime/druntime-test-runner-shared.exe
-rwxr-xr-x 1 Martin 197121 2.2M May  1 01:14 runtime/druntime-test-runner.exe
-rwxr-xr-x 1 Martin 197121  41K May  1 01:11 runtime/phobos2-test-runner-debug-shared.exe
-rwxr-xr-x 1 Martin 197121  39M May  1 01:22 runtime/phobos2-test-runner-debug.exe
-rwxr-xr-x 1 Martin 197121  39K May  1 01:10 runtime/phobos2-test-runner-shared.exe
-rwxr-xr-x 1 Martin 197121  25M May  1 01:19 runtime/phobos2-test-runner.exe

@kinke
Copy link
Member Author

kinke commented May 2, 2021

Includes ldc-developers/druntime#197 now as well, i.e., using a generalized rt.sections_elf_shared for Windows too, with both static and shared druntime.

@kinke
Copy link
Member Author

kinke commented May 3, 2021

Looks like we're almost there:

99% tests passed, 3 tests failed out of 1960
[...]
1376 - std.format.internal.write-shared (Failed)
1855 - std.format.internal.write-debug-shared (Failed)
1952 - druntime-test-shared (Failed)

The shared Phobos test runners represent a typical scenario: little .exe linked against 2 DLLs (druntime DLL and Phobos unittest DLL). It's also interesting because druntime is compiled all-at-once, while unittest-Phobos is compiled per-module; this affects dllimport (way more such dllimported refs when compiling separately, because symbols defined in any root module are never dllimported - accordingly more MS linker warnings about 'importing locally defined symbol').

Still TODO, OTOH:

  • CMake: copy & install rt.dso_windows object file to the lib dir on Windows
  • Compiler: link that object file automatically when linking against shared druntime
  • Compiler: default to -fvisibility=public with -shared on Windows?
  • Compiler: dllimport with -link-defaultlib-shared too, not requiring -fvisibility=public?
  • druntime: check core.thread for version (Shared) on Posix and check whether/what's needed for Windows too (inheritLoadedLibraries() etc.) - unsure, just a straight port from Posix
  • druntime: Proper UTF-8 support for rt_loadLibrary()
  • Test with dynamically loaded DLLs

@kinke kinke force-pushed the dll2 branch 2 times, most recently from 484fe58 to 4cf5b0c Compare May 4, 2021 14:33
@kinke kinke force-pushed the dll2 branch 3 times, most recently from dc73d0d to b0b8f49 Compare May 21, 2021 20:42
kinke added 13 commits May 22, 2021 00:10
By compiling druntime/Phobos with `-fvisibility=public` for the new
DLLs.

Compiling and linking druntime works fine:

> ls -lh lib/druntime-ldc*
-rwxr-xr-x 1 Martin 197121 2.4M Apr 24 19:28 lib/druntime-ldc-debug-shared.dll
-rw-r--r-- 1 Martin 197121 2.9M Apr 24 19:28 lib/druntime-ldc-debug-shared.lib
-rw-r--r-- 1 Martin 197121  12M Apr 24 19:28 lib/druntime-ldc-debug-shared.pdb
-rw-r--r-- 1 Martin 197121 8.6M Apr 24 19:28 lib/druntime-ldc-debug.lib
-rw-r--r-- 1 Martin 197121 4.7M Apr 24 19:28 lib/druntime-ldc-lto.lib
-rwxr-xr-x 1 Martin 197121 2.2M Apr 24 19:28 lib/druntime-ldc-shared.dll
-rw-r--r-- 1 Martin 197121 2.8M Apr 24 18:46 lib/druntime-ldc-shared.lib
-rw-r--r-- 1 Martin 197121 8.5M Apr 24 19:28 lib/druntime-ldc-shared.pdb
-rw-r--r-- 1 Martin 197121 4.4M Apr 24 19:28 lib/druntime-ldc.lib

The druntime DLL exports more than 10k symbols. The MS C runtime is
linked statically; that should probably be changed to the MS DLLs too.

Linking a non-Phobos hello-world app against the druntime DLL works; it
unsurprisingly crashes at runtime though.

The Phobos DLL can be compiled too, but linking fails (builtin TypeInfo
init symbols and vtables etc.).
And add oldnames.lib and legacy_stdio_definitions.lib for the Phobos
DLL, which are linked automatically with static druntime via pragma(lib)
directives.
@kinke
Copy link
Member Author

kinke commented May 23, 2021

Multiple identities for symbols across DLLs/executables aren't restricted to TypeInfos and templates, but include functions too: dlang/phobos#8110

@kinke kinke merged commit e3a0187 into ldc-developers:master May 23, 2021
@kinke kinke deleted the dll2 branch May 23, 2021 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant