Skip to content

attach global target features to module-level assembly - #160594

Open
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:asm-forward-target-features
Open

attach global target features to module-level assembly#160594
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:asm-forward-target-features

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor
  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

fixes #80608
fixes #127269

At long last, we can forward global target features to LLVM and it will preserve the target features a block of module-level assembly was defined with through LTO.

cc @nikic (who made this happen)
cc @RalfJung any nasty side-effects we might be overlooking here?

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Aug 5, 2026
@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 Aug 5, 2026
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 75 candidates
  • Random selection from 17 candidates

Props.TargetFeatures = StringRef(TargetFeatures, TargetFeaturesLen);
Props.TargetCPU = StringRef(TargetCPU, TargetCPULen);
unwrap(M)->appendModuleInlineAsm(
Module::GlobalAsmFragment(std::string(Asm, AsmLen), std::move(Props)));

@folkertdev folkertdev Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • the std::move is required here. It isn't there in some of the LLVM source, I'm not sure why, but llvm complains loudly without it.
  • I believe this needs a std::string instead of a StringRef because GlobalAsmFragment needs something owned. Hopefully this is right in terms of ownership and cleanup?

View changes since the review

|
LL | .intel_syntax noprefix
| ^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

@folkertdev folkertdev Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no idea where this comes from

View changes since the review

llvm::append_module_inline_asm(llmod, &asm, "", "");
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, &[]);
llvm::append_module_inline_asm(llmod, &asm);
llvm::append_module_inline_asm(llmod, &asm, "", "");

@folkertdev folkertdev Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe we just embed bytes here, so the target features and cpu don't seem relevant.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@RalfJung

RalfJung commented Aug 5, 2026

Copy link
Copy Markdown
Member

any nasty side-effects we might be overlooking here?

I don't have the slightest clue what it means to forward target features to assembly.^^

@folkertdev

Copy link
Copy Markdown
Contributor Author

Fair. So what this does is attach the target features and cpu information to piece of assembly. Previously the target information would sometimes get lost, especially when doing LTO and potentially merging modules with different target features. LLVM would error when assembly used instructions that are gated on a particular target feature, even though the feature is in fact globally enabled.

My practical question for you is: am I forwarding the right target features here? and might a particular target cpu that we forward imply target features that we didn't intend to enable?

@folkertdev
folkertdev force-pushed the asm-forward-target-features branch from 9bd2882 to 48835fa Compare August 5, 2026 22:37
@folkertdev folkertdev changed the title forward global target features to module-level assembly attach global target features to module-level assembly Aug 5, 2026
@rust-log-analyzer

This comment has been minimized.

@RalfJung

RalfJung commented Aug 6, 2026

Copy link
Copy Markdown
Member

I have no idea, sorry. I don't even know which potential problems one has to be aware of here.

@folkertdev
folkertdev force-pushed the asm-forward-target-features branch from 48835fa to fad8008 Compare August 6, 2026 08:57
@rust-log-analyzer

This comment has been minimized.

@folkertdev
folkertdev force-pushed the asm-forward-target-features branch from fad8008 to e416dec Compare August 6, 2026 09:45
@petrochenkov

Copy link
Copy Markdown
Contributor

r? @nikic

@rustbot rustbot assigned nikic and unassigned petrochenkov Aug 6, 2026
@rust-log-analyzer

This comment has been minimized.

@folkertdev
folkertdev force-pushed the asm-forward-target-features branch from e416dec to 9e1ce26 Compare August 6, 2026 10:56
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

6 participants