diff --git a/changelog/dmd.extern-dllimport.dd b/changelog/dmd.extern-dllimport.dd new file mode 100644 index 0000000000..eae2344b79 --- /dev/null +++ b/changelog/dmd.extern-dllimport.dd @@ -0,0 +1,7 @@ +export int a; now generates dllexport instead of dllimport + +In order to make it dllimport, use: + +--- +export extern int a; +--- diff --git a/compiler/src/dmd/declaration.d b/compiler/src/dmd/declaration.d index fac8ba1020..e8d8465a9f 100644 --- a/compiler/src/dmd/declaration.d +++ b/compiler/src/dmd/declaration.d @@ -1314,9 +1314,17 @@ extern (C++) class VarDeclaration : Declaration override final bool isImportedSymbol() const { - if (visibility.kind == Visibility.Kind.export_ && !_init && (storage_class & STC.static_ || parent.isModule())) - return true; - return false; + /* If global variable has `export` and `extern` then it is imported + * export int sym1; // definition: exported + * export extern int sym2; // declaration: imported + * export extern int sym3 = 0; // error, extern cannot have initializer + */ + bool result = + visibility.kind == Visibility.Kind.export_ && + storage_class & STC.extern_ && + (storage_class & STC.static_ || parent.isModule()); + //printf("isImportedSymbol() %s %d\n", toChars(), result); + return result; } final bool isCtorinit() const pure nothrow @nogc @safe diff --git a/compiler/src/dmd/tocsym.d b/compiler/src/dmd/tocsym.d index 284bffe724..5982487fa4 100644 --- a/compiler/src/dmd/tocsym.d +++ b/compiler/src/dmd/tocsym.d @@ -501,12 +501,18 @@ Symbol *toSymbol(Dsymbol s) /************************************* + * Create Windows import symbol from backend Symbol. + * Params: + * sym = backend symbol + * loc = location for error message purposes + * Returns: + * import symbol */ -Symbol *toImport(Symbol *sym, Loc loc) +private Symbol *createImport(Symbol *sym, Loc loc) { - //printf("Dsymbol.toImport('%s')\n", sym.Sident); - char *n = sym.Sident.ptr; + //printf("Dsymbol.createImport('%s')\n", sym.Sident.ptr); + const char* n = sym.Sident.ptr; import core.stdc.stdlib : alloca; const allocLen = 6 + strlen(n) + 1 + type_paramsize(sym.Stype).sizeof*3 + 1; char *id = cast(char *) alloca(allocLen); @@ -549,7 +555,7 @@ Symbol *toImport(Declaration ds) { if (!ds.csym) ds.csym = toSymbol(ds); - ds.isym = toImport(ds.csym, ds.loc); + ds.isym = createImport(ds.csym, ds.loc); } return ds.isym; } diff --git a/compiler/test/dshell/dll.d b/compiler/test/dshell/dll.d index 71b2c04ed3..d7d06e8830 100644 --- a/compiler/test/dshell/dll.d +++ b/compiler/test/dshell/dll.d @@ -6,8 +6,11 @@ int main() return DISABLED; version (DigitalMars) - version (OSX) // Shared libraries are not yet supported on OSX + { +// Disable DM Dlls for now, need to redesign it +// version (OSX) // Shared libraries are not yet supported on OSX return DISABLED; + } Vars.set(`SRC`, `$EXTRA_FILES/dll`); Vars.set(`EXE_NAME`, `$OUTPUT_BASE/testdll$EXE`);