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

Fix #3916 - undefined symbols with -dllimport=all on Windows #3923

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

kinke
Copy link
Member

@kinke kinke commented Feb 26, 2022

Instantiated data symbols were previously never dllimported with -dllimport=all. So if the parent template instance wasn't codegen'd into the binary directly, it remained undefined.

For -dllimport=defaultLibsOnly, the 'solution' to this problem was to define-on-declare data symbols instantiated from druntime/Phobos templates, making sure each binary defines all such symbols it references.

In both cases, switch to an approach where we dllimport all instantiated data symbols (or druntime/Phobos symbols only), and
dllexport them whenever defining them (so that other object files or binaries can import them). This may lead to more 'importing
locally defined symbol' linker warnings, but may also lead to less duplicates and possibly 'proper' sharing of instantiated globals
across the whole process.

This is superfluous and skipped with -linkonce-templates, as that mode defines all referenced instantiated symbols in each binary anyway, and so has already been a workaround.

@kinke kinke changed the title WIP: Fix #3916 - undefined symbols with -dllimport=all on Windows Fix #3916 - undefined symbols with -dllimport=all on Windows Feb 28, 2022
…ndows

Instantiated data symbols were previously never dllimported with
`-dllimport=all`. So if the parent template instance wasn't
codegen'd into the binary directly, it remained undefined.

For `-dllimport=defaultLibsOnly`, the 'solution' to this problem
was to define-on-declare data symbols instantiated from druntime/
Phobos templates, making sure each binary defines all such symbols
it references.

In both cases, switch to an approach where we dllimport all
instantiated data symbols (or druntime/Phobos symbols only), and
dllexport them whenever defining them (so that other object files
or binaries can import them). This may lead to more 'importing
locally defined symbol' linker warnings, but may also lead to less
duplicates and possibly 'proper' sharing of instantiated globals
across the whole process.

This is superfluous and skipped with `-linkonce-templates`, as
that mode defines all referenced instantiated symbols in each
binary anyway, and so has already been a workaround.
@kinke kinke marked this pull request as ready for review February 28, 2022 20:54
@kinke kinke merged commit f2a6fef into ldc-developers:master Feb 28, 2022
@kinke kinke deleted the fix3916 branch February 28, 2022 21:19
@kinke
Copy link
Member Author

kinke commented Mar 1, 2022

At work, we're using -dllimport=defaultLibsOnly, for a huge project consisting of ~140 dub packages/static libs. There are lots of 'importing locally defined symbol' linker warnings now, but I think they can be suppressed via /warning:<number>, need to test. And annoyingly, one symbol remains undefined - a std.variant.VariantN!16 init symbol referenced by its TypeInfo.

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