Skip to content

qemu: Enable user_static builds for providing user mode emulation.#16664

Open
Sumynwa wants to merge 4 commits into3.0-devfrom
sumsharma/enable_qemu_static
Open

qemu: Enable user_static builds for providing user mode emulation.#16664
Sumynwa wants to merge 4 commits into3.0-devfrom
sumsharma/enable_qemu_static

Conversation

@Sumynwa
Copy link
Copy Markdown
Contributor

@Sumynwa Sumynwa commented Apr 14, 2026

Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)

  • The toolchain has been rebuilt successfully (or no changes were made to it)
  • The toolchain/worker package manifests are up-to-date
  • Any updated packages successfully build (or no packages were changed)
  • Packages depending on static components modified in this PR (Golang, *-static subpackages, etc.) have had their Release tag incremented.
  • Package tests (%check section) have been verified with RUN_CHECK=y for existing SPEC files, or added to new SPEC files
  • All package sources are available
  • cgmanifest files are up-to-date and sorted (./cgmanifest.json, ./toolkit/scripts/toolchain/cgmanifest.json, .github/workflows/cgmanifest.json)
  • LICENSE-MAP files are up-to-date (./LICENSES-AND-NOTICES/SPECS/data/licenses.json, ./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md, ./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON)
  • All source files have up-to-date hashes in the *.signatures.json files
  • sudo make go-tidy-all and sudo make go-test-coverage pass
  • Documentation has been updated to match any changes to the build system
  • Ready to merge

Summary

This PR introduces changes to enable user_static builds in qemu to build qemu-user-static* arch specific packages for providing user mode emulation. This enables support to run for ex aarch64 bins using qemu-user-static-aarch64 sub-package via binfmt-misc on x86_64 host. By default, the binfmt config is set with 'F = fix binary' flag to preload the interpreter binary to allow running non-native instructions inside the container environment.

The sub-package qemu-user-binfmt also provides binfmt config but they are dynamic interpreter configurations.
For ex qemu-aarch64, the interpreter registered is "/usr/bin/qemu-aarch64" which is a dynamically linked shared object.
Also, the interpreter is registered without the F = fix binary flag.
We cannot use this package for container-based builds because:

  • there are no entries inside the /proc/sys/fs/binfmt_misc IN the containers mount ns
  • when installing arm64 packages, the pre/post scriptlets start to fail when trying to run without the 'F' flag
    • because there is no binfmt_misc registered inside container ns
    • in host, the interpreter is not loaded since without F indicates lazy loading by kernel
    • tries to execute arm64 instructions natively and fails
Change Log
  • Enable user_static global compile flag
  • configure user_static with 'enable_pie'
  • manage systemd-binfmt restarts post install/uninstall to avoid start-limit-hit
  • add conflicts between qemu-user-static and qemu-user-binfmt as both
    provide binfmt rules
Does this affect the toolchain?

NO

Associated issues
  • #xxxx
Links to CVEs
Test Methodology

@Sumynwa Sumynwa requested a review from a team as a code owner April 14, 2026 08:08
@microsoft-github-policy-service microsoft-github-policy-service Bot added Packaging 3.0-dev PRs Destined for AzureLinux 3.0 labels Apr 14, 2026
Comment thread SPECS/qemu/qemu.spec Outdated
@Sumynwa Sumynwa force-pushed the sumsharma/enable_qemu_static branch from 035ec95 to 322f5df Compare April 28, 2026 15:33
Copy link
Copy Markdown
Contributor

@harshitgupta1337 harshitgupta1337 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just a nit comment.

Comment thread SPECS/qemu/qemu.spec Outdated
Sumynwa added 3 commits May 4, 2026 10:06
Signed-off-by: Sumedh Alok Sharma <sumsharma@microsoft.com>
Signed-off-by: Sumedh Alok Sharma <sumsharma@microsoft.com>
@Sumynwa Sumynwa force-pushed the sumsharma/enable_qemu_static branch from fa7a302 to 95ad3e1 Compare May 4, 2026 10:09
@kgodara912
Copy link
Copy Markdown
Contributor

Buddy build after recent changes.

Copy link
Copy Markdown
Contributor

@kgodara912 kgodara912 left a comment

Choose a reason for hiding this comment

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

As such changes look fine, just a minor clarification needed.

Comment thread SPECS/qemu/qemu.spec
%{nil}

%pretrans user-static
touch %{setbinfmtonce}
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.

The parent directory may not be available in some scenarios, for example in containers, should we try to create the directory first, mkdir -p to avoid file exists, and then touch the file so that file creation doesn't fail or we are not going to support containers altogether as PR description says?

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.

Yes, we should create it just in case.
This works in vm install since it is already created by initramfs.
I will make changes.

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.

Changes done.

Signed-off-by: Sumedh Alok Sharma <sumsharma@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0-dev PRs Destined for AzureLinux 3.0 Packaging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants