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

Warn if a function is marked as both #[inline] and #[no_mangle] #72944

Closed
fschutt opened this issue Jun 3, 2020 · 2 comments · Fixed by #73034
Closed

Warn if a function is marked as both #[inline] and #[no_mangle] #72944

fschutt opened this issue Jun 3, 2020 · 2 comments · Fixed by #73034
Assignees
Labels
A-FFI Area: Foreign function interface (FFI) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fschutt
Copy link
Contributor

fschutt commented Jun 3, 2020

Code:

// src/lib.rs
#[inline] #[no_mangle] pub extern "C" fn foo() { }
# Cargo.toml
[package]
name = "foo"
version = "0.0.1"
edition = "2018"

[lib]
name = "foo"
crate-type = ["cdylib"]
cargo build --release

If the function is marked as #[inline], it doesn't get compiled into the dll file:

strings target/release/libfoo.so | grep foo

The reason a function may be marked as both #[inline] and #[no_mangle] is so that it gets inlined when compiling the crate as a rust library, but not inlined when compiling the crate as a cdylib.

There should be a warning to use something like #[cfg_attr(not(crate_type="cdylib"), inline] instead.

This issue has been assigned to @doctorn via this comment.

@Elinvynia Elinvynia added A-FFI Area: Foreign function interface (FFI) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2020
@doctorn
Copy link
Contributor

doctorn commented Jun 5, 2020

Related to #72463 - I think is that we should include #[inline]'d functions in cdylibs and staticlibs, but as a short term solution, a warning is a nice idea

@doctorn
Copy link
Contributor

doctorn commented Jun 5, 2020

@rustbot claim

@rustbot rustbot self-assigned this Jun 5, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue 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)
Manishearth added a commit to Manishearth/rust that referenced this issue 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 issue 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 bors closed this as completed in 0e332e9 Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants