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

link-dead-code does not include symbols for unused inlined functions #45174

Open
malbarbo opened this issue Oct 10, 2017 · 8 comments
Open

link-dead-code does not include symbols for unused inlined functions #45174

malbarbo opened this issue Oct 10, 2017 · 8 comments
Labels
A-codegen Area: Code generation C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@malbarbo
Copy link
Contributor

Consider a file x.rs:

#[inline]
fn gggg() {}
fn main() {}

The symbol gggg is not included in the compiled binary (tested with rustc -C link-dead-code x.rs && nm x | grep gggg). If the inline attribute is removed, the symbol is included.

@michaelwoerister
Copy link
Member

This is currently expected behavior as the compiler never generates any code for #[inline] functions unless they are referenced somewhere.

@malbarbo
Copy link
Contributor Author

But this seems contrary to the intent of the link-dead-code (improve coverage accuracy, see #31368)

@michaelwoerister
Copy link
Member

Yes, I can see how that would make sense when you are interested in code coverage.

@rust-lang/dev-tools @rust-lang/compiler Do we have compiler options that are targeted specifically towards code coverage? Or should we just produce code for unused inline functions if -C link-dead-code is specified?

@malbarbo malbarbo changed the title link-dead-code does include symbols for unused inlined functions link-dead-code does not include symbols for unused inlined functions Oct 10, 2017
@alexcrichton
Copy link
Member

@michaelwoerister AFAIK we don't have many other options for code coverage, we're definitely long overdue for a flag for "I'd like to generate code coverage", but there's lots of hairy problems about implementing such a flag (e.g. inline functions today, generics, etc)

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2017

If we don't want to extend the meaning of link-dead-code, perhaps it makes sense to add something equivalent to gcc's/clang's -fkeep-inline-functions flag?

I don't feel like the smaller emit-unused-inline-functions-in-the-binary feature needs to be blocked on a more general code coverage mode.

@michaelwoerister
Copy link
Member

Yeah, adding a targeted flag instead of changing the meaning of -C link-dead-code seems to preferable to me.

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2018
@steveklabnik
Copy link
Member

Triage: I'm not aware of any changes or additions here.

@tgnottingham
Copy link
Contributor

As of rustc 1.72.0, the original repro, verbatim, doesn't reproduce the issue.

These cases still do:

  • rustc -C link-dead-code -C opt-level=1 x.rs && nm x | grep gggg
  • rustc -C link-dead-code -C lto=thin x.rs && nm x | grep gggg
  • rustc -C link-dead-code -C opt-level=1 -C lto=fat x.rs && nm x | grep gggg

While these cases do not:

  • rustc -C link-dead-code -C lto=fat x.rs && nm x | grep gggg
  • rustc -C link-dead-code -C opt-level=1 -C lto=off x.rs && nm x | grep gggg

However, if the function is instead marked #[inline(always)], the issue reproduces in all cases, including the original one.


For the #[inline(always)] issue (without the involvement of -C opt-level > 0 or -C lto=thin), the problem is that the mono item is never placed in any CGU. The reason is in part that MonoItem::instantiation_mode returns LocalCopy for the item, despite the presence of -C link-dead-code. place_mono_items doesn't place it because its instantiation mode LocalCopy, and because nothing else calls it.

It would be tempting to have MonoItem::instantiation_mode not return LocalCopy if -C link-dead-code was used, but this would cause #[inline(always)] functions to not always be inlined, and comments like #76896 (comment) make me wonder if that's a problem. On the other hand, I wonder if -C link-dead-code fundamentally relies on inlining not happening to work as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants