Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9251] Cannot run code that imports Foundation on Linux with latest toolchain: error while loading shared libraries: libicuucswift.so.61: cannot open shared object file: No such file or directory #3591

Closed
benlangmuir opened this issue Nov 14, 2018 · 8 comments
Assignees

Comments

@benlangmuir
Copy link
Member

Previous ID SR-9251
Radar None
Original Reporter @benlangmuir
Type Bug
Status Closed
Resolution Done
Environment

Ubuntu 18.04

swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @compnerd
Priority Medium

md5: 72bacd2e697a1f289333e4bb3034a3e4

Issue Description:

A Swift binary built with the latest toolchain (swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04) will not load if Foundation has been imported:

$ cat t.swift 
import Foundation
print("hi")

$ swiftc t.swift && ./t
./t: error while loading shared libraries: libicuucswift.so.61: cannot open shared object file: No such file or directory

$ ldd t | grep icu
    libicuucswift.so.61 => not found
    libicui18nswift.so.61 => not found
    libicui18nswift.so.61 => /home/blangmuir/toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/lib/swift/linux/libicui18nswift.so.61 (0x00007f088d37d000)
    libicuucswift.so.61 => /home/blangmuir/toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/lib/swift/linux/libicuucswift.so.61 (0x00007f088cf9d000)
    libicudataswift.so.61 => /home/blangmuir/toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/lib/swift/linux/libicudataswift.so.61 (0x00007f088b3f8000)
    libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f088940e000)
    libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f08858e3000)

It works if I add /usr/lib/swift/linux to /LD_LIBRARY_PATH.

@spevans
Copy link
Collaborator

spevans commented Nov 15, 2018

It may possibly be a RUNPATH issue:

$ readelf -aW ~/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/lib/swift/linux/libswiftCore.so |grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/usr/lib/swift/linux]

$ readelf -aW ~/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so |grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/libdispatch-linux-x86_64/src] 

However the previous snapshot had:

readelf -aW ~/swift-DEVELOPMENT-SNAPSHOT-2018-11-01-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so |grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]

Note the the build system for Foundation also got moved from python/ninja to CMake between these two snapshots and the old build.py had:

$ grep -r ORIGIN build.py 
build.py:   foundation.LDFLAGS += '-ldispatch -lswiftDispatch -L'+Configuration.current.variables["LIBDISPATCH_BUILD_DIR"]+'/src -rpath \$$ORIGIN '

So it may be a case of adding a -rpath $ORIGIN to the linker for libFoundation

Note that when not including Foundation it works correctly:

$ cat t.swift 
print("hi")
$ ~/swift-DEVELOPMENT-SNAPSHOT-2018-11-13-a-ubuntu18.04/usr/bin/swiftc  t.swift  && ./t
hi

I will see if I can modify the CMake configuration for Foundation and see if that make a difference

@spevans
Copy link
Collaborator

spevans commented Nov 15, 2018

#1769

$ readelf -aW ~/swift-install/usr/lib/swift/linux/libFoundation.so |grep RUNPATH
0x000000000000001d (RUNPATH)            Library runpath: [/home/spse/swift-source/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:/home/spse/swift-source/build/buildbot_linux/libdispatch-linux-x86_64/src:$ORIGIN]
$ cat ~/src/hello.swift 
import Foundation

print("Hello")
$ ~/swift-install/usr/bin/swiftc ~/src/hello.swift && ./hello
Hello

@spevans
Copy link
Collaborator

spevans commented Nov 16, 2018

2nd fix for extra copy of `libFoundation.so`

#1776

@spevans
Copy link
Collaborator

spevans commented Nov 26, 2018

This has been fixed in swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a-ubuntu18.04

$ cat hello.swift 
import Foundation

print("Hello")
ubuntu1804:~ $ ~/swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a-ubuntu18.04/usr/bin/swiftc hello.swift && ./hello
Hello
ubuntu1804:~ spse$ ldd hello|grep icu
    libicuucswift.so.61 => /home/spse/swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a-ubuntu18.04/usr/lib/swift/linux/libicuucswift.so.61 (0x00007f669afda000)
    libicui18nswift.so.61 => /home/spse/swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a-ubuntu18.04/usr/lib/swift/linux/libicui18nswift.so.61 (0x00007f669aae4000)
    libicudataswift.so.61 => /home/spse/swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a-ubuntu18.04/usr/lib/swift/linux/libicudataswift.so.61 (0x00007f669876f000)
    libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007f6696785000)
    libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007f6692c5a000)

@benlangmuir
Copy link
Member Author

Verified with the Nov 25 toolchain. Thanks1

@norio-nomura
Copy link
Contributor

This issue happens again with swift-DEVELOPMENT-SNAPSHOT-2019-11-06-a and swift-DEVELOPMENT-SNAPSHOT-2019-11-07-a on ubuntu 16.04.
log:

$ docker run -it norionomura/swift:20191106a
root@54d16b7b3d58:/# echo 'import Foundation;print("hello")'|swiftc - -o main && ./main
./main: error while loading shared libraries: libicuucswift.so.61: cannot open shared object file: No such file or directory
root@54d16b7b3d58:/# ldd -v ./main|grep libicu
    libicuucswift.so.61 => not found
    libicui18nswift.so.61 => not found
    libicui18nswift.so.61 => /usr/lib/swift/linux/libicui18nswift.so.61 (0x00007fb10c953000)
    libicuucswift.so.61 => /usr/lib/swift/linux/libicuucswift.so.61 (0x00007fb10c57d000)
    libicudataswift.so.61 => /usr/lib/swift/linux/libicudataswift.so.61 (0x00007fb10a9d8000)
    /usr/lib/swift/linux/libicui18nswift.so.61:
    /usr/lib/swift/linux/libicuucswift.so.61:

@spevans
Copy link
Collaborator

spevans commented Nov 8, 2019

Looks like libFoundation.so has lost the $ORIGIN in its runpath. Compare

$ chrpath -l ~/swift-DEVELOPMENT-SNAPSHOT-2019-11-06-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so 
/home/spse/swift-DEVELOPMENT-SNAPSHOT-2019-11-06-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so: RUNPATH=/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/libdispatch-linux-x86_64

to:

$ chrpath -l ~/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so 
/home/spse/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu18.04/usr/lib/swift/linux/libFoundation.so: RUNPATH=/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/libdispatch-linux-x86_64:/home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/build/buildbot_linux/libdispatch-linux-x86_64/src:$ORIGIN

Probabaly a result of @compnerd's changes in #2524 migrating to CMake 3.15.1

The integration tests probably didnt catch this due to the buildpath still being in the RUNPATH (which shouldnt really be there)

@norio-nomura
Copy link
Contributor

confirmed that this issue has been resolved on swift-DEVELOPMENT-SNAPSHOT-2019-11-12-a for ubuntu 16.04.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants