Skip to content

Fix EII function aliases eliminated by LTO#153648

Open
AsakuraMizu wants to merge 1 commit intorust-lang:mainfrom
AsakuraMizu:fix-eii-lto-alias
Open

Fix EII function aliases eliminated by LTO#153648
AsakuraMizu wants to merge 1 commit intorust-lang:mainfrom
AsakuraMizu:fix-eii-lto-alias

Conversation

@AsakuraMizu
Copy link
Contributor

@AsakuraMizu AsakuraMizu commented Mar 10, 2026

Add EII function aliases to llvm.compiler.used so that LLVM's LTO passes do not eliminate them.

Fixes #153645

Tracking issue: #125418

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Mar 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2026

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@rustbot

This comment has been minimized.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 10, 2026

r? jdonszelmann

@bjorn3
Copy link
Member

bjorn3 commented Mar 10, 2026

I'm not sure if this is the right fix. They might need to be added to exported_symbols_for_lto instead. Otherwise they can still be made private by LTO, which would break dylibs. And I don't know if for_each_exported_symbols_include_dep already contains them to (for proper exporting during linking)

@jdonszelmann
Copy link
Contributor

hm, I wonder what the difference is between aliases and these shims. These shims pretty much act like aliases, and their symbol is the same as the EII declatation's. We already handle those symbols specially in a few places (look for the aliases field on CodegenAttrs). In fact, I personally thought we already kept them alive enough. I guess functions are optimized differently which makes some sense. In any case, I expect the problem to fundamentally also affect aliases of statics, something we don't test much at the moment, so the solution should apply to all aliases, not just these shims.

ExportedSymbol::NonGeneric(foreign_item),
SymbolExportInfo {
level: info.level,
kind: SymbolExportKind::Text,
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be SymbolExportKind::Data if the alias points to a data object.

@AsakuraMizu
Copy link
Contributor Author

I'm not sure if this is the right fix. They might need to be added to exported_symbols_for_lto instead. Otherwise they can still be made private by LTO, which would break dylibs. And I don't know if for_each_exported_symbols_include_dep already contains them to (for proper exporting during linking)

Thank you for your comment. My previous attempt was more of a hack than a fix. So I redesigned a better solution based on your suggestion. This should fix both my issue and #151271 now.

In any case, I expect the problem to fundamentally also affect aliases of statics, something we don't test much at the moment, so the solution should apply to all aliases, not just these shims.

The new attempt will apply to any foreign_item_symbol_aliases now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Externally Implementable Items: error: undefined symbol when opt-level >= 1

6 participants