"JIT session error: Symbols not found" when running swift command-line tool

Hi all,

I have a swift script that I've been running from the command line (macOS 12.4, Xcode 13.4.1) for a while with no issues.

I recently downloaded Xcode 14 beta 3 and the script no longer runs. It now fails with a "JIT session error: Symbols not found" error.

I can cut the script down to a very simple example

#!/usr/bin/swift

import Foundation

var url: URL = URL(fileURLWithPath: "/tmp")

I need to import Foundation to get access to the URL type for my script. Xcode 13.4.1 doesn't seem to need to do anything clever

% swift commandline-fail.swift
JIT session error: Symbols not found: [ _$s10Foundation3URLV15fileURLWithPathACSSh_tcfC, _$s10Foundation3URLVMa ]

Failed to materialize symbols: { (main, { __swift_FORCE_LOAD_$_swiftCoreFoundation_$_main, __swift_FORCE_LOAD_$_swiftDispatch_$_main, _$s4main3url10Foundation3URLVvp, __swift_FORCE_LOAD_$_swiftObjectiveC_$_main, __swift_FORCE_LOAD_$_swiftDarwin_$_main, _main, __swift_FORCE_LOAD_$_swiftXPC_$_main, __swift_FORCE_LOAD_$_swiftIOKit_$_main, ___swift_project_value_buffer, ___swift_allocate_value_buffer }) }

The failing swift version is

% swift --version 
swift-driver version: 1.60 Apple Swift version 5.7 (swiftlang-5.7.0.120.1 clang-1400.0.28.1)
Target: x86_64-apple-macosx12.0

This script runs fine using

% swift --version
swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)

Target: x86_64-apple-macosx12.0

Does anyone have any ideas how I can solve this issue? It looks like the JIT needs access to the Foundation library but I have no idea how to do this.

Cheers!

Answered by dagronf in 726633022

Okay I've re-tried this in Xcode 13 beta 6 and the problem appears to have fixed. Yay!

swift-driver version: 1.62.3 Apple Swift version 5.7 (swiftlang-5.7.0.123.8 clang-1400.0.29.50)
Target: x86_64-apple-macosx12.0

It seems to be a bug in Swift 5.7. We're using the below workaround

xcrun -sdk macosx swiftc YourScript.swift -o YourScript
YourScript [your additional arguments]

Just spent a couple of days trying to figure this out to no avail. Mine is a similar one in that i am using an own generated Module. Which i build using xcodebuild

xcodebuild archive -workspace ${workspace} -scheme ${scheme} \
        -sdk macosx13.0 \
        -arch arm64e \
        -arch arm64 \
        -arch x86_64 \
        -archivePath ${output_path} \
        ONLY_ACTIVE_ARCH=NO \
        SKIP_INSTALL=NO \
        BUILD_LIBRARY_FOR_DISTRIBUTION=YES \

Then

   xcodebuild -create-xcframework \
        -framework ${framework_path} \
        -output "${shared_path}/${scheme}.xcframework" 

This works fine on intel macs (Even after building with xcode 14 beta). But now fails on M1 macs with JIT session error: Symbols not found: [ _$s...... I don't think It has to do with the arch setup as the same build previously work with xcode 13 for both M1 and Intel.,

The recently released XCode 14 beta 4 does not seem to fix this. Hopefully we get a solution by RC as this is clearly a bug in the toolchain

Turns out this issue appears to be triggered by public classes in my module that are not declared as final.

so the following triggers the JIT session error: Symbols not found: [ error for swift on M1 macs (arm64) but not intel (x86_64)

public class Lambda { ..}

changing this to

final public class Lambda{..}

fixes this at least for now.

Accepted Answer

Okay I've re-tried this in Xcode 13 beta 6 and the problem appears to have fixed. Yay!

swift-driver version: 1.62.3 Apple Swift version 5.7 (swiftlang-5.7.0.123.8 clang-1400.0.29.50)
Target: x86_64-apple-macosx12.0

I also got same issue for Xcode 15.0 and swift version is 5.9 To fix this, instead of directly running the command "swift YourFileName.swift", execute the following commands in terminal: step 1-> swiftc YourFileName.swift (this will generate one executable file in the same folder with same name i.e, "YourFileName" step 2-> ./YourFileName

"JIT session error: Symbols not found" when running swift command-line tool
 
 
Q