Skip to content

The new binaries built with Static Linux SDK crashes #6287

Closed

Description

@ainame

New Issue Checklist

Bug Description

A fully statically linked binary named swiftlint-static that does not require
any dynamic libraries at runtime. Rules requiring SourceKit will be disabled and
reported to the console when running this binary.

https://github.com/realm/SwiftLint/releases/tag/0.61.0

I have tried this new binary for Linux hoping that we can simply run SwiftLint on plain ubuntu env on GitHub Actions.
It crashed with segmentation fault when linting some code. This seems to occur on both AMD64 and ARM64.

$ ./swiftlint-static
Linting Swift files in current working directory...
....
Linting 'xxxx.swift' (57/616)
Segmentation fault (core dumped)

To reproduce the issue, I did set up Linux environment with Swiftly. I managed to get minimum input file that can reproduce the crash on linting and some backtrace by building static linux sdk binary with 0.61.0 tag locally.

Environment (I used VMware Fusion with Ubuntu Desktop image on macOS so it's ARM env)

ainame@ainame-vm:~/repos/SwiftLint$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.3 LTS
Release:	24.04
Codename:	noble
ainame@ainame-vm:~/repos/SwiftLint$ swiftly list
Installed release toolchains
----------------------------
Swift 6.1.2 (in use) (default)

Installed snapshot toolchains
-----------------------------
ainame@ainame-vm:~/repos/SwiftLint$ swift --version
Swift version 6.1.2 (swift-6.1.2-RELEASE)
Target: aarch64-unknown-linux-gnu
ainame@ainame-vm:~/repos/SwiftLint$ swift sdk list
swift-6.1.2-RELEASE_static-linux-0.0.1
ainame@ainame-vm:~/repos/SwiftLint$ swift build --product swiftlint -Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT --swift-sdk aarch64-swift-linux-musl -Xswiftc -g
ainame@ainame-vm:~/repos/SwiftLint$ lldb ./.build/debug/swiftlint
(lldb) target create "./.build/debug/swiftlint"
Current executable set to '/home/ainame/repos/SwiftLint/.build/debug/swiftlint' (aarch64).
(lldb) run --no-cache -- ./Bug.swift
Process 26811 launched: '/home/ainame/repos/SwiftLint/.build/debug/swiftlint' (aarch64)
Linting Swift files at paths ./Bug.swift
Linting 'Bug.swift' (1/1)
Process 26811 stopped
* thread #7, name = 'swiftlint', stop reason = signal SIGSEGV: invalid permissions for mapped object (fault address: 0xfffff7d34dc8)
    frame #0: 0x00000000032202f0 swiftlint`Keyword.init(text=SwiftSyntax.SyntaxText @ 0x0000fffff7d36dc8) at Keyword.swift:228
   225 	  case wrt
   226 	  case yield
   227 	
-> 228 	  @_spi(RawSyntax) public init?(_ text: SyntaxText) {
   229 	    switch text.count {
   230 	    case 2:
   231 	      switch text { 

Full backtrace from lldb is here
https://gist.github.com/ainame/9a5851a2fd5dc32b0189d38b6bbe7c57

Bug.swift that I used above is this (redacted one from actual source code from our project but still make it crash).

import Foundation
import UIKit

class CustomTextField: UIView {
    private lazy var stackView: UIStackView = {
        let stack = UIStackView(
            axis: .vertical,
            alignment: .fill,
            distribution: .fill,
            spacing: .s,
            subviews: [
                UIStackView(
                    axis: .vertical,
                    alignment: .fill,
                    distribution: .fill,
                    subviews: []
                ),
            ]
        )
        return stack
    }()
}

This of course doesn't make SwiftLint crash on macOS nor Ubuntu with normal debug build binary.

Environment

  • SwiftLint version 0.61.0 / swiftlint-static for ARM64/AMD64
  • Xcode version N/A
  • Installation method used from GitHub Release page
  • Configuration file: The issue persists with no config file

Activity

  1. ainame commented on Oct 8, 2025

    @ainame
    ContributorAuthor

    I'm assuming this is more like either SwiftSyntax or even Swift compiler's (Static Link SDK?) issue. But I haven't been able to reproduce the same error without SwiftLint code yet. Once I identify minimum reproducible code for the crash with only SwiftSyntax, I'll report this problem to more appropriate place.

  2. SimplyDanny commented on Oct 8, 2025

    @SimplyDanny
    Collaborator

    Would you please provide the configuration you are using?

  3. added
    repro-neededIssues that cannot be reproduced or miss proper descriptive examples.
    helpQuestions or user problems that require more explanation rather than code changes.
    on Oct 8, 2025
  4. ainame commented on Oct 8, 2025

    @ainame
    ContributorAuthor

    @SimplyDanny Thank you for the quick response.
    I tried with no .swiftlint.yml in place and still reproduced the crash. So the configuration is only the default settings.

  5. SimplyDanny commented on Oct 8, 2025

    @SimplyDanny
    Collaborator

    The reason for the error in the backtrace might be missing debug info from the SDK according to

    error: Error while parsing SDK path from debug info

    Not sure if this is the actual issue or a follow-up. Because I can, at the moment, not reproduce the issue on Ubuntu 24.04.

  6. ainame commented on Oct 9, 2025

    @ainame
    ContributorAuthor
    error: Error while parsing SDK path from debug info: virtual llvm::Expected<XcodeSDK> lldb_private::Platform::GetSDKPathFromDebugInfo(CompileUnit &) not implemented for 'host' platform.
    warning: (aarch64) /home/ainame/repos/SwiftLint/.build/debug/swiftlint '/home/build-user/build/swift/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/module-cache/IGW25F86HR0M/posix_semaphore-2JY1NKZGJ2QLR.pcm' does not exist
    warning: (aarch64) /home/ainame/repos/SwiftLint/.build/debug/swiftlint Unable to locate module needed for external types.
    Debugging will be degraded due to missing types. Rebuilding the project will regenerate the needed module files.
    warning: (aarch64) /home/ainame/repos/SwiftLint/.build/debug/swiftlint '/home/build-user/build/swift/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/module-cache/IGW25F86HR0M/SwiftOverlayShims-2VGX0RM8PQG1L.pcm' does not exist
    

    It looks like those warnings are produced because debug info (DWARF?) was embed in Static Linux SDK and those file paths won't be available on end-user's environment. It just degrade backtrace quality.

    And the error is just a default behaviour of LLDB on non-Darwin platform?

    https://github.com/swiftlang/llvm-project/blob/ac93ccbb3cd9d9627b55ba69400adb6479f2c87a/lldb/include/lldb/Target/Platform.h#L455-L459


    @SimplyDanny Did you test this with x86_64 or aarch64? I have only MacBook Pro so haven't tried proper debugging with x86_64 yet. (I just ran the original 0.61.0 binary on x86_64 server and saw crashes when running swiftlint-static against a whole project.)

    Regarding other configuration, I have only minimum set up on my VM.
    I got the desktop image here https://cdimage.ubuntu.com/noble/daily-live/current/
    And having these at ~/.profile

    eval "$(~/.local/bin/mise activate bash)"
    
    # Added by swiftly
    . "/home/ainame/.local/share/swiftly/env.sh" 
    
  7. SimplyDanny commented on Oct 9, 2025

    @SimplyDanny
    Collaborator

    I ran my tests on x86_64.

  8. ainame commented on Oct 9, 2025

    @ainame
    ContributorAuthor

    Now I also ran swiftlint-static against Bug.swift I shared above on x86_64 and confirmed it didn't crash. I'll try to find out minimum reproducible input file on x86_64 as well 🙇

  9. SimplyDanny commented on Oct 9, 2025

    @SimplyDanny
    Collaborator

    Also on arm64, I'm unable to see the crash. Perhaps, you could try to setup a repository with the failing example and builds on both x86_64 and arm64 GitHub Action runners?

  10. ainame commented on Oct 10, 2025

    @ainame
    ContributorAuthor

    No luck on GitHub Actions so far https://github.com/ainame/swiftlint-static-test/blob/main/.github/workflows/ci.yml

    One suspect is that unlike glibc, musl seems to use limited stack size by default. So that parser implementation like SwiftSyntax and SwiftLint using it may hit that limit.

    The default stack size for new threads on glibc is determined based on the resource limit governing the main thread’s stack (RLIMIT_STACK). It generally ends up being 2-10 MB.
    musl provides a default thread stack size of 128k (80k prior to 1.1.21).

    https://wiki.musl-libc.org/functional-differences-from-glibc.html

    This is again, just my Ubuntu VM env on aarch64, the last output [0x0000fffff7d77000-0x0000fffff7d79000) --- seems to indicate that the process exhausted all the stack available (according to ChatGPT, sorry I'm not very familiar with lldb)

    ainame@ainame-vm:~/repos/SwiftLint$ lldb ./.build/debug/swiftlint
    (lldb) target create "./.build/debug/swiftlint"
    Current executable set to '/home/ainame/repos/SwiftLint/.build/debug/swiftlint' (aarch64).
    (lldb) run --no-cache -- ./Bug.swift
    Process 74885 exited with status = 9 (0x00000009) killed
    Process 74955 launched: '/home/ainame/repos/SwiftLint/.build/debug/swiftlint' (aarch64)
    Linting Swift files at paths ./Bug.swift
    Linting 'Bug.swift' (1/1)
    Process 74955 stopped
    * thread #6, name = 'swiftlint', stop reason = signal SIGSEGV: invalid permissions for mapped object (fault address: 0xfffff7d78f40)
        frame #0: 0x0000000002ff8d10 swiftlint`Lexer.Cursor.peek(offset=1) at Cursor.swift:537
       534 	}
       535 	
       536 	extension Lexer.Cursor {
    -> 537 	  func peek(at offset: Int = 0) -> UInt8? {
       538 	    precondition(offset >= 0)
       539 	    guard offset < self.input.count else {
       540 	      return nil
    Target 0: (swiftlint) stopped.
    (lldb) register read sp
          sp = 0x0000fffff7d78eb0
    (lldb) memory region $sp
    error: Error while parsing SDK path from debug info: virtual llvm::Expected<XcodeSDK> lldb_private::Platform::GetSDKPathFromDebugInfo(CompileUnit &) not implemented for 'host' platform.
    [0x0000fffff7d77000-0x0000fffff7d79000) ---
    

    I will continue making more complex input to reliably reproduce the issue

  11. ainame commented on Oct 10, 2025

    @ainame
    ContributorAuthor

    Actually increasing stack-size from 128K to 8M fixed the crash on my VM env.

    swift build --product swiftlint -c release \
        -Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT \
        --swift-sdk aarch64-swift-linux-musl \
        -Xswiftc -g \
        -Xlinker -z -Xlinker stack-size=8388608  # => 8MiB
    

    This doesn't explain why existing 0.61.0's swiftlint-static didn't crash on my GitHub Actions though.

  12. ainame commented on Oct 10, 2025

    @ainame
    ContributorAuthor

    I managed to reproduce crashes on GitHub Actions with https://github.com/apple/swift-nio repo's source.

    /home/runner/work/swiftlint-static-test/swiftlint-static-test/swift-nio-main/Tests/NIOHTTP1Tests/ByteBufferUtilsTest.swift:13:3: warning: Comment Spacing Violation: Prefer at least one space after slashes for comments (comment_spacing)
    /home/runner/work/_temp/960a1a2a-f600-4bfb-a202-05fd9c74e271.sh: line 2: 2118 Segmentation fault (core dumped) ../swiftlint-static lint
    Error: Process completed with exit code 139.

    https://github.com/ainame/swiftlint-static-test/actions/runs/18416560762/job/52481488144
    https://github.com/ainame/swiftlint-static-test/blob/main/.github/workflows/ci.yml

    I think next step would be to try binaries built with a larger stack-size mentioned above and see if it can fix the crash on GitHub Actions.

  13. ainame commented on Oct 11, 2025

    @ainame
    ContributorAuthor

    The default thread stack-size that matches Darwin's one (512 KiB) helped.

    I created a PR for this 🙏
    #6291

  14. added
    bugUnexpected and reproducible misbehavior.
    integrationIssues related to integration of SwiftLint into toolchains.
    and removed
    repro-neededIssues that cannot be reproduced or miss proper descriptive examples.
    helpQuestions or user problems that require more explanation rather than code changes.
    on Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.integrationIssues related to integration of SwiftLint into toolchains.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions