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

Windows: Add -dllimport CLI option for more selective implicit dllimports #3763

Merged
merged 7 commits into from
Jun 18, 2021

Conversation

kinke
Copy link
Member

@kinke kinke commented Jun 14, 2021

  • Newly require -link-defaultlib-shared for implicit dllimport.
    E.g., this enables to compile druntime DLL with -fvisibility=public for pure exports and no (local) imports (such as builtin TypeInfos).
  • -link-defaultlib-shared alone now only implicitly imports symbols from druntime/Phobos.
    This simplifies building complex DLLs linked against a bunch of static libs (dub only supports static lib dependencies!); the static
    libs don't need to be compiled with -fvisibility=public anymore (if the DLL itself isn't either), -link-defaultlib-shared is sufficient.
    This is mainly useful for existing DLLs with explicit exports, to make them link against shared druntime/Phobos and so end up with a single druntime/Phobos for the whole process.

* Newly require `-link-defaultlib-shared` for implicit dllimport.
  E.g., this enables to compile druntime DLL with `-fvisibility=public`
  for pure exports and no (local) imports (such as builtin TypeInfos).
* `-link-defaultlib-shared` alone now only implicitly imports symbols
  from druntime/Phobos.
  This simplifies building complex DLLs linked against a bunch of
  static libs (dub only supports static lib dependencies!); the static
  libs don't need to be compiled with `-fvisibility=public` anymore
  (if the DLL itself isn't either), `-link-defaultlib-shared` is
  sufficient.
  This is mainly useful for existing DLLs with explicit exports, to make
  them link against *shared* druntime/Phobos and so end up with a single
  druntime/Phobos for the whole process.
@kinke kinke force-pushed the selective_dllimport branch from 0d57325 to 9865e45 Compare June 14, 2021 15:47
@kinke
Copy link
Member Author

kinke commented Jun 14, 2021

With this proposal, the option of only dllimporting (~all external D globals) without own dllexports (previous -link-defaultlib-shared) is lost. This might be a bit of a hassle (I guess mainly for executables linked against non-defaultlib DLLs).

Until now, I've tried to handle these implicit dllimports without extra cmdline option, to keep things reasonably simple. Maybe an explicit option is better; having to use -fvisibility=public -link-defaultlib-shared for betterC executables (to dllimport external globals) isn't really intuitive. ;)

@kinke kinke changed the title Windows: Make implicit dllimport more selective Windows: Add -dllimport CLI option for more selective implicit dllimports Jun 14, 2021
@kinke kinke marked this pull request as ready for review June 14, 2021 23:37
@kinke
Copy link
Member Author

kinke commented Jun 15, 2021

I've tested this for an executable with ~150 dub dependencies (incl. big ones like vibe-d; all static libs), wanting to link it against shared druntime/Phobos - by enforcing -link-defaultlib-shared as implicit compile flag for all packages via reggae --dflags=-link-defaultlib-shared.

This led to 21 undefined symbols; some TLS variables (std.getopt - can be worked around in Phobos) and, annoyingly, culled templates (pre-instantiated in Phobos). -linkonce-templates to the rescue, and down to 8 undefined symbols.

@kinke
Copy link
Member Author

kinke commented Jun 15, 2021

After some fixes, down to 1 undefined symbol (ModuleInfo) - there are 3rd-party packages in std, e.g., std.io (https://github.com/MartinNowak/io/)...

@kinke
Copy link
Member Author

kinke commented Jun 16, 2021

No more linker errors, but hitting #3690 apparently.

@kinke kinke force-pushed the selective_dllimport branch from 7a06341 to db4faf3 Compare June 18, 2021 20:33
@kinke kinke merged commit 738b05a into ldc-developers:master Jun 18, 2021
@kinke kinke deleted the selective_dllimport branch June 18, 2021 22:23
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