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-14981] The new swift-driver is incorrectly adding an autolink file to linux static libraries #57323

Closed
finagolfin opened this issue Jul 27, 2021 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. transfer candidate The issue may belong in another repository

Comments

@finagolfin
Copy link
Contributor

Previous ID SR-14981
Radar rdar://problem/81165415
Original Reporter @buttaface
Type Bug
Status Resolved
Resolution Done
Environment

Fedora Core 33

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

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.

@drexin
Copy link
Member

drexin commented Jul 27, 2021

@swift-ci create

@finagolfin
Copy link
Contributor Author

It turns out @compnerd has already submitted a pull to fix this, just need to get it in:

apple/swift-driver#773

@finagolfin
Copy link
Contributor Author

There was a question of whether this is reproducible with Swift 5.5, here's an easy command to check:
> ./swift-5.5-DEVELOPMENT-SNAPSHOT-2021-07-27-a-centos8/usr/bin/swiftc -emit-library swift/test/Interpreter/Inputs/lto/module1.swift -module-name Test -v -static
...
/usr/bin/ar crs libTest.a /tmp/TemporaryDirectory.nkxsr7/module1-1.o /tmp/TemporaryDirectory.nkxsr7/Test-1.autolink

It's been in the 5.5 snapshots since May.

@finagolfin
Copy link
Contributor Author

Trunk fix is in, just need to get it into 5.5 now:

apple/swift-driver#777

@dduan
Copy link
Collaborator

dduan commented Feb 6, 2022

On the rare chance someone encountered this: this was NOT fixed in 5.5, but it was fixed since 5.5.2 (maybe 5.5.1, too, I didn't check).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added transfer candidate The issue may belong in another repository and removed compiler The Swift compiler in itself labels Nov 6, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. transfer candidate The issue may belong in another repository
Projects
None yet
Development

No branches or pull requests

4 participants