swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.46k stars 10.35k forks source link

Xcode build fails if using Swift.org toolchain when Address Sanitizer is enabled. #72878

Open bwhiteley opened 6 months ago

bwhiteley commented 6 months ago

Description

If I install a toolchain from Swift.org and enable Address Sanitizer for an iOS scheme, Xcode quickly fails the build with

note: Using global toolchain override 'Swift 5.10 Release 2024-03-04 (a)'. 
error: Could not get lib darwin path (in target '<MyApp>' from project '<MyApp>')

If I use the Xcode default toolchain, it will work.

What does the Swift.org toolchain need to make it compatible with Xcode + asan? Is there a workaround for this?

Reproduction

  1. You'll need an iOS project with Xcode.

  2. Download and install a toolchain from https://www.swift.org/download/ . For example, swift-5.10-RELEASE for Xcode 15.3.

  3. Select the Swift.org toolchain in Xcode: Xcode -> Toolchains -> Swift 5.10 Release ...

  4. Enable Address Sanitizer in the build scheme.

    image
  5. Build The build will quickly fail with

    note: Using global toolchain override 'Swift 5.10 Release 2024-03-04 (a)'. 
    error: Could not get lib darwin path (in target '<MyApp>' from project '<MyApp>')

Expected behavior

The build should work with asan support.

Environment

Xcode 15.3 with the toolchain downloaded from https://download.swift.org/swift-5.10-release/xcode/swift-5.10-RELEASE/swift-5.10-RELEASE-osx.pkg

Additional information

No response

drodriguez commented 6 months ago

@shahmishal, in case you are interested. It also happens in macOS ASAN, from what I was able to test.

pudge62 commented 4 days ago

@bwhiteley try to change the value of COMPILER_RT_ENABLE_IOS to TRUE in the files utils/swift_build_support/swift_build_support/products/cmake_product.py and utils/build-script-impl.

drodriguez commented 4 days ago

@pudge62 the problem was also happening when building for macOS, which I imagine COMPILER_RT_ENABLE_IOS would not help. In any case, I tried and I got the same results as before. Xcode 16 changed the error to "Unable to copy Address Sanitizer library: Could not determine where it lives." but still the same results.

pudge62 commented 3 days ago

@drodriguez In my case, the toolchain can build tsan for macos, but not work for ios simulator. These sanitizer libraries are at xxx.xctoolchain/usr/lib/clang/xxx/lib/darwin, you can check if libclang_rt.asan_xxx_dynamic.dylib exists.

drodriguez commented 2 days ago

The files exist, and trying to use them with the right command line flags works correctly in our tests. The only thing that doesn't seem to collaborate is the checkmark in the scheme editor in Xcode. It is probably checking for the existence of the file somehow, but for some reason it doesn't find it where the open source toolchains leave it.