[Embedded] Only strip "external" from global variables that have definitions

Embedded Swift ends up rewriting the linkage of global variables as
part of linking together all of the Swift modules. Doing so for extern
global variables (e.g., ones meant to be implemented in C) breaks the
LLVM module, because they will never have definitions. Only make this
change when the global variable is a definition.
This commit is contained in:
Doug Gregor
2025-12-01 15:41:59 -08:00
parent 96dca43eb9
commit 6b3935201d
2 changed files with 6 additions and 1 deletions

View File

@@ -522,6 +522,7 @@ void SILLinkerVisitor::visitGlobalAddrInst(GlobalAddrInst *GAI) {
// In Embedded Swift, we want to actually link globals from other modules too,
// so strip "external" from the linkage.
SILGlobalVariable *G = GAI->getReferencedGlobal();
if (G->isDefinition())
G->setLinkage(stripExternalFromLinkage(G->getLinkage()));
}

View File

@@ -21,8 +21,12 @@ public func publicFuncInAModule() {
@usableFromInline
internal func internalFuncInAModule() {
some_c_api()
_ = globalVariable
}
@_extern(c)
var globalVariable: Int
// BEGIN Main.swift
import MyModule