From e75782f0f96382ac3950349c032414a4ea8b1682 Mon Sep 17 00:00:00 2001 From: Dimi Racordon Date: Wed, 6 Sep 2023 17:46:21 +0200 Subject: [PATCH] Ensure monomorphized symbols have private linkage --- Sources/CodeGen/LLVM/Transpilation.swift | 5 +++++ Sources/IR/FunctionID.swift | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/Sources/CodeGen/LLVM/Transpilation.swift b/Sources/CodeGen/LLVM/Transpilation.swift index 4c15610ba..1309fc76d 100644 --- a/Sources/CodeGen/LLVM/Transpilation.swift +++ b/Sources/CodeGen/LLVM/Transpilation.swift @@ -443,6 +443,11 @@ extension LLVM.Module { // setLinkage(.private, for: llvmFunction) // } + // Monomorphized functions always have private linkage. + if f.isMonomorphized { + setLinkage(.private, for: llvmFunction) + } + // Functions that return `Never` have the `noreturn` attribute. if !m[f].isSubscript && (m[f].output == .never) { addAttribute(.init(.noreturn, in: &self), to: llvmFunction) diff --git a/Sources/IR/FunctionID.swift b/Sources/IR/FunctionID.swift index 06675d872..41e121451 100644 --- a/Sources/IR/FunctionID.swift +++ b/Sources/IR/FunctionID.swift @@ -61,6 +61,16 @@ extension Function { self.value = .monomorphized(base: base, arguments: arguments) } + /// `true` if `self` is the identity of a monomorphized function. + public var isMonomorphized: Bool { + switch value { + case .monomorphized: + return true + default: + return false + } + } + } }