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

global_asm! should document that it doesn't guarantee section placement #138247

Open
Qix- opened this issue Mar 9, 2025 · 3 comments
Open

global_asm! should document that it doesn't guarantee section placement #138247

Qix- opened this issue Mar 9, 2025 · 3 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-inline-assembly Area: Inline assembly (`asm!(…)`) needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Qix-
Copy link

Qix- commented Mar 9, 2025

Location

https://doc.rust-lang.org/stable/core/arch/macro.global_asm.html

Summary

Ran into a surprising bug today - global_asm! stuck some executable code into .rodata under release mode. The fix was simple - just needed to add a .section .text directive, but was surprising and neither the docs nor the book seem to mention this (maybe I missed it).

I documented my findings here: https://github.com/oro-os/development-notes/blob/master/Development%20Notes/x86/Scheduler%20Refactor%20(Mar%20'25).md#9-march-2025-fun-with-global_asm-linkage

Would you accept a PR to add a note about this?

@Qix- Qix- added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Mar 9, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2025
@lolbinarycat lolbinarycat added T-libs Relevant to the library team, which will review and decide on the PR/issue. A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Mar 9, 2025
@Noratrieb
Copy link
Member

Noratrieb commented Mar 9, 2025

uhhhh, I don't think it's supposed to require this. in fact, I think it's undefined behavior to add such directives there.. something else must have been wrong in your program to cause this

@Qix-
Copy link
Author

Qix- commented Mar 9, 2025

? Why would it be undefined behavior to add section directives? Is that documented somewhere?

@Noratrieb
Copy link
Member

Not quite undefiend behavior, but forbidden nevertheless.

https://doc.rust-lang.org/nightly/reference/inline-assembly.html#r-asm.ts-args.llvm-syntax

These targets impose an additional restriction on the assembly code: any assembler state (e.g. the current section which can be changed with .section) must be restored to its original value at the end of the asm string. Assembly code that does not conform to the GAS syntax will result in assembler-specific behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-inline-assembly Area: Inline assembly (`asm!(…)`) needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants