Windows: Make implicit dllimport more selective

* 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.
This commit is contained in:
Martin Kinkelin 2021-06-14 15:27:34 +02:00
parent 2f0ece3274
commit 9865e459d1
15 changed files with 73 additions and 23 deletions

View file

@ -1670,6 +1670,22 @@ std::string llvmTypeToString(llvm::Type *type) {
return result;
}
bool isDefaultLibSymbol(Dsymbol *sym) {
auto mod = sym->getModule();
if (!mod)
return false;
auto md = mod->md;
if (!md)
return false;
if (md->packages.length == 0)
return md->id == Id::object;
auto p = md->packages.ptr[0];
return p == Id::core || p == Id::std || p == Id::etc || p == Id::ldc;
}
llvm::GlobalVariable *declareGlobal(const Loc &loc, llvm::Module &module,
llvm::Type *type,
llvm::StringRef mangledName,