Skip to content

aarch64: add -mno-outline-atomics compilation flag #232

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

jmaksymowicz
Copy link
Contributor

@jmaksymowicz jmaksymowicz commented May 9, 2025

This fixes system hang on Zynq Ultrascale+ after update to GCC 14.2.

Description

The newer GCC version implements atomic operations using a function that may use LSE extension instructions. It decided whether to use these instructions using a flag in memory (__aarch64_have_lse_atomics). However, because we do not use glibc, the flag was never initialized. Additionally, because in kernel the .bss segment is not initialized to 0, system would hang non-deterministically on real hardware (on QEMU uninitialized memory reads as 0, so it would never hang).

With -mno-outline-atomics flag, GCC only uses LSE instructions if they are mandatory for the architecture given in -mcpu flag. LSE is mandatory starting from Arm v8.1.

Because we do not use glibc, the "outline atomics" feature would require additional changes to work. The changes would have to be in kernel, libphoenix and plo. Disabling the feature seems like a better choice because Phoenix-RTOS applications are compiled for a specific platform, so the target instruction set (and extensions) are known at compile time. If Phoenix-RTOS is ever ported to an Arm v8.0 system with LSE and enabling support would be beneficial, we can do it per-target by adding +lse to the -mcpu flag.

Motivation and Context

Closes phoenix-rtos/phoenix-rtos-project#1297

DONE: RTOS-1050

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@jmaksymowicz jmaksymowicz requested a review from agkaminski May 9, 2025 16:12
@jmaksymowicz jmaksymowicz self-assigned this May 9, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @jmaksymowicz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses a system hang issue on Zynq Ultrascale+ after updating to GCC 14.2. The newer GCC version uses a function for atomic operations that relies on the LSE extension instructions, determined by a flag in memory (__aarch64_have_lse_atomics). Since glibc is not used, this flag remains uninitialized, causing non-deterministic hangs on real hardware. To resolve this, the pull request adds the -mno-outline-atomics flag to the CFLAGS in target/aarch64.mk. This ensures that GCC only uses LSE instructions when they are mandatory for the architecture specified by the -mcpu flag (Arm v8.1 and later). Disabling "outline atomics" is deemed a better approach as Phoenix-RTOS applications are compiled for specific platforms, making the target instruction set known at compile time.

Highlights

  • Bug Fix: Addresses a system hang on Zynq Ultrascale+ after updating to GCC 14.2 due to uninitialized LSE atomics flag.
  • Compilation Flag: Adds the -mno-outline-atomics flag to CFLAGS in target/aarch64.mk to control LSE instruction usage.
  • Optimization: Disables "outline atomics" feature as Phoenix-RTOS applications are compiled for specific platforms, making the target instruction set known at compile time.

Changelog

  • target/aarch64.mk
    • Added -mno-outline-atomics to CFLAGS to prevent GCC from using LSE instructions based on an uninitialized flag.
    • Line 18 was modified to include the new flag.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A flag to control,
Atom's dance, a kernel's soul,
Hangs no more in wait.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a compilation flag -mno-outline-atomics to address a system hang issue on Zynq Ultrascale+ after updating to GCC 14.2. The change seems reasonable given the explanation in the pull request description. I have a few suggestions to improve the code clarity and maintainability.

Summary of Findings

  • Compiler Flag Placement: The -mno-outline-atomics flag is added directly to CFLAGS. Consider whether this flag should also be added to CXXFLAGS separately, or if it's intended to be applied to both C and C++ compilations via CFLAGS.

Merge Readiness

The pull request addresses a critical bug and the provided solution seems reasonable. However, before merging, it's important to ensure that the implications of this change are fully understood and that it doesn't introduce any regressions. I recommend addressing the review comments before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

Copy link
Member

@nalajcie nalajcie left a comment

Choose a reason for hiding this comment

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

  • maybe add short comment to the code regarding WHY this option is needed
  • maybe include the full issue description (from the PR) in the commit message body - that way it would be easier for the future developer to understand the change without too much digging.

Other than that - LGTM.

Copy link

github-actions bot commented May 9, 2025

Unit Test Results

7 958 tests  ±0   7 434 ✅ ±0   40m 38s ⏱️ +14s
  470 suites ±0     524 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 95f350d. ± Comparison against base commit f8c85a6.

♻️ This comment has been updated with latest results.

agkaminski
agkaminski previously approved these changes May 9, 2025
@agkaminski agkaminski dismissed their stale review May 9, 2025 18:41

Too fast :)

Copy link
Member

@agkaminski agkaminski left a comment

Choose a reason for hiding this comment

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

Shouldn't we set -mno-outline-atomics only for kernel and plo?

@nalajcie
Copy link
Member

Shouldn't we set -mno-outline-atomics only for kernel and plo?

IMHO the PR description is sufficient to tell why we don't want to do it right now (or maybe ever) - that's why I insist on putting it in the commit message body.

(tu summarize: it would be necessary to patch toolchain to support this feature (and introduce necessary changes in AUXVECTOR API), and right now we're not distributing "universal" target binaries so runtime check is not needed)

GCC 14.2 may implement atomic operations using a function that may use
LSE extension instructions. It decided whether to use these instructions
using a flag in memory. However, because we do not use glibc, the flag
was never initialized. The "outline atomics" feature would require
additional changes in kernel, libphoenix and plo and possibly toolchain.

Disabling the feature seems like a better choice because Phoenix-RTOS
applications are compiled for a specific platform, so the target
instruction set (and extensions) are known at compile time.

With -mno-outline-atomics flag, GCC only uses LSE instructions if they
are mandatory for the architecture given in -mcpu flag. LSE is mandatory
starting from Arm v8.1. If Phoenix-RTOS is ever ported to an Arm v8.0
system with LSE and enabling support would be beneficial, we can do it
per-target.

JIRA: RTOS-1050
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/RTOS-1050 branch from 0e17413 to 95f350d Compare May 12, 2025 08:55
@jmaksymowicz
Copy link
Contributor Author

I put the rationale for the changes in the commit message and added a comment in the Make script.

@jmaksymowicz jmaksymowicz merged commit e630102 into master May 13, 2025
37 checks passed
@jmaksymowicz jmaksymowicz deleted the jmaksymowicz/RTOS-1050 branch May 13, 2025 10:34
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.

aarch64: kernel build with the newest toolchain does not boot on ZynqMP
3 participants