[SR-14981] The new swift-driver is incorrectly adding an autolink file to linux static libraries #57323
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
transfer candidate
The issue may belong in another repository
Environment
Fedora Core 33
Additional Detail from JIRA
md5: c5d62db86a6b10ec660b52d09358b05e
Issue Description:
I've been seeing this for months when cross-compiling trunk Foundation for Android, which would manifest when linking plutil against libFoundation.a in that build, so I worked around it by disabling building plutil in my Swift 5.5 snapshot builds for Android and trunk. I figured it was a trunk issue that would go away in time, but months later, it's still there in trunk and the 5.5 branch, so I looked into it this weekend.
The problem is most easily reproduced on linux when building the early swift-driver with a recent host toolchain, with something like this command:
> PATH=/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-07-24-a-centos8/usr/bin:$PATH ./swift/utils/build-script -RA --verbose-build
That fails when building the Yams dependency with CMake, with the following output:
Building Swift Driver dependency: Yams
/usr/bin/cmake -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_BUILD_TYPE:=Release -DCMAKE_Swift_FLAGS=-module-cache-path "/home/butta/src/build/Ninja-Release/earlyswiftdriver-linux-x86_64/module-cache" -target x86_64-unknown-linux-gnu -DCMAKE_Swift_COMPILER:=/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-07-24-a-centos8/usr/bin/swiftc -DCMAKE_C_COMPILER:=clang -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -target x86_64-unknown-linux-gnu /home/butta/src/yams
...
error: autolink-extract command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: error opening input file 'lib/libYamsTests.a' (The file was not recognized as a valid object file)
ninja: build stopped: subcommand failed.
This is reproducible with a recent official Swift 5.5 snapshot build for linux but not the latest 5.4.2 release.
My testing shows the problem is that autolink-extract chokes on an autolink file added to that Swift static library by the Swift compiler, which isn't there when built with Swift 5.4 and the old C++ driver:
> ar t build/Ninja-Release/earlyswiftdriver-linux-x86_64/release/dependencies/yams/lib/libYamsTests.a
...
YamlErrorTests.swift.o
YamsTests.autolink
I tracked the problem to the new swift-driver in the host toolchain as this bug goes away if I pass in `-disallow-use-new-driver` when building the static libraries, and bisecting with old official trunk snapshot builds has it first showing up in the May 11 snapshot build, which is when we switched over to the new swift-driver.
It appears the upcoming 5.5 release would break Swift packages like Yams, that use CMake and static libraries on linux, unless this is fixed, which may not be that many people as I appear to be the first to report this.
I'm looking in the new swift-driver for the bug but I'm not that familiar with its source, so if someone who is can fix this quickly, please go right ahead.
@artemcm or @drexin, that's probably one of you.
The text was updated successfully, but these errors were encountered: