@@ -227,32 +227,39 @@ LLValue *DtoDelegateEquals(EXP op, LLValue *lhs, LLValue *rhs) {
227227
228228// //////////////////////////////////////////////////////////////////////////////
229229
230- LinkageWithCOMDAT DtoLinkage (Dsymbol *sym) {
231- LLGlobalValue::LinkageTypes linkage = LLGlobalValue::ExternalLinkage;
232- if (hasWeakUDA (sym)) {
233- linkage = LLGlobalValue::WeakAnyLinkage;
234- } else {
235- /* Function (incl. delegate) literals are emitted into each referencing
236- * compilation unit, so use internal linkage for all lambdas and all global
237- * variables they define.
238- * This makes sure these symbols don't accidentally collide when linking
239- * object files compiled by different compiler invocations (lambda mangles
240- * aren't stable - see https://issues.dlang.org/show_bug.cgi?id=23722).
241- */
242- auto potentialLambda = sym;
243- if (auto vd = sym->isVarDeclaration ()) {
244- if (vd->isDataseg ())
245- potentialLambda = vd->toParent2 ();
246- }
230+ namespace {
231+ LLGlobalValue::LinkageTypes DtoLinkageOnly (Dsymbol *sym) {
232+ if (hasWeakUDA (sym))
233+ return LLGlobalValue::WeakAnyLinkage;
234+
235+ // static in ImportC translates to internal linkage
236+ if (auto decl = sym->isDeclaration ())
237+ if ((decl->storage_class & STCstatic) && decl->isCsymbol ())
238+ return LLGlobalValue::InternalLinkage;
239+
240+ /* Function (incl. delegate) literals are emitted into each referencing
241+ * compilation unit, so use internal linkage for all lambdas and all global
242+ * variables they define.
243+ * This makes sure these symbols don't accidentally collide when linking
244+ * object files compiled by different compiler invocations (lambda mangles
245+ * aren't stable - see https://issues.dlang.org/show_bug.cgi?id=23722).
246+ */
247+ auto potentialLambda = sym;
248+ if (auto vd = sym->isVarDeclaration ())
249+ if (vd->isDataseg ())
250+ potentialLambda = vd->toParent2 ();
251+ if (potentialLambda->isFuncLiteralDeclaration ())
252+ return LLGlobalValue::InternalLinkage;
247253
248- if (potentialLambda->isFuncLiteralDeclaration ()) {
249- linkage = LLGlobalValue::InternalLinkage;
250- } else if (sym->isInstantiated ()) {
251- linkage = templateLinkage;
252- }
253- }
254+ if (sym->isInstantiated ())
255+ return templateLinkage;
254256
255- return {linkage, needsCOMDAT ()};
257+ return LLGlobalValue::ExternalLinkage;
258+ }
259+ }
260+
261+ LinkageWithCOMDAT DtoLinkage (Dsymbol *sym) {
262+ return {DtoLinkageOnly (sym), needsCOMDAT ()};
256263}
257264
258265bool needsCOMDAT () {
0 commit comments