macOS 15 缺少一個 Logger 符號,讓我的 Mac 應用程式無法啟動
Yardlet 在 macOS 15 上連續四天一啟動就閃退。SDK 將 Logger.isEnabled(type:) 標記為自 macOS 11 起可用,但 macOS 15.6.1 的 libswiftos 裡其實沒有這個符號。
我開發了 Yardlet,這是一款免費、開源的 Mac 應用程式,可以在單一視窗中並行執行 Codex 與 Claude Code 等編碼代理。它的系統需求寫著需要 macOS 15 或以上版本。但它卻在 macOS 15 上連續四天一啟動就退出,而我完全不知道。
我是怎麼發現的
10 月 31 日,我正準備用公司的 MacBook 做效能比較。那台 Mac 還停留在 macOS 15.6.1。Yardlet 一啟動就立刻退出,完全沒有跳出視窗,只留下一份當機報告。我一開始還以為只是公司那台 Mac 太舊了。
Termination Reason: DYLD, Symbol missing
Symbol not found: _$s2os6LoggerV9isEnabled4typeSbSo0a5_log_E2_ta_tF
Expected in: /usr/lib/swift/libswiftos.dylib那個符號是來自 os 模組的 Logger.isEnabled(type:)。我只在一個地方用到它,目的是在沒有人讀取除錯日誌時,略過建構文字選取相關的除錯訊息。
我下載了公開發行的 0.11.0、0.11.4 和 0.11.5 的磁碟映像檔,並用 nm -u 檢查。三個版本全都匯入了這個符號。0.11.0 是第一個公開版本,發布於 10 月 27 日。因為我自己的 Mac 跑的是 macOS 27,所以我一直沒遇到這個問題。
為什麼能通過編譯
專案的 deployment target 設為 macOS 15,因此我原本預期呼叫任何更新版本的 API 都會觸發可用性(availability)錯誤。在 Xcode 27.1 的 SDK 中,Logger 被標記為自 macOS 11 起可用,而 isEnabled(type:) 本身沒有另外標註可用性(此處為簡化版):
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
public struct Logger : @unchecked Sendable {
// ...
public func isEnabled(type: OSLogType) -> Bool於是編譯器認為這個方法從 macOS 11 起就存在。但 Command Line Tools 隨附的 macOS 15.5 SDK 在 libswiftos.tbd 中根本沒有這個符號,27 的 SDK 裡才有,而且 macOS 15.6.1 上的 libswiftos.dylib 也並未匯出它。我還沒檢查過 macOS 26。
修正方式
OSLog 有自己的 isEnabled(type:),底層對應的是 C 函式 os_log_type_enabled,這個函式從 macOS 10.12 起就一直存在。所以我改為保留一個 OSLog handle,用它來建立 Logger,並改向這個 handle 查詢狀態:
static let logHandle = OSLog(subsystem: bundleID, category: "conversation-selection")
static let log = Logger(logHandle)
guard logHandle.isEnabled(type: .debug) else { return }檢查其他匯入符號
我不想再用同樣的方式踩到下一個地雷。我在那台 macOS 15.6.1 的 Mac 上列出了執行檔所有非弱連結(non-weak)的匯入符號,並逐一比對當地系統函式庫實際匯出的符號清單。這是腳本的粗略版本(未檢查結束碼):
import re, subprocess, sys
def run(*args):
return subprocess.run(args, capture_output=True, text=True).stdout
def short(path):
name = re.sub(r"\.dylib$", "", path.split("/")[-1])
return re.sub(r"(\.[A-Z0-9]+)+$", "", name)
binary = sys.argv[1]
wanted = {}
for line in run("dyld_info", "-imports", binary).splitlines():
m = re.match(r"\s+0x[0-9A-F]+\s+(_\S+)\s+(\[weak-import\]\s+)?\(from (\S+)\)", line)
if m and not m.group(2):
wanted.setdefault(m.group(3), set()).add(m.group(1))
for line in run("dyld_info", "-dependents", binary).splitlines():
path = line.strip().split()[-1] if line.strip() else ""
if not path.startswith(("/usr/lib", "/System")) or short(path) not in wanted:
continue
libraries = [path] + [l.split()[-1] for l in run("dyld_info", "-dependents", path).splitlines() if "re-export" in l]
exported = set()
for library in libraries:
exported |= set(re.findall(r"(_\S+)", run("dyld_info", "-exports", library)))
for symbol in sorted(wanted[short(path)] - exported):
print(short(path), run("xcrun", "swift-demangle", "--compact", symbol).strip())腳本會追蹤直接 re-export,因為在 macOS 15 上 SwiftUI 會 re-export SwiftUICore。針對 0.11.5 的 4,261 個強匯入符號,腳本只印出了一行:libswiftos os.Logger.isEnabled(type: __C.os_log_type_t) -> Swift.Bool。
當天晚上 0.11.6 就發布了。發布之前,我把經過公證的磁碟映像檔複製到那台 macOS 15.6.1 的 Mac 上。腳本檢查了它的 4,291 個匯入符號後沒有印出任何缺失,我用空的使用者家目錄啟動應用程式也能穩定維持執行。
後續改變
現在每個版本在發布前都會跑過這項檢查,並在那台 macOS 15 的 Mac 上實際啟動一次。在最舊支援的 macOS 版本上自動啟動應用程式的 CI 作業已經排進計畫,只是還沒建好。
我一直以為 deployment target 會由編譯器替我嚴格把關。實際上,它只會按照 SDK 裡寫的標註來把關,而在這個案例中,SDK 寫的是 macOS 11。