Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

SwiftPM commands broken with swift-tensorflow-DEVELOPMENT-2019-12-19-a #347

Closed
dan-zheng opened this issue Dec 20, 2019 · 6 comments
Closed
Assignees

Comments

@dan-zheng
Copy link
Member

dan-zheng commented Dec 20, 2019

SwiftPM commands are broken with the swift-tensorflow-DEVELOPMENT-2019-12-19-a macOS toolchain:

$ swift build
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-build
  Reason: image not found
[1]    45688 abort      swift build

This error likely surfaced in the swift-DEVELOPMENT-SNAPSHOT-2019-12-16-a -> tensorflow merge: swiftlang/swift#28847.


Temporary fix: re-add the @executable_path/../lib/swift/macosx RPATH for SwiftPM tool binaries.

VERSION=swift-tensorflow-DEVELOPMENT-2019-01-30-a
sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/$VERSION.xctoolchain/usr/bin/swift-build
sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/$VERSION.xctoolchain/usr/bin/swift-package
sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/$VERSION.xctoolchain/usr/bin/swift-run
sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/$VERSION.xctoolchain/usr/bin/swift-test
sudo install_name_tool -add_rpath "@executable_path/../../../lib/swift/macosx" /Library/Developer/Toolchains/$VERSION.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper
@dan-zheng
Copy link
Member Author

dan-zheng commented Dec 20, 2019

Here's the macOS toolchain directory structure diff between swift-tensorflow-DEVELOPMENT-2019-12-19-a and the last known working toolchain (swift-tensorflow-DEVELOPMENT-2019-12-12-a):

diff --git a/Users/danielzheng/12.txt b/Users/danielzheng/19.txt
index f94b1dc..d7b5cc9 100644
--- a/Users/danielzheng/12.txt
+++ b/Users/danielzheng/19.txt
@@ -1,4 +1,4 @@
-swift-tensorflow-DEVELOPMENT-2019-12-12-a.xctoolchain
+swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain
 ├── Info.plist
 ├── System
 │   └── Library
@@ -1029,7 +1029,6 @@ swift-tensorflow-DEVELOPMENT-2019-12-12-a.xctoolchain
 │   ├── CodeRequirements-1
 │   ├── CodeResources
 │   └── CodeSignature
-├── swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain -> /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain
 └── usr
     ├── bin
     │   ├── clang -> clang-7
@@ -1832,4 +1831,4 @@ swift-tensorflow-DEVELOPMENT-2019-12-12-a.xctoolchain
         └── swift
             └── LICENSE.txt

-287 directories, 1545 files
+286 directories, 1545 files

There's no significant difference in the toolchain structure - the single-line symlink diff isn't significant. Perhaps RPATHs have changed for the swift-tensorflow-DEVELOPMENT-2019-12-19-a toolchain.

@dan-zheng
Copy link
Member Author

This appears to be an RPATH issue. RPATHs for SwiftPM tools like swift-build changed.

swift-tensorflow-DEVELOPMENT-2019-12-19-a, bad:

$ otool -l /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-build
...
Load command 30
          cmd LC_RPATH
      cmdsize 168
         path /Users/swiftninjas/s4tf/swift/swift-nightly-install/Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/lib/swift/macosx (offset 12)
Load command 31
          cmd LC_RPATH
      cmdsize 128
         path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/lib/swift (offset 12)
Load command 32
          cmd LC_RPATH
      cmdsize 32
         path @loader_path (offset 12)
Load command 33
          cmd LC_RPATH
      cmdsize 168
         path /Users/swiftninjas/s4tf/swift/swift-nightly-install/Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/lib/swift/macosx (offset 12)

swift-tensorflow-DEVELOPMENT-2019-12-12-a, good:

$ otool -l /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-12-a.xctoolchain/usr/bin/swift-build
...
Load command 28
          cmd LC_RPATH
      cmdsize 128
         path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/lib/swift (offset 12)
Load command 29
          cmd LC_RPATH
      cmdsize 32
         path @loader_path (offset 12)
Load command 30
          cmd LC_RPATH
      cmdsize 168
         path /Users/swiftninjas/s4tf/swift/swift-nightly-install/Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-12-a.xctoolchain/usr/lib/swift/macosx (offset 12)
