Skip to content

jemalloc crash on macOS/M1 #2362

@hassila

Description

@hassila

I've originally reported this to Apple which deemed it to be a bug in jemalloc, reproducible case and details:

I’m developing a Swift benchmark package that uses the jemalloc memory allocator, now I wanted to add tests to the package and unfortunately it isn’t possible on macOS - Xcode / XCTest will crash on macOS. Xctest on Linux on the other hand, works perfectly fine. It may be an issue on macOS Ventura / m1 hardware.

Backtrace from macOS:

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libjemalloc.2.dylib           	       0x100eeee94 je_free_default + 172
1   libjemalloc.2.dylib           	       0x100eef320 je_free_default + 1336
2   libjemalloc.2.dylib           	       0x100f36684 zone_free + 164
3   CoreFoundation                	       0x1a73530d0 _CFRelease + 1164
4   CoreFoundation                	       0x1a720a5ec __CFURLDeallocate + 52
5   CoreFoundation                	       0x1a7352d2c _CFRelease + 232
6   CoreFoundation                	       0x1a72a2ca0 _CFBundleDlfcnLoadBundle + 448
7   CoreFoundation                	       0x1a7320460 _CFBundleLoadExecutableAndReturnError + 564
8   Foundation                    	       0x1a81613c0 -[NSBundle loadAndReturnError:] + 412
9   XCTestCore                    	       0x1009f9918 -[XCTestDriver _loadTestBundleFromURL:error:] + 132
10  XCTestCore                    	       0x1009f81e0 -[XCTestDriver _prepareTestConfigurationAndIDESession] + 864
11  XCTestCore                    	       0x1009f7e48 -[XCTestDriver run] + 24
12  XCTestCore                    	       0x1009cd850 _XCTestMain + 88
13  xctest                        	       0x100741608 main + 192
14  dyld                          	       0x1007f108c start + 520

On Ubuntu it works though:

ubuntu@swift ~/package-benchmark (reproducible-xcode-test-failure)> swift test
[1/1] Planning buildCompiling plugin Benchmark-Plugin...
Compiling plugin GenerateManualPlugin...
Building for debugging...
[11/11] Linking BenchmarkPackageTests.xctest
Build complete! (1.28s)
Test Suite 'All tests' started at 2022-10-03 17:26:33.699
Test Suite 'debug.xctest' started at 2022-10-03 17:26:33.700
Test Suite 'BenchmarkTests' started at 2022-10-03 17:26:33.700
Test Case 'BenchmarkTests.testBaselineComparison' started at 2022-10-03 17:26:33.700
Not empty. Time (system CPU) Time (user CPU)
Test Case 'BenchmarkTests.testBaselineComparison' passed (0.001 seconds)
Test Suite 'BenchmarkTests' passed at 2022-10-03 17:26:33.701
	 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'debug.xctest' passed at 2022-10-03 17:26:33.701
	 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'All tests' passed at 2022-10-03 17:26:33.701
	 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
ubuntu@swift ~/package-benchmark (reproducible-xcode-test-failure)> 

While on macOS it crashes:

hassila@max ~> cd /tmp
hassila@max /tmp> gh repo clone ordo-one/package-benchmark
Cloning into 'package-benchmark'...
remote: Enumerating objects: 116, done.
remote: Counting objects: 100% (105/105), done.
remote: Compressing objects: 100% (94/94), done.
remote: Total 116 (delta 24), reused 46 (delta 4), pack-reused 11
Receiving objects: 100% (116/116), 82.29 KiB | 275.00 KiB/s, done.
Resolving deltas: 100% (24/24), done.
hassila@max /tmp> cd package-benchmark/
hassila@max /t/package-benchmark (main)> git checkout reproducible-xcode-test-failure
branch 'reproducible-xcode-test-failure' set up to track 'origin/reproducible-xcode-test-failure'.
Switched to a new branch 'reproducible-xcode-test-failure'
hassila@max /t/package-benchmark (reproducible-xcode-test-failure)> swift test
Fetching https://github.com/ordo-one/package-jemalloc from cache
Fetching https://github.com/apple/swift-argument-parser from cache
Fetching https://github.com/apple/swift-system from cache
Fetched https://github.com/ordo-one/package-jemalloc (0.55s)
Fetching https://github.com/swift-extras/swift-extras-json from cache
Fetched https://github.com/apple/swift-system (0.55s)
Fetching https://github.com/apple/swift-numerics from cache
Fetched https://github.com/apple/swift-argument-parser (0.55s)
Fetching https://github.com/ordo-one/TextTable from cache
Fetched https://github.com/swift-extras/swift-extras-json (0.54s)
Fetched https://github.com/ordo-one/TextTable (0.54s)
Fetched https://github.com/apple/swift-numerics (0.56s)
Computing version for https://github.com/ordo-one/package-jemalloc
Computed https://github.com/ordo-one/package-jemalloc at 1.0.0 (0.28s)
Computing version for https://github.com/ordo-one/TextTable
Computed https://github.com/ordo-one/TextTable at 0.0.1 (0.27s)
Computing version for https://github.com/swift-extras/swift-extras-json
Computed https://github.com/swift-extras/swift-extras-json at 0.6.0 (0.29s)
Computing version for https://github.com/apple/swift-numerics
Computed https://github.com/apple/swift-numerics at 1.0.2 (0.27s)
Computing version for https://github.com/apple/swift-argument-parser
Computed https://github.com/apple/swift-argument-parser at 1.1.4 (0.43s)
Computing version for https://github.com/apple/swift-system
Computed https://github.com/apple/swift-system at 1.2.1 (0.35s)
Creating working copy for https://github.com/ordo-one/TextTable
Working copy of https://github.com/ordo-one/TextTable resolved at 0.0.1
Creating working copy for https://github.com/apple/swift-numerics
Working copy of https://github.com/apple/swift-numerics resolved at 1.0.2
Creating working copy for https://github.com/apple/swift-system
Working copy of https://github.com/apple/swift-system resolved at 1.2.1
Creating working copy for https://github.com/ordo-one/package-jemalloc
Working copy of https://github.com/ordo-one/package-jemalloc resolved at 1.0.0
Creating working copy for https://github.com/apple/swift-argument-parser
Working copy of https://github.com/apple/swift-argument-parser resolved at 1.1.4
Creating working copy for https://github.com/swift-extras/swift-extras-json
Working copy of https://github.com/swift-extras/swift-extras-json resolved at 0.6.0
Compiling plugin Benchmark-Plugin...
Compiling plugin GenerateManualPlugin...
Building for debugging...
[147/147] Linking BenchmarkPackageTests
Build complete! (14.14s)
error: Exited with signal code 11
hassila@max /t/package-benchmark (reproducible-xcode-test-failure) [1]> 

I have set up a branch on the public repo with the reproducible crasher.

https://github.com/ordo-one/package-benchmark/tree/reproducible-xcode-test-failure

To reproduce:

  1. Install 'jemalloc' with Homebrew 'brew install jemalloc' on your macOS machine (prerequisite for project to build)
  2. Open the attached sample project with Xcode
  3. build and run the project (works fine)
  4. Run ‘swift test’ from the command line - or run the tests from Xcode

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions