Skip to content

Commit 6b39352

Browse files
committed
[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.
1 parent 96dca43 commit 6b39352

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/SIL/IR/Linker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ void SILLinkerVisitor::visitGlobalAddrInst(GlobalAddrInst *GAI) {
522522
// In Embedded Swift, we want to actually link globals from other modules too,
523523
// so strip "external" from the linkage.
524524
SILGlobalVariable *G = GAI->getReferencedGlobal();
525-
G->setLinkage(stripExternalFromLinkage(G->getLinkage()));
525+
if (G->isDefinition())
526+
G->setLinkage(stripExternalFromLinkage(G->getLinkage()));
526527
}
527528

528529
//===----------------------------------------------------------------------===//

test/embedded/modules-extern.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public func publicFuncInAModule() {
2121
@usableFromInline
2222
internal func internalFuncInAModule() {
2323
some_c_api()
24+
_ = globalVariable
2425
}
2526

27+
@_extern(c)
28+
var globalVariable: Int
29+
2630
// BEGIN Main.swift
2731

2832
import MyModule

0 commit comments

Comments
 (0)