Load command 31
          cmd LC_RPATH
      cmdsize 56
         path @executable_path/../lib/swift/macosx (offset 12)
Load command 32
          cmd LC_RPATH
      cmdsize 56
         path @executable_path/../lib/swift/pm/llbuild (offset 12)

The @executable_path/../lib/swift/macosx RPATH was removed in swiftlang/swift-package-manager#2462.

I wonder what logic adds the /Users/swiftninjas/s4tf/swift/swift-nightly-install/Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/lib/swift/macosx RPATH: this path comes from the toolchain build machine and doesn't work on machines installing the toolchain.

@dan-zheng
Copy link
Member Author

Temporary fix: re-add the @executable_path/../lib/swift/macosx RPATH for SwiftPM tool binaries.

$ sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-build
$ sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-package
$ sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-run
$ sudo install_name_tool -add_rpath "@executable_path/../lib/swift/macosx" /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-12-19-a.xctoolchain/usr/bin/swift-test

I'll ask on swiftlang/swift-package-manager#2462 to see if anyone's encountered these RPATH issues before.

Comparing RPATHs with recent swift.org/download toolchains seems productive for debugging.

@dan-zheng
Copy link
Member Author

dan-zheng commented Dec 20, 2019

The 2019-12-19 trunk development snapshot from swift.org/download has the following swift-build RPATHs:

$ otool -l /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-12-19-a.xctoolchain/usr/bin/swift-build
...
Load command 30
          cmd LC_RPATH
      cmdsize 32
         path /usr/lib/swift (offset 12)
Load command 31
          cmd LC_RPATH
      cmdsize 32
         path @loader_path (offset 12)
Load command 32
          cmd LC_RPATH
      cmdsize 224
         path /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift-nightly-install/Applications/Xcode.app/Contents/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-12-19-a.xctoolchain/usr/lib/swift/macosx (offset 12)

I think the /usr/lib/swift RPATH is key for preventing the dyld: Library not loaded: @rpath/libswiftCore.dylib error.

/usr/lib/swift isn't added as an RPATH for S4TF toolchains. This seems related to the swiftc -toolchain-stdlib-rpath flag, which is true by default on tensorflow branch but false on master branch: code here.

To support toolchains built with -toolchain-stdlib-rpath=true, perhaps re-adding the @executable_path/../lib/swift/macosx RPATH for SwiftPM tool binaries is the robust solution. I'll ask on swiftlang/swift-package-manager#2462 whether this makes sense.

@ematejska
Copy link
Contributor

Still reproduces with swift-tensorflow-DEVELOPMENT-2020-01-30-a.xctoolchain

@dan-zheng dan-zheng self-assigned this Feb 5, 2020
dan-zheng added a commit to dan-zheng/swift-package-manager that referenced this issue Feb 6, 2020
…arwin.

Add `@executable_path/../lib/swift/<platform>` RPATH on Darwin platforms.
This is necessary for experimental toolchains that include libraries not part of
the OS (e.g. `PythonKit` or `TensorFlow`).

Verified to fix SwiftPM command linker issues for Swift for TensorFlow
toolchains: tensorflow/swift#347.

Effectively reverts swiftlang#2548:
an unverified fix for the same issue that did not work.
dan-zheng added a commit to dan-zheng/swift-package-manager that referenced this issue Feb 6, 2020
Add `@executable_path/../lib/swift/<platform>` RPATH on Darwin platforms.
This is necessary for experimental toolchains that include libraries not part of
the OS (e.g. `PythonKit` or `TensorFlow`).

Verified to fix SwiftPM command linker issues for Swift for TensorFlow
toolchains: tensorflow/swift#347.

Effectively reverts swiftlang#2548:
an unverified fix for the same issue that did not work.
dan-zheng added a commit to dan-zheng/swift-package-manager that referenced this issue Feb 12, 2020
Add `@executable_path/../lib/swift/<platform>` RPATH on Darwin platforms.
This is necessary for experimental toolchains that include libraries not part of
the OS (e.g. `PythonKit` or `TensorFlow`).

Verified to fix SwiftPM command linker issues for Swift for TensorFlow
toolchains: tensorflow/swift#347.

Effectively reverts swiftlang#2548:
an unverified fix for the same issue that did not work.
@dan-zheng
Copy link
Member Author

Fixed in swiftlang/swift-package-manager#2553.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants