Skip to content

Add test fixture for experimental-lto-mode #6891

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

Merged
merged 5 commits into from
Dec 6, 2023
Merged

Add test fixture for experimental-lto-mode #6891

merged 5 commits into from
Dec 6, 2023

Conversation

rauhul
Copy link
Member

@rauhul rauhul commented Sep 12, 2023

Adds a test covering experimental lto mode and fixes a bug where the
lto mode was not passed to the linker.

Fixes #6888

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

@swift-ci please smoke test

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

[12/14] Write Objects.LinkFileList
error: autolink-extract command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: error opening input file '/tmp/Miscellaneous_LTO_SwiftAndCTargets.GHkhKS/Miscellaneous_LTO_SwiftAndCTargets/.build/x86_64-unknown-linux-gnu/debug/cLib.build/cLib.c.o' (The file was not recognized as a valid object file)

@fabianfett it looks lto (as currently implemented) just doesn't work on linux! Thanks for the report!

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

The error comes from swift-autolink-extract, which I know nothing about...

/usr/bin/swift-autolink-extract /swift-package-manager/Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.build/aarch64-unknown-linux-gnu/debug/cLib.build/cLib.c.o /swift-package-manager/Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.build/aarch64-unknown-linux-gnu/debug/exe.build/exe.swiftmodule.o /swift-package-manager/Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.build/aarch64-unknown-linux-gnu/debug/swiftLib.build/swiftLib.swiftmodule.o -o /swift-package-manager/Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.build/aarch64-unknown-linux-gnu/debug/cLib.build/exe.autolink
error: autolink-extract command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: error opening input file '/swift-package-manager/Fixtures/Miscellaneous/LTO/SwiftAndCTargets/.build/aarch64-unknown-linux-gnu/debug/cLib.build/cLib.c.o' (The file was not recognized as a valid object file

@neonichu
Copy link
Contributor

Maybe @artemcm does

@artemcm
Copy link
Contributor

artemcm commented Sep 12, 2023

swift-autolink-extract takes as input all the object files from compilation commands in order to extract auto-linking directives so that they can be specified as explicit flags to the linker, because non-Darwin linkers do not have auto-linking feature. It is strange why LLVM is not recognizing this object file as a valid .o.

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

swift-autolink-extract takes as input all the object files from compilation commands in order to extract auto-linking directives so that they can be specified as explicit flags to the linker, because non-Darwin linkers do not have auto-linking feature. It is strange why LLVM is not recognizing this object file as a valid .o.

Well this file doesn't exist on disk because the file extension is .bc right?

./.build/aarch64-unknown-linux-gnu/debug/swiftLib.build/swiftLib.swift.bc
./.build/aarch64-unknown-linux-gnu/debug/exe.build/main.swift.bc

@artemcm
Copy link
Contributor

artemcm commented Sep 12, 2023

swift-autolink-extract takes as input all the object files from compilation commands in order to extract auto-linking directives so that they can be specified as explicit flags to the linker, because non-Darwin linkers do not have auto-linking feature. It is strange why LLVM is not recognizing this object file as a valid .o.

Well this file doesn't exist on disk because the file extension is .bc right?

./.build/aarch64-unknown-linux-gnu/debug/swiftLib.build/swiftLib.swift.bc
./.build/aarch64-unknown-linux-gnu/debug/exe.build/main.swift.bc

Ah, then we need to teach the driver about how this works, I believe it is just forwarding compilation outputs to swift-autolink-extract.

@rauhul
Copy link
Member Author

rauhul commented Sep 12, 2023

swift-autolink-extract takes as input all the object files from compilation commands in order to extract auto-linking directives so that they can be specified as explicit flags to the linker, because non-Darwin linkers do not have auto-linking feature. It is strange why LLVM is not recognizing this object file as a valid .o.

Well this file doesn't exist on disk because the file extension is .bc right?

./.build/aarch64-unknown-linux-gnu/debug/swiftLib.build/swiftLib.swift.bc
./.build/aarch64-unknown-linux-gnu/debug/exe.build/main.swift.bc

Ah, then we need to teach the driver about how this works, I believe it is just forwarding compilation outputs to swift-autolink-extract.

I'm a little confused because we use .bc because that's the extension the driver chooses

@artemcm
Copy link
Contributor

artemcm commented Sep 12, 2023

swift-autolink-extract takes as input all the object files from compilation commands in order to extract auto-linking directives so that they can be specified as explicit flags to the linker, because non-Darwin linkers do not have auto-linking feature. It is strange why LLVM is not recognizing this object file as a valid .o.

Well this file doesn't exist on disk because the file extension is .bc right?

./.build/aarch64-unknown-linux-gnu/debug/swiftLib.build/swiftLib.swift.bc
./.build/aarch64-unknown-linux-gnu/debug/exe.build/main.swift.bc

Ah, then we need to teach the driver about how this works, I believe it is just forwarding compilation outputs to swift-autolink-extract.

I'm a little confused because we use .bc because that's the extension the driver chooses

This job must not be configured correctly. It cannot accept .bc files, so it must not have been taught about these compilation flows before now.

@rauhul
Copy link
Member Author

rauhul commented Sep 18, 2023

@artemcm would teaching lib/DriverTool/autolink_extract_main.cpp about llvm bitcode files (how to open/load/search for the auto link section) be the right approach to fix this?

@artemcm
Copy link
Contributor

artemcm commented Sep 18, 2023

@artemcm would teaching lib/DriverTool/autolink_extract_main.cpp about llvm bitcode files (how to open/load/search for the auto link section) be the right approach to fix this?

Reading the code, I get the impression that if we're using LTO, then we're using lld, which natively supports auto-linking with ELF.
(https://github.com/apple/swift/blob/3a05e798e6d045bb25e7539e07b870994bc88884/lib/IRGen/IRGenModule.cpp#L1701)

So I wonder if we can simply teach the driver that this flow does not require autolink-extract, and the rest of compilation downstream will "just work". Are you able to check this at desk? I won't be near a Linux box until tomorrow.

@artemcm
Copy link
Contributor

artemcm commented Sep 18, 2023

Hmm, the driver is already supposed to skip swift-autolink-extract when it knows we're doing LTO.
https://github.com/apple/swift/blob/3a05e798e6d045bb25e7539e07b870994bc88884/lib/Driver/Driver.cpp#L2255
https://github.com/apple/swift-driver/blob/e48171a466d624abdeaee3ea5d7a8b7237fda1eb/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift#L21

So we need to figure out why we're still generating this job here.

@rauhul
Copy link
Member Author

rauhul commented Sep 18, 2023

Hmm, the driver is already supposed to skip swift-autolink-extract when it knows we're doing LTO. https://github.com/apple/swift/blob/3a05e798e6d045bb25e7539e07b870994bc88884/lib/Driver/Driver.cpp#L2255 https://github.com/apple/swift-driver/blob/e48171a466d624abdeaee3ea5d7a8b7237fda1eb/Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift#L21

So we need to figure out why we're still generating this job here.

Oh I see, that is interesting.

Are you able to check this at desk? I won't be near a Linux box until tomorrow.

I've been running under docker to repro this issue. But I guess the question is why the driver doesn't see this link command as an lto job.

Lemme try to get the full swiftc command and maybe that will provide some clues.

@rauhul
Copy link
Member Author

rauhul commented Sep 18, 2023

@artemcm here's a verbose build log:
build.log

@rauhul
Copy link
Member Author

rauhul commented Sep 18, 2023

Maybe its as simple as adding --lto <#LTOKind#> to the swiftc call which spm produces

@rauhul
Copy link
Member Author

rauhul commented Sep 21, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Sep 21, 2023

@swift-ci please smoke test windows

@rauhul
Copy link
Member Author

rauhul commented Nov 3, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Nov 3, 2023

@swift-ci please smoke test windows

@rauhul rauhul marked this pull request as ready for review November 3, 2023 21:14
@rauhul
Copy link
Member Author

rauhul commented Nov 3, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Nov 3, 2023

@swift-ci please smoke test windows

@shahmishal
Copy link
Member

@swift-ci please smoke test windows

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

add a verbose flag to be able to help debug why this fixture is failing
on linux
@rauhul
Copy link
Member Author

rauhul commented Nov 6, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Nov 9, 2023

swiftlang/swift#69696
@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Nov 9, 2023

swiftlang/swift#69564
@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Dec 5, 2023

@swift-ci please test

@rauhul
Copy link
Member Author

rauhul commented Dec 6, 2023

@swift-ci please test

@rauhul rauhul enabled auto-merge (squash) December 6, 2023 05:28
@rauhul
Copy link
Member Author

rauhul commented Dec 6, 2023

@swift-ci please test

try fixture(name: "Miscellaneous/LTO/SwiftAndCTargets") { fixturePath in
do {
let output = try executeSwiftBuild(
fixturePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be using a mix of 4 and 2-space formatting. Additionally, why wrap this in do/catch if try fixture(name:) would be rethrowing the error anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had added XCTFail("\(error)") to help with debugging, removing and fixing indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 93f7309f8a58c7f6cce5827c254af5e8015d3eb2

@rauhul
Copy link
Member Author

rauhul commented Dec 6, 2023

@swift-ci please test

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@rauhul rauhul merged commit 906afa4 into main Dec 6, 2023
@rauhul rauhul deleted the lto-test-fixture branch December 6, 2023 20:27
@MaxDesiatov MaxDesiatov restored the lto-test-fixture branch December 7, 2023 16:18
@MaxDesiatov MaxDesiatov added bug build system Changes to interactions with build systems labels Dec 7, 2023
@MaxDesiatov MaxDesiatov deleted the lto-test-fixture branch December 7, 2023 16:25
MaxDesiatov added a commit that referenced this pull request Dec 11, 2023
Cherry-pick of #6891.

Adds a test covering experimental LTO mode and fixes a bug where the LTO
mode was not passed to the linker.

Fixes #6888

---------

Co-authored-by: Rauhul Varma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build system Changes to interactions with build systems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not build swift-nio example NIOUDPEchoServer with --experimental-lto-mode=full
5 participants