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

lto: use the object crate to load bitcode sections #115136

Closed
wants to merge 8 commits into from

Conversation

durin42
Copy link
Contributor

@durin42 durin42 commented Aug 23, 2023

Upstream change
llvm/llvm-project@6b539f5 changed isSectionBitcode works and it now only respects .llvm.lto sections instead of also .llvmbc, which it says was never intended to be used for LTO. We already have the object crate handy, so it's easy to use that to load the section.

We have to sniff for raw bitcode files by hand, as object doesn't support those, but that's easy enough. I also look for both .llvmbc and .llvm.lto sections so that the behavior of the new code matches the old LLVM behavior exactly, though .llvm.lto sections seem to not (currently) be covered by tests.

Fixes #115069

r? @nikic
@rustbot label: +llvm-main

Upstream change
llvm/llvm-project@6b539f5 changed
`isSectionBitcode` works and it now only respects `.llvm.lto` sections
instead of also `.llvmbc`, which it says was never intended to be used
for LTO. We already have the object crate handy, so it's easy to use
that to load the section.

We have to sniff for raw bitcode files by hand, as `object` doesn't
support those, but that's easy enough. I also look for both .llvmbc and
.llvm.lto sections so that the behavior of the new code matches the old
LLVM behavior exactly, though .llvm.lto sections seem to not (currently)
be covered by tests.

r? @nikic
@rustbot label: +llvm-main
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. llvm-main Marks PRs that are making Rust work with LLVM main (this label is consumed by CI tooling) labels Aug 23, 2023
@durin42
Copy link
Contributor Author

durin42 commented Aug 29, 2023

@nikic do you need anything else from me? I see you didn't tell bors to merge this.

@nikic
Copy link
Contributor

nikic commented Aug 29, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 29, 2023

📌 Commit ee81e0d has been approved by nikic

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 29, 2023
@bors
Copy link
Collaborator

bors commented Aug 29, 2023

⌛ Testing commit ee81e0d with merge 3fc4e39defc6373c71bdab390a7e0ac2ee38b4cc...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 29, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 29, 2023
Otherwise we lose the ability to do crate-level LTO for wasm targets now
that we're loading our own bitcode sections instead of using LLVM to do
it.
@rustbot
Copy link
Collaborator

rustbot commented Aug 29, 2023

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@durin42
Copy link
Contributor Author

durin42 commented Aug 29, 2023

@nikic back to you, I'm afraid: we had to enable the wasm feature in object otherwise wasm targets end up broken.

Sigh.

@rust-log-analyzer

This comment has been minimized.

We already allow enough cousins of this license I can't imagine it being
a problem.
@durin42
Copy link
Contributor Author

durin42 commented Aug 30, 2023

@bjorn3 should I just go back to calling the LLVM method if the file magic lines up with wasm?

@bjorn3
Copy link
Member

bjorn3 commented Aug 30, 2023

I think the bitcode will likely stay in a custom section, so using object will work fine. And if it no longer ends up in a custom section in the future you could either switch back or hopefully object supports actually parsing wasm object with the linking custom section files by then.

@durin42
Copy link
Contributor Author

durin42 commented Aug 30, 2023

Okay, so it sounds like this is probably fine for now?

@durin42 durin42 requested a review from nikic August 30, 2023 16:34
@zmodem
Copy link
Contributor

zmodem commented Sep 4, 2023

Do I understand correctly that this is just waiting for review from @nikic now?

@durin42
Copy link
Contributor Author

durin42 commented Sep 4, 2023 via email

@nikic
Copy link
Contributor

nikic commented Sep 4, 2023

r=me on the code change, but I believe the license needs to go under EXCEPTIONS, because it doesn't comply with Rust's license policy, so it's only allowed by dint of being a rustc only dep. Would be great if someone (@wesleywiser?) can confirm the license situation here.

@durin42
Copy link
Contributor Author

durin42 commented Sep 6, 2023

@wesleywiser do you need anything from me on the license front here?

@zmodem
Copy link
Contributor

zmodem commented Sep 6, 2023

We just tried cherry-picking this in Chromium, but it seems that on Mac this actually breaks tests/codegen/lto-removes-invokes.rs rather than fixing it (https://crbug.com/1476119#c3). Is there some CI that runs on Mac that can be triggered here?

@davidtwco
Copy link
Member

We just tried cherry-picking this in Chromium, but it seems that on Mac this actually breaks tests/codegen/lto-removes-invokes.rs rather than fixing it (https://crbug.com/1476119#c3). Is there some CI that runs on Mac that can be triggered here?

CI on macOS will be run during the merge testing so if there's a failure there then it'll be fixed before this gets merged.

@davidtwco
Copy link
Member

r=me on the code change, but I believe the license needs to go under EXCEPTIONS, because it doesn't comply with Rust's license policy, so it's only allowed by dint of being a rustc only dep. Would be great if someone (@wesleywiser?) can confirm the license situation here.

I think this is okay because the dependency is Apache 2.0 with LLVM Exception licensed, which is compatible with rustc's license.

@davidtwco
Copy link
Member

@bors r=nikic,davidtwco

@bors
Copy link
Collaborator

bors commented Sep 6, 2023

📌 Commit 3259458 has been approved by nikic,davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2023
@bors
Copy link
Collaborator

bors commented Sep 6, 2023

⌛ Testing commit 3259458 with merge c13be90883040fb63be9188e57aab4df0b1689d3...

@rust-log-analyzer
Copy link
Collaborator

The job dist-powerpc-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Collaborator

bors commented Sep 6, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 6, 2023
@nikic
Copy link
Contributor

nikic commented Sep 6, 2023

So, it looks like wasmparser needs AtomicU64 in the current implementation at least.

Given that using the object crate seems to be more complicated than I anticipated, I'd be fine with staying with an LLVM-based implementation (just with our own implementation of findBitcodeInMemBuffer looking for different sections).

@durin42
Copy link
Contributor Author

durin42 commented Sep 7, 2023

@rustbot label: -llvm-main

@rustbot rustbot removed the llvm-main Marks PRs that are making Rust work with LLVM main (this label is consumed by CI tooling) label Sep 7, 2023
@durin42
Copy link
Contributor Author

durin42 commented Sep 8, 2023

Obsoleted by #115641

@durin42 durin42 closed this Sep 8, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2023
lto: load bitcode sections by name

Upstream change
llvm/llvm-project@6b539f5 changed `isSectionBitcode` works and it now only respects `.llvm.lto` sections instead of also `.llvmbc`, which it says was never intended to be used for LTO. We instead load sections by name, and sniff for raw bitcode by hand.

This is an alternative approach to rust-lang#115136, where we tried the same thing using the `object` crate, but it got too fraught to continue.

r? `@nikic`
`@rustbot` label: +llvm-main
@durin42 durin42 deleted the llvm-18-fatlto-breakage branch October 20, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LLVM 18 breakage: failed to get bitcode from object file after LLVM 6b539f5eb8e
9 participants