Skip to content

hexagon: use a single global_asm! block for source-order stability - #1241

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
androm3da:fix/hexagon-global-asm-merge
Jul 28, 2026
Merged

hexagon: use a single global_asm! block for source-order stability#1241
tgross35 merged 1 commit into
rust-lang:mainfrom
androm3da:fix/hexagon-global-asm-merge

Conversation

@androm3da

@androm3da androm3da commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Since rust-lang/rust#145358 ("Sort mono items by symbol name", merged 2025-08-22), rustc sorts mono items within a codegen unit by symbol name rather than source order unless -Zcodegen-source-order is passed.

That breaks func_macro.s, which defines asm macros for use by "later" files.

Merge all includes into one global_asm! call. A single MonoItem cannot be reordered against itself, so the source order becomes the order the assembler sees. The file set and its order are unchanged, and all these items already shared one codegen unit, so object-file granularity is unaffected.

Closes: #1240

Since rust-lang/rust#145358 ("Sort mono items by symbol name", merged
2025-08-22), rustc sorts mono items within a codegen unit by symbol name
rather than source order unless -Zcodegen-source-order is passed.

That breaks func_macro.s, which defines asm macros for use by "later" files.

Merge all includes into one global_asm! call. A single MonoItem cannot be
reordered against itself, so the source order becomes the order the
assembler sees. The file set and its order are unchanged, and all these
items already shared one codegen unit, so object-file granularity is
unaffected.
@androm3da

Copy link
Copy Markdown
Contributor Author

Fixes #1240

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks. Looks like that PR merged almost a year ago, any idea why there wasn't any problem until now?

View changes since this review

@tgross35
tgross35 enabled auto-merge (rebase) July 28, 2026 19:48
@tgross35
tgross35 merged commit 1c37df1 into rust-lang:main Jul 28, 2026
44 checks passed
@bjorn3

bjorn3 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Be aware that macros are technically not allowed in global_asm!(). They are not on the list of allowed directives at https://doc.rust-lang.org/reference/inline-assembly.html#directives-support and for every stateful directive (which includes macros) you have to undo their effect before exitting the global_asm!() block. So at the very least you did have to use .push_section/.pop_section rather than .text and undefine all macros at the end (is that last one even possible?).

@androm3da

Copy link
Copy Markdown
Contributor Author

Be aware that macros are technically not allowed in global_asm!(). They are not on the list of allowed directives at https://doc.rust-lang.org/reference/inline-assembly.html#directives-support and for every stateful directive (which includes macros) you have to undo their effect before exitting the global_asm!() block. So at the very least you did have to use .push_section/.pop_section rather than .text and undefine all macros at the end (is that last one even possible?).

Okay - good point. I liked having the asm here resemble the corresponding stuff in compiler-rt. But I'm fine w/remediating this by fixing the asm to no longer depend on the .macro directive.

@androm3da

Copy link
Copy Markdown
Contributor Author

LGTM, thanks. Looks like that PR merged almost a year ago, any idea why there wasn't any problem until now?

Sadly, we have not done a good enough job maintaining the hexagon targets. 😖

@bjorn3

bjorn3 commented Jul 28, 2026

Copy link
Copy Markdown
Member

You still want to avoid code duplication you could use a rust macro that you invoke inside the global_asm!(). Something like global_asm!(function_begin!("foo"), "contents", function_end!("foo"), function_begin!("bar"), "contents2", function_end!("foo")) or global_asm!(function!("foo", "contents"), function!("bar", "contents2")). If you do it that way, you can probably split them into separate global_asm!() blocks again if you want.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compile compiler_builtins failed for target hexagon-unknown-linux-musl

3 participants