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

compiler: Use LLVM's Comdat support #131876

Merged
merged 3 commits into from
Oct 20, 2024

Conversation

workingjubilee
Copy link
Member

@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. labels Oct 18, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2024

Some changes occurred in coverage instrumentation.

cc @Zalathar

@Zalathar Zalathar added A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Oct 18, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2024

These commits modify compiler targets.
(See the Target Tier Policy.)

@workingjubilee
Copy link
Member Author

These commits modify compiler targets.

They really don't they just touch the public API...

@Zalathar
Copy link
Contributor

Thanks. r=me after squishing the fixups.

@workingjubilee workingjubilee force-pushed the llvm-c-c-c-comdat branch 2 times, most recently from 268a153 to 49bb96c Compare October 19, 2024 01:08
@Zalathar
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 19, 2024

📌 Commit 49bb96c has been approved by Zalathar

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 Oct 19, 2024
Comment on lines -1661 to -1669
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V,
const char *Name, size_t NameLen) {
Triple TargetTriple = Triple(unwrap(M)->getTargetTriple());
GlobalObject *GV = unwrap<GlobalObject>(V);
if (TargetTriple.supportsCOMDAT()) {
StringRef NameRef(Name, NameLen);
GV->setComdat(unwrap(M)->getOrInsertComdat(NameRef));
}
}
Copy link
Member Author

@workingjubilee workingjubilee Oct 19, 2024

Choose a reason for hiding this comment

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

afaict the LLVM-C API doesn't have an exact match of the support check we do here, which is why I implemented it via Rust. I'll go fix that.

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Oct 19, 2024
…r=Zalathar

compiler: Use LLVM's Comdat support

Acting on these long-ago issues:
- rust-lang#46437
- rust-lang#68955
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2024
…kingjubilee

Rollup of 8 pull requests

Successful merges:

 - rust-lang#127462 (std: uefi: Add basic Env variables)
 - rust-lang#131537 (Fix range misleading field access)
 - rust-lang#131838 (bootstrap: allow setting `--jobs` in config.toml)
 - rust-lang#131871 (x86-32 float return for 'Rust' ABI: treat all float types consistently)
 - rust-lang#131876 (compiler: Use LLVM's Comdat support)
 - rust-lang#131890 (Update `use` keyword docs to describe precise capturing)
 - rust-lang#131899 (Mark unexpected variant res suggestion as having placeholders)
 - rust-lang#131908 (rustdoc: Switch from FxHash to sha256 for static file hashing.)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 19, 2024
…r=Zalathar

compiler: Use LLVM's Comdat support

Acting on these long-ago issues:
- rust-lang#46437
- rust-lang#68955
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#127462 (std: uefi: Add basic Env variables)
 - rust-lang#131537 (Fix range misleading field access)
 - rust-lang#131838 (bootstrap: allow setting `--jobs` in config.toml)
 - rust-lang#131871 (x86-32 float return for 'Rust' ABI: treat all float types consistently)
 - rust-lang#131876 (compiler: Use LLVM's Comdat support)
 - rust-lang#131890 (Update `use` keyword docs to describe precise capturing)
 - rust-lang#131899 (Mark unexpected variant res suggestion as having placeholders)
 - rust-lang#131908 (rustdoc: Switch from FxHash to sha256 for static file hashing.)
 - rust-lang#131916 (small interpreter error cleanup)
 - rust-lang#131919 (zero-sized accesses are fine on null pointers)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#131922 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 19, 2024
Comment on lines +181 to +184
let name_buf = get_value_name(val).to_vec();
let name =
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
set_comdat(llmod, val, &name);
Copy link
Contributor

@Zalathar Zalathar Oct 19, 2024

Choose a reason for hiding this comment

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

Oh, looks like we need the supports-comdat check here too.

Or maybe this is a sign that the check should be inside set_comdat instead?

Copy link
Contributor

@klensy klensy Oct 19, 2024

Choose a reason for hiding this comment

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

Isn't this because !self.is_like_aix && !self.is_like_osx should be !self.is_like_aix || !self.is_like_osx?

No.

Copy link
Member Author

@workingjubilee workingjubilee Oct 19, 2024

Choose a reason for hiding this comment

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

I mean it's really a sign that "setting a comdat" needs to be a function on the CodegenCx, imo, where we already have acquired all the info, so that it isn't called when we don't have access to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that makes sense. Happy to leave that for future work.

workingjubilee and others added 2 commits October 19, 2024 10:46
Migrate `llvm::set_comdat` and `llvm::SetUniqueComdat` to LLVM-C FFI.

Note, now we can call `llvm::set_comdat` only when the target actually
supports adding comdat. As this has no convenient LLVM-C API, we
implement this as `TargetOptions::supports_comdat`.

Co-authored-by: Stuart Cook <[email protected]>
@Zalathar
Copy link
Contributor

This succeeded in aarch64-apple, so let's try it again.

@bors r+

@bors
Copy link
Contributor

bors commented Oct 20, 2024

📌 Commit 4927600 has been approved by Zalathar

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
Rollup of 4 pull requests

Successful merges:

 - rust-lang#131876 (compiler: Use LLVM's Comdat support)
 - rust-lang#131941 (compiletest: disambiguate html-tidy from rust tidy tool)
 - rust-lang#131942 (compiler: Adopt rust-analyzer impls for `LayoutCalculatorError`)
 - rust-lang#131945 (rustdoc: Clean up footnote handling)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0bfc49b into rust-lang:master Oct 20, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
Rollup merge of rust-lang#131876 - workingjubilee:llvm-c-c-c-comdat, r=Zalathar

compiler: Use LLVM's Comdat support

Acting on these long-ago issues:
- rust-lang#46437
- rust-lang#68955
@bors
Copy link
Contributor

bors commented Oct 20, 2024

⌛ Testing commit 4927600 with merge d68c327...

@workingjubilee workingjubilee deleted the llvm-c-c-c-comdat branch October 20, 2024 07:05
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 20, 2024
…nem,workingjubilee

Make `llvm::set_section` take a `&CStr`

There's no reason to convert the section name to an intermediate `String`, when the LLVM-C API wants a C string anyway.

Follow-up to rust-lang#131876.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 20, 2024
…nem,workingjubilee

Make `llvm::set_section` take a `&CStr`

There's no reason to convert the section name to an intermediate `String`, when the LLVM-C API wants a C string anyway.

Follow-up to rust-lang#131876.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
Rollup merge of rust-lang#131962 - Zalathar:llvm-set-section, r=Swatinem,workingjubilee

Make `llvm::set_section` take a `&CStr`

There's no reason to convert the section name to an intermediate `String`, when the LLVM-C API wants a C string anyway.

Follow-up to rust-lang#131876.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants