CwlUtils
CwlUtils copied to clipboard
Crash on M1
This line crashes on M1 Macs because the try fails
https://github.com/mattgallagher/CwlUtils/blob/0bfc4587d01cfc796b6c7e118fc631333dd8ab33/Sources/CwlUtils/CwlSysctl.swift#L164
In terminal, what does…
sysctl -n hw.cpufrequency
…produce on an M1?
@deirdresm just returns nothing and a 0 exit code:
Alex@MacBook-Pro ~ » sysctl -n hw.cpufrequency 1 ↵
Alex@MacBook-Pro ~ » echo $?
0
Alex@MacBook-Pro ~ »
Interesting. I was looking at the sources earlier on opensource.apple.com, but don't remember seeing M1-specific stuff relating to CPU speed, but I'll check it next time I'm in that codebase (which will likely be soon).
Weird, looks like it should be supported: https://github.com/EntityFX/anybench/blob/1209866ed4890276e449958c1b6845307c47581a/results/apple-arm-m1/Dhry.txt
I didn't notice the trailing 1 in your command on mobile, maybe try it without?
So as of right now, our software is compiling Intel only and compiles correctly (so runs in Rosetta). It just crashes when running on M1 because of that optional not unwrapping correctly. However, I just downloaded the project and tried to run the test on my M1 MacBook and got this compile error:
Showing Recent Messages
Build target CwlPreconditionTesting of project CwlPreconditionTesting with configuration Debug
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')
CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstruction.swift:185:166: error: cannot find 'x86_THREAD_STATE64' in scope
thread_swap_exception_ports(mach_thread_self(), EXC_MASK_BAD_INSTRUCTION, currentExceptionPtr, Int32(bitPattern: UInt32(EXCEPTION_STATE) | MACH_EXCEPTION_CODES), x86_THREAD_STATE64, masksPtr, countPtr, portsPtr, behaviorsPtr, flavorsPtr)
^~~~~~~~~~~~~~~~~~
CompileSwift normal arm64 CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift:44:59: error: cannot find type 'x86_thread_state64_t' in scope
public let x86_THREAD_STATE64_COUNT = UInt32(MemoryLayout<x86_thread_state64_t>.size / MemoryLayout<Int32>.size)
^~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:63:47: error: cannot find 'x86_thread_state64_t' in scope
var state = old_state.withMemoryRebound(to: x86_thread_state64_t.self, capacity: 1) { return $0.pointee }
^~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:77:3: error: type of expression is ambiguous without more context
withUnsafePointer(to: &f) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift:82:35: error: cannot find 'x86_thread_state64_t' in scope
new_state.withMemoryRebound(to: x86_thread_state64_t.self, capacity: 1) { $0.pointee = state }
^~~~~~~~~~~~~~~~~~~~
CompileSwift normal arm64 /Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift (in target 'CwlPreconditionTesting' from project 'CwlPreconditionTesting')
/Users/Alex/Downloads/CwlUtils-master/Dependencies/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift:44:59: error: cannot find type 'x86_thread_state64_t' in scope
public let x86_THREAD_STATE64_COUNT = UInt32(MemoryLayout<x86_thread_state64_t>.size / MemoryLayout<Int32>.size)
^~~~~~~~~~~~~~~~~~~~
I had Xcode compile the test under Rosetta and it compiled. Here are the tests that fail under Rosetta
Test-CwlUtils-2021.04.07_15-34-04--0400.xcresult.zip Test-CwlUtils-2021.04.07_15-33-58--0400.xcresult.zip Test-CwlUtils-2021.04.07_15-28-44--0400.xcresult.zip Test-CwlUtils-2021.04.07_15-28-43--0400.xcresult.zip Test-CwlUtils_macOSTests-2021.04.07_15-27-10--0400.xcresult.zip