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

Export #[inline] fns with extern indicators #73034

Merged
merged 7 commits into from
Jun 19, 2020
Merged

Export #[inline] fns with extern indicators #73034

merged 7 commits into from
Jun 19, 2020

Conversation

doctorn
Copy link
Contributor

@doctorn doctorn commented Jun 5, 2020

In ancient history (#36280) we stopped #[inline] fns being codegened if they weren't used. However,

observe that when writing something like

#![crate_type = "cdylib"]

#[no_mangle]
#[inline]
pub extern "C" fn foo() {
    // ...
}

we really do want foo to be codegened. This change makes this the case.

Resolves #72944, resolves #72463 (and maybe some more)

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 5, 2020
// with "internal" linkage and are never exported unless we're
// building a `staticlib` or `cdylib` and they are marked
// `#[no_mangle]`.
tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_MANGLE)
Copy link
Member

Choose a reason for hiding this comment

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

There is also #[export_name = "..."] and #[linkage = "..."] to consider so this should really be calling contains_extern_indicator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware of contains_extern_indicator, thank you so much for the suggestion!

// `#[no_mangle]`.
tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_MANGLE)
&& (tcx.sess.crate_types().contains(&CrateType::Cdylib)
|| tcx.sess.crate_types().contains(&CrateType::Staticlib))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check the crate type here? Even when building rlibs we'll still need to codegen and export #[no_mangle] #[inline] items in case they're linked into a staticlib or cdylib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to check I understand between these two you're saying that #[inline] should always be superseded by an extern indicator and crate-type/specifics of indicator are irrelevant?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this should be done regardless of the output crate type.

@doctorn doctorn requested review from Amanieu and ollie27 June 8, 2020 08:37
@doctorn doctorn changed the title Export #[inline] #[no_mangle] fns in cdylibs and staticlibs Export #[inline] fns with extern indicators Jun 8, 2020
@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 9, 2020

📌 Commit f57893b has been approved by matthewjasper

@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 Jun 9, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jun 11, 2020
…matthewjasper

Export `#[inline]` fns with extern indicators

In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However,

- rust-lang#72944
- rust-lang#72463

observe that when writing something like

```rust
#![crate_type = "cdylib"]

#[no_mangle]
#[inline]
pub extern "C" fn foo() {
    // ...
}
```

we really _do_ want `foo` to be codegened. This change makes this the case.

Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
@Aaron1011
Copy link
Member

@bors r-

Failed in #73240 (comment): The function random_inline in test codegen/sanitizer-no-sanitize-inlining.rs no longer gets the fastcc calling convention assigned by LLVM, since it is now visible outside of the module.

@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 Jun 11, 2020
@Dylan-DPC-zz
Copy link

failed in rollup log

@bors r-

@doctorn
Copy link
Contributor Author

doctorn commented Jun 15, 2020

@bors r-

Failed in #73240 (comment): The function random_inline in test codegen/sanitizer-no-sanitize-inlining.rs no longer gets the fastcc calling convention assigned by LLVM, since it is now visible outside of the module.

I can't reproduce this locally, is this an architecture specific failure?

@mati865
Copy link
Contributor

mati865 commented Jun 15, 2020

@doctorn do you have sanitizers enabled?

#sanitizers = false

@doctorn
Copy link
Contributor Author

doctorn commented Jun 15, 2020

@mati865 that'll do it 😅 Thanks!

@doctorn
Copy link
Contributor Author

doctorn commented Jun 15, 2020

So looking into this, random_inline only needs to be no_mangle so that it can be mentioned in the test, can we have a private #[no_export] attribute to deal with this kind of case?

@doctorn
Copy link
Contributor Author

doctorn commented Jun 15, 2020

I've update the sanitizer test so that it doesn't depend on the #[inline] symbol meaning that it's ok to mangle it

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 15, 2020

📌 Commit e8e0a0e has been approved by matthewjasper

@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 Jun 15, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 16, 2020
…matthewjasper

Export `#[inline]` fns with extern indicators

In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However,

- rust-lang#72944
- rust-lang#72463

observe that when writing something like

```rust
#![crate_type = "cdylib"]

#[no_mangle]
#[inline]
pub extern "C" fn foo() {
    // ...
}
```

we really _do_ want `foo` to be codegened. This change makes this the case.

Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 18, 2020
…matthewjasper

Export `#[inline]` fns with extern indicators

In ancient history (rust-lang#36280) we stopped `#[inline]` fns being codegened if they weren't used. However,

- rust-lang#72944
- rust-lang#72463

observe that when writing something like

```rust
#![crate_type = "cdylib"]

#[no_mangle]
#[inline]
pub extern "C" fn foo() {
    // ...
}
```

we really _do_ want `foo` to be codegened. This change makes this the case.

Resolves rust-lang#72944, resolves rust-lang#72463 (and maybe some more)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 19, 2020
…arth

Rollup of 17 pull requests

Successful merges:

 - rust-lang#70551 (Make all uses of ty::Error delay a span bug)
 - rust-lang#71338 (Expand "recursive opaque type" diagnostic)
 - rust-lang#71976 (Improve diagnostics for `let x += 1`)
 - rust-lang#72279 (add raw_ref macros)
 - rust-lang#72628 (Add tests for 'impl Default for [T; N]')
 - rust-lang#72804 (Further tweak lifetime errors involving `dyn Trait` and `impl Trait` in return position)
 - rust-lang#72814 (remove visit_terminator_kind from MIR visitor)
 - rust-lang#72836 (Complete the std::time documentation to warn about the inconsistencies between OS)
 - rust-lang#72968 (Only highlight doc search results via mouseover if mouse has moved)
 - rust-lang#73034 (Export `#[inline]` fns with extern indicators)
 - rust-lang#73315 (Clean up some weird command strings)
 - rust-lang#73320 (Make new type param suggestion more targetted)
 - rust-lang#73361 (Tweak "non-primitive cast" error)
 - rust-lang#73425 (Mention functions pointers in the documentation)
 - rust-lang#73428 (Fix typo in librustc_ast docs)
 - rust-lang#73447 (Improve document for `Result::as_deref(_mut)` methods)
 - rust-lang#73476 (Added tooltip for should_panic code examples)

Failed merges:

r? @ghost
@bors bors merged commit 0e332e9 into rust-lang:master Jun 19, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet