Map export visibility to LLVM DLL storage classes

Compatible with DMD, but restricted to Windows and functions only.

`export` functions with bodies get the dllexport attribute and will be
exported if the containing object is pulled in when linking.

Body-less `export` functions get the dllimport attribute and will be
accessed via an import table indirection, set up at runtime by the OS.

This is a temporary solution, the proper fix is a pending DMD PR, after
which LDC will need to be adapted.
This commit is contained in:
Martin 2016-10-26 15:25:38 +02:00
parent 8a2a6c1e7f
commit 67d5fe5624
6 changed files with 60 additions and 1 deletions

View file

@ -851,6 +851,14 @@ void DtoResolveVariable(VarDeclaration *vd) {
// as well).
gvar->setAlignment(DtoAlignment(vd));
/* TODO: set DLL storage class when `export` is fixed (an attribute)
if (global.params.isWindows && vd->isExport()) {
auto c = vd->isImportedSymbol() ? LLGlobalValue::DLLImportStorageClass
: LLGlobalValue::DLLExportStorageClass;
gvar->setDLLStorageClass(c);
}
*/
applyVarDeclUDAs(vd, gvar);
IF_LOG Logger::cout() << *gvar << '\n';